
// Make newform 81.6.c.g 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_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_81_6_c_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 := [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 := [[1, 1, 0, -1], [0, 0, 0, 0], [0, 13, 4, -4], [52, 52, 0, -24], [-128, -128, 0, 56], [0, -193, 156, -156], [-1587, 0, -24, 0], [-1204, 0, -72, 0], [0, 2368, -296, 296], [-809, -809, 0, -892], [0, -3892, -816, 816], [-2113, 0, -1044, 0], [0, -6554, -992, 992], [4120, 4120, 0, -2616], [-3812, -3812, 0, 320], [22410, 0, -864, 0], [0, -34880, 2992, -2992], [-8831, -8831, 0, -3444], [0, -3892, -2616, 2616], [17700, 0, 10632, 0], [1307, 0, -2160, 0], [25360, 25360, 0, 6456], [-21284, -21284, 0, -12304], [-30003, 0, -10992, 0], [97918, 97918, 0, 1056], [-97610, -97610, 0, 8096], [0, -135220, 9696, -9696], [-47844, 0, -22464, 0], [-49381, 0, 8460, 0], [0, 21937, 35536, -35536], [12080, 0, -3528, 0], [0, -115676, -18872, 18872], [-114857, -114857, 0, -16120], [0, 112964, -32784, 32784], [0, -209495, -9236, 9236], [87064, 87064, 0, 29712], [0, -42205, -50604, 50604], [245864, 0, -7632, 0], [0, -116132, 15592, -15592], [-45389, -45389, 0, 19100], [309660, 0, -1824, 0], [305894, 0, 42912, 0], [402148, 402148, 0, 152], [0, 626531, 54840, -54840], [-593331, 0, -32484, 0], [-740212, 0, -36144, 0], [0, -575320, 96168, -96168], [-123176, -123176, 0, -10824], [370204, 370204, 0, -9016], [0, -197833, -114108, 114108], [-802875, 0, -13488, 0], [0, 961372, -8864, 8864], [-330851, -330851, 0, 157224], [336648, 0, 151800, 0], [0, 427057, 223936, -223936], [1412068, 1412068, 0, -98176], [314181, 0, -138924, 0], [282800, 0, 306504, 0], [-1806950, -1806950, 0, -141504], [-152021, -152021, 0, -165760], [0, -240628, 50592, -50592], [0, -822167, 143740, -143740], [-305404, 0, -192672, 0], [0, -92360, 215008, -215008], [-985079, -985079, 0, 185736], [-2393861, -2393861, 0, 135356], [292732, 292732, 0, 400008], [0, 613058, -390048, 390048], [0, -596708, -129896, 129896], [1080034, 1080034, 0, 9696], [-2067182, -2067182, 0, 128960], [1592256, 0, -398136, 0], [182104, 182104, 0, 482016], [0, -135706, -112704, 112704], [-2244076, 0, -352800, 0], [0, 1239268, -56552, 56552], [-2141642, -2141642, 0, 375392], [799751, 0, -292428, 0], [0, 19981, -27368, 27368], [0, -1947001, 245640, -245640], [0, -2353016, -38144, 38144], [-1724771, -1724771, 0, -620484], [2275236, 0, 324864, 0], [306587, 0, -314136, 0], [5910892, 5910892, 0, -237696], [3804316, 3804316, 0, 228656], [1502574, 0, 1108416, 0], [-5467007, -5467007, 0, 381000], [-3302594, -3302594, 0, -871552], [0, -2892568, -425904, 425904], [2304264, 0, -148080, 0], [5073628, 5073628, 0, 305384], [765452, 0, -542448, 0], [0, -1466240, -33656, 33656], [0, -2238088, 24600, -24600], [3262272, 0, 1475616, 0], [0, 323794, -184256, 184256], [-35610, 0, -1640640, 0], [1830512, 0, 516888, 0], [1916543, 0, 85140, 0], [4698052, 4698052, 0, -1169520], [-10925427, 0, -260124, 0], [0, 4639708, 1209232, -1209232], [5491279, 5491279, 0, 1499048], [0, -5616976, -215952, 215952], [2079047, 0, 2206224, 0], [-7878344, -7878344, 0, -595048], [-2373471, 0, -81936, 0], [0, 7513132, -775472, 775472], [9132397, 9132397, 0, 687504], [0, 774788, 46488, -46488], [-1955626, 0, -1188000, 0], [0, 5324941, -1305440, 1305440], [-88040, -88040, 0, 2551296], [2700776, 0, -1438416, 0], [828931, 828931, 0, 596552], [0, 6296396, -976560, 976560], [-10652076, 0, 540792, 0], [0, 5813698, 212512, -212512], [15165988, 15165988, 0, -894184], [0, -2623945, -1746060, 1746060], [-3181403, -3181403, 0, -1396248], [-1540682, -1540682, 0, -296128], [13138068, 0, 1618800, 0], [-18005204, -18005204, 0, -87720], [7042653, 0, -13068, 0], [7350289, 7350289, 0, -1463532], [4561152, 0, -3095880, 0], [1517164, 1517164, 0, -2703336], [0, 2077214, 501600, -501600], [-6514108, 0, -1049184, 0], [0, 5808220, -1830512, 1830512], [0, -5000188, -3314472, 3314472], [14902166, 0, 666144, 0], [0, 10658353, -203000, 203000], [0, -23512981, 1236648, -1236648], [7962837, 0, -561588, 0], [0, 16356704, -1182840, 1182840], [0, -12312803, -3400724, 3400724], [4515129, 0, 2216376, 0], [187760, 0, -3677472, 0], [7398799, 7398799, 0, 2335196], [0, -21897220, -1796208, 1796208], [-18442416, 0, 2168040, 0], [-18241378, 0, 1954080, 0], [-26090936, -26090936, 0, -606664], [16777114, 16777114, 0, 697152], [-5904761, -5904761, 0, -801832], [0, 1875740, 5316240, -5316240], [-18415368, 0, -1417752, 0], [0, -17027257, 1714764, -1714764], [15162846, 0, -3532992, 0], [8288012, 0, 3375792, 0], [0, 6830776, 2772280, -2772280], [-10141616, -10141616, 0, -881952], [-10744376, -10744376, 0, 1648040], [21278000, 0, 2929608, 0], [26219059, 26219059, 0, -981880], [-3429205, 0, 1663344, 0], [0, -23069483, -670868, 670868], [-1977956, -1977956, 0, -4576024], [27010281, 0, 3732936, 0], [0, 12695180, -623400, 623400], [9988524, 0, 3561048, 0], [0, -13236818, 7611520, -7611520], [-24262832, -24262832, 0, 4890368], [-5593444, 0, -2531304, 0], [18047509, 18047509, 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_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_81_6_c_g(: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_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_81_6_c_g( : 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;