
// Make newform 294.4.e.c in Magma, downloaded from the LMFDB on 06 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_294_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_294_e_Hecke();"
// 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_e_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_e_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
        poly := [1, -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_294_e();"
function MakeCharacter_294_e()
    N := 294;
    order := 3;
    char_gens := [197, 199];
    v := [3, 2];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_294_e_Hecke();"
function MakeCharacter_294_e_Hecke( : Kf := false)
    N := 294;
    order := 3;
    char_gens := [197, 199];
    char_values := [[1, 0], [0, -1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := [[0, -2], [3, -3], [0, -18], [0, 0], [72, -72], [-34, 0], [-6, 6], [0, -92], [0, 180], [-114, 0], [-56, 56], [0, 34], [6, 0], [164, 0], [0, -168], [-654, 654], [492, -492], [0, 250], [124, -124], [36, 0], [-1010, 1010], [0, -56], [228, 0], [0, -390], [-70, 0], [1350, -1350], [0, -2000], [0, -696], [1114, -1114], [-462, 0], [1064, 0], [0, -180], [2718, -2718], [-1348, 0], [0, -558], [-1928, 1928], [2410, -2410], [0, -740], [3984, 0], [0, 1038], [2568, -2568], [-2698, 0], [0, 4116], [3310, -3310], [1278, 0], [-2936, 2936], [-3508, 0], [-1888, 0], [-3564, 3564], [0, -1334], [0, -2658], [-588, 0], [-5690, 5690], [180, 0], [0, -5310], [-828, 828], [4134, -4134], [0, 2968], [4786, -4786], [-4398, 0], [-4772, 4772], [6522, 0], [-6244, 0], [528, -528], [0, 5830], [0, -5046], [0, 5020], [-7486, 0], [10032, -10032], [5942, 0], [90, -90], [0, -10596], [-4016, 4016], [0, -3278], [4628, 0], [0, 2880], [-7974, 7974], [0, 12346], [0, -9738], [430, -430], [-1812, 0], [-10690, 0], [4116, -4116], [9938, 0], [0, -1784], [0, 11712], [7650, 0], [0, -3674], [-3102, 0], [8984, 0], [0, -3612], [9288, -9288], [5848, -5848], [-5952, 0], [0, -10748], [-16488, 0], [0, -14058], [14466, -14466], [0, -18524], [0, -4358], [-2140, 0], [-2022, 2022], [-7356, 7356], [0, -11202], [10564, -10564], [18574, -18574], [13188, 0], [0, 22506], [-10596, 10596], [14618, 0], [0, -5168], [-5726, 5726], [-7806, 0], [18052, -18052], [-6208, 0], [21510, -21510], [-11140, 0], [-9312, 9312], [0, -4878], [-9744, 0], [-2990, 2990], [33266, 0], [0, -5370], [-384, 384], [0, 14524], [24750, 0], [0, 1042], [0, 36960], [-16288, 0], [0, 7810], [36700, -36700], [29508, 0], [0, 15136], [3422, 0], [0, -31446], [-18718, 0], [1686, -1686], [-5492, 5492], [-17310, 0], [-35754, 35754], [33644, 0], [0, -28734], [28672, -28672], [-15912, 0], [-17534, 17534], [40656, 0], [23870, 0], [29610, -29610], [0, 45484], [0, -46164], [0, 2986], [6534, 0], [29756, 0], [0, -29952], [36268, -36268], [-23604, 0], [0, -34184], [0, 53922], [40538, 0], [3606, -3606], [0, -14064], [33066, 0], [-26368, 0], [0, -55884], [51126, -51126], [14184, -14184], [-51680, 51680], [-52094, 52094]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_e_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_4_e_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_e_c(:prec:=2)
    chi := MakeCharacter_294_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_e_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_e_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![324, 18, 1]>,<11,R![5184, -72, 1]>],Snew);
    return Vf;
end function;