
// Make newform 9450.2.a.cv in Magma, downloaded from the LMFDB on 19 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_cv();".
// 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_cv();".
// 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], [5], [4], [1], [8], [10], [-8], [-4], [9], [1], [-13], [-3], [-14], [6], [-11], [0], [7], [-10], [-15], [-11], [18], [-3], [14], [-10], [5], [17], [17], [4], [7], [4], [12], [-6], [-18], [12], [12], [6], [5], [-22], [5], [10], [-5], [-3], [6], [26], [9], [-2], [-11], [4], [6], [-8], [-12], [-12], [10], [15], [8], [-30], [4], [-6], [10], [-18], [25], [13], [20], [-22], [12], [-24], [6], [-13], [2], [10], [-14], [-24], [18], [14], [-6], [-26], [-26], [1], [-11], [5], [-1], [12], [22], [-38], [-7], [11], [4], [-6], [-7], [-36], [40], [-35], [-26], [-27], [-4], [35], [8], [2], [-19], [-18], [-34], [13], [28], [-6], [3], [-28], [4], [36], [-22], [7], [-30], [14], [-10], [3], [30], [12], [-32], [4], [4], [-20], [25], [40], [27], [-14], [2], [-11], [-44], [18], [10], [-24], [14], [-26], [-42], [18], [-8], [-28], [21], [-6], [-33], [26], [-2], [-26], [-26], [-52], [-15], [22], [14], [-30], [-52], [-21], [37], [43], [14], [15], [47], [7], [42], [42], [-29], [-42], [33], [16], [52], [14], [46], [-32], [-39], [42], [-16], [62], [-35], [3], [-10], [-4], [24], [8], [29], [46], [-22], [-36], [50], [39], [12], [-28], [7], [36], [34], [60], [34], [-21], [-16], [40], [-58], [-12], [-28], [-7], [-46], [67], [-45], [0], [-18], [56], [-15], [-26], [60], [-13], [-4], [-19], [45], [-12], [-22], [2], [-12], [42], [-6], [-29], [-17], [-31], [-6], [15], [11], [-6], [-36], [-35], [-16], [3], [-50], [27], [-28], [24], [26], [21], [-20], [-45], [-9], [6], [30], [-20], [4], [27], [30], [-24], [14], [-54], [-42], [12], [10], [-78], [40], [56], [48], [-76], [74], [-2], [-12], [-74], [8], [36], [28], [-77], [40], [-53], [6], [50], [48], [-33], [4], [-33], [-58], [74], [9], [-36], [-12], [-41], [17], [78], [-12], [-20], [-8], [-16], [4], [0], [-26], [-18], [41], [-69], [18], [-27], [-75], [-38], [40], [5], [-56], [-74], [12], [-2], [67], [-37], [48], [-24], [76], [32], [-80], [38], [-21], [-46], [-77], [6], [66], [-81], [-12], [-58], [-30], [-40], [-7], [-36], [64], [-46], [-65], [25], [31], [20], [-32], [-40], [30], [14], [85], [-93], [-32], [21], [40], [-40], [-45], [-40], [-2], [-2], [-76], [-71], [39], [58], [-6], [-31], [-64], [-15], [-78], [38], [-27], [-16], [4], [90], [-70], [22], [68], [6], [93], [66], [-36], [-21], [40], [-68], [-64], [18], [-2], [-68], [-63], [-39], [17], [-66], [-36], [-11], [74], [64], [-15], [-39], [74], [95], [57], [-71], [-57], [-57], [-85], [21], [-32], [13], [-29], [48], [-85], [-24], [-76], [-22], [99], [-60], [-56], [-25], [2], [58], [30], [-31], [-27], [-60], [-57], [-55], [48], [30], [76], [-60], [-9], [-15], [-70], [18], [-26], [99], [45], [64], [-30], [-69], [96], [-11], [8], [-56], [-6], [-66], [-20], [-18], [0], [-70], [-16], [44], [-20], [81], [95], [-63], [-47], [94], [92], [16], [-53], [36], [11], [1], [82], [6], [-30], [41], [-88], [-32], [-11], [16], [14], [21], [16], [-16], [-95], [12], [-6], [-3], [-96], [-50], [55], [37], [22], [-36], [44], [-109], [66], [31], [88], [54], [-24], [43], [3], [-93], [104], [5], [-92], [-75], [11], [-55], [-25], [53], [-36], [-60], [7], [-78], [63], [60], [30], [-96], [97], [-34], [-44], [40], [94], [-29], [-115], [-38], [-54], [74], [-6], [-13], [54], [-42], [92], [1], [10], [26], [8], [-48], [5], [79], [30], [-22], [-70], [-20], [-19], [14], [98], [94], [-10], [72], [-22], [78], [-89], [0], [-70], [77], [48], [-63], [101], [-27], [-27], [17], [77], [-34], [-47], [-7], [-40], [-6], [-52], [-12], [102], [-30], [103], [-63], [-50], [117], [20], [54], [15], [9], [-55], [-94], [33], [63], [-84], [-46], [-6], [74], [26], [-101], [-112], [-4], [-48], [-36], [-52], [67], [62], [-44], [-54], [31], [-17], [69], [20], [51], [-18], [107], [-65], [12], [-26], [-82], [32], [35], [-2], [101], [111], [86]];
    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_cv();".
// 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_cv(: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_cv();".
// 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_cv( : 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![-5, 1]>,<17,R![-4, 1]>,<19,R![-1, 1]>],Snew);
    return Vf;
end function;