
// Make newform 1296.4.a.u in Magma, downloaded from the LMFDB on 20 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_u();".
// 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_u();".
// 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], [8, -1], [-2, -3], [-37, 8], [2, -15], [45, 9], [25, 27], [-26, 19], [-26, 1], [-20, -3], [-52, 54], [17, 98], [-47, 6], [-154, -91], [108, -162], [-467, 136], [272, -105], [-461, -66], [-612, -144], [-349, 243], [556, -309], [-460, 107], [-234, 72], [317, 102], [-872, 91], [1042, -21], [837, -81], [1136, -270], [-1234, 161], [1078, -54], [-80, -467], [-1835, -242], [-533, -30], [-550, -847], [-182, 573], [-988, 939], [-1460, -216], [-1196, -215], [10, 937], [-2340, 288], [-1402, -756], [-1054, 1025], [749, -618], [-3420, 234], [-110, -702], [124, 789], [1510, -435], [1475, -640], [-754, 1497], [-1845, 1575], [-3158, -737], [3089, 1038], [-2709, -423], [-3493, 44], [-5122, -415], [2376, -1566], [2428, -324], [-5290, -915], [766, -1763], [3940, -255], [5534, -559], [-2297, 1701], [-7118, -17], [-1195, -1086], [-1682, 2737], [6964, -1137], [-6721, -744], [3943, 1234], [8408, -1581], [-53, -1808], [-1062, -666], [1492, -1317], [3278, -627], [2833, 351], [3880, 2053], [1090, 289], [-1564, -1890], [-4915, 2222], [6473, -186], [604, 2413], [1532, -141], [-1674, -2430], [569, -27], [7072, -1785], [9197, 386], [1017, -2475], [5465, 498], [10450, -1403], [-3692, 861], [12303, 1413], [-6310, 1421], [-10370, -702], [6823, -3698], [1213, -3576], [-7200, 5796], [4184, -2989], [7245, -603], [6532, 972], [11180, -918], [-2783, 7962], [6282, -504], [14959, -3518], [-107, 6130], [-13115, 4236], [-781, -3645], [6569, 2366], [-2106, 6264], [-980, -3023], [299, 1272], [-5132, 4929], [-21328, -486], [3131, -3448], [4093, -5466], [376, -5400], [20485, 1738], [25369, -1128], [-14202, 2970], [1898, 269], [14948, 1223], [-2428, -6549], [146, -1095], [22060, -1241], [1665, -1341], [4408, 3327], [16470, 324], [17444, 759], [-6444, -5652], [18214, 1689], [12062, -6099], [-7319, -5481], [-2150, -7469], [3472, -2019], [5834, 8100], [-1342, -2863], [2378, 9165], [-4086, -936], [4084, -6375], [12140, 5039], [-11583, -7371], [-5753, 7317], [-13058, -1439], [12472, -8895], [22500, -1440], [1838, 12852], [-11476, -4537], [-21094, 3909], [6094, -1259], [-7571, 7836], [22680, -7344], [4592, -8709], [342, 1008], [-28973, 4401], [-32696, 1801], [-23321, -8688], [-17704, 2231], [41794, 1134], [-26558, 3961], [-9826, -1080], [10124, 1115], [-10099, 1430], [-18999, -2115], [6982, -885], [-11556, -8964], [11429, 242], [-13672, -8929], [-29216, 7128], [37244, -3417], [-13822, 8748], [-30088, -6517], [11915, 9548], [51392, -2949], [-41372, 541], [28379, 5376], [-7670, 9195], [-31402, 10889], [11329, 5766], [-35442, -4356], [-30404, -3780], [-4624, -11157], [19546, -11559], [7577, -17434], [-22246, 525], [3123, -693], [-3590, -7541], [-20168, 8479], [6752, -810], [-13304, 18015], [18533, 5394], [-63036, 2124], [6455, -7641], [-4105, 8828], [27997, -7425], [2908, 10783], [-20385, 15525], [-43597, -1756], [30431, 7572], [-32956, 18615], [16471, -22976], [-18990, 18774], [38114, -8083], [-38630, -6015], [43184, -4785], [21683, 84], [13131, -20799], [42966, 6228], [7504, 19224], [-35549, -13382], [-14453, -1124], [40759, -9930], [48845, -7479], [22094, -21979], [-11342, 16737], [-40564, 12455], [-36368, -3923], [13025, 3630], [20068, 17493], [32653, -15938], [-18378, -6246], [-29512, -2773], [-24226, 13989], [34576, 4677], [9053, 2510], [-9614, -21114], [51085, -5192], [-37222, -15783], [1810, -9395], [29556, -28476], [-29342, 18501], [-424, -12781], [-10870, 26373], [-15716, 6264], [-48602, -7437], [-7129, 15992], [73888, 1419], [62342, -11395], [-55870, -7935], [-1098, -6516], [-14759, 34732], [33858, 21654], [87821, -3070], [-39260, 3888], [-68276, -13287], [-20626, 1620], [-48961, 28124], [-57016, 20915], [23164, 17604], [3691, 17038], [-40772, 30525], [52686, 4986], [-67750, -5127], [65619, -117], [52876, -7091], [-39022, -7539], [77158, -8819], [-59913, -5967], [94448, 4698], [-17012, -29001], [-64080, 846], [-43387, 24921], [-55208, -13521], [-22105, -1792], [42644, 13899], [-36394, 3780], [70550, 1061], [47455, -15780], [52740, -22122], [-91349, -13436], [50047, -13278], [-14302, -21655], [20684, -2337], [-31484, 6264], [-22237, 25284], [-17138, -8481], [49799, -13236], [73708, -324], [55612, -23111], [14582, -29967], [-14929, 22167], [-69229, -10288], [-31742, 15643], [18106, 24603], [109502, -19783], [85466, -17727], [-25103, 1212], [-22230, 37242], [32186, -43524], [24776, 6119], [-50780, -9849], [67527, -23085], [106336, 9847], [18801, 17271], [61883, -33148], [-76643, -22724], [-20392, 28587], [95858, 15821], [82942, 7449], [-50570, 3889], [-143460, -3744], [-31556, 18555], [103313, 15654], [119718, -14364], [83104, -33264], [-121292, 15553], [32344, 11949], [-61342, -27324], [-25516, 6479], [-33136, -8745], [10486, -17513], [-42928, 13986], [41192, 28331], [-42264, 1386], [103978, 14365], [-137504, 11553], [13788, -3420], [21251, -20277], [359, 3716], [130348, 109], [26651, 31836], [-82, -49699], [-116867, 3174], [-27115, 42042], [3924, 35118], [-115130, 30402], [-110006, 23257], [67961, -2943], [22705, 7047], [-90551, 11130], [68372, -23473], [-68634, 39852], [-19384, 46011], [-23788, -23077], [-27416, -7869], [-132301, -2836], [5641, -37341], [114372, 26568], [36938, 8748], [7487, 9908], [23735, -30876], [-58052, -38880], [5816, 39], [-102626, 21817], [-94564, 22643], [-74972, -16761], [63838, -43559], [-50535, -21393], [-149956, 3078], [-99641, 37032], [100304, 8207], [19098, -18828], [86092, 8997], [110729, -33723], [-67870, 4481], [16468, 60747], [14204, 2631], [-39834, -25020], [-22868, 32149], [-104580, 23040], [78722, -7435], [-6742, -50203], [22682, -7611], [-76049, 30664], [-29448, 34740], [-83701, -5320], [-4565, 69201], [38279, -41964], [83152, -57041], [152062, -20466], [-174931, 26217], [-38332, 58391], [-92099, 12663], [15652, -34343], [-141740, -19205], [-135542, 10923], [-71062, 16416], [-60551, 46504], [63774, -29538], [30134, 19656], [-122427, -20727], [23474, 40161], [9370, -39527], [-84871, -11242], [-82136, 63288], [37027, 62632], [50407, 1662], [43668, -49500], [-117542, 31497], [-36376, -20193], [1672, 9180], [-68732, 55225], [-24145, 6420], [-121508, -10709], [-44577, -26055], [-64127, -14394], [-44290, 28061], [16958, 525], [21328, 61668], [-87803, -18170], [-70193, -23682], [-127936, -15157], [84062, 2073], [-13959, 12933], [-170588, 47157], [-54622, -12871], [46746, 4068], [44764, -69552], [-16558, -40911], [-14723, -42974], [195253, -10092], [-79876, 11483], [-115657, -6252], [110890, -29159], [-93591, 32463], [49255, -47676], [-88522, 54669], [57726, 9396], [90054, 12546], [48562, 45429], [229077, -7407], [-95624, 24229], [-72044, 87247], [116804, 5238], [19484, -14977], [-226691, -9080], [163082, -15660], [216476, -4897], [-153217, 14192], [-266598, 17604], [-107732, 18144], [-48520, 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_u();".
// 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_u(: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_u();".
// 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_u( : 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;