
// Make newform 8112.2.a.cf in Magma, downloaded from the LMFDB on 25 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_cf();".
// 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_cf();".
// 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], [1, 1, 0], [-3, -1, 0], [-2, 4, -3], [0, 0, 0], [-3, 1, -1], [-3, 1, 3], [-3, 5, -2], [-3, 2, 1], [-5, 2, -5], [4, 1, -1], [0, 0, -1], [-1, 2, -4], [7, -3, 9], [-4, -2, -1], [8, -6, 4], [-7, 3, -5], [-4, 3, -4], [1, -2, -5], [7, -1, 2], [0, 5, -4], [6, -3, -1], [-2, -1, -2], [-3, 10, -4], [1, 3, 6], [-2, 8, 4], [4, -6, -3], [6, -6, 3], [-6, -1, -7], [-1, 10, -6], [-1, -4, 11], [-1, 4, 8], [4, -4, 11], [-12, 7, -12], [1, -5, 8], [1, 4, 2], [-4, 3, 2], [3, 10, 0], [7, 0, 5], [-7, -5, 6], [-6, 11, -14], [-6, -3, -8], [-1, 8, -4], [14, 9, -3], [18, -9, 10], [3, -2, -1], [-2, 8, 5], [-3, 14, -10], [3, 2, -3], [-13, 13, -13], [-4, 11, -7], [4, -3, -2], [3, -1, 1], [-14, 11, -16], [10, 9, -2], [11, -17, 11], [-14, 13, -5], [6, 4, 7], [21, -5, 0], [3, 7, -1], [25, -9, 8], [5, -8, -13], [4, -3, -8], [9, 11, -1], [8, -1, -14], [4, 12, -11], [9, -10, 21], [-4, 15, 1], [-14, 8, -4], [-4, 3, -6], [14, -5, 8], [-12, -7, -10], [-30, 4, -11], [18, -7, 17], [12, -7, 12], [-21, 6, -10], [19, -11, 7], [-13, 4, 7], [-15, 19, -6], [-9, -6, 10], [11, 13, -7], [2, 5, -16], [-9, -1, 11], [3, -6, -1], [9, -5, -9], [-7, 15, 7], [-17, 3, -6], [9, 14, -2], [-4, 28, -8], [-13, 0, 0], [16, -3, -13], [-3, 14, -10], [-8, 12, -5], [20, 6, 10], [11, -19, 10], [-8, -20, 2], [3, -4, 24], [-19, 21, -22], [-4, 30, -15], [10, -9, -11], [27, 0, 5], [0, 11, -19], [-8, 26, -15], [-1, 17, 2], [-4, -5, -3], [12, 4, -10], [-6, 12, 2], [-8, 11, 12], [5, -4, -2], [3, -26, 13], [26, 13, -1], [22, -12, 24], [-11, 17, -7], [-12, 9, 5], [-23, 3, 0], [9, -21, 5], [-10, 20, -1], [8, -29, 18], [-2, -6, -3], [-10, 5, -12], [8, -12, 5], [-18, 15, -25], [-17, 3, 2], [-2, 8, -21], [40, -4, 11], [11, -18, 23], [0, -28, 20], [12, -9, 15], [26, 5, 2], [-36, 23, -39], [-1, -9, 3], [-13, -7, -8], [4, 0, -13], [0, 13, 6], [2, 18, -18], [43, -5, 8], [-10, -12, 1], [6, 30, -6], [17, 0, 26], [-5, -11, 21], [18, -20, 15], [-25, 7, 18], [-13, 12, 23], [-7, -17, -4], [5, 6, -16], [15, -7, 12], [28, -8, 22], [-17, 21, -22], [33, -7, -3], [1, 20, 14], [-9, -9, 13], [3, 1, -19], [21, 4, 15], [36, -8, 11], [13, -8, 9], [-20, 14, -19], [-37, 16, -14], [26, -31, 30], [-20, 20, -23], [-4, -14, 1], [18, -5, -4], [-20, 23, -27], [35, 2, -12], [24, -5, 3], [8, -7, -6], [14, 6, 3], [-36, 15, -12], [2, -20, -14], [18, -7, -23], [-41, 3, -11], [-13, 0, -7], [-30, 40, -37], [-8, -9, 19], [-36, 27, -45], [9, 4, 2], [15, -25, 2], [11, -4, 7], [-10, -19, -1], [1, -1, 32], [-19, 10, -30], [30, 10, -8], [-14, 38, -7], [5, -15, -8], [-23, -3, 13], [14, 11, 4], [27, 9, -15], [6, 23, 12], [-7, -7, -31], [-18, 33, -9], [-9, 24, -27], [-15, -16, 14], [7, 3, 21], [-34, -3, -3], [-12, 20, 18], [-43, 10, -23], [19, -19, 42], [-4, -8, 14], [13, -38, 16], [-45, 3, 8], [24, -5, -3], [-4, 15, 1], [-9, -29, 4], [-25, -9, 2], [-8, -11, 9], [34, -3, -8], [-23, -17, 18], [-10, 0, -39], [22, -10, 7], [-11, -10, 16], [21, -12, 18], [13, -5, 30], [-22, -6, -3], [-40, -9, 9], [17, -1, 28], [-48, 24, -18], [-15, 39, -13], [2, -20, -10], [4, -3, -20], [10, 0, -30], [-32, -12, -6], [-15, -6, 27], [-42, 17, -18], [-10, 16, -9], [-30, -17, 0], [14, 9, -2], [22, -33, 29], [-6, -3, -34], [50, -7, -2], [-25, -18, 8], [13, -45, 8], [57, -23, 34], [-7, -11, -11], [-34, 19, 3], [-31, 25, -20], [-40, -14, 13], [-26, 13, 19], [24, 12, -2], [-23, 12, -25], [-3, 48, -15], [10, -14, 7], [-22, 3, -29], [-27, -10, 8], [28, -34, 21], [-6, -4, 15], [42, -25, 20], [31, 6, -3], [19, -54, 33], [-45, 13, 9], [9, -30, 26], [39, -35, 33], [-39, 26, -40], [-41, -19, 1], [-38, 3, -7], [-14, 38, -20], [-15, 34, -2], [20, -27, 19], [-41, 21, 5], [33, -28, 12], [-18, 31, -39], [32, -11, 27], [1, -46, 16], [13, 18, -11], [24, 11, -14], [-43, 29, -51], [4, -4, -15], [1, -6, 27], [-10, -7, 9], [-5, -19, -9], [-20, 4, 33], [-32, -2, 25], [35, -2, 6], [-41, 12, 24], [-8, -22, -3], [4, -2, -27], [52, -26, 14], [-34, 21, -26], [2, 6, 25], [-30, 3, 14], [-20, 39, -5], [-61, 20, -29], [11, 4, -3], [-12, 1, -19], [-24, -8, 21], [-44, 6, -32], [-4, -10, 34], [-6, 19, 3], [28, -3, 11], [-19, -2, 32], [16, 29, -26], [0, 42, -5], [-21, 44, 9], [-15, 8, -23], [48, -10, 28], [28, -33, 3], [23, -27, -33], [-15, -13, -26], [-28, 2, -27], [-9, -19, 23], [7, -32, 31], [-31, -17, -10], [15, -20, 25], [30, 16, -3], [2, -3, 18], [40, -18, -9], [-40, 4, 1], [-47, 32, -36], [-33, 10, -21], [57, -24, 9], [54, -8, 22], [-63, 30, -50], [43, -16, -9], [-25, -9, -11], [-11, 15, 1], [34, -6, -9], [-16, 0, -26], [-7, -9, -28], [37, 16, 2], [-27, 30, -5], [8, -12, 5], [18, -20, 3], [13, -34, -11], [-53, 31, -43], [3, -29, 13], [19, 16, -9], [-6, 14, -6], [8, 6, 20], [33, -13, 35], [39, 6, -21], [-29, 15, 1], [20, 2, -20], [-46, 10, -8], [-37, 41, 1], [45, -11, 8], [4, 10, 45], [-22, -8, 16], [13, -13, -7], [26, -22, 33], [5, -35, -7], [8, 20, -16], [-21, 11, -8], [48, 4, -11], [-18, 60, -39], [41, -15, 53], [14, -45, 14], [-20, 28, -25], [50, 3, 8], [-34, 32, -42], [-23, -16, -13], [-72, 17, -19], [-36, 9, -60], [-31, 11, 4], [-12, 22, -3], [28, -10, 55], [70, -26, 50], [22, -41, -14], [-23, 1, 14], [-16, 1, -10], [-24, 18, -4], [37, 16, -11], [45, -26, 4], [58, -30, 9], [18, -10, -5], [23, -1, 20], [14, -37, -10], [-37, 21, 17], [-13, 26, -20], [17, 10, 12], [-7, -24, 40], [17, -17, -41], [-28, 32, -15], [43, -4, -11], [12, -40, 6], [65, -42, 57], [3, 15, 14], [-24, 0, -32], [16, -40, 53], [-32, 35, -24], [5, 46, -16], [23, 14, -1], [-35, -2, -18], [19, 41, -19], [42, -13, 30], [16, -46, 9], [-20, 67, -18], [34, -10, -23], [-52, 2, 10], [-44, -19, 10], [28, -13, 20], [35, -11, 14], [10, -10, 13], [19, 15, -13], [-41, 20, -25], [-42, 22, -28], [44, 6, 10], [34, 8, 4], [-55, 51, -45], [9, -10, -31], [-80, 13, -13], [2, -56, 16], [42, -1, -29], [73, 14, 5], [-17, 12, -25], [-13, -25, 16], [7, -28, 44], [5, -21, 22], [28, 5, -31], [-30, 40, 11], [42, -52, 56], [-11, -12, 15], [-18, 33, -3], [-14, 7, 23], [14, -18, 56], [-26, 24, -19], [-25, 16, 19], [-14, 12, 19], [25, -20, 25], [11, -52, 52], [-3, 42, -26], [48, -51, 54], [-21, 26, 37], [18, 11, -34], [-51, 35, -14], [49, 4, 15], [58, -11, 52], [-49, -1, -16], [-16, -40, -7], [39, -47, 2], [92, -17, 18], [69, -17, 37]];
    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_cf();".
// 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_cf(: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_cf();".
// 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_cf( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8112_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![1, 3, -4, 1]>,<7,R![29, 31, 10, 1]>,<11,R![43, -30, -1, 1]>],Snew);
    return Vf;
end function;