
// Make newform 80.10.a.f in Magma, downloaded from the LMFDB on 25 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_f();".
// 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_f();".
// 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
        poly := [-252, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 4]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
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, 0], [-130, -1], [625, 0], [-850, -107], [-11992, 950], [57510, 676], [206410, -6428], [148260, -1420], [524610, 9699], [-1833490, 53480], [-806572, 77350], [-10560970, -102648], [-13478638, 77900], [-26444850, 12899], [-29206090, -261667], [-19517570, -568724], [27497780, -772360], [-137289858, 346000], [159290, 1208353], [3565468, -3139250], [60429090, 4415476], [-3438760, 9387820], [-701174370, -1374201], [415044330, 6690840], [319197290, -1311108], [-976995498, 5100600], [-354029030, -9431601], [162986250, 18426693], [1350842270, 9174360], [-36160190, -14766824], [10639830, -19864987], [-1359826872, -13706550], [-1434897270, -38991648], [-1541880380, -1590840], [-520250650, -91547800], [-4640560452, -16359850], [-609149650, -57092568], [228757990, -138412101], [-1678047210, -66102447], [1926905790, 202862376], [-6210451060, 4019120], [5062684022, 81978000], [7979350588, -158640350], [8431290650, -439698924], [-16104185010, 354050892], [-6746065800, -101809600], [-12881245592, 170269650], [25863718210, -155909601], [-21350968070, -429404687], [-29628471290, -531759520], [47279101170, -358116324], [79707693320, -23596540], [-5730071238, 1128029500], [-5991679752, -194246250], [49431889650, 231625032], [26337148690, -762279101], [78646100590, -11900480], [100741400268, -111355150], [-111198496730, 576203912], [-16830909678, -1478687100], [-46041187570, -1543885301], [-26427269850, -1772554224], [-129315122550, 2463289793], [-94633517292, -57090150], [-146432755990, -566095224], [-146927234890, -88090828], [-302722753072, -1657821950], [-110595320670, -2170921448], [-327740797990, -268037467], [196401016350, 3595222000], [-116956709070, 4257956376], [100501085880, 3278777040], [-92303932210, 3444803953], [149149221990, -1894370024], [-111412986660, -6462526780], [252781164930, -3699746001], [-15584297370, -78752160], [-581594714010, -4184752508], [-288670199598, 116752800], [40557647570, -11492866140], [592845389260, -1825492520], [414305454582, 10506831400], [347318902428, -174836550], [918852886170, 5460720076], [-690222193080, 7458649760], [790665170550, -7152227001], [502371543850, 14178025900], [502122359850, 12061758832], [595121601342, -14999207400], [-513085379710, 13944038599], [1222755871090, 1325371453], [-12270738360, -400615380], [-248443108730, -25886971527], [585657925288, 2709996550], [-1524252119100, 17853806900], [-606898425830, 14981481799], [-891598573730, -6933619040], [-1895557838518, 9162838400], [-499688809890, -17424633301], [-49147358738, -18455786200], [435613918410, -9457286167], [2044346893950, 22129772232], [391567244190, -13072836201], [-1530438889710, -7874129580], [-1805967445232, 8664043050], [-1039896164830, -6549162288], [1798748134770, -16484391327], [-2334492681550, 6007548176], [1153367838400, 59409980500], [-3705529803598, -10380211500], [1903117352550, -6363847507], [-37979740290, -49656092924], [2615159282610, -66061015428], [-1026816711140, -23783603220], [923046624828, 90327386150], [-121540402038, -96034524900], [-3188524038250, 57354605299], [4080486924710, -24847784167], [1263959199830, 35905004876], [-1106186840020, -76064012560], [-3220493030058, -54561083600], [4079918372890, 68543217476], [9369336481470, 1756183812], [4200732261630, 91354905099], [-1976679522912, -56899161850], [-3402924345298, -47471758600], [1323557560470, 10380157960], [7526269205160, 31669674180], [6559924642030, -93339121587], [2113582005470, 10658084976], [-10442753344980, 49979377160], [4600318843850, 72252214199], [-4263843944652, 75320670350], [7704992505750, 59928989632], [2221219914042, 190941921600], [2053143251090, -149164065480], [-1923902124210, 122016452076], [-10909819942830, 160394524973], [7696370660390, 21069546092], [-15680814897430, -120273471040], [-9904451685592, -27263087450], [4097505101382, -280037537400], [-114251846990, -126248838501], [-10934050095670, 22126260413], [6569380461310, 268957862480], [12834240453520, -179461857740], [16086545075230, 66444157676], [-11740232048150, 165424115032], [14648799414180, 36917441840], [-6424707504710, 161931059299], [3856773988270, -114904498288], [8628413327722, 237381628900], [20700276223630, 158386163199], [-3537720939330, 275273905173], [-188913401950, -144371976407], [8548555347908, -231750023050], [4256999817360, -129865354420], [13103130515210, 84093764780], [-19499654750270, 166820399252], [-31872115705138, 243005556800], [-18722461643190, -375915215967], [-12693295616870, 255240305776], [4995308032990, 448508909853], [8420057165568, 461079201450], [-793415651030, -617478279788], [-35693460996270, 40672527099], [24977396400388, -423166856850], [1664516457790, -361521602908], [38878259273570, -282673461240], [26861546275310, -543550388524], [-27999962980740, 37256390580], [-8533096659618, 540092120800], [-31852893448572, 155390081850], [-8045591262830, 122963525276], [6362704825920, -449863281640], [-9834452714550, 510045035400], [-34537772976352, -646984211150], [-14181769836858, -720470100000], [-20240737228910, 934568067699], [-14971447668210, -346496766080], [6130554459070, 671777947473], [-12250644111512, -196964157350], [-3543734654850, 1192507789876], [-15390641560510, -245376266908], [-61727973437430, -314972277501], [-22449081590330, 450697248760], [-1632797319890, -908927583928], [98670465029910, -75282704701], [-24856835299390, -354358351020], [24360672250148, 336449636750], [75815795057730, 554640791776], [74513342713190, -367568477401], [-57645646390432, 715852333750], [65494997214622, -41626168400], [57754445093970, -353667950427], [-14133942497950, 165721377476], [2360863054602, 278748997300], [-13420103217290, -637129359724], [77458461690210, -445226472528], [-14312926016390, -1244162813201], [-8149799591490, 755428400280], [63876477416828, -59188314950], [80688131107630, -1121440369948], [15121911070050, -1126010475200], [108111351218580, 850730606640], [-83701084188930, -140950374288], [148805353548640, -140202844080], [-1258287399370, -103059635101], [43429199706330, -210479676360], [-78126054295712, 1255096268250], [65568778726490, 2071454425692], [-8401052987098, -1518698519800], [-18141996931630, 1939805999899], [19995361584050, 2566489370393], [-93426487680240, 910947541380], [-18542041668718, 384881503500], [57341722882230, -65712225187], [17181384964242, 752249690400], [214549485312790, 191911280953], [-75946071347610, -656596247124], [-61912715047578, 76196155600], [43998895787200, 1284564284100], [-11309811498030, 668444972760], [-20463766272390, -4396805894101], [18201132928930, -2635096105787], [-199643835060490, -286949317920], [44402822968770, 1220918801676], [-5544811490480, -2680696219640], [39082880719710, 2206056125933], [52247547045648, -1643823113550], [-60571900360970, 731371225676], [-246003518991420, 1423681120340], [-21528709841732, -1530807592350], [317800925745922, 756159201700], [168797609889430, -1838780109201], [-45745566425130, 1239542328573], [-7940510836070, -581277627460], [-17293690803250, -637111935724], [-79929791836500, -1768012012500], [152587773390708, 360391453650], [157692402446910, 1955057904999], [-259259742383272, -1234396429850], [195058976603850, -1229323037401], [43529758521550, -4423344802000], [133232970250530, 1316699384376], [-109800537792520, -973561677160], [67859697263590, -4708609183347], [143775488850368, 4801514177150], [169146490590340, -1650957247080], [-25278830243470, 2268570199199], [-32342845457610, -4260600994508], [-60221682553598, 6564676612000], [-30156956686650, -3404349861207], [-185183561688830, 4305140052260], [99705955984910, 3545535645776], [-10140977228940, -4132194856020], [-116963004181818, -4604868777800], [-387180611267270, -603777448587], [-116937682220970, -686238919848], [-220474189260550, 1745759728032], [-411245394621510, 1823902242899], [53214063918490, 5729609692753], [69559630786790, 3258412768320], [-86326265463650, 2358690393776], [-472675032807510, -2503469367108], [-138613091623500, -6294162862300], [45485898376270, -5097361586240], [412792877821082, 3445848105200], [-577677554106890, 96303617799], [-174461350817930, 5214102715576], [-247287215093938, 4272086566800], [-199397403998190, 2878560289133], [216620313395330, -234771447924], [631490109178880, 2336819543440], [-344064566747630, -6485202905488], [-81351334519670, 5848547827599], [-111893196216030, -7365015587727], [356776751902030, -2015024067160], [161194295381602, 5600042810900], [533742508507608, -2040268863750], [-202040978833190, 8397724109299], [-105732798338172, 3954710129450], [-392492109060290, 3212040879733], [-114673983196058, 3664505789600], [-354674520248110, 536867445553], [-181942569135132, 9519239065350], [-40004287225110, 11282501293876], [294847037827470, 4024863455412], [22755430968640, -9892789903980], [-37590513100470, 4390478773740], [334567625403902, -8279528282200], [-92767792623950, 6088262326093], [-11254269034590, 6129327108876], [-53770182252072, 5331203329950], [475323401379470, -4910149452624], [126355783332750, 16460359903800], [188396872696948, -10642980974250], [-248860934405610, 2555308044576], [715733222705340, -4912583871180], [181558271382370, 7078642194573], [-207311959042550, -6315205705024], [480114102672190, 14692180799992], [357418590472200, 9296945095700], [103125713663670, 3249757378299], [161665662505608, 5638979923550], [-735893197828390, 7274875328772], [138385602365730, -16340209993287], [-35181399773890, -8028820576920], [-605366344024680, -3870648963240], [1045348382450230, 1543268531576], [-631792375464510, -14394336049401], [-339423838316010, -11927132300880], [-320650004977278, -2093320292400], [-571952276986370, 3213353834799], [-1068493124110730, 4023619128673], [-654727512437670, 16654022536840], [-272027189265900, 15878405726700], [608357888617908, -9109050212250], [-233057443872590, 2634885696776], [-1527528667257990, -87990037620], [-782760854925872, -3313255150050], [323882459150330, -18473966736048], [502597970780062, -4102352706800], [-134243227619550, -2260960650001], [-698063038558470, -4013978456424], [-1069788350365158, 8551493068300], [-820593191628860, -8165926740180], [-58628378163930, 11625653596799], [131183118632550, -13886072264307], [-750071749435490, 6236543445076], [1453517460494782, 5365228183400], [-442072955496770, -21244441176848], [553570737494920, -6870687395940], [-1668986249604050, 1444576857799], [-143892458992952, 13640060684550], [1251714798330490, 13629529666453], [800996392558190, -20746952057880], [-813131948452510, -17455114244224], [158481935457122, -3162024402300], [479990057680670, 21176599406473], [19331029132950, 1352631928576], [412797659026490, 9066012416192], [-936601110938730, 8258094785160], [-697908161021092, 9148840305550], [-791158085789330, 7481817450376], [-965106438557580, -18350605289340], [-252590598341338, -29604536430000], [-1726462405830390, -3800687683867], [-696051684035052, -17923953115650], [135375624017150, -12270786971668], [-717250947703432, -10216914171950], [913096801173370, 16246682498312], [164093026682222, 27773510962400], [2355947578065930, -1121507701501], [962713848688630, -21950886528160], [-2160722026995150, -4673470341324], [-388173713064200, 26609305575700], [1196223307931808, -8967129420150], [1827019129683210, -18146154460428], [-523547088958390, -11002412499601], [-811383391583970, -16078904813948], [-182776434104438, -14718135212000], [-1778492569242690, 14140852365033], [845406219567380, -15302624296360], [390184721780290, -14570281291347], [392565888772290, 33338505971476], [376841859194070, 17480786926812], [1819970536404770, -351599592101], [-507250801007518, -14566700156100], [803710496690328, 31993033787250], [-303723574620580, -37259364609140], [-185182669342750, -22555879083001], [-1035812187593850, -11771097401400], [373570275694748, -7771817487050], [-202263419997450, 2167170401332], [2312862343068740, 16761415822820], [-2313460312266012, 19648719789150], [-1152282558929950, 12760038175776], [2350392970392570, -5705158454340], [352179700124010, 8221129662472], [-1377005597515618, 33890048578400], [-1674905890165830, -4610115864024], [-2608878860374290, 10280735768333], [-3043173550889950, 1518510873632], [1194309179679380, -20638145615660], [-3504642153410110, 17754003450299], [1710343694627068, 41352631982250], [1387481922428870, 11195392652712], [1706754893561030, 23871797575999], [1466984577954870, -3967390686027], [569189659698730, -20054971295860], [1096702177674550, 32146120377976], [-2348405014031500, -20687909606800], [2806513585798450, -39292551131907], [-899481562299892, 5000992434350], [953198613494810, -46762564302624], [2802010494423160, 10349384304180], [2810017626404010, -32513033850720], [-3051496147008072, -15612941466850], [1956526553843862, 21104217021600], [1833340821007950, 35408910644200], [1393000467900330, 44349241904076], [203122662837390, 15041716512353], [2245943929556570, -13160710624288], [1273403304211430, -64618678995760], [-1375699810426212, -74407733781250], [-4133635004796010, -1504657942308], [3656492580094802, 33232737731600], [727924079726270, -2561883482201], [4087992322495260, 23431316090880], [2705602636131970, -27043833128824], [1982473854978630, -339486408648], [-3007655638155250, 37329701013899], [396213980691848, -7771664003750], [-3759410229812350, 11444763745332], [1640121257024542, -62708054901800], [2397947637835840, -75757264489280], [-5324698436490330, 17696839855673], [1004949887289690, 89093715637692], [-137961510847430, 12211361515399], [-1114362960655330, -64358271957040], [7698199146017310, 1738393317172], [2735563263781830, -51516538029387], [-887622464048380, -89855871489040], [331450293802730, -53566964148624], [871333923781150, 20471411558632], [-4293661435278410, -47083062144101], [370424960554290, 95047468492020], [-5628290687209232, -17256686191350], [868620625327400, 61016337748400]];
    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_f();".
// 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_f(:prec:=2)
    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_f();".
// 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_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_80_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,10,sign)));
    Vf := Kernel([<3,R![12864, 260, 1]>],Snew);
    return Vf;
end function;