
// Make newform 2496.2.a.bi in Magma, downloaded from the LMFDB on 11 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_2496_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_2496_2_a_bi();".
// 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_2496_2_a_bi();".
// 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 := [-2, 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_2496_a();"
function MakeCharacter_2496_a()
    N := 2496;
    order := 1;
    char_gens := [703, 1093, 833, 769];
    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_2496_a_Hecke( : Kf := Kf)
    return MakeCharacter_2496_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], [0, 1], [0, -1], [-2, 0], [1, 0], [2, 2], [0, -1], [4, 0], [-2, 0], [4, -1], [2, 2], [8, -1], [4, -2], [6, 2], [2, 0], [2, 2], [-2, -4], [4, 1], [-2, 0], [6, -2], [0, 4], [-2, 2], [12, 1], [-2, 2], [-2, -2], [-8, 2], [0, -4], [6, -4], [6, -4], [0, -2], [-8, 0], [-8, -1], [4, -4], [12, -1], [12, -3], [10, 0], [16, 1], [-2, 2], [6, 2], [-12, -4], [-14, 0], [8, -4], [-6, 4], [8, -3], [-16, -2], [-12, 0], [4, 3], [-6, -4], [-10, 4], [-10, 6], [-2, 0], [6, -2], [0, 0], [-10, 2], [-12, 0], [-18, 0], [8, 7], [2, 0], [24, -1], [12, 6], [12, -5], [-20, -1], [-12, 8], [6, 0], [0, -3], [12, 5], [-2, 4], [-20, 4], [2, -2], [-8, -9], [-18, -6], [24, 0], [-10, 0], [-8, 3], [-14, -6], [10, 6], [-14, -6], [12, 5], [-18, -6], [-8, 8], [-26, -4], [-14, 2], [-10, -4], [0, -6], [8, -12], [-12, -7], [-2, -2], [-8, 1], [16, 3], [-8, 0], [-14, -4], [-12, 7], [8, 8], [12, 5], [-4, 4], [8, -7], [14, 4], [-4, -4], [-10, 0], [12, 4], [-12, 7], [4, 0], [-26, -6], [4, -6], [2, -12], [6, -6], [-12, -3], [12, 4], [22, -8], [-8, -12], [42, 2], [-32, -1], [4, 7], [-12, -11], [2, 10], [20, 1], [0, -4], [14, 4], [-36, -4], [18, 6], [-6, 8], [-38, 4], [14, 12], [-20, 5], [-22, 6], [-18, 8], [-4, 12], [16, -2], [14, 8], [-4, -5], [-2, 0], [-16, 6], [-18, -12], [24, 3], [42, 0], [-20, -5], [-4, -13], [-30, 2], [30, -4], [-16, -5], [4, 7], [-32, 6], [-26, 0], [6, 4], [2, -16], [2, -2], [-10, -14], [-12, 4], [34, -2], [-14, -10], [14, -14], [-12, 14], [8, 0], [4, -6], [40, 0], [8, -4], [-8, 7], [-10, -4], [-20, -5], [-38, 6], [46, -2], [-4, -5], [-4, -4], [28, 5], [-14, -4], [-16, 4], [-6, 16], [22, -6], [-10, -10], [10, -12], [18, 10], [36, -4], [-18, 2], [-8, -10], [34, 8], [4, -9], [28, -5], [-8, -6], [30, -8], [-8, 19], [52, 4], [30, -4], [4, 9], [14, 2], [26, -2], [-6, 8], [8, 3], [22, 2], [14, 10], [-14, -8], [6, -18], [-20, 16], [-20, 7], [28, 12], [14, -10], [2, -4], [-18, 8], [-36, 1], [32, 4], [8, 1], [-16, -12], [-34, 0], [18, 0], [2, -2], [42, -4], [12, 3], [0, 24], [36, 1], [20, -2], [-42, -4], [18, -4], [-16, 0], [-34, 12], [-22, -10], [34, 0], [-48, 8], [-22, 12], [38, 8], [44, 3], [26, -8], [-8, 15], [-44, 5], [4, 7], [40, -12], [10, -12], [34, 0], [-68, 0], [48, 2], [50, 2], [-6, 8], [4, 0], [-8, 13], [-6, 18], [36, -8], [-2, -16], [38, 10], [28, -17], [4, 12], [16, -16], [-10, -6], [-52, 2], [-8, 4], [-6, 10], [12, -19], [-28, 8], [-24, 3], [-38, -14], [-24, 15], [28, 12], [6, -8], [8, -9], [-30, 4], [6, -20], [-42, -4], [14, -4], [22, 8], [-24, 7], [10, -10], [-30, 8], [48, 10], [12, 4], [14, -4], [34, 8], [-12, 9], [12, 8], [-48, -3], [24, -17], [-44, 11], [-18, 6], [-42, 8], [-28, 5], [14, -10], [-32, -6], [-2, 16], [8, -7], [-38, -8], [42, 2], [2, -20], [8, -16], [-8, 4], [48, 3], [16, 12], [10, -10], [-36, 7], [16, -12], [22, 4], [-36, -1], [68, 5], [-26, -2], [34, -4], [-12, -12], [12, 5], [-22, -6], [26, 0], [10, -14], [-48, 0], [-6, 6], [4, -12], [28, 7], [26, 8], [16, 9], [-80, -2], [-28, 16], [4, -8], [-18, 6], [-4, 16], [2, -16], [-14, 4], [-34, -4], [-20, 0], [40, -3], [-34, -12], [36, 4], [6, 6], [38, 8], [2, 12], [42, 2], [38, -10], [-6, -6], [68, 6], [-70, -4], [34, 8], [-76, -3], [4, 1], [22, 12], [16, 1], [-20, -23], [-16, 20], [-18, -12], [46, 0], [-42, -12], [8, -8], [-2, 20], [8, 11], [6, 22], [-6, 18], [-16, 15], [-34, 6], [0, -6], [-46, 6], [-18, -8], [60, 3], [0, -2], [-16, -15], [36, 8], [38, 0], [40, 5], [-58, 2], [-22, 2], [-28, -15], [-10, 22], [-60, -5], [0, 10], [-18, 8], [38, 4], [-50, 2], [-38, 0], [-50, -10], [74, -6], [-22, 6], [-62, -2], [-20, -20], [-22, -24], [-4, 22], [-14, 24], [0, 21], [-20, 1], [2, 0], [-24, -20], [36, -2], [-2, 6], [10, 16], [-56, -4], [-30, -8], [70, -10], [72, -4], [-14, 4], [10, -4], [-14, 28], [-60, 7], [48, 3], [-16, -21], [20, -15], [-32, 25], [-6, -12], [-16, -3], [-2, 12], [-32, -21], [-52, -4], [22, -6], [-4, -9], [-42, -16], [60, -12], [-10, -14], [-2, -28], [-64, -3], [50, 6], [4, 12], [32, 5], [-38, -10], [-6, 2], [16, 23], [28, 13], [0, -11], [32, 4], [14, 16], [-4, 13], [-44, -1], [-42, 20], [-14, -8], [-70, 4], [-52, 12], [12, 26], [2, -28], [18, 4], [-10, 0], [48, 4], [52, -3], [28, -20], [46, -2], [10, -2], [-42, 12], [24, -24], [34, -20], [4, 27], [-48, 16], [-36, -11], [-8, 5], [-8, -24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2496_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_2496_2_a_bi();".
// 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_2496_2_a_bi(:prec:=2)
    chi := MakeCharacter_2496_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_2496_2_a_bi();".
// 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_2496_2_a_bi( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_2496_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-8, 0, 1]>,<7,R![-8, 0, 1]>,<11,R![2, 1]>,<17,R![-28, -4, 1]>,<19,R![-8, 0, 1]>],Snew);
    return Vf;
end function;