
// Make newform 294.4.a.k in Magma, downloaded from the LMFDB on 14 September 2025.
// 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_k();".
// 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_k();".
// 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;
    Rf_num := [[1, 0], [0, 7]];
    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_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 := 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]];
    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, -3], [-42, 1], [36, 2], [-154, 6], [-40, 18], [-192, 6], [268, -12], [-378, -5], [200, 24], [-156, 10], [-26, -24], [-432, -2], [-708, 13], [72, 24], [-762, -30], [-372, -83], [488, 84], [156, -136], [-54, 29], [372, 125], [618, 87], [96, 106], [-454, 90], [784, -96], [966, -48], [-716, -192], [60, -24], [324, -30], [12, 92], [-1154, 192], [1004, 108], [-12, -157], [-1208, 132], [1380, 86], [-1002, -111], [594, 114], [216, -189], [1190, -222], [-958, 96], [314, 240], [1152, -204], [756, -60], [1608, 300], [2040, 18], [-3072, 231], [36, -546], [1278, 246], [-5484, -153], [1128, -490], [1710, -297], [3042, -66], [-6930, 23], [-456, -454], [-3230, -48], [4276, 510], [-588, 622], [1794, -13], [3660, 166], [3012, -418], [8448, -15], [-3566, -72], [-44, -168], [-784, 252], [3030, 594], [-5052, -33], [5490, -125], [-1214, 618], [3408, 64], [-2462, -504], [-4724, -792], [2904, 140], [1208, 450], [-8196, -643], [-3564, -18], [-2868, 645], [2016, 562], [1434, -648], [4878, 942], [1560, -549], [-4200, -360], [2594, 714], [-6666, -432], [4590, 912], [1062, -1315], [2668, -204], [-5616, 286], [-3372, -782], [-9132, 540], [-138, -954], [-3328, 900], [4296, 992], [-3354, -1357], [-54, 571], [11964, 132], [-13514, -960], [-6572, 1116], [-4398, 600], [5472, -1874], [-884, 1242], [5044, -276], [-22632, -249], [-5712, -1422], [15198, -1255], [-12826, -1350], [2040, 909], [9576, -780], [-7848, -708], [-4220, 1194], [-8628, -1420], [-6916, -516], [2708, 870], [-12468, -442], [-13956, 630], [-25992, -486], [19086, -942], [-17388, -69], [8772, 1800], [-12618, -2067], [7650, -1830], [-18972, 576], [7104, -2250], [28456, -216], [-12480, -1064], [16008, 26], [7608, -681], [-3384, 1452], [-25802, 342], [-2968, -1692], [18896, -1824], [5226, -2383], [20088, -525], [-906, 1769], [-7116, 400], [4338, 927], [-29134, 240], [22692, -684], [-7902, -1152], [20392, -1980], [9402, 2034], [10152, -443], [-18540, -1130], [-732, 1875], [26922, 1289], [-3012, 526], [17246, 1482], [29912, -108], [28566, -1335], [-16600, 2292], [-2724, 314], [17560, -2508], [-3130, -546], [-21068, 1032], [-15318, 1705], [-17136, 521], [3606, -2849], [4074, -1506], [4978, -432], [28860, 1368], [-18948, 352], [-17556, -1710], [-26184, 1904], [-21052, 1104], [-34524, -2237], [-27146, 1872], [-8334, 311], [25890, -510], [14604, -1115], [29238, -798], [1420, -3972], [-44544, 256], [-12102, 4267], [-4044, -936], [-9264, 5598], [13680, -2826], [-12204, 647], [-35672, -2520], [-54372, 848], [6084, 600], [13266, 3467], [-26858, -2466], [18846, 3113], [1698, 2616], [-8676, 6156], [-11212, -612], [-19200, -5056], [-540, -117], [-4146, 2598], [-37732, 2772], [-66222, 1027], [57954, -1782], [20334, -4883], [-57804, -696], [-20876, 3912], [138, -6387], [-1260, -1838], [-56322, 1512], [-61272, -1452], [-25200, 425], [22380, 4031], [45396, 2188], [-13698, 6257], [20472, 5872], [16830, 3210], [20870, 3696], [8100, 6138], [496, 1512], [49086, 3387], [73324, 348], [-20172, 4588], [-9684, -1582], [-9216, -4477], [-36100, 4176], [21042, 6275], [47958, 1674], [-29832, -270], [49760, -792], [13440, -3054], [-7662, 5784], [-15280, -228], [-44484, 2092], [-10340, -2148], [49266, 2849], [56794, 1434], [-91632, 1454], [40962, -2562], [-24568, 1296], [-3156, -7878], [-19964, -6816], [44334, 3072], [30732, -1094], [11184, 4284], [43596, 2643], [-75178, -936], [-17482, -2034], [33672, -2204], [15630, -5286], [61236, -936], [-12144, 2136], [-23562, -6336], [4230, 4903], [49260, 1858], [-28920, -1298], [-29808, -2506], [-54724, 5148], [-22726, 3630], [31922, 7920], [-6150, 5535], [-29938, -294], [6564, 691], [-28206, 5699], [-37670, -2334], [18028, 9840], [-13428, -1474], [-20934, -10469], [82416, 595], [26368, -5760], [-18650, 4362], [-1536, -7443], [852, 9131], [49206, 4269], [-5964, -3360], [16782, 9528], [-72354, -5079], [120284, -816], [11440, -7290], [-90324, -2157], [-11252, -5832], [-49836, -2109], [48544, -8460], [-59652, 1387], [15096, 5014], [-24198, -3258], [-15982, -3960], [43322, 2304], [-38400, 5650], [33648, 8584], [78868, -276], [66936, -1564], [-127140, 1629], [41340, -6844], [-94506, 3246], [3946, -3936], [-50206, 6648], [-56280, 7594], [76074, 4009], [-38930, 504], [-25548, -3260], [47948, -6150], [20976, 758], [-38938, -2040], [-105342, -2017], [132168, -1000], [-25662, 3829], [62592, -5870], [12660, -1528], [32232, -5643], [70344, 486], [17052, 10140], [-34314, -12822], [74036, 1860], [-58344, 6900], [36990, 4674], [-86448, -7495], [35250, -4542], [92554, -3816], [-69984, -10600], [36576, 3486], [-92812, 6198], [33952, 3744], [36630, -9150], [87180, -7915], [-26796, 13300], [5806, 3810], [-78852, 7537], [46092, 6078], [155124, -1978], [-53516, 13488], [27414, 6401], [-13260, -5688], [-53526, 4488], [-59580, 9049], [59960, 9972], [-3876, -11262], [84638, 7470], [-26224, 3714], [-51474, 1848], [24904, -4374], [94944, -9242], [-38880, 2902], [-84712, 7488], [-35184, 598], [-59928, -5436], [45882, -535], [92268, -1101], [55128, 8214], [-10114, -6984], [-28204, 1062], [-8334, -1219], [-15792, 4200], [-68176, 2118], [-138262, -7050], [-34176, 16365], [-121472, -10344], [154104, 2440], [-59442, 11145], [83532, -10410], [-99454, -2520], [-119546, 2544], [80664, 4072], [-142834, -7920], [110586, 3571], [-97632, -5812], [-26196, 3932], [31398, -5568], [88318, -2178], [-11918, 2184], [110622, 12439], [-67026, -10434], [-50586, -5706], [10500, 6996], [47572, -3744], [-115374, 6401], [-46592, 1152], [-163366, -192], [-74754, -2730], [152700, 5850], [-62558, -12498], [61686, -3312], [-47640, 750], [-84690, -2424], [-43524, 9360], [19458, 5178], [-71304, 13281], [-170610, -4971], [133596, -231], [-30594, -13183], [-36902, 9600], [-18384, 5808], [104342, -6216], [-63540, 2612], [-98952, -120], [95916, 1512], [62232, 17547], [-36380, -19008], [105012, -3558], [-73492, 13092], [25086, -2409], [13670, 1206], [-104100, -11322], [-53282, 13398], [61440, 16068], [-230376, -728], [29274, 8519], [95532, -648], [149920, -11682], [116940, -9105], [-61602, -5496], [46892, -12180], [14502, 21443], [148890, -8547], [74184, -4460], [69058, -9912], [-30962, -13128], [-73884, 2520], [-255744, 2562], [-121224, -6069], [-26712, -18054], [-112026, -294], [127984, 16236], [82348, 12804], [146310, 3471], [138558, -15246], [37296, 406], [127734, 7709], [66708, -6410], [-16680, -17130], [68364, 8479], [-61566, 11046], [-63828, -17312], [-107016, 10563], [169914, 7319], [-196698, -4350], [119300, -4518], [182940, -14048], [132012, 7554]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_4_a_k();".
// 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_k(: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_k();".
// 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_k( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-62, 12, 1]>,<11,R![-3524, 4, 1]>],Snew);
    return Vf;
end function;