
// Make newform 225.10.b.b 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_10_b_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_225_10_b_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 := [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 := 10;
    raw_aps := [[0, 11], [0, 0], [0, 0], [0, 2994], [14648, 0], [0, 18953], [0, -220549], [-441820, 0], [0, -1132068], [-1049350, 0], [-7910568, 0], [0, 10496279], [-13285562, 0], [0, -11565382], [0, -6936844], [0, 28817587], [-32042120, 0], [110664022, 0], [0, 59284134], [-276679712, 0], [0, -132011647], [-448202760, 0], [0, -425507898], [189894930, 0], [0, 507074639], [1315368558, 0], [0, -913986362], [0, 92683686], [-1978689590, 0], [0, -789373343], [0, -1200002666], [1968395208, 0], [0, -1014547269], [1136729140, 0], [-4738537510, 0], [2262162472, 0], [0, 5894429639], [0, 5730396898], [0, -6685328004], [0, -5313181593], [26125435120, 0], [2346889262, 0], [-22406421032, 0], [0, -18297974987], [0, -2707727859], [-262713880, 0], [13449310292, 0], [0, -13323132782], [0, 16815895966], [-50045292150, 0], [0, 16481279937], [-7954217240, 0], [-75247743998, 0], [98463127008, 0], [0, 4261995711], [0, -2953271908], [-71596101350, 0], [-124754651888, 0], [0, -56412090201], [-87020807922, 0], [0, 1638482118], [0, 74930082147], [0, 92284955074], [-90464979072, 0], [0, 5396519473], [0, 20915967481], [-12330976908, 0], [0, 10898790979], [0, -42180645094], [1232948810, 0], [0, -86693861883], [63815917320, 0], [0, -56120803026], [0, 360501936773], [204331000340, 0], [0, 273590000292], [-346262180070, 0], [0, -128378846141], [-20167945242, 0], [43340521510, 0], [510680461160, 0], [321228183382, 0], [-447617411472, 0], [0, -70592884147], [850497697160, 0], [0, -151593956418], [-1403278417670, 0], [0, -167676799181], [-1042749631842, 0], [0, -487041877122], [0, -98925339254], [-908731105320, 0], [0, -584814609466], [2491486068688, 0], [557571087620, 0], [0, -900683427928], [-2401096873670, 0], [-1030077035282, 0], [0, 533184539918], [2517486023382, 0], [0, 551764665514], [0, -545360019879], [0, -515402612838], [-4066175272590, 0], [986144387492, 0], [0, 1434736569119], [0, 570847449366], [0, 1485881303177], [1772617523720, 0], [1258381908842, 0], [0, -87267302246], [0, 2315184728873], [0, 1252588819671], [-544227615740, 0], [-6519747334448, 0], [3362965780158, 0], [0, 590409610338], [0, 3315881241296], [0, -412594607593], [-440214037640, 0], [9777884642542, 0], [0, 2112955182093], [0, -3784885095459], [0, 960142726962], [-3998388906788, 0], [-11273616080282, 0], [-11267900052070, 0], [-9052470846240, 0], [0, -672041784346], [0, 328700582893], [-2155870422700, 0], [0, 3867971311792], [-11244801937688, 0], [0, 5927219420359], [2247651763758, 0], [14450525662270, 0], [0, -2595112025733], [0, 6996923647894], [0, 10063439240881], [-8957747618710, 0], [-1764457434948, 0], [-14808178742322, 0], [0, -1698253657862], [0, 9417210817226], [-11894665629990, 0], [-12288146871880, 0], [0, -2306772628527], [0, -2146814139169], [6404282426420, 0], [0, 1622103952592], [0, -14485573502361], [-7504473544522, 0], [0, 14357066803618], [0, 4999125801756], [0, -2354230971786], [-26966252086912, 0], [3966177723440, 0], [19691225561210, 0], [0, 10565241691299], [-5410718200082, 0], [0, 1721295372966], [0, 2092201666117], [0, -7490012901886], [28246046905488, 0], [0, -23112093263389], [0, -24018146662608], [23121091830512, 0], [0, 6768091725339]];
    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_10_b_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_225_10_b_b(:prec:=2)
    chi := MakeCharacter_225_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_10_b_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_225_10_b_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<2,R![484, 0, 1]>,<11,R![-14648, 1]>],Snew);
    return Vf;
end function;