
// Make newform 9576.2.a.j in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9576_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_9576_2_a_j();".
// 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_9576_2_a_j();".
// 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_9576_a();"
function MakeCharacter_9576_a()
    N := 9576;
    order := 1;
    char_gens := [7183, 4789, 5321, 4105, 1009];
    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_9576_a_Hecke(Kf)
    return MakeCharacter_9576_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], [0], [-2], [0], [1], [-4], [0], [8], [6], [6], [-4], [2], [12], [12], [-10], [4], [-10], [-10], [4], [-14], [-10], [-2], [-8], [-16], [2], [-6], [20], [-16], [6], [-18], [-8], [-2], [8], [-18], [4], [20], [18], [-10], [-22], [12], [26], [10], [-20], [-8], [24], [-8], [-30], [-6], [0], [-2], [22], [-6], [8], [-26], [16], [-22], [-28], [-16], [2], [-4], [-6], [-14], [32], [20], [-18], [-20], [14], [16], [-36], [-12], [6], [-20], [28], [-10], [22], [-32], [26], [-14], [-38], [-26], [-34], [16], [-12], [-8], [-10], [40], [-8], [6], [22], [36], [12], [-28], [-22], [-18], [-14], [-4], [-2], [8], [-18], [-24], [-36], [28], [42], [-2], [-4], [-6], [22], [24], [-14], [6], [16], [-8], [-40], [-16], [18], [-30], [-10], [-10], [-14], [14], [30], [4], [2], [10], [14], [0], [-6], [52], [46], [8], [-2], [-12], [2], [-30], [-28], [-14], [-34], [4], [30], [-16], [-54], [-46], [-32], [-34], [14], [-20], [-6], [46], [-8], [-20], [52], [-40], [-30], [8], [32], [34], [-18], [-24], [-40], [56], [12], [8], [56], [-52], [46], [-34], [48], [-22], [-34], [8], [22], [32], [60], [-20], [-6], [48], [-42], [-8], [44], [10], [14], [-12], [-24], [-14], [-28], [22], [-10], [10], [64], [20], [6], [32], [-30], [6], [-10], [0], [6], [-12], [40], [-54], [26], [-34], [-64], [20], [26], [-46], [4], [30], [32], [24], [40], [0], [58], [-8], [-54], [42], [62], [-6], [-24], [4], [8], [36], [-58], [-54], [34], [32], [20], [-58], [20], [-68], [20], [-68], [38], [-2], [42], [-44], [28], [-2], [-52], [-76], [78], [34], [46], [-44], [72], [40], [-20], [-18], [20], [-32], [18], [-52], [-40], [-10], [-52], [-34], [-62], [76], [-46], [58], [62], [-36], [28], [-44], [28], [48], [38], [42], [72], [-66], [0], [-34], [-12], [-36], [22], [-30], [46], [-4], [-72], [42], [58], [-28], [24], [-30], [8], [4], [-14], [54], [-62], [-20], [-60], [-74], [20], [64], [16], [72], [24], [74], [72], [0], [-14], [4], [46], [-70], [30], [72], [-14], [50], [-18], [-48], [4], [28], [70], [-50], [46], [-2], [-2], [28], [62], [30], [-16], [-6], [-34], [0], [-76], [-18], [-6], [-2], [48], [68], [-38], [-76], [-82], [-18], [54], [38], [32], [-58], [62], [26], [44], [-24], [-58], [2], [80], [-40], [24], [44], [38], [-22], [0], [-66], [-14], [-6], [-14], [-22], [30], [-26], [-44], [-10], [18], [-56], [-30], [60], [16], [-54], [24], [52], [24], [36], [-56], [22], [12], [-92], [10], [-84], [70], [-42], [78], [-24], [94], [-4], [52], [40], [18], [-92], [-12], [62], [-38], [-64], [-36], [78], [-50], [-64], [102], [28], [-50], [-2], [30], [100], [-38], [-42], [92], [-42], [104], [84], [-30], [30], [-18], [-86], [20], [-22], [-12], [-66], [48], [96], [-32], [72], [-14], [-72], [36], [-70], [42], [-42], [-54], [32], [18], [42], [-32], [44], [-16], [102], [16], [-10], [70], [-92], [88], [-18], [86], [-90], [6], [-98], [8], [-80], [-40], [50], [14], [24], [-40], [-44], [68], [34], [-48], [42], [-52], [42], [80], [-112], [-48], [-110], [-82], [-44], [-30], [-20], [-46], [14], [-16], [-52], [50], [-84], [-82], [-50], [34], [-78], [-60], [-50], [-16], [-58], [-58], [114], [10], [16], [-60], [50], [48], [68], [80], [26], [24], [74], [-66], [-64], [70], [36], [-98], [-4], [80], [62], [72], [36], [48], [-58], [-84], [102], [56], [34], [28], [-38], [54], [-54], [24], [-52], [-74], [70], [-58], [-26], [24], [-86], [-36], [80], [-52], [-86], [-114], [-54], [-44], [82], [110], [-8], [24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9576_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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