
// Make newform 45.6.b.b in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_45_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_45_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_45_6_b_b();".
// 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_45_6_b_b();".
// 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 := [3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    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_45_b();"
function MakeCharacter_45_b()
    N := 45;
    order := 2;
    char_gens := [11, 37];
    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_45_b_Hecke();"
function MakeCharacter_45_b_Hecke(Kf)
    N := 45;
    order := 2;
    char_gens := [11, 37];
    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, -1], [0, 0], [45, -5], [0, -9], [-252, 0], [0, -18], [0, 104], [-220, 0], [0, -367], [6930, 0], [6752, 0], [0, 2106], [198, 0], [0, -63], [0, 1589], [0, 878], [24660, 0], [-5698, 0], [0, -6579], [-53352, 0], [0, 10692], [51920, 0], [0, 9323], [9990, 0], [0, -15264], [109098, 0], [0, 10647], [0, -14641], [-21010, 0], [0, -15832], [0, -13149], [-192852, 0], [0, 21644], [-318340, 0], [-84150, 0], [-155848, 0], [0, 53766], [0, -21843], [0, 2729], [0, 74258], [-444420, 0], [156902, 0], [-332352, 0], [0, 118512], [0, -8986], [-395800, 0], [-251548, 0], [0, -43533], [0, -175501], [547670, 0], [0, -7252], [1005840, 0], [895202, 0], [-558252, 0], [0, 118784], [0, 245993], [1736370, 0], [-1720048, 0], [0, 191826], [-1465002, 0], [0, -248823], [0, -359962], [0, 139941], [-568152, 0], [0, -259668], [0, -19846], [-1580548, 0], [0, 185256], [0, 579239], [-1594450, 0], [0, 44528], [-1104840, 0], [0, -277029], [0, 442242], [5093420, 0], [0, -478627], [-1799910, 0], [0, -739314], [642798, 0], [-2057110, 0], [2937420, 0], [2717702, 0], [-4994352, 0], [0, -313848], [-4704040, 0], [0, 859463], [-6203250, 0], [0, -324684], [3851298, 0], [0, -313893], [0, -197221], [6763680, 0], [0, 1005831], [6875748, 0], [6940100, 0], [0, -138847], [-4979790, 0], [147798, 0], [0, 1867617], [-9998098, 0], [0, 1787661], [0, -136366], [0, 1309643], [2270070, 0], [14380652, 0], [0, 850176], [0, -193681], [0, -1056712], [8800200, 0], [-10766998, 0], [0, -2279709], [0, -1253718], [0, -1825396], [9732380, 0], [-8601448, 0], [6424398, 0], [0, 549837], [0, -569911], [0, 2516978], [1221660, 0], [16278902, 0], [0, 2169792], [0, -395626], [0, -1553377], [4502852, 0], [4880898, 0], [-9969610, 0], [11916720, 0], [0, -208449], [0, -919098], [6169460, 0], [0, 2375513], [-15181648, 0], [0, -98334], [-4514202, 0], [-12079870, 0], [0, 1571558], [0, 5206581], [0, 3155114], [-24879690, 0], [-3954148, 0], [3435498, 0], [0, -595233], [0, 5098199], [15201470, 0], [-28901160, 0], [0, -3046878], [0, -2570716], [19550540, 0], [0, -4083907], [0, 298926], [42283998, 0], [0, 20277], [0, -584431], [0, -4332159], [-1876752, 0], [-6768520, 0], [-11535570, 0], [0, 5919156], [-29491902, 0], [0, -3160261], [0, 2474228], [0, -7114329], [-38477052, 0], [0, -4073176], [0, -4348927], [-52159648, 0], [0, -1474614]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_45_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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