
// Make newform 9450.2.a.ed 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_ed();".
// 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_ed();".
// 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 := [-18, -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], [0, 1], [-2, 1], [0, 1], [2, 0], [0, -1], [3, 0], [-1, 2], [-5, 1], [3, -1], [-2, -1], [3, 2], [6, 0], [-3, 1], [-1, -1], [-2, 2], [3, -1], [-11, 1], [2, 1], [0, 0], [-6, 2], [10, -2], [-6, 3], [-8, 0], [15, -1], [8, 2], [-9, 2], [-11, -1], [3, 0], [9, -1], [-10, 0], [0, -3], [-10, -3], [4, -3], [-14, -1], [9, 1], [3, 1], [-6, -2], [-7, -3], [0, -4], [-14, -2], [6, 0], [14, -3], [-1, -3], [10, 2], [24, 0], [2, 2], [21, -1], [-3, 5], [-16, 1], [6, 1], [6, -5], [24, 0], [-12, -3], [-1, 7], [22, 0], [18, -2], [7, 3], [-15, -3], [22, -3], [-6, -4], [10, -2], [18, -2], [-1, 5], [4, 0], [-3, 3], [-22, 0], [0, 3], [-12, -2], [10, 4], [-23, 0], [17, -1], [-6, 3], [3, 0], [4, 7], [0, 6], [-16, -1], [3, 0], [-10, 2], [21, 3], [13, -1], [8, 0], [-9, -5], [0, 4], [28, -2], [24, 2], [-5, -3], [-30, 2], [-36, 0], [7, 5], [12, 0], [11, -7], [6, -1], [6, -7], [18, 0], [-2, 3], [2, -6], [-14, -5], [-18, 2], [-12, 0], [30, 0], [5, 5], [7, -9], [36, 0], [-6, 3], [-21, 5], [14, 3], [4, -10], [28, -3], [-9, 8], [8, 2], [14, -2], [12, -6], [13, -8], [-3, -7], [-18, 4], [12, -8], [-13, -3], [-26, 6], [-27, -3], [27, 1], [26, -4], [15, 0], [26, 2], [18, -6], [4, 2], [-32, 2], [11, 1], [-24, -3], [32, -1], [-29, 6], [9, -1], [-40, -1], [3, 5], [-5, 6], [27, -3], [-6, 10], [20, 4], [6, 4], [1, 7], [3, -3], [2, 6], [-24, 0], [-8, -5], [-12, 10], [38, 0], [18, 3], [-5, -6], [3, 3], [16, 4], [-9, 2], [34, -1], [-21, 3], [-4, 11], [-6, 4], [25, 5], [-12, 3], [-12, 12], [48, -3], [-17, 1], [45, 0], [-24, 3], [18, -5], [-16, -7], [-8, -3], [29, 0], [3, -9], [-24, -5], [-13, 3], [0, -4], [-8, 6], [-25, 6], [39, -5], [29, -3], [-3, -9], [4, 6], [-7, 1], [-8, 4], [12, 4], [-17, -2], [-30, -5], [24, 8], [-6, 8], [4, -11], [1, -12], [23, -3], [0, -4], [7, -3], [-21, 7], [11, -7], [-6, -5], [-24, 0], [-42, 0], [5, 3], [13, -2], [-12, 6], [12, -12], [-12, -9], [47, -5], [-2, 0], [32, -2], [33, 2], [-51, -1], [-7, -8], [-48, 0], [18, -2], [-10, 10], [28, -2], [-24, -3], [-11, -11], [-30, 6], [-18, -6], [2, 5], [-23, -9], [30, 2], [30, -5], [-6, -10], [14, 12], [2, 1], [6, 6], [16, 4], [12, -14], [2, 2], [-36, 1], [-12, -6], [28, -2], [-36, 9], [-50, 4], [2, -6], [-46, 1], [-30, 6], [7, 3], [-21, -5], [-4, 11], [6, 10], [54, -2], [-36, -4], [12, 6], [-16, -4], [58, 2], [14, 0], [-12, 10], [-18, -8], [-20, 6], [3, 0], [59, -1], [18, 9], [13, -8], [-3, -3], [30, 6], [-22, 12], [27, -3], [60, -3], [-16, 0], [-17, -4], [-30, -6], [-11, 3], [55, -5], [-24, -10], [-19, -1], [-20, -5], [-42, -7], [-28, -2], [-39, 3], [45, -3], [4, 9], [-36, 0], [-58, -4], [10, -11], [-53, 5], [-16, 13], [22, 2], [34, -6], [51, -1], [2, -6], [-55, -4], [-9, 4], [-18, -3], [14, -9], [57, -2], [50, -4], [37, 0], [3, 15], [10, 12], [30, 4], [-34, 5], [15, 3], [12, -17], [-30, -4], [12, -11], [-48, 0], [-23, -1], [-42, -8], [8, 0], [-33, 3], [-6, 13], [-11, 1], [-2, -12], [54, 2], [20, 9], [-36, 4], [-28, 0], [-8, -6], [-33, 9], [-31, 1], [21, -3], [-11, 12], [-21, 12], [9, -1], [-42, 0], [-32, -7], [0, 15], [14, -11], [-45, 0], [-48, 4], [-77, 1], [-6, -6], [62, 2], [22, 2], [-6, 9], [-17, 7], [27, -14], [-22, -1], [-4, -4], [31, 11], [48, -9], [6, -6], [14, -20], [-30, -6], [-19, -6], [18, -4], [32, 6], [-60, 6], [2, 8], [24, -6], [-28, 15], [16, -14], [-8, 7], [-36, -1], [18, 8], [-28, 5], [-24, -4], [6, 1], [-82, -2], [64, 4], [-12, -10], [-6, -4], [50, 2], [-8, 4], [-63, 2], [-26, 16], [2, -14], [-30, 13], [-48, 12], [-3, -10], [57, 6], [-18, 5], [-26, -4], [-45, 5], [-12, 12], [84, -1], [-14, 5], [10, -14], [45, -5], [13, 11], [23, -4], [36, 7], [2, -2], [-42, 7], [57, -1], [23, -9], [25, 0], [-30, 7], [27, 7], [-77, -3], [-21, -5], [19, -7], [6, 13], [-27, 6], [-53, -3], [21, -2], [38, 0], [39, -2], [-4, 12], [-56, -2], [-20, 1], [45, 0], [-85, 2], [-21, 7], [72, -4], [-23, 4], [-9, -17], [-50, -8], [-49, 7], [33, -1], [-16, 18], [9, 0], [50, -4], [9, -2], [-41, 1], [-24, -9], [-36, -6], [29, -7], [64, -1], [-30, -8], [43, -1], [6, 13], [37, -13], [42, 8], [-3, -21], [20, 2], [58, -10], [24, 10], [72, 0], [-8, -8], [-78, 0], [63, -4], [24, -11], [-32, -10], [-48, 15], [9, -12], [-47, 15], [54, -6], [-9, 13], [-36, -12], [2, -10], [-66, 6], [-4, 15], [60, 1], [59, -1], [-48, 0], [4, -9], [-45, 3], [17, 14], [-16, 20], [46, -1], [32, -16], [24, -14], [48, -6], [-4, -6], [3, -15], [26, -17], [51, -11], [-5, -2], [-57, 0], [2, 9], [-19, -7], [-20, 4], [-24, 0], [-21, -1], [15, 5], [-32, -12], [39, 6], [-28, 0], [33, 9], [16, -1], [108, -1], [20, -18], [8, -20], [90, -5], [-28, -6], [4, -16], [4, 0], [-82, -3], [-84, 2], [-78, -2], [44, 0], [55, 9], [3, -15], [0, 12], [11, -16], [-18, -17], [-26, -9], [6, 0], [32, -16], [24, 0], [0, 8], [-5, 3], [-15, -19], [-2, -22], [0, -6], [64, 0], [33, -7], [14, 6], [12, -8], [-16, 0], [38, 9], [-26, 0], [24, 4], [-7, -8], [63, 3], [36, -1], [5, 3], [34, 3], [-36, 18], [-13, -20], [8, -2], [-42, -8], [34, -14], [15, -18], [-20, -6], [-20, 19], [30, -4], [-6, -9], [-25, 10], [-47, 7], [1, 0], [-18, -9], [-48, 12], [-2, 10], [72, -12], [-55, -9], [-38, 14], [-54, -4], [-43, 7], [24, 14], [10, -8], [-17, -6], [-16, 10], [-12, 0], [30, -18], [-46, -9], [99, -6], [-53, 17], [-3, 1], [15, -19], [-18, 15], [55, 1], [-66, 0], [-5, 9], [48, -11], [-14, 16], [69, -4], [-8, 18], [93, 1], [41, -9], [16, -4], [-24, 24], [-6, 0], [-67, -10], [-30, 24], [54, 8], [59, -15], [-5, 3], [-30, 2], [-32, 6], [-18, 4], [72, -10], [19, -6], [72, 0], [-54, -2], [48, -3], [17, 9], [-14, -18], [-57, -5], [-16, -10], [16, 0], [0, -9], [6, -24], [69, 1], [-2, 1], [68, -2], [-28, 4], [-30, 1], [-28, -15], [-9, 15], [0, -21], [16, 10], [-30, 14], [-100, -1], [-35, 5], [11, 6], [-42, -11], [-72, -3], [2, 10], [-9, 0], [11, -2], [69, 1], [10, -2], [18, -8], [-9, 3], [2, 18], [84, 6], [-11, -7], [6, -22], [18, 0], [7, 9]];
    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_ed();".
// 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_ed(: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_ed();".
// 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_ed( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-18, -1, 1]>,<13,R![-16, 3, 1]>,<17,R![-18, -1, 1]>,<19,R![-2, 1]>],Snew);
    return Vf;
end function;