
// Make newform 9576.2.a.h in Magma, downloaded from the LMFDB on 19 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_h();".
// 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_h();".
// 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], [-2], [1], [6], [0], [-4], [-1], [4], [-2], [-2], [0], [-10], [-4], [4], [-14], [0], [-2], [12], [0], [-2], [10], [-6], [-10], [-2], [-6], [6], [0], [-8], [6], [2], [-2], [-8], [12], [-22], [10], [-6], [4], [0], [-14], [4], [20], [-16], [6], [-18], [-4], [8], [-6], [-8], [-10], [16], [-20], [-26], [2], [-6], [12], [18], [-28], [22], [18], [-4], [-6], [28], [12], [-22], [-30], [8], [14], [-18], [2], [0], [-24], [-28], [-16], [0], [-24], [2], [-14], [6], [-18], [-14], [-20], [24], [-14], [-6], [22], [26], [10], [-18], [-4], [-30], [-4], [-26], [18], [-20], [-40], [6], [-18], [-16], [10], [-8], [-22], [20], [-6], [-28], [30], [38], [-12], [-16], [-26], [34], [-38], [12], [12], [20], [-34], [4], [0], [-38], [-8], [-28], [46], [18], [36], [20], [14], [22], [-36], [-40], [34], [-20], [-32], [-22], [34], [-36], [34], [14], [52], [-18], [-12], [36], [-18], [44], [-12], [-4], [-24], [-26], [54], [52], [-32], [32], [-40], [28], [48], [44], [-16], [4], [-16], [54], [30], [2], [2], [-24], [8], [6], [0], [-30], [-14], [42], [-34], [20], [0], [-24], [-62], [-30], [-44], [20], [-6], [-26], [22], [4], [52], [16], [2], [24], [6], [32], [-28], [-6], [24], [-46], [18], [-64], [30], [-34], [6], [-2], [2], [-4], [20], [-14], [18], [8], [-38], [66], [18], [-16], [36], [4], [-56], [-18], [30], [4], [-48], [16], [18], [-24], [46], [24], [26], [-48], [-14], [22], [-60], [-52], [-58], [-54], [40], [34], [-42], [34], [56], [-50], [-34], [-44], [24], [14], [42], [2], [-24], [-8], [20], [-16], [4], [-6], [56], [52], [-44], [36], [76], [-22], [28], [8], [-30], [-70], [6], [38], [20], [6], [-6], [-10], [12], [18], [16], [24], [44], [50], [-76], [36], [66], [-8], [16], [74], [-48], [-30], [-4], [22], [-68], [50], [6], [0], [32], [72], [24], [-4], [-60], [78], [62], [48], [-6], [-6], [26], [-62], [44], [44], [14], [6], [-86], [-60], [44], [-10], [-18], [-24], [24], [-12], [-22], [0], [-68], [-16], [-34], [4], [-74], [14], [28], [40], [-86], [-58], [-64], [-62], [-84], [80], [50], [30], [46], [40], [-34], [-32], [4], [-48], [-6], [90], [66], [-68], [74], [-76], [58], [-56], [62], [26], [-32], [-24], [48], [-6], [26], [-2], [72], [-62], [28], [80], [10], [32], [-38], [6], [54], [48], [-42], [0], [58], [0], [24], [-22], [-24], [72], [36], [84], [-22], [-30], [-6], [94], [-50], [56], [-60], [50], [52], [78], [-40], [60], [-82], [16], [70], [-22], [-44], [-20], [72], [44], [72], [-40], [-82], [-28], [8], [-82], [-58], [18], [-60], [80], [26], [22], [50], [-20], [90], [0], [4], [-18], [18], [-38], [-16], [-58], [-22], [-48], [-90], [-90], [-78], [52], [100], [-6], [90], [-16], [-86], [60], [56], [18], [-28], [48], [-96], [-6], [18], [-88], [72], [92], [56], [-82], [22], [68], [-48], [-50], [0], [-22], [44], [-16], [80], [-42], [-20], [92], [-96], [2], [18], [108], [72], [2], [20], [40], [-72], [-62], [-32], [-2], [42], [-20], [-40], [-2], [26], [-84], [50], [16], [-32], [92], [-14], [82], [-18], [24], [-20], [22], [88], [32], [30], [24], [-72], [10], [-56], [-12], [-18], [22], [-6], [86], [-50], [84], [54], [-30], [76], [104], [58], [-100], [-64], [50], [-78], [2], [26], [-92], [78], [-24], [-24], [-18], [-64], [-50], [-20], [-88], [40], [-80], [-22], [-100], [88], [-86], [-20], [66], [-94], [4], [30], [46], [94], [-80], [106], [-82], [20], [10], [72], [-42], [14], [86], [2], [-44], [14], [-24], [102]];
    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_h();".
// 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_h(: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_h();".
// 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_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<11,R![-6, 1]>,<13,R![0, 1]>,<17,R![4, 1]>],Snew);
    return Vf;
end function;