
// Make newform 9282.2.a.g in Magma, downloaded from the LMFDB on 11 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_9282_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_9282_2_a_g();".
// 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_9282_2_a_g();".
// 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_9282_a();"
function MakeCharacter_9282_a()
    N := 9282;
    order := 1;
    char_gens := [3095, 3979, 8569, 547];
    v := [1, 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_9282_a_Hecke(Kf)
    return MakeCharacter_9282_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]];
    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], [1], [-3], [1], [0], [1], [-1], [2], [0], [-3], [2], [8], [6], [2], [-9], [-12], [6], [2], [-1], [9], [-4], [-4], [-6], [-15], [2], [15], [14], [9], [-10], [0], [-7], [-12], [12], [-22], [15], [20], [17], [2], [12], [24], [-6], [-16], [-21], [23], [-12], [20], [5], [8], [12], [-22], [-18], [-12], [-10], [12], [-12], [9], [24], [11], [-10], [12], [8], [-18], [14], [-15], [-1], [18], [17], [8], [0], [-10], [18], [6], [17], [32], [-4], [-3], [18], [26], [33], [23], [6], [17], [15], [2], [29], [-12], [6], [20], [18], [-34], [-15], [-36], [41], [-42], [-4], [9], [18], [39], [5], [32], [-31], [-3], [-12], [9], [-40], [-1], [24], [-9], [45], [35], [8], [35], [-6], [-19], [32], [-30], [-13], [48], [-39], [36], [32], [-28], [-42], [24], [-7], [0], [-10], [-27], [14], [2], [29], [3], [-22], [8], [45], [38], [24], [47], [-33], [30], [-37], [6], [-16], [-36], [35], [-12], [26], [-21], [5], [0], [-22], [42], [-58], [-21], [8], [48], [-7], [42], [8], [18], [-18], [-9], [26], [3], [-12], [-30], [-22], [-28], [-34], [36], [33], [-40], [-18], [32], [-34], [21], [-10], [-18], [20], [2], [-58], [-18], [-13], [42], [60], [-45], [38], [-4], [-31], [-42], [2], [-6], [56], [18], [27], [57], [-67], [-1], [18], [12], [-54], [35], [50], [-4], [24], [18], [-13], [48], [-54], [-16], [38], [27], [8], [36], [54], [-28], [47], [12], [21], [-45], [-4], [-16], [-54], [-1], [-69], [-34], [-21], [24], [8], [-72], [32], [2], [-40], [-3], [35], [24], [14], [-6], [-51], [12], [12], [23], [-34], [-34], [36], [0], [38], [-15], [44], [-51], [-46], [30], [-30], [29], [21], [72], [38], [-55], [54], [47], [14], [48], [-10], [-34], [18], [-49], [30], [54], [-4], [-30], [-76], [68], [-37], [47], [-40], [-28], [9], [26], [-70], [-60], [-24], [-40], [-33], [-28], [-67], [-57], [-34], [66], [-43], [-18], [-39], [72], [-42], [-45], [23], [-48], [74], [27], [-24], [2], [50], [-18], [56], [-36], [-67], [14], [-84], [-64], [30], [14], [-24], [-24], [78], [-22], [6], [26], [84], [0], [-82], [3], [80], [5], [51], [32], [-39], [-28], [-46], [-1], [-18], [-78], [-46], [18], [8], [-54], [-40], [24], [-82], [-18], [-40], [50], [65], [-27], [-54], [-25], [27], [84], [32], [-28], [12], [-30], [-22], [71], [-75], [-25], [-4], [6], [15], [-60], [-36], [54], [44], [45], [-45], [-60], [-28], [-19], [-3], [62], [50], [-36], [-22], [-39], [-78], [-88], [-73], [-33], [-18], [-31], [-18], [-100], [45], [-30], [53], [-69], [5], [-18], [62], [-37], [-16], [48], [17], [-27], [0], [-43], [-48], [-88], [-40], [12], [77], [-75], [-55], [81], [50], [18], [-84], [-25], [-82], [-72], [-94], [-60], [17], [-18], [90], [-85], [-13], [-42], [-3], [53], [-66], [60], [-36], [-43], [99], [63], [-28], [78], [-93], [30], [-82], [-9], [-70], [21], [23], [-66], [-7], [90], [-61], [83], [-13], [56], [-81], [45], [-91], [108], [-19], [63], [-28], [54], [35], [-13], [17], [90], [24], [54], [32], [-54], [98], [69], [62], [33], [-13], [59], [0], [35], [-112], [32], [68], [36], [-36], [107], [80], [-72], [0], [-7], [72], [-67], [6], [80], [27], [33], [-82], [-72], [53], [42], [-28], [102], [-106], [84], [-28], [83], [44], [-102], [-70], [114], [-111], [5], [41], [27], [71], [38], [60], [47], [-3], [-13], [50], [90], [84], [-7], [-82], [80], [-30], [0], [-49], [54], [-34], [-10], [42], [8], [-60], [32], [-46], [23], [-81], [54], [-25], [96], [-76], [-30], [66], [-102], [20], [30], [92], [-114], [47], [-24], [-58], [18], [2], [-22], [72], [-57], [41], [-39], [-105], [53], [101], [9], [98], [-75], [78], [35], [24], [114], [-108], [-73], [104]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9282_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9282_2_a_g();".
// 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_9282_2_a_g(:prec:=1)
    chi := MakeCharacter_9282_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(4027) - 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_9282_2_a_g();".
// 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_9282_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9282_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![3, 1]>,<11,R![0, 1]>,<19,R![-2, 1]>],Snew);
    return Vf;
end function;