
// Make newform 196.4.a.e in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_196_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_196_4_a_e();".
// 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_196_4_a_e();".
// 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 := [-9, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    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_196_a();"
function MakeCharacter_196_a()
    N := 196;
    order := 1;
    char_gens := [99, 101];
    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_196_a_Hecke(Kf)
    return MakeCharacter_196_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 := [[0, 0], [0, -1], [-7, 2], [0, 0], [16, 7], [-14, -4], [-77, 4], [-112, -3], [34, 7], [-118, -28], [-98, -7], [173, -42], [-210, -12], [-172, 0], [42, 15], [-219, 42], [-28, -37], [49, 74], [168, 7], [448, -56], [483, -20], [-26, -133], [196, 88], [147, -60], [-210, 76], [-511, -106], [1106, -9], [-1692, -63], [-1131, -14], [734, 140], [-1448, 56], [-532, 233], [791, 224], [252, -152], [-15, -294], [306, 133], [329, -330], [-76, 273], [644, -4], [-2863, -118], [1596, -357], [-98, 272], [-606, 231], [-1069, 84], [-878, -140], [2114, 357], [-172, 168], [728, 600], [-4116, -165], [273, 922], [-2513, 448], [4692, 84], [4151, -216], [-5208, 84], [4011, 492], [-3498, 777], [-2863, 494], [2926, -541], [1733, 42], [646, 700], [-2184, 895], [-1890, 576], [2604, -896], [2534, 41], [2667, -932], [-7095, 546], [2984, -651], [694, -700], [3060, -693], [-630, -668], [-3549, -1596], [3110, -805], [3794, 429], [5613, 1078], [-2736, 28], [-3878, -449], [1649, 1190], [6013, 470], [-3837, 420], [-3745, -648], [-14532, 192], [-3158, 812], [1998, -1575], [686, 1308], [-9170, -829], [-3980, -623], [4742, -2044], [-8445, -812], [266, -940], [432, -2240], [10556, -1351], [9394, 1501], [9206, -567], [4224, -2436], [-10548, 1225], [6048, -1512], [-2163, -1146], [-2709, -396], [3332, 417], [-13475, 854], [6784, 1652], [11957, -238], [4816, -737], [17643, -420], [-5624, 623], [8127, 64], [20356, 592], [-21, 1932], [-10314, 2457], [-12586, -2100], [8890, -1441], [-9095, -1330], [-8786, -2828], [-6300, -2069], [4688, -1848], [-20177, -1232], [-14308, -2112], [25662, 273], [5265, -630], [-1052, 2296], [-17283, 1186], [-154, -252], [-17535, -822], [-1176, -4641], [-12796, 2145], [-17770, 1904], [5213, 3654], [1134, -2205], [16800, -1352], [-12887, 2], [2332, 2891], [7344, 2520], [5914, -4417], [-14558, 308], [-33761, 16], [-28266, 1300], [10241, -1738], [-11480, 2999], [15162, 1428], [-20173, 3164], [17220, -3536], [29881, -350], [9414, -119], [19284, 1680], [-483, -3254], [8344, -512], [-5110, -1860], [7707, 3828], [-22204, -1695], [2846, 2387], [-11835, -1442], [7266, -1968], [-24316, 1848], [33894, 1755], [-18260, 371], [14160, -672], [8958, 5971], [17703, -4248], [33866, 144], [10073, 4502], [-4444, -511], [-3434, -3668], [-4048, 5880], [8232, 5109], [9579, -2436], [3906, -4779], [15842, 4557], [-17227, -5526]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_196_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_196_4_a_e();".
// 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_196_4_a_e(:prec:=2)
    chi := MakeCharacter_196_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(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_196_4_a_e();".
// 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_196_4_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_196_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<3,R![-37, 0, 1]>,<5,R![-99, 14, 1]>],Snew);
    return Vf;
end function;