
// Make newform 294.8.a.b in Magma, downloaded from the LMFDB on 15 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_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_294_8_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_294_8_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_294_a();"
function MakeCharacter_294_a()
    N := 294;
    order := 1;
    char_gens := [197, 199];
    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_294_a_Hecke( : Kf := Kf)
    return MakeCharacter_294_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 := [[-8], [-27], [-165], [0], [-2055], [-2720], [15708], [-6752], [30828], [-118305], [147517], [311732], [491400], [-577174], [854862], [1166883], [167079], [-1027274], [-3268114], [3046842], [3209110], [7127987], [-4365909], [11996214], [-13343639], [-10635090], [11353336], [-1399569], [1934702], [-26385912], [-18498727], [3728499], [-36508314], [-45167834], [-22395642], [-78994021], [-62421692], [-18400132], [43180038], [85482114], [-128756532], [10822120], [-46207896], [33494645], [-134731206], [78653476], [89441282], [-160136009], [217747209], [-159058820], [9475428], [76391172], [228614665], [-113193081], [-155406378], [-80758110], [273009261], [-582098975], [584235968], [4303242], [-381182690], [52689033], [467610004], [152321592], [-197466713], [815674071], [-746780644], [555804473], [726699804], [-465884834], [1547551848], [15985650], [-91216529], [-1379701336], [628207784], [986494002], [-885325818], [-2090019572], [-862443096], [-447155615], [-322182000], [651038030], [2996265732], [-459955502], [-3455357255], [-2790019419], [-3299577696], [-778810873], [-3587056506], [482745488], [3663081780], [2539380378], [-3266843875], [-1627044291], [3762618050], [-126437400], [-2287569315], [-5476601022], [4930284376], [-5985527578], [6644989436], [496316229], [-6476968221], [7075919136], [-430814110], [-5682793247], [-8040905775], [5737581132], [-5281991670], [-2134033835], [-6593625941], [2946073436], [2455288074], [3240343030], [6135206021], [-10672782654], [1430036098], [2722393866], [772402053], [6834103560], [-431455010], [38807693], [-2154459081], [13726608243], [-4250671088], [-2595207105], [395512142], [-8902788906], [9819183361], [229386238], [14248468970], [1830251430], [21317049005], [-2316350278], [1441923432], [648045715], [-10638046770], [-2161245134], [-10279892817], [-21611087400], [-9726167666], [14758655475], [23753138600], [20055185613], [20873871448], [-6499286748], [-20242275182], [12330400026], [18975857146], [16389886890], [-895028704], [775706562], [-3010540480], [-32624024772], [34887729164], [-22498271370], [-35772089968], [23351226774], [29288238805], [-39424033329], [3925575696], [-10321145694], [-25480483477], [-25436407035], [-20711921790], [-35355729660], [-22514229793], [29066837674], [-51893601193], [-11097224409], [-15206549889], [128455654], [414216624], [-55802449243], [51138806515], [-63059209452], [5943952310], [-71729502375], [43250493592], [53358229426], [-8310806749], [-25989887655], [-75987868858], [43495893654], [9722872014], [-72947830029], [-212838310], [4329549118], [-27058737733], [80670241776], [71055729007], [-45040971537], [64363689368], [-2714041686], [-72768049779], [-231866934], [1320873782], [-15040827670], [-43758261846], [-86419342002], [41724242637], [-52494936080], [-44635235582], [-35380167314], [37640716560], [35780518569], [68655240568], [134487200919], [-78411470148], [-12369105758], [36823341698], [9646278255], [153075929243], [-65366281191], [50107923984], [-78042633170], [134686960889], [-85408681596], [-71437816194], [-16990545654], [46148871008], [50815447144], [-104654050566], [-59145052417], [115606361709], [203977183640], [167084714202], [62573378244], [-167164547255], [83021402820], [-156131795578], [183241562488], [25616960075], [-187305275550], [-4687282742], [-125970060408], [-191665200587], [188479769745], [-2535452748], [143407141092], [36094136244], [-56980659008], [-133096166681], [-139551902686], [91370727432], [185613110196], [47153281717], [-190125510396], [-119938792144], [139477080816], [-103376598694], [102373916766], [89676190410], [-215557519154], [-13079597595], [65279167977], [78713308862], [-281874517340], [106904822301], [122141046427], [113673869720], [-44916469299], [-168365154854], [-325068604964], [352478149878], [-261259084562], [-345394457055], [-202490433864], [98276252756], [-37907262543], [356616079888], [-63738191026], [-179788440245], [-146993077123], [73440249475], [225881804944], [-187080381897], [-378142634452], [35600813846], [-78086213472], [141027557862], [-62423753569], [-270509564880], [200864479108], [-319977853418], [-438132793164], [198590306183], [-295943254623], [269082134923], [173403107964], [-314122886706], [-376947247191], [-363081939900], [200178337572], [585229669160], [280791036615], [-174400893608], [332091823266], [-374193918804], [306587886034], [33358135354], [-329885888055], [-235596779971], [532742806197], [-169946385082], [-663798818206], [-344681488371], [-32884740086], [-296406822174], [560916573014], [-336626326002], [637914121098], [123447221328], [286217877152], [-410716633356], [492994349578], [-286252599969], [317955290316], [1419792763], [-140108607432], [-233799035912], [-619032349030], [772210287441], [-173470933792], [257528252400], [198054775693], [-147361370374], [787643281606], [228396077886], [-342589881195], [-693740954002], [-89763624255], [-156479828480], [401491173864], [788388820118], [-687316472316], [471344669648], [-185931836526], [-242964496433], [792248271103], [-296886756262], [935389809864], [1011184225209], [-752885087311], [1029018444519], [-399430425357], [740723287042], [326133428498], [253043522082], [231082222713], [915271082512], [-12815858989], [196303871106], [-797336643725], [271137529730], [-1119191919930], [627198845838], [-859237339425], [-242898808308], [47017285146], [-610399418962], [907106730792], [-916972317354], [-897558979956], [-995832022724], [1083344558387], [-155792347074], [-708450122296], [-853136155207], [-982878368817], [1077639097744], [1400786657778], [-872927647065], [-3976889648], [-1364804707996], [-681137758536], [689284687320], [-57451728491], [493094622786], [-1183535867438], [-1089686870502], [1175901260382], [-81855221968], [1089163894056], [-1245727117550], [1067330863830], [-1377310249696], [-1406601518564], [-404323419616], [-260553389472], [-6099444175], [55139492346], [-1105262336019], [-733806394610], [157882767330], [1117750646063], [-904674302261], [-1264786422606], [1622647513028], [1740995558745], [178718305648], [1737330369060], [-139445733676], [1573270962306], [-206651863131], [1410893705215], [873127860926], [-1880657929494], [1156095463066], [1838203360395], [-1097841807287], [887595111669], [439382618019], [-4935442738], [1816844188754], [-220354426731], [441094520244], [497037361744], [1230593198508], [-940138576698], [2525543286261], [-1849059758582], [-2057674514526], [-791457803253], [8340796870], [950038387950], [2193612320271], [1132497768492], [2629861025578], [-2335596341244]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_8_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_294_8_a_b(:prec:=1)
    chi := MakeCharacter_294_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_294_8_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_294_8_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<5,R![165, 1]>],Snew);
    return Vf;
end function;