
// Make newform 80.10.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_80_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_80_10_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_80_10_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_80_a();"
function MakeCharacter_80_a()
    N := 80;
    order := 1;
    char_gens := [31, 21, 17];
    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_80_a_Hecke(Kf)
    return MakeCharacter_80_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 := 10;
    raw_aps := [[0], [-46], [-625], [10318], [5568], [45986], [-381318], [-610460], [1447914], [5385510], [-3053852], [12889442], [-33786618], [36886234], [44163798], [29746266], [65575380], [40183202], [115706158], [231681708], [358691906], [486017080], [-251168886], [-526039110], [-1075981438], [-663828378], [-586834526], [-858642762], [2410026530], [-785948934], [1330206478], [-3168537792], [4334483922], [7742227300], [3713669850], [-5806523252], [-4941926518], [180144154], [-4516162242], [-2346402534], [10623734700], [8916076502], [995469228], [25185319706], [-2257736718], [4309192120], [34083206608], [-18478303046], [14745826038], [61912423790], [29309468346], [-7515616680], [15433088462], [8530765248], [-22675972998], [-54665486526], [-49176085710], [-147502984052], [-135893028358], [-112159910778], [48392191234], [196104291906], [-5055420242], [188661510228], [-92807979094], [-190705097958], [-124343359112], [-333152181118], [-161682966642], [220718745110], [-79845572334], [25360478760], [295956466918], [329079587066], [729572154940], [-54693113046], [-837797667750], [-126116657758], [-165707349918], [232260877790], [-782753298180], [217217333882], [567021528828], [50262668546], [861416657080], [-38225630646], [-1608039383610], [-506545070758], [190358558142], [501409903714], [-1909576561842], [-1642655431080], [1095653101558], [-355730179392], [-400600865180], [1737915426114], [473007123750], [1093518477882], [-950535488126], [-52451469778], [2413127729878], [4137014878722], [1882568365794], [-2812399891170], [-4781858077832], [3857962464362], [850973113398], [-3742703398254], [3179432734080], [1118647853942], [-2977752850202], [-938863381534], [-517369879878], [-4352325429620], [2885990476348], [-2312050192338], [890549431234], [1966366903398], [-2121688289334], [-4044928798980], [-3662368071478], [667203030866], [-5834513035278], [1198985744634], [10289608279288], [2829904378242], [-4944775686850], [5733838894680], [11531800344958], [9989000557706], [9793933299340], [-15075553866006], [13286249593828], [6926976966602], [1100579739882], [2689200254210], [14416656278466], [-9290430970922], [21063128443722], [20516237365050], [-12761995501232], [-9374935658838], [-6380470913846], [6817944287118], [3252327696290], [9684330089520], [-20765050732654], [9585931105362], [6747640949860], [6141030509994], [-25659753260998], [-4597273143378], [15759436190914], [-23970135513282], [-22120505480162], [18035386861908], [29352196157200], [-21183882904170], [-19073995212118], [-1051874156658], [-34111237339362], [50006269420986], [45564675031078], [-41831607459432], [-3901863307758], [5231995605954], [-3677530173212], [24359944053242], [-42755120895310], [-37045308734094], [3588039791100], [949259385902], [65521939916628], [-35239361977534], [17568638369680], [29970103992810], [-16522506278792], [52721211708822], [59262036359674], [41531280143090], [1115320927078], [-34872798076272], [-76230760134454], [66007546815522], [-35115607579686], [-10198559891970], [-1982431961998], [49250962296514], [7495449510590], [79901624254548], [-29723465000854], [111233048935194], [-117223440354392], [58536537128322], [-54247898851722], [-21310143025734], [-101197677559858], [31918696200506], [78516502367202], [-137085434939886], [-77406292888410], [-135469345928132], [-92601314445238], [-3130432491310], [-100888662364380], [50461099689882], [46450078812640], [13094830902834], [102532429275450], [101429157379528], [124342734347162], [82257210858762], [-175909489960286], [103214645007798], [-214309313971920], [111586949225462], [117751996992478], [-95828620139118], [-63529808749122], [29447684440626], [-108389138196358], [-73919925829280], [-13409878065390], [-118681889135726], [298304065851558], [128794191367370], [74499185831586], [-57545645460480], [8381810942758], [-179920368548712], [77811300876146], [102212862805780], [-280948461276452], [-48883706510538], [3854132708434], [108606654161838], [-132767503315450], [-239830645757814], [198435541381980], [3068873043108], [134964196946394], [-77351979256832], [-197358215838086], [270668237031830], [-348147494692254], [167283998109480], [-139337006566562], [-244370128903992], [-163377663989660], [-11414050792926], [-99286212607918], [200130919056402], [-128753005517802], [-277689696933490], [-200895091493094], [-390073508352300], [-182936237106778], [-301407609258722], [-357645924009078], [-547748608408198], [-219034355918966], [-253320183139002], [564016740088430], [166517096934866], [-102629469772758], [640485537303220], [274807401818790], [-266019109485078], [469562100814474], [496880413989906], [469578438057182], [-194330793497042], [170032765857626], [327322920138640], [-187609500070678], [433274059361194], [-694743140256162], [-431349321546730], [-217982727607258], [-562599488235792], [-43257310423206], [-140750871318812], [857760902086758], [59929225081382], [870797804025958], [438144289854468], [-750631819670374], [-159532021945278], [46503110111920], [1084468403151510], [-711240301138638], [-78969514177722], [-926807179920174], [-169220435392752], [390452887598906], [-648180736830030], [-1023817740268652], [-22864762330734], [174359169783900], [767293242852958], [-354014696138254], [-1242974323690518], [-649782716783720], [752171926610274], [-581561475063392], [221634194424962], [-413220774289362], [-357751625255530], [-123720714476760], [-269654254881694], [-1206050360709126], [14456646179070], [482947568662242], [-1252506989615966], [1585530404487918], [79429376433290], [-604243468530300], [1054146040733268], [1034564940708506], [-247844006228970], [869686603109368], [712252338968642], [-513625866700158], [-95150730783086], [199691028017826], [427626796959902], [1359522546010900], [-390237875417126], [-1050555977000442], [-2114453325396054], [-2071614978425518], [1657422483949002], [-2275348672015640], [-1291513884989766], [2003668805892688], [645682849772598], [-454813709985070], [-949995438843174], [-1577655668450218], [-782863777286642], [125977356724706], [-409138782430998], [-676540518154710], [-1549646546493812], [-406591985592654], [774144242368980], [-761711484159718], [-1541209313186402], [-268189838285052], [-15261198016398], [-603093000247952], [914502335024522], [2541257597075922], [1051060701580594], [-444260083765570], [-1504329400547214], [-105315231837960], [1541446138715208], [-700739457888078], [-1917593646534726], [1217684479289642], [2218950764160522], [11483885632518], [3114788933668740], [-1806044818871882], [-1824744976795894], [-1809708244188798], [1283482530817234], [-196807248778378], [-1284246416526192], [-1736656747268900], [873975419736354], [-390624920243910], [-1107087010417172], [-604423811210158], [-4341601424336940], [1481188061666388], [2358396005148626], [3507230201872710], [-807492724171198], [2543913318427662], [1455748357228146], [-4447235530467002], [-3449732563754478], [4696226168029540], [3796973534717034], [-2516300360594372], [478214399085842], [-3567263576818646], [-3190129354336602], [2831920931275190], [-439668976000374], [149624399547780], [-2868441935729282], [4818275707489788], [-540503575412974], [3013931263053880], [-804519115364550], [1639884381543328], [-1032480374117718], [-2396641444894510], [-3835832511097254], [82196040996838], [-4386102215491758], [2707753068121530], [-1594277098738292], [573691620303962], [3972655843887762], [2554543281869674], [6520995664634460], [-1983706861350574], [185277860781042], [-2621312424417246], [-6707440538980832], [4773074035518482], [-5647209338401698], [-1889309158378080], [-1860975517550642], [-4926564362085918], [-3509508265199766], [7435790493866370], [-4381179315862558], [5228971614973398], [1346612385805860], [1654843469815946], [5323431842762682], [5597820466882914], [5578319047308990], [7541318374992088], [5337610717285080]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_80_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_80_10_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_80_10_a_b(:prec:=1)
    chi := MakeCharacter_80_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_80_10_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_80_10_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![46, 1]>],Snew);
    return Vf;
end function;