
// Make newform 450.4.c.f in Magma, downloaded from the LMFDB on 18 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_450_c_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_450_4_c_f();".
// 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_450_4_c_f();".
// 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_450_c();"
function MakeCharacter_450_c()
    N := 450;
    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_450_c_Hecke();"
function MakeCharacter_450_c_Hecke( : Kf := false)
    N := 450;
    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 := ISA(Type(Kf), Fld), 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]];
    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, 7], [-6, 0], [0, -34], [0, -39], [-44, 0], [0, 60], [126, 0], [-244, 0], [0, -152], [480, 0], [0, -52], [0, -300], [0, -129], [534, 0], [362, 0], [0, -134], [972, 0], [0, -235], [-1244, 0], [0, 198], [-972, 0], [0, -23], [1506, 0], [0, 737], [0, -462], [-698, 0], [0, -111], [0, -953], [-2874, 0], [0, 399], [700, 0], [114, 0], [1064, 0], [0, -974], [0, -1030], [0, 624], [0, -573], [-1146, 0], [-118, 0], [-1692, 0], [0, -1675], [0, 1803], [-2696, 0], [-4, 0], [0, 581], [0, 1200], [2314, 0], [0, -9], [-5868, 0], [-4330, 0], [-498, 0], [0, -321], [0, -3984], [-4218, 0], [848, 0], [0, -752], [1308, 0], [0, 2966], [0, 2613], [0, 2224], [9132, 0], [0, 1085], [0, -3837], [9596, 0], [0, 6079], [0, -5160], [2158, 0], [0, -165], [-8664, 0], [0, 1891], [0, -5638], [-980, 0], [0, -2100], [13338, 0], [0, -3596], [2316, 0], [12358, 0], [3306, 0], [-14506, 0], [6480, 0], [0, -5947], [12688, 0], [0, 2484], [-11508, 0], [0, 541], [11238, 0], [0, 1151], [0, -7938], [4644, 0], [0, 1213], [-234, 0], [-14204, 0], [0, 2460], [-4458, 0], [-4212, 0], [0, 5606], [14018, 0], [0, 9100], [0, 5913], [0, -1476], [3084, 0], [-4756, 0], [0, -5507], [0, 426], [0, 7773], [-8616, 0], [17510, 0], [0, -6947], [0, 3248], [0, 285], [2140, 0], [14660, 0], [456, 0], [0, 11726], [0, -3612], [0, 9573], [27810, 0], [-30598, 0], [0, 1889], [0, 13599], [0, 16158], [29324, 0], [-22782, 0], [-26054, 0], [-5976, 0], [0, -2555], [0, -8668], [13660, 0], [0, 660], [15860, 0], [0, 11080], [-13116, 0], [-32846, 0], [0, -5991], [0, -10538], [0, -11043], [21384, 0], [5228, 0], [38010, 0], [0, -19321], [0, 7716], [3886, 0], [27552, 0], [0, -7552], [0, 6153], [47500, 0], [0, 2136], [0, -13898], [39996, 0], [0, 1886], [0, 2892], [0, -4220], [31920, 0], [-34652, 0], [1404, 0], [0, -3827], [-11298, 0], [0, -14484], [0, 23205], [0, -20753], [18246, 0], [0, -12999], [0, 7308], [-2968, 0], [0, -4526]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_4_c_f();".
// 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_450_4_c_f(:prec:=2)
    chi := MakeCharacter_450_c();
    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_450_4_c_f();".
// 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_450_4_c_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<7,R![196, 0, 1]>,<11,R![6, 1]>],Snew);
    return Vf;
end function;