
// Make newform 9450.2.a.dt in Magma, downloaded from the LMFDB on 19 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_dt();".
// 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_dt();".
// 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
        Kf := Rationals();
    end if;
    return [Kf!elt[1] : elt in input];
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], [1], [2], [3], [-1], [0], [-3], [3], [-1], [4], [10], [-1], [-10], [1], [5], [10], [3], [-5], [10], [4], [-4], [-1], [-2], [12], [-7], [6], [6], [2], [-16], [7], [-18], [-8], [-9], [20], [17], [7], [-18], [14], [0], [19], [0], [-11], [-10], [17], [19], [-16], [-19], [-14], [18], [8], [4], [0], [14], [11], [0], [15], [12], [-8], [22], [-14], [-4], [-6], [-20], [-2], [13], [23], [-14], [1], [21], [-29], [23], [4], [12], [24], [-2], [38], [14], [-30], [21], [14], [-24], [4], [13], [40], [-36], [11], [38], [-8], [20], [0], [34], [-24], [-36], [-30], [-16], [-5], [-4], [-18], [-12], [-17], [-19], [-18], [-3], [8], [-7], [-6], [15], [36], [-1], [36], [-10], [-22], [32], [46], [14], [-2], [-7], [-34], [-14], [35], [-12], [-22], [4], [-34], [-50], [-30], [3], [-31], [-32], [-39], [32], [20], [-15], [-38], [-24], [2], [-30], [36], [2], [-3], [-40], [-46], [38], [-20], [49], [-51], [48], [-17], [-32], [13], [-3], [-4], [52], [-48], [-34], [26], [-2], [-2], [-4], [-36], [-52], [-21], [-18], [-16], [-50], [43], [19], [28], [34], [-7], [27], [-21], [32], [-19], [-23], [-27], [-8], [-5], [-38], [57], [22], [29], [-33], [-18], [38], [-26], [-11], [-12], [48], [34], [1], [64], [12], [21], [1], [26], [-21], [-40], [-13], [-31], [-18], [18], [-15], [-58], [59], [-42], [36], [-22], [-57], [-60], [38], [-7], [-6], [-28], [-40], [6], [49], [57], [-52], [-40], [-30], [6], [-52], [-28], [-17], [-8], [-7], [-20], [-40], [12], [-56], [-54], [56], [24], [64], [11], [-8], [-28], [52], [-22], [-15], [-38], [3], [30], [-71], [-60], [23], [-37], [-46], [9], [21], [-24], [30], [26], [-58], [26], [54], [6], [60], [-38], [46], [-62], [-9], [32], [42], [82], [-31], [54], [-3], [72], [-56], [60], [-68], [-59], [8], [26], [-6], [-1], [-44], [26], [84], [15], [-26], [-60], [-34], [-21], [53], [-57], [-18], [17], [76], [-59], [-48], [-66], [52], [52], [-87], [28], [-18], [-19], [-38], [-18], [-31], [-39], [68], [57], [60], [46], [6], [87], [50], [1], [-75], [56], [-63], [0], [-36], [-44], [-68], [-82], [58], [-84], [24], [2], [-91], [12], [-47], [-54], [8], [-18], [4], [12], [-73], [21], [16], [27], [-80], [64], [-16], [-68], [24], [44], [39], [56], [15], [-61], [24], [-78], [-10], [-9], [69], [-89], [-54], [66], [-6], [56], [90], [0], [-80], [43], [17], [2], [-52], [50], [34], [56], [-83], [0], [-44], [-65], [9], [-67], [14], [13], [69], [-56], [18], [-66], [-46], [-8], [-30], [48], [-66], [-60], [42], [49], [13], [46], [-1], [34], [26], [90], [-37], [29], [-29], [-13], [-57], [-27], [15], [12], [-22], [57], [14], [64], [-62], [6], [54], [15], [-62], [-87], [-54], [-71], [43], [8], [81], [60], [27], [2], [-7], [55], [12], [-5], [-54], [-2], [-88], [24], [22], [-74], [-80], [30], [-39], [6], [11], [30], [-1], [34], [-21], [-37], [-12], [72], [-22], [85], [50], [24], [98], [22], [70], [17], [-28], [-90], [30], [39], [-47], [75], [-76], [-35], [81], [-22], [-59], [-80], [-78], [60], [92], [55], [58], [-24], [-10], [-60], [-8], [58], [38], [-30], [-46], [-86], [66], [-48], [82], [111], [4], [69], [-20], [30], [44], [-72], [94], [-24], [-32], [64], [55], [0], [-9], [24], [-2], [5], [-12], [33], [37], [80], [31], [31], [-88], [34], [-30], [22], [-100], [40], [-2], [44], [99], [-28], [-8], [57], [60], [49], [-66], [47], [71], [83], [-88], [-9], [-98], [63], [28], [-121], [-88], [34], [90], [-40], [48], [14], [48], [32], [73], [-62], [-50], [54], [55], [81], [14], [33], [-8], [21], [-32], [0], [58], [5], [48], [-96], [-44], [106], [88], [34], [-54], [-77], [-112], [9], [-34], [101], [90], [-12], [1], [13], [36], [88], [77], [-40], [-24], [-52], [57], [80], [-18], [90], [23], [-72], [-51], [-34], [-5], [115], [127], [-4], [41], [-84], [-51], [-9], [-122], [-69], [-38], [0]];
    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_dt();".
// 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_dt(:prec:=1)
    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_dt();".
// 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_dt( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-2, 1]>,<13,R![-3, 1]>,<17,R![1, 1]>,<19,R![0, 1]>],Snew);
    return Vf;
end function;