
// Make newform 9450.2.a.ea 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_ea();".
// 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_ea();".
// 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 := [-6, 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], [0, 1], [-1, 1], [-1, 0], [-2, -1], [1, -1], [5, -1], [1, -1], [-4, 3], [0, 2], [1, -2], [-2, -4], [3, 1], [5, -2], [6, 2], [-5, 0], [-3, -1], [-2, -4], [-4, -1], [6, 2], [11, 0], [-12, 1], [0, 5], [-13, -1], [4, -3], [2, -7], [4, 1], [-4, -2], [-7, -4], [-10, 2], [10, 5], [3, -1], [0, 5], [-3, -1], [-9, 2], [-6, 1], [-6, 7], [4, -2], [5, 1], [-8, -6], [-17, 4], [8, 2], [-3, 5], [-15, 0], [-4, 0], [-3, 6], [-8, 2], [-4, 7], [-4, 10], [18, -3], [8, 8], [12, 0], [3, -11], [8, -2], [3, -3], [-16, 4], [-6, -3], [-20, 1], [-6, -10], [22, 1], [-6, -3], [-2, -11], [14, -4], [-13, 0], [-13, -4], [-6, 8], [-3, -7], [9, -10], [19, 1], [-7, 9], [-20, -3], [10, 0], [-12, 2], [-24, -2], [8, 6], [6, -6], [10, -8], [-19, -8], [10, 4], [2, -4], [-4, -8], [-1, 3], [-30, 1], [32, 0], [-5, 2], [10, 0], [-16, 5], [-22, 4], [-36, 0], [-10, -12], [-24, 8], [-2, 2], [14, -3], [-4, 7], [3, 0], [-16, 8], [-22, 5], [14, -6], [-11, -9], [-5, 6], [0, 13], [5, -10], [22, -1], [11, 10], [-12, -2], [-3, -1], [-28, 6], [1, 9], [36, 5], [34, 2], [34, 4], [0, 2], [-8, 1], [-28, 7], [6, -8], [-3, -5], [-36, 5], [10, 10], [-23, -10], [-4, -4], [8, -1], [16, -14], [-10, -12], [6, 7], [2, -7], [11, -3], [-35, -1], [34, 4], [33, 3], [-44, -1], [24, 8], [-5, -10], [16, -15], [24, 6], [-18, -14], [-22, 10], [16, -4], [-6, -16], [-51, -1], [-24, -13], [-2, -14], [-2, -2], [-40, -1], [1, 5], [-5, 2], [-6, 11], [-7, 3], [-28, 6], [-21, 14], [-7, 2], [0, 0], [28, -4], [-16, 4], [2, -8], [-12, -8], [8, 11], [-10, -8], [-6, -9], [12, 14], [-20, -2], [-15, 10], [-6, -12], [20, 6], [-2, 12], [-13, -15], [1, 14], [-4, 2], [-54, -4], [-3, 5], [-11, 9], [5, 14], [4, -12], [-15, -2], [-19, -12], [7, 17], [-24, 0], [5, 5], [14, -17], [-61, -2], [2, -21], [-45, -2], [-5, -3], [-6, -18], [-6, -19], [8, 17], [-29, -6], [-12, -1], [28, 2], [30, 6], [-65, 0], [-36, 2], [10, 15], [5, -16], [41, 2], [18, 6], [1, -8], [-32, -2], [19, 9], [-11, -11], [0, 22], [54, 6], [-9, -4], [34, 11], [3, -11], [32, 3], [-36, -6], [2, 18], [-13, -2], [28, -3], [30, 6], [-9, 10], [-14, 6], [32, 8], [0, 19], [-24, 12], [3, 9], [35, -3], [-32, 11], [-16, 8], [0, 3], [54, -5], [4, 0], [-48, -1], [-27, -12], [-4, 12], [5, 15], [-6, -13], [16, -16], [-12, 10], [20, 17], [24, 1], [20, -16], [24, 10], [-14, 5], [-15, -19], [6, -5], [36, -15], [6, -3], [10, 20], [19, 3], [-6, -9], [-57, -2], [-30, 16], [-7, 27], [-6, -6], [-33, 8], [-9, 5], [10, 11], [51, -4], [-55, 3], [-22, 3], [54, 6], [-26, 14], [2, 25], [16, -9], [18, -1], [28, -15], [44, -15], [0, 23], [40, -10], [10, -8], [23, 4], [16, 10], [42, 12], [-8, -18], [-9, 26], [-54, 8], [61, 1], [-30, -8], [56, -6], [-28, -10], [6, -19], [27, -3], [-42, 9], [10, 18], [-40, 0], [-15, 4], [12, 25], [34, -16], [56, -6], [-25, 11], [16, -21], [48, -10], [16, 26], [15, 11], [23, -17], [45, -6], [-6, 16], [39, 2], [-12, -8], [-43, 0], [40, 3], [10, 6], [52, -6], [20, 7], [-21, 14], [70, -3], [-26, 0], [-5, 19], [42, -14], [54, -2], [-65, 4], [17, 14], [8, -10], [35, 5], [12, -22], [14, 9], [-46, -15], [9, -5], [18, 20], [-45, -4], [15, -3], [-28, 4], [3, 18], [16, -4], [68, 4], [36, 0], [34, 13], [50, 12], [2, -21], [4, -33], [8, 10], [8, -25], [-17, 2], [50, -13], [-15, -1], [-2, -16], [-32, -18], [-48, -2], [-50, -12], [18, -14], [31, -8], [19, 10], [-12, 17], [13, 6], [-50, 15], [-32, 0], [20, 9], [-10, 7], [48, 18], [-32, 21], [-33, -7], [-26, -13], [35, 7], [-3, 20], [0, -2], [-50, 3], [12, -25], [-43, 0], [47, -5], [51, -3], [-46, 5], [-10, 24], [-14, -25], [-6, 8], [-42, -20], [0, -36], [36, 4], [-3, -20], [29, -11], [-10, 8], [14, 23], [12, -22], [14, -19], [76, 2], [-3, -8], [-6, -23], [20, -6], [57, 9], [21, -29], [43, 3], [50, 4], [47, -8], [-27, 23], [-48, -8], [16, -24], [-70, 4], [30, 6], [68, -6], [-54, -11], [-6, 23], [-28, -27], [24, -9], [70, 12], [7, -9], [1, 18], [18, -19], [-7, -18], [6, 23], [70, 10], [50, -8], [39, 11], [3, 0], [-77, -3], [73, -2], [-19, 2], [-73, 1], [15, 27], [-20, 24], [-42, -4], [-33, 16], [30, 25], [-28, 20], [-30, 1], [36, 21], [4, 15], [-63, 8], [-18, 16], [-45, 21], [40, 11], [-39, 26], [31, -26], [72, -5], [-21, -9], [4, 38], [3, -20], [78, 0], [69, 5], [-23, -7], [-44, 18], [17, 20], [48, 11], [18, -5], [8, 4], [0, 28], [30, -12], [58, -1], [50, 3], [-44, 17], [-5, 34], [54, -8], [5, -31], [-66, 8], [-17, -10], [-62, 13], [-37, -20], [-47, 3], [-52, -16], [-18, -3], [14, 10], [-13, -21], [-50, 12], [12, 8], [-24, -9], [22, 5], [26, 6], [-41, -21], [-68, 4], [-34, -1], [-38, 26], [27, -22], [1, -14], [49, 5], [28, 10], [-21, -12], [3, 9], [-42, 2], [45, 10], [-56, 1], [-46, 4], [-8, -27], [58, 15], [-21, -28], [-70, 16], [-38, 24], [24, -19], [-14, -41], [-44, 9], [24, 29], [-30, 30], [-20, 2], [36, 11], [-48, 22], [-2, 8], [68, 6], [-34, 8], [45, -11], [-82, -7], [55, -2], [14, -25], [58, -8], [60, 10], [6, 15], [22, -13], [30, -16], [-48, 24], [60, 5], [-27, -25], [12, 15], [19, -14], [52, -20], [-4, -15], [-59, -1], [-56, -22], [-55, 5], [-7, 17], [-38, -8], [3, -13], [-43, -23], [-54, -19], [50, -6], [-30, 10], [-36, 22], [-68, 14], [76, 6], [22, -4], [-70, -15], [-41, -8], [72, -2], [-28, -30], [53, 27], [-36, 8], [-19, 2], [34, 1], [31, -5], [7, -15], [-43, 5], [-4, -13], [43, 6], [58, -4], [63, 7], [32, 28], [-75, 10], [4, 30], [42, -16], [70, -12], [-32, 4], [12, 36], [6, -22], [-4, 21], [-30, -15], [63, 21], [94, 8], [-64, -6], [46, 8], [67, -4], [-19, -6], [94, 12], [-33, -25], [-40, 26], [-9, -18], [18, 17], [18, 4], [-62, 17], [15, -8], [-38, -20], [48, -20], [-2, -29], [-12, 19], [72, 5], [-18, -30], [-50, 2], [41, 1], [-18, 0], [27, -16], [-12, 29], [-31, -8], [-72, 0], [64, 21], [-71, -8], [-47, 17], [14, -10], [-52, 2], [-57, 19], [48, -14], [52, -3], [-64, -22], [-7, -2], [68, 21], [42, -28], [-8, 21], [-35, 12], [-72, -10], [-11, 24], [60, 15], [3, 11], [-19, 5], [71, -14], [-42, -6], [-37, 1], [-2, -38], [47, 3], [37, -27], [-86, -4], [73, -6], [-12, 18], [-34, 3]];
    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_ea();".
// 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_ea(: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_ea();".
// 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_ea( : 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, 0, 1]>,<13,R![-5, 2, 1]>,<17,R![1, 1]>,<19,R![-2, 4, 1]>],Snew);
    return Vf;
end function;