
// Make newform 90.10.a.g in Magma, downloaded from the LMFDB on 12 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_90_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_90_10_a_g();".
// 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_90_10_a_g();".
// 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_90_a();"
function MakeCharacter_90_a()
    N := 90;
    order := 1;
    char_gens := [11, 37];
    v := [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_90_a_Hecke(Kf)
    return MakeCharacter_90_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]];
    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 := 10;
    raw_aps := [[16], [0], [-625], [5432], [-73932], [-114514], [-41682], [1057460], [-1599336], [-2184510], [-9619648], [4799942], [-9531882], [-13464484], [-11441952], [-53615766], [-81862620], [-104691298], [140571092], [-97098792], [171848906], [-117380080], [-323637636], [894379110], [232678562], [-651287622], [-1711289224], [1315529988], [310670030], [2748497934], [2643228272], [2637243708], [-5165390922], [2767510700], [6041512650], [407205752], [180937982], [5880024596], [-1361971992], [14177810034], [-2664561300], [-4054459498], [10138453728], [-7576855294], [220768218], [-29929648120], [29253295892], [-51848186704], [-45627268212], [62149486790], [3721653654], [-3622213680], [-33655649038], [58810967748], [75207199998], [11631613224], [-28387127790], [147987437552], [-75885718858], [-172150741722], [-149932098484], [-9517454406], [90589991492], [281284978728], [-91124841094], [-103167160542], [251079713612], [-404966931118], [-420847766892], [-399382661890], [78880610334], [-139841955240], [508662124832], [-296760755434], [-453918315940], [-267567337296], [-334750227750], [-455573026258], [-218973464082], [-363048380710], [1143397373820], [658288381382], [127825241328], [-57678573454], [411418476920], [-117253956396], [-91567645890], [-1550291360758], [1618248291858], [904369989536], [1282546930908], [531423133920], [-1109159424808], [904143489108], [1011457964180], [-126416528136], [408225809250], [-2969579127882], [-401653005124], [-635088051778], [2743866104372], [1313576369778], [3110997094044], [1458894785670], [-3947098889668], [-527903672638], [-4569426093852], [-3191681953746], [-2726105896920], [116094268442], [-3819511168048], [-3740205423034], [-6244351750122], [4466335884620], [-3080033159848], [-7876838940162], [-2808327609484], [-2033649887352], [-5290555685166], [5067660475020], [-6058040539978], [5032181760866], [8612762246778], [337705726884], [174896268212], [5365769532258], [5454523610150], [6609528829680], [11265201110792], [-15501016553794], [8867024126660], [-10458638267256], [337332134672], [1618643342102], [3166757378118], [9411362126210], [3004211579034], [4787648419172], [8826568835778], [4758748012950], [13227012170732], [-19620396712662], [1443693209096], [6159678146868], [-7894822138210], [-13945529457480], [2068676705846], [-12774864046362], [24475144854140], [30498716265744], [-33230548648498], [-16521947419122], [-21906067187164], [-16319209237032], [-1981026007588], [1603755699408], [-28142812868200], [5394184376670], [-12505057932118], [-9230946987342], [-41341703100612], [-10571486308986], [-42812764872328], [-5229297241932], [-3564212404242], [-19228630768296], [-32879361244288], [16628034364742], [-8574101271310], [4331331303594], [36886443032100], [50560820271902], [31150496359128], [-28464820588534], [28559261634320], [-26652744990810], [-22755298276708], [46205727437178], [-29131751004424], [-10668271943410], [-28863890301328], [-23307606416772], [159034555046], [57187515431478], [-4760336643936], [-69477190719030], [22360404829502], [38310337233236], [8331239426090], [35903385102048], [-18777864569854], [-99708915986556], [12984900799892], [-27617637645822], [4668853910028], [-84610098532266], [128098136174642], [-67101280728994], [145333508148798], [-149514487922136], [-205475764590], [-123460658876368], [82562730766262], [32178216350690], [-159410305930380], [106965417123618], [45721087151360], [25528202595084], [148813097066550], [132981642200972], [44527191662162], [42689551185738], [106397882754536], [92417313718548], [-214577724346920], [-97135689878038], [102486567402272], [48377865827118], [180095029027128], [39830081423874], [-180867751012858], [-23496466291720], [214640501115390], [-233354813005024], [78067524433308], [-251271189453130], [216148553853414], [141626409527520], [-218598029540008], [2625084040788], [132795245149646], [-275408609572780], [-263286038830048], [-211674546013962], [-1368940735684], [-37126152990912], [177594292020050], [-124058076853686], [125215907350980], [-58514663584392], [-21596519224356], [304415325462332], [-187358463906664], [-97097514569170], [146462572726254], [359048270541480], [138655034567312], [-384978490899492], [285969351203660], [122561484253824], [-454211645664418], [-103854997326402], [195149671925448], [297135817984010], [-281506658687406], [-12763133181300], [31422960215222], [128691857540972], [194730364819578], [166983937759802], [544348085171216], [120710048000748], [33747051331430], [496440975770366], [8227535353758], [-78691163484220], [132366143772210], [-458063937836922], [-220311445152724], [-130485256898406], [631205802723182], [267264481792292], [-56837174222374], [364915136891360], [-235350158449678], [250101824466056], [730046662833588], [783962581322270], [-798454364792758], [-391130796878292], [22446766718544], [504584887658312], [213886270474008], [869954293033382], [-761847256468708], [-40592998498032], [-691459060187374], [-893475638103222], [-384277864346920], [-630231616775010], [680182095033138], [-713087358027972], [-2601204728826], [838436286845748], [-550289518072594], [-113879669113470], [5988177321152], [825946574328234], [686860494252900], [511520967526292], [787798438308746], [-1319944243607982], [533039143304720], [-1262232646753476], [499475867380892], [-59499243923038], [-1156634769303612], [-467161189628530], [328979012727240], [-990413925935194], [-43141118129376], [-1037938644734070], [-428905379038242], [1159188145893716], [18610830744168], [-1146802093586710], [1101590136374700], [131841329508768], [1650188345661506], [-259553037688530], [418281082706132], [1020429808991642], [-398549153841342], [-1467487349811664], [-219909893702826], [853545819980402], [940975652440100], [334697282900876], [-307213189554192], [1336348870978554], [-1078404429868018], [-1908320320217502], [-145247353999360], [-1082376815046516], [-619943244227188], [-1529451960092652], [2188860151210430], [1930073275830174], [1976000212970282], [-1447730350256608], [1635997673517206], [98979401788998], [-819544688906790], [-597974272497688], [-36999198222846], [-1177242189310020], [-718205261756218], [-2084103611425348], [-1578988211817552], [-783779510094102], [-468234803543548], [918848327840522], [-386268215173422], [-1704251843933344], [-1085263840138570], [-1847441246301786], [2631789905699040], [1172025501042708], [-2371741452191922], [-2528188633523976], [-350667437464858], [-2592157714008522], [-1482298834007232], [1823556263788740], [1891940444246132], [982790291176106], [1403453551541298], [400432606741016], [1084076550276122], [3195437788105308], [-2938517986818100], [-1599614996296896], [1646054025154410], [-1524211551564328], [-1414927660242658], [1283593998570060], [1183232196333888], [-2172753691985374], [-1465860937260210], [-4726490827432198], [-1784826362701662], [1593234442228854], [-2685502354352248], [-781188234279522], [2709724641955460], [3988944930899784], [2712108312273872], [2010292270280342], [914774595020396], [1299980082933648], [-2625345993117310], [-1290762921513126], [4921135399821780], [5084798554882532], [-3348314886398712], [-358483998503974], [856598503841120], [4970781844118550], [-2717560907575828], [-3743369681485782], [-3209525743335010], [-3606253264783746], [1711698193718912], [667763585014758], [-5651468067921030], [-3292271415825208], [3251052106616462], [4363832100644238], [3225011495479076], [-939996800541540], [5014017766961426], [-893566468831542], [5212879090862004], [-550723908992668], [-5668737592274518], [-5192161915636302], [-4980961474198080], [-2497913500337608], [-3830365618520082], [7592476470936984], [-3039890148231870], [-5344101447024058], [-4984933733360352], [-640723819594140], [-6665829824608054], [2918342611612818], [-3004022204872836], [-3472501285622490], [7640716346464412], [4310245584019080]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_90_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_90_10_a_g();".
// 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_90_10_a_g(:prec:=1)
    chi := MakeCharacter_90_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 10));
    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_90_10_a_g();".
// 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_90_10_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_90_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<7,R![-5432, 1]>,<11,R![73932, 1]>],Snew);
    return Vf;
end function;