
// Make newform 196.3.g.j in Magma, downloaded from the LMFDB on 12 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_196_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_196_g_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_3_g_j();".
// 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_3_g_j();".
// 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 := [64, -64, 64, -48, 24, -16, 9, -8, 6, -6, 4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-896, 656, -424, 216, -198, 55, -12, 110, -26, 40, -4, -1], [-128, -1344, 56, -8, 64, 3, 8, 210, 6, -4, -54, -5], [384, -184, 104, -44, 29, -26, 78, -18, 16, -22, 9, -2], [-32, 480, 184, 236, -120, 107, -32, 10, -58, 16, -22, 3], [-448, 192, -280, 40, -48, -15, -40, 38, -30, 20, -2, 25], [288, 32, 112, 52, -8, 23, 16, -22, 46, -8, -6, 7], [-256, -376, -296, 120, -127, 23, -18, 12, -22, 26, 11, 7], [-208, 264, 40, 208, 53, -10, -38, 14, -20, 2, -7, -6], [-1408, 992, -1016, 456, -112, 101, -48, 134, -70, 92, -50, 13], [-1216, 3008, -1304, 1352, -752, 37, -264, 142, -198, 132, -122, 29], [244, -328, 280, -176, 99, -70, 40, -38, 30, -20, 19, -8]];
    Rf_basisdens := [1, 544, 1088, 272, 272, 1088, 272, 272, 136, 272, 544, 68];
    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_g();"
function MakeCharacter_196_g()
    N := 196;
    order := 6;
    char_gens := [99, 101];
    v := [3, 4];
    // 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_g_Hecke();"
function MakeCharacter_196_g_Hecke(Kf)
    N := 196;
    order := 6;
    char_gens := [99, 101];
    char_values := [[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 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 := 3;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [-1, 1, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 4, 2, -4, 3, 0, 2, 0, 0, 0, -1, 2], [-1, 0, 0, -3, -2, 0, 0, 0, -2, -2, 0, 1], [0, 2, -2, -2, 0, 0, 0, 0, 0, 0, 0, -2], [0, -8, -4, 0, 0, 0, 0, -1, 2, 2, -2, 0], [0, -4, -2, 0, 0, 0, 0, 0, 3, -1, -3, 0], [-8, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 6], [0, -8, -4, 8, -2, 0, -6, 0, 0, 0, -2, -4], [-8, 10, -6, 0, 0, -8, 0, 0, 2, 2, -2, 0], [4, 0, 0, -2, 2, 0, 0, 0, 2, 2, 0, -6], [0, 0, 0, -4, -5, 0, 2, 2, 7, -5, 0, 2], [0, -16, -8, 0, 0, 0, 0, 6, 0, 8, 0, 0], [0, -8, 4, 8, 2, 18, 0, 0, 0, 0, 2, 4], [0, 0, 0, 0, -4, 0, 11, 0, 0, 0, 4, 0], [-29, 5, 3, 0, 0, -29, 0, 0, 4, 4, -4, 0], [0, -4, -2, 4, -3, 0, 24, 0, 0, 0, 1, -2], [0, 0, 0, 8, -2, 0, -12, -12, -2, -2, 0, -4], [0, 12, -4, -12, -4, 18, 0, 0, 0, 0, -4, -4], [0, 0, 0, 0, 0, 0, 0, -12, -4, 4, 4, 0], [0, 0, 0, 8, -14, 0, -23, -23, 10, -14, 0, -4], [66, -24, 4, 0, 0, 66, 0, 0, -10, -10, 10, 0], [-40, 0, 0, -6, -6, 0, 0, 0, -6, -6, 0, 6], [0, -29, 9, 29, 10, -35, 0, 0, 0, 0, 10, 9], [0, 40, 20, 0, 0, 0, 0, 14, -6, -14, 6, 0], [0, 20, 10, 0, 0, 0, 0, 20, -3, -7, 3, 0], [0, 34, -22, -34, -6, 36, 0, 0, 0, 0, -6, -22], [32, 0, 0, -42, -17, 0, 0, 0, -17, -17, 0, -8], [0, 0, 0, 4, -15, 0, -4, -4, 13, -15, 0, -2], [0, 8, 4, 0, 0, 0, 0, -13, -38, 34, 38, 0], [0, 28, 12, -28, -20, -66, 0, 0, 0, 0, -20, 12], [0, 0, 0, -24, 22, 0, 3, 3, -10, 22, 0, 12], [-62, -36, 12, 0, 0, -62, 0, 0, -12, -12, 12, 0], [0, -52, -26, 52, -27, 0, -36, 0, 0, 0, 1, -26], [0, 53, -17, -53, -18, -41, 0, 0, 0, 0, -18, -17], [0, 4, 2, 0, 0, 0, 0, -34, 25, -27, -25, 0], [0, 0, 0, -16, 12, 0, 22, 22, -4, 12, 0, 8], [-171, -9, -19, 0, 0, -171, 0, 0, -14, -14, 14, 0], [0, 28, 14, -28, -3, 0, 20, 0, 0, 0, 17, 14], [7, 0, 0, -35, -4, 0, 0, 0, -4, -4, 0, -27], [0, -24, -12, 0, 0, 0, 0, -28, -34, 46, 34, 0], [0, 26, -40, -26, 7, -124, 0, 0, 0, 0, 7, -40], [-122, 0, 0, -20, -2, 0, 0, 0, -2, -2, 0, -16], [0, -72, -36, 72, -14, 0, 26, 0, 0, 0, -22, -36], [0, 0, 0, -36, 3, 0, -8, -8, 15, 3, 0, 18], [0, 0, 0, 104, -62, 0, -60, -60, 10, -62, 0, -52], [0, 40, 20, -40, 50, 0, -41, 0, 0, 0, -30, 20], [-263, 75, -23, 0, 0, -263, 0, 0, 26, 26, -26, 0], [38, 8, -48, 0, 0, 38, 0, 0, -20, -20, 20, 0], [0, 0, 0, -36, 7, 0, 56, 56, 11, 7, 0, 18], [0, 106, -62, -106, -22, 8, 0, 0, 0, 0, -22, -62], [0, 0, 0, 40, -30, 0, 39, 39, 10, -30, 0, -20], [162, 64, -56, 0, 0, 162, 0, 0, 4, 4, -4, 0], [0, 72, 36, -72, 26, 0, 44, 0, 0, 0, 10, 36], [0, -15, -29, 15, 22, -125, 0, 0, 0, 0, 22, -29], [0, -24, -12, 0, 0, 0, 0, -80, 2, 10, -2, 0], [0, -8, 24, 8, -8, 226, 0, 0, 0, 0, -8, 24], [194, 0, 0, 0, -8, 0, 0, 0, -8, -8, 0, 16], [0, -128, -64, 128, -80, 0, -17, 0, 0, 0, 16, -64], [-55, 0, 0, -65, -18, 0, 0, 0, -18, -18, 0, -29], [0, 0, 0, -8, 78, 0, 13, 13, -74, 78, 0, 4], [0, 48, 24, -48, 16, 0, 112, 0, 0, 0, 8, 24], [316, -30, 18, 0, 0, 316, 0, 0, -6, -6, 6, 0], [-222, 28, 24, 0, 0, -222, 0, 0, 26, 26, -26, 0], [0, -60, -30, 0, 0, 0, 0, 62, -15, 45, 15, 0], [12, 0, 0, 50, 21, 0, 0, 0, 21, 21, 0, 8], [0, 12, 6, -12, -7, 0, -98, 0, 0, 0, 13, 6], [215, 0, 0, 61, 4, 0, 0, 0, 4, 4, 0, 53], [0, -80, 28, 80, 26, 126, 0, 0, 0, 0, 26, 28], [0, 108, 54, 0, 0, 0, 0, 92, -17, -37, 17, 0], [0, -24, -12, 24, 54, 0, 28, 0, 0, 0, -66, -12], [-62, 92, -84, 0, 0, -62, 0, 0, 4, 4, -4, 0], [0, 0, 0, -148, 87, 0, -42, -42, -13, 87, 0, 74], [0, 128, 64, 0, 0, 0, 0, -114, 20, -84, -20, 0], [0, -74, 14, 74, 30, 184, 0, 0, 0, 0, 30, 14], [-135, -125, 37, 0, 0, -135, 0, 0, -44, -44, 44, 0], [356, -34, 76, 0, 0, 356, 0, 0, 21, 21, -21, 0], [0, 50, -114, -50, 32, -40, 0, 0, 0, 0, 32, -114], [0, 0, 0, -96, -32, 0, -53, -53, 80, -32, 0, 48], [-118, 0, 0, 64, 20, 0, 0, 0, 20, 20, 0, 24], [0, -76, -38, 76, 11, 0, 48, 0, 0, 0, -49, -38], [-236, 0, 0, -106, -8, 0, 0, 0, -8, -8, 0, -90], [0, 104, 52, 0, 0, 0, 0, -32, 6, -58, -6, 0], [0, -4, -2, 0, 0, 0, 0, 80, 55, -53, -55, 0], [58, 0, 0, -72, 12, 0, 0, 0, 12, 12, 0, -96], [-108, -66, 64, 0, 0, -108, 0, 0, -1, -1, 1, 0], [387, 0, 0, 57, 36, 0, 0, 0, 36, 36, 0, -15], [0, 0, 0, -8, 34, 0, 128, 128, -30, 34, 0, 4], [0, 168, 84, 0, 0, 0, 0, -45, 30, -114, -30, 0], [0, 8, 4, -8, -38, 0, -30, 0, 0, 0, 42, 4], [0, -60, -30, 60, 23, 0, -32, 0, 0, 0, -53, -30], [0, 0, 0, 132, 5, 0, -80, -80, -71, 5, 0, -66], [0, 76, 38, 0, 0, 0, 0, -128, -85, 47, 85, 0], [0, 0, 0, 136, -18, 0, 92, 92, -50, -18, 0, -68], [233, 67, 77, 0, 0, 233, 0, 0, 72, 72, -72, 0], [0, -50, 50, 50, 0, 292, 0, 0, 0, 0, 0, 50], [0, 48, 24, 0, 0, 0, 0, 87, -56, 32, 56, 0], [-222, 156, -100, 0, 0, -222, 0, 0, 28, 28, -28, 0], [0, 0, 0, 108, -73, 0, -50, -50, 19, -73, 0, -54], [0, -44, 88, 44, -22, -162, 0, 0, 0, 0, -22, 88], [0, 32, 16, -32, -20, 0, 5, 0, 0, 0, 36, 16], [-172, -98, 28, 0, 0, -172, 0, 0, -35, -35, 35, 0], [0, -4, -2, 4, -99, 0, 50, 0, 0, 0, 97, -2], [0, 104, 44, -104, -74, -154, 0, 0, 0, 0, -74, 44], [0, 0, 0, -72, 66, 0, -41, -41, -30, 66, 0, 36], [-250, 36, 60, 0, 0, -250, 0, 0, 48, 48, -48, 0], [0, 16, 8, -16, 0, 0, -216, 0, 0, 0, 8, 8], [510, 0, 0, -104, -26, 0, 0, 0, -26, -26, 0, -52], [0, -192, -96, 0, 0, 0, 0, 40, -80, 176, 80, 0], [0, 134, -54, -134, -40, 248, 0, 0, 0, 0, -40, -54], [340, 0, 0, 170, 69, 0, 0, 0, 69, 69, 0, 32], [0, -176, -88, 176, -108, 0, -17, 0, 0, 0, 20, -88], [0, 0, 0, 0, -68, 0, 164, 164, 68, -68, 0, 0], [0, -134, -4, 134, 69, 436, 0, 0, 0, 0, 69, -4], [0, 0, 0, 208, -80, 0, -133, -133, -24, -80, 0, -104], [0, 56, 28, -56, 90, 0, -54, 0, 0, 0, -62, 28], [-244, 158, 10, 0, 0, -244, 0, 0, 84, 84, -84, 0], [0, 0, 0, -292, 59, 0, 38, 38, 87, 59, 0, 146], [0, -65, -67, 65, 66, -199, 0, 0, 0, 0, 66, -67], [-586, 0, 0, -12, -68, 0, 0, 0, -68, -68, 0, 124], [97, 203, -107, 0, 0, 97, 0, 0, 48, 48, -48, 0], [0, -4, -2, 4, 29, 0, 104, 0, 0, 0, -31, -2], [0, -168, -84, 0, 0, 0, 0, 35, 78, 6, -78, 0], [164, 0, 0, -94, -36, 0, 0, 0, -36, -36, 0, -22], [624, 2, -6, 0, 0, 624, 0, 0, -2, -2, 2, 0], [0, -160, -80, 0, 0, 0, 0, 18, 12, 68, -12, 0], [0, 0, 0, -16, 4, 0, 234, 234, 4, 4, 0, 8], [579, 85, -61, 0, 0, 579, 0, 0, 12, 12, -12, 0], [0, 252, 126, -252, 101, 0, 190, 0, 0, 0, 25, 126], [0, 0, 0, 260, -119, 0, -196, -196, -11, -119, 0, -130], [0, 92, 46, 0, 0, 0, 0, -16, 59, -105, -59, 0], [-128, 0, 0, -18, 44, 0, 0, 0, 44, 44, 0, -106], [-392, 30, -10, 0, 0, -392, 0, 0, 10, 10, -10, 0], [-532, 0, 0, 318, 90, 0, 0, 0, 90, 90, 0, 138], [0, 107, -35, -107, -36, -3, 0, 0, 0, 0, -36, -35], [0, 120, 60, -120, -106, 0, 51, 0, 0, 0, 166, 60], [603, 0, 0, -103, 14, 0, 0, 0, 14, 14, 0, -131], [0, 106, -168, -106, 31, 244, 0, 0, 0, 0, 31, -168], [0, 0, 0, 160, -136, 0, -139, -139, 56, -136, 0, -80], [174, -312, 8, 0, 0, 174, 0, 0, -152, -152, 152, 0], [0, -168, -84, 168, -122, 0, -160, 0, 0, 0, 38, -84], [0, 0, 0, 220, -253, 0, -108, -108, 143, -253, 0, -110], [0, -53, 157, 53, -52, 589, 0, 0, 0, 0, -52, 157], [0, 0, 0, -232, -74, 0, -30, -30, 190, -74, 0, 116], [-505, 0, 0, 5, 62, 0, 0, 0, 62, 62, 0, -119], [0, 154, -34, -154, -60, 416, 0, 0, 0, 0, -60, -34], [0, 40, 20, 0, 0, 0, 0, -79, 42, -62, -42, 0], [0, -392, -196, 0, 0, 0, 0, 28, -14, 210, 14, 0], [104, -198, -46, 0, 0, 104, 0, 0, -122, -122, 122, 0], [-590, 0, 0, -220, -18, 0, 0, 0, -18, -18, 0, -184], [0, 0, 0, 484, -275, 0, -188, -188, 33, -275, 0, -242], [0, 144, 72, 0, 0, 0, 0, -274, -172, 100, 172, 0], [0, -332, -166, 332, -137, 0, -92, 0, 0, 0, -29, -166], [0, 0, 0, -132, -41, 0, 236, 236, 107, -41, 0, 66], [0, 488, 244, 0, 0, 0, 0, 128, -98, -146, 98, 0], [-992, -34, -38, 0, 0, -992, 0, 0, -36, -36, 36, 0], [954, 0, 0, 52, -32, 0, 0, 0, -32, -32, 0, 116], [0, -113, 61, 113, 26, 41, 0, 0, 0, 0, 26, 61], [0, 356, 178, 0, 0, 0, 0, 34, -55, -123, 55, 0], [282, 0, 0, -216, -76, 0, 0, 0, -76, -76, 0, -64], [0, 0, 0, -44, 149, 0, -104, -104, -127, 149, 0, 22], [0, 256, 128, 0, 0, 0, 0, 99, -28, -100, 28, 0], [0, 44, 4, -44, -24, 782, 0, 0, 0, 0, -24, 4], [0, -72, -36, 72, 26, 0, 46, 0, 0, 0, -62, -36], [0, 0, 0, 0, 212, 0, 160, 0, 0, 0, -212, 0], [0, -413, 141, 413, 136, 773, 0, 0, 0, 0, 136, 141]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_196_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_196_3_g_j();".
// 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_3_g_j(:prec:=12)
    chi := MakeCharacter_196_g();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    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_3_g_j();".
// 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_3_g_j( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_196_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![200704, 0, -114688, 0, 51200, 0, -7296, 0, 768, 0, -32, 0, 1]>,<5,R![1024, -896, 720, -120, 32, 2, 1]>,<11,R![12036125753344, 0, -277100888064, 0, 4603248640, 0, -33955840, 0, 182272, 0, -512, 0, 1]>],Snew);
    return Vf;
end function;