
// Make newform 5328.2.a.f in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_5328_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_5328_2_a_f();".
// 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_5328_2_a_f();".
// 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_5328_a();"
function MakeCharacter_5328_a()
    N := 5328;
    order := 1;
    char_gens := [1999, 1333, 2369, 1297];
    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_5328_a_Hecke(Kf)
    return MakeCharacter_5328_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], [0], [-2], [3], [5], [-3], [-3], [-5], [3], [0], [-4], [1], [-6], [-4], [-4], [3], [14], [-14], [-12], [12], [13], [-6], [-7], [1], [-12], [-10], [2], [-13], [-13], [-2], [17], [-10], [0], [16], [18], [9], [10], [-7], [13], [-19], [-18], [-10], [7], [-4], [21], [-4], [-24], [16], [-18], [-20], [-20], [-8], [-10], [2], [-7], [-12], [-23], [0], [-21], [9], [17], [-25], [-14], [12], [-8], [-22], [-16], [-15], [-18], [-26], [18], [16], [-29], [20], [32], [29], [-26], [-10], [21], [-6], [35], [38], [-11], [27], [26], [-12], [22], [-24], [10], [20], [6], [-31], [-4], [33], [-15], [-16], [3], [24], [0], [9], [-27], [46], [-38], [-41], [-12], [-8], [-12], [-46], [40], [19], [-4], [38], [-2], [-16], [-22], [50], [-5], [-41], [30], [-8], [45], [37], [13], [42], [-2], [44], [-3], [6], [28], [20], [-34], [-24], [4], [7], [22], [-40], [-11], [32], [-38], [-27], [-6], [7], [45], [32], [11], [34], [-19], [47], [-43], [6], [22], [-48], [5], [-26], [25], [32], [38], [-8], [2], [30], [-54], [-46], [4], [36], [45], [-6], [50], [-9], [-46], [6], [-44], [-2], [-12], [-7], [5], [-6], [-16], [-9], [-20], [10], [10], [30], [-27], [-38], [0], [21], [-32], [-17], [38], [12], [-14], [52], [43], [-7], [28], [-52], [-34], [46], [-10], [-3], [36], [49], [-2], [46], [-4], [-68], [25], [-13], [53], [6], [22], [10], [52], [-33], [-21], [41], [-34], [-6], [-73], [57], [-62], [-19], [46], [36], [12], [-35], [-58], [-30], [-56], [10], [-44], [52], [55], [18], [64], [24], [53], [-6], [0], [-12], [-2], [-13], [-43], [33], [36], [63], [58], [-72], [30], [21], [-59], [-46], [6], [-76], [-40], [-52], [-32], [0], [11], [14], [-30], [22], [-46], [16], [57], [-26], [-67], [46], [22], [4], [-27], [-7], [46], [-56], [-49], [41], [57], [-10], [27], [-48], [40], [42], [20], [62], [-32], [40], [64], [10], [2], [-67], [-54], [64], [48], [43], [16], [42], [-35], [39], [24], [-62], [-84], [-42], [0], [64], [-71], [-28], [0], [62], [-66], [61], [-8], [-45], [38], [22], [85], [72], [27], [81], [-58], [71], [-27], [37], [-74], [7], [22], [16], [40], [-20], [-27], [26], [10], [-66], [-82], [30], [-55], [-44], [-28], [-54], [40], [-56], [-40], [4], [24], [-14], [-12], [10], [0], [-52], [-48], [-2], [80], [-65], [-6], [-46], [-62], [24], [19], [24], [-96], [-12], [38], [-66], [-59], [-24], [2], [-6], [-18], [2], [2], [-84], [44], [-10], [53], [80], [34], [69], [-62], [-67], [-1], [57], [64], [-55], [-66], [-6], [92], [6], [-7], [-14], [48], [57], [-79], [14], [66], [-7], [12], [101], [34], [-48], [-68], [-33], [66], [25], [-80], [14], [-48], [-23], [87], [22], [12], [-8], [-57], [-85], [8], [105], [-88], [-77], [20], [-3], [42], [-4], [72], [81], [52], [65], [-15], [-18], [19], [10], [14], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5328_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5328_2_a_f();".
// 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_5328_2_a_f(:prec:=1)
    chi := MakeCharacter_5328_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_5328_2_a_f();".
// 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_5328_2_a_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5328_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<7,R![-3, 1]>,<11,R![-5, 1]>,<13,R![3, 1]>],Snew);
    return Vf;
end function;