
// Make newform 216.4.a.g in Magma, downloaded from the LMFDB on 22 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_216_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_216_4_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_216_4_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
        poly := [-1, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-6, 12]];
    Rf_basisdens := [1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_216_a();"
function MakeCharacter_216_a()
    N := 216;
    order := 1;
    char_gens := [55, 109, 137];
    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_216_a_Hecke( : Kf := Kf)
    return MakeCharacter_216_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 := 4;
    raw_aps := [[0, 0], [0, 0], [2, 1], [-3, 2], [26, -3], [13, -2], [94, -1], [-37, -8], [74, 5], [144, 8], [-124, 8], [171, 10], [0, -32], [-128, -4], [66, 1], [476, 14], [-502, 21], [-17, -34], [-433, -16], [388, -30], [937, -12], [91, -26], [-668, -46], [438, -21], [-19, 88], [-720, -72], [-95, -50], [366, 103], [130, -100], [-1434, 35], [-1004, -92], [-440, -92], [-294, 29], [-171, 100], [724, -118], [2711, 14], [-2114, 60], [453, -48], [354, 81], [1152, 32], [876, -10], [-1815, 182], [1806, -121], [1343, 28], [-294, 13], [-983, 126], [241, -196], [2188, 256], [-1452, -150], [-3614, -184], [-2824, -164], [4468, -134], [57, 52], [-3080, 348], [-860, -302], [812, 342], [-3650, 31], [-5857, -26], [-3638, 348], [-3392, -32], [-4456, 4], [3894, 155], [2088, -172], [-210, 87], [4611, -204], [-156, -206], [-6595, -4], [4101, -16], [-156, -302], [-933, 294], [-380, -158], [4254, 303], [-5399, 70], [3731, -366], [2135, 468], [-1296, 216], [2834, -599], [-2290, 492], [10668, -330], [1833, 16], [7986, -151], [3773, -258], [11242, 437], [490, 156], [-36, -504], [5812, 346], [7106, 753], [2318, 1004], [1118, 303], [365, -462], [1794, 337], [12124, -178], [-371, 1030], [-7122, 7], [7344, -424], [5706, -283], [6330, 189], [12034, -207], [6631, 520], [-2979, 186], [-1867, -212], [-20242, -105], [-3472, 1304], [9182, -321], [-14109, -884], [-12541, -788], [-682, -357], [7556, 1122], [-15408, 872], [-1838, -644], [13853, -234], [-2953, 806], [-12942, 329], [-2549, -408], [1087, -378], [-1468, -990], [-3552, 996], [-17168, 856], [-4452, 78], [132, 1410], [1559, 1406], [-2549, 832], [-20518, 749], [6968, 188], [1808, 1044], [18702, -217], [11309, 1210], [-9892, -722], [18372, 192], [15650, -1228], [25880, -228], [12026, -1795], [-15477, 578], [10661, -902], [-4898, 2655], [-33841, -480], [-15708, 1490], [-11069, -112], [11384, 1244], [4828, -338], [-6512, -2916], [6762, -907], [20951, -1470], [-38270, -559], [-1583, -898], [33852, 830], [7931, 1350], [8796, 366], [-31527, -1028], [23858, 313], [4755, -62], [-5246, 209], [21125, 1748], [-1124, 1358], [-16721, -1224], [5864, 2004], [-6140, 912], [-2420, 2022], [-3981, -3036], [7926, -1349], [13446, -1997], [-8082, 3303], [-1789, 538], [-3378, -169], [-39324, -878], [-20370, -873], [-40871, 982], [-36938, -324]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_216_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_216_4_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_216_4_a_g(:prec:=2)
    chi := MakeCharacter_216_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_216_4_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_216_4_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_216_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<5,R![-176, -4, 1]>],Snew);
    return Vf;
end function;