
// Make newform 9576.2.a.bx in Magma, downloaded from the LMFDB on 25 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_bx();".
// 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_bx();".
// 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 := [-4, -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_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], [2, 0], [-1, 0], [-2, 0], [1, 1], [-1, -1], [-1, 0], [3, -1], [-5, 1], [3, 1], [-5, -1], [0, -2], [4, 0], [0, 0], [-1, 1], [2, 2], [-2, 0], [-6, 2], [-3, -3], [-10, 0], [9, -1], [5, -1], [-8, -2], [0, -2], [-10, 0], [-13, 1], [1, 1], [-5, -1], [-5, 1], [17, -1], [-1, 5], [10, 2], [6, 2], [-13, 1], [9, -1], [-16, -2], [-8, 4], [-10, -2], [-4, -2], [1, -3], [7, 3], [11, 3], [-2, 0], [-15, 3], [-14, -2], [-8, -4], [3, -3], [-6, 2], [4, 6], [-6, 2], [-13, -1], [-4, -6], [-13, -3], [14, 0], [-9, -5], [14, 0], [12, 0], [-2, 0], [-17, 1], [8, 4], [-8, 2], [8, -4], [-16, 0], [2, 8], [3, -3], [-4, 0], [10, 4], [-16, 2], [12, 2], [-15, -3], [-5, 3], [-18, 2], [9, 5], [8, 4], [-32, 0], [-7, -1], [-4, -6], [-19, -5], [-12, 2], [11, -3], [31, -1], [-31, 1], [0, -6], [27, -3], [-4, -2], [29, -1], [24, -2], [24, -2], [6, -6], [11, -3], [-20, 4], [7, -7], [2, 0], [28, 0], [-12, 0], [16, 6], [-18, 4], [8, -8], [-24, -2], [12, 8], [15, -3], [-8, -4], [-21, 5], [20, 0], [-8, 2], [5, 3], [-1, 7], [-27, -3], [-2, -4], [27, 5], [0, 6], [-16, 4], [-14, -2], [-14, -2], [25, -1], [-12, 0], [-10, 2], [17, 7], [-15, -7], [-15, 5], [-30, 4], [12, -2], [5, 1], [-30, -2], [-13, 5], [4, -10], [-2, -2], [14, 6], [-10, -4], [16, -4], [-35, -3], [5, 3], [-10, 4], [-23, 1], [-14, 0], [-26, 4], [-26, -6], [10, 8], [10, 6], [-22, 6], [13, -9], [18, 6], [-21, 7], [-17, -5], [-2, 6], [6, 0], [-12, -6], [-4, 0], [11, -5], [1, 5], [29, 1], [20, -8], [18, 2], [2, 2], [-31, -7], [-14, -2], [-25, -5], [-36, 6], [8, -10], [-8, 6], [5, -9], [24, 0], [4, -4], [-3, -5], [8, 0], [-3, 3], [-20, 2], [18, 0], [0, -10], [-5, 7], [27, -5], [15, -1], [-42, 4], [19, -3], [15, 7], [0, -12], [-3, 3], [19, 1], [34, -4], [2, 14], [18, 6], [13, -7], [16, -6], [-3, -3], [-32, -2], [-29, -9], [-18, -6], [-2, 4], [-28, 0], [-2, 8], [16, -2], [-12, 8], [34, 0], [-18, 0], [2, 8], [6, 8], [20, -6], [1, -7], [48, 0], [15, 1], [-1, 9], [-47, 1], [6, -8], [5, 15], [46, 0], [0, 0], [11, 7], [-10, -6], [-2, -2], [-16, 2], [50, 0], [-6, 6], [44, -4], [-10, 6], [40, -6], [36, -4], [10, 8], [-1, -1], [-11, 3], [-5, 7], [45, -1], [3, -7], [22, 2], [6, 2], [20, 6], [6, 0], [11, 3], [17, 3], [8, -14], [-18, 4], [6, 6], [27, 5], [-9, 5], [36, -8], [-8, -12], [6, 0], [47, 5], [-26, -4], [36, 4], [-41, -1], [38, 2], [24, -8], [-3, -3], [42, 4], [14, -6], [-4, -16], [-12, -8], [22, 6], [11, 7], [-62, 0], [-41, -9], [3, -5], [6, 0], [-18, 8], [-2, 0], [-46, 4], [4, -8], [54, -4], [18, 0], [11, -11], [-27, -7], [58, 0], [31, -9], [-3, 1], [-14, 6], [-49, 1], [-1, 7], [30, 6], [-15, -9], [-53, 3], [-12, -8], [28, 2], [-28, 4], [62, 0], [-16, 12], [34, -4], [9, 17], [-20, 10], [9, 7], [0, 0], [40, 8], [48, -4], [7, 7], [46, -6], [17, 5], [-26, -8], [25, -9], [6, 6], [54, 0], [-25, -11], [41, 3], [-49, 1], [40, 4], [-17, -9], [-4, -14], [5, 3], [-12, 6], [76, 0], [-10, -6], [-12, 14], [-5, 1], [-20, -12], [5, 13], [0, -4], [-28, -6], [11, 11], [15, 11], [27, -5], [36, -2], [-22, 2], [-17, 1], [21, 11], [6, 6], [-35, 5], [-22, 4], [-25, -3], [-41, 7], [36, -6], [-20, 16], [-6, 2], [36, 2], [-22, -8], [-25, -15], [-36, -4], [-16, 6], [-16, -4], [0, 4], [17, -15], [-15, -9], [58, -8], [21, 7], [-20, 8], [15, 9], [-8, 12], [59, 5], [-3, -7], [64, -2], [-16, -18], [42, 10], [37, 9], [-34, -2], [-10, 0], [5, 11], [15, 5], [5, -3], [2, -16], [-38, 2], [24, 0], [2, 12], [30, 6], [-18, -4], [9, 3], [69, 3], [25, -11], [42, -8], [12, -8], [9, -5], [12, 4], [57, 1], [-16, 6], [-5, -9], [1, 17], [39, 3], [50, -2], [56, -10], [0, -22], [69, -5], [54, 0], [-16, 18], [-2, 6], [45, 1], [-29, 5], [72, -4], [30, -8], [-48, -8], [7, -5], [-20, 6], [41, 5], [-20, 10], [-20, -10], [-70, 6], [-2, 2], [-32, 8], [30, 2], [-56, 8], [-76, -4], [-8, -6], [-4, -8], [62, -2], [0, 10], [16, 6], [80, -2], [-8, -12], [-7, 1], [24, -18], [5, 11], [84, -2], [-34, 14], [41, -9], [-21, -13], [-42, 2], [-29, -3], [42, 12], [-22, 4], [-24, -8], [-2, -8], [21, 15], [32, 8], [-39, 15], [22, -12], [57, -1], [-27, 1], [-32, 4], [26, 0], [-16, -14], [7, -9], [-47, 3], [-13, 3], [6, 22], [-27, -9], [57, -3], [-5, -13], [4, 4], [16, 18], [32, 2], [-33, 7], [-38, 10], [54, -6], [-22, 6], [-68, -6], [-22, 4], [-44, 0], [40, 16], [-46, -4], [27, -17], [16, 22], [15, 15], [-52, 0], [-8, -8], [-27, -5], [48, 4], [-49, -1], [-43, -11], [-64, 6], [25, 3], [-26, 10], [72, 0], [-28, -10], [39, 11], [-28, 8], [-78, 2], [-40, -2], [-63, -3], [28, -18], [-37, 13], [43, 3], [-2, 6], [0, 2], [-19, 7], [-22, -6], [-59, -5], [-9, -9], [-5, -25], [-34, -6], [24, -10], [9, -17], [-85, -7], [26, 18], [-50, -6], [55, 1], [-23, -15], [10, -6], [38, 8], [-33, -9], [-27, -3], [-43, -5], [26, 2], [2, 10], [37, 3], [4, -6], [12, -18], [8, -18], [14, -4], [24, -4], [-30, -4], [2, 0], [38, -14], [-62, 10], [-35, 11], [61, -7], [6, -2], [28, -6], [38, -8], [-16, -18], [52, -14], [-8, 12], [-27, 15], [-2, -26], [-24, -12], [71, 1], [18, 2], [-57, -3], [46, 2], [-21, -17], [37, 9], [27, 19], [-19, 15], [39, -1], [-30, -6], [-47, 3], [40, 8], [-58, -4], [-53, 5], [-44, -8], [34, 4], [0, 14], [30, 8], [3, 27], [59, 5], [-34, -8], [-54, -6], [13, -17], [23, 7], [36, -18], [-21, -7], [-52, -6], [0, -22], [-9, -13], [-50, -4], [-44, -4], [-19, -5]];
    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_bx();".
// 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_bx(: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_bx();".
// 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_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9576_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![-2, 1]>,<11,R![2, 1]>,<13,R![-16, -2, 1]>,<17,R![-16, 2, 1]>],Snew);
    return Vf;
end function;