
// Make newform 294.4.e.l in Magma, downloaded from the LMFDB on 24 April 2024.
// 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_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_e_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 := [112896, 336, 337, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [112896, -337, 337, -1], [673, 0, 0, 1]];
    Rf_basisdens := [1, 1, 113232, 337];
    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_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)
    N := 294;
    order := 3;
    char_gens := [197, 199];
    char_values := [[1, 0, 0, 0], [0, 0, -1, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, 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+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, -2, 0], [3, 0, -3, 0], [0, 1, 2, 0], [0, 0, 0, 0], [-33, -1, 34, -1], [-20, 0, 0, -1], [-48, 4, 44, 4], [0, -3, 23, 0], [0, 4, -76, 0], [33, 0, 0, 11], [-259, -2, 261, -2], [0, -9, 1, 0], [216, 0, 0, -6], [-46, 0, 0, -15], [0, 12, 282, 0], [123, -3, -120, -3], [9, -25, 16, -25], [0, -4, 114, 0], [-338, -11, 349, -11], [246, 0, 0, -20], [-478, 35, 443, 35], [0, -8, 267, 0], [123, 0, 0, -25], [0, -42, 408, 0], [-959, 0, 0, -35], [342, 20, -362, 20], [0, 21, -1237, 0], [0, 45, -132, 0], [274, 49, -323, 49], [-840, 0, 0, -82], [-1393, 0, 0, -68], [0, 7, 86, 0], [1710, -50, -1660, -50], [850, 0, 0, -101], [0, -6, -468, 0], [-437, -59, 496, -59], [-628, -18, 646, -18], [0, -132, -1028, 0], [-1266, 0, 0, -8], [0, 70, 212, 0], [-1380, 114, 1266, 114], [1264, 0, 0, 143], [0, -78, 414, 0], [811, -222, -589, -222], [-1410, 0, 0, -170], [-2908, 36, 2872, 36], [2834, 0, 0, -102], [4489, 0, 0, -9], [3135, -57, -3078, -57], [0, 211, 289, 0], [0, -62, -1882, 0], [3024, 0, 0, -54], [71, 39, -110, 39], [-9, 0, 0, -75], [0, -48, -2322, 0], [-5070, -102, 5172, -102], [1845, -55, -1790, -55], [0, -247, 2256, 0], [2728, 255, -2983, 255], [2406, 0, 0, -38], [2858, 17, -2875, 17], [2007, 0, 0, 9], [-3920, 0, 0, 175], [-1152, 86, 1066, 86], [0, -38, 2935, 0], [0, 63, -3408, 0], [0, -147, -1385, 0], [-1039, 0, 0, -44], [3228, -168, -3060, -168], [-5594, 0, 0, 232], [-1464, -162, 1626, -162], [0, 218, 1660, 0], [5231, -354, -4877, -354], [0, -157, 9437, 0], [-4864, 0, 0, -307], [0, 302, -1328, 0], [11934, -68, -11866, -68], [0, -319, -2469, 0], [0, 264, -7776, 0], [143, 366, -509, 366], [-1728, 0, 0, 174], [6530, 0, 0, -53], [-2604, 246, 2358, 246], [4114, 0, 0, -201], [0, 41, 8640, 0], [0, 91, 4544, 0], [-10956, 0, 0, 38], [0, 518, 3347, 0], [7482, 0, 0, 274], [80, 0, 0, 797], [0, 502, 6134, 0], [-12342, -218, 12560, -218], [-1019, -282, 1301, -282], [2637, 0, 0, -633], [0, 101, 2045, 0], [2916, 0, 0, -606], [0, 423, -138, 0], [-13506, -426, 13932, -426], [0, 675, -4807, 0], [0, 583, -7041, 0], [4664, 0, 0, 364], [-17163, 301, 16862, 301], [20805, -143, -20662, -143], [0, 690, 7890, 0], [-18626, 287, 18339, 287], [-7249, -544, 7793, -544], [-7455, 0, 0, 623], [0, 510, 7506, 0], [-5178, 1014, 4164, 1014], [-19115, 0, 0, 348], [0, -802, -6627, 0], [3976, -538, -3438, -538], [-78, 0, 0, 472], [-526, 1259, -733, 1259], [-4213, 0, 0, 645], [-30570, -82, 30652, -82], [13654, 0, 0, 591], [-366, 420, -54, 420], [0, 399, 12006, 0], [12936, 0, 0, 688], [12158, -211, -11947, -211], [10397, 0, 0, -798], [0, 1131, -4212, 0], [18789, -21, -18768, -21], [0, 627, -3715, 0], [3561, 0, 0, -493], [0, -744, 10186, 0], [0, 264, -3750, 0], [2479, 0, 0, 496], [0, -823, -9651, 0], [14146, 191, -14337, 191], [8046, 0, 0, -1128], [0, -356, -21951, 0], [-10690, 0, 0, 724], [0, 80, 3124, 0], [-17045, 0, 0, 910], [5886, 1616, -7502, 1616], [-3490, 562, 2928, 562], [-24975, 0, 0, -813], [-6480, 958, 5522, 958], [-5318, 0, 0, -674], [0, -1127, -3310, 0], [20272, -608, -19664, -608], [20061, 0, 0, -627], [-8308, -703, 9011, -703], [5208, 0, 0, -1876], [30058, 0, 0, 567], [-10626, -1374, 12000, -1374], [0, 486, -13312, 0], [0, -196, 19930, 0], [0, 458, 7862, 0], [-13626, 0, 0, 1782], [-19384, 0, 0, -963], [0, 846, 12210, 0], [-6320, -637, 6957, -637], [37674, 0, 0, 450], [0, 1613, -18493, 0], [0, 384, -46422, 0], [-13355, 0, 0, -204], [10431, 977, -11408, 977], [0, -1822, 19342, 0], [12234, 0, 0, -962], [-21475, 0, 0, -804], [0, 891, -26472, 0], [-13386, 444, 12942, 444], [-5388, 1788, 3600, 1788], [8695, -2394, -6301, -2394], [-18802, 873, 17929, 873]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_294_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_294_4_e_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_e_l(:prec:=4)
    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_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_e_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_294_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![108900, 1650, 355, -5, 1]>,<11,R![617796, 52662, 3703, 67, 1]>],Snew);
    return Vf;
end function;