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