
// Make newform 7942.2.a.bj in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7942_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_7942_2_a_bj();".
// 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_7942_2_a_bj();".
// 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 := [-2, -8, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-5, 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_7942_a();"
function MakeCharacter_7942_a()
    N := 7942;
    order := 1;
    char_gens := [5777, 6139];
    v := [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_7942_a_Hecke(Kf)
    return MakeCharacter_7942_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 := [[1, 0, 0], [0, 1, 0], [2, 0, 0], [2, 1, 0], [1, 0, 0], [-2, 0, -1], [3, -1, 1], [0, 0, 0], [4, -2, 0], [1, 0, 0], [-1, -2, 1], [-1, 3, -1], [-3, -1, -1], [2, -1, -1], [-3, 1, -2], [0, -4, 0], [0, 0, 0], [4, -2, -1], [0, -3, 0], [2, -1, -1], [3, -1, -1], [-2, 3, 0], [2, 3, 1], [-1, -2, 2], [3, 2, -2], [2, 0, -1], [3, -1, 2], [-9, -5, 2], [-2, -4, -1], [5, 2, -2], [-2, 0, 2], [3, 5, -2], [6, 4, -1], [4, -6, 0], [5, 6, -1], [6, 1, 4], [0, -4, 0], [-2, 2, -4], [-4, -5, 4], [5, 2, -1], [-10, 2, 0], [3, -5, -1], [15, 1, -2], [-7, 3, 1], [-11, -2, 2], [14, 1, 1], [8, 6, 0], [14, -1, -1], [7, 6, 1], [9, -1, -3], [7, -1, 5], [-12, -4, 0], [2, 4, 2], [2, -3, 2], [2, -2, 4], [12, -6, -2], [5, -1, 1], [-12, 0, 0], [4, 2, 1], [1, 3, -3], [4, 2, -4], [-13, 4, 0], [-7, -11, 2], [-11, -5, 2], [-4, -2, 3], [-9, 1, -5], [-4, 1, 2], [0, -4, 6], [-3, -3, -2], [5, 2, 6], [-5, 8, 4], [16, -6, 2], [14, 5, -3], [29, 4, -1], [10, -3, -4], [8, -6, 0], [15, 3, -3], [-13, -3, 1], [-15, 4, 3], [7, 11, -5], [-14, 1, 0], [-17, 3, 1], [14, -3, -2], [12, -2, 7], [18, 0, -2], [2, 5, 4], [-19, -2, 3], [-15, 1, -1], [8, -6, -3], [-7, -5, 2], [0, -1, -2], [12, 1, -2], [10, -7, 3], [8, 2, -4], [-2, 0, 2], [10, -4, 2], [14, 4, -2], [-18, 8, 1], [15, -1, 2], [-15, 8, 3], [-2, 1, 1], [26, 0, -1], [-12, -6, 0], [12, 0, 6], [9, 5, -2], [-1, 2, 5], [22, -1, 0], [6, -4, 2], [22, -1, 1], [-2, -8, 4], [2, 1, 2], [6, 12, 1], [6, 4, 1], [32, -6, -2], [-22, -5, -1], [15, 4, 0], [10, -7, 2], [-14, -5, 5], [7, 7, -3], [29, -1, 2], [11, 1, -1], [-13, -13, 1], [-28, 6, 1], [-10, -9, 4], [-28, 5, 0], [23, -6, 2], [14, 8, 0], [14, -7, 1], [-10, 9, 3], [31, 6, -3], [-11, 3, 2], [-26, 7, 2], [-18, 1, 5], [0, -12, -2], [-12, 8, -6], [-34, 8, 2], [-15, -3, 5], [2, 7, -5], [11, 3, -5], [-3, 5, -11], [10, -1, 5], [-15, 2, -5], [19, 7, -6], [6, 3, 5], [-9, 1, -7], [6, 5, -5], [-19, -4, 7], [15, -7, -1], [-10, 2, -8], [-7, -13, -2], [-26, 0, 4], [-15, 4, -5], [-14, 13, -2], [-4, 9, 6], [-4, 2, -10], [-16, 8, -8], [4, -3, 10], [23, 4, -4], [2, -16, 0], [5, -2, -9], [-16, -10, -2], [-2, 0, 4], [-8, 2, -2], [-18, 11, 4], [15, -2, -2], [10, 11, -5], [-9, -5, -6], [14, -8, 4], [-18, 8, 8], [-23, -3, 5], [-2, -1, 3], [-6, -12, 6], [-40, 0, -4], [32, -4, 0], [-28, 2, 0], [5, -12, 8], [2, -1, -9], [-25, 1, -1], [0, -1, 0], [-20, -6, -7], [-35, 5, -2], [-7, 15, 6], [-14, 8, -2], [3, -9, 7], [-1, 3, -6], [-13, -9, 5], [4, 6, -1], [-14, -11, -2], [-6, -8, -2], [-8, -7, 0], [-13, 12, 1], [-6, -5, 11], [-10, 1, -12], [-37, 7, 5], [23, -2, 9], [2, -8, 9], [-2, 0, 10], [-10, 20, 4], [6, 0, 8], [26, 8, -2], [-21, 2, -2], [26, -3, -2], [-8, 8, -6], [-46, -4, 0], [-48, -10, 2], [-12, 8, 2], [-26, -5, 9], [20, -2, -8], [-4, -8, 6], [8, 2, 2], [30, 16, -6], [7, 15, -1], [-2, 1, -3], [6, 9, 6], [0, -2, 10], [-9, -8, 12], [-10, -8, -2], [21, -3, 1], [12, 8, 8], [5, 1, -9], [-22, -8, 9], [-12, -4, 0], [50, -4, 1], [-20, -10, 4], [-23, 13, 2], [-11, -14, 7], [-26, -8, 0], [-32, 6, 0], [-20, 8, -12], [-47, 3, -6], [-5, -9, -9], [21, -1, -2], [10, 15, -10], [-21, -13, -3], [-42, 4, 2], [24, 4, 4], [16, 2, 1], [-16, 2, 5], [-18, -10, 8], [13, 5, -6], [18, -18, 0], [-13, -5, 6], [-24, -8, 4], [11, 9, -9], [-42, 8, 4], [28, -13, -6], [5, -15, -2], [-20, 14, 2], [-4, -6, 4], [-10, 17, -8], [-15, 2, 6], [3, -9, -3], [-25, 3, -10], [-6, -12, 5], [10, 14, 0], [-7, 2, -1], [-24, 8, 0], [16, -8, 0], [7, -5, -11], [-11, -3, 7], [4, 0, -12], [-34, -5, 7], [-23, 16, -4], [31, -6, 5], [-38, 12, 5], [8, 2, 6], [18, -8, -8], [-14, 12, 5], [-23, 1, 6], [-30, -12, -3], [34, 4, -8], [-50, -12, 2], [4, -14, 3], [10, -10, 8], [49, -13, -5], [22, 17, -9], [-6, 8, -6], [-3, -2, -1], [-46, -4, 2], [20, 22, -8], [-4, -9, -4], [-11, 7, -14], [18, 12, -10], [-13, 2, -10], [-10, -17, 11], [2, 21, -1], [-50, -8, 3], [-22, -14, -4], [-40, 6, -8], [-31, 5, 5], [19, 5, 7], [18, -2, 16], [-7, -19, 7], [14, 7, -1], [19, -2, 10], [-13, 0, -7], [-5, -5, 10], [15, 1, 5], [29, 3, -10], [-7, -5, -6], [32, -4, 2], [24, 6, -1], [14, -10, 16], [-16, -12, -4], [30, 12, -2], [-16, 10, 9], [16, -7, 0], [-6, -4, -6], [-28, -10, 12], [-31, -2, -5], [48, 1, 4], [38, -8, 6], [-42, 4, -2], [-4, -7, 8], [8, -12, -8], [35, -23, -5], [14, 12, -10], [-22, 8, -6], [6, -24, 5], [-26, 16, -4], [-10, -11, -7], [-35, -26, 11], [-53, 8, 0], [-4, -6, -16], [-6, 4, 2], [15, -24, -3], [20, -1, 0], [-58, -11, 6], [14, 19, -2], [12, 22, -13], [-3, 14, 6], [-17, -21, 3], [16, -14, -6], [14, 5, 5], [45, 1, -6], [-24, 13, -2], [57, 3, -3], [-1, -7, -1], [-46, -6, 0], [26, -14, 8], [-10, -8, -6], [53, -12, -4], [40, -18, 1], [-7, 11, -10], [-3, 21, -11], [-34, 3, -3], [-16, 0, 10], [-28, 2, 2], [-24, 3, -18], [63, -9, 3], [16, -8, 16], [50, -6, -8], [-23, -25, 13], [18, -21, -6], [51, 4, 5], [8, 24, -8], [12, 4, 0], [1, 27, -6], [-20, -16, -4], [-51, 11, 2], [10, 16, -11], [9, 7, -1], [11, -15, 14], [18, 27, -13], [-12, -12, 8], [37, -6, -6], [24, -30, -9], [-28, 3, 12], [17, -1, -11], [-22, -6, -4], [6, 8, -2], [22, 28, -10], [-36, -2, -13], [6, 17, -8], [-30, -24, 10], [-16, -5, -12], [-12, 4, 4], [-10, -4, 12], [4, 16, -2], [-14, 4, -14], [64, 16, -8], [3, 18, 10], [-52, -20, 8], [47, 1, -3], [26, -7, -13], [-13, -11, -6], [22, 3, -7], [-44, -4, 0], [16, 32, -12], [-48, -4, -4], [-35, 14, 3], [-38, -20, 2], [48, 15, -2], [56, 23, -8], [34, -1, -3], [-27, 11, 11], [2, -32, 6], [-46, 0, -1], [50, -12, -10], [26, -20, 1], [-24, 2, -3], [27, -4, -4], [20, 15, 2], [26, 12, 3], [-10, 0, 3], [-32, -15, 2], [-54, -20, 6], [-43, 23, 7], [-32, 9, -18], [-18, -4, 2], [76, 8, -4], [-52, -10, 1], [68, 6, -2], [-38, 11, -13], [3, 3, -9], [-12, 0, -8], [20, 16, -16], [-18, 7, 11], [35, -6, 6], [4, -5, -20], [53, 7, 7], [11, 8, 0], [-10, 9, -3], [26, -9, -3], [-3, 14, -2], [-19, -9, 9], [56, -6, 14], [-45, -17, 11], [-54, 7, -2], [24, -12, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7942_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7942_2_a_bj();".
// 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_7942_2_a_bj(:prec:=3)
    chi := MakeCharacter_7942_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_7942_2_a_bj();".
// 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_7942_2_a_bj( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7942_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, -8, 0, 1]>,<5,R![-2, 1]>,<13,R![-71, -5, 7, 1]>],Snew);
    return Vf;
end function;