
// Make newform 9576.2.a.bh in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9576_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_9576_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_9576_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 := [-7, 0, 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_9576_a();"
function MakeCharacter_9576_a()
    N := 9576;
    order := 1;
    char_gens := [7183, 4789, 5321, 4105, 1009];
    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_9576_a_Hecke(Kf)
    return MakeCharacter_9576_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], [0, 0], [-1, 1], [1, 0], [-2, 0], [-4, 0], [3, 1], [1, 0], [6, 0], [-3, 1], [-4, -2], [0, -2], [-2, -4], [-2, 0], [-5, -1], [1, -3], [-4, 4], [8, 2], [4, -4], [-3, -1], [-4, 2], [6, -2], [-9, 3], [-6, 0], [6, -4], [-7, -1], [8, 4], [-1, 1], [10, 0], [9, -3], [-4, 0], [9, -3], [-12, 4], [-6, -2], [-10, 2], [14, -2], [-4, -6], [-2, 4], [-10, 2], [-14, 0], [-7, 7], [6, -4], [-6, 0], [-20, 2], [16, 4], [12, 4], [-12, -4], [0, 2], [-18, -2], [2, 4], [10, -2], [-8, -2], [-10, 0], [-5, -1], [-8, 2], [-8, -2], [-4, -10], [10, 2], [-14, 6], [15, 3], [8, 0], [-14, -4], [-8, 6], [17, 1], [12, -2], [-3, -3], [2, 10], [2, -4], [4, -6], [10, 0], [17, -1], [22, -4], [4, 8], [-26, 0], [2, -2], [18, 6], [6, -6], [-18, 0], [-11, 1], [8, 8], [-15, -3], [4, -6], [-21, -3], [-14, 0], [-20, 6], [-16, 2], [-7, 1], [-18, 6], [-3, 3], [-8, 8], [5, 5], [-7, 5], [4, -12], [-4, 2], [12, 0], [5, -7], [-16, 2], [0, -6], [8, -6], [-6, -8], [10, -2], [-6, -6], [6, -6], [-21, -1], [8, -12], [-4, 14], [-9, 3], [-29, 1], [-19, 7], [-2, 16], [12, 4], [-26, 2], [-16, -8], [-22, 6], [34, 0], [-9, -1], [0, -8], [-9, -5], [-16, 8], [-13, -3], [-24, 4], [4, 10], [4, -10], [5, 11], [-42, 2], [4, 8], [-6, 14], [-33, 3], [-26, -6], [-4, 6], [26, 0], [31, 1], [18, 10], [-10, -16], [-21, -3], [4, -10], [-2, -4], [8, -10], [26, 8], [8, -12], [8, -16], [2, 2], [6, 4], [25, -5], [14, 8], [20, 4], [-42, -4], [-18, 12], [-28, -4], [-3, -5], [2, -4], [33, 7], [20, -8], [-22, -6], [-4, 8], [11, -3], [24, 0], [-25, 1], [-38, 0], [0, 2], [6, 0], [1, -7], [22, 8], [16, 4], [25, 13], [32, -4], [16, 0], [-8, 6], [-12, 2], [-19, 11], [31, 9], [-12, -8], [-44, -2], [-10, -2], [-12, 4], [13, 3], [26, 4], [56, 0], [44, 6], [-2, -16], [8, 0], [-28, 12], [-12, 6], [-6, -12], [10, -12], [33, -9], [10, 20], [-4, -6], [-4, 14], [-7, 9], [12, -16], [30, 0], [14, 14], [-8, 14], [6, 12], [-20, 18], [6, -14], [-2, -12], [-31, -13], [-3, -23], [-31, -3], [20, -4], [22, -8], [4, 16], [13, 9], [3, 9], [4, 12], [17, -13], [42, -6], [-20, -2], [30, 10], [-5, 5], [-14, 0], [-62, 2], [-12, -12], [24, -8], [2, 4], [12, 10], [-5, 1], [-42, 6], [50, 4], [32, 12], [9, -3], [48, -8], [-8, -8], [-6, -20], [8, 18], [-21, 17], [40, 6], [16, -22], [-10, 8], [16, 6], [-20, 12], [-13, -21], [4, 16], [31, 11], [44, -6], [4, -4], [12, -14], [10, -2], [19, 1], [6, 10], [32, -8], [-52, -6], [-4, -10], [-25, -1], [-66, 2], [-30, -14], [-18, 10], [10, -24], [10, 0], [-15, 15], [-4, -6], [-16, 20], [-11, -13], [-30, -12], [38, -8], [-60, -2], [20, -10], [-60, 2], [50, -10], [31, 13], [64, 2], [40, 8], [-37, 9], [-36, 10], [-5, 11], [9, -9], [10, 18], [10, -26], [-34, -4], [-40, 4], [-2, -12], [-8, 16], [2, -24], [-18, 2], [0, 6], [16, -6], [-24, -6], [3, -9], [18, 14], [-62, 0], [33, -3], [14, -8], [26, 10], [-8, 22], [34, 8], [-9, 3], [-42, -10], [-28, 6], [-10, 18], [45, 5], [47, 11], [-24, -16], [-18, 12], [39, -3], [8, 2], [-25, -23], [-50, -14], [-10, 22], [-8, 14], [41, -3], [-20, 12], [-19, 7], [-46, -8], [22, -12], [9, 15], [-8, -4], [-64, 2], [-38, -14], [37, 17], [22, 14], [-1, -1], [-22, -6], [54, 12], [-34, -12], [-21, -13], [59, 1], [0, 14], [-12, -16], [-4, -8], [14, 2], [24, -2], [18, 26], [-6, -18], [26, 4], [10, 18], [4, -8], [3, 13], [28, 20], [-30, -16], [-17, 7], [30, -14], [7, -25], [-56, -12], [21, -3], [-6, 4], [10, -20], [10, 0], [30, 6], [10, 28], [60, 8], [-6, 20], [0, 20], [-19, 9], [69, -9], [-42, -16], [24, 0], [-12, 20], [53, -5], [8, -4], [12, 10], [64, 8], [44, 4], [-26, 4], [0, 6], [-9, -9], [3, -17], [14, 22], [-27, 7], [70, 8], [-53, -3], [9, 3], [-11, -9], [58, -2], [-32, 14], [11, 29], [44, 16], [8, 14], [-46, -16], [-40, -2], [-60, -6], [33, -11], [-18, -10], [-6, 20], [4, -8], [34, 24], [22, -4], [15, 21], [10, -8], [-20, 26], [24, 24], [54, -4], [48, -12], [-84, 2], [-54, 2], [-42, -12], [54, -8], [-38, 0], [-2, -10], [52, -18], [-34, -20], [30, -12], [0, -20], [43, 5], [-18, 8], [44, 20], [-30, -12], [-48, 4], [42, 6], [-36, -20], [44, 0], [14, -2], [-48, -14], [-12, -6], [44, -12], [-58, -12], [-1, -5], [-4, -28], [-59, 9], [6, -20], [-22, 18], [-71, 7], [2, -24], [-26, 16], [-39, -21], [21, -21], [-44, -18], [-87, 7], [-20, 4], [63, 15], [2, 0], [12, -30], [56, -8], [-92, 0], [-46, 0], [73, -9], [-30, -6], [-30, 2], [11, 31], [-32, -16], [34, -16], [18, 28], [-20, -4], [42, -20], [-15, 27], [10, -22], [-38, 24], [-36, 4], [8, 32], [35, 7], [-24, 16], [62, 4], [-17, 9], [-42, 16], [19, -1], [42, 10], [84, 4], [36, 4], [-16, -4], [26, -26], [-36, -24], [32, 14], [-5, 33], [-26, 24], [41, 25], [-48, 6], [0, -16], [-6, 28], [-29, 7], [-48, 24], [0, -8], [-51, 11], [44, 10], [-10, 10], [-14, -8], [20, 12], [-27, -3], [-16, 4], [-30, 14], [54, 18], [-23, 19], [30, 6], [-2, -10], [-53, -15], [-30, 32], [12, -4], [18, 2], [-71, 1], [-51, 13], [-18, 32], [90, 0], [16, 0], [-42, 0], [-2, -38], [-28, -14], [90, 10], [-90, 6], [-96, -4], [24, 20], [2, 4], [-64, 0], [-4, 10], [60, -6], [10, -24], [-4, -18], [40, -20], [-54, -6], [-10, -10], [34, -10], [26, 10], [2, -6], [11, 19], [56, 0], [-24, 14], [35, 1], [15, -3], [-36, -22], [28, -2], [-32, -28], [33, -15], [-85, 11], [50, 24], [-43, 5], [52, 0], [-14, -2], [-80, -10], [-10, 16], [-63, -9], [20, -18], [-38, 10], [-54, 22], [-89, -5], [14, 8], [-2, 24], [57, -11], [68, -8], [-1, 9], [-67, -17], [84, 6], [32, -24], [19, -21]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9576_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9576_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_9576_2_a_bh(:prec:=2)
    chi := MakeCharacter_9576_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(3833) - 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_9576_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_9576_2_a_bh( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-6, 2, 1]>,<11,R![2, 1]>,<13,R![4, 1]>,<17,R![2, -6, 1]>],Snew);
    return Vf;
end function;