
// Make newform 225.4.e.b in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_225_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_225_e_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_e_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_4_e_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 := [9, -3, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-3, -2, 2, 1], [0, 5, 1, -1], [-9, 2, 1, 2]];
    Rf_basisdens := [1, 6, 3, 3];
    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_e();"
function MakeCharacter_225_e()
    N := 225;
    order := 3;
    char_gens := [101, 127];
    v := [1, 3];
    // 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_e_Hecke();"
function MakeCharacter_225_e_Hecke(Kf)
    N := 225;
    order := 3;
    char_gens := [101, 127];
    char_values := [[-1, 1, 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], [1, -1, -1, -1], [0, 0, 0, 0], [0, 2, 0, 3], [0, -37, 0, 8], [-13, -2, -15, 15], [-54, 0, -9, 0], [-52, 0, -27, 0], [7, -26, -19, 19], [0, 26, 0, -1], [-23, 20, -3, 3], [-2, 0, -54, 0], [-115, 17, -98, 98], [0, 47, 0, -6], [0, 154, 0, 91], [54, 0, 162, 0], [-331, 467, 136, -136], [0, -272, 0, 105], [527, -461, 66, -66], [756, 0, 144, 0], [106, 0, -243, 0], [0, 556, 0, -309], [0, 460, 0, -107], [-162, 0, 72, 0], [0, 317, 0, 102], [0, 872, 0, -91], [-1021, 1042, 21, -21], [756, 0, -81, 0], [866, 0, -270, 0], [-1073, 1234, 161, -161], [1024, 0, -54, 0], [-547, 80, -467, 467], [0, -1835, 0, -242], [-563, 533, -30, 30], [1397, -550, 847, -847], [0, -182, 0, 573], [-49, 988, 939, -939], [-1676, 0, -216, 0], [1411, -1196, 215, -215], [0, 10, 0, 937], [2052, 0, -288, 0], [-2158, 0, -756, 0], [0, -1054, 0, 1025], [131, -749, -618, 618], [3186, 0, -234, 0], [812, 0, 702, 0], [913, -124, 789, -789], [0, -1510, 0, 435], [0, -1475, 0, 640], [-743, -754, -1497, 1497], [270, 0, -1575, 0], [-3895, 3158, -737, 737], [0, -3089, 0, -1038], [3132, 0, 423, 0], [-3449, 3493, 44, -44], [0, 5122, 0, 415], [810, 0, -1566, 0], [-2104, 0, 324, 0], [0, -5290, 0, -915], [0, -766, 0, 1763], [-3685, 3940, 255, -255], [4975, -5534, -559, 559], [-596, 0, 1701, 0], [-7135, 7118, -17, 17], [0, -1195, 0, -1086], [0, -1682, 0, 2737], [0, 6964, 0, -1137], [-7465, 6721, -744, 744], [-5177, 3943, -1234, 1234], [0, -8408, 0, 1581], [0, -53, 0, -1808], [1728, 0, 666, 0], [0, -1492, 0, 1317], [2651, -3278, -627, 627], [-3184, 0, -351, 0], [-5933, 3880, -2053, 2053], [0, -1090, 0, -289], [3454, 0, 1890, 0], [2693, -4915, -2222, 2222], [-6287, 6473, 186, -186], [3017, -604, 2413, -2413], [0, -1532, 0, 141], [4104, 0, 2430, 0], [-542, 0, 27, 0], [0, 7072, 0, -1785], [0, -9197, 0, -386], [-1458, 0, -2475, 0], [0, 5465, 0, 498], [0, -10450, 0, 1403], [2831, -3692, -861, 861], [13716, 0, 1413, 0], [0, -6310, 0, 1421], [-11072, 0, -702, 0], [3125, -6823, -3698, 3698], [-2363, -1213, -3576, 3576], [-1404, 0, 5796, 0], [-1195, 4184, 2989, -2989], [6642, 0, -603, 0], [7504, 0, 972, 0], [10262, 0, -918, 0], [0, 2783, 0, -7962], [-5778, 0, 504, 0], [-11441, 14959, 3518, -3518], [0, 107, 0, -6130], [-8879, 13115, 4236, -4236], [4426, 0, 3645, 0], [0, -6569, 0, -2366], [-4158, 0, -6264, 0], [-4003, 980, -3023, 3023], [0, -299, 0, -1272], [203, -5132, -4929, 4929], [21814, 0, 486, 0], [-317, -3131, -3448, 3448], [0, 4093, 0, -5466], [5024, 0, 5400, 0], [0, -20485, 0, -1738], [-24241, 25369, 1128, -1128], [-11232, 0, 2970, 0], [2167, -1898, 269, -269], [0, 14948, 0, 1223], [8977, -2428, 6549, -6549], [0, 146, 0, -1095], [0, 22060, 0, -1241], [324, 0, -1341, 0], [0, 4408, 0, 3327], [16794, 0, 324, 0], [0, -17444, 0, -759], [12096, 0, 5652, 0], [0, -18214, 0, -1689], [5963, -12062, -6099, 6099], [12800, 0, 5481, 0], [9619, -2150, 7469, -7469], [1453, -3472, -2019, 2019], [-13934, 0, -8100, 0], [4205, -1342, 2863, -2863], [-11543, 2378, -9165, 9165], [5022, 0, 936, 0], [2291, 4084, 6375, -6375], [17179, -12140, 5039, -5039], [-18954, 0, -7371, 0], [-1564, 0, -7317, 0], [0, 13058, 0, 1439], [-3577, 12472, 8895, -8895], [21060, 0, -1440, 0], [14690, 0, 12852, 0], [0, -11476, 0, -4537], [0, -21094, 0, 3909], [0, 6094, 0, -1259], [265, 7571, 7836, -7836], [15336, 0, -7344, 0], [-4117, -4592, -8709, 8709], [1350, 0, 1008, 0], [-24572, 0, 4401, 0], [30895, -32696, -1801, 1801], [0, 23321, 0, 8688], [0, -17704, 0, 2231], [-42928, 0, -1134, 0], [0, 26558, 0, -3961], [10906, 0, 1080, 0], [-11239, 10124, -1115, 1115], [0, 10099, 0, -1430], [21114, 0, 2115, 0], [-6097, 6982, 885, -885], [20520, 0, 8964, 0], [11671, -11429, 242, -242], [0, 13672, 0, 8929], [22088, 0, -7128, 0], [0, 37244, 0, -3417]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_225_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_225_4_e_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_4_e_b(:prec:=4)
    chi := MakeCharacter_225_e();
    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_e_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_4_e_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![36, 18, 15, -3, 1]>],Snew);
    return Vf;
end function;