
// Make newform 294.4.a.c in Magma, downloaded from the LMFDB on 06 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_c();".
// 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_c();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [-3], [6], [0], [-30], [-53], [84], [97], [84], [-180], [-179], [-145], [-126], [-325], [366], [-768], [264], [-818], [-523], [-342], [43], [-1171], [810], [600], [-386], [-618], [-1475], [1884], [413], [-882], [2483], [-2118], [3012], [37], [-1644], [1088], [-506], [1844], [-162], [2724], [-1254], [1807], [714], [-3709], [-1044], [136], [1484], [2032], [-6198], [4591], [4530], [1530], [-5534], [468], [2490], [1572], [-1806], [6112], [-4231], [-3816], [3997], [-4608], [631], [-3894], [2185], [3504], [2945], [4277], [7188], [9406], [-3390], [-4812], [7099], [2963], [-11899], [-2568], [-10146], [6229], [-2472], [7075], [4158], [-6595], [1518], [-8567], [-10640], [7032], [-14814], [-11251], [3852], [-475], [-5934], [13368], [6653], [15444], [683], [-9882], [-4206], [-9060], [15679], [-7711], [4292], [-9858], [13890], [19038], [-8053], [17137], [-18144], [24702], [-2172], [-4175], [-2261], [-16318], [-26550], [-19925], [-6832], [10212], [-3779], [-16998], [-21750], [-10944], [-10955], [25103], [5604], [10968], [-8405], [468], [-25066], [-11082], [-13481], [-24317], [-18217], [19782], [-4921], [18098], [24468], [-21719], [30306], [-27296], [35100], [44394], [8584], [-9834], [43856], [13266], [-17453], [35172], [-3503], [-22848], [13456], [40710], [2906], [19188], [-17251], [2094], [-40267], [17604], [3509], [34638], [17353], [46920], [18354], [35568], [-27343], [-51024], [-2226], [-35304], [-2341], [-29015], [44765], [40632], [-51600], [34522], [-61692], [41285], [-10511], [45576], [-21691], [-58530], [-52208], [41653], [-34153], [8424], [-12907], [-34392], [-7986], [-64500], [-37810], [52783], [11321], [-37878], [62791], [-28422], [-26560], [-20928], [-20208], [71688], [12035], [-10810], [-76914], [63168], [48174], [44731], [-55790], [52534], [-26370], [-20994], [59104], [-52638], [-16020], [31492], [92735], [23112], [-40636], [20256], [-33576], [23545], [26480], [55524], [-31128], [-26514], [-85879], [9289], [41646], [2360], [54522], [74906], [-54768], [10230], [22003], [12738], [20729], [-9164], [18053], [52566], [-53783], [-80610], [32515], [7590], [34164], [24750], [-116418], [-21287], [29329], [-29386], [-69624], [-84792], [104527], [98310], [-54304], [21528], [40553], [74652], [-60402], [-33605], [1704], [37776], [-78859], [47791], [81666], [-67646], [-13903], [50832], [-34577], [-114623], [-95910], [16849], [-14382], [-92790], [61652], [10446], [-45623], [28844], [-3077], [68165], [-91730], [-134180], [-65526], [-74845], [20915], [72924], [87816], [34901], [-89910], [43021], [44956], [37290], [-115831], [-74286], [-55727], [-81198], [-44292], [-9060], [11226], [110988], [-107209], [31674], [-61307], [150696], [1626], [19351], [-110870], [-37806], [29036], [-18900], [-133381], [-5347], [53034], [-79445], [-129768], [-96649], [-152112], [46446], [-88206], [122264], [-69336], [-59201], [-114786], [112668], [133543], [68562], [53917], [27047], [-83358], [32597], [-48234], [-104129], [-32671], [-145763], [42204], [-121158], [72629], [-7086], [47149], [134346], [130517], [2214], [-89902], [24468], [-79829], [138457], [168659], [7776], [-56556], [-115297], [-142278], [56394], [27379], [93260], [175806], [12318], [-125756], [-147502], [55818], [-152120], [88523], [27090], [6450], [61896], [139548], [26802], [-72622], [21678], [-200838], [-226986], [53137], [-78274], [40320], [-229285], [-76258], [-41952], [-71675], [-70566], [122670], [188683], [-111619], [21180], [82836], [-180710], [-28092], [-187265], [92460], [1332], [-91072], [159936], [235684], [-115332], [58445], [-192446], [126965], [-124542], [-178471], [-47262], [27348], [-51713], [-221730], [189890], [-20420], [34398], [-23671], [-44022], [-61094], [-185712], [129296], [-202746], [20622], [65053], [-113194], [234828], [-212507], [203244], [-257042], [175980], [9648], [201428], [245609], [-271218], [-12642], [87829], [252324], [274164], [28932], [267013], [146376], [-3330], [145474], [-58614], [92514], [21888], [92356], [277824]];
    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_c();".
// 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_c(:prec:=1)
    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_c();".
// 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_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-6, 1]>,<11,R![30, 1]>],Snew);
    return Vf;
end function;