
// Make newform 8450.2.a.bu in Magma, downloaded from the LMFDB on 16 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_bu();".
// 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_bu();".
// 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, -3, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, -1, 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)
    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], [0, 0, 1], [0, 0, 0], [2, -1, -1], [2, -3, 0], [0, 0, 0], [-1, -1, 0], [-5, 2, 1], [1, -3, 1], [-4, -2, 2], [1, 3, 4], [1, 2, 3], [1, -1, 3], [-2, 0, 0], [2, 1, 1], [-2, -3, -2], [4, -4, -2], [0, 4, -3], [4, 0, -2], [-6, -2, 4], [3, -3, -6], [-3, -5, -4], [2, -2, 5], [2, 1, -1], [9, -1, 2], [-2, 4, -1], [9, 4, 0], [0, 0, -1], [2, -6, 0], [14, 0, 0], [-3, 6, 4], [-5, -4, -7], [5, 3, -4], [-1, -2, 5], [-6, 0, -6], [9, -7, -6], [-4, 5, -2], [0, 8, -1], [9, -12, -2], [-13, 0, 5], [-2, 2, -2], [4, 0, -3], [3, -5, -6], [14, 0, 0], [0, 5, -4], [2, 8, 4], [2, -3, -2], [22, 1, 1], [-6, 14, 8], [16, -8, -1], [19, 1, 2], [1, 11, 0], [-10, 3, 1], [3, 6, 1], [6, -4, 4], [-12, -5, -11], [-10, 8, 5], [4, 8, -6], [9, 6, 5], [-9, 13, 7], [-4, -6, -2], [6, -9, -8], [2, -4, 6], [7, 3, 8], [-4, -14, 4], [3, -4, 7], [-4, 4, -10], [1, -5, 0], [12, 4, 9], [2, -8, -5], [19, -3, 4], [-8, -2, -2], [-2, -10, 4], [4, 6, 8], [-6, 7, -2], [7, 11, -11], [0, 4, 9], [-10, 1, 6], [14, 5, 9], [0, -5, 1], [5, 15, 1], [2, -10, -13], [-11, -1, -14], [8, -10, -4], [13, -7, -14], [-6, 10, -12], [-10, 5, -7], [29, -7, -4], [-20, -4, -3], [-13, 7, 9], [18, -6, -2], [11, 3, 0], [7, -18, -12], [-4, 3, 8], [9, 3, -11], [5, -8, -8], [-28, 2, 0], [-11, -8, 8], [-6, -6, -8], [14, -18, -15], [-22, -8, -8], [4, 5, 14], [-10, 4, 2], [-1, 10, 12], [12, -3, -6], [29, -15, -8], [-4, 8, -4], [-8, -2, -2], [22, 2, 6], [-13, 18, -2], [-5, 0, -10], [5, 14, -9], [22, -14, 2], [-18, -3, 0], [-2, 0, -2], [10, -5, -3], [2, 8, -1], [-4, 5, 9], [-6, -5, 4], [15, 1, 3], [24, -14, 1], [-22, 26, 12], [-14, 16, 14], [-4, 16, 20], [-3, -6, -15], [20, -16, 1], [-8, -16, -7], [22, -16, 0], [4, 7, -11], [17, 2, 19], [11, -6, 9], [-9, 11, 11], [20, 8, -2], [11, 16, -9], [15, 10, -2], [5, -1, 1], [16, -9, -14], [-4, -4, 13], [-29, 3, -9], [-11, 3, -1], [11, 16, 3], [-44, 10, 3], [9, 4, 4], [14, -22, -11], [-8, -10, 8], [3, -11, -4], [-1, 11, -17], [-19, 15, 8], [4, 1, 14], [1, 5, 15], [-12, 14, 6], [5, -4, -8], [-16, -2, -11], [30, -19, -11], [-30, 8, -7], [2, -4, 4], [26, -16, 2], [30, 16, -10], [8, -4, -2], [0, 18, 6], [-26, 10, -1], [-13, -1, -20], [17, 4, 8], [-32, 21, 4], [-8, -10, 4], [24, -3, 1], [16, -4, 8], [8, -15, -8], [-3, 10, -8], [19, -9, -1], [18, -10, -8], [4, -18, -8], [13, 1, -8], [-16, 28, 12], [-8, 14, 18], [-3, -12, -16], [-4, -4, 12], [2, -4, 19], [9, -23, -11], [6, -6, -8], [5, 17, -1], [-22, 7, 16], [9, 6, 23], [-14, 8, -2], [-1, 6, -24], [-28, 24, 17], [-6, -21, 18], [20, -18, -12], [20, 7, 25], [31, 7, 2], [-23, 5, 0], [-22, -10, -4], [-23, 18, -9], [18, 10, 27], [-24, 32, 20], [-31, -13, -4], [-14, -8, 10], [5, 8, 3], [18, 0, -10], [-8, -8, -12], [-20, 0, 12], [15, -1, 20], [6, -4, -6], [30, -7, -17], [-6, -1, -6], [10, -28, 0], [16, 4, 12], [-12, 14, 12], [-36, 11, -3], [8, -5, 18], [-1, -15, -22], [-26, -2, -29], [4, 17, 7], [38, 0, 10], [-4, -8, -6], [-22, 15, 5], [-27, 25, 5], [-29, -10, 10], [-20, -9, -1], [5, 4, 5], [-10, -6, 23], [-8, -6, -24], [-17, 12, -20], [-13, -13, -11], [14, 6, -25], [-14, 12, -8], [27, 7, -10], [-11, 31, 12], [25, -23, -17], [-5, -2, -7], [13, -12, -25], [7, 16, 5], [3, 25, 8], [-12, -5, -25], [20, 6, -8], [-18, -19, 15], [-15, 7, -15], [-8, 10, 26], [42, 1, -6], [15, -17, -14], [-50, 2, 2], [-48, 12, 6], [-24, -15, -15], [40, 10, 6], [-19, -27, 14], [-15, -19, 14], [-11, 13, -15], [25, 2, -19], [-50, 5, -4], [-5, 8, -12], [-8, -18, 20], [-5, -24, -2], [11, -22, -12], [-25, -11, -1], [-23, 6, 21], [44, 1, 2], [-20, -14, -35], [42, 2, 0], [-9, 16, -7], [3, 9, 16], [-34, 25, -5], [-18, 4, -11], [-22, 14, -2], [35, -5, -17], [-28, -14, 2], [31, -3, -5], [-12, -4, -4], [7, -4, 0], [-42, 6, -13], [0, 10, 8], [-12, 20, 15], [28, 14, -7], [21, 1, -16], [13, -25, 6], [-26, -14, -16], [-9, 19, -23], [-8, 6, -2], [10, 0, 15], [-19, 19, -5], [-6, 10, 20], [45, 4, -14], [-6, -24, 14], [-1, 23, -19], [50, 0, -12], [26, 20, 3], [31, 5, 14], [-2, 4, -22], [-35, 32, 19], [20, 18, -10], [25, -18, -10], [-30, 0, -7], [-12, -24, 3], [-28, -4, -28], [3, -24, -11], [-38, 24, 2], [44, -2, 8], [1, 11, 32], [32, -3, 20], [35, -27, -25], [32, 0, 11], [44, -2, 0], [-67, 9, 9], [-16, 6, -28], [46, 0, -15], [18, 18, 2], [2, 8, -2], [-30, -16, -8], [-18, -22, -5], [-17, -9, 20], [-11, -28, -31], [-35, 18, 22], [12, -12, -3], [-56, 11, 13], [-2, -8, 4], [43, 2, -12], [-45, 26, 10], [12, -32, -20], [-28, 6, -26], [-13, -21, 2], [31, 1, -3], [-66, -6, -16], [1, -3, 14], [-24, 22, -3], [20, -12, -12], [1, -13, -14], [-27, 7, 13], [-18, 30, 6], [6, 16, -25], [34, -15, -19], [-2, 16, 32], [-24, -4, -25], [40, -7, -10], [23, -3, 12], [32, -32, -11], [30, -18, -18], [-20, 14, -23], [10, -28, 11], [1, 19, 20], [-5, -26, -2], [-9, -20, 16], [-24, 1, 2], [26, 18, -22], [34, 14, -17], [3, 33, 28], [17, 6, -7], [-19, 12, -1], [24, -44, -18], [-36, -16, -42], [-37, 3, 20], [3, -22, 5], [16, 23, -24], [-25, -25, -22], [-26, 8, -2], [41, 20, -10], [-44, 22, 3], [54, 2, -10], [47, -9, 0], [24, 17, 8], [-16, 6, -34], [9, 26, -12], [-7, 0, -13], [-6, 27, 5], [-29, 15, -17], [-49, 26, -5], [44, -50, -24], [24, -8, -22], [-9, -1, -9], [-27, -4, 2], [-25, -23, 19], [32, 4, 12], [-36, 13, 8], [-7, 21, -3], [-58, 4, -1], [0, 20, -30], [-48, 10, 22], [3, 22, 7], [-2, -16, -22], [18, -18, 0], [-35, -16, -14], [9, 29, -18], [18, -24, -25], [34, 26, -12], [55, -14, 12], [-34, -4, -40], [6, -11, -16], [-45, -16, -8], [-24, 10, -14], [0, 26, 38], [40, -2, 35], [15, 27, 13], [-26, 51, 9], [1, 32, -11], [20, 9, -34], [66, 0, -5], [37, -1, 38], [14, 16, 36], [26, 16, -22], [-61, 29, 7], [-9, -3, -5], [-28, 18, -5], [8, 20, 48], [-5, 31, 4], [-31, 21, 21], [6, 14, 50], [0, -2, -27], [27, -33, 4], [-2, -12, -18], [14, 33, -7], [4, -2, 41], [3, -32, -11], [-27, 9, -4], [-40, 31, -2], [0, 16, 27], [-60, 31, 20], [-71, 9, 0], [-4, 26, -2], [-2, 14, -10], [-11, 26, 18], [-6, -28, -30], [-13, 11, 7], [-30, -6, -12], [60, -19, -24], [-48, 5, -7], [10, -39, 4], [-8, 30, -12], [4, -11, -46], [-24, 20, 25], [-54, 11, 25], [-27, 24, -17], [38, -16, -20]];
    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_bu();".
// 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_bu(: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_bu();".
// 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_bu( : 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, -4, 0, 1]>,<7,R![5, 3, -5, 1]>,<11,R![31, -27, -3, 1]>,<17,R![-2, 2, 4, 1]>,<31,R![218, -58, -6, 1]>],Snew);
    return Vf;
end function;