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