
// Make newform 225.4.f.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_225_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_225_f_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_f_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_4_f_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, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 3]];
    Rf_basisdens := [1, 1, 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_f();"
function MakeCharacter_225_f()
    N := 225;
    order := 4;
    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_f_Hecke();"
function MakeCharacter_225_f_Hecke(Kf)
    N := 225;
    order := 4;
    char_gens := [101, 127];
    char_values := [[-1, 0, 0, 0], [0, 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 := 4;
    raw_aps := [[0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [-9, 0, 9, 0], [0, 9, 0, 9], [63, 0, 63, 0], [0, 14, 0, 0], [0, 0, 70, 0], [0, 0, 0, -34], [0, -54, 0, 54], [196, 0, 0, 0], [207, 0, -207, 0], [0, 63, 0, 63], [-144, 0, -144, 0], [0, -168, 0, 0], [0, 0, 0, 106], [0, -63, 0, 63], [-322, 0, 0, 0], [378, 0, -378, 0], [0, -198, 0, -198], [378, 0, 378, 0], [0, 0, 488, 0], [0, 0, 0, -364], [0, -63, 0, 63], [-252, 0, 252, 0], [0, -378, 0, -378], [945, 0, 945, 0], [0, 624, 0, 0], [0, 0, -70, 0], [0, 0, 0, -246], [315, 0, -315, 0], [0, -315, 0, -315], [0, -610, 0, 0], [0, 0, -308, 0], [0, -576, 0, 576], [-2072, 0, 0, 0], [-315, 0, 315, 0], [-2394, 0, -2394, 0], [0, -350, 0, 0], [0, 0, 0, 154], [0, -369, 0, 369], [3094, 0, 0, 0], [0, 198, 0, 198], [-1242, 0, -1242, 0], [0, 1756, 0, 0], [0, 0, -700, 0], [1316, 0, 0, 0], [2205, 0, 2205, 0], [0, -308, 0, 0], [0, 0, -3206, 0], [0, 0, 0, 6], [0, 306, 0, -306], [-700, 0, 0, 0], [0, -1197, 0, -1197], [0, 1358, 0, 0], [0, 0, 0, 666], [0, -378, 0, 378], [-2716, 0, 0, 0], [3843, 0, -3843, 0], [0, 891, 0, 891], [126, 0, 126, 0], [0, 0, 0, 364], [3024, 0, -3024, 0], [0, -2394, 0, -2394], [-5418, 0, -5418, 0], [0, -932, 0, 0], [-6622, 0, 0, 0], [2790, 0, -2790, 0], [0, 876, 0, 0], [0, 0, 5614, 0], [0, 0, 0, -714], [0, 2700, 0, -2700], [5481, 0, -5481, 0], [2709, 0, 2709, 0], [0, 0, -13916, 0], [0, 0, 0, -3248], [0, -1584, 0, 1584], [-5607, 0, 5607, 0], [0, 1899, 0, 1899], [0, 0, -1694, 0], [0, -63, 0, 63], [12850, 0, 0, 0], [0, 1692, 0, 1692], [11214, 0, 11214, 0], [0, 0, 2324, 0], [0, 0, 0, 2680], [0, -873, 0, 873], [-7200, 0, 7200, 0], [0, 3276, 0, 3276], [-4095, 0, -4095, 0], [0, -4676, 0, 0], [0, 3654, 0, -3654], [6975, 0, -6975, 0], [0, 495, 0, 495], [0, 0, -574, 0], [0, 0, 0, -3808], [0, 1134, 0, -1134], [0, 3339, 0, 3339], [-8694, 0, -8694, 0], [-646, 0, 0, 0], [-11340, 0, 11340, 0], [0, -2766, 0, 0], [0, 0, 0, 1260], [0, -4923, 0, 4923], [-12238, 0, 0, 0], [4536, 0, -4536, 0], [0, -4312, 0, 0], [0, 0, 0, 6734], [0, 1836, 0, -1836], [6748, 0, 0, 0], [-13671, 0, 13671, 0], [3213, 0, 3213, 0], [0, 4670, 0, 0], [0, 0, 2828, 0], [-12220, 0, 0, 0], [0, -513, 0, -513], [4914, 0, 4914, 0], [0, 1120, 0, 0], [0, 0, 0, -10184], [0, 3393, 0, -3393], [-22610, 0, 0, 0], [1278, 0, 1278, 0], [0, 3696, 0, 0], [0, 0, 0, 2416], [12418, 0, 0, 0], [0, -1710, 0, -1710], [0, 0, 2086, 0], [0, 2520, 0, -2520], [14931, 0, -14931, 0], [-8757, 0, -8757, 0], [0, 0, 33010, 0], [0, 0, 0, 2232], [-18704, 0, 0, 0], [-2187, 0, 2187, 0], [0, 1071, 0, 1071], [0, 0, 35336, 0], [0, 0, 0, 4676], [19278, 0, -19278, 0], [0, -11522, 0, 0], [0, -6687, 0, 6687], [-37100, 0, 0, 0], [0, 2970, 0, 2970], [-1575, 0, -1575, 0], [0, 10928, 0, 0], [0, 0, -1190, 0], [0, -2268, 0, 2268], [3969, 0, 3969, 0], [0, -15694, 0, 0], [0, 0, 13412, 0], [0, 0, 0, 15826], [-15939, 0, 15939, 0], [0, 7245, 0, 7245], [-11574, 0, -11574, 0], [0, -6370, 0, 0], [30600, 0, -30600, 0], [0, 3708, 0, 3708], [0, 0, 3724, 0], [0, 12159, 0, -12159], [30744, 0, -30744, 0], [0, -252, 0, -252], [0, -1408, 0, 0], [0, 0, 0, 1518], [-30051, 0, 30051, 0], [0, 2583, 0, 2583], [0, 8982, 0, 0], [0, 0, 0, -9688], [-40516, 0, 0, 0], [-945, 0, 945, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_225_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_225_4_f_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_4_f_a(:prec:=4)
    chi := MakeCharacter_225_f();
    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_f_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_4_f_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_225_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![81, 0, 0, 0, 1]>,<7,R![162, 18, 1]>],Snew);
    return Vf;
end function;