
// Make newform 9450.2.a.em in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9450_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_9450_2_a_em();".
// 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_9450_2_a_em();".
// 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 := [-10, 0, 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_9450_a();"
function MakeCharacter_9450_a()
    N := 9450;
    order := 1;
    char_gens := [9101, 6427, 6751];
    v := [1, 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_9450_a_Hecke(Kf)
    return MakeCharacter_9450_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, 0], [-1, 0], [-2, 0], [-1, -1], [1, 2], [3, 0], [-2, 1], [-5, 1], [0, -2], [2, -3], [-4, 0], [0, -1], [-1, -3], [3, -1], [-6, 2], [-7, 1], [-6, 3], [4, 2], [-2, 2], [-5, -3], [0, 1], [-5, 0], [2, 3], [-6, -3], [0, 2], [2, 2], [6, 3], [-2, -4], [-5, 3], [-4, 3], [-12, 3], [6, 2], [-9, -3], [-5, -1], [-21, -1], [6, -2], [-12, 0], [16, -1], [-19, 2], [-13, 1], [0, 0], [21, -2], [3, -5], [-2, -7], [-6, 2], [-4, 1], [6, -5], [21, -1], [-6, -3], [-10, -5], [-14, -3], [10, -2], [-19, 0], [10, 2], [-10, -4], [4, -2], [-2, -2], [-12, 1], [9, 4], [2, 7], [6, -4], [-18, 0], [-2, -1], [-25, 1], [-18, 5], [-7, -2], [-23, 0], [5, -5], [24, 0], [-22, 0], [-2, -9], [-2, 2], [-8, 1], [20, 2], [17, 3], [3, 5], [-6, -1], [-2, 7], [-2, 7], [-18, 4], [-12, -6], [-24, -2], [18, 5], [3, -10], [-22, -1], [-1, 10], [2, 1], [11, 3], [4, 2], [1, 1], [8, 6], [11, 2], [8, -1], [30, 0], [10, 3], [25, 2], [21, 2], [-2, -5], [8, 8], [17, -5], [14, -9], [-24, 0], [14, 8], [28, 0], [22, -1], [7, -2], [2, -7], [-28, 2], [24, -1], [-4, 5], [-28, -3], [-10, 6], [-27, 1], [4, 2], [15, -4], [21, -7], [-31, 3], [-19, 4], [-10, 4], [16, 6], [-10, 2], [20, 0], [2, -8], [-10, -2], [0, 2], [5, -1], [22, 1], [-3, -7], [6, -4], [-14, -8], [8, -12], [-12, -13], [-3, -12], [16, 0], [36, 0], [-2, 6], [-12, 3], [6, 0], [10, 2], [15, 9], [26, -8], [21, 10], [-9, 13], [-15, -11], [12, 10], [7, 16], [24, 0], [-24, 5], [-4, 6], [29, -6], [36, 6], [-24, -2], [-4, -6], [-20, -8], [-2, 8], [11, -8], [10, -7], [-20, 11], [-46, 0], [10, -11], [13, 3], [-18, -9], [-12, -9], [11, 15], [49, 3], [-10, 6], [-12, -4], [20, 10], [22, 8], [-6, 4], [14, -7], [17, 2], [20, -3], [-11, 6], [-6, -4], [10, 10], [14, 6], [7, -3], [25, 5], [26, -4], [22, -4], [33, -2], [-12, 9], [24, -6], [-26, 9], [13, 8], [37, 0], [-9, -15], [0, -9], [-19, 4], [36, 8], [-28, -6], [11, 14], [5, 8], [15, -4], [4, -6], [-1, -16], [-1, -3], [37, -9], [-16, -3], [-35, -5], [-22, -1], [-26, -5], [40, 5], [0, 4], [-46, -4], [-42, -3], [-19, 6], [35, -4], [-26, 10], [39, -1], [28, 2], [32, 8], [-12, 10], [-2, 0], [-21, 12], [32, -8], [-20, -2], [20, 6], [-28, 3], [4, 10], [-17, -5], [-26, 11], [-48, 4], [-29, -12], [0, -5], [30, 5], [21, -14], [6, 20], [-19, -10], [-5, 9], [-20, -11], [33, -10], [-2, -8], [0, 2], [-65, -1], [54, -2], [-5, 21], [-25, 4], [35, -12], [14, -1], [42, -1], [3, -18], [-9, 15], [-18, 10], [-10, -4], [-20, 8], [-32, 8], [-44, 6], [9, 18], [24, -15], [20, 8], [48, -9], [-17, 6], [-28, -15], [10, -6], [14, 2], [-14, -11], [3, -21], [-25, -2], [27, -13], [-41, -7], [4, -2], [-21, 4], [51, -3], [41, 0], [6, -7], [-5, -11], [35, -1], [-6, -24], [8, 15], [-15, -9], [16, -1], [-26, 11], [-17, -4], [-16, 15], [10, 16], [-52, 10], [-12, -4], [17, -3], [3, 15], [-49, 5], [20, 0], [72, -3], [-15, -22], [-24, 6], [-66, -5], [-29, -8], [19, -17], [34, -4], [-76, -2], [18, -2], [26, -16], [30, -9], [4, 3], [-82, 1], [24, -9], [-38, 14], [-10, -10], [13, 17], [0, 14], [6, 24], [-66, 1], [-32, 16], [5, 6], [22, -8], [12, 12], [2, 15], [69, 3], [14, 8], [50, 10], [18, -2], [36, -9], [-34, -6], [82, -2], [-12, 3], [2, -19], [-6, 10], [-13, 16], [-39, 14], [10, -25], [-19, 5], [-12, -3], [-16, -3], [16, -22], [50, 2], [14, -8], [-3, 3], [-8, -25], [22, 10], [-40, 1], [-18, -9], [34, -4], [-4, -19], [34, 0], [-15, 0], [16, -15], [18, -17], [12, 17], [-58, 7], [-6, 0], [-9, -17], [2, -16], [11, 16], [-1, -1], [-42, -16], [33, 9], [68, -1], [-15, -14], [-83, -2], [9, -3], [-70, 6], [78, 0], [-39, 0], [9, 15], [14, 16], [-12, 6], [-10, -4], [-46, -9], [-51, -2], [34, -1], [-59, -6], [53, -8], [-29, -6], [-6, -4], [-16, -20], [-49, 10], [9, 18], [62, 4], [-76, 7], [21, -3], [-46, 6], [12, 5], [28, 2], [10, 16], [-68, 5], [61, -2], [-26, -20], [26, -20], [-22, -11], [-18, -24], [90, 3], [-25, -10], [57, -3], [25, -11], [-32, -10], [68, 6], [3, -1], [45, 10], [14, 25], [-1, -14], [17, 8], [-8, -21], [28, -6], [16, 12], [65, -8], [-30, -18], [-18, 6], [5, 17], [-72, 6], [-4, 10], [6, -24], [14, 4], [68, 10], [-84, 1], [-12, 21], [-42, -12], [12, -6], [28, -7], [-73, -1], [-81, -6], [24, 17], [1, 2], [6, -22], [10, 10], [-6, 6], [-62, 4], [77, -3], [12, -22], [38, -6], [-48, 9], [-62, -10], [-70, 8], [48, 5], [-30, -8], [12, 12], [13, -6], [49, 17], [-14, 15], [-12, -24], [-16, 17], [12, -12], [10, 0], [-69, 0], [-17, -4], [16, 0], [28, -8], [-46, -18], [30, 0], [-66, 12], [-26, -10], [-10, 12], [24, -14], [-52, -16], [12, 20], [-34, 16], [40, 3], [-14, 14], [22, 21], [5, -1], [69, 0], [38, 8], [-47, -16], [47, 5], [4, 29], [-6, -2], [-73, -7], [2, 27], [38, -17], [-5, -9], [-34, 2], [66, -3], [-5, 18], [-32, -4], [-82, -8], [-4, 26], [-20, 24], [-28, -4], [7, 29], [-51, -16], [29, 19], [5, 26], [-28, -20], [-6, 4], [42, -12], [70, 7], [43, 9], [30, 0], [-24, 16], [-1, -16], [-28, -3], [6, 12], [4, 24], [-22, 26], [46, 3], [-42, -12], [-45, 8], [40, 12], [-59, 11], [-41, 19], [19, -2], [0, -12], [12, -8], [31, 17], [2, 26], [9, -3], [54, 5], [-8, -19], [-38, 8], [-6, 19], [4, 26], [0, 10], [-72, -6], [32, -2], [12, -14], [24, 20], [0, 7], [25, -24], [-54, 9], [-21, -13], [8, -3], [-35, -23], [64, -14], [-17, 20], [-84, -9], [-34, 6], [-96, 2], [72, -7], [-20, 9], [-8, -17], [4, -25], [48, 6], [36, 26], [-68, 6], [-16, 7], [-76, -14], [-31, -4], [-28, -11], [28, 22], [34, 26], [32, -22], [5, -8], [-27, 13], [-64, 10], [31, 11], [-65, 4], [-16, 10], [-16, -4], [63, -1], [17, -13], [-72, 5], [-6, 0], [-20, 17], [44, 11], [27, -5], [-44, -7], [42, 0], [26, 11], [16, 8], [-70, 6], [59, -5], [21, -25], [-57, -18], [-33, 5], [-28, -20], [-11, 22], [59, -12], [-13, -8], [-23, -2], [-55, -19], [-46, -9], [59, -15], [38, 26], [-13, 19], [28, -4], [-36, 25], [-48, -12], [-11, -6], [-49, 8], [-92, 5], [20, -16], [28, 10], [-28, -24], [-77, -14], [-4, -16], [81, -2], [-5, -25], [82, 0], [43, 8], [38, -11], [90, 4], [24, -24], [-14, -26], [14, 20], [-50, -10], [14, 17], [15, -20], [-68, 10]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9450_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9450_2_a_em();".
// 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_9450_2_a_em(:prec:=2)
    chi := MakeCharacter_9450_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(4297) - 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_9450_2_a_em();".
// 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_9450_2_a_em( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![2, 1]>,<13,R![-9, 2, 1]>,<17,R![-39, -2, 1]>,<19,R![-3, 1]>],Snew);
    return Vf;
end function;