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