
// Make newform 8112.2.a.cg in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_8112_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_8112_2_a_cg();".
// 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_8112_2_a_cg();".
// 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 := [1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 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_8112_a();"
function MakeCharacter_8112_a()
    N := 8112;
    order := 1;
    char_gens := [5071, 6085, 2705, 3889];
    v := [1, 1, 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_8112_a_Hecke(Kf)
    return MakeCharacter_8112_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 := 2;
    raw_aps := [[0, 0, 0], [1, 0, 0], [-2, 1, 1], [0, 1, -1], [0, 3, -2], [0, 0, 0], [0, -2, -1], [-2, 0, 1], [2, -5, 1], [1, -3, 2], [-3, -5, 2], [-7, 0, 1], [-2, -3, 2], [5, 2, 2], [2, 0, -1], [-8, 3, -4], [-2, 2, 2], [-8, 6, -5], [7, -7, 3], [1, -5, -2], [2, -9, 3], [-3, 3, -3], [5, -2, 1], [-3, 1, -7], [-1, -2, -10], [4, -3, 7], [2, 4, -4], [4, -3, -4], [0, -5, 10], [7, 2, -1], [-3, 0, 6], [-7, 9, 0], [-5, 0, 10], [4, 5, 4], [-17, 3, -3], [-8, 1, 7], [-3, 14, -4], [11, -5, 11], [9, -2, 0], [13, -5, 16], [-4, 1, -13], [-15, 7, -1], [-1, 13, -1], [-9, 12, 4], [-11, 8, 1], [-7, -1, -5], [-3, -5, 10], [-14, 7, -12], [11, -8, 8], [-7, 13, -10], [6, 2, -1], [5, -2, 15], [1, 1, 13], [12, -18, 17], [-7, 7, -15], [-17, 11, -17], [8, 8, 1], [-21, 0, 1], [-10, 1, 8], [-8, 7, -5], [-14, 14, -13], [12, -17, 15], [-7, 1, 0], [17, 1, 3], [12, -10, 23], [-5, -7, -7], [0, -9, 4], [3, 1, -2], [9, -2, 3], [-14, 0, -8], [3, 21, -11], [-15, 7, -19], [9, -11, 1], [10, -1, 16], [-1, 6, 5], [-3, -3, -13], [-15, -4, 4], [8, -4, 1], [-7, 13, -12], [28, -1, 3], [5, -12, 8], [-4, -6, 1], [11, 9, 7], [-6, -14, -1], [-3, 7, -18], [-6, -4, 1], [14, 4, -7], [-10, -9, -5], [-5, -8, -4], [-16, -4, -8], [-5, 20, 6], [-1, -2, -3], [-29, 12, -6], [14, -23, 18], [6, -16, 18], [4, -21, 9], [8, 2, 0], [-13, 16, -14], [-22, 17, -15], [-6, 5, 14], [-15, 16, 11], [-19, -5, -8], [13, 10, -1], [-16, 5, -12], [20, -27, 21], [-9, -4, -1], [-4, 14, -12], [14, -26, 8], [-25, 11, 5], [-7, 2, -24], [-15, 9, -14], [11, -24, 17], [-2, 12, -12], [6, 22, -11], [-31, 14, -27], [28, -9, 27], [-8, 8, -29], [-4, 13, -2], [7, -23, 1], [22, 17, -8], [-1, -5, -23], [-8, 3, 0], [3, 0, -1], [18, -3, 3], [18, -15, 20], [2, -3, -14], [-23, 11, -10], [0, 4, 16], [3, -2, -25], [-25, 1, -19], [-5, 24, -17], [-4, -16, 17], [28, -9, 1], [16, 1, 4], [17, 7, 7], [20, -16, 10], [18, 7, 7], [-2, -13, 0], [16, 4, -2], [5, 2, 2], [-28, 26, -19], [-16, 29, 6], [22, -21, 3], [5, -3, -28], [28, 1, 19], [19, -6, 12], [-4, -5, -11], [-12, 22, 12], [-40, 25, -31], [0, 0, 15], [-31, -6, 4], [-36, 2, -7], [-4, -10, -7], [15, -7, -8], [16, -3, -24], [-37, 19, -16], [18, -11, -10], [-5, -14, -2], [19, -19, 9], [-14, 11, 18], [-28, -11, 8], [-7, -25, 9], [-9, 28, -25], [17, -18, 28], [-7, -16, -9], [-3, 27, -9], [-8, -1, 2], [7, -23, -1], [6, 6, -8], [25, -36, 37], [-12, 38, -11], [23, -33, 32], [-4, 5, -6], [-29, 6, -13], [3, 22, -9], [-31, 10, -6], [14, 11, -1], [1, 1, -28], [15, -28, 9], [8, 17, 7], [7, -24, 14], [-32, -6, 2], [0, -3, -18], [14, 1, 21], [-4, 20, -21], [-15, 31, -7], [12, -34, 1], [-43, 5, -13], [30, -26, 45], [9, -30, 21], [-29, -5, 16], [41, -22, 38], [34, -16, 39], [17, -4, 1], [-16, 26, 16], [5, -19, 30], [-4, 25, -11], [-24, -14, 4], [-25, 26, -40], [-10, -33, 11], [-23, -2, 19], [35, -12, 31], [-6, -15, 19], [-6, 43, -9], [43, -24, 17], [-13, 9, -5], [8, 7, -13], [-40, 7, -10], [22, 3, -12], [3, -10, 6], [-23, 10, -16], [-4, -7, -41], [-36, 21, -2], [13, -38, 7], [-4, -17, -9], [-24, 26, -28], [8, -34, 7], [-14, 6, 24], [1, 29, 11], [6, -30, 28], [-24, 18, -28], [-33, 23, -2], [27, -9, 19], [22, 17, 4], [25, 7, 13], [11, -39, 9], [-33, 38, -25], [-9, 11, -25], [27, -15, 25], [-43, -18, 8], [28, -11, -13], [38, 1, 21], [-14, 10, -31], [-33, 28, -29], [30, -13, 13], [16, 37, -8], [-21, 20, -15], [-24, 10, -4], [43, 5, 20], [15, 27, 8], [-34, 31, -48], [5, 14, 15], [-1, -34, 6], [-18, 13, -2], [24, 13, 2], [-15, -25, 17], [25, -35, 14], [-37, 37, -14], [-32, 14, -19], [-13, -8, 28], [-32, 30, -27], [-9, -10, -40], [30, 8, -17], [-23, 48, -37], [20, -14, 42], [-17, 12, 0], [-19, 4, -23], [4, -2, -3], [5, 0, -10], [17, -16, 47], [-31, 24, 25], [-25, 46, -36], [-21, 37, -42], [-9, -9, -37], [16, 16, -13], [-32, 19, 0], [9, -29, 30], [41, 20, -11], [24, 4, 13], [50, -1, -6], [-38, -23, 6], [41, -4, -2], [3, 20, 8], [2, -11, 2], [30, -51, 38], [10, -32, 14], [-17, 11, 15], [-56, 29, -38], [17, -25, -25], [-51, 16, -13], [21, -15, -20], [-29, -17, 20], [3, 0, 1], [20, 7, 24], [34, -30, -18], [26, -28, 14], [-7, -6, 11], [-37, 10, -7], [-1, -26, -26], [13, -41, 7], [60, -5, 12], [-23, 15, -12], [31, -21, 28], [-42, 6, -26], [-5, 6, 11], [6, -22, -1], [-16, 43, -33], [20, 17, -20], [-14, 10, -25], [-73, 21, -28], [20, 15, -13], [-11, 11, -16], [-10, 27, 8], [-5, 7, -41], [-18, 15, -30], [32, -41, 44], [33, 4, 18], [37, -1, -14], [15, -41, 0], [-6, 26, 4], [-21, 36, -12], [49, -19, 32], [-12, -38, 1], [-24, 20, 7], [-10, 31, -16], [4, -22, -4], [44, 11, -1], [-15, 18, -26], [-29, 19, -6], [30, -21, 2], [-34, -23, 0], [31, -27, -10], [24, -14, 21], [-6, 4, -25], [17, -15, 20], [40, -4, 10], [46, -14, -22], [40, 6, -5], [-37, 11, 22], [-24, 26, -31], [-58, 26, -50], [-36, 14, -34], [28, -18, -3], [-14, -19, -15], [42, -7, 6], [-34, 12, 36], [40, -8, 23], [-18, 33, -28], [-2, 6, 13], [-28, -16, -12], [-46, 5, -1], [-2, -33, -14], [88, -9, 18], [14, 6, -27], [-23, -11, 33], [38, -39, 50], [13, 5, -25], [14, 2, 56], [39, -35, 52], [3, 32, -11], [-35, 7, 13], [-8, -3, 23], [-48, 17, 8], [14, 27, -14], [12, -16, 54], [29, 29, -23], [58, 11, 1], [-51, 23, 11], [58, -22, 6], [15, -5, -16], [-57, 54, -58], [18, -43, 40], [30, -33, 4], [-14, 39, -45], [1, -9, -17], [12, 2, -23], [-39, 2, -28], [19, -38, -6], [45, -4, 20], [6, -64, 17], [-52, 19, -16], [29, -9, -16], [-20, 14, -4], [-13, 41, -26], [-62, 23, -29], [-8, -32, 4], [-10, 27, -6], [11, 21, -1], [11, 10, -16], [-11, 7, -18], [-61, 20, -36], [-22, 32, -41], [-7, -13, -1], [-36, 29, -8], [-17, -29, 31], [-6, 69, -32], [14, 0, -26], [-47, 17, 1], [27, 9, 27], [32, -5, 1], [-16, -15, -38], [-36, 24, -31], [45, 13, 0], [24, -70, 42], [2, 36, -34], [-2, 40, -24], [-4, 22, 15], [57, -27, 42], [21, -12, -3], [-26, -16, -16], [13, 42, -9], [5, 9, -26], [39, -15, 0], [26, -57, 27], [51, -28, 2], [-48, -5, -25], [13, -18, -51], [4, -43, 2], [-26, -12, 36], [-13, 49, -40], [-9, 70, -23], [-37, 48, -37], [-20, 26, 14], [10, 43, -40], [-17, 9, -24], [-52, 33, -10], [79, -25, 24], [-33, 40, 16], [-33, -12, 12], [-7, 35, -45], [31, 5, -6], [-3, 59, -45], [40, 1, 27], [3, 5, 16], [47, -33, -11], [-26, -9, 15], [-2, 47, 10], [-16, 19, -59], [-1, -33, 19], [6, -22, 49]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8112_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8112_2_a_cg();".
// 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_8112_2_a_cg(:prec:=3)
    chi := MakeCharacter_8112_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_8112_2_a_cg();".
// 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_8112_2_a_cg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8112_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-13, 5, 6, 1]>,<7,R![1, -1, -2, 1]>,<11,R![41, -8, -5, 1]>],Snew);
    return Vf;
end function;