
// Make newform 2496.2.a.bh in Magma, downloaded from the LMFDB on 24 April 2024.
// 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_bh();".
// 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_bh();".
// 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 := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 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)
    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+1)]];
    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, -1], [-1, -1], [2, 0], [1, 0], [0, -2], [3, -1], [-2, -2], [0, 2], [-1, 3], [4, 2], [-1, -1], [2, -2], [2, 4], [-4, 2], [4, -2], [8, -2], [9, 1], [0, 2], [-4, -2], [0, -4], [12, 2], [1, 5], [0, 2], [-6, -4], [6, 2], [10, -2], [10, 4], [-2, 0], [-2, 2], [2, 6], [-9, -1], [4, 8], [-15, -3], [21, 1], [0, -6], [5, 1], [-2, -8], [-2, 0], [-6, -6], [4, 6], [6, 2], [2, -8], [-25, -1], [14, 2], [8, -4], [11, 7], [2, -4], [6, 0], [-4, 6], [-8, 2], [0, 10], [-20, 4], [-8, 2], [0, -4], [-16, 2], [-1, -9], [6, -4], [3, 3], [-18, 2], [1, 5], [-9, -1], [14, 6], [14, -8], [7, -1], [-3, 5], [2, 4], [-20, 0], [-8, -10], [3, 11], [10, -12], [-28, 0], [26, 4], [-1, 11], [-30, 0], [-6, 8], [12, 2], [-7, 5], [12, -10], [34, -2], [18, -4], [10, 0], [-4, 2], [-18, 2], [-26, 2], [-3, -15], [-12, -10], [7, 7], [11, 3], [-16, 8], [-8, 14], [-33, 3], [-20, 4], [29, 5], [4, 16], [-5, -5], [10, 4], [32, -4], [-2, 0], [-8, 4], [-7, -3], [6, -2], [8, 10], [-30, -2], [-10, -4], [20, -6], [13, 1], [16, 4], [30, 8], [-28, 0], [-8, -10], [-21, 11], [23, 7], [-3, -7], [8, 6], [9, 9], [-32, 0], [12, -10], [8, 12], [-4, 18], [32, -6], [12, 10], [10, 0], [-3, -11], [-6, 0], [14, 0], [-2, -2], [-6, -2], [-10, 8], [35, -5], [12, -2], [-10, 10], [-24, 6], [-21, -5], [-26, 12], [-15, -3], [11, 3], [34, 0], [-22, 4], [15, -5], [-11, 9], [14, -14], [2, 16], [-44, 2], [8, -10], [16, -2], [-24, -6], [-24, -4], [-30, -8], [4, -14], [28, -10], [-26, 10], [-14, 14], [-2, 10], [50, -2], [-4, 8], [-25, 15], [0, 14], [29, 1], [28, 6], [36, -2], [-13, -1], [-24, -12], [-7, -3], [36, -6], [32, 4], [42, 8], [-20, -18], [18, -12], [10, -4], [8, -10], [26, 2], [24, -6], [6, 18], [-18, -12], [-25, -1], [-3, 17], [-6, -18], [-14, 20], [11, -5], [-22, 18], [-24, -10], [33, -3], [34, -12], [10, 8], [-28, -2], [39, -5], [24, -6], [10, -4], [8, 26], [4, 18], [-16, 12], [41, -3], [2, -6], [-16, -6], [-46, 0], [6, -8], [25, 5], [-6, -10], [-17, -1], [40, -12], [22, -16], [-16, -14], [32, 2], [-12, 10], [3, -25], [10, -2], [9, 5], [14, 2], [-12, 10], [48, -2], [32, 12], [-10, -4], [-22, 0], [-14, 0], [4, -16], [58, 0], [-12, -18], [45, 1], [-10, -12], [39, -1], [33, 5], [-17, 19], [-12, 12], [22, 4], [-34, 4], [4, -24], [-30, 6], [44, -10], [-28, 14], [36, -8], [45, -3], [-20, 18], [16, -4], [-36, 6], [-44, -10], [-23, 13], [-6, -14], [30, 2], [-16, -26], [2, 22], [-36, -8], [52, 2], [5, -7], [-2, -2], [-13, 3], [32, 10], [3, -33], [-2, 6], [-18, 16], [27, -13], [-8, -2], [-6, -12], [-4, -26], [18, 16], [30, -8], [43, -1], [-10, 4], [-30, 0], [-22, -2], [-8, -20], [10, -20], [-30, -8], [-3, 25], [4, -8], [-21, -5], [27, -13], [-13, 3], [30, 0], [-8, -2], [-27, 21], [48, 10], [-34, -6], [-58, -8], [9, 25], [-14, 4], [-12, -22], [-58, -4], [4, 12], [-6, -10], [-21, -5], [-62, 6], [56, -10], [55, -1], [-12, 20], [-4, 18], [-31, 13], [-19, -15], [40, -6], [12, -30], [12, 0], [21, 1], [48, 10], [56, 2], [54, 4], [0, -12], [38, 20], [4, 0], [7, -1], [34, 8], [-33, 23], [30, 18], [12, -24], [-52, -16], [-4, 22], [-6, -14], [6, 28], [-40, -2], [-10, 24], [-20, -8], [-49, -17], [54, 8], [-4, -8], [-34, 8], [-42, 16], [-50, 0], [42, -8], [0, 26], [8, -10], [-42, 2], [-42, 20], [-40, 6], [29, 9], [-27, -23], [20, -6], [21, 1], [-23, 25], [-32, 8], [40, -6], [10, -20], [8, 18], [60, 8], [14, 4], [-1, -13], [-4, -14], [60, 2], [-69, -5], [28, 6], [-62, -2], [0, 6], [2, 20], [17, -11], [-50, 10], [-21, -29], [-54, -6], [-66, -8], [-7, -11], [86, 0], [-10, -36], [-47, 9], [48, 18], [41, 5], [-42, -14], [24, -26], [-6, 4], [-26, 0], [2, -36], [24, -6], [10, -32], [28, 2], [0, -34], [40, -12], [6, 0], [-10, -22], [36, -18], [-33, -1], [33, -19], [-64, -14], [-26, 2], [14, 2], [-38, 4], [-32, 6], [-12, -16], [30, -28], [-12, 26], [32, 0], [6, -28], [-30, -8], [-8, -14], [-31, 5], [-21, 19], [-21, -13], [-47, -3], [-19, 17], [-12, -14], [69, 5], [-12, -6], [-9, 11], [48, 20], [76, -2], [9, 21], [78, 4], [-44, 8], [10, 20], [-28, -30], [-19, -11], [12, -6], [0, -12], [-29, 19], [0, 6], [-28, 18], [15, 7], [-47, -11], [-9, 15], [-8, 4], [46, -8], [9, 29], [-17, -1], [6, -36], [66, 16], [28, -22], [-44, 8], [18, -34], [-2, -36], [-40, -2], [24, 10], [-56, 20], [1, 5], [-14, 26], [42, -12], [-20, 26], [8, 34], [18, -2], [10, -24], [-79, 5], [12, -12], [13, -31], [57, 13], [-26, 18]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_2496_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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