
// Make newform 9126.2.a.c in Magma, downloaded from the LMFDB on 12 April 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_9126_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_9126_2_a_c();".
// 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_9126_2_a_c();".
// 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_9126_a();"
function MakeCharacter_9126_a()
    N := 9126;
    order := 1;
    char_gens := [677, 3889];
    v := [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_9126_a_Hecke( : Kf := Kf)
    return MakeCharacter_9126_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], [0], [-2], [-4], [2], [0], [6], [-3], [-4], [-4], [5], [3], [-6], [7], [-10], [12], [10], [1], [11], [-16], [-5], [-1], [0], [-6], [7], [-2], [16], [2], [17], [-16], [13], [20], [-18], [7], [12], [15], [-7], [4], [-18], [2], [6], [3], [-8], [-14], [18], [-7], [-28], [0], [12], [6], [-2], [6], [-21], [0], [0], [-18], [-30], [8], [-30], [-22], [7], [-16], [-23], [-12], [11], [-12], [25], [29], [12], [-25], [32], [-6], [-19], [-34], [11], [-12], [-18], [-29], [18], [14], [-12], [-10], [-12], [-17], [-31], [6], [8], [-1], [-18], [23], [20], [-42], [-11], [-26], [-4], [-8], [-34], [18], [27], [37], [-5], [-24], [38], [-14], [-33], [-15], [4], [-14], [-14], [-26], [27], [31], [2], [20], [41], [-20], [-11], [-2], [-36], [36], [10], [-41], [48], [-16], [23], [-30], [-26], [-16], [13], [1], [-48], [-28], [45], [15], [36], [21], [40], [-17], [24], [12], [-5], [-20], [9], [6], [-17], [-56], [-22], [52], [-4], [-28], [-21], [-42], [-41], [-38], [15], [-12], [0], [-36], [39], [-4], [-24], [44], [31], [-48], [54], [-14], [-33], [17], [46], [-16], [-24], [-18], [-38], [47], [3], [-26], [1], [-40], [64], [-43], [27], [16], [-29], [10], [44], [-50], [-2], [51], [31], [-12], [-14], [-42], [-32], [28], [46], [66], [10], [-38], [10], [-38], [24], [32], [-2], [49], [-28], [18], [5], [-24], [24], [3], [-10], [-30], [-1], [38], [54], [-19], [-53], [-28], [32], [12], [-38], [-41], [-48], [-25], [-12], [5], [-16], [6], [-32], [0], [19], [31], [-48], [-68], [20], [-26], [38], [-4], [-6], [26], [-30], [7], [-51], [10], [-8], [30], [-32], [26], [49], [42], [37], [-20], [50], [17], [-68], [50], [-45], [-8], [-12], [-70], [55], [6], [25], [-26], [72], [-41], [20], [28], [-12], [6], [-74], [17], [-54], [41], [5], [-51], [58], [66], [-67], [-36], [-16], [-72], [32], [-74], [-45], [22], [74], [-14], [-17], [-16], [-24], [44], [-18], [58], [61], [0], [-69], [-76], [22], [7], [-10], [4], [-60], [-34], [-8], [-41], [22], [27], [86], [33], [42], [-8], [-72], [-17], [52], [-55], [0], [-14], [67], [-22], [20], [2], [84], [-11], [64], [13], [35], [-36], [88], [-28], [-19], [56], [20], [36], [55], [-8], [67], [10], [42], [23], [3], [-78], [-16], [-17], [-8], [40], [-53], [28], [-26], [-18], [71], [-25], [30], [41], [21], [-30], [24], [18], [42], [-30], [-1], [-18], [14], [10], [47], [22], [18], [-37], [-33], [-90], [31], [10], [-78], [-21], [3], [-24], [-24], [1], [-22], [70], [-60], [-38], [-33], [-82], [-16], [-36], [-72], [-73], [-44], [-46], [-66], [14], [36], [71], [-6], [13], [63], [8], [-36], [-54], [35], [-10], [-103], [56], [-6], [-1], [62], [-48], [-76], [66], [91], [84], [44], [37], [5], [-18], [-72], [64], [12], [-66], [80], [83], [60], [18], [-71], [-46], [-106], [-48], [23], [40], [-73], [-90], [44], [-42], [-97], [-34], [19], [67], [-57], [37], [-22], [32], [-77], [6], [94], [-6], [49], [-42], [-17], [-1], [-3], [74], [-26], [-54], [-46], [52], [6], [108], [39], [-56], [5], [-24]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_9126_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_9126_2_a_c();".
// 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_9126_2_a_c(:prec:=1)
    chi := MakeCharacter_9126_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(3271) - 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_9126_2_a_c();".
// 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_9126_2_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_9126_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<5,R![2, 1]>,<7,R![4, 1]>,<11,R![-2, 1]>,<17,R![-6, 1]>],Snew);
    return Vf;
end function;