
// Make newform 1296.4.a.l in Magma, downloaded from the LMFDB on 25 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_l();".
// 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_l();".
// 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 := [-26, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 3]];
    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)
    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], [-5, -1], [-9, 1], [11, -2], [31, 1], [2, 1], [-64, 5], [-35, -1], [115, -7], [-107, -3], [138, 14], [235, 2], [55, 24], [-249, -15], [82, 14], [-83, 2], [-517, 15], [577, -12], [172, 32], [-166, -21], [-181, -13], [-621, -21], [-226, 40], [-53, 22], [-649, 43], [-767, -81], [-1456, 1], [-358, 18], [-357, -87], [-1016, -66], [1001, -59], [619, -34], [-915, 88], [-649, 145], [-797, -159], [1331, 3], [-780, 16], [-1479, -111], [-3009, 33], [3164, -56], [-990, 116], [-4049, 29], [683, 246], [134, -230], [1244, -106], [2813, 197], [1615, 57], [-1461, -90], [-1933, 225], [-2234, 287], [477, 3], [711, 350], [-1528, 55], [4695, 108], [-149, 341], [226, -382], [-4760, 132], [-673, -99], [-2729, -187], [-3071, -63], [-6181, 25], [-1952, -453], [-3499, 139], [5871, 50], [2123, -47], [-2809, -49], [3831, -376], [3033, -96], [-1809, -325], [-677, -160], [-1704, 282], [-4541, 147], [-809, -131], [-1332, 73], [-487, -11], [-625, -647], [-5974, -234], [5059, -322], [-6441, -346], [14037, 141], [-525, 371], [1600, -658], [7994, 45], [9931, 399], [7359, -468], [3114, 189], [-1021, -462], [-8333, 341], [-9475, 389], [8840, 91], [2595, -231], [6728, -226], [11077, 524], [12157, 162], [4692, 852], [9487, 299], [1262, 253], [-16544, 36], [3438, -910], [9451, -228], [11666, 136], [-1647, -1392], [5471, 178], [-4455, -170], [3578, 699], [3175, -112], [-2818, -1256], [-9287, -55], [7907, -1272], [-8271, -431], [7106, -462], [21763, -232], [-1853, -336], [-16992, -368], [9223, 650], [-18839, 810], [3912, -618], [-2125, -971], [2959, 23], [-973, 939], [19927, -95], [-12985, 463], [24816, -147], [-22853, -9], [4234, 1532], [-23921, 319], [-20400, -372], [-5429, -27], [-3481, -1323], [23740, 225], [1137, -2241], [17529, -995], [9566, -1068], [13503, 1209], [-14285, -875], [8322, 1056], [-2423, 873], [-11409, -1041], [-15982, -179], [21328, 171], [2027, 841], [-9835, 65], [-6620, -1240], [-21902, -44], [-3945, -1161], [11387, 1125], [-3009, -435], [2961, -2186], [-27896, 1208], [-17553, -637], [-13274, 32], [-19864, -481], [11213, 601], [-13057, 254], [-18765, 159], [11080, 42], [5127, 753], [16038, -1576], [5003, 163], [13059, 672], [-36606, 885], [-3467, 1359], [-1752, 3012], [-26257, 562], [7771, 2591], [-13544, 600], [-16681, 2463], [20126, 1116], [-761, -2269], [2255, -3614], [16031, 315], [-29971, -2099], [-2373, -1840], [-1063, -697], [-34165, 1729], [8359, 792], [20730, -2820], [13640, -3268], [-8737, -1989], [-5793, -1019], [-18209, 2696], [19811, 1989], [-21342, -1725], [-5143, 2503], [15179, -2105], [-25282, 1542], [13035, 151], [11023, -1838], [-10976, 1964], [-6830, -2129], [5739, 3978], [-9864, -4463], [34127, 1159], [-39368, 1259], [8327, -1820], [-44861, -1772], [-7121, -3089], [55511, 736], [-29216, -2062], [-16437, 981], [-4921, -1915], [49555, -1481], [49847, 276], [-27664, -2753], [20186, 940], [-42136, 2720], [2333, 256], [-63625, -980], [23901, -1436], [-40350, -1663], [-51313, -59], [-6881, 2253], [55255, -1513], [-7863, 2853], [39863, -1602], [9733, 3189], [32595, -498], [50648, 1870], [-66841, 115], [-17633, 1285], [-28415, -891], [51187, 2078], [-42992, 186], [-31107, -3486], [27775, -383], [-52869, 645], [4328, 436], [-56061, -1007], [1535, -2165], [64491, 1757], [33556, 48], [-11363, 1623], [-22913, 344], [-16353, -845], [-36673, 673], [-22097, -4007], [-74382, 636], [5325, 2094], [-10672, -1214], [-32993, -1348], [-35468, 24], [42337, 3345], [7154, 4476], [14219, -4004], [46415, -677], [75728, 1532], [-54583, -572], [-26555, -2931], [24528, 2670], [-32449, 2049], [29058, 1011], [75781, 845], [-27205, -27], [-49521, 1149], [24076, 887], [-70558, 2394], [47527, 3591], [59142, 4182], [41258, -351], [18443, 1847], [28527, -882], [47555, -3885], [-108438, -1804], [49687, -4099], [-51341, -4182], [19202, 646], [87903, -1500], [101377, 2112], [-3657, 3537], [13023, 4103], [-16836, 2032], [-15529, 7908], [-3551, -6621], [13955, -3396], [-41000, -2796], [9713, -1463], [43763, 1401], [-61318, -2049], [63979, 5414], [24257, -3641], [8089, -657], [-75037, -2003], [11111, -2703], [-106379, 1662], [-37140, -5466], [-42650, -2372], [-67261, 2407], [-108017, 2391], [-73410, -1605], [39435, 231], [-135580, 97], [61871, 868], [47265, 5190], [-105721, 3339], [13787, -611], [-10525, -3547], [-67405, 2233], [35676, -2376], [-36565, 443], [12991, -1178], [88314, -2724], [13072, 3000], [49745, -4703], [64209, 2581], [-97162, 756], [3623, 6943], [129851, -1257], [66529, 5579], [56458, -7430], [-10297, 8371], [48138, -2670], [-78429, -1371], [87965, 3929], [159664, 1172], [-42190, 3123], [11651, -2894], [46309, -2587], [-21817, 2892], [62151, 6021], [92419, 2448], [-377, 7834], [42538, 7670], [66448, -66], [19823, 5473], [9222, -5335], [-25100, 6225], [-29837, 2700], [16743, 2271], [-115838, -148], [-13945, -309], [138995, -1781], [23391, 7795], [9111, -4110], [-41768, 8637], [-24436, 6448], [106598, 5508], [-56573, -3292], [-107605, -5532], [102076, -3744], [149011, -3017], [-55229, 7889], [-49869, -525], [-18993, 8167], [36227, -5927], [-5596, 2233], [-47062, -3642], [133207, 1206], [61123, 6335], [-80354, 188], [118173, 3445], [75178, 2317], [66095, -2519], [160531, -117], [-32137, -8649], [-95654, -1756], [-61107, -5355], [-75620, 5192], [-14797, 13645], [60683, -7511], [73243, 5197], [-120809, -6568], [135516, -4404], [-114581, 4190], [-1696, -2161], [-72597, -8764], [-66733, -2705], [-17116, 10802], [86242, 7345], [-104641, -4169], [117744, -8663], [-131431, 1369], [-172717, 1795], [45401, -7993], [45034, -7904], [-62247, 6666], [-2316, 11946], [185662, -104], [57818, 4897], [21887, -4263], [-8417, 10073], [-32425, -10874], [189216, 5392], [119819, 3928], [142709, -4132], [-118904, -52], [-82289, -8667], [47931, -6289], [147764, -1780], [137337, -6303], [34259, -1596], [-62965, 403], [-142052, -3553], [50151, -7256], [70263, -327], [-37561, 9573], [-1404, -3356], [-29709, -330], [-168035, 300], [12079, 8219], [-214621, -423], [172442, 109], [55813, 12909], [-30105, 7953], [-160050, 2028], [14188, 12360], [27727, 3265], [31735, -13438], [-127631, -9666], [-150389, -4885], [109019, -2700], [162127, -3007], [-109996, -3959], [-49469, -9294], [-86145, -1723], [-28126, -6836], [-66544, -5714], [-106333, 5177], [-105518, -4519], [-160759, 3877], [-49385, -8881], [5474, 16038], [107071, 8663], [20541, -2574], [-31762, -7260], [87215, -13721], [-34249, -5090], [100590, -6396], [-17300, -12456], [-210677, 2015]];
    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_l();".
// 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_l(: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_l();".
// 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_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1296_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-216, 9, 1]>],Snew);
    return Vf;
end function;