
// Make newform 8450.2.a.w 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_w();".
// 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_w();".
// 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], [1], [3], [0], [6], [5], [0], [0], [-4], [-11], [6], [-2], [3], [9], [0], [8], [16], [6], [-14], [-16], [6], [9], [10], [-6], [-5], [12], [2], [12], [1], [-9], [-6], [-19], [-18], [-16], [-17], [-2], [15], [-15], [-24], [8], [0], [4], [27], [-10], [23], [19], [24], [-4], [24], [0], [23], [-15], [-12], [-9], [6], [20], [1], [-6], [-14], [-9], [-2], [30], [-14], [-15], [20], [16], [-6], [2], [-6], [-6], [-32], [-14], [-19], [0], [-30], [13], [-15], [5], [-36], [-10], [30], [16], [20], [18], [9], [4], [-42], [-8], [12], [-30], [19], [27], [-4], [-9], [6], [-27], [-14], [20], [34], [-21], [36], [9], [17], [-32], [6], [-24], [-18], [-19], [13], [13], [-18], [-1], [-28], [-9], [-2], [9], [27], [12], [-4], [-20], [18], [6], [-13], [6], [-10], [0], [-29], [25], [-7], [-12], [-40], [-23], [-3], [-34], [-39], [22], [-42], [-18], [-49], [36], [43], [-36], [-40], [-24], [46], [12], [-31], [-36], [10], [-15], [52], [27], [-8], [0], [-34], [42], [-50], [0], [-48], [-24], [-5], [33], [0], [-39], [-22], [-41], [47], [-54], [-24], [14], [0], [-26], [-34], [21], [-28], [-6], [-20], [38], [-32], [-39], [-23], [0], [27], [-24], [7], [4], [5], [24], [16], [12], [47], [-24], [66], [36], [-22], [19], [36], [48], [-54], [-28], [22], [-7], [-15], [18], [56], [-24], [45], [-25], [-2], [-48], [-23], [-42], [-6], [35], [4], [-27], [-9], [3], [50], [50], [51], [-8], [0], [-4], [36], [24], [-8], [-27], [-41], [35], [-58], [-3], [-44], [27], [-22], [-54], [-57], [60], [-66], [-28], [1], [74], [-48], [-18], [16], [39], [35], [21], [34], [3], [75], [14], [-15], [57], [68], [46], [-75], [-20], [-29], [-6], [44], [34], [18], [32], [66], [51], [-50], [6], [-40], [58], [10], [74], [4], [4], [-30], [-28], [-22], [60], [-81], [-4], [72], [-28], [16], [24], [70], [-57], [-34], [39], [18], [42], [24], [-69], [46], [-66], [56], [-9], [-12], [-38], [76], [42], [-52], [-12], [-76], [-50], [0], [-64], [-18], [7], [9], [36], [21], [76], [15], [65], [-36], [-54], [16], [6], [8], [22], [66], [16], [-72], [50], [-76], [64], [51], [54], [50], [87], [26], [-66], [-4], [-90], [-34], [42], [-31], [1], [7], [-12], [12], [26], [-27], [-15], [-40], [46], [72], [27], [-85], [-38], [-66], [-17], [2], [-6], [42], [45], [24], [9], [-65], [-21], [0], [-27], [94], [64], [54], [-5], [-82], [-72], [-7], [0], [90], [32], [-14], [-3], [-30], [10], [81], [-26], [12], [96], [-65], [-12], [23], [-75], [-10], [10], [88], [72], [35], [27], [-27], [-14], [6], [-14], [26], [90], [-76], [24], [2], [6], [-8], [60], [0], [8], [-62], [93], [4], [75], [-56], [-27], [-42], [-49], [-32], [102], [30], [1], [54], [-72], [30], [-77], [-63], [87], [28], [3], [-42], [-57], [-7], [78]];
    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_w();".
// 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_w(: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_w();".
// 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_w( : 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![-1, 1]>,<11,R![-3, 1]>,<17,R![-6, 1]>,<31,R![4, 1]>],Snew);
    return Vf;
end function;