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