
// Make newform 90.6.c.d in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_90_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_90_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_90_6_c_d();".
// 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_90_6_c_d();".
// 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 := [25, 0, -9, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 24, 0, -1], [0, 8, 0, -2], [-36, 0, 8, 0]];
    Rf_basisdens := [1, 5, 5, 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_90_c();"
function MakeCharacter_90_c()
    N := 90;
    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_90_c_Hecke();"
function MakeCharacter_90_c_Hecke(Kf)
    N := 90;
    order := 2;
    char_gens := [11, 37];
    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, 0, 2, 0], [0, 0, 0, 0], [0, 5, -15, 0], [0, 0, 0, -1], [0, -74, -37, 0], [0, 0, 0, 63], [0, 0, -583, 0], [2244, 0, 0, 0], [0, 0, 250, 0], [0, -54, -27, 0], [3856, 0, 0, 0], [0, 0, 0, 401], [0, -1100, -550, 0], [0, 0, 0, 304], [0, 0, -9950, 0], [0, 0, 573, 0], [0, -4286, -2143, 0], [-38158, 0, 0, 0], [0, 0, 0, -2078], [0, 1908, 954, 0], [0, 0, 0, -3980], [20664, 0, 0, 0], [0, 0, 48484, 0], [0, 6848, 3424, 0], [0, 0, 0, 334], [0, -11806, -5903, 0], [0, 0, 0, 10241], [0, 0, 3756, 0], [58238, 0, 0, 0], [0, 0, 108657, 0], [0, 0, 0, 12179], [0, 32034, 16017, 0], [0, 0, -168957, 0], [-92620, 0, 0, 0], [0, 3394, 1697, 0], [40384, 0, 0, 0], [0, 0, 0, -4673], [0, 0, 0, -26290], [0, 0, 97218, 0], [0, 0, 161111, 0], [0, 49354, 24677, 0], [242522, 0, 0, 0], [0, 33372, 16686, 0], [0, 0, 0, 41470], [0, 0, -299819, 0], [-650184, 0, 0, 0], [986316, 0, 0, 0], [0, 0, 0, -39827], [0, 0, 217700, 0], [1161226, 0, 0, 0], [0, 0, -606517, 0], [0, 160652, 80326, 0], [471490, 0, 0, 0], [0, -68982, -34491, 0], [0, 0, 62103, 0], [0, 0, 214978, 0], [0, -164898, -82449, 0], [1544728, 0, 0, 0], [0, 0, 0, -12109], [0, 148032, 74016, 0], [0, 0, 0, 97478], [0, 0, -1245741, 0], [0, 0, 0, -181692], [0, 256548, 128274, 0], [0, 0, 0, -136130], [0, 0, 493751, 0], [-918644, 0, 0, 0], [0, 0, 0, -20392], [0, 0, 928800, 0], [-950578, 0, 0, 0], [0, 0, -383785, 0], [0, 18456, 9228, 0], [0, 0, 0, -11593], [0, 0, 0, -85419], [-2692220, 0, 0, 0], [0, 0, -282550, 0], [0, 626978, 313489, 0], [0, 0, 0, 229853], [0, 450764, 225382, 0], [1150282, 0, 0, 0], [0, -568834, -284417, 0], [2890774, 0, 0, 0], [0, -227600, -113800, 0], [0, 0, 0, 215434], [-1948968, 0, 0, 0], [0, 0, -2870988, 0], [0, -61788, -30894, 0], [0, 0, 0, 89162], [0, -484578, -242289, 0], [0, 0, 0, -273777], [0, 0, -4558416, 0], [0, -484276, -242138, 0], [0, 0, 0, 28761], [0, -299886, -149943, 0], [-5682396, 0, 0, 0], [0, 0, 1680150, 0], [0, 642642, 321321, 0], [0, 973892, 486946, 0], [0, 0, 0, -190042], [-4769582, 0, 0, 0], [0, 0, 0, 63320], [0, 0, -2572329, 0], [0, 0, 4759472, 0], [0, 148004, 74002, 0], [-11172596, 0, 0, 0], [0, 0, 0, -7444], [0, 0, -4650708, 0], [0, 0, 3459009, 0], [0, 1809624, 904812, 0], [-6957610, 0, 0, 0], [0, 0, 0, 352081], [0, 0, 0, 337999], [0, 0, 4573685, 0], [12331780, 0, 0, 0], [6874520, 0, 0, 0], [0, 1038244, 519122, 0], [0, 0, 0, -502902], [0, 0, -747834, 0], [0, 0, 5881969, 0], [0, 385630, 192815, 0], [-12813958, 0, 0, 0], [0, 0, 0, 618522], [0, 0, 8601563, 0], [0, 0, 2805184, 0], [-3890636, 0, 0, 0], [0, 2325742, 1162871, 0], [1605354, 0, 0, 0], [0, 1197464, 598732, 0], [0, 0, 0, -1358595], [0, 0, 0, -654499], [-25712620, 0, 0, 0], [0, 0, 3939150, 0], [-26964880, 0, 0, 0], [0, 0, 0, -224905], [0, -3267444, -1633722, 0], [5189346, 0, 0, 0], [0, 0, -9438363, 0], [0, 0, 0, 993134], [0, 0, -13126231, 0], [0, -347556, -173778, 0], [9819508, 0, 0, 0], [0, -665530, -332765, 0], [0, 0, 0, 754047], [0, 0, -13899448, 0], [10897134, 0, 0, 0], [0, 1307392, 653696, 0], [0, 0, 0, -285361], [0, 0, 11931621, 0], [-14928620, 0, 0, 0], [0, 0, 4951878, 0], [0, 0, 0, -220481], [0, -3372696, -1686348, 0], [0, 0, 0, 357978], [0, 0, 8353794, 0], [0, 0, 0, 409620], [0, 4027200, 2013600, 0], [-26678928, 0, 0, 0], [0, 693324, 346662, 0], [0, 0, 0, 206716], [0, -1494002, -747001, 0], [0, 0, 15884892, 0], [0, 0, -11262715, 0], [0, 0, 0, 9739], [0, -18846, -9423, 0], [0, 0, -10049463, 0], [0, 0, 6985814, 0], [140392, 0, 0, 0], [0, 0, 0, -1031277]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_90_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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