
// Make newform 288.4.a.d in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_288_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_288_4_a_d();".
// 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_288_4_a_d();".
// 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_288_a();"
function MakeCharacter_288_a()
    N := 288;
    order := 1;
    char_gens := [127, 37, 65];
    v := [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_288_a_Hecke(Kf)
    return MakeCharacter_288_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 := 4;
    raw_aps := [[0], [0], [-4], [0], [0], [18], [-104], [0], [0], [-284], [0], [214], [-472], [0], [0], [-572], [0], [830], [0], [0], [-1098], [0], [0], [176], [-594], [1940], [0], [0], [1746], [1328], [0], [0], [2776], [0], [940], [0], [286], [0], [0], [2012], [0], [-3942], [0], [5362], [-5404], [0], [0], [0], [0], [-6390], [-7088], [0], [5310], [0], [-8096], [0], [-8140], [0], [-9126], [5792], [0], [-3452], [0], [0], [-6838], [4676], [0], [12366], [0], [9470], [12848], [0], [0], [-12922], [0], [0], [15340], [9614], [15880], [-7146], [0], [10890], [0], [-4862], [0], [0], [-10120], [-16506], [19660], [0], [0], [0], [0], [0], [0], [0], [-17996], [1480], [0], [5922], [0], [-24836], [0], [-4280], [0], [-3454], [0], [-24368], [0], [-17030], [0], [23222], [-26464], [0], [0], [14872], [0], [0], [-1012], [0], [-25850], [-4462], [-34996], [0], [0], [31252], [36810], [0], [0], [-38718], [0], [0], [0], [-35046], [27320], [9650], [16852], [0], [-16276], [39704], [0], [47012], [0], [0], [-23166], [0], [-20378], [-20056], [0], [0], [-42514], [51808], [0], [0], [0], [0], [0], [-47480], [51946], [48460], [0], [-15512], [0], [0], [-22936], [0], [0], [52886], [-63810], [-48532], [0], [-56738], [0], [-18378], [0], [-60736], [0], [55660], [0], [65806], [0], [0], [71082], [-72544], [0], [-61204], [-66654], [0], [-25434], [0], [-59202], [0], [0], [-73508], [0], [33088], [-55150], [39042], [-84064], [0], [14684], [0], [-60966], [-85410], [0], [53924], [0], [0], [-57776], [0], [-7774], [62348], [0], [0], [0], [-38630], [0], [99320], [0], [16412], [97290], [0], [61096], [0], [0], [-99866], [-64688], [0], [0], [0], [25938], [0], [0], [109408], [0], [0], [7326], [98572], [0], [0], [0], [0], [0], [17710], [-36032], [0], [0], [0], [0], [0], [-127134], [-127760], [0], [-28746], [-71212], [0], [-95238], [0], [-114764], [134026], [0], [0], [123210], [-29378], [-40216], [0], [-140404], [-98960], [0], [43852], [107822], [0], [-126522], [0], [58734], [0], [0], [52670], [35210], [0], [0], [0], [0], [-107818], [0], [0], [83358], [-135716], [0], [58640], [155948], [0], [87728], [0], [133198], [108940], [0], [10868], [0], [0], [-121862], [92956], [0], [0], [0], [103086], [0], [181170], [0], [170102], [0], [32756], [185720], [0], [0], [-164970], [0], [0], [130878], [-1040], [0], [-176726], [-187772], [0], [186088], [-167490], [0], [0], [0], [26492], [129330], [161276], [0], [0], [0], [0], [98494], [-105008], [-113130], [0], [-219098], [-75064], [-130540], [0], [222772], [0], [183690], [0], [0], [-227084], [0], [225414], [-171292], [0], [233350], [-197312], [0], [0], [57496], [0], [-224714], [-73840], [0], [0], [0], [-175318], [-95036], [0], [186410], [0], [0], [0], [235300], [0], [-248094], [0], [0], [-225182], [-249080], [260406], [-213700], [-266728], [0], [222304], [0], [0], [0], [151866], [0], [0], [244926], [-270292], [0], [0], [0], [-48618], [0], [273416], [0], [22172], [-73186], [265928], [0], [51656], [163300], [0], [-205326], [-272120], [0], [0], [293618], [264316], [0], [0], [186966], [141700], [0], [0], [83336], [0], [166540], [17494], [0], [0], [251962], [37444], [0], [200560], [0], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_288_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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