
// Make newform 9450.2.a.dy 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_dy();".
// 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_dy();".
// 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], [5], [5], [-3], [-6], [-1], [1], [1], [10], [4], [-5], [11], [2], [4], [0], [-12], [-12], [12], [1], [16], [-16], [4], [9], [16], [-8], [-18], [3], [-10], [13], [6], [-10], [9], [-15], [7], [-1], [0], [-18], [-4], [-12], [-12], [20], [10], [-3], [-22], [0], [16], [8], [-6], [-24], [19], [19], [17], [24], [17], [-16], [-26], [20], [20], [-12], [25], [18], [-12], [12], [26], [-12], [22], [-6], [-33], [-14], [-10], [-3], [26], [-35], [25], [-35], [22], [5], [-11], [28], [30], [14], [-16], [-4], [20], [-18], [-6], [-26], [24], [28], [34], [-4], [10], [21], [-13], [30], [19], [32], [-37], [12], [-4], [-30], [-32], [-16], [-36], [29], [2], [-17], [-2], [35], [-31], [14], [-32], [-18], [13], [-28], [-10], [-12], [-42], [-16], [-8], [-34], [6], [45], [-40], [-40], [-38], [-2], [-22], [29], [-7], [-47], [-18], [-35], [-6], [5], [42], [0], [-24], [30], [-54], [-38], [-20], [-16], [-19], [38], [30], [41], [-35], [40], [-12], [31], [55], [-56], [9], [42], [-12], [-33], [8], [29], [38], [-21], [-45], [5], [31], [-53], [-43], [-36], [-9], [16], [-28], [50], [-19], [20], [-40], [10], [-2], [-8], [36], [-40], [-3], [13], [-48], [30], [11], [21], [10], [-12], [-54], [12], [-22], [25], [40], [10], [2], [-13], [-62], [32], [47], [44], [46], [-62], [25], [42], [-35], [-56], [12], [-4], [14], [13], [-8], [60], [-28], [-47], [-22], [12], [-51], [-4], [26], [-67], [-8], [4], [-42], [64], [-23], [14], [46], [-7], [-38], [-56], [1], [-20], [-44], [8], [29], [-36], [-64], [8], [-54], [20], [-64], [14], [54], [-6], [-10], [-19], [36], [-33], [17], [-48], [24], [46], [-6], [-19], [-16], [-37], [40], [58], [12], [-66], [14], [9], [47], [-26], [-54], [-80], [7], [44], [58], [-39], [-50], [-45], [-12], [-24], [-36], [8], [53], [-51], [-37], [23], [-39], [-26], [-35], [-84], [-26], [78], [61], [-68], [31], [18], [33], [-16], [26], [18], [16], [36], [27], [-60], [2], [-84], [59], [-48], [4], [70], [-46], [8], [24], [37], [-3], [86], [-6], [11], [-57], [-19], [37], [-12], [50], [-40], [36], [4], [15], [56], [-9], [47], [48], [20], [63], [-36], [42], [80], [39], [-78], [-54], [-38], [-38], [-78], [49], [-34], [61], [-93], [-42], [-65], [-44], [-33], [-8], [52], [-54], [-62], [-8], [28], [-75], [-26], [-24], [-9], [-84], [81], [21], [55], [10], [26], [24], [-25], [45], [32], [-10], [90], [75], [-57], [-84], [81], [-42], [8], [13], [69], [-44], [-42], [16], [-14], [-33], [-87], [30], [-63], [-2], [-21], [-16], [42], [31], [-25], [1], [-36], [60], [-43], [80], [14], [64], [30], [6], [-45], [22], [69], [6], [-69], [30], [-84], [-67], [30], [60], [87], [66], [-2], [-66], [-70], [12], [-14], [-8], [-24], [62], [65], [-47], [58], [39], [-45], [50], [92], [-74], [48], [-92], [-72], [-95], [-15], [-68], [-72], [77], [-48], [51], [-92], [-53], [56], [-6], [90], [90], [94], [103], [34], [-59], [-75], [85], [60], [-16], [-16], [12], [62], [-60], [-37], [12], [-88], [41], [35], [30], [-20], [-67], [-30], [68], [12], [81], [-2], [44], [-68], [-42], [-10], [84], [-77], [93], [-49], [-54], [-40], [16], [48], [8], [92], [-68], [90], [-16], [-80], [16], [-36], [-16], [37], [54], [68], [-55], [-36], [-25], [18], [95], [78], [-13], [-78], [-30], [-16], [15], [-46], [45], [78], [-59], [-31], [-70], [-55], [105], [100], [-44], [-76], [2], [36], [-78], [-82], [-50], [10], [41], [86], [-108], [96], [95], [-25], [-78], [36], [70], [-87], [-98], [-78], [122], [-15], [-94], [-21], [-42], [52], [114], [92], [112], [-74], [59], [-18], [-30], [-62], [-64], [-72], [42], [-10], [6], [1], [48], [-4], [57], [-64], [-36], [-44], [50], [48], [-61], [50], [28], [37], [-74], [-96], [-33], [-65], [24], [-73], [14], [60], [-11], [64], [-19], [115], [-47], [-32], [69], [-23], [-60], [-12], [94], [12], [-16], [-22], [-36], [76], [110], [-50]];
    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_dy();".
// 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_dy(: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_dy();".
// 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_dy( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9450_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<11,R![-5, 1]>,<13,R![-5, 1]>,<17,R![3, 1]>,<19,R![6, 1]>],Snew);
    return Vf;
end function;