
// Make newform 900.6.a.v in Magma, downloaded from the LMFDB on 30 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_900_a();"
// 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_6_a_v();".
// 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_6_a_v();".
// 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 := [-94, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 60]];
    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_900_a();"
function MakeCharacter_900_a()
    N := 900;
    order := 1;
    char_gens := [451, 101, 577];
    v := [1, 1, 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;

function MakeCharacter_900_a_Hecke(Kf)
    return MakeCharacter_900_a();
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], [0, 0], [0, 0], [71, 0], [0, -1], [137, 0], [0, 1], [-1087, 0], [0, 7], [0, 7], [-2269, 0], [-6010, 0], [0, -3], [4283, 0], [0, 2], [0, -43], [0, -50], [12719, 0], [6899, 0], [0, 69], [-24010, 0], [12236, 0], [0, 46], [0, 96], [-19651, 0], [0, -235], [-152380, 0], [0, 307], [3137, 0], [0, 160], [3620, 0], [0, 157], [0, -462], [-311536, 0], [0, -258], [123221, 0], [-387061, 0], [-508327, 0], [0, -107], [0, -823], [0, -476], [317261, 0], [0, -743], [-775273, 0], [0, 1154], [-752503, 0], [543989, 0], [-1163713, 0], [0, -1683], [-559927, 0], [0, 2589], [0, 1205], [1729409, 0], [0, -394], [0, 1738], [0, -1381], [0, -3265], [1012052, 0], [-1651279, 0], [0, -283], [-1884223, 0], [0, -3576], [-424891, 0], [0, 2212], [-2260957, 0], [0, -2950], [3395552, 0], [-372979, 0], [0, 1518], [-2717986, 0], [0, 4113], [0, 65], [-1965319, 0], [-1234477, 0], [-2367997, 0], [0, 5542], [0, 3067], [-2025169, 0], [0, -9501], [1592153, 0], [0, -4643], [-92902, 0], [0, 2463], [-3070453, 0], [1699787, 0], [0, 118], [0, 10838], [67190, 0], [0, 14187], [1086020, 0], [0, -2853], [0, -12254], [7395989, 0], [0, 6944], [427757, 0], [0, -9089], [0, -8298], [0, -16011], [7286093, 0], [-7435651, 0], [2894360, 0], [0, -4764], [0, 8933], [0, -10207], [-3732631, 0], [-7317541, 0], [0, 10947], [0, 21443], [0, 29466], [-8664049, 0], [10734020, 0], [16640390, 0], [0, 11031], [-1046023, 0], [-4214041, 0], [0, 15306], [13699160, 0], [0, -25172], [0, -13256], [0, -5027], [-8160202, 0], [10634450, 0], [0, 21121], [0, -30476], [-11062552, 0], [0, -8989], [14627093, 0], [0, -41049], [11630999, 0], [17799650, 0], [10327664, 0], [0, 3468], [2266748, 0], [-15536899, 0], [0, 43924], [26395247, 0], [0, 31375], [33520361, 0], [0, 7046], [0, 23241], [19965701, 0], [0, -62404], [35799383, 0], [0, 49331], [5025314, 0], [0, 35331], [-22444153, 0], [0, -53962], [-22876264, 0], [0, 9658], [-27197989, 0], [0, 7338], [18101063, 0], [0, 54370], [2915960, 0], [0, 39798], [-5635747, 0], [0, -33677], [-24195469, 0], [0, -3236], [0, -61765], [0, -36332], [25926020, 0], [0, 91960], [0, -70866], [0, -43532], [39679739, 0], [-50365210, 0], [-6400603, 0], [0, 14986], [0, 16945], [13244099, 0], [0, -34504], [-39281563, 0], [-51811567, 0], [0, -30806], [49210961, 0], [0, -49367], [-22157293, 0], [33381107, 0], [18807251, 0], [0, -70112], [-67144747, 0], [0, 121480], [0, 74770], [0, 75364], [-44546131, 0], [-34114603, 0], [-6702067, 0], [0, -4057], [-64987783, 0], [0, 57673], [40594451, 0], [0, 70509], [0, -141183], [0, -80668], [27348002, 0], [-63118750, 0], [0, 63586], [0, -109195], [0, 3505], [24464948, 0], [11972330, 0], [-4744786, 0], [0, -68640], [0, -66029], [-50717923, 0], [0, -112417], [0, -179862], [77922611, 0], [-103981561, 0], [0, 156536], [10088363, 0], [0, 186132], [0, 179042], [-10932502, 0], [70156091, 0], [0, -80921], [0, -164363], [0, 69171], [72739889, 0], [-40295407, 0], [0, 132776], [4546820, 0], [0, 29943], [113345747, 0], [0, 237969], [0, -33744], [-22973791, 0], [0, 131617], [-1870243, 0], [42965336, 0], [-21883291, 0], [0, -251768], [9367160, 0], [0, 224800], [18604286, 0], [0, -188895], [0, -217326], [0, -167429], [0, -26209], [41823071, 0], [142516373, 0], [58271687, 0], [0, -54748], [0, -229998], [120980009, 0], [0, 179645], [-76303513, 0], [0, -9730], [158062850, 0], [0, 249329], [0, -215110], [172417277, 0], [0, -331937], [0, 251308], [-87289759, 0], [-120763120, 0], [0, -137957], [-68205670, 0], [87969983, 0], [0, -47361], [63101114, 0], [108380543, 0], [0, 12304], [37247936, 0], [0, -143306], [0, 41706], [195779960, 0], [0, -100554], [8607071, 0], [-8375920, 0], [150979190, 0], [-1635637, 0], [215324369, 0], [166131467, 0], [0, 45790], [62236103, 0], [-109240801, 0], [0, -348010], [0, 2203], [94525748, 0], [0, -317431], [-133191169, 0], [99189941, 0], [0, 236494], [28499153, 0], [0, 233417], [251241836, 0], [0, -174019], [0, 210606], [0, -127082], [0, 257846], [0, 271426], [-45111193, 0], [0, -326303], [-281134201, 0], [0, -161307], [0, -438771], [-233272840, 0], [53527130, 0], [0, 67808], [296912723, 0], [0, -499656], [289983752, 0], [-40418599, 0], [0, -176394], [-120546643, 0], [0, -82911], [70798790, 0], [0, -163303], [0, -390790], [0, -281728], [-226683793, 0], [0, -53367], [-136602427, 0], [0, 143417], [0, 348512], [46742333, 0], [0, 436319], [-146911648, 0], [320285819, 0], [0, 308097], [141190067, 0], [0, -193926], [286911902, 0], [-232572583, 0], [-356125147, 0], [0, 112933], [0, 310673], [-187104679, 0], [0, 210996], [21086303, 0], [0, 275343], [69702209, 0], [0, 594996], [-29854477, 0], [0, -237501], [357119921, 0], [-380854780, 0], [-104200933, 0], [0, -138957], [0, 293031], [-70401871, 0], [0, 86027], [0, 277936], [196738469, 0], [-507358999, 0], [0, -177457], [0, -704294], [153719921, 0], [79161590, 0], [0, -140635], [-415329883, 0], [-544516177, 0], [0, -893282], [0, 95903], [0, 720463], [0, -526117], [0, -603705], [-176326609, 0], [0, 514278], [0, 468747], [0, -641578], [-328646320, 0], [-481342537, 0], [0, -216468], [76328300, 0], [326591591, 0], [0, 614932], [-86502757, 0], [0, -367261], [0, 806446], [105133148, 0], [-109142971, 0], [0, -618865], [0, -663298], [-421437577, 0], [0, 437512], [-418765579, 0], [0, -944974], [0, -121933], [-179530900, 0], [0, 1241101], [-262146664, 0], [0, 474076], [-710721421, 0], [486581930, 0], [-382502320, 0], [0, -375249], [-58490023, 0], [0, 167869], [0, 1051921], [-697370521, 0], [0, 700734], [279608153, 0], [362592767, 0], [0, -382083], [607771019, 0], [0, 636070], [-720675586, 0], [0, -28117], [323090189, 0], [0, -947027], [0, -219593], [-279336148, 0], [178570121, 0], [0, 935569], [-270757183, 0], [0, -139266], [261236003, 0], [0, 1119884], [0, -1108486], [73161929, 0], [535662569, 0], [0, -155704], [0, -849622], [-802685299, 0], [0, -448361], [0, -1253989], [0, -600794], [376055159, 0], [0, -706686], [0, 1040476], [47095130, 0], [0, 923481], [0, -543573], [0, -745231], [-170786629, 0], [0, 332581]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_900_6_a_v();".
// 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_6_a_v(:prec:=2)
    chi := MakeCharacter_900_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_6_a_v();".
// 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_6_a_v( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![-71, 1]>,<11,R![-338400, 0, 1]>],Snew);
    return Vf;
end function;