
// Make newform 196.6.e.l in Magma, downloaded from the LMFDB on 06 May 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_6_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_196_6_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 := [7574050372, 101983864, -101466410, -1033736, 513939, 3512, -1166, -4, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0], [154804482, 1207188, -1204253, -5868, 2929, 6, -2, 0], [29772446498102, 750824392415, -133425745560, -4133910386, 137621616, 8103275, -85096, -6342], [-87630052846, 174712287203, 1642339762, -1091175064, -5573995, 2223256, 6342, -1812], [-324400058017, 647704479056, 3284679524, -2182350128, -11147990, 4446512, 12684, -3624], [-1577553071198356, 1912473924308, 16349284342082, -75716475004, -56639445545, 452390441, 65623087, -739557], [199229885932, -396400657576, -6170256904, 4089892863, 35389165, -14098777, -56889, 16254], [-21491134416808, 42799209040044, 548680240801, -364123453372, -2493570135, 994446838, 2981216, -851776]];
    Rf_basisdens := [1, 2780050, 149139952325, 21305707475, 21305707475, 298279904650, 3277801150, 42611414950];
    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, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0, 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+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 := 6;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, -1, -1, 0], [0, 0, 1, 7, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [111, -111, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 15, -42, 0], [0, 0, 80, -73, 0, -80, -7, 0], [0, 0, -33, -44, 0, 0, 0, 0], [0, -852, 0, 0, -8, 0, 0, -8], [5181, 0, 0, 0, -7, 0, 0, 0], [0, 0, 126, -300, 0, -126, 174, 0], [0, -3433, 0, 0, 27, 0, 0, 27], [0, 0, 0, 0, 0, -508, -551, 0], [-7249, 0, 0, 0, 63, 0, 0, 0], [0, 0, -206, -1088, 0, 0, 0, 0], [-132, 132, 0, 0, 0, 0, 0, -14], [0, 0, 317, -2164, 0, -317, 1847, 0], [0, 0, 1647, 293, 0, 0, 0, 0], [-48846, 48846, 0, 0, 0, 0, 0, -90], [5418, 0, 0, 0, -78, 0, 0, 0], [0, 0, 258, -5783, 0, -258, 5525, 0], [0, 29326, 0, 0, -210, 0, 0, -210], [0, 0, 0, 0, 0, 1777, 4601, 0], [0, 0, 2000, -2179, 0, 0, 0, 0], [0, 0, 0, 0, 0, -642, -1573, 0], [0, 0, -447, 10767, 0, 447, -10320, 0], [0, 0, 1182, 14636, 0, 0, 0, 0], [0, -67386, 0, 0, -506, 0, 0, -506], [-72259, 72259, 0, 0, 0, 0, 0, 135], [-21603, 0, 0, 0, 195, 0, 0, 0], [-125642, 0, 0, 0, 546, 0, 0, 0], [0, 0, 561, -21384, 0, 0, 0, 0], [42714, -42714, 0, 0, 0, 0, 0, -546], [0, 0, 0, 0, 0, -8019, -12991, 0], [0, 111078, 0, 0, -1408, 0, 0, -1408], [-172766, 172766, 0, 0, 0, 0, 0, 666], [0, 0, 5937, 27281, 0, -5937, -33218, 0], [0, 136169, 0, 0, -1407, 0, 0, -1407], [0, 0, 0, 0, 0, -5354, -46930, 0], [0, 0, -3573, 41007, 0, 0, 0, 0], [76482, -76482, 0, 0, 0, 0, 0, 2262], [0, 0, 0, 0, 0, -13179, -27918, 0], [0, -139446, 0, 0, -1598, 0, 0, -1598], [445885, -445885, 0, 0, 0, 0, 0, -2127], [395868, 0, 0, 0, -2002, 0, 0, 0], [0, 0, -9954, -27756, 0, 9954, 37710, 0], [-287298, 0, 0, 0, -66, 0, 0, 0], [0, 0, 0, 0, 0, -11028, 101976, 0], [0, 0, -25245, 6468, 0, 25245, 18777, 0], [0, 0, 27831, -22437, 0, 0, 0, 0], [0, -163548, 0, 0, 2676, 0, 0, 2676], [-574068, 0, 0, 0, 936, 0, 0, 0], [0, 0, -8478, -9093, 0, 8478, 17571, 0], [0, 0, 0, 0, 0, -34055, -103015, 0], [0, 0, -23064, -8265, 0, 0, 0, 0], [-1090650, 1090650, 0, 0, 0, 0, 0, -4230], [0, 0, -27689, 20359, 0, 27689, 7330, 0], [0, 0, -18852, -93908, 0, 0, 0, 0], [918566, -918566, 0, 0, 0, 0, 0, -1692], [-53856, 0, 0, 0, -2480, 0, 0, 0], [0, 0, 79857, -11840, 0, -79857, -68017, 0], [0, 0, 0, 0, 0, -13283, -25996, 0], [0, 0, 0, 0, 0, 33495, 19063, 0], [0, 0, 83560, -32576, 0, -83560, -50984, 0], [0, 0, -72636, 43011, 0, 0, 0, 0], [0, 288828, 0, 0, -5806, 0, 0, -5806], [0, 2929013, 0, 0, -219, 0, 0, -219], [-1588411, 0, 0, 0, -543, 0, 0, 0], [-1791339, 1791339, 0, 0, 0, 0, 0, -6477], [0, 0, 0, 0, 0, -84687, 103434, 0], [0, 0, 5390, 314165, 0, -5390, -319555, 0], [0, 1105170, 0, 0, 9734, 0, 0, 9734], [0, 0, -47448, 125692, 0, 47448, -78244, 0], [0, -785818, 0, 0, -8832, 0, 0, -8832], [-1152311, 0, 0, 0, 10545, 0, 0, 0], [0, 0, -122938, 165392, 0, 0, 0, 0], [-1191129, 1191129, 0, 0, 0, 0, 0, 12485], [0, 0, 53337, 435697, 0, 0, 0, 0], [0, -195459, 0, 0, 12057, 0, 0, 12057], [0, 0, -115650, -183471, 0, 115650, 299121, 0], [0, 0, 0, 0, 0, 66431, -279209, 0], [-3639966, 0, 0, 0, -3684, 0, 0, 0], [2244132, -2244132, 0, 0, 0, 0, 0, -8304], [0, 0, 0, 0, 0, 225276, -104757, 0], [0, 0, 204360, 64404, 0, 0, 0, 0], [0, -1480590, 0, 0, -374, 0, 0, -374], [4748166, 0, 0, 0, -11016, 0, 0, 0], [0, 4932213, 0, 0, 5775, 0, 0, 5775], [0, 0, 0, 0, 0, 205573, 142766, 0], [1162012, 0, 0, 0, 5604, 0, 0, 0], [0, 0, 20419, -221156, 0, 0, 0, 0], [0, 0, 35018, 806468, 0, -35018, -841486, 0], [245976, -245976, 0, 0, 0, 0, 0, 20148], [7056654, 0, 0, 0, 5070, 0, 0, 0], [0, -385814, 0, 0, 34962, 0, 0, 34962], [0, 0, 0, 0, 0, -124880, -635716, 0], [0, 0, 235313, -669559, 0, 0, 0, 0], [0, 0, 90458, -43375, 0, -90458, -47083, 0], [0, 0, -254931, 237108, 0, 0, 0, 0], [0, -4467694, 0, 0, -3324, 0, 0, -3324], [3120601, 0, 0, 0, 22593, 0, 0, 0], [-6485952, 6485952, 0, 0, 0, 0, 0, -20358], [0, 0, -108883, 139532, 0, 108883, -30649, 0], [0, -1453353, 0, 0, 14603, 0, 0, 14603], [-3815317, 3815317, 0, 0, 0, 0, 0, -29331], [0, 0, 290898, -23109, 0, -290898, -267789, 0], [0, 0, 0, 0, 0, -143823, -859443, 0], [0, 0, -226660, -241783, 0, 0, 0, 0], [-2382732, 2382732, 0, 0, 0, 0, 0, 31412], [0, 0, 0, 0, 0, -346416, -77475, 0], [0, 0, 108084, -293952, 0, 0, 0, 0], [6425595, -6425595, 0, 0, 0, 0, 0, -11631], [-1594881, 0, 0, 0, -42317, 0, 0, 0], [0, 0, -405261, 929936, 0, 405261, -524675, 0], [1985534, 0, 0, 0, -16602, 0, 0, 0], [-10938993, 10938993, 0, 0, 0, 0, 0, 18941], [0, 0, 0, 0, 0, 16173, 471329, 0], [0, 0, -77826, -1064748, 0, 77826, 1142574, 0], [0, 6291213, 0, 0, -10311, 0, 0, -10311], [3088965, 0, 0, 0, -65283, 0, 0, 0], [0, 0, 505635, 277185, 0, -505635, -782820, 0], [-4921686, 0, 0, 0, -71118, 0, 0, 0], [0, 0, 230463, 359523, 0, 0, 0, 0], [911106, -911106, 0, 0, 0, 0, 0, -85866], [0, 0, -466167, 479568, 0, 0, 0, 0], [15972099, 0, 0, 0, 8103, 0, 0, 0], [0, -7243561, 0, 0, 19803, 0, 0, 19803], [0, 0, -209510, 1928296, 0, 0, 0, 0], [0, 0, 0, 0, 0, 69582, 193406, 0], [0, 0, 360081, -405381, 0, 0, 0, 0], [5596965, -5596965, 0, 0, 0, 0, 0, -42717], [-5579706, 0, 0, 0, 32050, 0, 0, 0], [0, 8616988, 0, 0, -16920, 0, 0, -16920], [-1637515, 0, 0, 0, 32001, 0, 0, 0], [0, 0, 669992, -610843, 0, 0, 0, 0], [0, 0, 0, 0, 0, -331026, -45063, 0], [0, 0, 47119, -670775, 0, -47119, 623656, 0], [0, 0, 503829, 410500, 0, -503829, -914329, 0], [0, 0, 0, 0, 0, -605577, -1559322, 0], [-8248713, 8248713, 0, 0, 0, 0, 0, -15469], [0, 0, 0, 0, 0, -414699, -1126779, 0], [0, -28908330, 0, 0, -13764, 0, 0, -13764], [7249736, -7249736, 0, 0, 0, 0, 0, 18096], [14405754, 0, 0, 0, 77586, 0, 0, 0], [0, 0, -200775, 951883, 0, 200775, -751108, 0], [0, 0, 0, 0, 0, -473506, 1664218, 0], [0, 0, 0, 0, 0, 283293, -215166, 0], [0, 0, 1063882, -142145, 0, -1063882, -921737, 0], [0, 0, 814845, 671216, 0, 0, 0, 0], [0, 10099494, 0, 0, 49654, 0, 0, 49654], [0, 15540283, 0, 0, 2271, 0, 0, 2271], [0, 0, 0, 0, 0, -384018, -1306359, 0], [357674, 0, 0, 0, -159654, 0, 0, 0], [0, 0, -52018, -689992, 0, 0, 0, 0], [-18400030, 18400030, 0, 0, 0, 0, 0, 35646], [-31891266, 0, 0, 0, -27166, 0, 0, 0], [0, 15567332, 0, 0, 40428, 0, 0, 40428], [0, 0, -188576, -369695, 0, 0, 0, 0], [0, 0, 0, 0, 0, -658470, 2008067, 0], [0, 0, 8441, -883093, 0, -8441, 874652, 0], [0, 13629243, 0, 0, 25779, 0, 0, 25779], [44269368, 0, 0, 0, 22822, 0, 0, 0], [-21514152, 0, 0, 0, 27084, 0, 0, 0], [0, 0, 1450795, -1667804, 0, 0, 0, 0], [24978354, -24978354, 0, 0, 0, 0, 0, -107850], [0, 0, 1122154, 1771900, 0, -1122154, -2894054, 0], [5344636, -5344636, 0, 0, 0, 0, 0, -36804], [0, 0, -97017, -1362071, 0, 97017, 1459088, 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_6_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_196_6_e_l(:prec:=8)
    chi := MakeCharacter_196_e();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_6_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_196_6_e_l( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_196_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![101185065216, 0, 389985696, 0, 1184980, 0, 1226, 0, 1]>],Snew);
    return Vf;
end function;