
// Make newform 8450.2.a.be in Magma, downloaded from the LMFDB on 19 April 2024.
// 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_be();".
// 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_be();".
// 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 := [-5, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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)
    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+1)]];
    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], [0, 0], [1, -1], [1, 1], [0, 0], [-2, 1], [-5, 0], [1, -2], [-1, -1], [-4, -2], [2, -3], [-1, -4], [-3, 5], [-2, 1], [1, -2], [-1, 2], [-3, -2], [11, 0], [-2, -2], [4, -4], [1, 5], [5, -4], [-9, 3], [-12, 1], [-3, -6], [-3, 2], [16, -2], [-13, 4], [9, -3], [-8, -3], [-15, 0], [4, 4], [16, 2], [-10, 5], [-2, 3], [6, -4], [-13, 3], [-7, 2], [-6, 9], [6, 0], [-1, 3], [15, -6], [4, 5], [4, -5], [11, -9], [5, 0], [-7, 6], [11, 2], [4, 3], [15, 0], [7, 4], [7, 0], [-12, -3], [5, -10], [-4, 5], [7, -8], [0, -4], [16, -3], [-5, 7], [-7, 7], [15, -3], [-2, -4], [-9, -3], [13, -3], [7, 7], [2, -5], [-17, 6], [-23, -2], [-13, -5], [-27, 3], [31, 1], [-8, -6], [2, 4], [-17, 0], [-15, 6], [16, -8], [-9, 1], [12, 3], [-11, 12], [-23, 7], [-15, 5], [4, 1], [-25, -2], [-12, -2], [-16, 5], [-24, -3], [-1, 3], [-32, 1], [4, 5], [0, 3], [-5, -5], [-4, 9], [7, 10], [7, -6], [16, 10], [2, -10], [14, 8], [-14, 0], [0, -10], [-19, -8], [36, -6], [16, -11], [15, -3], [2, -3], [-19, 6], [-14, 13], [-4, 2], [-9, 6], [-1, -6], [-5, 0], [4, 2], [19, 4], [-34, 1], [-2, -3], [-1, -1], [-19, 6], [-32, -5], [37, -2], [-12, 12], [-6, 5], [-4, 10], [21, -6], [-1, -10], [-20, 6], [30, -9], [8, 1], [-8, 7], [-12, -4], [11, 3], [-26, -3], [-42, 0], [-31, 12], [31, 6], [-17, 10], [-20, -6], [-8, 16], [24, 7], [-5, -14], [-6, 0], [-12, 11], [17, -10], [-38, 6], [-23, -8], [-8, -13], [-25, 11], [-7, -9], [13, 4], [-15, 13], [-17, -2], [35, -6], [-19, 5], [6, 5], [-40, -4], [1, -12], [23, 8], [-28, -6], [6, 6], [-41, 3], [39, 3], [-34, -1], [3, -12], [-10, 6], [-15, 12], [-5, -2], [-38, 7], [26, 0], [-20, 9], [-7, -8], [-21, 3], [-7, 11], [-2, -6], [-20, 19], [21, 10], [-4, 0], [40, 7], [5, -2], [-4, -7], [1, -12], [36, -5], [11, -9], [-11, 4], [5, -14], [-23, 10], [6, 0], [11, -4], [13, -6], [35, -12], [-30, 14], [6, 9], [2, -14], [1, -14], [-2, 2], [-21, 15], [-9, 27], [12, -6], [3, -25], [-12, 11], [34, 4], [32, -7], [-6, -12], [24, -17], [-27, 7], [28, -22], [-36, -6], [-27, 6], [-12, 11], [21, 6], [33, 12], [35, 0], [49, 0], [3, -6], [10, 12], [-9, 12], [56, -4], [-5, -18], [-25, -8], [14, -13], [-23, -8], [35, 2], [1, 8], [-22, 4], [-23, 19], [20, 9], [8, 5], [-16, 21], [22, 10], [-53, -2], [13, -6], [-5, 4], [33, -10], [14, 6], [22, -12], [-46, 14], [-3, -13], [13, -23], [-6, -10], [53, -7], [-12, -12], [19, 4], [-25, -16], [-25, -18], [4, 0], [-35, -9], [-8, 4], [-26, 10], [40, 8], [-8, -17], [6, -10], [-61, 5], [-37, 15], [40, 10], [19, -2], [-22, 30], [41, -10], [16, -11], [-61, 9], [-7, 0], [13, 16], [-7, 6], [1, 3], [-1, -4], [-22, 25], [5, -17], [-33, 6], [-31, 18], [5, 20], [30, -15], [-28, 12], [-29, 22], [-20, -22], [-11, 8], [-19, 24], [44, 3], [-13, -5], [44, -18], [-18, 30], [4, -24], [42, -10], [-25, -1], [51, -12], [10, 27], [41, -13], [13, -30], [-58, 6], [17, 5], [58, 0], [-28, 5], [14, 7], [-22, 8], [-41, 13], [-4, -4], [-43, -4], [25, -2], [-10, -2], [14, -19], [-31, -12], [42, 0], [20, 14], [-14, 5], [-9, -19], [70, 1], [20, 0], [5, 14], [-15, 10], [-30, 13], [31, -26], [-1, 12], [-17, 1], [13, -9], [-50, 13], [15, -24], [53, 11], [39, -4], [55, -14], [4, 29], [7, 7], [31, -2], [-27, 4], [-46, -7], [-33, -5], [-40, -12], [31, 19], [19, 2], [19, -23], [28, -7], [27, 17], [29, 0], [-8, -20], [-25, -4], [-2, 18], [7, 19], [-31, 3], [-19, -4], [-57, 8], [23, 17], [-18, 8], [-55, -7], [4, 27], [55, -15], [-19, 21], [68, 5], [-7, -31], [-18, -8], [29, 8], [-24, 12], [-57, 22], [2, -24], [17, -4], [-32, -20], [-42, -7], [8, -6], [28, -8], [20, -11], [-1, -15], [14, -4], [5, -10], [25, -2], [-72, 6], [-3, 12], [-55, 6], [-24, 24], [-43, 20], [50, -19], [2, -5], [-10, -17], [-30, 12], [19, -25], [-13, 0], [22, -20], [18, 7], [79, -5], [81, -6], [50, -15], [40, -15], [-16, -16], [-6, -12], [-4, -12], [-45, 6], [86, -5], [11, -22], [71, 8], [-7, 18], [-2, -14], [9, -13], [-24, 24], [-41, 21], [-40, -20], [54, 10], [-30, 12], [37, 0], [-34, 32], [9, -30], [-47, -9], [23, -34], [24, -10], [-41, 0], [-40, 14], [-67, 9], [0, 24], [28, -18], [-41, -8], [-33, 4], [-5, -17], [16, -2], [-58, 12], [19, -34], [-57, 12], [-10, 12], [-7, 14], [45, 11], [8, 2], [-1, -25], [74, -6], [3, -4], [62, 14], [-31, -4], [-55, 1], [-10, 20], [36, 6], [36, -12], [-51, 13], [-33, 12], [30, -21], [59, 0], [38, -31], [25, -11], [39, -18], [-22, -20], [-27, 12]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_8450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_8450_2_a_be();".
// 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_be(:prec:=2)
    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_be();".
// 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_be( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_8450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![-5, -1, 1]>,<7,R![-5, -1, 1]>,<11,R![-3, -3, 1]>,<17,R![-3, 3, 1]>,<31,R![4, 10, 1]>],Snew);
    return Vf;
end function;