
// Make newform 240.8.a.c in Magma, downloaded from the LMFDB on 05 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_240_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_240_8_a_c();".
// 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_240_8_a_c();".
// 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_240_a();"
function MakeCharacter_240_a()
    N := 240;
    order := 1;
    char_gens := [31, 181, 161, 97];
    v := [1, 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_240_a_Hecke( : Kf := Kf)
    return MakeCharacter_240_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 := 8;
    raw_aps := [[0], [-27], [-125], [420], [2944], [-11006], [-16546], [25364], [5880], [163042], [201600], [120530], [-115910], [19148], [-841016], [501890], [1586176], [-372962], [-4561044], [-1512832], [-1522910], [-4231920], [1854204], [-6888174], [3700034], [-18002454], [5372068], [11539764], [-1571794], [-25204954], [-39408004], [-14108208], [-8005122], [-46071644], [72352498], [37006208], [-78507982], [46818412], [25004280], [53067066], [-42205400], [-100020490], [-61761016], [-76741894], [-181031838], [-61608448], [169916860], [-148128884], [39612740], [-37181586], [-179591418], [373328104], [-257021534], [127344408], [130681926], [267746792], [149432066], [153184904], [654462402], [551492754], [210200436], [542401698], [-926477356], [212976144], [363896258], [-317049014], [-224556372], [-1238861078], [583643116], [-469471298], [61855854], [12353736], [12551388], [-565993958], [-1777759180], [-1181946168], [602482194], [-186765014], [-996333222], [-2386442326], [-2596441936], [2838495214], [1528084320], [-2660612822], [-2292224800], [934042716], [-88501222], [-1210641590], [857427882], [1946619588], [959955164], [-303578520], [-436058564], [-834813448], [4502299364], [-2416997824], [3512093474], [990013090], [-445925932], [2847531150], [-4341160300], [3001237914], [7438857204], [-720170814], [2301861244], [-7372565086], [-736500396], [-5085392138], [-4860225208], [6784663226], [-2852501644], [7754672626], [-6340967562], [-3198311084], [3794592488], [6779638290], [1132032588], [5542646896], [9417645178], [-7463900240], [5583091942], [3399326250], [-13892978478], [7225755732], [5833864724], [4374864898], [-3546849794], [10654527792], [9211691932], [-581769958], [-143208364], [-17601209792], [21039792464], [-3910148702], [12024211074], [11894778338], [-7776143502], [-24436520836], [-2269696214], [-16319960150], [-6993929052], [4009493514], [-18857165156], [-16638566084], [-13722438210], [656953880], [-8709973182], [1938246806], [795332180], [-2241718192], [19916852370], [-27690602566], [16561617868], [-6699035496], [-3878144916], [7158695008], [-25415979160], [-23456596934], [9300700362], [-11311724390], [-4462699548], [19087166174], [13410184756], [-46419105240], [39297221294], [36936970560], [10286750008], [-32443943142], [51631209890], [-16994003774], [-41848708656], [26842530118], [-39134173704], [19652040018], [27737289248], [40001959026], [-10792357020], [-46562907294], [-7712404292], [16002109990], [53274605620], [13152394544], [-18279816974], [11429844526], [-3227786712], [33951852050], [-43686468606], [28399662956], [-14875958518], [53850615016], [46385483962], [8804386444], [-44975293428], [-100882651414], [30497344236], [-3145564754], [-70996312814], [-44434624014], [23194845846], [46992735872], [-57061966182], [-28766663568], [-22454123238], [-63899184014], [120721296432], [44989341210], [119503519984], [9262516372], [-19938400062], [-105784408004], [12025821818], [-85040735198], [35270053140], [-94888724084], [-140996750304], [129501254378], [41828439212], [42370874298], [-157082473312], [145817505642], [-177885092306], [179677019248], [2501981970], [14794271444], [180199032524], [85150422830], [-46847504562], [163357112624], [-37494266596], [-95316749184], [-154845797790], [-140363244676], [92088582664], [-197515942702], [-148621932956], [111506287296], [28018651602], [184379615458], [127818525024], [-239133900528], [218277608964], [-14455016484], [-159482716948], [243586444398], [57160127118], [-211142618624], [155312962588], [-26930328200], [41073325276], [-20849765888], [23594438650], [7344701282], [228705878520], [-118628500086], [-115171803302], [-107909666832], [265844727142], [-279910804124], [-16944732078], [232889018402], [226731599948], [341604325460], [222680811902], [-331704264294], [6428715894], [60797777492], [274490412266], [-343350178022], [18247105780], [-21741633454], [327453908054], [49520193044], [423245618], [-37307322912], [-152390231094], [233186030932], [-376245924132], [-24438007410], [-37796685414], [192256648560], [238277513840], [289651593056], [-397293469360], [-54558222594], [-117075333636], [-314510680680], [-86185208942], [-233333335902], [-14620874192], [-475894201470], [-550231006454], [-215048700916], [416777099958], [363544592496], [309489976538], [-146798181990], [-11689443392], [-355539241806], [-152997817200], [440976525652], [404553816786], [-198604181062], [33382889768], [241809645324], [-641815991908], [-8263961326], [113540195844], [611704294166], [-11153538336], [-344196164118], [513746439168], [-291723568614], [-270994912470], [-680554140668], [-388546874656], [-533748885014], [-572884016952], [430196319048], [-588784045110], [-446445770718], [373658969860], [-726916504510], [560333473106], [-114793519372], [-42620806458], [387317829346], [786195065020], [-54809007748], [-944354088408], [609713545586], [468943190502], [127633862474], [842458221280], [613072589276], [217696034692], [-800358080428], [843640399958], [952668251806], [935095175258], [-586753336164], [-629369412278], [1095548745910], [469316967594], [508162224288], [-573855559894], [1029185088600], [-644624138722], [-440427142132], [-122509621080], [-277002840398], [1025901896844], [137683662762], [-774502333550], [557598148796], [-966078987834], [464359072086], [721355027504], [639132980256], [151235544582], [417354064984], [128364399514], [29807468954], [695147931768], [-1165701285584], [89326970764], [-498038430950], [-429411307686], [-759402096636], [-645530392054], [384266804376], [-993085706556], [-162113076680], [1042572527946], [489621452016], [-137375705510], [1297100394904], [-280709276448], [1138542713714], [-1132429534902], [-59642028374], [-1489327909958], [1715152017342], [-376567652092], [-967780304066], [-1455926500212], [-685928559272], [-944430017984], [-583514569054], [1720606778268], [525389649024], [1217946955074], [-1713124342414], [-423839792912], [-1362102009140], [-297355467368], [1718432668538], [601102060360], [553488693354], [1286922889580], [1635310559874], [-825457010042], [195785043654], [-922577152180], [1584311938030], [-1659003132134], [-1854857279560], [796524311834], [-569968293734], [1565223137772], [148928395776], [-259049487966], [-866975873694], [-692248187420], [-1196888223756], [534712054946], [-1855775202526], [917941314464], [510388117124], [823212904470], [1797006140696], [-885723117062], [1828762826362], [1228742023848], [2252425089016], [-339443313406], [1256469257066], [-1155207055780], [-2568769800150], [-2235011942516], [-1365044240504]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_240_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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