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