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