
// Make newform 2.30.a.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_2_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_2_30_a_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_2_30_a_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_2_a();"
function MakeCharacter_2_a()
    N := 2;
    order := 1;
    char_gens := [];
    v := [];
    // 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_2_a_Hecke(Kf)
    return MakeCharacter_2_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 := 30;
    raw_aps := [[-16384], [-2792556], [6651856470], [1432518476648], [-777022624156548], [-27095750590848706], [623720384075229138], [23397560477447780], [-101961500467007428296], [-193842816899629681650], [-4411693069206519719008], [68464702455096345074678], [-130597382880843284243958], [-655176150269911693888996], [1883486986380896623798128], [6529902016158550020796614], [44894091442793669254526700], [35309137728183249168305582], [-383658355413958878684363052], [728985379862346402417775272], [724286660588086686263964074], [-2013411690690004127061099760], [-7236735323128970857830291036], [13578154221906201595278362490], [22518383238623495861116621538], [222680543962903953337980688182], [-293840931572717652560976629176], [-180718466946205048102718775972], [-159004003980255016627299658210], [649105337269045412174627857074], [-3491899928708247093618687029632], [5199728614683824477250292460052], [-14262746545718278539363739877142], [88595992385394450446936918780], [16626551650755555028034572515750], [38735152085518808786066495104952], [-34232788464592876758965936121202], [122832875981471178232945670599604], [-108585391030864906875526426271352], [-8135036583935117018478824584866], [-391204796938073070496893331394940], [126477080482293803470100495279942], [-230536159406429490011259712285248], [-430456361548926561614125511596606], [220726620563880216822810252302358], [-1284862534585591883689580738481880], [942939512793552849140853648429092], [7898005926389012411508406355956064], [18965471275209383144340636267083508], [18066850877170124838433161978310070], [-26386119977320911159875349942147126], [-16095478209829574296485371898901200], [-50221331300087703469534598201038], [-58721604515599699580955118782699348], [13234905437586712287457280840310018], [-227613128425138190060751569425694616], [85544203047825446778305971723161150], [112404702213039231894941483321442512], [-297851173116252872714693057300582362], [-36308018789270814811809546899950278], [-566564534561078081279138547409183156], [55696544689589510060488669831784694], [286613338356953493892079920411727108], [-1261790229943793686186275676284482088], [-1737141430066628491163282216324066086], [-1707378280198579844671060406331557202], [44948281028490278370535323168697532], [2906106192955281713681834674022067218], [6847289547081546906034157239712643468], [8637817483492479040033801711829722190], [-6181556575879993643261049923286368286], [-634727759824920646542541583860699320], [-12694241364759837559960267824195372112], [-14414906511941640585673465471679510266], [42631023973464175874138803774938406700], [-6287922165060809177524496288417256576], [-35158204084872660806889997833428694570], [-67214957647783163503004052037110582082], [17415969051347742208594291411717763922], [24859555656083487783189772053404697530], [-56520724260086881850744541737457745740], [135712380030514913248235666657218027382], [-125589519943622856874756187817298349328], [260317126685902367751210195677167314674], [-254017563558782116775363585415801648040], [242259142250895126792172622015422143084], [-491991727460610696504972152319516982590], [207288315877678878825767549461190057258], [362984315700276111130700449929587615742], [135938863474078992213292896224976012944], [571728782930319460298990021213738310948], [-660236019200021794166652264264952828320], [-240330855754693092995314920587109986872], [1562271206401059215134489834624953639132], [-1405870983964246386740381438772660056380], [1475023397234583032602098565833236876184], [711334049246677064280218834696841487470], [-3514839652262992439656621091202914304918], [129306954205282483288782746511735262844], [-2955101612880500903435973188420382822898], [564186587786105582828954401793324336948], [2407899905453056360626365177243052604638], [-8338037711618169540308804211250330263036], [-7787956380715771504693691578444897725990], [-10738364502744986925705610752925100027668], [-19846769022299700439237745912426397015742], [-5815332117761947281323416408597200070212], [2080553122178551165234175859556421519634], [21928219734351107129228438715000326914680], [11643842198003457420038032854642502467962], [9019481986536325220058768647897842105568], [7074867441302995892281292217377359089974], [2474704935830217920356278498537999426378], [-55573492589163414321239224087069950396580], [6801349929444655585812609771732615776792], [55050810361168248981785705876398009874562], [41327183122197652133615764018811836253204], [-71294861308909186156837893601087509685272], [25563813005691022424974175922322223546814], [23145020549315715178738923254405702579940], [-47344789404929288993654462300167499803738], [115677284389935886230549594748023435596834], [-115938026660819897476980051086712025830282], [227985665364932076725725337710087947084444], [-128262515551683116126459714426657956280188], [262615436326854245036860381558463883439662], [-198211859843867985809442282926630939274730], [-490474444354285096378506001330495310240880], [-424028904973034027458542915736596803419912], [292123346352477275322796211136995028957134], [481596003755499033182015811639562454143220], [-586417221884876209464504384858155027641656], [183132907962180223476890893161885975152432], [608700392346416997538735357736678405827718], [150857997953622101182314986380881362018202], [727607386419401374780028336030371058550530], [-392968051926975154750027978774277196714666], [852629345997097321176854735228075419671908], [-995076549694364724760164719199235423913202], [725597769859173109653931639470355218632970], [-573900815192824822112199384749772887672548], [2738412009155922736706935662931166480988102], [-581100006802560975306091971450813082269736], [-347953004630629240331693863497471372247572], [541232736722358204960294487267638551377070], [-631677666366076307716271306853121364506200], [-3805321073480662769532054050221262723492506], [5433163848314132521213225518864054131846778], [-1230390995122019151830770968854140534959220], [1949696326828590843759789931096130941508064], [2909460924932369386075278981814977045363998], [7454815750640093593143557234575137833433522], [-6983145660380489407984899648215501124386236], [-3035000264273020423828011937741233727846632], [11700177354929378360227332233837950920479228], [1405678990863612165105979580341517203040592], [9410150479926266843294830177874063880019640], [-14805142023814078401471305531289876145295070], [1188568221164481395189745740443866380967818], [4569575776046272471557733829968803700133982], [3711156716578709752365795956798700378445188], [18429447893889167035000259427372775234547034], [-28448520646628443637161015533169469533018072], [21799192873576463891634536524839255153007932], [-22472575661160743898653737074567263989726062], [-37119335902900089990286802105072784334586376], [3414725139517665296012739561513101866428512], [10326453505134345028681146056134608050574518]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2_30_a_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_2_30_a_a(:prec:=1)
    chi := MakeCharacter_2_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 30));
    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_2_30_a_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_2_30_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,30,sign)));
    Vf := Kernel([<3,R![2792556, 1]>],Snew);
    return Vf;
end function;