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