
// Make newform 5616.2.a.bz in Magma, downloaded from the LMFDB on 10 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_5616_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_5616_2_a_bz();".
// 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_5616_2_a_bz();".
// 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;
    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_5616_a();"
function MakeCharacter_5616_a()
    N := 5616;
    order := 1;
    char_gens := [703, 4213, 2081, 3889];
    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_5616_a_Hecke( : Kf := Kf)
    return MakeCharacter_5616_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], [0, 0], [3, -1], [1, 0], [0, -1], [1, 0], [3, -1], [4, -1], [0, 3], [3, 2], [-2, 4], [-1, -4], [9, 0], [-2, -1], [-3, -3], [-9, 3], [-3, 0], [5, 2], [7, -5], [-6, 6], [-7, 3], [10, -3], [3, 2], [6, -2], [-4, 8], [-3, 6], [1, 5], [6, -3], [8, 5], [3, 0], [-11, 0], [9, -4], [0, 6], [1, -10], [12, 3], [-5, 4], [-10, 1], [-11, 9], [15, -4], [0, -3], [3, 5], [-7, -3], [3, 1], [-10, 1], [-6, -6], [-11, -3], [-2, 7], [4, -11], [-3, -7], [-4, 3], [3, 10], [3, 6], [-4, 5], [3, 3], [6, -1], [21, 3], [0, 13], [-5, 8], [-10, 6], [0, 8], [19, 5], [3, -12], [-11, -3], [3, -3], [2, -2], [-9, -7], [1, 12], [-1, -2], [15, 0], [5, -1], [9, 4], [9, 6], [13, 10], [11, -7], [13, -4], [-18, 4], [6, -14], [-7, 12], [30, -2], [2, -4], [-30, -4], [26, -6], [-21, 6], [-19, -7], [28, 0], [-9, 10], [27, -2], [35, 0], [12, -11], [16, -5], [9, -6], [-6, 9], [-32, 8], [36, -3], [-26, -7], [-9, -10], [-6, 10], [9, -18], [-2, 3], [-31, 1], [31, -5], [3, 12], [-3, 12], [9, -14], [4, -12], [-7, -3], [9, -7], [-15, 7], [-12, -14], [14, -1], [22, -3], [-1, 8], [6, 1], [-2, -4], [7, -18], [24, -4], [-23, 6], [3, 5], [-18, -6], [-3, -4], [-19, 4], [14, -10], [-3, -2], [12, -18], [-20, 14], [15, -16], [-31, 5], [-6, -6], [1, 6], [8, 4], [-38, 3], [-9, -3], [13, -15], [-1, -13], [-18, 8], [-1, 10], [-18, -5], [-29, 10], [-39, -2], [-24, 15], [25, -6], [-6, 2], [-17, -4], [-21, 2], [2, -12], [-36, -3], [-25, 7], [-9, 17], [-11, -2], [24, 2], [-13, -12], [33, 10], [19, 1], [9, 6], [-20, -4], [-18, -11], [-14, -4], [27, 6], [38, -15], [-18, 10], [-33, 12], [-30, 0], [4, 6], [-42, 0], [18, 6], [30, -10], [1, -8], [-31, 11], [-13, 4], [-21, -6], [42, -6], [-7, -4], [-18, 13], [-25, 4], [-8, 26], [30, 0], [-2, 14], [-45, -3], [-8, 16], [11, 10], [37, 9], [-48, -6], [-22, 27], [-9, -3], [21, -11], [-18, -15], [-28, -7], [-8, 24], [-31, 0], [3, -18], [8, -28], [-12, 14], [-35, 22], [12, -1], [-51, -6], [18, 0], [11, -4], [-31, 8], [27, -16], [-9, 30], [-6, 6], [28, -24], [11, -22], [-1, -9], [15, 3], [-54, 8], [-53, 1], [39, 2], [3, -10], [7, -11], [-7, 30], [-12, -3], [-17, -6], [-48, 17], [21, -13], [-1, 3], [13, 0], [15, 14], [42, -21], [-3, 0], [23, 0], [25, 7], [0, -17], [37, -20], [-36, 21], [32, 14], [15, -33], [-12, 13], [-41, 1], [9, 1], [17, -14], [7, 18], [-23, 12], [33, -24], [31, -14], [6, -27], [5, 0], [51, 7], [27, -20], [-51, -4], [9, -19], [19, -20], [-32, 24], [-4, -5], [-15, 15], [-12, 27], [19, 4], [0, -30], [-5, 6], [15, -18], [14, 9], [54, 5], [-24, 12], [41, -1], [-33, 9], [-36, -13], [-52, 0], [-17, -12], [-27, -6], [-55, -10], [-29, -16], [-36, -10], [14, -36], [26, -13], [3, -24], [13, -2], [3, -28], [3, 9], [-32, 6], [-12, -8], [-31, 12], [-14, -10], [-22, 26], [49, -3], [-1, 13], [37, 7], [12, 14], [-4, 20], [71, -10], [-18, 6], [18, -42], [4, -3], [-33, 2], [26, -27], [31, 18], [-21, -7], [-10, 35], [15, 0], [-8, 15], [-24, 35], [6, -36], [-42, 0], [36, 15], [-12, 27], [41, -34], [0, 31], [-2, 35], [27, -2], [0, -2], [-26, 9], [5, -33], [30, 4], [-62, 13], [6, -2], [13, 18], [5, -14], [-27, 1], [-16, -16], [63, 3], [-58, 19], [48, 1], [-6, -3], [-57, 13], [16, 10], [6, -29], [-16, -24], [54, -18], [0, -13], [5, -13], [18, -9], [-53, 0], [-25, 5], [-3, 9], [-32, -7], [-42, -15], [-58, 16], [-11, 9], [13, -35], [9, -13], [-42, 6], [35, 12], [51, -24], [-77, 4], [-6, -17], [46, 13], [-48, 14], [71, 2], [-21, 35], [-22, -21], [-44, -8], [-7, -8], [-24, 19], [75, 8], [-17, -18], [42, 2], [36, -42], [-1, 2], [22, -47], [-39, 7], [-36, 22], [-35, 2], [5, 10], [-9, 0], [-26, 15], [-22, 12], [-66, 2], [-9, -14], [-24, 12], [15, -24], [-33, 38], [20, -17], [51, 6], [-57, 24], [66, -12], [19, -8], [-40, 41], [-27, 3], [-17, 10], [-31, 16], [36, 15], [31, 2], [-36, 41], [21, -12], [28, -1], [23, 19], [12, 33], [39, -36], [-28, 44], [0, -26], [38, 1], [3, 30], [-33, -21], [-11, -36], [39, -18], [-20, -8], [66, 5], [25, 20], [53, 1], [16, 0], [-45, -2], [-28, -24], [-60, 17], [12, 25], [1, -3], [21, -14], [-7, -16], [-29, 30], [30, 15], [-29, -14], [45, -30], [-40, 3], [12, -21], [52, 16], [6, -33], [-42, -1], [-47, -6], [-31, 44], [33, -10], [19, -25], [12, 6], [62, -18], [12, -19], [-15, 39], [40, -47], [-37, 31], [-18, 24], [51, 10], [-62, 15], [3, 27], [9, -23], [72, 7], [59, -23], [33, -11], [33, -26], [11, 21], [-21, -2], [33, 15], [36, 12], [70, -3], [45, -3]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_5616_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_5616_2_a_bz();".
// 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_5616_2_a_bz(:prec:=2)
    chi := MakeCharacter_5616_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_5616_2_a_bz();".
// 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_5616_2_a_bz( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_5616_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, -5, 1]>,<7,R![-1, 1]>,<11,R![-3, 1, 1]>,<17,R![3, -5, 1]>],Snew);
    return Vf;
end function;