
// Make newform 9600.2.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9600_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_9600_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_9600_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_9600_a();"
function MakeCharacter_9600_a()
    N := 9600;
    order := 1;
    char_gens := [4351, 901, 6401, 5377];
    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_9600_a_Hecke(Kf)
    return MakeCharacter_9600_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], [-2], [-4], [2], [2], [-8], [-4], [0], [-6], [-2], [6], [0], [-4], [0], [4], [-14], [4], [12], [10], [10], [-12], [-14], [-10], [0], [10], [4], [6], [-2], [2], [-12], [2], [4], [-12], [10], [-18], [8], [-16], [12], [12], [22], [8], [2], [-8], [14], [-20], [18], [-12], [14], [6], [0], [-2], [12], [-18], [24], [-16], [14], [-6], [18], [-12], [16], [-12], [-16], [26], [-24], [-20], [2], [12], [2], [30], [-4], [38], [-2], [32], [24], [20], [6], [6], [-14], [-20], [38], [28], [-18], [6], [-36], [14], [-18], [-28], [26], [4], [36], [14], [4], [4], [-44], [8], [14], [-16], [14], [16], [-28], [-36], [38], [4], [-38], [-4], [30], [-36], [30], [-14], [46], [14], [-4], [34], [-42], [48], [12], [-12], [-36], [-22], [-34], [20], [12], [24], [40], [-2], [-36], [-42], [42], [12], [40], [-22], [2], [22], [14], [24], [32], [-12], [-18], [-24], [8], [22], [-44], [38], [36], [38], [42], [8], [8], [-34], [-46], [40], [24], [8], [0], [-6], [-42], [38], [-28], [52], [2], [2], [4], [-6], [-56], [10], [54], [-22], [-44], [-12], [18], [-8], [-26], [34], [-30], [12], [52], [58], [10], [-58], [-36], [-54], [-34], [-24], [12], [26], [-4], [-26], [-32], [14], [60], [-28], [-20], [28], [46], [-10], [10], [22], [-48], [4], [-10], [34], [-2], [12], [24], [22], [-20], [26], [8], [34], [-4], [-22], [-20], [-12], [58], [30], [22], [0], [-36], [-2], [-66], [30], [-30], [-44], [10], [-2], [-28], [26], [20], [26], [16], [-58], [-62], [56], [-52], [-22], [-4], [-12], [-60], [-36], [-20], [38], [-46], [-58], [-44], [46], [-60], [-4], [24], [-54], [-14], [-4], [10], [-80], [-44], [-2], [12], [-72], [54], [34], [-28], [46], [14], [18], [36], [44], [-6], [40], [-52], [-14], [-28], [-10], [50], [-66], [-14], [-76], [42], [30], [-12], [28], [-58], [-12], [2], [40], [40], [-46], [36], [-14], [34], [-4], [84], [-18], [84], [-26], [36], [-26], [-32], [-36], [-32], [-38], [84], [-30], [-36], [-16], [-30], [-44], [-10], [-12], [-2], [-40], [48], [54], [88], [64], [-6], [28], [28], [-78], [-22], [52], [10], [-48], [-74], [-54], [-70], [24], [-64], [-80], [28], [-10], [60], [-34], [12], [20], [36], [-14], [22], [-42], [-38], [22], [34], [0], [22], [24], [-92], [-74], [-12], [-36], [40], [32], [-50], [24], [-54], [-38], [70], [48], [84], [-6], [-48], [-2], [18], [24], [28], [4], [-14], [-64], [38], [26], [20], [-16], [48], [0], [10], [-38], [-44], [-24], [-34], [78], [-22], [-28], [-54], [22], [-18], [-64], [-96], [10], [-38], [92], [-28], [82], [-60], [-4], [40], [56], [62], [94], [46], [-96], [-60], [-54], [18], [42], [-6], [0], [-30], [74], [6], [56], [52], [-6], [84], [4], [88], [58], [64], [40], [22], [-102], [-84], [20], [6], [40], [-12], [42], [-48], [4], [66], [-72], [-60], [-10], [36], [64], [60], [70], [-106], [70], [42], [-32], [-26], [68], [-86], [50], [60], [82], [86], [12], [36], [14], [54], [4], [-36], [4], [-66], [62], [12], [-66], [-52], [-14], [-34], [-16], [18], [60], [34], [-8], [34], [-98], [76], [22], [-36], [-30], [-20], [20], [34], [20], [82], [-44], [30], [-4], [-84], [10], [-94], [54], [0], [82], [-100], [94], [28], [20], [62], [86], [-68], [110], [0], [20], [-30], [100], [-72], [10], [8], [96], [14], [-94], [-46], [-2], [26], [84], [30], [-70], [44], [-92], [100], [70], [56], [80], [98], [-104], [-46], [48], [-94], [34], [-92], [18], [32], [10], [-4], [34], [-48], [36], [0], [-66], [-90]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9600_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9600_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_9600_2_a_e(:prec:=1)
    chi := MakeCharacter_9600_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(3833) - 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_9600_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_9600_2_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9600_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![2, 1]>,<11,R![4, 1]>,<13,R![-2, 1]>,<17,R![-2, 1]>,<29,R![0, 1]>,<31,R![6, 1]>],Snew);
    return Vf;
end function;