
// Make newform 7616.2.a.q in Magma, downloaded from the LMFDB on 09 January 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_7616_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_7616_2_a_q();".
// 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_7616_2_a_q();".
// 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_7616_a();"
function MakeCharacter_7616_a()
    N := 7616;
    order := 1;
    char_gens := [5951, 3333, 3265, 2689];
    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_7616_a_Hecke( : Kf := Kf)
    return MakeCharacter_7616_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, -1], [1, -1], [1, 0], [0, 0], [-4, 2], [1, 0], [-4, 2], [0, 0], [0, 0], [3, -1], [0, -2], [0, -3], [-6, 1], [2, -2], [5, 1], [-4, 4], [4, -3], [3, 1], [0, 6], [-4, 3], [10, -2], [-6, 0], [-14, 2], [-5, 1], [-12, 6], [-2, 4], [4, 2], [2, 8], [2, -2], [11, -3], [16, -4], [-14, -1], [-11, -3], [-6, 9], [-2, 7], [2, -4], [-10, 2], [-12, 9], [-16, 1], [-6, 3], [-14, 0], [9, -9], [-4, 6], [2, -2], [12, -7], [8, -10], [4, 10], [1, 5], [-16, -4], [-6, 6], [10, -1], [15, 5], [-12, -6], [-2, -4], [-8, 8], [-10, 4], [4, 4], [12, -8], [5, 1], [3, -5], [6, -12], [-4, -4], [-11, -7], [19, -11], [6, 0], [-7, -1], [-16, 0], [30, 0], [-24, 4], [0, 12], [3, -3], [-8, -11], [14, -13], [12, 4], [8, -8], [1, -7], [5, -13], [-14, 2], [-24, 2], [11, -5], [14, -13], [0, 12], [-4, -6], [-4, 3], [16, -4], [-14, 14], [-7, -3], [24, -6], [-18, -1], [12, -18], [8, -5], [0, -4], [11, -11], [-12, -8], [-1, -17], [-2, -10], [12, -21], [-16, -4], [-16, 20], [26, -4], [-18, 12], [12, -12], [14, 7], [-4, -10], [10, -14], [8, -2], [36, -6], [14, -23], [-22, 0], [-15, 5], [-7, 17], [-24, 0], [28, -12], [1, 7], [8, 16], [-16, 17], [8, -8], [-2, 20], [-37, 1], [22, 6], [-28, -6], [-38, 8], [-18, 18], [-36, -5], [-2, -16], [-20, -6], [-28, 1], [-12, 8], [12, -14], [-2, -21], [-6, -6], [16, -2], [34, -9], [30, -6], [-22, 24], [-18, 6], [8, 8], [10, 8], [38, -2], [-8, -3], [8, -2], [10, -26], [-12, 12], [24, -2], [8, -8], [6, -8], [-15, 15], [-14, 18], [15, -3], [30, -2], [-11, -1], [29, 11], [-45, 3], [2, -16], [30, -6], [10, -11], [37, -13], [-12, -4], [12, 9], [-28, 16], [11, -5], [10, -5], [-16, 16], [-11, 17], [27, 3], [14, 0], [8, 17], [-12, -4], [12, 3], [32, -8], [-20, -12], [-52, -2], [-27, -7], [0, 14], [-13, 1], [4, 18], [44, -14], [-24, 2], [-8, -12], [4, -20], [8, -17], [22, -6], [-58, 4], [-5, 17], [-24, 0], [-10, 2], [22, -18], [4, -20], [24, 12], [8, 15], [-24, 30], [8, -16], [-18, 6], [-24, 18], [25, 11], [-22, 12], [-12, 10], [44, -11], [-18, 18], [-48, 6], [-5, 31], [-22, 20], [-34, 6], [-8, -22], [42, -6], [-46, -6], [38, 7], [32, 4], [10, 12], [40, 4], [54, 0], [-10, 0], [-10, -14], [36, -15], [-20, -11], [-32, 16], [4, 8], [-14, 2], [-5, -13], [-43, 17], [8, -3], [-18, 9], [20, 0], [-24, 30], [-17, -9], [6, 0], [-42, -6], [48, -10], [-22, -2], [10, 9], [-12, 16], [28, -20], [-26, -13], [-8, -6], [6, -6], [-2, -8], [-18, -18], [50, -8], [6, 0], [4, -16], [-74, 0], [-10, -6], [6, -11], [-15, -21], [-53, -1], [-12, 23], [-32, 17], [11, 5], [10, 29], [30, -23], [-15, 15], [-17, -19], [57, -13], [-2, -16], [-62, 5], [2, -10], [-37, -1], [-32, 17], [-26, 16], [-22, 18], [-33, -15], [3, 1], [9, 7], [12, 3], [-10, 14], [33, 9], [30, 0], [58, 0], [38, 7], [-25, -19], [68, -4], [12, 20], [15, -19], [36, -28], [-26, -2], [34, 11], [-23, 9], [-14, 37], [50, 4], [30, 12], [76, -2], [-20, -16], [-42, -2], [-45, 19], [-18, -27], [-22, 0], [-32, 14], [-48, 2], [-20, -16], [-36, 18], [-3, 21], [-22, -8], [-5, -13], [46, 0], [68, 1], [46, -20], [-48, 18], [37, 5], [18, -8], [-36, 8], [-14, -16], [28, -20], [40, 2], [12, -8], [-4, 6], [15, -39], [-52, 5], [-9, -15], [54, -23], [-65, 11], [54, -12], [-32, 20], [6, -23], [70, -7], [-16, 12], [-34, 4], [-14, 14], [-8, 19], [-18, -12], [-16, -1], [10, 34], [56, -26], [27, -19], [6, 0], [14, -18], [22, -24], [5, 17], [-46, 16], [-18, 42], [-32, 6], [4, -16], [-32, 25], [-68, 2], [-56, 6], [16, -40], [-26, -3], [-72, 3], [16, -17], [-46, 12], [22, 3], [-15, 21], [6, -12], [-29, 13], [-66, -3], [-26, 2], [-7, -1], [-19, 23], [-13, 19], [24, 9], [-24, -20], [-4, -30], [14, -11], [49, -35], [-49, 11], [26, 22], [-30, 0], [-36, 21], [10, -4], [-36, 12], [-42, 22], [-21, 21], [51, 9], [-18, 48], [-50, 18], [-15, -19], [76, -7], [46, 19], [-2, -26], [-6, 27], [0, -11], [-38, -10], [26, -17], [-26, 16], [-28, -4], [8, -23], [34, 2], [-44, 34], [-24, 12], [18, 20], [28, 5], [-30, 12], [-28, 30], [36, -18], [-16, 5], [-56, 8], [60, 8], [-28, -10], [58, 6], [14, -32], [28, -44], [-30, -24], [33, -45], [32, -40], [-39, 27], [-16, -24], [-34, 36], [-36, -12], [-16, 20], [-57, -9], [34, 24], [63, 3], [-22, 9], [-28, -5], [48, 6], [-20, 16], [-29, -33], [54, -15], [46, 0], [-20, 23], [63, -7], [-7, 37], [9, 3], [-4, 8], [22, 25], [96, 3], [12, 24], [-11, 1], [-25, -23], [102, 0], [-22, 1], [-4, 35], [18, -12], [0, -12], [26, -24], [66, -12], [24, -24], [-12, 24], [-16, 26], [-45, -21]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7616_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7616_2_a_q();".
// 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_7616_2_a_q(:prec:=2)
    chi := MakeCharacter_7616_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_7616_2_a_q();".
// 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_7616_2_a_q( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7616_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-3, 1, 1]>,<5,R![-3, -1, 1]>,<11,R![0, 1]>,<19,R![-4, 6, 1]>],Snew);
    return Vf;
end function;