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


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