
// Make newform 450.4.c.c in Magma, downloaded from the LMFDB on 14 November 2024.
// 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_c();".
// 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_c();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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)
    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 := 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]];
    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, 2], [0, 0], [0, 0], [0, 34], [-27, 0], [0, -28], [0, 21], [-35, 0], [0, 78], [-120, 0], [182, 0], [0, -146], [-357, 0], [0, -148], [0, -84], [0, -702], [-840, 0], [-238, 0], [0, -461], [708, 0], [0, -133], [-650, 0], [0, 903], [735, 0], [0, -1106], [-462, 0], [0, 812], [0, -789], [-230, 0], [0, 2073], [0, 1114], [-252, 0], [0, 1941], [1645, 0], [-1800, 0], [-3298, 0], [0, -266], [0, 1157], [0, -1764], [0, 1848], [135, 0], [2282, 0], [1398, 0], [0, 3317], [0, 1686], [1540, 0], [-3043, 0], [0, 3332], [0, 1596], [-4340, 0], [0, 3018], [4440, 0], [-3703, 0], [-7077, 0], [0, 6846], [0, 3438], [-1680, 0], [5222, 0], [0, 1384], [3858, 0], [0, 4277], [0, -6342], [0, -5831], [2478, 0], [0, -2758], [0, 636], [6887, 0], [0, -7331], [0, -5349], [-11270, 0], [0, -1302], [-750, 0], [0, 1204], [0, -1198], [-8105, 0], [0, 3318], [-13770, 0], [0, 3724], [-6117, 0], [-6125, 0], [1575, 0], [-988, 0], [558, 0], [0, -2443], [-12320, 0], [0, 2343], [10905, 0], [0, 3319], [6468, 0], [0, 11972], [0, 6636], [-630, 0], [0, -10646], [2388, 0], [10540, 0], [0, -6972], [-9030, 0], [-10437, 0], [0, -8113], [-14848, 0], [0, 20329], [0, -15324], [0, 9408], [-24375, 0], [-988, 0], [0, 16429], [0, -13839], [0, -14007], [21090, 0], [5747, 0], [0, -17696], [0, 26102], [0, -4194], [7420, 0], [-5818, 0], [29478, 0], [0, 5852], [0, -29484], [0, 3498], [7905, 0], [27272, 0], [0, 12602], [0, 25536], [0, -2127], [-8953, 0], [-23172, 0], [-9620, 0], [4830, 0], [0, -11816], [0, 23492], [-35300, 0], [0, -16242], [10712, 0], [0, 13504], [18123, 0], [-9485, 0], [0, 31248], [0, 15484], [0, 34146], [-36030, 0], [-6748, 0], [5598, 0], [0, 5732], [0, -39999], [-16940, 0], [-45360, 0], [0, -43918], [0, -3339], [36925, 0], [0, 40608], [0, -35156], [-2142, 0], [0, -19153], [0, -24444], [0, -20036], [33468, 0], [-35090, 0], [-32130, 0], [0, -20531], [-7812, 0], [0, 23256], [0, -14097], [0, 34144], [32613, 0], [0, -43359], [0, 28518], [18122, 0], [0, 28924]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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