
// Make newform 900.3.c.t in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_900_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_900_3_c_t();".
// 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_c_t();".
// 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, -12, 55, -84, 50, 0, -7, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [-9803, 9875, 9940, -7188, -746, 958, 137, -71], [-5259, 30415, -47500, 24796, 1262, -3526, -229, 457], [-6231, 36305, -62820, 38344, 118, -5354, -41, 743], [-2372, 19070, -34050, 23728, -914, -3308, 143, 486], [4981, -37780, 57390, -32124, -538, 4474, 56, -638], [-5467, 59265, -123760, 89368, -4154, -12598, 553, 1811], [5849, -49845, 93290, -63856, 2018, 8976, -256, -1277]];
    Rf_basisdens := [1, 1030, 1030, 1030, 515, 515, 1030, 515];
    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_c();"
function MakeCharacter_900_c()
    N := 900;
    order := 2;
    char_gens := [451, 101, 577];
    v := [1, 2, 2];
    // 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_c_Hecke();"
function MakeCharacter_900_c_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, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, -1, 1, 1, 0, 1], [1, 1, 0, -2, 1, 0, 3, 2], [-2, 1, 1, 3, -1, 1, 1, 1], [-2, 2, 3, 0, -2, -1, -3, 0], [-1, -1, 6, 0, -4, -2, 1, 0], [1, 1, 0, 0, 5, -4, 5, 0], [6, -2, 5, -6, 2, 5, 5, -2], [-4, -4, 11, 1, -7, 3, -8, -1], [24, -2, 8, -6, 2, 8, 8, -2], [4, -2, -13, 0, 2, -9, -7, 0], [-3, -3, 4, 6, 8, -4, -5, -6], [2, 2, -2, 2, -12, -10, 10, -2], [-38, 0, 13, -12, 0, 5, 1, -4], [-4, -4, 16, 0, -2, 0, -4, 0], [24, -7, -17, 3, 7, -1, 7, 1], [-1, -1, -12, 2, -14, 12, -15, -2], [-5, -5, 18, 2, 1, -2, -5, -2], [-20, -10, -4, -18, 10, 4, 8, -6], [2, 2, 6, -2, -6, -10, 14, 2], [-4, -4, 4, 16, -18, -20, 0, -16], [-16, 0, 16, -12, 0, 8, 4, -4], [-35, 8, 28, 0, -8, 12, 4, 0], [-18, 4, -27, 36, -4, -11, -3, 12], [0, 0, 34, -14, -8, -6, 20, 14], [7, 7, -28, -2, 33, 4, 5, 2], [-58, -7, -17, 3, 7, -1, 7, 1], [16, -4, 16, -24, 4, 8, 4, -8], [10, 10, -48, 8, 18, -8, 10, -8], [-7, -7, 32, -6, -33, 8, -9, 6], [86, 8, 26, 12, -8, 18, 14, 4], [-8, -8, 14, 10, 60, -2, -16, -10], [-44, 2, -16, 18, -2, -8, -4, 6], [-12, -12, 51, 13, -45, -29, 4, -13], [16, 17, -5, 27, -17, -21, -29, 9], [-17, -17, 52, 18, 20, -20, -15, -18], [-1, -1, -26, 6, -47, 18, -25, -6], [-34, -2, -25, 30, 2, -1, 11, 10], [6, 6, 0, -16, -4, 8, 14, 16], [-28, 3, -25, 9, -3, -25, -25, 3], [-1, -1, -4, 8, 151, -8, -1, -8], [49, 10, -36, 42, -10, -28, -24, 14], [-32, 10, 12, 42, -10, 20, 24, 14], [-10, -10, 11, 13, -23, 3, -26, -13], [-17, -17, 58, 12, 64, -14, -15, -12], [-8, -8, 45, -5, -47, -3, 0, 5], [-19, -19, 60, -10, 47, 36, -45, 10], [-10, 5, 27, -9, -5, 11, 3, -3], [204, -18, -69, 12, 18, -25, -3, 4], [-5, -5, 54, -6, 53, -22, 23, 6], [-129, -2, 22, -30, 2, 6, -2, -10], [-6, -6, 68, -20, -150, -4, 18, 20], [92, -28, -42, -36, 28, -10, 6, -12], [9, 9, -50, -10, 147, 34, -15, 10], [90, 6, -3, -6, -6, -19, -27, -2], [-4, -4, 34, 2, -136, -22, 16, -2], [4, -5, 59, -63, 5, 27, 11, -21], [-210, 14, 11, 60, -14, 23, 29, 20], [11, 11, -26, -24, 92, 30, 5, 24], [-120, -2, -62, 30, 2, -38, -26, 10], [-25, -25, 62, 8, -180, 22, -55, -8], [-8, -8, 22, 26, 66, -42, 8, -26], [7, -4, -10, 0, 4, -2, 2, 0], [16, -4, -14, -24, 4, -22, -26, -8], [10, 10, 4, -16, 218, -12, 38, 16], [303, -18, -100, 54, 18, -28, 8, 18], [20, 20, 12, -32, 90, -28, 80, 32], [6, -8, -60, -24, 8, -60, -60, -8], [10, 42, -37, 132, -42, -33, -31, 44], [-1, -1, -82, 14, -75, 58, -73, -14], [-44, -44, 81, 59, 67, -23, -80, -59], [88, -3, -27, 15, 3, -11, -3, 5], [15, 15, -12, -14, 126, -20, 49, 14], [-2, -2, -28, 8, 30, 20, -30, -8], [-314, -4, 3, 12, 4, 19, 27, 4], [-108, 1, 21, 27, -1, 37, 45, 9], [-204, 30, 41, -12, -30, -27, -61, -4], [-155, 12, 70, -24, -12, 30, 10, -8], [-23, -23, 84, 14, 15, -20, -17, -14], [-76, 6, 140, -102, -6, 60, 20, -34], [17, 17, -16, -60, 165, 68, 9, 60], [329, 22, 88, 6, -22, 48, 28, 2], [-2, -2, -95, 39, 23, 25, -66, -39], [42, 42, -112, -28, 54, 0, 70, 28], [268, 20, 122, -24, -20, 66, 38, -8], [12, -10, 110, -78, 10, 78, 62, -26], [38, 8, -105, 84, -8, -65, -45, 28], [-36, -36, 26, 34, -168, 50, -120, -34], [21, 21, -128, 38, 237, -32, 15, -38], [2, 2, -10, -2, 312, 6, -2, 2], [12, 12, 35, -35, 327, -13, 60, 35], [28, 28, -20, -64, -172, 36, 56, 64], [47, 47, -164, 42, -16, -108, 113, -42], [-19, -19, 74, 46, 103, -90, 25, -46], [-252, -50, -104, -42, 50, -32, 4, -14], [-282, -26, 47, -72, 26, 51, 53, -24], [21, 21, 34, -64, -26, 10, 75, 64], [16, 35, 71, 33, -35, 23, -1, 11], [0, 0, -46, 86, -96, -126, 40, -86], [-96, -22, 30, -42, 22, 46, 54, -14], [55, 55, -168, -22, -177, -8, 85, 22], [314, 42, 27, 72, -42, -9, -27, 24], [33, 33, -172, -10, 114, 60, -17, 10], [171, -36, -28, -108, 36, -28, -28, -36], [-45, -45, 20, 90, -131, -20, -115, -90], [192, -58, 49, -144, 58, 69, 79, -48], [-14, -14, 140, -36, -14, -12, 34, 36], [-21, 52, 178, 0, -52, 74, 22, 0], [-42, -42, 126, 14, -138, 14, -70, -14], [-124, 54, 190, -102, -54, 14, -74, -34], [-68, -34, -51, 48, 34, 49, 99, 16], [-17, -17, -50, 16, 208, 86, -119, -16], [50, 50, -129, -3, -93, -65, 118, 3], [-96, 8, -26, 36, -8, -18, -14, 12], [24, 24, -274, 74, 116, 30, -80, -74], [40, 40, -128, -72, -108, 112, 0, 72], [-432, 58, 218, 18, -58, 114, 62, 6], [17, 17, -84, 62, 19, -108, 63, -62], [232, 50, -126, 222, -50, -78, -54, 74], [420, -30, 144, -222, 30, 56, 12, -74], [138, -58, 39, -138, 58, 63, 75, -46], [-68, -68, 280, -20, 84, 32, -80, 20], [46, 46, -120, -4, 26, -56, 106, 4], [278, 90, 189, 42, -90, 37, -39, 14], [274, -83, -141, -57, 83, -13, 51, -19], [69, 69, -248, -68, 153, 108, 29, 68], [12, 12, 197, -77, 141, -91, 180, 77], [-622, -24, -116, 24, 24, -52, -20, 8], [-28, -28, 92, -12, -264, 44, -60, 12], [44, 44, -292, 72, 192, -28, 0, -72], [22, 22, 12, -132, 46, 164, -10, 132], [164, 55, 145, -51, -55, 1, -71, -17], [-452, 40, -80, 120, -40, -80, -80, 40], [347, -44, 170, -192, 44, 130, 110, -64], [-690, 28, -53, 108, -28, -37, -29, 36], [-13, -13, 60, -70, -212, 132, -75, 70], [-136, -8, -122, 96, 8, -42, -2, 32], [740, 42, 55, 36, -42, -5, -35, 12], [29, 29, 18, -104, 130, 74, 59, 104], [364, -30, 182, -174, 30, 126, 98, -58], [46, 46, 79, -139, -89, 15, 170, 139], [3, 3, -92, 42, -371, -4, -35, -42], [-232, 66, 70, 78, -66, -10, -50, 26], [-35, -35, 220, 44, -355, -168, 89, -44], [-246, -33, -147, 141, 33, 13, 93, 47], [264, -72, -114, -120, 72, -50, -18, -40], [-42, -42, -12, 88, 114, 4, -134, -88], [30, 30, 100, -120, 66, 20, 130, 120], [330, -61, -199, 9, 61, -71, -7, 3], [144, -36, -58, 48, 36, 46, 98, 16], [-77, -77, 226, 44, 150, -6, -115, -44], [-70, -70, 226, 34, -80, -14, -90, -34], [-44, -44, 64, 96, 16, -80, -60, -96], [18, 18, 174, -122, -64, -2, 142, 122], [28, 28, 45, -81, 483, 5, 104, 81], [406, -62, -55, 24, 62, 85, 155, 8], [-105, -48, 6, -12, 48, 94, 138, -4], [-216, -58, -86, -42, 58, 2, 46, -14], [-31, -31, -100, 130, 5, -36, -125, -130], [600, -64, -420, 168, 64, -180, -60, 56], [14, 14, -178, -2, 406, 126, -110, 2], [78, 78, -228, 12, 272, -108, 174, -12], [622, 12, -222, 204, -12, -110, -54, 68], [20, 20, 132, -112, -72, 12, 120, 112], [-134, -134, 291, 121, -97, 3, -258, -121], [262, 16, 244, -72, -16, 164, 124, -24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_3_c_t();".
// 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_c_t(:prec:=8)
    chi := MakeCharacter_900_c();
    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_c_t();".
// 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_c_t( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![961, 0, 9532, 0, 6470, 0, 188, 0, 1]>,<13,R![-1559, -3916, -418, 4, 1]>,<17,R![132400, 1920, -832, 0, 1]>],Snew);
    return Vf;
end function;