
// Make newform 450.6.c.p in Magma, downloaded from the LMFDB on 14 May 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_6_c_p();".
// 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_6_c_p();".
// 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 := [1040400, 0, 2041, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1021, 0, 1], [0, 3061, 0, 1], [6123, 0, 6, 0]];
    Rf_basisdens := [1, 1020, 340, 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)
    N := 450;
    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 := 6;
    raw_aps := [[0, -4, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, -50, -1, 0], [-270, 0, 0, -2], [0, -445, -2, 0], [0, 246, 10, 0], [-296, 0, 0, -5], [0, -1830, -10, 0], [2850, 0, 0, -2], [-2854, 0, 0, 5], [0, 5650, -24, 0], [-7710, 0, 0, 30], [0, -3160, -41, 0], [0, -3900, -100, 0], [0, 13914, 70, 0], [25260, 0, 0, 52], [-14563, 0, 0, 90], [0, 48700, -3, 0], [-3090, 0, 0, -126], [0, -16450, 120, 0], [-3956, 0, 0, 360], [0, 81732, -100, 0], [82320, 0, 0, -336], [0, 26215, 364, 0], [-45750, 0, 0, 22], [0, 45980, -24, 0], [0, 101478, -470, 0], [-84947, 0, 0, -70], [0, 86736, -400, 0], [0, -144740, -576, 0], [-141930, 0, 0, 1082], [0, 170844, -540, 0], [70840, 0, 0, 120], [383940, 0, 0, 252], [40274, 0, 0, -1545], [0, -220205, 842, 0], [0, 212000, -1915, 0], [0, 230274, 1870, 0], [0, 339618, -770, 0], [248760, 0, 0, -3128], [-25393, 0, 0, 2870], [-22650, 0, 0, -214], [0, 533495, 960, 0], [0, 329628, -220, 0], [-472094, 0, 0, -895], [-407164, 0, 0, -2435], [0, 577310, -1507, 0], [0, 305850, -2250, 0], [-74159, 0, 0, 4030], [0, 196914, 4110, 0], [-736350, 0, 0, 4526], [-791695, 0, 0, -2320], [-37740, 0, 0, -2996], [0, -1204356, -2300, 0], [0, -304686, 190, 0], [-848670, 0, 0, -514], [-517732, 0, 0, 5880], [0, 894145, -794, 0], [184290, 0, 0, 1246], [0, 147500, 1553, 0], [0, -1999968, -2400, 0], [0, -270260, 3363, 0], [-313800, 0, 0, -9976], [0, -337285, -14200, 0], [0, -1260372, 3860, 0], [-1805584, 0, 0, -1680], [0, -329465, -14372, 0], [0, -2658180, -7260, 0], [-1024718, 0, 0, 7920], [0, 31530, 6870, 0], [-1257510, 0, 0, 15158], [0, -579290, 2877, 0], [0, -1246495, -8134, 0], [249880, 0, 0, -10175], [0, -1652700, 11900, 0], [-531270, 0, 0, 19174], [0, -1751285, 3358, 0], [1002990, 0, 0, -17838], [-543773, 0, 0, -16460], [-2235510, 0, 0, -6362], [564674, 0, 0, -28200], [1288890, 0, 0, 22230], [0, 2883335, -10796, 0], [2572882, 0, 0, 7575], [0, 3563076, 4700, 0], [-390540, 0, 0, -22324], [0, -1093550, -18888, 0], [-801930, 0, 0, -28374], [0, -141940, 18168, 0], [0, -1502538, 11610, 0], [753300, 0, 0, -31988], [0, -5155370, 17921, 0], [-4392240, 0, 0, -15248], [5214604, 0, 0, 10875], [0, 688170, -8410, 0], [6989460, 0, 0, 9516], [-6477630, 0, 0, 25086], [0, 1002920, -20127, 0], [-6547597, 0, 0, -6830], [0, -3944480, -35640, 0], [0, -2171112, -28440, 0], [0, 2459766, 9370, 0], [4503750, 0, 0, 7802], [9979964, 0, 0, -4055], [0, 9712345, -29604, 0], [0, 14144646, 12810, 0], [0, 6641502, 22690, 0], [10172820, 0, 0, -29748], [2190275, 0, 0, 72220], [0, 4343860, -26424, 0], [0, 2658350, 62424, 0], [0, 2152170, 12630, 0], [6300820, 0, 0, -8745], [-3710110, 0, 0, -34735], [8761620, 0, 0, -21588], [0, -10274320, -5592, 0], [0, 5613048, 28360, 0], [0, 6280512, -25600, 0], [-7575990, 0, 0, -27290], [-1921618, 0, 0, 9480], [0, -12083350, -31128, 0], [0, 9746814, 16930, 0], [0, -4905048, 46040, 0], [5260424, 0, 0, -43680], [-8702970, 0, 0, -56294], [-2098991, 0, 0, 53410], [-4332090, 0, 0, -37398], [0, -16516010, -23865, 0], [0, -23563630, 8016, 0], [7135360, 0, 0, 28560], [0, 3448920, 12840, 0], [6333740, 0, 0, -93360], [0, 9233185, 90090, 0], [-4998360, 0, 0, 18008], [2624161, 0, 0, -74320], [0, -6048594, 92210, 0], [0, -891560, 110739, 0], [0, -4094748, -11620, 0], [-9125850, 0, 0, -48678], [26380208, 0, 0, 19025], [25383240, 0, 0, -1160], [0, 7541330, 2257, 0], [0, -20323434, 34490, 0], [-6350186, 0, 0, 117960], [-21616290, 0, 0, -10734], [0, 3973145, 111654, 0], [0, 1726308, 115100, 0], [10258840, 0, 0, -8880], [0, -38936196, -1180, 0], [0, 7068115, -159526, 0], [-21082860, 0, 0, -125268], [0, 9718640, -152917, 0], [0, -1031148, 55180, 0], [0, -24418040, 71040, 0], [43295460, 0, 0, -22980], [836542, 0, 0, -155535], [-39073230, 0, 0, 15502], [0, 15644365, -27904, 0], [-2480760, 0, 0, -68296], [0, -4365594, -162070, 0], [0, -16138200, 55640, 0], [0, -8886860, 132744, 0], [-8099040, 0, 0, 32672], [0, 6070836, -28980, 0], [0, 19233672, 116600, 0], [-19759198, 0, 0, 18645], [0, 40496170, -68112, 0]];
    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_6_c_p();".
// 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_6_c_p(:prec:=4)
    chi := MakeCharacter_450_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_c_p();".
// 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_6_c_p( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![1171624441, 0, 78458, 0, 1]>,<11,R![-74016, 540, 1]>],Snew);
    return Vf;
end function;