
// Make newform 900.3.f.d in Magma, downloaded from the LMFDB on 16 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_900_f_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_900_3_f_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_900_3_f_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 := [4, 0, 17, 0, 40, 0, -12, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [104, 0, 896, 0, -244, 0, 19, 0], [453, 0, 882, 0, -278, 0, 23, 0], [0, -204, 0, -611, 0, 174, 0, -14], [0, 437, 0, 1548, 0, -452, 0, 37], [0, 249, 0, 326, 0, -104, 0, 9], [401, 0, 1644, 0, -486, 0, 41, 0], [0, 32, 0, -1277, 0, 348, 0, -28]];
    Rf_basisdens := [1, 55, 55, 55, 110, 22, 55, 55];
    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_900_f();"
function MakeCharacter_900_f()
    N := 900;
    order := 2;
    char_gens := [451, 101, 577];
    v := [1, 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_900_f_Hecke();"
function MakeCharacter_900_f_Hecke(Kf)
    N := 900;
    order := 2;
    char_gens := [451, 101, 577];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -2, 0, 0, 2], [0, 1, 0, 0, 0, 0, 1, 0], [0, 0, 0, -2, 4, 0, 0, 2], [0, 0, 0, 2, -4, -1, 0, -2], [2, -1, -2, 0, 0, 0, 5, 0], [0, 0, 0, -2, 2, 0, 0, -4], [10, -2, 2, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 2, 0], [0, 0, 0, -2, 4, -6, 0, 2], [-17, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -10, -8, 0, 0, -2], [0, 0, 0, -14, -20, 0, 0, 6], [0, 0, 0, -8, 16, -6, 0, 8], [-6, 18, 6, 0, 0, 0, 0, 0], [-28, 10, -10, 0, 0, 0, 0, 0], [0, 0, 0, 1, -9, 0, 0, 10], [-10, 22, 10, 0, 0, 0, -8, 0], [0, 0, 0, -2, 4, -11, 0, 2], [-2, -4, 2, 0, 0, 0, -10, 0], [0, 0, 0, -11, -5, 0, 0, -6], [-55, -2, 2, 0, 0, 0, 0, 0], [0, 0, 0, -12, 24, 18, 0, 12], [68, 10, -10, 0, 0, 0, 0, 0], [0, 0, 0, -26, -36, 0, 0, 10], [0, 0, 0, 5, -13, 0, 0, 18], [-100, 2, -2, 0, 0, 0, 0, 0], [0, 0, 0, -8, 16, -5, 0, 8], [0, 0, 0, -18, -26, 0, 0, 8], [10, -2, -10, 0, 0, 0, 28, 0], [0, 0, 0, 12, -24, -29, 0, -12], [-16, 33, 16, 0, 0, 0, -15, 0], [30, -22, 22, 0, 0, 0, 0, 0], [10, 0, -10, 0, 0, 0, 30, 0], [0, 0, 0, -12, 24, -18, 0, 12], [0, 0, 0, 43, 41, 0, 0, 2], [0, 0, 0, 54, 84, 0, 0, -30], [0, 0, 0, -8, 16, 16, 0, 8], [2, 9, -2, 0, 0, 0, 15, 0], [62, 40, -40, 0, 0, 0, 0, 0], [20, -26, -20, 0, 0, 0, 34, 0], [0, 0, 0, -22, 44, 7, 0, 22], [0, 0, 0, -28, 56, 22, 0, 28], [0, -20, 0, 0, 0, 0, -20, 0], [-20, 49, 20, 0, 0, 0, -11, 0], [0, 0, 0, -8, -12, 0, 0, 4], [0, 0, 0, -82, -144, 0, 0, 62], [80, -28, 28, 0, 0, 0, 0, 0], [0, 0, 0, -8, 16, 22, 0, 8], [26, -58, -26, 0, 0, 0, 20, 0], [127, 30, -30, 0, 0, 0, 0, 0], [10, -55, -10, 0, 0, 0, -25, 0], [0, 0, 0, -28, 56, 18, 0, 28], [0, 0, 0, -18, -86, 0, 0, 68], [300, 28, -28, 0, 0, 0, 0, 0], [20, -42, -20, 0, 0, 0, 18, 0], [0, 0, 0, 18, -36, -20, 0, -18], [118, 20, -20, 0, 0, 0, 0, 0], [0, 0, 0, -39, -135, 0, 0, 96], [0, 0, 0, 62, -124, -2, 0, -62], [0, 0, 0, -15, -47, 0, 0, 32], [-30, 56, 30, 0, 0, 0, -34, 0], [0, 0, 0, 28, -56, -50, 0, -28], [0, 0, 0, 32, -64, -76, 0, -32], [0, -53, 0, 0, 0, 0, -53, 0], [0, 0, 0, -32, 64, -41, 0, 32], [0, 0, 0, 21, 115, 0, 0, -94], [140, 42, -42, 0, 0, 0, 0, 0], [0, 0, 0, 12, -24, -106, 0, -12], [34, -52, -34, 0, 0, 0, 50, 0], [0, 0, 0, 36, -44, 0, 0, 80], [0, 0, 0, 28, -56, 74, 0, -28], [38, -39, -38, 0, 0, 0, 75, 0], [0, 0, 0, 104, 170, 0, 0, -66], [-150, 8, -8, 0, 0, 0, 0, 0], [0, 0, 0, 8, -16, 28, 0, -8], [-87, 30, -30, 0, 0, 0, 0, 0], [-445, 12, -12, 0, 0, 0, 0, 0], [-2, -19, 2, 0, 0, 0, -25, 0], [392, -60, 60, 0, 0, 0, 0, 0], [-50, 28, 50, 0, 0, 0, -122, 0], [0, 0, 0, -42, 84, 63, 0, 42], [14, -22, -14, 0, 0, 0, 20, 0], [0, 0, 0, -65, 3, 0, 0, -68], [15, 78, -78, 0, 0, 0, 0, 0], [0, 0, 0, 108, -216, -23, 0, -108], [308, -80, 80, 0, 0, 0, 0, 0], [0, 0, 0, 168, 316, 0, 0, -148], [0, 0, 0, -6, -16, 0, 0, 10], [-48, 134, 48, 0, 0, 0, -10, 0], [0, 0, 0, 78, 62, 0, 0, 16], [30, -46, -30, 0, 0, 0, 44, 0], [-30, 30, 30, 0, 0, 0, -60, 0], [0, 0, 0, 56, 36, 0, 0, 20], [-50, 8, -8, 0, 0, 0, 0, 0], [-97, -120, 120, 0, 0, 0, 0, 0], [0, 0, 0, 117, 263, 0, 0, -146], [312, -80, 80, 0, 0, 0, 0, 0], [0, 0, 0, 169, 105, 0, 0, 64], [0, 0, 0, -38, 76, -72, 0, 38], [0, 0, 0, -18, 124, 0, 0, -142], [-115, -72, 72, 0, 0, 0, 0, 0], [-90, 178, 90, 0, 0, 0, -92, 0], [0, 0, 0, 88, -176, -65, 0, -88], [0, 0, 0, 37, 173, 0, 0, -136], [0, 0, 0, 12, -24, -197, 0, -12], [-90, 120, 90, 0, 0, 0, -150, 0], [-503, 10, -10, 0, 0, 0, 0, 0], [0, 0, 0, -160, 8, 0, 0, -168], [0, 0, 0, 8, -16, 70, 0, -8], [0, 0, 0, 112, -224, 34, 0, -112], [22, -46, -22, 0, 0, 0, 20, 0], [-80, 82, 80, 0, 0, 0, -158, 0], [-302, -60, 60, 0, 0, 0, 0, 0], [0, 0, 0, 50, -48, 0, 0, 98], [0, 0, 0, 136, 20, 0, 0, 116], [0, 0, 0, -18, 36, 134, 0, 18], [84, -227, -84, 0, 0, 0, 25, 0], [42, -90, 90, 0, 0, 0, 0, 0], [0, 0, 0, 8, -16, 14, 0, -8], [0, 0, 0, 12, -24, -40, 0, -12], [0, 0, 0, -81, 65, 0, 0, -146], [10, -79, -10, 0, 0, 0, -49, 0], [58, 10, -10, 0, 0, 0, 0, 0], [760, 92, -92, 0, 0, 0, 0, 0], [78, -4, -78, 0, 0, 0, 230, 0], [0, 0, 0, -78, -256, 0, 0, 178], [0, 0, 0, 38, -76, -32, 0, -38], [-26, 58, 26, 0, 0, 0, -20, 0], [0, 0, 0, 70, 98, 0, 0, -28], [50, -130, -50, 0, 0, 0, 20, 0], [0, 0, 0, 128, -256, -88, 0, -128], [-497, 40, -40, 0, 0, 0, 0, 0], [405, -38, 38, 0, 0, 0, 0, 0], [0, 0, 0, -98, 196, 36, 0, 98], [0, 0, 0, -182, -168, 0, 0, -14], [0, 0, 0, 72, -144, -198, 0, -72], [-130, 188, -188, 0, 0, 0, 0, 0], [-10, 34, 10, 0, 0, 0, 4, 0], [878, 60, -60, 0, 0, 0, 0, 0], [0, 0, 0, 152, 108, 0, 0, 44], [0, 0, 0, -187, -299, 0, 0, 112], [370, -118, 118, 0, 0, 0, 0, 0], [36, 52, -36, 0, 0, 0, 160, 0], [0, 0, 0, -92, 184, 106, 0, 92], [0, 0, 0, -8, 16, -77, 0, 8], [56, -63, -56, 0, 0, 0, 105, 0], [0, 0, 0, -278, -496, 0, 0, 218], [0, 0, 0, 8, -16, -300, 0, -8], [-642, -140, 140, 0, 0, 0, 0, 0], [0, 0, 0, 71, 135, 0, 0, -64], [0, 0, 0, -148, -292, 0, 0, 144], [0, 0, 0, -190, -272, 0, 0, 82], [-40, 36, 40, 0, 0, 0, -84, 0], [52, -146, -52, 0, 0, 0, 10, 0], [-250, 8, -8, 0, 0, 0, 0, 0], [0, 0, 0, -202, 404, 59, 0, 202], [1018, 50, -50, 0, 0, 0, 0, 0], [0, 0, 0, -134, -180, 0, 0, 46], [0, 0, 0, -168, 336, -71, 0, 168], [0, 0, 0, 176, 456, 0, 0, -280], [120, -303, -120, 0, 0, 0, 57, 0], [0, 0, 0, 142, -284, 35, 0, -142], [0, 0, 0, 184, -30, 0, 0, 214], [30, -64, -30, 0, 0, 0, 26, 0], [0, 0, 0, -92, 184, -52, 0, 92]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_3_f_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_900_3_f_d(:prec:=8)
    chi := MakeCharacter_900_f();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_900_3_f_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_900_3_f_d( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_f();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![2000, 0, -136, 0, 1]>,<29,R![-64, -20, 1]>],Snew);
    return Vf;
end function;