
// Make newform 450.6.c.m in Magma, downloaded from the LMFDB on 25 April 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_m();".
// 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_m();".
// 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)
    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+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, 2], [0, 0], [0, 0], [0, 74], [384, 0], [0, -167], [0, -288], [664, 0], [0, -1920], [-96, 0], [-4564, 0], [0, -2899], [-6720, 0], [0, -7436], [0, 9600], [0, 3888], [13056, 0], [42782, 0], [0, -18328], [64512, 0], [0, -8405], [-28076, 0], [0, -33216], [81792, 0], [0, 14969], [178656, 0], [0, -57614], [0, 38016], [231118, 0], [0, 71232], [0, 494], [224256, 0], [0, 139488], [-177200, 0], [-236064, 0], [-482836, 0], [0, -190543], [0, 81460], [0, 283008], [0, -109104], [412416, 0], [-25558, 0], [400128, 0], [0, 349825], [0, -203184], [361996, 0], [151856, 0], [0, -546662], [0, 283200], [587206, 0], [0, 289728], [584448, 0], [-414130, 0], [-1899648, 0], [0, -223872], [0, -33792], [-564192, 0], [720308, 0], [0, 70571], [584448, 0], [0, 88528], [0, -478416], [0, -1441432], [-2600448, 0], [0, -1290395], [0, -1155504], [-637024, 0], [0, -1693327], [0, -1389120], [-1555358, 0], [0, 1058880], [-2174976, 0], [0, -526678], [0, -338549], [5107480, 0], [0, 816000], [4465632, 0], [0, 305513], [-6091584, 0], [-2891078, 0], [2984064, 0], [822074, 0], [6324480, 0], [0, -425951], [334732, 0], [0, -881088], [-6518592, 0], [0, 46037], [257568, 0], [0, 1981138], [0, 1744704], [-513024, 0], [0, -2072494], [2758656, 0], [-660896, 0], [0, -472320], [7837728, 0], [3296448, 0], [0, 3251188], [9827138, 0], [0, 1712900], [0, 3216816], [0, 376512], [11148096, 0], [191024, 0], [0, -5186089], [0, 1485312], [0, -3779136], [-6691584, 0], [-3203590, 0], [0, 6779246], [0, -5382701], [0, 4667520], [-9076640, 0], [-11336740, 0], [15544896, 0], [0, -4400132], [0, -5422464], [0, -4943856], [14615040, 0], [15779222, 0], [0, 3324697], [0, -2212752], [0, -2339136], [-5541016, 0], [-6534432, 0], [3865414, 0], [-4806144, 0], [0, 9529490], [0, 2848081], [-18490160, 0], [0, 4951680], [-9059140, 0], [0, 5833835], [-12739776, 0], [-10678274, 0], [0, -4593168], [0, 4641044], [0, -10896], [-12308544, 0], [-23463592, 0], [-14420640, 0], [0, 17170942], [0, -10666368], [-2637506, 0], [10057728, 0], [0, -11537381], [0, -17582304], [-16602200, 0], [0, -14850432], [0, 5897129], [-21037824, 0], [0, 10609588], [0, -11440896], [0, 4843460], [9381120, 0], [42187012, 0], [30455616, 0], [0, -7392349], [-9919968, 0], [0, -1458048], [0, 7043040], [0, -7597426], [-56121984, 0], [0, -17281248], [0, 27819264], [-36002788, 0], [0, -11790547]];
    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_m();".
// 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_m(:prec:=2)
    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_m();".
// 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_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![21904, 0, 1]>,<11,R![-384, 1]>],Snew);
    return Vf;
end function;