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