
// Make newform 1296.4.a.q in Magma, downloaded from the LMFDB on 22 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_1296_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_1296_4_a_q();".
// 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_1296_4_a_q();".
// 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 := [-50, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_1296_a();"
function MakeCharacter_1296_a()
    N := 1296;
    order := 1;
    char_gens := [1135, 325, 1217];
    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_1296_a_Hecke( : Kf := Kf)
    return MakeCharacter_1296_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 := 4;
    raw_aps := [[0, 0], [0, 0], [4, 1], [15, -1], [23, 3], [46, -1], [11, 8], [43, -5], [29, 1], [54, -1], [-68, -16], [-90, -1], [336, -2], [35, 23], [-426, 2], [334, -16], [-274, 6], [142, -17], [-581, 11], [403, 3], [-755, 18], [11, -41], [-770, -38], [1323, 0], [236, 50], [48, -102], [-202, 82], [-348, -112], [-554, -53], [1491, -28], [1457, -11], [13, -139], [-2157, -28], [1014, -86], [944, -55], [-734, -190], [1096, -147], [2250, 42], [1377, 129], [-582, 167], [1092, 16], [3066, 28], [351, -137], [1589, -166], [582, 43], [-184, 204], [3143, 11], [551, 139], [465, 201], [-3038, -77], [1525, -38], [-1238, 62], [2439, -28], [3673, -75], [-1531, 46], [-2482, 402], [5072, 205], [-6389, 151], [-530, 96], [-2083, -62], [4204, 16], [1440, -343], [-3996, 272], [-2496, -360], [-2337, -48], [-4062, 151], [3355, -301], [-372, -398], [3399, -433], [-2760, -342], [-1126, -536], [11193, -51], [692, 508], [2282, -180], [5008, 252], [-225, -225], [1546, 124], [-124, -891], [-1311, -234], [-1803, -82], [-228, 148], [-4612, -567], [-8342, 358], [-1037, 552], [-5514, 42], [-626, 1034], [-1376, -282], [3521, 610], [1810, -564], [-16814, 114], [-9666, 542], [1429, 589], [-6136, -884], [12873, 221], [-6699, -223], [3552, -992], [1866, 1044], [-6004, 1194], [12455, 355], [-9192, 33], [3370, -170], [-3026, -789], [674, 454], [-4583, 666], [-11274, 190], [-7183, 434], [-16945, 99], [3859, -1164], [-12456, -332], [-7271, 230], [-12515, -339], [-5578, 568], [15729, -274], [12272, -312], [-478, 834], [22519, -348], [8178, 174], [-6923, -67], [-9186, 456], [2979, -69], [-7762, -1409], [-563, -1702], [-9434, -376], [-17386, 1186], [-5807, 657], [-1638, 1607], [-9166, -469], [18863, 1019], [3213, -723], [-3898, 1168], [-12464, -1428], [-19060, -728], [-10803, 605], [26390, 440], [-8653, -708], [12545, -402], [-9096, 653], [-7393, -181], [10540, -415], [8021, -578], [19952, 192], [-19722, -1489], [14068, -648], [3547, -1817], [26914, 604], [10221, 937], [-4438, -564], [-3603, 198], [16098, -530], [35753, 149], [7596, -211], [404, 890], [-15122, 1370], [-16571, 97], [9932, -372], [-7225, 1419], [2507, 2391], [11255, -492], [20241, 54], [-10566, -209], [-10719, 1049], [-5883, -882], [9601, 1753], [-26247, 2041], [-12072, 862], [-16740, -1092], [-3589, 43], [-25076, -495], [37067, -544], [34246, -1288], [-33720, -1988], [5520, -1311], [38002, 494], [3319, 1116], [22789, -1599], [25040, -1778], [11731, 199], [-35442, -1477], [-41446, -894], [12236, 3157], [21706, -2190], [-24455, 777], [24474, 2399], [19212, 2458], [-19674, -1938], [-42030, -217], [-1826, 3691], [17415, -2373], [25426, -2104], [34281, 1529], [40417, 1138], [16836, 2636], [44333, -663], [-1352, -1979], [-25815, 449], [-24718, -1160], [47095, 1576], [24274, 764], [21383, -1192], [-13257, -3853], [-3802, -505], [-64499, 833], [31328, -774], [19867, -2644], [-56739, -971], [50502, -192], [-10649, -2089], [-4614, 2554], [-4204, 1634], [2705, 1473], [-6468, 338], [9750, -3289], [-19381, 1091], [-56981, -1769], [-23408, 3256], [55268, 258], [-52085, -345], [-7355, 3466], [-10398, 2038], [-25374, 1499], [-11758, -2521], [2337, 441], [-15315, -2462], [11410, -4790], [-5004, 4148], [-1558, 1895], [-60888, -1962], [-8175, -1775], [19386, 3170], [56030, -2230], [47736, -1963], [2573, 3189], [15037, 2313], [22621, 3114], [28764, -424], [-43730, 1790], [35411, -1584], [-6032, 6154], [-33092, 4532], [-6451, -483], [33873, 3149], [47659, 1871], [-16810, -522], [6418, 5212], [216, -4386], [61777, 2381], [-10393, -5233], [-3891, 961], [-8266, -5386], [-38336, -1536], [-47622, -2157], [-50457, 1296], [1318, 86], [-8255, 5382], [76422, -1425], [19941, 149], [12782, 1647], [-73423, 1833], [-23418, 1247], [136, 1510], [-8320, 6352], [-4776, 1352], [-23876, 3393], [23592, -4182], [23314, 720], [82804, 848], [6362, -4433], [-78187, -302], [-69416, 3776], [77606, 1219], [10708, 1641], [-100907, 2697], [-23768, -1482], [-60988, 3800], [-91145, 3920], [20050, 1158], [-46368, 1008], [-112552, -595], [-66623, -554], [48710, -850], [37730, -2142], [75836, 2764], [51788, -5768], [88586, 619], [-7190, 4154], [-33028, -7216], [-12763, 3450], [64530, 4116], [-19769, -6609], [-10027, 3382], [-39086, 1052], [32967, -3857], [-75371, -3902], [39528, -884], [-20298, -9409], [-66518, -1769], [-82376, -1368], [34212, -319], [87393, -5635], [-55694, 5034], [-32311, -8494], [-103792, 866], [41695, 2207], [-84265, 6035], [20076, -7612], [33044, 890], [-125055, -11], [-90766, -52], [-22604, -6584], [-16444, -4731], [66549, 3421], [114714, 3644], [-20587, -7294], [-46825, -6513], [-126850, 3754], [36200, 5222], [-8106, -7002], [84504, 5040], [44273, -1190], [-89400, 5758], [-68878, 4618], [-24368, 7422], [-64924, 2913], [122900, 1388], [-36956, -2574], [13287, -11116], [-56271, 4429], [-5355, 1625], [81467, -2837], [-97218, 3968], [102694, 752], [105642, -6001], [-30048, 2120], [-62529, -6373], [86709, 1205], [38670, 1494], [-1622, 5459], [-22227, 2302], [-21460, -9126], [-55698, -3042], [40834, -3801], [32124, 2026], [1554, 8479], [64680, -8020], [106840, 1357], [20747, 13083], [-168408, 1697], [129212, 6724], [-117888, 2644], [57602, -2477], [15417, 3357], [-20341, -13084], [20122, 11863], [41301, -9711], [64280, 5477], [48935, -11260], [-103870, 6078], [131233, 613], [-81740, 4010], [-22401, 6991], [-176632, -1543], [-134613, 6712], [-152175, -3579], [-33386, 12478], [-146974, -5782], [16389, 4386], [8238, -7688], [82628, -1280], [-182006, 2672], [81127, 3579], [151317, 857], [-87680, -3880], [-29504, -1983], [186662, -4146], [-20332, 673], [-165543, 1525], [41670, 3766], [21595, 9948], [125106, 8736], [-114985, -2616], [59526, 879], [51683, 7852], [-19842, -942], [-146457, -2728], [65687, 5171], [-53943, -11219], [-171132, -528], [12332, 10173], [-34039, 2961], [59568, -9768], [-10955, -3290], [-145958, -2937], [136311, 859], [202641, 1765], [27690, -2366], [-60053, 12340], [-14799, 2937], [80925, 8934], [-49115, 2057], [64822, 799], [171920, 3533], [4896, -266], [-20179, 16589], [180965, -906], [77800, -6667], [169733, -743], [-81188, -7803], [-3795, 17818], [186277, 4001], [22668, -3296], [27515, 5412], [-111710, -9925], [139237, 2925], [-59638, 11114], [-18789, -12256], [-133976, -319], [-22344, -5924], [57592, 8688], [89781, -9910], [91150, 7350], [207896, -3286], [-33184, -12950], [44866, -3446], [-7352, 7280], [-14873, -4520], [-126028, -51], [131900, 3872], [-188061, 3592], [63384, -160], [35534, -114]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1296_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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