
// Make newform 25.20.b.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_25_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_25_b_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_25_20_b_a();".
// 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_25_20_b_a();".
// 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 := [1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 2]];
    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_25_b();"
function MakeCharacter_25_b()
    N := 25;
    order := 2;
    char_gens := [2];
    v := [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_25_b_Hecke();"
function MakeCharacter_25_b_Hecke(Kf)
    N := 25;
    order := 2;
    char_gens := [2];
    char_values := [[-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 := 20;
    raw_aps := [[0, 228], [0, -25326], [0, 0], [0, -8458772], [-16212108, 0], [0, -25210807531], [0, 112535049753], [1710278572660, 0], [0, -7018267394436], [-1137835269510, 0], [-104626880141728, 0], [0, -84696163685297], [-3309984750560838, 0], [0, -563956766096746], [0, 1749346993837128], [0, -14978147056490151], [-58391397642732420, 0], [23373685132672742, 0], [0, -102551262128691122], [-177902341950417768, 0], [0, -149926887519330061], [92227090144007440, 0], [0, -604271411735292966], [-4371201192290304330, 0], [0, -317506611109224047], [-14225184990751604898, 0], [0, -2453647187076798076], [0, 13231261364988978378], [18417779076742725130, 0], [0, -12871050969975495081], [0, 44036013699367208128], [71928888557627226972, 0], [0, -147713086646041497747], [-138478242598622657780, 0], [266021193813555196050, 0], [575578481645706044552, 0], [0, -536187740465668265597], [0, 290382331499503845794], [0, 121696208584940292828], [0, 596751441329959175589], [4146639259449756929940, 0], [3323637583685998127822, 0], [6193795096341916302912, 0], [0, 2603485647368385120479], [0, 1211918156618856013503], [1059072621521283111400, 0], [-13242387429757990150708, 0], [0, -10046068391503954029136], [0, -10174704183613989958722], [39990035937447287206690, 0], [0, -12108516586255834719741], [-26241066116230112579280, 0], [73644506169104941694162, 0], [72930920304932253837252, 0], [0, -31906015258452324677247], [0, 67909912391778342404244], [133672004682359243213610, 0], [200547574021219881238832, 0], [0, 100111373587048279914103], [-119239496202616376591478, 0], [0, 1730542386027763482734], [0, 106617756265899916244529], [0, 95943543390753517906678], [-154521700942476731981208, 0], [0, -143703808055550204283381], [0, 13176634663877792425203], [-1053375627397004455028428, 0], [0, 338079949872258585320953], [0, 531623112953752223720178], [714666649174805721201850, 0], [0, 253660382794544667765999], [-3320064150855122758012920, 0], [0, -1122149285287428849933272], [0, -2553032448998186477560711], [4289751162168739890186940, 0], [0, 934015313787304858382784], [6474481839876985824443970, 0], [0, 613798557500060085423403], [-517895245995397565310798, 0], [-2818767450506973223394570, 0], [-8655708588109946594551740, 0], [-5216517712913512492334818, 0], [10436381488383884270310672, 0], [0, -7255475650928139054389641], [-17985690752159857937736680, 0], [0, -4368424738489666030687746], [16057594567447141671042750, 0], [0, -1337933117019628683437747], [6968065181802302254603542, 0], [0, 12492168779146717898089544], [0, 9726534589414843761202278], [-33415333454065222785017760, 0], [0, -24309041359816518525583172], [9867302508639730608865812, 0], [35415047001126952989663700, 0], [0, -7360176317848269558139476], [48829005109648323366368730, 0], [71444530606997803992245082, 0], [0, -44994745466899167466048186], [-93360210082563133894716538, 0], [0, -13733520801803917280289122], [0, 71294349745067251832079003], [0, 86126137689090257500352394], [-52489258032363872534509290, 0], [-3216737162983851125343868, 0], [0, 58726414066498271532109153], [0, 934431004517548051466778], [0, 75082536856947411557075079], [-165804217294620955662035400, 0], [-254795398167551616303036598, 0], [0, 157095646725366284800067728], [0, 195738836390316669231404369], [0, 243033110613935929600981053], [451098253696556017748426860, 0], [203805071384693884419692072, 0], [577926950333012117394136962, 0], [0, -386024634137601373103491246], [0, -696128400067817709823572], [0, 309735111380330916299435349], [79662660304446879314894580, 0], [-185436309592288012497255058, 0], [0, -295765987908056061412677361], [0, -148709031111798953958400497], [0, 629713288549816194497669334], [31996453716239418771490412, 0], [2064629078554311470359104102, 0], [1440955677319441783081036930, 0], [1263930301200965104242038160, 0], [0, 277233874453351457497720228], [0, -403281507318762472189125091], [-663849768850552007374925180, 0], [0, 1820473801495790425826840004], [-1554577041827633477827398448, 0], [0, 667030259504543405301391303], [-68982915656223958871596758, 0], [809673088318519394490554110, 0], [0, -504619233995272863740622111], [0, -2441537095402754215804046522], [0, 591728867796238663414382403], [5084951459230685387890761030, 0], [-27213304830712131339736108, 0], [-516380791107383402431504818, 0], [0, 988119407063131880489634764], [0, -583972684215130944686028222], [-4208089612099645624896372710, 0], [-8492535037153362379496144280, 0], [0, 4666724715226855424145700649], [0, -5551869849924255768029065947], [-11147795036950497002528898020, 0], [0, -5772272632254493646799434256], [0, 7795587026637439860499943803], [335920487479087202598947922, 0], [0, 67187154346173783121803434], [0, 4619436214422988136418913428], [0, -9029250693224067890624604422], [-19930387918681950794667229008, 0], [-10431956843245634836995714440, 0], [5177357237229028065304968990, 0], [0, 4666007922161076443673741853], [4501145845350783495352219062, 0], [0, 8806276250308628797030967478], [0, -2968650989326972058749810101], [0, -12924439952111530391749933172], [20573213660753757730929994932, 0], [0, -11726186370273181729324120647], [0, -21276288793223824789124417316], [52147222626560601969944350112, 0], [0, -807706283527310342670516497]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_25_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_25_20_b_a();".
// 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_25_20_b_a(:prec:=2)
    chi := MakeCharacter_25_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 20));
    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_25_20_b_a();".
// 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_25_20_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_25_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,20,sign)));
    Vf := Kernel([<2,R![207936, 0, 1]>],Snew);
    return Vf;
end function;