
// Make newform 1932.2.a.b in Magma, downloaded from the LMFDB on 13 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1932_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1932_2_a_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1932_2_a_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1932_a();"
function MakeCharacter_1932_a()
    N := 1932;
    order := 1;
    char_gens := [967, 1289, 829, 925];
    v := [1, 1, 1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_1932_a_Hecke(Kf)
    return MakeCharacter_1932_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..(prec+1)]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[0], [1], [0], [1], [3], [2], [0], [5], [-1], [6], [-10], [2], [3], [-4], [3], [3], [9], [-1], [8], [-12], [8], [14], [6], [-6], [-10], [15], [-1], [12], [-4], [-6], [-13], [3], [15], [-4], [-15], [-1], [-13], [11], [15], [6], [-12], [2], [-3], [-19], [-6], [-7], [-13], [-10], [-30], [-25], [24], [0], [17], [18], [15], [3], [-30], [20], [-13], [-18], [20], [-12], [20], [-3], [-1], [6], [11], [-22], [18], [-10], [-18], [24], [-31], [-10], [-34], [-6], [-6], [-22], [-3], [14], [-6], [-28], [15], [-19], [8], [12], [-30], [-22], [30], [-1], [18], [-12], [-4], [18], [-4], [-24], [15], [18], [5], [-25], [8], [-30], [0], [-39], [-40], [14], [-33], [-6], [-42], [20], [32], [-34], [-18], [20], [-34], [9], [23], [-36], [0], [-24], [-25], [-7], [48], [48], [32], [-21], [26], [0], [35], [26], [-4], [-21], [32], [-16], [-27], [-10], [-24], [23], [-18], [-18], [38], [36], [-31], [3], [14], [30], [-4], [39], [-4], [-42], [-13], [42], [32], [0], [32], [0], [38], [30], [29], [12], [-12], [15], [44], [-42], [-21], [6], [23], [44], [-22], [-45], [51], [14], [-45], [44], [38], [30], [-43], [-42], [-7], [-58], [53], [6], [5], [63], [39], [30], [-43], [-28], [-7], [-48], [14], [12], [20], [39], [-21], [-24], [-46], [-10], [48], [39], [15], [32], [14], [-1], [-30], [-15], [-16], [66], [0], [50], [29], [21], [-10], [-18], [-24], [38], [5], [6], [-72], [18], [-25], [-67], [-48], [-16], [27], [-19], [18], [-36], [8], [60], [41], [-52], [20], [60], [-37], [-36], [17], [-6], [-12], [-72], [57], [-28], [20], [47], [-9], [-15], [-46], [6], [-58], [-51], [-4], [0], [-27], [-25], [-54], [-42], [-4], [47], [21], [38], [20], [51], [-46], [11], [-27], [-43], [-9], [-18], [-4], [-72], [-4], [-34], [74], [-10], [-40], [2], [60], [47], [44], [-60], [75], [80], [-42], [38], [50], [-30], [-10], [75], [56], [30], [21], [-18], [-6], [-36], [-46], [-60], [68], [81], [9], [-58], [-22], [-66], [2], [-24], [14], [59], [48], [-7], [-57], [-22], [-27], [78], [-45], [-40], [-57], [-19], [-27], [0], [-31], [72], [-85], [62], [-33], [53], [39], [-7], [-52], [80], [51], [69], [2], [-60], [-28], [3], [-16], [93], [38], [-42], [2], [-16], [-22], [-3], [-27], [-10], [-21], [-54], [20], [17], [66], [6], [-94], [-61], [-36], [35], [-10], [-33], [42], [-18], [18], [18], [-28], [-27], [48], [57], [44], [71], [21], [98], [2], [84], [56], [42], [-3], [35], [62], [-12], [-75], [65], [-12], [-4], [12], [54], [65], [-36], [-76], [57], [-55], [32], [-4], [-48], [68], [-33], [54], [-28], [9], [14], [29], [18], [26], [90], [-40], [60], [50], [-54], [-3], [26], [-100], [42], [-64], [-84], [-10], [-18], [63], [8], [-22], [30], [-6], [92], [-36], [72], [54], [-19], [102], [-36], [-52], [-57], [33], [78], [-70], [9]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1932_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1932_2_a_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_1932_2_a_b(:prec:=1)
    chi := MakeCharacter_1932_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1932_2_a_b();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_1932_2_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1932_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<11,R![-3, 1]>],Snew);
    return Vf;
end function;