
// Make newform 225.4.b.h in Magma, downloaded from the LMFDB on 18 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_4_b_h();".
// 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_4_b_h();".
// 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 := [25, 0, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, -4, 0, 1], [0, 14, 0, -1], [-9, 0, 2, 0]];
    Rf_basisdens := [1, 5, 5, 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, 0, 0], [-1, 0, 0, 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 := 4;
    raw_aps := [[0, -1, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, -13, 0, -4], [-14, 0, -4, 0], [0, 9, 0, -16], [0, -34, 0, -20], [-3, 0, 4, 0], [0, -66, 0, 12], [46, 0, -28, 0], [61, 0, 28, 0], [0, 142, 0, -24], [-196, 0, 52, 0], [0, 345, 0, -4], [0, -310, 0, -32], [0, 424, 0, -28], [62, 0, 64, 0], [375, 0, 56, 0], [0, 179, 0, -100], [-412, 0, -20, 0], [0, -54, 0, 8], [440, 0, -160, 0], [0, -78, 0, -192], [-432, 0, -144, 0], [0, -521, 0, 0], [-504, 0, 36, 0], [0, 380, 0, -264], [0, -840, 0, -132], [-1013, 0, 24, 0], [0, 1492, 0, 128], [0, -456, 0, 40], [960, 0, -276, 0], [0, 1014, 0, -24], [1108, 0, 216, 0], [1474, 0, 488, 0], [-273, 0, 380, 0], [0, -1019, 0, 264], [0, 1067, 0, 420], [0, -1152, 0, 324], [0, 942, 0, 228], [-1690, 0, 520, 0], [-79, 0, -432, 0], [326, 0, 916, 0], [0, -1357, 0, 312], [0, 1302, 0, -168], [2301, 0, 172, 0], [1571, 0, -372, 0], [0, 1949, 0, 804], [0, -5492, 0, 164], [-1297, 0, 776, 0], [0, -1620, 0, -1116], [-712, 0, 676, 0], [-231, 0, -496, 0], [3228, 0, -600, 0], [0, 2100, 0, -552], [0, -2812, 0, 580], [2618, 0, -44, 0], [1464, 0, -376, 0], [0, 6203, 0, 368], [-1578, 0, 228, 0], [0, -161, 0, -1316], [0, -3702, 0, 480], [0, 585, 0, -188], [2946, 0, -264, 0], [0, -3733, 0, -1080], [0, 4240, 0, 1448], [292, 0, 1480, 0], [0, 2823, 0, 1288], [0, -454, 0, -320], [2334, 0, -272, 0], [0, 366, 0, 1236], [6132, 0, -156, 0], [0, -6067, 0, -532], [0, 915, 0, 416], [3015, 0, -1460, 0], [0, -492, 0, -2280], [1092, 0, 2004, 0], [0, 6225, 0, -1328], [11520, 0, 684, 0], [12163, 0, -24, 0], [10768, 0, -1084, 0], [-1242, 0, -2008, 0], [3174, 0, -2868, 0], [0, -8733, 0, 200], [-525, 0, -1580, 0], [0, 1056, 0, 456], [-14116, 0, 1048, 0], [0, -918, 0, -2864], [-7632, 0, 2700, 0], [0, -6200, 0, -1784], [0, -3770, 0, -1612], [11430, 0, 720, 0], [0, 3349, 0, 1860], [7880, 0, 2704, 0], [-2643, 0, -1316, 0], [0, 16916, 0, -284], [-7378, 0, -2216, 0], [12734, 0, -908, 0], [0, -2985, 0, 3236], [13501, 0, 1888, 0], [0, -4128, 0, 2536], [0, 2826, 0, -2160], [0, -9018, 0, 1188], [-5862, 0, -3444, 0], [22379, 0, -276, 0], [0, 5509, 0, 2160], [0, -360, 0, 5868], [0, -3460, 0, -356], [724, 0, 968, 0], [-21301, 0, -696, 0], [0, -20256, 0, -2000], [0, 18138, 0, -688], [0, 14784, 0, -204], [-9167, 0, 3156, 0], [6057, 0, -700, 0], [-7236, 0, 2952, 0], [0, 8620, 0, 616], [0, -11404, 0, 640], [0, -3922, 0, -2000], [9020, 0, 1060, 0], [3522, 0, -4720, 0], [0, -22034, 0, 1288], [0, -18138, 0, 2172], [0, 4488, 0, -2400], [-3216, 0, -2776, 0], [-22570, 0, -2756, 0], [-18273, 0, 1624, 0], [-2886, 0, -2892, 0], [0, 16891, 0, -2436], [0, 8870, 0, 3696], [23268, 0, 1696, 0], [0, 21460, 0, -976], [4344, 0, 3224, 0], [0, -6369, 0, -3656], [-1068, 0, -3072, 0], [18661, 0, 4872, 0], [0, -6732, 0, -3060], [0, -13575, 0, 652], [0, -9140, 0, -1192], [1480, 0, 4460, 0], [-173, 0, 2980, 0], [-16878, 0, 2208, 0], [0, 21113, 0, 3252], [0, 4496, 0, -8420], [-14650, 0, -3520, 0], [-21050, 0, -3340, 0], [0, -6173, 0, -1160], [0, 33260, 0, -2552], [13200, 0, -2840, 0], [0, 5720, 0, -1256], [0, -16003, 0, -4984], [6472, 0, -6472, 0], [0, -3175, 0, -9444], [0, -14490, 0, 3168], [0, 6020, 0, -2608], [-19022, 0, 1040, 0], [14265, 0, 1900, 0], [3298, 0, -3964, 0], [0, -7567, 0, -4312], [-11926, 0, 6112, 0], [0, -3606, 0, -1884], [0, 34696, 0, 2096], [0, -24296, 0, 3120], [9414, 0, -8568, 0], [0, 13706, 0, 2440], [0, -14436, 0, 432], [-20263, 0, -5820, 0], [0, 13646, 0, 4784]];
    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_4_b_h();".
// 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_4_b_h(:prec:=4)
    chi := MakeCharacter_225_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_4_b_h();".
// 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_4_b_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![324, 0, 40, 0, 1]>,<7,R![18225, 0, 946, 0, 1]>,<11,R![-108, 28, 1]>],Snew);
    return Vf;
end function;