
// Make newform 6930.2.a.bs in Magma, downloaded from the LMFDB on 17 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_6930_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_6930_2_a_bs();".
// 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_6930_2_a_bs();".
// 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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 2]];
    Rf_basisdens := [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_6930_a();"
function MakeCharacter_6930_a()
    N := 6930;
    order := 1;
    char_gens := [1541, 1387, 2971, 2521];
    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_6930_a_Hecke(Kf)
    return MakeCharacter_6930_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], [-1, 0], [1, 0], [2, 0], [1, -1], [-3, 1], [-3, -1], [0, 2], [-3, -1], [3, 1], [-5, -1], [-1, -1], [-1, 3], [-10, 0], [-4, 0], [-1, 1], [-5, -1], [-3, 1], [8, -2], [1, -1], [-7, -1], [0, -2], [-7, 1], [-1, 3], [6, 2], [-10, -2], [18, 0], [-2, 0], [-10, 2], [14, -2], [-12, -2], [-5, -1], [-2, 0], [17, -1], [1, 1], [-9, 3], [-14, 0], [-4, 2], [-6, -2], [7, -3], [-11, 1], [7, -1], [-6, -4], [-9, 1], [13, -1], [-12, 4], [-9, -3], [7, 1], [-6, 0], [-5, 3], [6, 4], [0, -4], [-5, 5], [-8, 4], [-14, 0], [-12, 0], [-2, -2], [-1, -3], [6, 2], [10, 0], [-10, -6], [-8, 0], [3, -5], [0, 2], [0, 0], [9, 5], [6, 6], [7, -3], [-5, 5], [-5, 3], [-12, -4], [-14, -2], [16, 0], [15, -5], [1, -3], [-15, -3], [32, 0], [8, 2], [-16, 4], [0, -2], [-3, 5], [3, -1], [2, -6], [-7, -5], [-6, -6], [-1, 3], [9, 1], [-2, 6], [-4, 4], [0, 4], [-12, 4], [2, -2], [6, -6], [-8, 2], [-32, -2], [4, 2], [-16, 4], [-20, 2], [-15, 5], [-8, -6], [27, 1], [-27, -1], [-5, 5], [-27, 1], [12, -8], [31, 1], [-1, -1], [-14, 8], [0, -8], [24, 0], [-28, 2], [-14, 0], [-12, -4], [-6, -6], [-30, -2], [-23, 1], [-24, -6], [-32, 4], [-9, -3], [-11, -7], [14, 0], [-7, -5], [2, 0], [-26, 4], [10, 8], [32, 0], [-38, -2], [8, -6], [29, -1], [22, -6], [-30, -2], [-21, -7], [-3, 9], [-18, 0], [-44, -2], [2, -2], [16, -2], [3, 1], [11, 7], [10, 8], [30, -2], [-38, 2], [-3, 11], [-14, 2], [4, -2], [23, -3], [-2, 4], [-3, 11], [2, -6], [14, 4], [-33, -5], [-6, -8], [-21, 7], [-35, 1], [35, 5], [28, 6], [-16, 10], [13, -11], [19, -7], [-14, 8], [-36, -4], [-4, 0], [4, 10], [9, -7], [-4, -12], [-24, -6], [8, -10], [14, 8], [8, -4], [-3, -1], [35, 3], [-9, -1], [39, 5], [-10, 4], [13, -5], [3, 3], [-12, 4], [51, 1], [-2, -2], [10, -6], [35, 1], [-1, 1], [-13, 5], [22, 0], [10, -2], [-6, -10], [42, -4], [34, 2], [49, 1], [2, -6], [-10, 2], [30, 4], [4, 8], [-25, -3], [10, 4], [7, 9], [1, 3], [28, -6], [-34, 0], [-14, -2], [37, -3], [42, 4], [-36, 0], [34, 0], [-51, -1], [42, 2], [-31, -1], [-12, -2], [39, -1], [-10, 12], [16, 0], [46, 2], [-26, -6], [34, -4], [-24, 8], [27, -9], [-19, 3], [28, 6], [18, -12], [-2, 10], [-20, -4], [-30, -6], [31, -3], [-26, 8], [23, -7], [-13, -5], [-4, 12], [-2, -14], [9, 15], [39, -1], [15, 1], [-15, -1], [-8, -4], [-14, 0], [12, -10], [30, -8], [-32, 0], [30, -2], [31, 5], [17, -3], [14, -6], [10, -8], [13, -5], [-20, -8], [8, 8], [24, 12], [43, -7], [8, 4], [-30, -6], [43, 7], [61, 3], [-6, -4], [4, -2], [18, 6], [24, -2], [18, 6], [46, 4], [-30, 8], [-20, 0], [-6, 10], [33, -9], [42, 4], [-21, 5], [-8, -14], [11, 3], [56, -2], [7, 3], [-36, -6], [41, 3], [25, 13], [-13, 11], [-13, 5], [-4, 2], [-44, 4], [33, 3], [0, -18], [-18, 0], [18, 10], [-2, 16], [18, -10], [2, 8], [-15, -13], [-24, -12], [21, -3], [30, -4], [8, -2], [-31, 3], [-25, -9], [17, -11], [-10, 6], [32, 2], [32, 12], [14, -2], [-25, -1], [-17, -3], [-20, -2], [30, 6], [-10, -14], [28, 6], [6, -12], [-3, 11], [17, -5], [-16, 12], [-66, -4], [-57, 5], [37, -1], [53, 1], [-54, 6], [-20, 2], [9, 1], [-17, -3], [-13, -1], [0, 4], [48, -10], [60, 0], [11, -5], [5, -3], [-57, 1], [39, 7], [12, 10], [-15, -11], [24, 0], [-14, -4], [90, 0], [-32, -4], [18, 6], [20, 8], [-24, 14], [48, -6], [8, -6], [20, -4], [23, 1], [-69, -3], [16, 0], [50, 8], [69, 3], [52, -6], [-24, 0], [43, 9], [12, -6], [-11, 9], [-32, 0], [26, 12], [-42, 2], [-13, 13], [-11, 17], [38, 2], [14, 4], [69, 5], [-52, -10], [17, 9], [16, 8], [0, 14], [-17, -3], [-4, 4], [-60, -8], [28, 14], [-33, -15], [12, -4], [39, -9], [-5, -11], [-8, -12], [-20, -8], [-6, -16], [48, 2], [4, -16], [12, 14], [16, -4], [-26, -12], [-8, 12], [-34, 12], [18, 2], [-41, -7], [-48, -12], [-29, -5], [38, -4], [-3, -3], [24, 2], [-28, 10], [34, -4], [0, -8], [10, -12], [31, 3], [-19, -11], [-2, 2], [27, -5], [25, 13], [47, -9], [8, -6], [14, 8], [-26, -10], [4, 0], [63, -1], [-83, -3], [8, -16], [16, -14], [10, -10], [-10, 8], [-5, 1], [-22, 4], [-48, 12], [-81, -3], [-17, 19], [-6, -18], [-5, 5], [51, -3], [-28, -16], [40, -12], [44, 6], [-54, 0], [-1, 13], [-13, 21], [1, 21], [-62, 4], [59, 3], [24, 8], [-27, 3], [12, 6], [43, -5], [10, 16], [13, -9], [-18, -2], [31, 15], [-22, -8], [-63, 3], [-15, 7], [-28, 18], [-4, -4], [20, -2], [-44, 0], [-12, -16], [35, -1], [-71, 9], [-58, 8], [22, 4], [-76, -6], [45, 1], [14, -2], [-14, -6], [58, 6], [10, 4], [-65, -9], [58, -4], [-82, 0], [18, -2], [96, -2], [-54, -4], [-3, -21], [-39, 17], [24, 8], [-2, -2], [-67, -3], [6, 8], [-35, 9], [14, -12], [18, 18], [46, 0], [-14, 4], [46, 6], [-64, 0], [0, -4], [36, 18], [54, 10], [37, 1], [-105, 1], [44, 4], [-15, 7], [-10, 0], [-76, 0], [-43, -9], [-4, 12], [38, 4], [-30, -6], [-30, 12], [-55, -11], [-49, 1], [2, -12], [-36, 6], [-71, -7], [69, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6930_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6930_2_a_bs();".
// 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_6930_2_a_bs(:prec:=2)
    chi := MakeCharacter_6930_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(3449) - 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_6930_2_a_bs();".
// 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_6930_2_a_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6930_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<13,R![-2, 1]>,<17,R![-16, -2, 1]>,<19,R![-8, 6, 1]>,<23,R![-8, 6, 1]>,<29,R![-68, 0, 1]>,<31,R![-8, 6, 1]>],Snew);
    return Vf;
end function;