
// Make newform 7728.2.a.e in Magma, downloaded from the LMFDB on 20 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7728_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_7728_2_a_e();".
// 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_7728_2_a_e();".
// 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_7728_a();"
function MakeCharacter_7728_a()
    N := 7728;
    order := 1;
    char_gens := [4831, 5797, 5153, 6625, 6721];
    v := [1, 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_7728_a_Hecke(Kf)
    return MakeCharacter_7728_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], [-1], [2], [4], [3], [-1], [-6], [2], [-2], [1], [8], [5], [3], [-5], [13], [0], [0], [-16], [2], [-6], [6], [10], [9], [-11], [-4], [-4], [-14], [7], [-15], [19], [16], [17], [-13], [1], [11], [1], [2], [-16], [-2], [-3], [13], [-6], [11], [19], [2], [2], [13], [24], [4], [15], [14], [-3], [19], [22], [16], [31], [6], [20], [-16], [-16], [-21], [1], [-2], [-5], [18], [-6], [10], [-22], [-16], [-29], [34], [10], [30], [-6], [6], [25], [-2], [18], [8], [23], [-37], [32], [20], [-34], [-14], [-30], [11], [10], [-4], [20], [30], [36], [-12], [33], [-38], [19], [11], [8], [10], [32], [-27], [20], [10], [-35], [-10], [6], [24], [0], [10], [46], [12], [50], [45], [9], [4], [36], [-48], [13], [-31], [4], [16], [-8], [-45], [18], [0], [-23], [30], [12], [3], [-20], [-12], [39], [10], [-36], [-39], [22], [-6], [6], [-12], [5], [15], [18], [-50], [28], [-19], [-56], [-54], [55], [-6], [-48], [16], [48], [8], [-2], [-30], [19], [-48], [-20], [-53], [20], [22], [-9], [-10], [-13], [24], [-62], [-27], [-9], [2], [27], [-40], [42], [-18], [29], [10], [-45], [34], [49], [-34], [65], [-51], [-33], [-46], [-7], [-44], [-15], [-56], [34], [24], [-12], [33], [39], [20], [22], [18], [44], [25], [-41], [-28], [54], [49], [-42], [63], [16], [38], [36], [-46], [-11], [-69], [6], [6], [-24], [-38], [33], [-70], [-64], [26], [-61], [71], [-60], [40], [9], [-55], [-42], [-16], [40], [-36], [-27], [52], [-48], [-36], [-51], [32], [31], [34], [-4], [32], [-27], [-20], [-64], [-77], [21], [55], [2], [-14], [70], [-59], [8], [-24], [-27], [-71], [22], [30], [28], [-63], [27], [-26], [-8], [-57], [30], [49], [15], [59], [-9], [30], [0], [60], [40], [38], [-50], [-38], [-80], [-6], [80], [19], [36], [-16], [61], [-8], [-34], [-54], [66], [54], [74], [-85], [-44], [-30], [61], [-66], [66], [8], [18], [-32], [20], [-33], [-77], [-10], [22], [-66], [86], [-52], [-42], [-13], [4], [-29], [-9], [-62], [3], [30], [-17], [-8], [39], [11], [-49], [36], [71], [8], [-75], [10], [1], [9], [-53], [-9], [-24], [76], [75], [13], [74], [20], [84], [-15], [-88], [-33], [14], [-30], [-82], [48], [-14], [17], [83], [-78], [59], [62], [28], [25], [-30], [-86], [22], [3], [-36], [25], [14], [-51], [-6], [-30], [46], [74], [-36], [63], [72], [45], [-40], [-25], [27], [-14], [-34], [-8], [36], [-42], [-43], [-23], [46], [28], [-51], [-25], [12], [32], [84], [54], [29], [-12], [-68], [-33], [-11], [32], [-4], [-60], [-76], [49], [-42], [-16], [-87], [22], [87], [50], [82], [-10], [-40], [8], [-50], [34], [-5], [54], [4], [-6], [-16], [-84], [-38], [-18], [-21], [-20], [6], [-46], [70], [68], [-48], [-20], [70], [87], [-78], [60], [-96], [57], [13], [-54], [74], [-57], [-67], [-5], [-35], [-22], [0], [-108], [97], [-43], [-37]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7728_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7728_2_a_e();".
// 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_7728_2_a_e(:prec:=1)
    chi := MakeCharacter_7728_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(3067) - 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_7728_2_a_e();".
// 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_7728_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7728_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![0, 1]>,<11,R![1, 1]>,<13,R![-2, 1]>,<17,R![-4, 1]>],Snew);
    return Vf;
end function;