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