
// Make newform 6930.2.a.bw in Magma, downloaded from the LMFDB on 20 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_bw();".
// 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_bw();".
// 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, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [0, 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], [0, 1], [0, -1], [0, 0], [-2, -1], [-2, 2], [4, -2], [0, -1], [-2, 0], [0, 0], [0, 2], [-6, 0], [-8, 0], [2, 2], [-2, 1], [-8, -2], [2, -4], [-4, 0], [0, 4], [-12, -1], [-10, 0], [-6, -4], [4, 2], [0, 2], [0, 1], [-8, -3], [-4, 2], [-4, 4], [0, 1], [-4, 2], [-6, 0], [-20, 0], [-6, 0], [-2, 5], [14, -1], [-6, 0], [0, -2], [0, -1], [-4, -4], [2, -4], [-2, 0], [12, -2], [-6, -3], [0, -8], [8, 0], [20, 1], [-6, 4], [-18, 1], [2, 6], [8, 0], [-10, -2], [-12, -2], [-10, 2], [8, 0], [-14, 0], [-4, 5], [-14, 3], [-2, -6], [-14, 3], [18, -1], [14, -4], [2, 4], [4, 0], [2, 0], [8, -2], [-14, -2], [6, -2], [2, -1], [-4, -6], [14, -6], [-4, 0], [8, 2], [-22, 2], [14, -6], [6, -4], [-14, -2], [-4, -2], [-18, 4], [22, -3], [-10, 4], [28, -2], [20, 4], [-2, -4], [2, 4], [2, 8], [4, 0], [0, -6], [-8, 4], [-28, 4], [12, 4], [8, 6], [30, 3], [6, 2], [4, 11], [-2, 5], [-4, -1], [4, -10], [30, 4], [28, 2], [-24, -5], [-10, -9], [-2, 4], [16, -2], [-12, -7], [4, 8], [10, 2], [0, 0], [-30, 4], [0, 1], [-34, -1], [4, 2], [38, 0], [-20, 4], [24, -2], [-10, 2], [-4, -4], [40, -1], [-22, 4], [-6, 4], [4, 12], [-18, -1], [-10, -6], [-18, -8], [-26, 1], [32, 4], [40, 1], [-18, -1], [-16, 0], [-20, 2], [-8, -1], [6, 8], [-6, -10], [42, 0], [18, -1], [-6, 8], [-24, -9], [-8, 8], [22, -6], [8, -6], [24, -2], [8, 7], [10, -5], [16, -3], [12, 1], [26, -3], [14, 11], [34, 4], [-4, -1], [-2, -3], [10, 1], [-30, -1], [8, -10], [-8, -6], [-24, 1], [6, 6], [-6, -8], [24, -6], [30, 2], [12, 6], [52, -2], [12, 3], [-8, -10], [-4, 2], [12, 3], [-22, 0], [-30, 0], [16, 2], [32, 3], [-6, 11], [26, 4], [0, 16], [-4, 11], [-2, 3], [-6, -2], [20, -6], [-22, 10], [-4, -12], [-24, -6], [0, -13], [-48, 3], [14, -5], [-30, 8], [30, -2], [4, -4], [-22, 0], [32, 0], [-10, -12], [-20, 0], [-8, 2], [-14, -12], [36, 8], [-30, 4], [-6, 8], [24, 7], [-4, 5], [10, -11], [-46, 4], [24, -4], [34, 0], [-6, -2], [24, 0], [-30, 0], [-20, 6], [4, -8], [12, 5], [50, 5], [-38, 0], [10, 8], [-24, 10], [16, -2], [12, -10], [14, -6], [-24, 0], [-58, 0], [-10, 11], [30, 6], [48, 1], [-4, -6], [54, 4], [16, -6], [28, -2], [-40, 1], [-38, -4], [-48, -6], [40, -4], [36, 0], [44, 9], [-20, -6], [20, 0], [28, -3], [16, 2], [-2, 11], [10, -4], [-34, -8], [-8, 2], [2, -9], [12, -16], [-16, -16], [-24, 8], [6, 16], [12, 17], [-48, 0], [-8, -12], [-4, 14], [-38, 5], [-12, 18], [-30, -4], [30, 4], [66, 1], [-26, -2], [-26, 10], [32, 6], [-2, -4], [-10, -7], [34, -12], [-14, 12], [8, -12], [-12, 4], [26, -14], [32, 1], [-6, -16], [18, 5], [42, 2], [-8, -19], [-20, -2], [-50, -4], [-8, -1], [-26, 5], [-42, 4], [-48, 6], [50, 4], [44, 10], [56, -6], [-36, 3], [2, 12], [12, -4], [14, 3], [-36, -10], [34, -7], [18, 2], [10, 11], [56, -2], [10, -8], [38, -12], [16, -8], [-6, -18], [-30, 6], [8, -10], [-54, 4], [-64, -2], [-22, 0], [-30, -16], [24, 16], [34, 8], [-8, -10], [46, -7], [-14, -4], [-10, -4], [12, 0], [-12, -4], [16, 2], [-30, 16], [0, 10], [-36, 1], [-40, -6], [22, -10], [-46, 5], [-14, 2], [-36, 13], [2, -9], [52, 2], [-46, 2], [-12, -2], [6, -15], [14, 12], [60, 5], [16, 12], [30, -14], [-6, 12], [-12, -4], [-18, 6], [-14, 8], [8, -18], [20, -4], [32, 8], [38, -12], [-4, 11], [6, -2], [0, 12], [-44, -2], [-30, 5], [48, 10], [-2, -4], [-20, 1], [-26, 2], [-28, 6], [28, 9], [32, -11], [26, -4], [-16, 16], [-30, 0], [0, -6], [-12, 9], [10, 15], [12, 22], [-30, -4], [-32, 0], [2, -8], [-46, -6], [4, 18], [4, -13], [-36, -3], [78, 1], [-56, -6], [-2, 14], [-54, -7], [-38, -16], [2, -2], [42, -3], [0, -26], [-36, -12], [-6, 4], [-34, 10], [40, 4], [-18, 2], [-64, -2], [34, -11], [-80, 0], [-10, -18], [12, -10], [36, -7], [-36, -6], [-34, -11], [-50, 6], [82, -2], [6, -14], [-6, -8], [24, -19], [-12, 10], [-46, 0], [20, 6], [16, -22], [-32, 0], [-22, -16], [72, -8], [36, -16], [-30, -12], [10, 0], [-44, -8], [64, 2], [24, 22], [42, -8], [24, 0], [28, -5], [36, -4], [-30, -12], [-42, -12], [-28, -13], [4, 22], [6, -10], [-62, 12], [-64, -8], [44, 5], [24, 7], [-36, 8], [-24, 0], [-26, -6], [6, -8], [-4, 4], [62, -5], [-22, 16], [-18, -10], [-26, 21], [-24, -8], [-6, 24], [-66, 7], [-30, -2], [8, 5], [18, 21], [-36, 20], [-50, -4], [-22, 20], [-20, -8], [40, 11], [22, 11], [-60, 6], [-46, 8], [-60, -8], [56, 2], [80, -2], [90, 0], [20, -5], [-66, 10], [-38, -6], [-46, 7], [-16, 24], [-12, 16], [-6, -6], [8, 17], [2, 15], [-70, -2], [22, -10], [-34, -11], [10, -11], [-26, 22], [34, 10], [32, -12], [30, 5], [4, 4], [-46, 2], [-18, 6], [-6, 14], [-32, -15], [-72, 2], [-100, -1], [-16, 5], [-56, -6], [72, -8], [8, 30], [38, -16], [22, -11], [82, -8], [40, 2], [-4, 0], [8, -5], [82, 1], [40, 16], [8, -6], [14, -3], [-18, 2], [60, -12], [8, -7], [18, 14], [-72, 8], [6, -13], [-42, -6], [6, -20], [42, -2]];
    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_bw();".
// 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_bw(: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_bw();".
// 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_bw( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6930_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<13,R![-12, 0, 1]>,<17,R![-12, 0, 1]>,<19,R![0, 1]>,<23,R![-8, 4, 1]>,<29,R![-44, 4, 1]>,<31,R![-32, -8, 1]>],Snew);
    return Vf;
end function;