
// Make newform 9576.2.a.br 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_br();".
// 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_br();".
// 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 := [-3, 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], [0, 2], [4, 0], [5, 1], [1, 0], [-4, -2], [-1, 1], [0, 2], [-4, 2], [8, -2], [-2, 4], [-3, -5], [3, -3], [8, 0], [8, 2], [-4, 0], [-1, 3], [4, 2], [-2, 2], [5, 3], [0, 6], [6, 0], [-1, -9], [0, -4], [-3, -3], [2, -8], [-1, 1], [-4, -4], [3, -3], [-4, 4], [6, 2], [-6, 2], [-18, 2], [4, -6], [-10, 0], [6, 6], [0, 6], [3, -13], [-10, 8], [-8, 6], [0, -10], [0, -4], [4, 12], [4, 0], [-4, -10], [10, -2], [-6, -4], [18, 2], [6, -8], [22, 4], [9, -1], [-14, -8], [10, -4], [6, -4], [6, -10], [-2, -14], [17, -1], [8, -8], [24, 2], [-4, 10], [27, 1], [4, -10], [-13, 1], [-6, 6], [10, -4], [22, 8], [10, 8], [-13, 3], [8, -2], [-12, -8], [-2, 16], [-6, -14], [18, 2], [6, -2], [6, 0], [3, -11], [8, 16], [-5, -3], [-8, -10], [-3, -11], [2, -4], [8, 2], [-6, -8], [19, 9], [2, -6], [19, -13], [0, 8], [-5, 1], [31, 1], [-20, -8], [6, 8], [4, 0], [3, 5], [6, 12], [10, 16], [-4, -2], [18, -8], [2, -22], [-10, 2], [18, 2], [-3, 11], [-24, -4], [28, -10], [-3, 11], [5, -15], [-1, 11], [6, -20], [-4, 12], [18, 6], [8, -16], [-10, 2], [-14, 4], [5, 7], [0, -24], [-7, 7], [-20, -4], [-15, 1], [-8, -20], [-8, 14], [-2, -4], [-17, -1], [-22, -10], [12, 0], [-10, -14], [-23, -9], [2, 6], [4, -2], [34, 4], [9, 25], [-6, 6], [22, 16], [9, 1], [36, -2], [-20, -6], [20, 2], [12, -14], [-32, 4], [0, 16], [-2, 10], [-10, 0], [23, -13], [46, 4], [-12, 12], [-26, -4], [4, -6], [-20, 12], [3, 11], [34, 12], [-5, -13], [-12, 16], [2, 22], [4, -20], [29, -11], [0, -8], [-27, -3], [26, -8], [6, -20], [12, -26], [19, 9], [-18, 12], [-48, -4], [-9, -7], [8, 12], [-32, 12], [-8, 22], [-8, -18], [-21, -13], [5, -3], [-28, -16], [46, 4], [-30, 2], [-12, 28], [-25, -9], [-6, -24], [-28, 20], [32, 2], [6, -8], [-40, 0], [0, 8], [0, 2], [-16, 18], [12, -10], [15, -9], [-6, 12], [0, 6], [-40, 2], [-21, -7], [12, 8], [28, -18], [14, -14], [50, 4], [-24, 6], [54, -8], [26, -2], [14, -20], [-57, 3], [27, 5], [27, 5], [-44, -12], [22, 12], [-44, -8], [31, 17], [1, -27], [-36, -4], [-1, 11], [42, -2], [16, 18], [-14, -18], [-43, 5], [-22, -20], [18, -10], [-12, -4], [48, 8], [-6, 8], [38, 0], [-55, -3], [22, 2], [-30, 12], [-16, 4], [-9, 33], [16, -24], [-28, -4], [10, 20], [14, 20], [33, -11], [-4, 10], [-42, -4], [-58, 8], [-28, 10], [-44, 0], [33, -5], [20, 16], [-23, -9], [-4, -6], [-12, -12], [-30, -12], [-30, 18], [13, -23], [58, 6], [0, 0], [-32, 22], [18, 0], [-3, -33], [10, -26], [38, -14], [-50, -2], [40, 14], [58, 0], [-61, 3], [-42, 8], [40, 4], [-21, 3], [-36, 6], [6, -16], [16, -14], [-30, 16], [44, -6], [2, 26], [33, -11], [8, -6], [-24, -16], [-3, 9], [32, -10], [-51, 7], [-61, 3], [2, -10], [2, 26], [38, 8], [-8, -24], [-34, -12], [8, 8], [-14, -20], [-38, -10], [26, 4], [52, 14], [-36, -26], [9, 7], [-34, -18], [-70, 4], [-33, -15], [6, 20], [30, 6], [-42, 16], [-30, 8], [5, 3], [-38, -14], [2, -40], [-34, -2], [-21, 25], [-31, -9], [52, 4], [-18, -4], [13, 25], [-52, -10], [1, 17], [-30, -14], [18, 2], [24, -26], [-37, -11], [4, -28], [51, -1], [18, -20], [-34, -4], [-13, 27], [-24, -12], [6, -4], [46, 6], [-21, -19], [-30, -34], [-3, 7], [-46, 14], [-24, -2], [-10, 0], [-3, -17], [33, 21], [40, 6], [36, 16], [12, -40], [-46, -2], [-50, 16], [-14, 30], [50, 2], [34, 0], [-62, 14], [-12, 0], [-51, 13], [16, 8], [-62, 16], [25, -29], [10, 30], [9, 3], [8, -12], [19, -31], [10, -4], [-44, -2], [34, 24], [-46, -6], [26, 4], [-12, 32], [16, -6], [8, 0], [-49, -15], [3, -9], [38, 0], [72, 4], [40, -24], [-45, -13], [16, -12], [-32, -26], [32, -8], [-20, -36], [-10, 4], [-42, 0], [-51, 15], [25, 39], [-54, -10], [23, 27], [-26, 24], [33, 9], [-21, 15], [19, 23], [-10, -22], [-36, -14], [-11, -19], [36, 28], [-28, 34], [-20, 10], [-12, 2], [-6, -12], [35, -35], [50, -6], [-22, 12], [60, 0], [-20, -22], [22, 12], [9, -27], [-14, -4], [-30, -28], [-4, -28], [-66, -16], [-52, -16], [64, -2], [22, 26], [70, 0], [-82, 0], [50, -4], [-6, 38], [-16, -6], [36, 18], [40, 22], [-8, -12], [-51, 29], [78, -8], [-4, -28], [24, 34], [16, 8], [-18, -2], [-4, -28], [-88, 4], [6, 50], [-26, -12], [18, -36], [4, 20], [-50, 4], [-15, -41], [-4, -36], [-41, 33], [-34, -32], [30, -14], [27, -37], [58, -4], [-10, 40], [-53, 23], [27, -21], [-8, 26], [3, 19], [24, 0], [-39, -5], [58, -4], [-6, 52], [8, -56], [4, 8], [16, 22], [-21, 27], [18, -2], [-10, -26], [5, -29], [64, 24], [68, 18], [50, 24], [-32, 16], [-22, 4], [47, -29], [-18, -2], [-46, 0], [52, 16], [8, -24], [25, 47], [20, 36], [-18, -36], [73, 1], [-50, 16], [-67, -21], [62, 6], [60, -12], [20, -52], [0, -44], [34, 42], [12, -8], [-18, 32], [29, 17], [-34, -8], [79, -3], [44, 18], [24, -8], [10, -44], [-51, 3], [24, 4], [-16, -12], [63, -25], [16, 30], [26, -18], [-14, 8], [20, 8], [-29, -23], [4, -56], [-2, -14], [-10, -42], [-1, -13], [22, 26], [-30, 26], [69, -7], [-62, 4], [-20, 4], [30, 14], [3, 49], [91, -7], [22, 4], [-12, 26], [-88, 0], [44, 14], [-54, -10], [54, 0], [-50, -10], [-2, 26], [56, 12], [8, -8], [-54, 24], [-4, -12], [0, -26], [-22, -36], [68, 18], [-4, -10], [-64, -20], [46, 10], [10, -46], [18, -14], [-18, -38], [-34, 46], [-47, 3], [32, -8], [52, -6], [-11, -15], [21, -39], [-8, -34], [-40, 18], [-8, 36], [-57, 29], [57, 3], [2, -48], [3, -23], [-4, -24], [-82, 2], [38, 24], [30, -8], [15, -25], [-40, 10], [-98, -2], [-62, -6], [33, 7], [48, -14], [38, -40], [-45, 29], [12, -8], [-47, -7], [-37, -17], [-54, -8], [8, -40], [57, -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_br();".
// 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_br(: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_br();".
// 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_br( : 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, -2, 1]>,<11,R![-12, 0, 1]>,<13,R![-4, 1]>,<17,R![22, -10, 1]>],Snew);
    return Vf;
end function;