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