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