
// Make newform 5328.2.a.l in Magma, downloaded from the LMFDB on 25 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_l();".
// 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_l();".
// 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], [0], [1], [3], [-1], [3], [7], [3], [0], [-2], [1], [6], [4], [6], [-9], [0], [-10], [-2], [12], [5], [-2], [3], [3], [2], [-6], [-14], [9], [5], [6], [-5], [18], [12], [-14], [18], [-5], [8], [-11], [-15], [9], [12], [20], [-9], [26], [21], [28], [28], [16], [-24], [-16], [-30], [-24], [-28], [18], [27], [6], [-15], [-8], [17], [-9], [1], [-9], [16], [0], [-10], [-30], [4], [5], [6], [26], [6], [30], [25], [20], [16], [21], [6], [8], [3], [-22], [-15], [-10], [-39], [-25], [10], [36], [18], [8], [6], [34], [6], [-39], [-38], [15], [13], [-24], [-21], [-18], [-8], [11], [13], [-30], [36], [21], [4], [38], [0], [-24], [-6], [-25], [-14], [2], [24], [-38], [-20], [12], [-5], [3], [-24], [24], [-25], [-19], [-27], [18], [40], [24], [-25], [24], [-8], [-34], [-38], [-36], [-32], [5], [-54], [-16], [21], [34], [-12], [27], [52], [-45], [-17], [-18], [17], [-12], [-37], [21], [13], [-18], [-58], [0], [25], [18], [-23], [24], [-38], [-18], [38], [6], [6], [24], [-44], [-12], [3], [-18], [16], [53], [-22], [-36], [48], [-22], [-24], [-19], [-41], [-54], [-56], [39], [16], [8], [28], [0], [-49], [-18], [6], [33], [2], [55], [-22], [-12], [38], [-48], [-29], [-39], [-36], [-36], [-52], [-46], [6], [33], [18], [-5], [-4], [14], [36], [42], [19], [-39], [3], [-50], [38], [60], [16], [-3], [39], [-43], [10], [-18], [-9], [-27], [50], [-41], [18], [-38], [-48], [-37], [6], [-48], [-8], [-48], [-58], [46], [-11], [-66], [-26], [-54], [5], [0], [54], [-36], [-12], [-41], [-53], [71], [-6], [39], [46], [54], [-14], [-15], [59], [78], [-30], [38], [-48], [-72], [14], [-8], [-57], [-28], [-56], [12], [32], [-52], [-81], [4], [-51], [-54], [28], [42], [-13], [25], [74], [-68], [35], [79], [63], [-34], [-61], [24], [-30], [4], [78], [8], [28], [-48], [44], [-6], [-20], [-9], [-48], [-12], [-36], [-27], [-46], [-6], [-5], [27], [60], [-56], [-46], [66], [16], [48], [49], [-22], [6], [-22], [60], [59], [36], [75], [-36], [-14], [57], [-70], [-27], [9], [14], [81], [13], [-67], [-90], [-11], [48], [56], [-2], [28], [-3], [18], [14], [-72], [-8], [6], [-11], [72], [-4], [18], [56], [52], [26], [-72], [54], [-62], [60], [-66], [20], [-68], [36], [-42], [-14], [35], [60], [64], [80], [-54], [75], [60], [48], [-12], [86], [12], [93], [18], [-98], [-64], [-36], [-62], [20], [72], [52], [66], [57], [-50], [8], [-33], [-36], [53], [81], [5], [18], [87], [-20], [36], [-32], [36], [-17], [86], [4], [-63], [65], [54], [-30], [-35], [-72], [-91], [-38], [60], [-62], [3], [-76], [-9], [-20], [90], [-30], [67], [-7], [0], [88], [36], [35], [-33], [78], [-95], [68], [-57], [12], [43], [6], [72], [-24], [-97], [18], [39], [29], [-90], [-99], [-90], [-2], [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_l();".
// 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_l(: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_l();".
// 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_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5328_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<7,R![-1, 1]>,<11,R![-3, 1]>,<13,R![1, 1]>],Snew);
    return Vf;
end function;