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