
// Make newform 1296.4.a.i in Magma, downloaded from the LMFDB on 24 April 2024.
// 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_i();".
// 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_i();".
// 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 := [-8, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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)
    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+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 := [[0, 0], [0, 0], [-7, -1], [-5, 3], [29, 8], [-13, 15], [-54, 9], [52, -27], [7, 19], [25, 1], [-23, 3], [2, -54], [-115, 98], [-41, -6], [245, -91], [54, -162], [331, 136], [167, 105], [-527, 66], [756, -144], [-106, -243], [247, 309], [353, 107], [162, 72], [419, -102], [781, 91], [1021, 21], [-756, -81], [866, 270], [1073, 161], [1024, 54], [547, -467], [2077, -242], [-563, 30], [1397, -847], [391, -573], [-49, -939], [-1676, 216], [1411, -215], [-947, 937], [2052, 288], [-2158, 756], [29, 1025], [131, 618], [3186, 234], [-812, 702], [913, -789], [1075, 435], [-835, -640], [743, -1497], [270, 1575], [3895, -737], [4127, -1038], [3132, -423], [3449, 44], [5537, -415], [-810, -1566], [2104, 324], [-6205, 915], [997, -1763], [3685, 255], [-4975, -559], [-596, -1701], [7135, -17], [-2281, 1086], [-1055, 2737], [5827, 1137], [-7465, 744], [-5177, 1234], [6827, 1581], [1861, -1808], [1728, -666], [175, 1317], [2651, 627], [3184, -351], [-5933, 2053], [-1379, 289], [-3454, 1890], [2693, 2222], [6287, 186], [-3017, 2413], [1391, 141], [4104, -2430], [542, 27], [5287, 1785], [-9583, 386], [1458, -2475], [5963, -498], [-9047, -1403], [-2831, -861], [-13716, 1413], [4889, 1421], [-11072, 702], [-3125, -3698], [-2363, 3576], [1404, 5796], [-1195, -2989], [-6642, -603], [7504, -972], [10262, 918], [5179, -7962], [-5778, -504], [-11441, -3518], [-6023, 6130], [-8879, -4236], [-4426, 3645], [-8935, 2366], [-4158, 6264], [4003, -3023], [1571, -1272], [-203, -4929], [-21814, 486], [317, -3448], [-1373, 5466], [-5024, 5400], [-22223, 1738], [24241, 1128], [11232, 2970], [-2167, 269], [-16171, 1223], [-8977, 6549], [-949, 1095], [-20819, -1241], [-324, -1341], [7735, -3327], [-16794, 324], [18203, -759], [12096, -5652], [19903, -1689], [5963, 6099], [-12800, 5481], [9619, -7469], [1453, 2019], [13934, -8100], [4205, -2863], [11543, -9165], [5022, -936], [-2291, 6375], [-17179, 5039], [18954, -7371], [1564, -7317], [14497, -1439], [3577, 8895], [-21060, -1440], [14690, -12852], [16013, -4537], [-17185, -3909], [-4835, -1259], [265, -7836], [-15336, -7344], [-4117, 8709], [-1350, 1008], [-24572, -4401], [30895, 1801], [-32009, 8688], [15473, 2231], [42928, -1134], [22597, 3961], [-10906, 1080], [-11239, 1115], [8669, 1430], [21114, -2115], [6097, 885], [20520, -8964], [-11671, 242], [22601, -8929], [-22088, -7128], [33827, 3417], [-5074, -8748], [36605, -6517], [-21463, 9548], [48443, 2949], [40831, 541], [33755, -5376], [1525, -9195], [20513, 10889], [17095, -5766], [39798, -4356], [-34184, 3780], [-15781, 11157], [7987, 11559], [9857, -17434], [-21721, -525], [-2430, -693], [11131, -7541], [11689, 8479], [5942, 810], [4711, -18015], [23927, -5394], [60912, 2124], [-1186, 7641], [-4723, 8828], [20572, 7425], [-13691, 10783], [4860, 15525], [45353, -1756], [38003, -7572], [-14341, -18615], [6505, -22976], [216, 18774], [-30031, -8083], [-44645, 6015], [38399, 4785], [21767, -84], [7668, -20799], [-49194, 6228], [26728, -19224], [48931, -13382], [15577, -1124], [30829, 9930], [41366, 7479], [-115, -21979], [5395, -16737], [28109, 12455], [40291, -3923], [16655, -3630], [37561, -17493], [-16715, -15938], [24624, -6246], [32285, -2773], [-10237, -13989], [39253, -4677], [-11563, 2510], [-30728, 21114], [-45893, -5192], [-53005, 15783], [7585, -9395], [-1080, -28476], [-10841, -18501], [13205, -12781], [15503, -26373], [-9452, -6264], [-56039, 7437], [-8863, 15992], [75307, -1419], [-50947, -11395], [-63805, 7935], [7614, -6516], [-19973, 34732], [-55512, 21654], [-84751, -3070], [-35372, -3888], [-81563, 13287], [-19006, -1620], [20837, 28124], [36101, 20915], [40768, -17604], [-20729, 17038], [-10247, -30525], [-57672, 4986], [-72877, 5127], [-65502, -117], [-45785, -7091], [-46561, 7539], [-68339, -8819], [65880, -5967], [99146, -4698], [-46013, 29001], [63234, 846], [-18466, -24921], [-68729, 13521], [23897, -1792], [56543, -13899], [-32614, -3780], [-71611, 1061], [31675, 15780], [-30618, -22122], [104785, -13436], [36769, 13278], [35957, -21655], [18347, 2337], [-25220, -6264], [3047, -25284], [-25619, 8481], [36563, 13236], [73384, 324], [-32501, -23111], [-15385, 29967], [7238, -22167], [79517, -10288], [16099, 15643], [42709, -24603], [-89719, -19783], [67739, 17727], [-23891, -1212], [-15012, 37242], [-11338, 43524], [-30895, 6119], [-60629, 9849], [-44442, -23085], [-116183, 9847], [-36072, 17271], [-28735, -33148], [99367, -22724], [8195, -28587], [-111679, 15821], [90391, -7449], [46681, 3889], [147204, -3744], [-13001, -18555], [118967, -15654], [-105354, -14364], [49840, 33264], [105739, 15553], [44293, -11949], [-88666, 27324], [19037, 6479], [-41881, 8745], [7027, -17513], [-28942, -13986], [-69523, 28331], [40878, 1386], [-118343, 14365], [-125951, -11553], [-10368, -3420], [974, 20277], [-4075, 3716], [-130457, 109], [58487, -31836], [49781, -49699], [-113693, -3174], [14927, -42042], [-39042, 35118], [-84728, -30402], [86749, 23257], [65018, 2943], [29752, -7047], [-79421, -11130], [-44899, -23473], [28782, 39852], [26627, -46011], [46865, -23077], [-35285, 7869], [135137, -2836], [-31700, 37341], [-140940, 26568], [45686, -8748], [-17395, 9908], [-7141, 30876], [-96932, 38880], [5855, -39], [80809, 21817], [71921, 22643], [-91733, 16761], [-20279, -43559], [71928, -21393], [-146878, -3078], [-62609, -37032], [-108511, 8207], [-270, -18828], [95089, -8997], [77006, 33723], [63389, 4481], [77215, -60747], [16835, -2631], [64854, -25020], [-9281, 32149], [81540, 23040], [-71287, -7435], [56945, -50203], [15071, 7611], [45385, 30664], [-5292, 34740], [89021, -5320], [64636, -69201], [-3685, 41964], [-26111, -57041], [131596, 20466], [-148714, -26217], [-20059, 58391], [-79436, -12663], [18691, -34343], [160945, -19205], [-124619, -10923], [-54646, -16416], [14047, 46504], [-34236, -29538], [49790, -19656], [143154, -20727], [63635, -40161], [30157, -39527], [96113, -11242], [-18848, -63288], [-99659, 62632], [52069, -1662], [5832, -49500], [-86045, -31497], [-56569, 20193], [10852, -9180], [13507, 55225], [-17725, -6420], [132217, -10709], [70632, -26055], [-78521, 14394], [16229, 28061], [17483, -525], [82996, -61668], [105973, -18170], [-93875, 23682], [143093, -15157], [86135, -2073], [1026, 12933], [-123431, -47157], [67493, -12871], [-50814, 4068], [-24788, 69552], [-57469, 40911], [57697, -42974], [185161, 10092], [68393, 11483], [-121909, 6252], [-81731, -29159], [61128, 32463], [1579, 47676], [-33853, -54669], [-67122, 9396], [-102600, 12546], [93991, -45429], [-221670, -7407], [71395, 24229], [-15203, 87247], [122042, -5238], [-4507, -14977], [235771, -9080], [147422, 15660], [-211579, -4897], [139025, 14192], [248994, 17604], [-89588, -18144], [29081, 19439]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1296_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1296_4_a_i();".
// 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_i(: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_i();".
// 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_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1296_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![48, 15, 1]>],Snew);
    return Vf;
end function;