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