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