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