
// Make newform 8450.2.a.bx in Magma, downloaded from the LMFDB on 12 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_8450_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_8450_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_8450_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 := [1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 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_8450_a();"
function MakeCharacter_8450_a()
    N := 8450;
    order := 1;
    char_gens := [677, 3551];
    v := [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_8450_a_Hecke( : Kf := Kf)
    return MakeCharacter_8450_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]];
    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 := [[1, 0, 0], [-1, 1, 1], [0, 0, 0], [0, -2, 2], [0, -2, 1], [0, 0, 0], [0, -4, 1], [-2, 3, -2], [-2, 2, -4], [-6, 4, -4], [6, 0, 2], [-6, 2, -2], [-4, 1, -4], [-6, 5, -2], [-2, 0, -4], [2, -2, 4], [1, 3, 3], [4, -8, 8], [7, -3, -3], [2, 2, -4], [-3, 3, -7], [-8, 0, -6], [-2, 3, -2], [-9, 5, 3], [4, 8, -3], [6, -4, 8], [-8, -6, 0], [-6, 3, -14], [0, 2, 2], [5, -5, 13], [-2, -8, 4], [-2, 1, 2], [7, -11, 3], [16, -6, 11], [4, 4, 6], [8, -6, 2], [-20, 2, -2], [-8, 2, 7], [-14, 0, 0], [6, 0, 4], [12, -2, -3], [-8, 8, -6], [2, -2, 2], [0, -9, 0], [-6, 18, -12], [12, -6, -4], [-8, -6, -5], [-8, 0, -4], [3, -3, 13], [-16, 8, -8], [-7, -5, 5], [-4, 10, -12], [2, -4, 4], [-8, 10, 5], [4, 13, -4], [8, 0, 2], [12, 8, 0], [-14, 8, -18], [-8, 6, -4], [16, -4, 13], [-6, 11, 2], [-2, -2, 6], [0, 14, -1], [-4, 2, -4], [-8, -4, -3], [-14, 10, 6], [-8, -12, -4], [4, 5, -12], [-8, 8, 0], [10, -2, -6], [0, -8, 15], [18, 0, -2], [-8, -8, 4], [4, -4, -4], [17, -17, 23], [-20, 16, -16], [0, -10, 8], [-10, 10, -24], [-4, -4, -5], [13, -1, 5], [0, 0, 8], [-2, -2, 4], [22, -4, 0], [-1, -19, 15], [-22, 10, 6], [16, -22, 5], [-16, 1, -16], [-10, 8, 4], [-22, 14, -2], [20, -14, 10], [-15, -5, -5], [14, -4, 24], [6, -22, 4], [-7, 27, -9], [-20, 14, -17], [4, 10, 16], [-12, 2, 6], [5, 3, -11], [-4, 2, 1], [14, 8, 10], [1, 7, -9], [28, -24, 34], [-4, -8, 20], [-11, 15, -7], [-19, -13, -1], [-16, 21, -4], [14, -27, 10], [8, 4, -9], [18, -4, 18], [-20, 11, 8], [4, -4, 22], [-12, -10, 12], [-7, -9, 17], [-16, 16, -4], [14, -20, -2], [-24, -7, -4], [22, -5, 26], [-40, 12, -14], [-28, 26, -30], [-17, 1, 9], [-4, -4, 8], [3, 25, -9], [14, 8, -2], [18, 15, -6], [2, -11, -22], [-8, 30, -8], [26, -8, 6], [-2, -6, -2], [-14, 10, -6], [8, -12, -10], [29, -9, 11], [14, -8, 0], [-14, 8, 2], [-6, 2, -8], [-24, -4, -9], [4, -20, 15], [8, 2, -14], [4, -2, -19], [-30, 12, -22], [36, -7, 4], [-12, 10, -9], [-24, 4, 18], [-18, -2, -14], [-9, -7, 13], [-2, -16, 18], [22, -10, 0], [-12, 6, 6], [16, -12, 1], [-3, 19, -13], [32, -24, 14], [36, 4, -4], [20, -8, 17], [28, -22, 37], [24, -18, 26], [-17, 1, -7], [-4, -26, 12], [-10, 24, 0], [-40, 17, -36], [-20, 13, -16], [-32, -4, -2], [-22, 23, -18], [8, -9, -24], [18, 16, -16], [26, -3, -14], [-28, 15, -28], [36, -28, 36], [4, 18, -4], [-18, -2, 2], [-8, -3, -36], [-20, 0, 14], [-3, -13, 7], [2, 10, 24], [-10, 14, -28], [-44, 4, -13], [10, 10, -2], [7, -19, 3], [-4, 32, 0], [34, 18, -12], [-22, 2, 10], [-20, -6, -20], [12, -20, -16], [2, -39, 22], [36, -32, 38], [24, -20, 19], [20, 6, 0], [4, -34, -2], [4, 14, -14], [-13, 25, 5], [24, -32, 3], [38, -8, 34], [-24, 17, 4], [4, -14, -27], [18, 5, -10], [4, -26, 20], [29, -13, 23], [4, 9, 20], [-32, -8, 9], [-32, 22, -26], [-4, -11, -12], [-6, -18, 12], [-20, -28, 10], [-14, 48, -32], [40, -2, 16], [-8, 0, -19], [-20, 30, -21], [-14, -4, -8], [22, -6, 32], [24, -14, 3], [19, -11, -17], [20, -10, 17], [4, -20, -27], [-18, 2, 28], [-22, -26, 10], [16, -10, 5], [-26, 40, -20], [38, -16, 28], [32, -10, 18], [-18, 24, 16], [-26, 18, -24], [38, -22, 22], [-6, 28, 8], [12, -48, 12], [-19, -1, -7], [14, 0, -14], [4, -16, -12], [-8, 30, 18], [22, 16, 8], [-14, -28, 8], [10, -24, 10], [-9, -23, 21], [-46, -12, 12], [11, -15, -15], [-54, 10, -10], [56, -9, 20], [-44, 18, -11], [-54, 14, -16], [25, 27, -7], [2, 24, -20], [2, -21, 2], [-16, -6, 24], [8, -44, 20], [-2, 19, -10], [-28, 34, -38], [-52, 6, -16], [-6, 12, -20], [16, -42, 12], [42, -24, 50], [-4, 0, -16], [-25, 13, -3], [32, 12, -2], [14, 8, 26], [-9, -15, 11], [-38, -16, 8], [-33, 41, -41], [48, -10, 12], [-4, -36, 0], [46, -30, 30], [-28, -8, -20], [34, -28, 22], [27, 17, -25], [-18, 6, 0], [36, -14, 17], [46, 4, 2], [-34, -16, 0], [-28, 4, 9], [8, 6, -19], [24, 8, -6], [-30, 4, -28], [3, 29, 5], [-10, 16, -34], [-10, 10, -14], [-14, -9, -10], [-20, -11, 0], [-34, 40, -32], [4, 1, -8], [-8, -8, 18], [22, 7, 6], [-30, 34, -32], [-48, 8, -7], [-27, 23, -9], [52, -20, 34], [4, -12, 40], [-4, 2, 18], [20, -44, 36], [4, -14, 3], [-52, 0, 0], [-28, -13, 0], [-2, -22, 18], [34, -6, 30], [15, 9, -9], [-20, 48, -32], [-4, 26, -25], [-2, 12, -36], [15, -27, 25], [20, 12, 24], [-50, 16, -48], [0, -12, -28], [22, -36, -6], [31, -23, 45], [-8, -38, 21], [-24, 12, -47], [10, -24, 12], [-34, 18, -44], [-14, 33, -18], [31, 9, 21], [0, -12, 13], [-6, 11, -2], [36, -2, -30], [-16, 16, -36], [36, -10, 40], [8, 28, -22], [28, -12, 10], [22, -44, 16], [35, -39, 13], [14, -8, -42], [-53, 17, -41], [16, -52, 32], [26, 6, 4], [-28, 13, -32], [52, -32, 45], [27, -7, 53], [16, -21, -24], [-56, 0, 2], [0, -10, -20], [16, 7, -4], [8, 32, -5], [-5, 53, -27], [16, -6, 31], [4, 60, -26], [-20, 46, -10], [38, -16, -4], [8, 30, 8], [4, -28, 38], [20, 4, 4], [28, -50, -9], [-48, 30, -59], [-48, 4, 4], [12, -43, 24], [0, 36, -35], [-18, -16, 28], [24, -2, 54], [-36, -5, 4], [-12, 10, -2], [70, -20, 28], [30, -6, 16], [26, -53, 6], [4, -8, 44], [-44, 0, 0], [54, -8, 20], [-24, 36, -22], [-5, -27, 17], [19, 25, -21], [32, 28, -4], [-28, 36, 12], [-48, -8, 10], [-8, 5, 8], [-22, 50, -38], [6, 21, -22], [4, 7, -24], [-22, -10, 12], [-28, -36, 0], [-38, 16, -24], [-28, 34, 26], [-18, 27, -2], [-4, -22, 27], [-20, 17, 8], [-66, 16, -26], [8, 26, -26], [-3, -13, -7], [3, 17, -23], [-53, 5, 21], [48, 0, 0], [56, 4, -2], [-44, -10, 0], [22, 28, 2], [-20, 8, 32], [50, 14, -18], [-8, -7, 20], [32, -23, 16], [-24, 3, 20], [30, -64, 20], [16, -24, 37], [76, -18, 26], [-68, 24, -9], [-30, 39, 18], [-18, 48, -46], [-62, 10, -2], [14, -30, 48], [-42, 5, 14], [-2, 4, -40], [44, -56, 29], [10, 10, 56], [-1, -11, 37], [22, -55, 18], [-18, 14, -12], [40, -48, -7], [42, -46, 56], [-4, 0, -5], [-10, 17, 26], [26, -40, -18], [10, 10, 36], [-13, 17, -33], [46, -34, 6], [11, 5, 31], [-68, 6, -20], [6, -54, 20], [-22, -2, 10], [24, -27, -4], [-17, -31, 17], [-21, 25, 37], [45, -29, 45], [18, -2, -6], [38, -31, 38], [-20, 10, 29], [-31, 59, -15], [-18, -34, 10], [8, -22, -28], [64, -2, 10], [-44, 8, 25], [-30, 0, -28], [16, -12, -16], [30, 0, 4], [-10, 50, -14], [-16, 4, 12], [23, 5, 47], [-40, -18, 20], [19, 1, -31], [36, -13, -32], [-8, 6, 3], [52, -40, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8450_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8450_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_8450_2_a_bx(:prec:=3)
    chi := MakeCharacter_8450_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(2999) - 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_8450_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_8450_2_a_bx( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-13, -4, 3, 1]>,<7,R![-8, -4, 4, 1]>,<11,R![-13, -4, 3, 1]>,<17,R![-97, -22, 5, 1]>,<31,R![-104, 76, -16, 1]>],Snew);
    return Vf;
end function;