
// Make newform 900.6.a.b in Magma, downloaded from the LMFDB on 19 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_b();".
// 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_b();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-218], [480], [622], [186], [-1204], [-3186], [-5526], [9356], [-5618], [14394], [370], [16146], [-4374], [11748], [13202], [11542], [29532], [-33698], [31208], [-38466], [-119514], [-94658], [-101046], [143434], [-57054], [-3118], [-54534], [-24698], [-236640], [-22158], [-193204], [-448554], [-140860], [335878], [101650], [139242], [-265014], [142812], [109670], [-294948], [-1003034], [-823998], [-906712], [506384], [542050], [-1448574], [-478786], [374106], [-169416], [-353746], [-1255200], [-1128774], [-263082], [1187742], [431300], [-743114], [-1921926], [1630714], [71250], [1617622], [682788], [2704438], [2603466], [-661432], [-1717058], [131370], [3509510], [2219922], [-4397304], [2298238], [1735606], [-5391148], [3272814], [-603114], [749422], [-5313570], [999326], [-2037396], [-5114614], [3304044], [2016382], [6583208], [-4817826], [6203994], [-2843834], [1756050], [-7668566], [-1359030], [2027064], [-2464274], [-10384800], [6494156], [-10356522], [-5873046], [-2172954], [-1073606], [7090334], [-6697634], [11900850], [8756358], [1156770], [-7078072], [3134038], [11383266], [-15865518], [15099840], [-8087050], [710398], [-5964338], [14843226], [-18204220], [1094612], [-7440462], [10791514], [-9629982], [-10001862], [4010604], [12033818], [-2012306], [16240962], [4629102], [11679368], [-19954290], [-4883314], [13577784], [-6424106], [-9085562], [20245700], [-5448306], [-1140724], [-19015322], [-22355082], [-10070398], [-4059630], [17225566], [-21079302], [18787686], [-13245616], [7669254], [8827858], [-30692310], [32841362], [8421168], [-23512610], [-11305038], [10007756], [26142894], [1920406], [25659378], [20564314], [31686762], [-3969626], [13794468], [8081264], [-29995638], [20762038], [3476418], [1867002], [-38550054], [-16487522], [23697624], [-57758958], [-11010282], [37080716], [-4529354], [48133490], [-6583038], [-4208916], [-12850786], [10956708], [45775582], [-4843216], [25735158], [-33806392], [-62019174], [49981570], [-57294046], [-36813122], [-6114768], [-60224282], [-3492990], [-47645058], [-15832590], [-61872866], [62395354], [7384382], [-30693852], [-89087402], [33655566], [73865240], [-49430130], [6313026], [-28761894], [15705134], [-35986154], [43898850], [33435270], [12922794], [70917332], [73041958], [85545554], [-58516620], [-79055094], [30785312], [79407990], [-86447514], [-60088264], [18524326], [60799398], [102571594], [-16734174], [-10757712], [16411190], [-73660970], [55510062], [-12950358], [-130092318], [-1743094], [-14055328], [-111937938], [-4824614], [-53973486], [-16704742], [-22932030], [-30355200], [5993758], [52134744], [-28727906], [-14874532], [-118880332], [71188746], [68961802], [-101908710], [-59730778], [1733658], [-64663860], [-68964300], [90515886], [5006816], [-135815870], [-39846970], [-151296990], [-7855224], [178843030], [-92782968], [-53198644], [-91262058], [192271870], [185548782], [103308786], [-72508786], [171432906], [127705188], [74743862], [127968934], [167485338], [-153070490], [60420658], [2536818], [107223614], [-128246210], [127675818], [102656444], [125692074], [7725558], [-117575198], [-13605342], [-13358578], [-199472618], [177674566], [-118991056], [219223318], [-72036878], [-82664358], [190137350], [27723878], [7114128], [120953022], [90437516], [158414178], [152268662], [-64587506], [150290196], [-125381594], [84724050], [-254755120], [28155402], [-14636898], [-51225102], [-61863438], [-188093328], [-109011434], [8093022], [-330402532], [-178217502], [14058060], [8865094], [-129779090], [-302926566], [157058312], [259211718], [-294021568], [16373182], [141762954], [143006150], [-315577464], [295603342], [42640926], [79182450], [-345171810], [-232432262], [-288144390], [246439274], [-273022764], [-166745052], [109188646], [64319562], [292992008], [146681182], [8682510], [315231706], [19726530], [335429246], [-29781412], [157106290], [51621474], [-89589126], [307075970], [-129114822], [-124694920], [-72595698], [-71673136], [124515426], [-362300350], [-459132390], [-486978154], [67643782], [-195395378], [387794058], [-139860666], [292970180], [94565922], [424846308], [436932650], [-112331546], [-271366764], [-285073278], [-182511760], [313070614], [351804798], [-147807878], [57794126], [280406418], [354168408], [-94782648], [-533737422], [-134164674], [-419929466], [63721494], [130381794], [-48256044], [-422437250], [-161227946], [-222764430], [-289954694], [-284409610], [97035312], [118447028], [158531862], [-12828810], [-635090716], [37251070], [-176643612], [-184900572], [-87428306], [-112118886], [-261046178], [32265858], [50405778], [198567934], [-534368238], [-300081844], [-544487346], [334034132], [398855710], [-163260542], [-430464702], [-29366890], [92968218], [-526293804], [-425404250], [278776044], [-668089586], [-480629272], [-323678874], [298482752], [261335814], [-94337470], [87907290], [211464958], [153509682], [-250777290], [124806980], [510630070], [131144622], [252778018], [422614860], [397301614], [404242242], [485170278], [834528512], [638898574], [289677426], [491162784], [119215462], [72537570], [-551702706], [-374739570], [-45554738], [557171346], [247936500], [251075734], [635590122], [248498118], [-243159294], [-317263768], [-300899976]];
    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_b();".
// 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_b(:prec:=1)
    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_b();".
// 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_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_900_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<7,R![218, 1]>,<11,R![-480, 1]>],Snew);
    return Vf;
end function;