
// Make newform 816.4.a.s in Magma, downloaded from the LMFDB on 20 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_816_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_816_4_a_s();".
// 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_816_4_a_s();".
// 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 := [-10, -14, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-8, -4, 1], [-10, 0, 1]];
    Rf_basisdens := [1, 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_816_a();"
function MakeCharacter_816_a()
    N := 816;
    order := 1;
    char_gens := [511, 613, 545, 241];
    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_816_a_Hecke( : Kf := Kf)
    return MakeCharacter_816_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], [-3, 0, 0], [3, -1, 0], [2, 3, 1], [-13, 1, -4], [11, 8, 5], [17, 0, 0], [49, 0, 5], [-33, -11, 0], [26, -8, -20], [46, -2, -12], [48, -8, 26], [245, -11, 4], [47, 48, 43], [-148, -35, 21], [184, 17, -41], [70, -16, -22], [-18, -1, -37], [464, 30, 18], [288, 50, -46], [-236, -31, 55], [114, -120, -54], [540, -43, 25], [486, -85, -21], [66, 71, -133], [380, 50, 88], [427, 60, 71], [971, 111, 106], [628, 8, 54], [915, -103, -50], [1773, -188, -23], [-7, -199, -110], [448, 95, 169], [268, -83, 121], [2204, -145, -63], [1264, -48, 168], [1867, -150, -113], [406, -274, -248], [195, 257, -16], [199, 7, -300], [562, 62, -300], [1096, -309, -7], [-396, -157, -165], [418, 22, 382], [-1129, 61, 90], [-2782, 291, 33], [-146, 78, 400], [1361, 280, -495], [1881, -123, 78], [2262, -84, -12], [-2659, 565, -20], [-2694, 413, 83], [1914, 177, 165], [-176, -298, 18], [-498, 213, -3], [-296, 364, -308], [1969, 553, 552], [-2811, -8, 373], [-316, -267, 151], [-6538, 361, 97], [-1394, 18, -196], [-4564, -464, -338], [2012, -476, -228], [-3548, -390, -466], [-3410, 745, 57], [5494, -216, 248], [-1439, 574, 3], [-2288, 435, 229], [1504, -254, -434], [-1915, -182, 249], [-1610, -934, -442], [-2320, -410, 694], [-1008, 206, 646], [5794, 824, 844], [-1042, 291, 121], [2246, -557, 269], [5504, 400, -222], [5634, -543, -103], [-3503, -1043, -544], [533, 594, -1011], [-8876, -356, -564], [4403, 236, -7], [2436, -66, -438], [2111, -474, 131], [592, 1030, -746], [-11400, 1, 105], [-9082, 288, 388], [-4031, -784, -881], [3958, -266, 734], [7368, 88, 944], [-9612, 939, -177], [6515, 1069, 708], [130, -174, 420], [5084, 333, 121], [-32, -1095, 865], [2185, 875, -168], [3760, -590, -1372], [69, -623, -736], [13548, 156, -436], [-3096, -66, 696], [614, -1437, 1065], [4226, -1430, -1074], [3582, 368, -438], [13126, 409, -831], [230, 249, -401], [-167, -1554, 869], [-11188, 884, 1028], [-3808, 295, 985], [-2908, -773, 1675], [-7078, -1600, -2160], [1348, -117, -1885], [-2033, -2424, -927], [-4426, -356, -440], [-630, 1452, 538], [-3619, 96, -1683], [899, -2003, 530], [6110, -1399, -529], [8, 3057, -35], [-4237, -2213, -828], [84, 1177, -1307], [5597, 2124, 1987], [-9268, -3, -941], [6669, 957, -1632], [12945, -931, -1674], [-10184, 1702, 1282], [20688, -384, -390], [7688, 2769, 1943], [561, -1487, -330], [3932, 2106, 246], [11658, -1724, -1064], [-4495, -636, 1193], [1996, -2302, -1906], [-6134, 588, 918], [481, 840, -1133], [12854, -304, 124], [24425, 1886, 2405], [1130, 1035, -293], [2902, 2089, -713], [1396, -1610, -1380], [-8339, -1287, 1136], [-11608, 243, 931], [19735, 1925, 114], [-15388, -2518, -2242], [-1059, 903, -2412], [12670, -2240, 600], [-7255, 2019, -1856], [-15370, -1746, 702], [-18682, -2454, 2110], [-2824, -1674, 346], [23034, -551, 879], [-24180, -219, -697], [-5170, 920, 1172], [-22911, -2574, -225], [-4967, -3661, -3216], [-2608, -3205, -1293], [-365, -2303, 3160], [6921, 510, 3711], [3443, 529, -1866], [-23090, 1230, -470], [-8322, 3108, 828], [-6376, 2742, -1454], [-6796, 2204, 1990], [-3217, -1160, 2487], [-1034, -3742, 2004], [17218, 1814, 2030], [12317, -5627, -674], [-9294, -843, -1629], [-30914, 276, 2308], [7306, -2703, 3317], [27646, 974, -1402], [35624, 121, 1393], [-9295, 3492, 119], [-42533, -1837, 370], [-3501, 2806, 2239], [-6379, 4164, -1855], [26195, -6577, -1132], [-19970, 1239, 2253], [-22727, 2105, -2376], [-8409, -2250, 1589], [32251, -1368, 2293], [13803, -2856, -4485], [-2668, 844, 4796], [-29200, -2637, -583], [-5600, 1832, -2498], [-9694, -810, -800], [8738, 1306, -2138], [-31228, -3607, -1053], [-13401, -3606, 221], [-18020, -2631, 407], [-19240, -5246, -4350], [18890, 1524, 492], [-4688, -4730, -6046], [-24735, 3224, -1427], [5078, 767, 4099], [35377, 503, -2608], [10610, -2596, -1180], [-30950, -1404, 636], [-28708, -780, -662], [31498, -6166, -1942], [3038, 3980, 6722], [26453, -5485, -2674], [-11982, 1833, 4663], [21425, -4698, 1609], [7909, -924, 1775], [-10290, -5423, -5873], [-50924, -567, 851], [45812, -1158, 2694], [7352, 4150, 3730], [14725, -3355, -2908], [18812, -2380, 3540], [-9988, 2985, -4241], [50600, 3475, 2241], [-7446, 546, -2580], [-9726, -4623, 1203], [-21239, -69, -2824], [-12228, 2380, -1234], [22623, -3862, -3127], [-31630, -6107, -8159], [-15043, 187, 8156], [34094, 3441, -6683], [-65323, 2004, 435], [7392, -5952, -872], [24316, 4040, 4466], [41320, -5259, 1753], [24292, -5651, -5511], [-3814, -6490, -4038], [55227, 1611, 1416], [-2537, 293, 5312], [-22417, 1652, 4899], [24044, 82, -6150], [-46237, -4248, -5411], [-53914, 6344, 314], [44444, 716, -3016], [15182, 9328, 3588], [11376, -6580, -5216], [45278, 3894, -5732], [68822, 3627, 3059], [-32139, -3521, 5714], [14187, -2757, -3978], [2858, 3899, -3759], [5743, -1185, 7190], [18956, 5744, 3008], [-6867, -10770, -1533], [-4413, 5070, -4405], [-7701, 6999, 8748], [-13649, -4023, 3956], [-35956, 2393, 2465], [-11367, 10837, 1822], [44703, -7978, 1225], [-23610, 7077, 3591], [445, -1932, 9011], [-6374, -4970, 9526], [-35286, -6989, -1079], [-26416, 2094, -6660], [15208, -2125, -9799], [26450, -2917, 173], [-45928, -8446, -7180], [-58150, 6699, 2125], [-12149, -6365, 508], [20338, 550, 10102], [67782, 1110, -540], [-56756, -7168, -5848], [62084, -1852, 2378], [41772, 7682, 5072], [-9719, -599, -6220], [-20611, -9920, -7423], [22108, 427, 6341], [28862, -8883, 2845], [-22594, -1473, -555], [8930, 6370, -1474], [28380, 4122, -2520], [3099, 1286, 8813], [31711, 3006, -413], [55820, 3918, -734], [20722, 6090, -542], [-28571, -7746, -8837], [-3254, 6143, -1007], [61813, -4566, 1321], [-7335, 1336, -4657], [-57482, -681, 5597], [-19916, -7588, 416], [62456, 4159, 3251], [-43696, 7196, -2540], [-24102, 8510, 3938], [22956, 7065, -8491], [-94806, -1053, -2127], [-3822, -8940, -4316], [7774, 5576, 2040], [-21663, 4414, -3529], [-98100, 1586, -2556], [41659, 7247, 464], [-43157, 5069, -3160], [-31076, -2949, -1279], [101889, -6031, -2070], [-24372, -2874, 14292], [10043, 493, 646], [110720, -4652, -3100], [53346, 5643, -10173], [-26905, -5047, 520], [-33680, 10410, 3566], [26013, -11232, -9285], [-76310, -7873, -10393], [133336, -936, -1616], [53107, -9001, -2414], [-21886, -9691, 615], [-63222, -826, -842], [-9838, 1352, 4734], [143504, -3496, 1730], [84454, 11561, 14163], [69826, 3376, 6996], [-1560, -5390, -6254], [-41670, -200, 1124], [-28589, -2305, 1196], [-995, -7560, -2983], [-66524, -44, 8768], [4219, 1812, -179], [-13658, -11406, -8308], [63853, -1641, -496], [8104, 1080, -8210], [-13932, -1614, -11460], [57862, -1212, 4774], [-95140, -6173, 6569], [3900, -8705, -6375], [110517, 7352, -3115], [29162, 9364, 5300], [25767, 1524, -3615], [-94062, -8796, -6686], [96724, -9755, -5271], [61292, 5314, 8982], [-100891, 4297, 8404], [-54334, -11019, -4227], [-5987, 3395, -3466], [-101520, 6543, 4611], [-36134, 8090, -7496], [26700, 2536, -3304], [-48533, 1133, 7712], [-46979, -3576, -15529], [-29137, 16759, -832], [-76516, -8467, -9925], [44999, 11042, 15657], [95589, 7002, -1119], [-71624, -5458, -2604], [97483, 9191, 14800], [-3951, -1088, -1679], [-29460, 12360, 3198], [-23537, 11711, 8358], [-76988, -13515, -2777], [76017, 6280, 15253], [35971, 1511, 4086], [-5278, -15584, -5516], [-12473, 12686, -3375], [-17688, 10030, 4564], [61156, 13256, 12326], [108520, 8415, -2885], [14683, 14848, -9195], [69706, -8755, -3671], [-81420, -5422, 7870], [-40388, 2916, -7852], [-99853, -3137, -5604], [25914, -6990, -19044], [-50326, 9895, 5223], [71693, 263, 4774], [-136148, -11152, -7444], [-42044, 13412, 15308], [8823, -10182, -10851], [59021, -21728, 267], [-53127, 21755, -2566], [10836, 108, -4984], [-121718, -5069, 4567], [-37332, 3110, 7478], [-2198, 15205, -9761], [-2359, 8311, -164], [-19066, 5263, -4229], [-81684, -9738, -2894], [-111020, 1966, 2772], [-73715, -6589, -776], [17128, 7450, -4342], [-77033, 13338, 5807], [22428, 985, -12001], [51053, -26832, -6901], [-83657, 10583, 14756], [74474, 5215, 8803], [-108346, -4989, -2699], [-100537, 2883, -140], [87604, -7025, 6979], [-110417, 13667, -7594], [56875, -5802, 14609], [-41294, 21426, 14798], [-30598, -7787, -2961], [79552, -9218, 3366], [-15124, 6837, 14507], [-23343, -11627, -612], [69916, -602, 11006], [15625, 9932, 16153], [143252, 9709, 15845], [113500, 6660, -6954], [38432, -13344, 2272], [-16348, 8681, -3889], [-41268, 18556, -9092], [58708, 955, -10955], [14698, -1611, -12107], [15528, 6290, 14208], [-84645, 15306, -10203], [-86878, -18972, -26132], [134520, -2485, 3897], [-41692, -24549, -5397], [-6178, -5724, -14468], [-34660, -7508, -10282], [17059, 15164, 11955], [6763, 7043, -4330], [-21996, 22338, 2124], [38230, 8372, 13260], [-31222, 21879, 6889], [-134416, -14818, -11262], [-192103, 7326, -1443], [125446, -5680, -3328], [-27309, -19253, -6614], [-41152, -1797, -7193], [-26965, 18817, -7346], [202020, 6711, -489], [-26178, -10468, 11556], [-96446, 630, 13346], [8365, 7811, 19292], [172980, -3431, -9315], [-41228, -552, -15454], [101394, -24245, -9237], [116468, 14926, 4582], [-8355, -5587, 16308], [62455, -17996, -11241], [172685, -6251, -6050]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_816_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_816_4_a_s();".
// 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_816_4_a_s(:prec:=3)
    chi := MakeCharacter_816_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_816_4_a_s();".
// 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_816_4_a_s( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_816_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![466, -59, -8, 1]>,<7,R![-2304, -672, -8, 1]>],Snew);
    return Vf;
end function;