
// Make newform 294.4.a.l in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_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_294_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_294_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 := [-2, 0, 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_294_a();"
function MakeCharacter_294_a()
    N := 294;
    order := 1;
    char_gens := [197, 199];
    v := [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_294_a_Hecke(Kf)
    return MakeCharacter_294_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], [-3, 0], [-6, 1], [0, 0], [2, -6], [-24, -15], [-66, -11], [-60, 46], [-38, 102], [-56, -150], [-216, -54], [-140, 180], [-18, 127], [-64, -288], [132, -338], [134, 192], [-168, 298], [252, 353], [-192, 144], [-198, -342], [156, -595], [-424, 300], [324, 80], [306, -175], [1092, 133], [810, 351], [264, 350], [694, 402], [-680, -1008], [246, 912], [-1028, 744], [-156, -1008], [1164, -1350], [180, 844], [926, -216], [-2092, 108], [2100, -1193], [-3008, -636], [-108, 986], [390, 609], [2478, 810], [408, -417], [1354, 90], [-1918, 1104], [4042, 600], [-2304, -876], [-1116, -2244], [-3912, -1332], [-3264, -594], [1632, -237], [1500, -2106], [1170, -3498], [-1116, 3615], [-5664, 170], [-2778, -2253], [270, 3462], [-1506, -1681], [-6000, 334], [3490, -864], [-3220, 2790], [-5292, 746], [-2430, 4811], [-5460, 938], [-5100, 26], [-1824, -3951], [-3886, -2016], [9988, 840], [1760, 5388], [6810, -798], [5316, -3261], [7194, -2057], [-82, 3354], [0, 4904], [5506, -6072], [3148, -1560], [4824, -2932], [-7784, -2886], [3612, 1081], [-11508, -618], [11196, 3309], [5016, 7846], [1530, 5064], [-3966, -162], [5592, -117], [6792, -2136], [-50, -4158], [-4602, 2880], [9582, 336], [6870, -1315], [-4460, -1884], [-3816, -2606], [-1836, 7078], [-8388, -2532], [4074, -1410], [-1336, 10020], [-7656, -6472], [4662, -277], [-12510, -1961], [8148, -2580], [-170, 2928], [7156, -6972], [1266, -336], [-9432, 1354], [-2236, 11442], [3940, -4284], [-10728, -8577], [-6552, -12306], [-4842, 11045], [8794, -846], [-18696, -891], [-8232, 5988], [-144, 18780], [23132, -3294], [-8892, -5060], [-12028, -2148], [-22484, -6162], [-7236, 13954], [-7236, 12138], [3912, -8526], [-14286, -1902], [-16620, -2841], [-12, -1512], [12582, 10749], [-5874, 17010], [-15348, -6072], [-10080, -7458], [1120, -5448], [10464, -7520], [7872, 2302], [16632, 4203], [-19152, -2676], [11738, 3702], [-20536, -468], [-11560, 2544], [-31038, 2957], [7224, 3507], [13494, 2801], [1116, -22696], [-15774, 18591], [-21278, -14496], [-1812, 10428], [-7134, -5208], [-8600, -2388], [-9306, 26106], [20136, -13759], [1764, -31094], [5796, -2121], [-26718, 2501], [-16548, 20114], [7426, -26334], [-2176, -5772], [-31026, 4869], [-1648, 10356], [-27060, -12874], [-5552, -15708], [-5270, 16830], [-5060, -9216], [-20382, 6901], [-8592, -5279], [-22410, -23153], [21798, -2130], [-25774, -7584], [5220, 14736], [1572, -16448], [20388, -12918], [10920, 26576], [14636, -8904], [10788, 11279], [-6890, -15168], [56802, -4009], [-50082, -4614], [-10644, 6161], [22890, 22314], [2716, 21180], [19200, -13840], [-2718, 21487], [4932, -11400], [-22944, 15366], [29784, 17754], [55764, -4061], [5848, -1464], [-15804, -31168], [-6036, -41880], [-33702, 10847], [39002, 20190], [-11154, 9257], [-4158, 17736], [31140, 1116], [38036, 25020], [-54048, -16360], [-9324, -42165], [-19950, -21570], [1772, 21612], [-18750, 35011], [19518, -22014], [8550, -50087], [23700, -35880], [6652, 6840], [-1518, 2049], [40308, 22966], [9678, 23664], [-2712, 19788], [30672, -5243], [-56100, 4831], [38268, -13340], [8478, -34375], [-48984, -16864], [-12126, 4314], [-41018, 23184], [3396, 24054], [-7808, 44328], [12030, 52107], [-47132, 12396], [-3204, -4124], [57372, -19162], [-44064, -22301], [-33388, -33144], [-47862, -7249], [20394, -9822], [25176, -9174], [45560, 3000], [33720, -21618], [-9246, -21816], [-9760, -15132], [18996, 56620], [63076, 10044], [39066, 17813], [42854, 6186], [-25416, 2626], [-14322, 12990], [21728, 51840], [-19188, 7566], [-2420, -3864], [60606, -27456], [-38196, 14414], [56160, 11892], [-37284, 49707], [23494, -26592], [-38342, 25014], [30024, -16844], [-22254, 21210], [300, -13512], [-13488, -17064], [43350, -41664], [65502, 31459], [39132, -1730], [-31056, 29114], [-50568, 12506], [-14068, 42708], [32134, -26058], [21266, 23328], [-63774, 4323], [96898, -5694], [-42348, 7283], [65970, -26005], [-19402, -22182], [7972, 19488], [-15732, -40478], [16794, 27571], [22416, -20413], [12976, 19728], [-66262, -10566], [-23520, -53175], [62964, 27799], [-354, -31551], [-25236, 65616], [5406, 20160], [-79914, -7899], [26972, -54192], [48224, 33582], [-41076, 52503], [-16580, -22968], [-52956, -28701], [29584, 876], [-85428, 10955], [-8496, -84694], [-25242, -37578], [-62254, 37608], [-29926, 30576], [-63336, -29138], [-65904, 2200], [-98852, 17676], [57336, 12812], [-10116, -9231], [-51180, 46972], [92682, -8658], [-53462, -20352], [42706, 24240], [9696, -66610], [39474, -17411], [11102, 15552], [92316, -2684], [47044, 17490], [-73800, -21646], [-47578, -1272], [58866, 3071], [68904, 28144], [49650, -62291], [44664, -18674], [124716, 9736], [-6648, -28827], [38952, -25938], [62004, 42156], [79098, -11094], [-16828, 2028], [-45960, 69636], [94818, 14370], [41424, 13045], [62094, 18498], [16234, -24840], [-61056, 83048], [42432, -15930], [42268, 3102], [65224, -85944], [93786, -33750], [148284, 23749], [66396, 9868], [-38782, -22902], [-35988, 32321], [-16524, 42054], [-86124, -33086], [72196, -18240], [92982, -51991], [-92244, -3024], [-40038, -52968], [-67980, -92671], [50192, 1716], [-65028, -55098], [-31214, 12222], [-99008, 62010], [-153906, 22728], [-61672, -43230], [21000, -5110], [-67800, -75614], [-20320, 34296], [-90408, 46402], [101568, 8100], [-1470, 118541], [119964, -5085], [25680, -98502], [830, -83016], [91516, 64590], [7842, -48955], [20496, -69576], [30112, -10386], [-143162, -50442], [-71520, 56097], [161272, 33600], [-37272, -82760], [-98802, -57375], [-9060, 55986], [68450, 41976], [-12682, -11928], [-52056, 66344], [178574, 24336], [-18654, -32825], [-52272, 121676], [-28668, 38468], [58806, 1008], [120818, 25950], [13330, -50232], [75894, -31133], [-85230, 45102], [-97350, -41538], [-39684, 50532], [31348, 12720], [86850, 62585], [70480, 48528], [-5926, -69456], [-61086, 96942], [42828, -18810], [-123394, -44442], [-55194, -24792], [10176, 92562], [-34194, -107496], [67620, 63816], [-26754, -48198], [-42312, 60345], [131478, -70887], [27564, -31167], [-127506, 18353], [-66934, -50928], [-89040, -76464], [138550, 34104], [-27804, -153524], [-17688, -105600], [17028, 133872], [109944, -945], [35236, -32352], [-48684, -68994], [99164, 51492], [-155874, -21561], [-46214, 51966], [130188, -70974], [79346, -59322], [-143712, 57780], [-24792, 59864], [41490, -3229], [97020, 71544], [-14752, 106278], [7596, 92331], [-77202, 4056], [20, -134484], [-34866, 38039], [-43734, 104853], [30264, -78508], [137026, 16824], [-41458, -68952], [-22116, 79992], [77304, -134970], [-93288, 4467], [23688, 16434], [-11142, 173754], [122392, -58404], [103996, -87420], [-37866, -45897], [-66654, -10950], [142056, 96482], [-30498, -69967], [46116, 149026], [99384, -90018], [-147540, -6421], [21294, 172302], [139188, 20104], [-130248, 7971], [38298, 108719], [-90582, 43458], [14860, 49650], [92628, -113320], [195708, -84546]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_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_294_4_a_l(:prec:=2)
    chi := MakeCharacter_294_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_294_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_294_4_a_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![34, 12, 1]>,<11,R![-68, -4, 1]>],Snew);
    return Vf;
end function;