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