
// Make newform 243.8.a.b in Magma, downloaded from the LMFDB on 12 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_243_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_243_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_243_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_243_a();"
function MakeCharacter_243_a()
    N := 243;
    order := 1;
    char_gens := [2];
    v := [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_243_a_Hecke( : Kf := Kf)
    return MakeCharacter_243_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], [0], [0], [-508], [0], [2009], [0], [43091], [0], [0], [152471], [279710], [0], [-409495], [0], [0], [0], [1537199], [-4058455], [0], [1236809], [-4517617], [0], [0], [-17521555], [0], [-21919729], [0], [26745749], [0], [14113763], [0], [0], [-55325104], [0], [-8211439], [-85831225], [-87366376], [0], [0], [0], [-39803374], [0], [-103191961], [0], [218522573], [249458609], [43012139], [0], [362736857], [0], [0], [57587054], [0], [0], [0], [0], [-623847391], [609742193], [0], [758477909], [0], [-179002672], [0], [-1084883206], [0], [995522189], [1275706622], [0], [-695221114], [0], [0], [-1852889185], [-1958292025], [-2103854248], [0], [0], [435791663], [0], [-2127270058], [0], [-2237031742], [0], [-2204004565], [-3251541412], [0], [0], [-1744992103], [0], [-4102845559], [0], [0], [134432657], [0], [3551478368], [0], [0], [0], [4974471641], [-3687820966], [1141486163], [0], [0], [0], [6077201744], [-9218901373], [0], [0], [0], [2903216423], [-2361308020], [-7091760769], [0], [-7611344227], [-11701693036], [0], [1049453960], [0], [0], [0], [8203481951], [15493953371], [0], [0], [14826640451], [0], [-17742333199], [0], [-8015953132], [2970082541], [-18964820233], [0], [14595726548], [16165573733], [0], [-17999753137], [0], [-22342109107], [0], [0], [20948385761], [0], [-13519203469], [0], [-31043163763], [0], [35419116635], [0], [-18748577176], [0], [-36275909578], [0], [37334058245], [0], [6807804503], [0], [37771539572], [0], [-3585136438], [0], [0], [0], [53271099797], [0], [0], [0], [11003969279], [56143662110], [-57521540707], [0], [0], [-67996562746], [0], [70840448726], [49897047557], [0], [75034548581], [0], [-69152294521], [-27673681441], [34911323492], [0], [59933073794], [0], [0], [0], [-7151442415], [31894277216], [-1759810219], [0], [33178345145], [0], [90302808896], [0], [0], [0], [113913744779], [44791124549], [0], [0], [0], [-100228319149], [-22128346267], [47032005437], [0], [0], [98808015419], [0], [0], [4413109736], [-155685057742], [0], [-34885689355], [0], [0], [9698537591], [-168602468515], [0], [0], [0], [-180774495763], [-203036984068], [0], [160553958569], [0], [206387167883], [0], [0], [-218882089012], [0], [-42710083414], [118614299003], [243037754867], [0], [-158155779640], [0], [-213733316707], [0], [0], [0], [0], [164765206613], [49556144561], [-243200106061], [0], [0], [19435062815], [0], [300437142563], [0], [325477139450], [0], [0], [332407311749], [0], [0], [-70511348959], [129088823693], [0], [-335485949833], [-156166497895], [0], [164116971077], [-331810754266], [0], [361861459583], [0], [0], [420126117599], [0], [89280316406], [-209508132880], [93705760949], [215557383101], [378266174417], [128257978799], [0], [-453870014953], [40846679999], [0], [0], [488128532141], [0], [21742728803], [-166814226265], [0], [-558825625999], [0], [381013003403], [0], [0], [0], [0], [0], [457937737046], [0], [-592330038223], [0], [0], [-561409671613], [-620547893701], [0], [555858893861], [0], [-152350838728], [-733415815495], [0], [-585604243147], [0], [211544875511], [0], [0], [0], [553726637165], [0], [-656182596979], [0], [0], [-536076464539], [0], [-334062778231], [-668749773373], [0], [237577468679], [0], [865096817822], [701316188408], [-564446103976], [0], [0], [889821195533], [0], [660683389532], [0], [1003143627344], [0], [-1002036741973], [0], [556812663113], [-1138807018420], [728022582095], [0], [0], [115882766924], [0], [0], [233201165474], [230792827955], [0], [0], [1183168007336], [-1284621384727], [0], [1180707000956], [1312098531971], [0], [0], [0], [0], [0], [1183803846035], [0], [0], [0], [1443967823753], [1504162675994], [0], [1087759532969], [1138469033591], [0], [-870963767848], [0], [0], [1664870678201], [-1306818152695], [0], [0], [-1128679148089], [0], [1803682042253], [0], [0], [180019816100], [0], [329473892963], [0], [-125148010636], [-1753215818830], [-1829441497699], [0], [-1375386740887], [0], [0], [2008326260408], [0], [-1032463128919], [1981894435388], [0], [367659032537], [0], [-238786802773], [0], [-898411237063], [0], [0], [1908987230969], [-752223535555], [0], [-2327638200205], [0], [1829538330971], [0], [0], [-2101566858373], [-1530268989082], [0], [0], [-2496891989245], [0], [0], [0], [-1981649403685], [0], [0], [1824061896179], [0], [0], [0], [1695387743336], [0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_243_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_243_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_243_8_a_b(:prec:=1)
    chi := MakeCharacter_243_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_243_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_243_8_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_243_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![0, 1]>,<7,R![508, 1]>],Snew);
    return Vf;
end function;