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