
// Make newform 450.7.b.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_450_b_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_7_b_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_450_7_b_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, 0, 2, 0], [0, 1, 0, 1], [0, 1, 0, -1]];
    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_450_b();"
function MakeCharacter_450_b()
    N := 450;
    order := 2;
    char_gens := [101, 127];
    v := [1, 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_b_Hecke();"
function MakeCharacter_450_b_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 := 7;
    raw_aps := [[0, 0, 0, -4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 242, 0, 0], [0, 0, -948, 0], [0, 1684, 0, 0], [0, 0, 0, -9], [-5744, 0, 0, 0], [0, 0, 0, -2388], [0, 0, 20757, 0], [-39796, 0, 0, 0], [0, -26263, 0, 0], [0, 0, 26193, 0], [0, 1900, 0, 0], [0, 0, 0, -54300], [0, 0, 0, 168813], [0, 0, -176664, 0], [13250, 0, 0, 0], [0, -84484, 0, 0], [0, 0, 375804, 0], [0, 118072, 0, 0], [35116, 0, 0, 0], [0, 0, 0, -7764], [0, 0, -91449, 0], [0, 160712, 0, 0], [0, 0, -472899, 0], [0, 996706, 0, 0], [0, 0, 0, 184320], [-194456, 0, 0, 0], [0, 0, 0, -581169], [0, -1528606, 0, 0], [0, 0, -2173560, 0], [0, 0, 0, 3170751], [1092328, 0, 0, 0], [0, 0, -1570395, 0], [-4078708, 0, 0, 0], [0, -3077839, 0, 0], [0, 400348, 0, 0], [0, 0, 0, -3397416], [0, 0, 0, -2524317], [0, 0, -5258736, 0], [-10381192, 0, 0, 0], [0, 0, -9188184, 0], [0, -1965977, 0, 0], [0, 0, 0, -3804003], [565900, 0, 0, 0], [-13516504, 0, 0, 0], [0, -2677418, 0, 0], [0, 0, 0, 9621132], [-4346408, 0, 0, 0], [0, 0, 0, -14307111], [0, 0, -14421216, 0], [-3120928, 0, 0, 0], [0, 0, -3602844, 0], [0, 0, 0, -10208769], [0, 0, 0, 22101816], [0, 0, 177723, 0], [29639900, 0, 0, 0], [0, -6610636, 0, 0], [0, 0, 4330041, 0], [0, -3371624, 0, 0], [0, 0, 0, -7087971], [0, 2615300, 0, 0], [0, 0, -22077384, 0], [0, 11238913, 0, 0], [0, 0, 0, 19531077], [-5761384, 0, 0, 0], [0, 20052584, 0, 0], [0, 0, 0, -47950836], [42063838, 0, 0, 0], [0, 0, 0, -12443361], [0, 0, -9893844, 0], [0, 13292738, 0, 0], [0, 8941465, 0, 0], [-72097760, 0, 0, 0], [0, 0, 0, 6142272], [0, 0, -34960155, 0], [0, -7845553, 0, 0], [0, 0, 33553191, 0], [115511632, 0, 0, 0], [0, 0, 103727724, 0], [139238840, 0, 0, 0], [0, 0, 70987572, 0], [0, -20031569, 0, 0], [138591844, 0, 0, 0], [0, 0, 0, -78801828], [0, 0, -43215993, 0], [0, -17833240, 0, 0], [0, 0, -107468013, 0], [0, 57489058, 0, 0], [0, 0, 0, -62345988], [0, 0, -63242772, 0], [0, 37584422, 0, 0], [0, 0, -31877952, 0], [-91545824, 0, 0, 0], [0, 0, 0, -113874372], [0, 0, 16970181, 0], [0, 0, 63703071, 0], [0, -18884528, 0, 0], [25479992, 0, 0, 0], [0, -102607948, 0, 0], [0, 0, 0, 170513523], [0, 0, 0, -119414172], [0, 0, -172530591, 0], [241501808, 0, 0, 0], [0, 24698951, 0, 0], [0, 0, 0, 121659144], [0, 0, 0, 191373777], [0, 0, -122541204, 0], [-431090242, 0, 0, 0], [0, -8349526, 0, 0], [0, -96160391, 0, 0], [0, 0, 0, 132245481], [-254873216, 0, 0, 0], [92360180, 0, 0, 0], [0, 0, 300283863, 0], [0, 187973164, 0, 0], [0, 0, 0, -18649764], [0, 0, 0, 182968467], [0, 0, -98531736, 0], [-472544818, 0, 0, 0], [0, 274416625, 0, 0], [0, 0, 0, 71248245], [0, 0, 0, -221364], [-372812200, 0, 0, 0], [0, 0, -439233525, 0], [246510232, 0, 0, 0], [0, 0, -67909788, 0], [0, -195685426, 0, 0], [0, 17453908, 0, 0], [302999344, 0, 0, 0], [0, 0, 0, 173685480], [-82327012, 0, 0, 0], [0, 301789340, 0, 0], [0, 0, 164743329, 0], [-815795570, 0, 0, 0], [0, 0, 0, -259215939], [0, 201231080, 0, 0], [0, 0, 0, 366945645], [0, 0, -2149857, 0], [225521120, 0, 0, 0], [0, 0, -195893571, 0], [0, -353667914, 0, 0], [0, 0, 0, 188334792], [-503826392, 0, 0, 0], [0, 0, 539780124, 0], [0, -9399257, 0, 0], [0, 0, 0, 485377377], [-551931608, 0, 0, 0], [0, 0, 0, 258564168], [0, 292693535, 0, 0], [0, 0, 303886863, 0], [0, 110042452, 0, 0], [0, 0, 0, -828702744], [0, -365807116, 0, 0], [0, 0, -649544808, 0], [215986660, 0, 0, 0], [0, 0, 219290889, 0], [0, 371224169, 0, 0], [0, 0, -128527629, 0], [0, 0, 0, -607538568], [0, 0, 0, 485654193], [0, 547054910, 0, 0], [0, 0, -313329276, 0], [0, 0, 0, -841488423], [0, 0, 0, -835705176], [509602268, 0, 0, 0], [0, 495390023, 0, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_7_b_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_450_7_b_a(:prec:=4)
    chi := MakeCharacter_450_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 7));
    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_7_b_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_450_7_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,7,sign)));
    Vf := Kernel([<7,R![234256, 0, 1]>],Snew);
    return Vf;
end function;