
// Make newform 6720.2.a.bs in Magma, downloaded from the LMFDB on 19 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_6720_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_6720_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_6720_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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_6720_a();"
function MakeCharacter_6720_a()
    N := 6720;
    order := 1;
    char_gens := [1471, 3781, 4481, 5377, 1921];
    v := [1, 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_6720_a_Hecke( : Kf := Kf)
    return MakeCharacter_6720_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]];
    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 := [[0], [1], [-1], [1], [2], [-4], [2], [-2], [-4], [2], [6], [6], [6], [-4], [0], [-8], [0], [10], [-12], [14], [4], [8], [12], [-14], [8], [6], [8], [-12], [-2], [12], [16], [-4], [16], [14], [22], [20], [-24], [-4], [8], [-18], [10], [-18], [-14], [2], [12], [-18], [12], [-20], [28], [-14], [-4], [6], [-2], [24], [-2], [-8], [30], [2], [-10], [6], [4], [30], [-16], [8], [-24], [8], [36], [18], [8], [-14], [-14], [18], [-4], [34], [16], [-16], [14], [-12], [34], [-14], [-28], [-22], [6], [-8], [14], [24], [-22], [-26], [-38], [24], [36], [-8], [32], [18], [24], [32], [6], [-18], [-8], [-38], [12], [0], [-4], [26], [-32], [16], [12], [-6], [-30], [-26], [-4], [30], [20], [38], [-8], [46], [-16], [-24], [-20], [6], [34], [6], [-34], [-24], [-6], [-30], [26], [-20], [28], [-28], [-40], [-24], [-40], [2], [-38], [-26], [38], [8], [6], [-10], [22], [-22], [-24], [-44], [6], [4], [-28], [-34], [-14], [-44], [22], [2], [-4], [16], [4], [58], [8], [34], [-44], [-30], [-32], [-4], [-16], [-32], [36], [-24], [-16], [-4], [-50], [-18], [10], [38], [62], [34], [10], [54], [28], [30], [-60], [-50], [0], [48], [-46], [-62], [24], [6], [-26], [0], [14], [12], [8], [-52], [48], [18], [40], [42], [14], [-14], [46], [-24], [18], [-34], [-32], [46], [0], [22], [-22], [-36], [-50], [2], [-10], [-66], [32], [28], [-44], [-50], [-40], [-30], [-32], [-60], [58], [-42], [30], [-64], [44], [54], [-18], [-30], [-64], [-22], [-46], [-26], [44], [46], [24], [-8], [-30], [12], [58], [-68], [-60], [46], [0], [22], [-66], [60], [12], [-20], [20], [-44], [14], [2], [-20], [-30], [14], [10], [-10], [-44], [-2], [-64], [-16], [0], [34], [16], [18], [-62], [26], [30], [-76], [36], [-34], [28], [-16], [-32], [-8], [44], [-44], [-62], [58], [40], [56], [40], [-48], [54], [8], [50], [62], [-64], [46], [50], [-22], [76], [60], [28], [42], [-54], [-54], [26], [16], [32], [4], [-4], [-12], [8], [-48], [-62], [-36], [-54], [54], [66], [-72], [26], [-30], [-4], [-20], [-58], [12], [-54], [-40], [42], [-14], [70], [-62], [16], [-88], [78], [-32], [-44], [-60], [-64], [62], [-28], [82], [-84], [68], [68], [-70], [-66], [-50], [52], [-6], [-92], [86], [68], [-60], [22], [-30], [60], [36], [-2], [-18], [-50], [-78], [16], [-66], [-62], [84], [-36], [12], [64], [-38], [6], [72], [-90], [-40], [54], [-14], [16], [-6], [-30], [10], [-24], [78], [90], [-34], [-84], [-6], [24], [-74], [-28], [-2], [92], [64], [8], [-50], [24], [72], [-28], [20], [80], [-26], [-54], [54], [-40], [86], [26], [26], [-6], [-8], [66], [-74], [36], [-80], [-10], [74], [-30], [62], [-86], [-4], [32], [-20], [-96], [48], [-4], [58], [14], [38], [44], [58], [-48], [70], [28], [24], [-56], [40], [94], [100], [-30], [34], [52], [34], [22], [60], [-56], [40], [78], [106], [54], [108]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6720_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_6720_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_6720_2_a_bs(:prec:=1)
    chi := MakeCharacter_6720_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(3067) - 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_6720_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_6720_2_a_bs( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_6720_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-2, 1]>,<13,R![4, 1]>,<17,R![-2, 1]>,<19,R![2, 1]>,<23,R![4, 1]>,<29,R![-2, 1]>,<31,R![-6, 1]>],Snew);
    return Vf;
end function;