
// Make newform 9450.2.a.en in Magma, downloaded from the LMFDB on 24 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_en();".
// 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_en();".
// 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, 1], [1, -1], [-5, 0], [-4, 1], [-3, 1], [-1, 1], [1, -3], [6, 1], [4, -2], [7, 0], [2, 0], [3, 3], [7, 0], [-2, -2], [9, 2], [3, -3], [10, 0], [10, -1], [2, 2], [9, 2], [-2, 1], [2, -1], [5, -3], [-2, -1], [0, 1], [10, -1], [12, -2], [-1, -2], [2, -2], [-8, 3], [5, 5], [2, 5], [-5, 1], [1, 4], [12, -3], [4, -5], [-12, -2], [5, 3], [-20, 2], [1, -6], [12, 2], [-15, 3], [-3, 0], [12, 4], [-7, 2], [12, 2], [-6, -7], [0, 2], [-4, -1], [-16, 4], [-12, 0], [-1, -1], [-16, -2], [-13, -1], [0, 4], [12, -3], [6, 5], [6, 6], [8, 1], [12, 3], [4, 9], [10, 0], [15, 4], [-3, -2], [-18, 0], [5, -1], [1, -2], [-11, -1], [15, -5], [14, -5], [18, -4], [-20, -2], [28, -2], [12, -2], [2, -10], [6, 8], [3, -10], [-2, 0], [-6, 8], [12, -8], [-5, 5], [0, 3], [-4, -8], [1, 0], [10, 8], [-14, -1], [2, 4], [16, 4], [-2, -4], [-12, 0], [-22, -2], [-16, 1], [14, 1], [-7, 2], [44, 0], [12, 1], [6, -2], [-11, 5], [23, 6], [22, 1], [-3, 10], [28, 3], [-1, -14], [0, -6], [-21, -3], [20, -6], [-33, -1], [14, 11], [18, -2], [-18, -4], [16, -2], [-22, -3], [-2, 11], [6, 0], [-19, -7], [14, 5], [-6, 2], [11, 4], [-8, 0], [10, -3], [-8, 6], [-18, -4], [36, 3], [-36, -1], [1, -1], [-21, 5], [34, 0], [-3, -3], [6, 11], [20, -4], [-11, -4], [14, -5], [24, -6], [-22, -10], [-2, -6], [-8, -4], [14, 8], [23, 5], [-6, -3], [18, -2], [-10, -14], [-14, -3], [3, -1], [19, 2], [4, -11], [5, 1], [8, -6], [-3, 12], [31, 8], [-48, 0], [-4, -8], [-16, -8], [-2, -4], [36, 0], [26, 3], [-30, -4], [-24, -3], [4, 10], [12, -10], [3, -12], [-6, -12], [36, 2], [22, -12], [13, -1], [-3, 2], [-16, 10], [-6, 0], [21, 3], [-25, -9], [-1, -12], [-20, -12], [-9, 12], [17, 0], [-11, -13], [-16, -4], [5, 3], [12, 13], [-23, 0], [-4, 9], [27, 6], [-1, 3], [18, 6], [32, -1], [26, -3], [15, -10], [-34, 5], [-16, 10], [26, 2], [43, 0], [0, 6], [-8, -19], [41, 4], [13, 14], [-18, -6], [-11, -4], [8, -6], [25, -1], [-31, -5], [12, 6], [38, 2], [-23, -2], [-20, -1], [-21, 15], [-14, -15], [44, 2], [-42, -2], [-7, 0], [-2, -1], [-2, -2], [-21, 6], [-18, -14], [-12, -8], [22, 1], [32, 8], [-17, 7], [19, 3], [38, 7], [24, 16], [30, -9], [-8, -11], [28, 8], [-6, 15], [-31, -4], [-44, 0], [47, 9], [16, 7], [-60, -4], [-40, -10], [26, -3], [-30, -3], [0, 16], [44, 2], [8, 7], [13, 7], [12, -9], [6, -9], [-24, -9], [-30, -4], [-35, -3], [-4, 23], [23, -10], [42, 0], [-53, 5], [-30, 6], [-5, -20], [35, -1], [-16, -11], [25, -2], [21, 17], [-60, 1], [-2, -14], [-50, 2], [-72, 1], [18, 11], [-8, 7], [-18, -7], [22, -13], [38, 5], [-44, 6], [42, -4], [11, 4], [24, -10], [-30, 0], [20, 6], [-31, 8], [54, 0], [21, 11], [-2, -20], [-28, -6], [48, -2], [32, -7], [-23, -5], [28, -5], [-66, 2], [80, 0], [-57, 6], [6, -3], [-66, -4], [12, 2], [15, 1], [-6, -1], [-20, 10], [-4, 10], [-29, 1], [11, 9], [19, 16], [34, 4], [27, -6], [-72, 0], [-37, 10], [-2, 21], [70, 2], [-16, -14], [2, -17], [1, -8], [32, -11], [-18, -4], [-41, -7], [-14, 22], [18, -6], [27, 8], [27, -8], [0, 2], [-1, 3], [-16, -10], [-44, 11], [32, 1], [51, -3], [-18, 0], [-15, -18], [11, -13], [8, -12], [41, 8], [0, 16], [-12, -20], [36, 0], [0, 11], [-34, 12], [-16, -23], [-26, -15], [-4, -2], [-70, -3], [-1, -26], [-32, -13], [-43, -7], [18, 16], [28, 6], [44, -10], [-6, 8], [-50, -2], [11, -8], [7, 26], [50, -7], [-35, 14], [4, -3], [-56, 0], [-38, 11], [60, -7], [28, -2], [6, -7], [-1, -1], [-44, -1], [-53, 5], [7, 10], [32, -10], [-8, -1], [-50, 1], [-77, 2], [41, -11], [33, 15], [56, -3], [-58, -8], [52, 5], [-42, 0], [-70, -4], [80, -4], [8, -16], [15, 6], [-67, 7], [6, -4], [28, -1], [8, 14], [8, 13], [32, -2], [-27, 12], [-40, 5], [-40, 6], [17, 11], [63, -3], [-49, -11], [-26, -16], [-15, -10], [-13, 5], [12, 0], [-8, 8], [-34, 0], [-30, -6], [-48, 14], [-32, 19], [-68, 1], [34, 11], [6, 3], [-22, -8], [21, 17], [-1, -8], [32, 5], [-19, -6], [-12, 15], [-14, 14], [26, -12], [53, -7], [5, 2], [-45, 11], [39, 16], [29, 6], [29, -5], [-49, -7], [-12, -8], [58, -8], [3, -12], [36, -9], [-52, 0], [-12, 15], [6, -15], [-66, 11], [-57, 6], [46, 4], [51, 3], [34, 17], [41, 2], [-35, 12], [22, 1], [49, 13], [-16, -2], [23, -4], [6, -24], [27, 15], [51, -13], [-24, -14], [-49, 10], [-62, -5], [48, 3], [12, 20], [44, -4], [-30, -12], [-4, -3], [-40, -15], [42, 1], [27, 14], [18, -12], [-41, -13], [42, 0], [-21, -22], [12, -7], [65, -6], [57, 5], [28, -24], [12, 21], [2, -6], [-31, 13], [2, 28], [-4, -16], [-10, 11], [-20, 5], [-78, 10], [-25, -11], [-60, 8], [64, -3], [-38, 14], [21, 12], [67, 0], [-1, 27], [36, -10], [21, -18], [-11, -5], [-18, 6], [5, 14], [70, -3], [42, -16], [-70, 1], [-4, -17], [21, 18], [-34, -12], [34, 8], [18, 9], [40, -15], [26, -17], [22, 7], [10, -2], [0, 26], [-30, -21], [36, 6], [6, 4], [-64, -6], [-58, -8], [-39, -21], [0, 13], [-31, -24], [8, 3], [-14, -16], [64, -14], [36, -3], [20, -17], [-94, -4], [8, 8], [-62, 1], [-29, 1], [30, -9], [-17, 6], [20, -12], [-22, -23], [25, 9], [-72, 2], [5, 19], [21, 7], [-30, 20], [93, -3], [43, -1], [48, 3], [10, -22], [-22, 26], [-24, 6], [-80, 2], [8, -2], [42, -16], [44, 9], [-47, 14], [84, -6], [-12, 10], [-83, 9], [12, 24], [7, 8], [-8, 23], [47, -11], [-23, -13], [-61, 3], [38, 9], [-5, -18], [34, -16], [-9, -3], [24, 4], [7, 16], [116, -2], [18, -24], [42, 4], [40, -4], [32, -16], [-50, -2], [42, -5], [4, 13], [65, 11], [-62, -4], [-4, 18], [-38, 8], [-37, -20], [-61, 0], [-30, -8], [-53, 1], [-12, 10], [-37, 2], [-16, -7], [50, -16], [12, -13], [71, -4], [90, 8], [-68, -8], [80, 3], [22, 7], [50, -7], [-18, -18], [-50, -10], [17, 15], [-14, 16], [-23, -2], [-70, 11], [7, 2], [120, 0], [-98, -1], [7, 14], [51, -13], [-22, 6], [48, -14], [-81, 9], [-4, -10], [2, 9], [-76, -14], [-13, 0], [66, -7], [18, -12], [62, 13], [13, -24], [-20, 22], [49, 20], [-38, 1], [93, -3], [-7, -9], [-103, 4], [22, -26], [59, 19], [-82, 6], [-9, 13], [31, -13], [26, 16], [5, -6], [-48, -6], [48, 7]];
    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_en();".
// 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_en(: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_en();".
// 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_en( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-6, 4, 1]>,<13,R![-9, -2, 1]>,<17,R![5, 1]>,<19,R![6, 8, 1]>],Snew);
    return Vf;
end function;