
// Make newform 3120.2.a.bg in Magma, downloaded from the LMFDB on 20 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_3120_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_3120_2_a_bg();".
// 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_3120_2_a_bg();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_3120_a();"
function MakeCharacter_3120_a()
    N := 3120;
    order := 1;
    char_gens := [1951, 2341, 2081, 2497, 2641];
    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_3120_a_Hecke( : Kf := Kf)
    return MakeCharacter_3120_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, 0], [1, 0], [1, 0], [0, 1], [4, -1], [1, 0], [-2, 3], [0, 2], [4, -1], [-2, 0], [4, -2], [2, -5], [-2, -3], [4, -4], [-4, 2], [2, -1], [8, 0], [-6, 3], [8, -4], [0, 3], [10, -4], [-4, 5], [8, 0], [-10, 3], [-10, 5], [-2, -2], [-8, 4], [8, -5], [-10, 2], [2, 0], [8, -6], [12, -2], [10, -4], [8, -1], [-14, -1], [-4, 0], [-2, -8], [-12, 1], [12, 4], [14, 0], [20, -2], [2, 7], [-8, 0], [14, 3], [-2, -6], [-8, -4], [-12, 0], [-4, -4], [-16, 6], [-10, 0], [14, -3], [8, 3], [18, 4], [4, 8], [2, -8], [-16, 8], [-10, 2], [-4, -6], [-10, 8], [10, 4], [-12, 12], [-2, 10], [-12, 1], [8, -12], [-6, 12], [6, 2], [-16, -4], [-6, -2], [-8, -9], [-10, -6], [2, 4], [-4, -4], [-8, 4], [-18, -2], [-8, 2], [-12, -6], [14, -14], [26, -5], [2, 4], [-6, 8], [-4, -2], [-2, -14], [-20, -4], [26, -6], [4, 7], [8, 3], [6, -3], [-34, 1], [-14, 1], [8, 1], [-8, 11], [-8, 17], [0, 3], [20, 8], [16, -14], [0, 12], [-38, 3], [-6, 0], [-20, -4], [-34, 0], [-12, -12], [-34, 0], [24, -1], [2, 2], [-24, 1], [-10, 17], [8, -6], [10, 10], [0, -12], [-2, 1], [-8, 12], [-6, -7], [-6, -4], [-16, -6], [-20, 4], [10, 6], [-4, 5], [-4, -3], [30, 4], [4, 8], [-34, -2], [-14, 0], [18, 7], [8, 8], [-32, -2], [-10, 6], [14, -2], [-16, -4], [32, 6], [-6, 15], [-8, 14], [12, 2], [12, 3], [-18, -2], [10, -8], [10, -10], [-18, 2], [0, -12], [18, -15], [-6, 8], [-16, 16], [-38, -3], [24, 8], [-32, -6], [30, 0], [24, -5], [-38, 1], [-2, 21], [-40, -5], [20, 14], [-34, 0], [2, -4], [-20, 8], [-12, 9], [44, -2], [-24, -4], [20, 5], [-2, -13], [-38, -4], [-6, -17], [32, -12], [22, -5], [36, -4], [-4, -8], [-22, 14], [28, -16], [20, -9], [14, 2], [18, 4], [18, -13], [16, -12], [-18, 12], [8, 4], [-18, 9], [28, -13], [2, 2], [0, -6], [18, -17], [8, -4], [46, -8], [8, -3], [12, 4], [-26, -8], [-6, 12], [-4, -6], [-34, 2], [-10, 14], [4, 3], [2, 22], [-8, -19], [10, 14], [-24, 6], [-40, 5], [-14, 5], [12, 8], [22, -9], [18, -8], [14, -4], [10, -18], [-20, 7], [-2, 4], [-4, 9], [26, 5], [46, -13], [-4, -15], [34, -3], [-12, 18], [4, -8], [-26, -5], [32, -21], [-38, 2], [6, 4], [0, 12], [0, 6], [-12, 0], [-30, -2], [24, 0], [34, 4], [-36, 18], [30, -4], [-6, 9], [4, 14], [-30, 0], [-20, 0], [24, 7], [-14, 27], [62, -3], [16, -26], [0, -18], [36, -13], [6, 22], [16, -9], [-4, -12], [2, -22], [-28, -10], [-44, -2], [42, 10], [6, -20], [-36, 6], [-48, 8], [56, 0], [16, -9], [16, 0], [-10, 14], [-6, -18], [-8, 12], [20, -36], [-20, 27], [0, 24], [-32, 16], [-2, 4], [-14, -24], [20, -22], [6, 15], [-14, 5], [20, 17], [22, 0], [-44, -3], [38, 0], [-34, -11], [24, 2], [24, 1], [14, -22], [54, -2], [-46, 20], [56, 1], [-54, 7], [22, 19], [4, -1], [-10, 4], [-18, 8], [20, 7], [-2, 9], [0, -16], [18, 12], [16, 7], [0, -32], [-10, 14], [-14, 6], [52, 2], [-12, -9], [28, -20], [64, 0], [6, 16], [40, 0], [0, 0], [-22, 14], [-18, 2], [-12, 18], [-38, -2], [54, 2], [-44, 16], [-46, 6], [56, -4], [-34, -20], [14, -12], [-40, 8], [-22, 17], [-20, -24], [20, 21], [26, -12], [-10, -6], [-12, -11], [8, 25], [44, 12], [14, -21], [8, 17], [-14, -19], [28, -28], [-50, 10], [20, 23], [-42, 4], [-46, 0], [68, 4], [28, -12], [22, 11], [12, -15], [-8, 23], [2, 8], [-54, 2], [-4, -16], [42, -12], [14, -20], [-40, 29], [42, -12], [22, 13], [24, -10], [-28, -15], [44, -5], [-26, 8], [-34, 8], [-30, 21], [24, -32], [64, -12], [16, -40], [24, -30], [-2, 4], [-6, 34], [10, -20], [24, -18], [-6, 17], [46, 5], [2, 15], [56, -4], [-82, 4], [-36, -16], [50, -25], [-20, 33], [-12, 12], [10, -31], [-16, 6], [-26, 35], [-30, -3], [-8, 26], [10, -7], [-38, -20], [0, 19], [16, 4], [-14, -32], [-4, 6], [-26, 44], [34, 18], [8, 12], [16, 28], [-28, -2], [18, -10], [6, -22], [-32, -19], [-26, 19], [-4, 2], [-12, -16], [-44, 16], [-10, 16], [60, 15], [38, 18], [-20, 13], [-24, 6], [-10, 1], [10, -2], [26, 12], [-18, 40], [-70, 16], [-4, -4], [2, -36], [48, 12], [-4, -36], [-12, 10], [46, -18], [0, 0], [4, -1], [42, -6], [22, -8], [-12, -5], [52, -16], [24, 3], [-54, -4], [-28, 22], [10, -4], [-56, -5], [-26, 24], [-34, 8], [22, -27], [48, 3], [66, 6], [-38, 25], [76, -9], [62, 8], [50, -32], [-36, -13], [20, -27], [2, -36], [-6, -3], [8, -21], [24, 19], [-38, 4], [30, -28], [0, 9], [40, -2], [-86, -2], [-36, 5], [-2, 0], [82, -1], [-4, -36], [-20, 32], [-38, -12], [-10, 22], [8, 23], [-18, -23], [16, 22], [56, 18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3120_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3120_2_a_bg();".
// 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_3120_2_a_bg(:prec:=2)
    chi := MakeCharacter_3120_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(2999) - 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_3120_2_a_bg();".
// 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_3120_2_a_bg( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3120_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<7,R![-4, -1, 1]>,<11,R![8, -7, 1]>,<17,R![-38, 1, 1]>,<19,R![-16, -2, 1]>,<31,R![-8, -6, 1]>],Snew);
    return Vf;
end function;