
// Make newform 8450.2.a.x in Magma, downloaded from the LMFDB on 04 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_x();".
// 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_x();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [2], [0], [5], [3], [0], [-3], [4], [-6], [9], [-5], [2], [0], [-2], [-9], [9], [9], [-1], [5], [0], [14], [-16], [-15], [6], [8], [-3], [16], [-6], [-2], [6], [-20], [-6], [6], [-10], [0], [7], [-17], [-16], [-24], [3], [0], [11], [12], [20], [-24], [-16], [14], [-4], [-9], [16], [-6], [15], [-8], [-24], [15], [-18], [9], [19], [22], [-12], [-14], [0], [20], [-18], [19], [0], [-20], [13], [-30], [-20], [-6], [21], [10], [-29], [-29], [36], [18], [-22], [-12], [22], [6], [4], [-36], [-2], [20], [-6], [-6], [26], [0], [-1], [-30], [15], [-7], [6], [25], [-24], [36], [18], [40], [16], [-2], [-36], [0], [-27], [-28], [-4], [15], [-6], [30], [5], [22], [32], [18], [4], [-20], [3], [-4], [6], [-33], [0], [-2], [25], [-6], [-15], [1], [-33], [40], [-30], [-20], [14], [-11], [-33], [-22], [-23], [-12], [40], [12], [-49], [-3], [-42], [13], [-36], [4], [9], [5], [0], [-10], [54], [2], [-45], [-10], [9], [-20], [-24], [-44], [24], [8], [-42], [13], [42], [-3], [27], [-31], [-18], [6], [21], [14], [1], [10], [-21], [60], [16], [0], [-28], [14], [51], [-35], [-6], [-38], [29], [8], [0], [22], [0], [-21], [18], [61], [-1], [-14], [-9], [-26], [-3], [44], [-6], [0], [-33], [-2], [-59], [6], [24], [-54], [50], [-16], [29], [-9], [-66], [-11], [24], [0], [14], [43], [42], [-26], [-21], [-51], [-26], [40], [3], [-15], [6], [38], [-32], [-24], [-25], [-60], [-19], [-54], [-36], [10], [57], [22], [2], [43], [-66], [-14], [-48], [34], [-24], [-42], [42], [60], [-52], [28], [70], [42], [24], [-28], [60], [-17], [-6], [68], [0], [-48], [-1], [18], [33], [-58], [-19], [-15], [38], [-20], [6], [28], [-26], [72], [26], [-12], [36], [77], [3], [-34], [23], [-64], [68], [67], [41], [60], [4], [58], [-12], [84], [40], [-78], [28], [-31], [30], [-11], [-18], [-11], [57], [-9], [24], [66], [-69], [19], [87], [-34], [-54], [42], [-7], [-29], [78], [-82], [36], [20], [32], [84], [26], [-60], [-11], [-48], [60], [21], [-68], [21], [74], [51], [-48], [-52], [-45], [86], [32], [-78], [29], [-30], [-49], [67], [59], [-60], [15], [-44], [-18], [-82], [-9], [-5], [9], [-38], [-24], [-38], [88], [56], [-90], [0], [80], [-24], [6], [5], [5], [-45], [57], [-41], [-52], [18], [-26], [14], [51], [33], [3], [-81], [-75], [-70], [30], [60], [-36], [-32], [-86], [-78], [-31], [11], [48], [56], [-24], [-21], [14], [13], [-87], [-72], [-34], [51], [-14], [-48], [-48], [47], [-24], [-20], [0], [-41], [-53], [44], [54], [94], [-18], [81], [28], [-15], [-95], [-29], [51], [-70], [54], [-14], [-27], [-1], [0], [30], [56], [86], [72], [-67], [12], [-29], [-99], [72], [-64], [-50], [-57], [24], [4], [-42], [-90], [33], [-22], [9], [-12], [-34], [66], [18], [-30], [7], [96]];
    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_x();".
// 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_x(:prec:=1)
    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_x();".
// 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_x( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-2, 1]>,<7,R![-5, 1]>,<11,R![-3, 1]>,<17,R![3, 1]>,<31,R![5, 1]>],Snew);
    return Vf;
end function;