
// Make newform 225.12.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_225_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_225_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_225_12_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_225_12_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_225_b();"
function MakeCharacter_225_b()
    N := 225;
    order := 2;
    char_gens := [101, 127];
    v := [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_225_b_Hecke();"
function MakeCharacter_225_b_Hecke(Kf)
    N := 225;
    order := 2;
    char_gens := [101, 127];
    char_values := [[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 := 12;
    raw_aps := [[0, 39], [0, 0], [0, 0], [0, 13880], [-637836, 0], [0, 383107], [0, 1542177], [19511404, 0], [0, -7656180], [10751262, 0], [-50937400, 0], [0, -332370415], [-898833450, 0], [0, -478973594], [0, -777870672], [0, -1896208515], [555306924, 0], [4950420998, 0], [0, -2646199642], [14831086248, 0], [0, 6985502605], [-3720542360, 0], [0, -4384227018], [-25472769174, 0], [0, 19546247423], [-9310781526, 0], [0, 24287526256], [0, 112797856638], [69451179514, 0], [0, 179832287847], [0, -125136527932], [97891780812, 0], [0, -77507353131], [1126265370436, 0], [-1384580812362, 0], [-698601450208, 0], [0, -1065634926979], [0, -81782243486], [0, -4404712620], [0, 365425787697], [3923714421540, 0], [2279308973150, 0], [-3387088726656, 0], [0, -2464603888127], [0, 3178925136171], [3785535410272, 0], [179493837380, 0], [0, 1112842189852], [0, -207923917470], [-18124772488334, 0], [0, 9382029939], [-17625242631984, 0], [-890116982734, 0], [24228041356548, 0], [0, 3902458675713], [0, -8297787387684], [28523590257006, 0], [23379994087976, 0], [0, 15182060134529], [-15974859435594, 0], [0, 14352253578022], [0, -24087698084139], [0, -12867514520338], [-34604265524376, 0], [0, 6303294455029], [0, -40912148456817], [-34011469184548, 0], [0, 29971974146279], [0, 48934252675662], [142789606547098, 0], [0, -72122960386497], [-124349284943496, 0], [0, 80054767044884], [0, -17362911437609], [146500203674500, 0], [0, -32170925819904], [-39890033609466, 0], [0, -53275989621403], [-34144491481698, 0], [-53334901088234, 0], [-101287654153404, 0], [-157928472303826, 0], [-513171359936640, 0], [0, -37462383977111], [368335241090320, 0], [0, 55623915115458], [-88331413841262, 0], [0, 4710468861155], [697133548616898, 0], [0, -93970635866924], [0, 160003317813498], [-150382370364240, 0], [0, -88273136777752], [860958181676292, 0], [-601209457412516, 0], [0, -546015175914852], [876371101334814, 0], [371989239852150, 0], [0, -486753740856314], [1746062781765590, 0], [0, -87312212992690], [0, 791824502921247], [0, 487898958924102], [1924274391870426, 0], [1611320399461196, 0], [0, 1266251642697023], [0, -1557537920561202], [0, 1103615217700119], [3411585709398408, 0], [-1575452477398774, 0], [0, 252796059751028], [0, -991873583453537], [0, -965493214172931], [-947688701475164, 0], [1005926522765312, 0], [-1131443807632530, 0], [0, -434152779329534], [0, -688182437684628], [0, -1276379270195919], [926792107209060, 0], [-1903318977724498, 0], [0, 2464950253290865], [0, 215146657006851], [0, 1906220266148826], [4037287750902356, 0], [4712672943685602, 0], [-866706096098606, 0], [26266614058368, 0], [0, 2840090942087696], [0, -811557939019109], [-3647940323190644, 0], [0, -3380224134351876], [26483336560376, 0], [0, -3686821812397279], [-6209832596186874, 0], [8861954082034942, 0], [0, 1475237204836821], [0, -6777261083207578], [0, -7996124741041497], [9458590804847370, 0], [-10799627434960948, 0], [11041089876780186, 0], [0, 6305176490429488], [0, -393086171796858], [5925892982962570, 0], [21020885793462840, 0], [0, -9918914734009001], [0, 3983194218784413], [15974892909578980, 0], [0, 2014628742882864], [0, -4884787546844395], [-16258292298256914, 0], [0, 8303058714823786], [0, -9565707178220772], [0, 5362583326926842], [28224866626031568, 0], [-18355082826013760, 0], [-11012509124864814, 0], [0, -4181783525457661], [-22294170304617630, 0], [0, -18901916315470446], [0, -2397840515245197], [0, -16870979059442752], [-35858687142537900, 0], [0, -6001167458810703], [0, 2213434248027540], [-37916708594080408, 0], [0, -28800140229439]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_225_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_225_12_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_225_12_b_a(:prec:=2)
    chi := MakeCharacter_225_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_225_12_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_225_12_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![6084, 0, 1]>,<11,R![637836, 1]>],Snew);
    return Vf;
end function;