
// Make newform 9450.2.a.cw in Magma, downloaded from the LMFDB on 16 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_cw();".
// 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_cw();".
// 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], [8], [-8], [1], [-2], [0], [3], [6], [-4], [9], [8], [3], [5], [-12], [1], [-2], [10], [-12], [10], [-13], [12], [-2], [3], [14], [12], [20], [-1], [-2], [14], [-4], [10], [-18], [14], [-23], [6], [-11], [3], [8], [-10], [-12], [6], [-18], [-28], [19], [-1], [8], [3], [-5], [15], [28], [29], [-6], [-2], [22], [24], [-26], [-6], [-22], [31], [-30], [10], [6], [18], [20], [14], [-2], [3], [34], [26], [4], [-35], [-8], [-27], [28], [19], [20], [-35], [-21], [1], [40], [9], [20], [-35], [-10], [-18], [-21], [-16], [22], [-12], [-24], [16], [-12], [12], [10], [-31], [6], [-24], [17], [-46], [-20], [-11], [-12], [42], [48], [13], [-20], [-33], [8], [-40], [-16], [34], [20], [-15], [-4], [12], [-31], [-9], [-8], [-33], [42], [48], [37], [-19], [8], [7], [-10], [33], [-26], [1], [-14], [-50], [-14], [-4], [-6], [-16], [-8], [46], [-18], [-23], [27], [-7], [37], [44], [-26], [8], [23], [-28], [2], [-49], [-32], [11], [22], [-20], [-11], [0], [4], [-16], [-56], [-53], [42], [45], [22], [-11], [-59], [-24], [4], [-2], [-53], [-59], [2], [-30], [28], [12], [-6], [5], [12], [33], [13], [-44], [-48], [24], [62], [-18], [5], [-3], [-1], [-49], [-12], [12], [-47], [-54], [23], [65], [16], [-48], [24], [10], [-13], [-53], [21], [-10], [-68], [-69], [58], [-40], [38], [-30], [-50], [37], [59], [22], [-68], [42], [35], [18], [-31], [60], [-30], [22], [-13], [15], [24], [-51], [-8], [-4], [49], [4], [-20], [70], [12], [-1], [-33], [-36], [-8], [-7], [-24], [-8], [66], [23], [6], [-45], [36], [37], [-58], [-1], [-11], [38], [-37], [75], [46], [-17], [-26], [28], [-4], [-55], [16], [48], [-70], [53], [36], [-50], [-38], [0], [56], [-24], [-11], [-38], [-49], [-4], [-65], [-14], [-44], [26], [-17], [1], [-23], [20], [-51], [-75], [-4], [-17], [17], [-20], [-10], [-16], [-32], [-20], [54], [-5], [66], [60], [-30], [52], [-20], [-52], [37], [46], [18], [-61], [6], [37], [-3], [-54], [75], [66], [-48], [-20], [-48], [-82], [-40], [-37], [-72], [81], [-34], [-42], [70], [-77], [-28], [-46], [8], [-45], [-2], [-62], [-39], [46], [73], [40], [-28], [-21], [-4], [-52], [-62], [6], [-53], [-22], [-9], [-14], [82], [-20], [0], [76], [-42], [66], [57], [92], [-30], [-35], [36], [2], [54], [76], [51], [0], [-72], [-43], [23], [-84], [87], [-9], [32], [-18], [-52], [-70], [-21], [-48], [-50], [-15], [-6], [72], [-74], [-84], [-27], [-18], [4], [62], [80], [50], [62], [62], [22], [24], [12], [-41], [92], [64], [34], [60], [60], [-58], [-32], [38], [64], [-54], [-56], [-36], [-19], [-42], [-76], [44], [-56], [-24], [-35], [82], [-76], [-37], [37], [90], [21], [80], [-14], [70], [52], [4], [-62], [84], [-34], [62], [-33], [52], [58], [14], [4], [18], [88], [11], [-5], [-65], [78], [11], [-58], [-60], [73], [-57], [-78], [-100], [51], [46], [-37], [21], [-53], [-6], [58], [12], [74], [67], [-32], [-73], [-9], [-44], [-47], [24], [62], [-105], [-42], [-76], [-76], [-32], [-33], [-77], [32], [81], [-44], [-73], [24], [106], [44], [-72], [-5], [10], [-68], [47], [-94], [74], [7], [86], [-13], [76], [83], [76], [102], [-33], [57], [60], [-8], [-42], [89], [-9], [54], [50], [19], [30], [68], [44], [16], [-76], [20], [-36], [-24], [28], [-65], [18], [64], [-14], [-27], [-62], [27], [-45], [-51], [-102], [20], [-37], [-34], [25], [83], [-68], [46], [48], [-108], [-27], [-75], [93], [-2], [52], [92], [92], [46], [12], [-36], [-48], [19], [0], [17], [116], [-50], [24], [-72], [-72], [64], [109], [66], [70], [66], [33], [-90], [0], [-48], [-66], [-63], [64], [-41], [67], [-26], [-18], [-6], [43], [18], [43], [11], [-121], [-24], [-34], [57], [37], [-22], [84], [19], [30], [16], [15], [-47], [101], [38], [50], [120], [-76], [-36], [94], [-106], [-19], [-2], [45], [47], [48], [-60], [-26]];
    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_cw();".
// 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_cw(: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_cw();".
// 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_cw( : 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![-8, 1]>,<19,R![8, 1]>],Snew);
    return Vf;
end function;