
// Make newform 900.3.u.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_u();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_900_u_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_u_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_900_3_u_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 := [81, 0, 45, 0, 16, 0, 5, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [0, 45, 0, 16, 0, 32, 0, 1], [-51, 0, -32, 0, -16, 0, 1, 0], [-225, 0, -80, 0, -16, 0, -5, 0], [0, 165, 0, 40, 0, 8, 0, 1], [0, 13, 0, 0, 0, 0, 0, 1], [-27, 0, -7, 0, -5, 0, -1, 0], [0, -3, 0, 10, 0, 2, 0, 1]];
    Rf_basisdens := [1, 432, 48, 144, 72, 48, 9, 18];
    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_u();"
function MakeCharacter_900_u()
    N := 900;
    order := 6;
    char_gens := [451, 101, 577];
    v := [6, 5, 3];
    // 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_u_Hecke();"
function MakeCharacter_900_u_Hecke(Kf)
    N := 900;
    order := 6;
    char_gens := [451, 101, 577];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 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, 0, 0, 0, 0], [0, -1, 0, 0, 0, -1, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0], [0, -3, 0, 0, -3, -2, 0, -3], [-12, 0, -2, -5, 0, 0, -2, 0], [0, -1, 0, 0, 0, 0, 0, 3], [0, 9, 0, 0, 1, -7, 0, 2], [-2, 0, 0, 0, 0, 0, -3, 0], [0, -15, 0, 0, 2, -32, 0, 1], [21, 0, -7, 14, 0, 0, -7, 0], [-8, 0, 9, -8, 0, 0, 0, 0], [0, -10, 0, 0, 12, -10, 0, 0], [9, 0, -8, 7, 0, 0, 16, 0], [0, 0, 0, 0, 0, 23, 0, 0], [0, -27, 0, 0, 3, -12, 0, -3], [0, 0, 0, 0, -8, -16, 0, -16], [-9, 0, -8, 25, 0, 0, 16, 0], [9, 0, -9, -16, 0, 0, 9, 0], [0, 49, 0, 0, 0, 0, 0, -18], [-12, 0, -4, -28, 0, 0, 2, 0], [0, -17, 0, 0, 9, -17, 0, 0], [-15, 0, 15, 34, 0, 0, -15, 0], [0, 27, 0, 0, -3, 12, 0, 3], [48, 0, 16, 112, 0, 0, -8, 0], [0, -6, 0, 0, -6, -101, 0, -6], [147, 0, -1, 74, 0, 0, -1, 0], [0, 95, 0, 0, 0, 0, 0, -9], [0, 27, 0, 0, 11, -5, 0, 22], [-74, 0, 0, 0, 0, 0, 18, 0], [0, 81, 0, 0, 42, 120, 0, 21], [0, 56, 0, 0, 54, 56, 0, 0], [54, 0, -29, 4, 0, 0, 58, 0], [0, 132, 0, 0, 2, 67, 0, -2], [41, 0, 6, 41, 0, 0, 0, 0], [54, 0, -23, -8, 0, 0, 46, 0], [-27, 0, 27, 164, 0, 0, -27, 0], [0, -143, 0, 0, 0, 0, 0, -63], [0, -134, 0, 0, -12, -134, 0, 0], [0, 27, 0, 0, 42, 12, 0, 21], [0, 153, 0, 0, -21, 66, 0, 21], [-48, 0, -40, -136, 0, 0, 20, 0], [122, 0, 0, 0, 0, 0, 42, 0], [39, 0, -37, 38, 0, 0, -37, 0], [0, -49, 0, 0, 0, 0, 0, 0], [0, 72, 0, 0, 64, 56, 0, 128], [142, 0, 0, 0, 0, 0, 24, 0], [-266, 0, 51, -266, 0, 0, 0, 0], [0, 45, 0, 0, 45, -4, 0, 45], [0, -288, 0, 0, -18, -153, 0, 18], [-190, 0, 45, -190, 0, 0, 0, 0], [0, -117, 0, 0, 19, 155, 0, 38], [54, 0, 9, -72, 0, 0, -18, 0], [-96, 0, 96, -97, 0, 0, -96, 0], [138, 0, -122, 154, 0, 0, 61, 0], [0, 9, 0, 0, -24, 42, 0, -12], [0, -75, 0, 0, 23, -26, 0, -23], [-48, 0, -88, -184, 0, 0, 44, 0], [98, 0, 0, 0, 0, 0, 126, 0], [0, 63, 0, 0, 63, 328, 0, 63], [213, 0, 61, 76, 0, 0, 61, 0], [0, -361, 0, 0, 0, 0, 0, 9], [0, -51, 0, 0, 14, -116, 0, 7], [0, -151, 0, 0, -9, -151, 0, 0], [-144, 0, -47, 238, 0, 0, 94, 0], [0, 12, 0, 0, 12, 299, 0, 12], [0, -51, 0, 0, -5, -28, 0, 5], [123, 0, -123, 218, 0, 0, 123, 0], [0, -47, 0, 0, 0, 0, 0, -114], [0, 9, 0, 0, 168, -150, 0, 84], [-129, 0, 129, -56, 0, 0, -129, 0], [0, 480, 0, 0, 34, 257, 0, -34], [252, 0, 36, 540, 0, 0, -18, 0], [0, -99, 0, 0, -99, -146, 0, -99], [0, 143, 0, 0, 0, 0, 0, 3], [-194, 0, 0, 0, 0, 0, 93, 0], [0, -75, 0, 0, -170, 20, 0, -85], [-183, 0, 37, -110, 0, 0, 37, 0], [0, 146, 0, 0, -72, 146, 0, 0], [-9, 0, 10, -11, 0, 0, -20, 0], [-211, 0, 114, -211, 0, 0, 0, 0], [18, 0, 69, -156, 0, 0, -138, 0], [-177, 0, 177, 38, 0, 0, -177, 0], [-444, 0, 44, -844, 0, 0, -22, 0], [0, 7, 0, 0, 81, 7, 0, 0], [171, 0, -171, 76, 0, 0, 171, 0], [0, 486, 0, 0, 24, 255, 0, -24], [54, 0, -174, -66, 0, 0, 87, 0], [0, -18, 0, 0, -18, -113, 0, -18], [285, 0, -11, 148, 0, 0, -11, 0], [0, 431, 0, 0, 0, 0, 0, 57], [0, 135, 0, 0, -25, -185, 0, -50], [-63, 0, -99, 18, 0, 0, -99, 0], [0, -82, 0, 0, 204, -82, 0, 0], [-117, 0, -10, 137, 0, 0, 20, 0], [161, 0, -162, 161, 0, 0, 0, 0], [0, -72, 0, 0, 24, 120, 0, 48], [-342, 0, 5, 332, 0, 0, -10, 0], [-30, 0, 86, 26, 0, 0, -43, 0], [0, -566, 0, 0, 36, -566, 0, 0], [266, 0, 0, 0, 0, 0, 168, 0], [0, 108, 0, 0, 108, -155, 0, 108], [0, -126, 0, 0, -86, -46, 0, -172], [0, -585, 0, 0, -24, -1146, 0, -12], [438, 0, 136, 151, 0, 0, 136, 0], [67, 0, -258, 67, 0, 0, 0, 0], [0, -127, 0, 0, -9, -127, 0, 0], [0, -276, 0, 0, 154, -61, 0, -154], [0, -396, 0, 0, -28, 340, 0, -56], [108, 0, 67, -242, 0, 0, -134, 0], [198, 0, -198, -283, 0, 0, 198, 0], [0, 529, 0, 0, 0, 0, 0, -87], [0, 226, 0, 0, 108, 226, 0, 0], [0, -411, 0, 0, 20, -842, 0, 10], [90, 0, -90, 547, 0, 0, 90, 0], [482, 0, 0, 0, 0, 0, -156, 0], [96, 0, 130, -17, 0, 0, 130, 0], [0, -577, 0, 0, 0, 0, 0, 0], [0, 198, 0, 0, -90, -378, 0, -180], [0, -339, 0, 0, 158, -836, 0, 79], [-201, 0, -185, -8, 0, 0, -185, 0], [-1058, 0, -45, -1058, 0, 0, 0, 0], [0, -237, 0, 0, -237, 218, 0, -237], [0, 1029, 0, 0, 19, 524, 0, -19], [0, -153, 0, 0, -57, 39, 0, -114], [-81, 0, 81, -706, 0, 0, -81, 0], [-312, 0, 160, -464, 0, 0, -80, 0], [75, 0, -75, 52, 0, 0, 75, 0], [-252, 0, 396, -108, 0, 0, -198, 0], [0, 135, 0, 0, 135, -536, 0, 135], [0, -433, 0, 0, 0, 0, 0, -315], [-578, 0, 0, 0, 0, 0, -9, 0], [0, 189, 0, 0, 174, 204, 0, 87], [202, 0, -105, 202, 0, 0, 0, 0], [0, -694, 0, 0, 144, -694, 0, 0], [-738, 0, 27, 684, 0, 0, -54, 0], [662, 0, 129, 662, 0, 0, 0, 0], [0, -468, 0, 0, -156, 156, 0, -312], [0, -455, 0, 0, 0, 0, 0, 207], [0, -405, 0, 0, -150, -660, 0, -75], [534, 0, 34, 1102, 0, 0, -17, 0], [-142, 0, 0, 0, 0, 0, 243, 0], [687, 0, -61, 374, 0, 0, -61, 0], [0, 287, 0, 0, 0, 0, 0, 21], [0, -468, 0, 0, -92, 284, 0, -184], [-506, 0, 0, 0, 0, 0, -120, 0], [-477, 0, -69, -204, 0, 0, -69, 0], [0, 9, 0, 0, 9, -1168, 0, 9], [0, 549, 0, 0, -45, 252, 0, 45], [-517, 0, -12, -517, 0, 0, 0, 0], [0, -126, 0, 0, 50, 226, 0, 100], [0, -767, 0, 0, 0, 0, 0, -15], [-600, 0, 136, -1064, 0, 0, -68, 0], [0, 397, 0, 0, -177, 397, 0, 0], [0, 363, 0, 0, -22, 748, 0, -11], [0, -204, 0, 0, -204, 61, 0, -204], [81, 0, -15, 48, 0, 0, -15, 0], [1294, 0, 0, 0, 0, 0, 126, 0], [459, 0, 99, 180, 0, 0, 99, 0], [0, -730, 0, 0, -348, -730, 0, 0], [18, 0, 47, -112, 0, 0, -94, 0], [0, -396, 0, 0, -126, -261, 0, 126], [0, 315, 0, 0, 243, 171, 0, 486], [0, 481, 0, 0, 0, 0, 0, 387], [-432, 0, 648, -216, 0, 0, -324, 0], [0, -3, 0, 0, -308, 302, 0, -154], [0, 1221, 0, 0, -25, 598, 0, 25], [98, 0, 0, 0, 0, 0, -450, 0], [0, -45, 0, 0, -45, -932, 0, -45]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_u_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_3_u_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_900_3_u_a(:prec:=8)
    chi := MakeCharacter_900_u();
    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_u_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_900_3_u_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_u();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![29986576, 0, -815924, 0, 16725, 0, -149, 0, 1]>],Snew);
    return Vf;
end function;