
// Make newform 81.6.c.e in Magma, downloaded from the LMFDB on 02 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_81_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_81_c_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_81_6_c_e();".
// 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_81_6_c_e();".
// 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 := [121, -11, -10, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-121, -10, 10, 1], [0, 21, 1, -1], [-21, 10, 0, 1]];
    Rf_basisdens := [1, 110, 11, 10];
    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_81_c();"
function MakeCharacter_81_c()
    N := 81;
    order := 3;
    char_gens := [2];
    v := [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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_81_c_Hecke();"
function MakeCharacter_81_c_Hecke( : Kf := false)
    N := 81;
    order := 3;
    char_gens := [2];
    char_values := [[0, 1, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 6;
    raw_aps := [[-2, -2, 0, -1], [0, 0, 0, 0], [0, -17, 4, -4], [76, 76, 0, 24], [184, 184, 0, 56], [0, -37, -156, 156], [1563, 0, -24, 0], [-1132, 0, 72, 0], [0, -2072, -296, 296], [-83, -83, 0, -892], [0, -4708, 816, -816], [-1069, 0, 1044, 0], [0, 7546, -992, 992], [6736, 6736, 0, 2616], [4132, 4132, 0, 320], [-23274, 0, -864, 0], [0, 31888, 2992, -2992], [-5387, -5387, 0, 3444], [0, -6508, 2616, -2616], [-7068, 0, 10632, 0], [3467, 0, 2160, 0], [18904, 18904, 0, -6456], [8980, 8980, 0, -12304], [19011, 0, -10992, 0], [96862, 96862, 0, -1056], [105706, 105706, 0, 8096], [0, -125524, -9696, 9696], [25380, 0, -22464, 0], [-57841, 0, -8460, 0], [0, -57473, 35536, -35536], [15608, 0, 3528, 0], [0, 134548, -18872, 18872], [98737, 98737, 0, -16120], [0, 80180, 32784, -32784], [0, 218731, -9236, 9236], [57352, 57352, 0, -29712], [0, -92809, 50604, -50604], [253496, 0, 7632, 0], [0, 100540, 15592, -15592], [64489, 64489, 0, 19100], [-311484, 0, -1824, 0], [262982, 0, -42912, 0], [-401996, -401996, 0, 152], [0, 681371, -54840, 54840], [560847, 0, -32484, 0], [-704068, 0, 36144, 0], [0, -479152, -96168, 96168], [-112352, -112352, 0, 10824], [-379220, -379220, 0, -9016], [0, -311941, 114108, -114108], [789387, 0, -13488, 0], [0, -952508, -8864, 8864], [-488075, -488075, 0, -157224], [-184848, 0, 151800, 0], [0, -650993, 223936, -223936], [-1510244, -1510244, 0, -98176], [-453105, 0, -138924, 0], [-23704, 0, -306504, 0], [-1665446, -1665446, 0, 141504], [-13739, -13739, 0, -165760], [0, -190036, -50592, 50592], [0, 678427, 143740, -143740], [-112732, 0, 192672, 0], [0, -122648, 215008, -215008], [-1170815, -1170815, 0, -185736], [2529217, 2529217, 0, 135356], [-107276, -107276, 0, -400008], [0, 223010, 390048, -390048], [0, 726604, -129896, 129896], [1070338, 1070338, 0, -9696], [2196142, 2196142, 0, 128960], [-1990392, 0, -398136, 0], [-299912, -299912, 0, -482016], [0, -248410, 112704, -112704], [-1891276, 0, 352800, 0], [0, -1182716, -56552, 56552], [2517034, 2517034, 0, 375392], [1092179, 0, 292428, 0], [0, 7387, -27368, 27368], [0, -1701361, -245640, 245640], [0, 2391160, -38144, 38144], [-1104287, -1104287, 0, 620484], [-1950372, 0, 324864, 0], [620723, 0, 314136, 0], [6148588, 6148588, 0, 237696], [-3575660, -3575660, 0, 228656], [-394158, 0, 1108416, 0], [-5848007, -5848007, 0, -381000], [2431042, 2431042, 0, -871552], [0, -3318472, 425904, -425904], [-2452344, 0, -148080, 0], [-4768244, -4768244, 0, 305384], [1307900, 0, 542448, 0], [0, 1499896, -33656, 33656], [0, -2213488, -24600, 24600], [-1786656, 0, 1475616, 0], [0, -139538, -184256, 184256], [-1605030, 0, -1640640, 0], [1313624, 0, -516888, 0], [1831403, 0, -85140, 0], [5867572, 5867572, 0, 1169520], [10665303, 0, -260124, 0], [0, -5848940, 1209232, -1209232], [-3992231, -3992231, 0, 1499048], [0, -5832928, 215952, -215952], [-127177, 0, -2206224, 0], [7283296, 7283296, 0, -595048], [2291535, 0, -81936, 0], [0, -6737660, -775472, 775472], [8444893, 8444893, 0, -687504], [0, 821276, -46488, 46488], [-767626, 0, 1188000, 0], [0, -4019501, -1305440, 1305440], [-2639336, -2639336, 0, -2551296], [4139192, 0, 1438416, 0], [-232379, -232379, 0, 596552], [0, 5319836, 976560, -976560], [11192868, 0, 540792, 0], [0, -6026210, 212512, -212512], [-16060172, -16060172, 0, -894184], [0, -4370005, 1746060, -1746060], [-1785155, -1785155, 0, 1396248], [1244554, 1244554, 0, -296128], [-11519268, 0, 1618800, 0], [-17917484, -17917484, 0, 87720], [-7055721, 0, -13068, 0], [8813821, 8813821, 0, 1463532], [-7657032, 0, -3095880, 0], [4220500, 4220500, 0, 2703336], [0, 2578814, -501600, 501600], [-5464924, 0, 1049184, 0], [0, -3977708, -1830512, 1830512], [0, -8314660, 3314472, -3314472], [14236022, 0, -666144, 0], [0, -10455353, -203000, 203000], [0, -22276333, -1236648, 1236648], [-8524425, 0, -561588, 0], [0, 15173864, 1182840, -1182840], [0, 15713527, -3400724, 3400724], [-2298753, 0, 2216376, 0], [3865232, 0, 3677472, 0], [-5063603, -5063603, 0, 2335196], [0, -23693428, 1796208, -1796208], [20610456, 0, 2168040, 0], [-20195458, 0, -1954080, 0], [25484272, 25484272, 0, -606664], [16079962, 16079962, 0, -697152], [5102929, 5102929, 0, -801832], [0, 7191980, -5316240, 5316240], [16997616, 0, -1417752, 0], [0, -15312493, -1714764, 1714764], [-18695838, 0, -3532992, 0], [4912220, 0, -3375792, 0], [0, -9603056, 2772280, -2772280], [-9259664, -9259664, 0, 881952], [12392416, 12392416, 0, 1648040], [18348392, 0, -2929608, 0], [-27200939, -27200939, 0, -981880], [-5092549, 0, -1663344, 0], [0, 23740351, -670868, 670868], [-2598068, -2598068, 0, -4576024], [-23277345, 0, 3732936, 0], [0, 12071780, 623400, -623400], [-6427476, 0, 3561048, 0], [0, 5625298, 7611520, -7611520], [29153200, 29153200, 0, 4890368], [-3062140, 0, 2531304, 0], [13735273, 13735273, 0, -4312236]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_81_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_81_6_c_e();".
// 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_81_6_c_e(:prec:=4)
    chi := MakeCharacter_81_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_81_6_c_e();".
// 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_81_6_c_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_81_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![900, -90, 39, 3, 1]>],Snew);
    return Vf;
end function;