
// Make newform 7938.2.a.bv in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7938_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_7938_2_a_bv();".
// 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_7938_2_a_bv();".
// 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, -4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-3, -1, 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_7938_a();"
function MakeCharacter_7938_a()
    N := 7938;
    order := 1;
    char_gens := [6077, 3727];
    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_7938_a_Hecke(Kf)
    return MakeCharacter_7938_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, 0, 0], [0, 0, 1], [0, 0, 0], [0, 0, -1], [-3, 2, 1], [2, -2, 0], [2, -3, 0], [2, 1, 0], [0, 3, -2], [-6, -1, 1], [-1, 0, 0], [-1, 1, -2], [2, 3, 3], [3, 3, 3], [-5, -1, -1], [5, 1, 2], [-3, -1, -2], [-2, 1, -4], [4, -7, -2], [-8, 1, -4], [0, -4, 1], [-1, -2, -3], [2, 4, 1], [-8, -2, 2], [10, -4, -3], [-1, 3, 0], [-7, -5, 1], [1, 1, -1], [13, -1, 3], [3, 5, -5], [0, 0, -2], [-8, 5, -3], [-5, 1, -4], [1, 5, 8], [-2, 1, 2], [-1, -3, 3], [-7, 6, -3], [-5, -1, 0], [2, -11, -1], [1, -7, 2], [0, -1, 4], [-9, 6, -3], [5, 0, 3], [-11, 8, 4], [-13, 3, 0], [-1, -6, -6], [-7, -6, -6], [-13, 7, 1], [-2, -2, -4], [6, -3, 2], [5, 4, -2], [-13, 0, 0], [-3, -6, -3], [4, 2, -1], [2, -8, 1], [0, 6, -8], [-3, -1, -8], [14, 0, 9], [5, 1, 9], [-20, 1, 2], [5, 4, 10], [-8, -5, -4], [-1, -2, -1], [4, -2, 2], [3, 3, 9], [-16, -3, -3], [15, 2, -2], [6, 6, 3], [-11, 1, 8], [2, 1, 4], [-5, 5, 9], [-10, 6, 3], [4, 1, 5], [13, -8, -1], [-10, -5, -3], [-23, 2, 3], [12, 2, -8], [1, -13, -4], [-4, 0, -3], [-10, -8, -2], [0, 2, -2], [-11, 14, 8], [-4, 6, 3], [-9, 14, 1], [4, -10, -5], [8, 4, -7], [-26, 1, 2], [0, 3, 1], [-8, 13, 8], [-11, -7, -9], [3, -3, 8], [-7, 15, 0], [14, -5, -2], [1, -5, -13], [-36, 0, -3], [1, -4, -4], [1, 11, -1], [2, -12, 9], [-15, -7, 4], [-12, -4, 7], [-18, -3, -8], [-20, 11, -5], [21, -6, 0], [-3, 14, 7], [-26, -8, -1], [8, -2, -9], [-7, -14, -8], [-15, 0, -3], [17, -3, 3], [-9, -1, -5], [-6, -7, -2], [-15, -15, 5], [-17, -11, -1], [17, 3, 15], [24, 3, -1], [-13, 15, 6], [-2, 5, 5], [19, -13, -7], [2, -5, 3], [-8, 16, 5], [-7, 12, -12], [0, -3, 0], [10, -7, -4], [8, -9, 0], [-7, 19, -4], [17, -9, -9], [-31, 10, 7], [-17, 7, -1], [-6, 5, 13], [12, -16, 1], [5, 4, -8], [6, 2, 1], [-6, -4, 1], [5, -2, -3], [-2, -20, 5], [-18, 6, -5], [-18, 11, -5], [-13, 13, -11], [3, 3, -8], [-5, -17, 2], [31, -1, 7], [19, -11, -4], [-9, 9, 6], [19, 1, 8], [-34, 4, 3], [14, -9, -3], [5, -2, 13], [11, 0, 9], [1, -1, 0], [-17, 4, 8], [-21, 3, -9], [-4, 6, -12], [1, -13, 11], [3, -1, 16], [-29, 2, 2], [13, -11, -13], [-42, 3, 3], [-7, 0, -3], [8, -2, 2], [-1, -8, -4], [4, -16, -2], [-37, -6, -3], [5, 10, 4], [-18, -6, 9], [-22, -11, -17], [-22, 3, 3], [-4, 0, -3], [-7, -9, 3], [-17, 14, 2], [-2, -1, 12], [16, 7, 2], [-29, 17, 8], [3, -1, -5], [18, -7, 13], [22, -10, -6], [39, -10, -2], [41, -5, 0], [-28, 3, -3], [-13, 21, 6], [15, 8, 13], [-1, -11, -3], [-8, -14, 11], [-20, -7, -18], [14, 10, -10], [26, 13, -11], [-3, 26, -8], [32, -9, 6], [39, 5, 10], [-29, -4, 8], [16, -14, 5], [-2, 2, -10], [-17, 1, -13], [25, -4, -2], [13, -10, -4], [10, 17, 22], [-1, 15, 15], [-2, 22, 17], [1, -10, 11], [-10, 7, -2], [-6, 9, -15], [15, -4, -11], [-34, -9, 0], [9, 20, 4], [-12, -15, 0], [19, -16, -4], [-4, -6, 0], [13, -16, -7], [-26, 17, 5], [26, -12, -6], [2, 24, -6], [-20, -13, -3], [-3, 14, 16], [-4, 13, 8], [3, -9, 6], [2, 15, -12], [-32, 4, -1], [9, 18, 14], [9, -15, 11], [-27, 15, -7], [10, -14, 8], [37, -14, 2], [7, 8, 20], [31, 7, -1], [23, 13, 7], [-19, 24, -9], [-14, 8, -20], [3, 21, 10], [3, -16, -8], [-33, 12, 9], [-18, -7, -8], [34, 13, -7], [31, -17, -1], [30, 0, 21], [8, 6, 6], [-31, -2, -20], [-5, 1, -4], [38, 4, 19], [35, 10, 13], [5, 25, -13], [0, -18, -10], [29, 6, 6], [-25, -6, -3], [15, -1, 1], [12, 3, -4], [21, -15, 12], [21, 14, 19], [22, -4, -14], [-10, 6, 3], [24, 3, 21], [-11, -20, -10], [14, 1, -11], [18, -24, -3], [28, 7, 14], [24, 12, 8], [-3, -21, 5], [-16, -3, -9], [6, 14, -14], [-31, 16, 11], [-13, 3, 9], [-11, -8, -13], [24, -3, 13], [25, 10, -4], [28, 4, 14], [24, -12, -15], [19, -17, -13], [-12, 3, 15], [66, -9, -2], [-32, 10, -10], [-33, -9, -27], [39, -22, -11], [26, -18, -15], [-12, -4, -5], [2, 9, 3], [22, -8, 8], [-15, 2, 7], [38, -17, 6], [3, 8, -17], [22, -38, -10], [24, -18, -3], [-24, 9, -12], [27, -7, -2], [-53, -10, 2], [-31, -9, -9], [-9, -1, -29], [-27, -15, -13], [6, -19, 1], [24, -18, 5], [23, 0, 3], [36, 0, -12], [-19, -14, 16], [-26, 38, 8], [-41, 11, -7], [-2, 5, 18], [23, -9, -15], [-9, -24, 21], [-10, -9, -9], [-2, 2, -16], [44, 7, -8], [51, -4, -2], [7, 25, -4], [-1, 7, 13], [10, 1, 23], [59, -5, -5], [-19, 21, 3], [5, -3, 24], [-5, 11, -24], [2, -9, -21], [-10, -23, -24], [8, 0, 15], [3, -6, -12], [-18, 15, 10], [11, -2, -13], [5, 18, 0], [2, 19, 5], [17, -9, 21], [52, 11, 11], [23, 1, 20], [-4, 9, 15], [-19, 1, 1], [23, 9, -9], [25, 7, -10], [63, -18, -3], [-20, -20, 5], [-11, 35, 15], [38, 6, 21], [14, 12, 24], [16, 22, -13], [-2, -22, -23], [22, 2, -11], [-61, 6, -12], [25, 20, 19], [36, 2, 25], [-3, 3, 23], [-17, 1, 20], [41, -29, -7], [-60, 5, 10], [-69, 6, 1], [38, 0, 6], [1, 28, -7], [-1, -3, 21], [-17, 26, 8], [26, 19, 28], [-12, -4, 13], [18, 15, 6], [66, -3, 3], [38, 6, 21], [11, -39, -6], [-2, 20, -19], [32, -8, -8], [-28, 12, -3], [53, 9, 21], [-34, -2, -32], [15, -31, 1], [-41, 37, 5], [-2, -28, -5], [9, 9, -23], [16, 14, 5], [14, -2, -12], [-1, -2, 21], [-8, -2, 20], [28, 20, 31], [-33, 3, -20], [-44, 11, -8], [-47, -5, 11], [11, -30, 3], [70, 2, -1], [-9, 5, 13], [22, -26, -16], [78, -6, -4], [-35, -17, 2], [25, 17, 11], [-27, -6, 16], [13, 4, 2], [43, 4, -16], [-63, 3, 9], [-20, 8, -8], [28, -17, -13], [-21, -12, 2], [2, -33, -15], [-19, -5, 7], [-56, 32, 9], [34, -20, 14], [-7, 28, -5], [-68, 19, 8], [-12, -36, 10], [-10, -12, 27], [7, 19, 2], [-26, 10, 17], [54, -12, 5], [-13, 0, -21], [-18, -3, 18], [56, -2, 27], [-19, 27, 24], [2, -2, 23], [27, -7, -5], [25, -23, -7], [38, -23, -12], [15, 11, 13], [13, -4, -26], [-28, -15, -3], [23, -8, 10], [19, -5, -1], [48, -3, 31], [4, -1, -22], [-7, -12, -30], [43, -17, 11], [25, -34, -13], [-1, -12, 15], [-20, -22, -23], [-2, -5, 8], [22, -19, -2], [-2, 8, -11], [21, 11, -5], [-28, -24, -27], [12, 36, -7], [27, -33, -19], [-38, 1, -13], [39, -3, 21], [-27, 36, 1], [-6, -30, -13], [-40, 39, 18], [-16, 31, -6], [44, 19, 10], [-46, 12, 6], [56, 4, -7], [-37, -17, 5], [-42, 24, 6], [-15, -16, -20], [-24, 15, -4], [43, 7, 23], [14, -5, 1], [14, 6, -15], [-34, -8, 17]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7938_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7938_2_a_bv();".
// 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_7938_2_a_bv(:prec:=3)
    chi := MakeCharacter_7938_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(3023) - 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_7938_2_a_bv();".
// 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_7938_2_a_bv( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7938_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, -6, 1, 1]>,<11,R![-3, -6, -1, 1]>,<13,R![-69, 1, 8, 1]>,<17,R![24, -12, -4, 1]>,<23,R![-3, 12, -7, 1]>],Snew);
    return Vf;
end function;