
// Make newform 966.4.a.g in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_966_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_966_4_a_g();".
// 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_966_4_a_g();".
// 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 := [14, -11, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-8, 1, 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_966_a();"
function MakeCharacter_966_a()
    N := 966;
    order := 1;
    char_gens := [323, 829, 925];
    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_966_a_Hecke(Kf)
    return MakeCharacter_966_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 := 4;
    raw_aps := [[2, 0, 0], [3, 0, 0], [-4, -3, 1], [-7, 0, 0], [-24, 8, -5], [-8, 19, 4], [-44, 2, -15], [-24, -12, 1], [23, 0, 0], [-104, 4, 29], [-62, -12, -13], [-234, 6, -27], [-148, 82, 71], [-152, -61, 8], [84, -18, -68], [-12, -39, 87], [84, -113, 141], [-46, -9, -156], [-50, -129, 99], [-106, -145, -28], [120, -190, 13], [-546, -268, 65], [-376, 92, -237], [-104, -133, 134], [144, 22, 97], [86, -39, -161], [-436, -56, 224], [-372, 231, 70], [32, 119, -85], [74, 139, -111], [-78, 247, -22], [-138, 806, -313], [100, -284, 383], [588, -5, -259], [1196, -446, -76], [-476, -58, -568], [-600, 30, 538], [-1100, 253, -89], [834, 1030, -327], [1464, -678, -239], [1064, 63, -421], [530, 194, 395], [-1008, 1162, 372], [-1514, 494, 216], [532, 317, -84], [-732, 1329, -597], [1958, -1114, -351], [-1156, -717, 217], [-134, 317, 133], [1448, 577, 123], [-1038, -817, 591], [596, 1169, 167], [-2996, 334, 395], [-1110, -42, 692], [2118, -1458, 250], [-1734, -474, 549], [1524, -1515, -1070], [3350, 1710, -461], [188, -927, -452], [-2462, 906, -1464], [-2694, 57, 691], [-1284, -1316, 608], [1170, 1132, 493], [2546, -1313, 1658], [3426, -1168, 326], [-134, 849, -975], [-560, -1152, -118], [-96, 2081, 186], [-430, 214, -1127], [2382, -501, 791], [7592, -1026, 115], [-264, 907, 341], [-4954, 1699, -1412], [-258, -914, -763], [1434, -1492, 486], [7210, -244, -1241], [2078, 2510, 841], [-2078, 2418, -1610], [1612, 674, -643], [1308, -2272, 647], [-666, -913, 1239], [-6306, 127, -618], [-6186, 1937, -600], [1242, 1942, 84], [-2342, 880, 1039], [3976, 840, -1692], [1310, 3337, -1159], [-8454, 1629, -385], [6282, -1283, -3009], [2086, -2592, 2297], [764, -3400, 2849], [12598, 82, 971], [2178, -1576, -401], [10274, 3535, -1022], [-2904, -159, -2279], [-5240, -1967, -1257], [2518, -1630, 2582], [12194, -396, 2004], [-5670, 376, -592], [-4646, 698, 3938], [-6228, 53, 117], [3692, -2434, 3406], [5708, 439, 1478], [-1682, -6076, -602], [-4076, 2676, 2753], [7614, 4408, -2572], [-2058, -3297, -3084], [1042, 1814, -1580], [-2910, -13, -2726], [-7542, 2297, 2655], [-7806, -4375, 1532], [1402, 5656, -961], [12492, -1863, -1250], [-13904, 379, -1254], [-12230, -1770, 1459], [-11260, -683, -1328], [-10160, 6059, -4298], [6152, -2873, -4017], [-6498, -2081, 3763], [22044, -996, 939], [20130, 1410, -357], [-13732, -2284, -1955], [5466, 5005, 1294], [-23590, -3134, -181], [-20578, 1307, -2152], [-4080, -929, -4583], [-2962, 145, -5776], [-4634, -8300, -787], [-890, 6984, -4703], [-3072, 1058, 3662], [-16774, 318, -1003], [-2548, -1661, -3135], [-5204, 7925, 4637], [-14042, -2546, -1877], [-1418, -904, -54], [24442, -3698, 3532], [8186, 4008, -4421], [-3594, 725, 6885], [33772, 1794, -1276], [-18612, 4767, -2670], [-12918, -10682, 2373], [-15690, 5070, 1426], [-7648, -6765, -2973], [1270, -9357, 5073], [18692, -248, 3477], [6882, -2661, 8126], [30574, -42, 3108], [-19866, -7670, 412], [-28672, -2864, -150], [-12128, 8602, -634], [-19770, -6632, -410], [-14878, -11534, 2724], [-24570, -4743, 1104], [-21614, 5239, -290], [-22650, 3461, -2485], [-10592, 2402, 2672], [-19906, 318, -4073], [-10570, -301, -2381], [25868, 6352, -201], [-34796, 4236, 376], [-244, 6628, -7210], [-21032, 8677, -566], [-2212, -4664, -386], [-19824, -1095, -2290], [-29132, -6739, 2388], [3030, -2976, 7171], [-7378, 5921, -3358], [5756, -4832, -5875], [1266, -2991, -669], [-10568, 1305, 338], [-38044, 2993, -3028], [-2506, 4428, -6456], [-10414, -7551, 7044], [-22828, 9850, -5735], [10280, -13220, 6636], [-21004, 10700, 217], [38414, -743, 2958], [-8426, 1253, 11641], [-13888, -6521, -2411], [-15276, 9881, -9245], [-20520, 12053, 1065], [-12748, 2311, -6852], [16446, 17389, -501], [30196, -3753, 9022], [-4346, -10428, 4651], [19786, 501, -8260], [12822, -9716, 11216], [-11108, -5770, -5729], [6018, -3579, 5419], [20518, -1634, -2329], [-6010, 2427, 1851], [31160, 37, -729], [-6138, -2918, 2836], [39540, 726, -7971], [-14208, 8741, -5166], [-10968, 8283, -6606], [196, -10961, -7062], [16700, -12690, 12626], [29518, -4920, -624], [1032, 10115, 9903], [-37312, 7080, -9342], [23936, -13560, 3940], [11998, 10553, 7561], [18564, 11915, 6402], [12572, 16498, 3481], [14022, -7884, 10632], [-39546, 5202, -3625], [-13120, 17481, -9525], [32278, -11845, 6671], [39738, -770, -2413], [8870, -13882, -3214], [-2950, 8981, -9935], [-9178, 3060, 4487], [18022, -18952, -5142], [-15970, -13063, 11314], [20510, -667, 1813], [43058, -3214, -6863], [25712, -6809, -6292], [16786, -4790, -3131], [56336, -3686, 6065], [44940, -7595, -12338], [-3120, 556, 6810], [-38912, 14079, 11396], [13596, 6960, -10596], [-20322, 12348, 2187], [19302, 7661, -12131], [33408, 18552, 963], [-54624, 3000, 7224], [-48646, 5495, -8304], [-498, 6038, -453], [15880, -7644, 1013], [-14700, 10657, -1738], [36096, -3013, -8115], [-40534, 3316, -3158], [37104, -17687, -16372], [7990, 20653, -9008], [-16618, 11714, -15594], [8794, -16608, 8445], [33906, -13742, 2663], [926, -24986, 2651], [-35112, -2984, 5903], [-35560, -23529, 7133], [9016, -8426, 638], [22388, -13270, 22839], [-15532, -6026, -7903], [-29158, 9375, -7294], [13904, 6780, 11872], [-7798, -19408, -8210], [34752, 830, 4355], [-21786, 11334, 1719], [27274, -21986, -14875], [27550, 1056, -3636], [-70246, 10100, -1137], [60904, -13936, 4585], [18684, -3040, 18215], [712, 35610, -3570], [40654, 9610, 3675], [-12380, 26016, -7597], [41776, -2343, -8368], [-12260, 12768, -217], [17270, -5371, -2060], [37570, 6012, -8680], [-39426, 27847, 4563], [-36438, -992, 10353], [-39484, -10795, 1152], [-60576, -11390, 8505], [-11688, 3572, -3422], [-28956, 16116, -7199], [-77024, 17112, 2765], [17746, -20825, 6419], [66012, 5872, 10001], [34008, 35454, -7913], [3352, -9375, -4398], [58864, 5386, 9304], [-22216, -16528, -4443], [-11108, -21440, 398], [-23002, -25970, 7189], [-12972, 29150, 1871], [-4584, 18074, -24357], [56008, -876, 10257], [-26612, -11262, -7628], [40282, -3457, 13648], [-109978, -3128, 519], [-48354, -17290, -6375], [-364, -23275, 3677], [33202, -36818, -4967], [-60636, 1990, -5905], [24064, -13648, 10366], [37382, -4741, -13372], [-30310, -2472, -6006], [77934, 4855, -3936], [-136516, -1053, 4116], [43252, 35535, -12708], [-76832, 15822, 12211], [-52578, 15112, -11498], [-81002, -12840, 1507], [-50896, -11496, 11068], [-68768, 19809, 19954], [43850, -20484, -9423], [-9874, 13860, 21697], [-81168, -6407, -2976], [-64344, 30896, -8826], [-107638, 180, 3343], [83728, -5025, -10887], [29674, -26732, 18970], [43348, 44942, -1987], [-49388, 24733, 20155], [-3626, -15516, -11925], [48632, -28202, 30662], [-55484, 27795, 15512], [-30782, 31580, -5313], [4090, -26920, 2103], [46358, 8247, 1217], [43494, -15380, 4387], [53318, 5806, -16427], [-57186, -1696, 8018], [-68562, -25576, -4197], [-41190, -47298, 2697], [44092, -14708, -537], [45438, -17538, 9694], [-94442, -1872, 1280], [-45012, -6719, -19602], [45682, -1487, 17089], [-92714, 17880, 15573], [58524, -23814, 3985], [-53754, 32107, 527], [-75260, 15320, -27029], [-105976, -13485, 471], [11220, -10666, -25156], [56444, 37666, 1818], [16158, -38004, 3166], [110052, 5226, -5685], [-37622, 8395, -8230], [16272, -22453, 36291], [17394, 22198, -13482], [7976, 9240, 18146], [68716, -25630, -29806], [-28786, 21526, 4142], [-38406, 46645, 22321], [-32596, 26383, 25359], [77868, -33968, 35993], [80442, -11396, -9868], [48492, -10305, -30634], [109386, 21746, -11727], [-14784, -25064, -10150], [-1106, -56311, 6646], [-55062, -16615, 6309], [-10372, -12221, 22593], [-30020, -6765, -35625], [76718, 38878, -17887], [77586, -31433, -6688], [74300, 23704, 957], [73528, 35062, -6321], [71764, 12045, -5769], [-72706, -10312, 2057], [-5986, 3312, 6014], [109216, 31502, -9294], [29364, -11198, 34383], [-47780, 14708, 30519], [-15758, 10310, 28537], [64014, 15052, 3997], [-1708, -24358, -15317], [105662, -8242, 7487], [-98030, 3524, 2934], [87228, -2170, -2772], [12890, 8820, -20534], [27780, -42643, -13940], [10628, -14334, -17616], [-30820, -17435, -530], [98630, 16243, 6664], [-42958, 38652, -19311], [5808, -1528, -15068], [-19340, 4166, 10250], [-64140, -5480, 9676], [38140, -52428, -22055], [-78524, -5735, -20277], [62044, 21183, -14449], [35538, -57950, 3146], [-163966, 26780, 992], [16664, -19268, -41023], [16106, -3266, -11771], [-47792, -1079, -35926], [148788, -2582, 18472], [111292, -46249, -4412], [-70358, -15929, 12531], [-37378, -55779, 27150], [139714, -14937, -22790], [66590, 27588, -4484], [3768, -31066, -10723], [-42644, 15294, 42098], [-26184, 7692, 35397], [31246, 11369, -26899], [128048, 5228, -9566], [170668, -20718, -16232], [-102270, 8175, 5256], [125154, 5667, 23277], [-150306, 19480, 2599], [18748, 17230, 28457], [14624, 72381, -6006], [32448, 19818, 28197], [100524, 28040, 17763], [-149148, 8999, -32192], [8968, -12382, -29662], [12872, -6715, -5218], [-88704, 16135, 38048], [17098, 55267, -22074], [202088, -14544, -4044], [19082, 38626, -37372], [-13030, 50164, 17474], [166528, 4721, -12409], [-139420, 4415, -22632], [6150, -27266, 35866], [574, 44232, -28874], [-39004, 8141, 31054], [21536, 35423, 14088], [76062, 5028, 43100], [-58666, 17528, 12737], [20386, -72296, -13861], [38420, -7056, 9607], [162952, -17598, 30816], [-223798, 14020, 1333], [18322, -62078, 34717], [-65300, -37075, 30087], [-35190, -1605, -5666], [-86580, -10319, -20116], [28970, 16998, -12474], [-11252, -28953, 4808], [-30626, -2002, -35756], [-136740, -2625, 9781], [37290, -53469, 4450]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_966_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_966_4_a_g();".
// 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_966_4_a_g(:prec:=3)
    chi := MakeCharacter_966_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_966_4_a_g();".
// 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_966_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_966_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-724, -29, 15, 1]>],Snew);
    return Vf;
end function;