
// Make newform 576.7.e.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_576_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_576_e_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_576_7_e_b();".
// 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_576_7_e_b();".
// 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
        poly := [2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 3]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_576_e();"
function MakeCharacter_576_e()
    N := 576;
    order := 2;
    char_gens := [127, 325, 65];
    v := [2, 2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_576_e_Hecke();"
function MakeCharacter_576_e_Hecke(Kf)
    N := 576;
    order := 2;
    char_gens := [127, 325, 65];
    char_values := [[1, 0], [1, 0], [-1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 7;
    raw_aps := [[0, 0], [0, 0], [0, 41], [-484, 0], [0, 316], [-3368, 0], [0, -3], [-5744, 0], [0, 796], [0, 6919], [-39796, 0], [-52526, 0], [0, 8731], [-3800, 0], [0, -18100], [0, 56271], [0, -58888], [-13250, 0], [-168968, 0], [0, 125268], [236144, 0], [-35116, 0], [0, -2588], [0, 30483], [-321424, 0], [0, 157633], [1993412, 0], [0, -61440], [-194456, 0], [0, 193723], [3057212, 0], [0, 724520], [0, 1056917], [1092328, 0], [0, -523465], [-4078708, 0], [-6155678, 0], [-800696, 0], [0, -1132472], [0, -841439], [0, -1752912], [10381192, 0], [0, -3062728], [-3931954, 0], [0, 1268001], [-565900, 0], [13516504, 0], [-5354836, 0], [0, -3207044], [-4346408, 0], [0, 4769037], [0, 4807072], [-3120928, 0], [0, 1200948], [0, -3402923], [0, -7367272], [0, 59241], [29639900, 0], [-13221272, 0], [0, 1443347], [6743248, 0], [0, -2362657], [5230600, 0], [0, -7359128], [22477826, 0], [0, -6510359], [5761384, 0], [-40105168, 0], [0, 15983612], [42063838, 0], [0, 4147787], [0, 3297948], [-26585476, 0], [-17882930, 0], [-72097760, 0], [0, -2047424], [0, -11653385], [-15691106, 0], [0, 11184397], [-115511632, 0], [0, 34575908], [-139238840, 0], [0, 23662524], [-40063138, 0], [-138591844, 0], [0, -26267276], [0, 14405331], [35666480, 0], [0, 35822671], [114978116, 0], [0, 20781996], [0, 21080924], [-75168844, 0], [0, 10625984], [-91545824, 0], [0, 37958124], [0, 5656727], [0, 21234357], [37769056, 0], [-25479992, 0], [-205215896, 0], [0, -56837841], [0, -39804724], [0, 57510197], [-241501808, 0], [-49397902, 0], [0, -40553048], [0, -63791259], [0, 40847068], [-431090242, 0], [16699052, 0], [192320782, 0], [0, 44081827], [-254873216, 0], [92360180, 0], [0, 100094621], [-375946328, 0], [0, -6216588], [0, 60989489], [0, -32843912], [472544818, 0], [548833250, 0], [0, -23749415], [0, -73788], [372812200, 0], [0, 146411175], [246510232, 0], [0, 22636596], [391370852, 0], [-34907816, 0], [302999344, 0], [0, -57895160], [-82327012, 0], [603578680, 0], [0, 54914443], [815795570, 0], [0, -86405313], [402462160, 0], [0, -122315215], [0, 716619], [-225521120, 0], [0, 65297857], [-707335828, 0], [0, -62778264], [-503826392, 0], [0, -179926708], [18798514, 0], [0, 161792459], [-551931608, 0], [0, -86188056], [585387070, 0], [0, 101295621], [-220084904, 0], [0, -276234248], [-731614232, 0], [0, -216514936], [-215986660, 0], [0, -73096963], [-742448338, 0], [0, 42842543], [0, 202512856], [0, -161884731], [-1094109820, 0], [0, 104443092], [0, -280496141], [0, 278568392], [509602268, 0], [990780046, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_576_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_576_7_e_b();".
// 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_576_7_e_b(:prec:=2)
    chi := MakeCharacter_576_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_576_7_e_b();".
// 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_576_7_e_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_576_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<5,R![30258, 0, 1]>,<7,R![484, 1]>],Snew);
    return Vf;
end function;