
// Make newform 81.12.c.f in Magma, downloaded from the LMFDB on 05 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_12_c_f();".
// 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_12_c_f();".
// 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 := [64, -8, -7, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [-64, -7, 7, 1], [12, 45, 3, -3], [-744, 315, 21, 51]];
    Rf_basisdens := [1, 56, 2, 28];
    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 := 12;
    raw_aps := [[0, 0, 0, 1], [0, 0, 0, 0], [0, 0, -10, 10], [50071, 50071, 0, 0], [0, 0, 0, -9554], [0, 1039121, 0, 0], [0, 0, 100902, 0], [-579301, 0, 0, 0], [0, 0, 118670, -118670], [0, 0, 0, 3197296], [0, -89057548, 0, 0], [-566931913, 0, 0, 0], [0, 0, -23233696, 23233696], [-1257516392, -1257516392, 0, 0], [0, 0, 0, 50254198], [0, 0, -84450132, 0], [0, 0, 60259742, -60259742], [1112205613, 1112205613, 0, 0], [0, 4034467871, 0, 0], [0, 0, 122107188, 0], [-31135508287, 0, 0, 0], [617559745, 617559745, 0, 0], [0, 0, 0, -83402324], [0, 0, -90530850, 0], [104737106371, 104737106371, 0, 0], [0, 0, 0, -924534992], [0, -6247263979, 0, 0], [0, 0, 3146443830, 0], [24183077258, 0, 0, 0], [0, 0, -5746825774, 5746825774], [-624548755924, 0, 0, 0], [0, 0, -763829608, 763829608], [0, 0, 0, 10091774926], [0, -820573790563, 0, 0], [0, 0, 2033963516, -2033963516], [442760819701, 442760819701, 0, 0], [0, -1380813005242, 0, 0], [1604680267637, 0, 0, 0], [0, 0, 43352669654, -43352669654], [0, 0, 0, 37564987360], [0, 0, 9585824988, 0], [3915885813149, 0, 0, 0], [0, 0, 0, 39913779034], [0, -5210242610329, 0, 0], [0, 0, 81013126434, 0], [-4182840348739, 0, 0, 0], [0, 7563095487593, 0, 0], [573122576308, 573122576308, 0, 0], [0, 0, 0, 192070634908], [0, 9400474034, 0, 0], [0, 0, 16111263864, 0], [0, 0, 32787609404, -32787609404], [-18631723344305, -18631723344305, 0, 0], [0, 0, 255016196088, 0], [0, 0, 267877850636, -267877850636], [0, 0, 0, -560604937052], [0, 0, -73611146826, 0], [-14614723041469, 0, 0, 0], [15914230961134, 15914230961134, 0, 0], [0, 0, 0, 40410764608], [0, -8181570432592, 0, 0], [0, 0, 639194771570, -639194771570], [72175587168800, 0, 0, 0], [0, 0, -1270793973958, 1270793973958], [57840506204197, 57840506204197, 0, 0], [0, 0, 0, -351365889908], [-47969363300117, -47969363300117, 0, 0], [0, -84601891319131, 0, 0], [0, 0, 2986704758444, -2986704758444], [-79519412054255, -79519412054255, 0, 0], [0, 0, 0, -227998240820], [0, 0, 2316947652438, 0], [-187648887961805, -187648887961805, 0, 0], [0, -141420089027953, 0, 0], [123349618386335, 0, 0, 0], [0, 0, -1105473910096, 1105473910096], [0, 0, 0, -4754049103418], [-73345299917002, 0, 0, 0], [0, 0, 4140556609604, -4140556609604], [0, 18382855229225, 0, 0], [0, 0, -1313665834282, 1313665834282], [-205437800018273, -205437800018273, 0, 0], [0, 0, -5757524305038, 0], [-249325408280302, 0, 0, 0], [-589695736146764, -589695736146764, 0, 0], [0, 0, 0, 7571455259260], [0, 0, 6189919844250, 0], [-51004007988566, -51004007988566, 0, 0], [0, 0, 0, 9749910736234], [0, 609318870555545, 0, 0], [0, 0, 6879184703034, 0], [0, 0, 0, -8312018237804], [323112955092113, 0, 0, 0], [0, 0, -9922168153270, 9922168153270], [0, 287587471246784, 0, 0], [0, 0, -241284202350, 0], [0, 0, 17608256385278, -17608256385278], [0, 0, 11102800205562, 0], [-979906792241113, 0, 0, 0], [-128083633264375, 0, 0, 0], [430639006937971, 430639006937971, 0, 0], [0, 0, 20002055731014, 0], [0, 0, -11393245977808, 11393245977808], [0, 0, 0, 19351493370010], [0, 381991488465275, 0, 0], [-430812088341685, 0, 0, 0], [0, 0, 0, 32430595160194], [0, 0, -46697382582732, 0], [0, 0, 19925302066928, -19925302066928], [2203544793376390, 2203544793376390, 0, 0], [0, 1893319891624673, 0, 0], [-707135396852437, 0, 0, 0], [0, 0, -65393427904330, 65393427904330], [-656529394840331, -656529394840331, 0, 0], [-2414021666455933, 0, 0, 0], [0, 0, 0, -25427229290516], [0, 2810765497300856, 0, 0], [0, 0, 85287587385168, 0], [0, 0, 52571204546804, -52571204546804], [0, 0, 0, -73650324501716], [0, -4354364703378277, 0, 0], [2412881936379445, 2412881936379445, 0, 0], [0, 0, 0, -81119184771266], [0, 0, -42468157094664, 0], [68573247489400, 68573247489400, 0, 0], [0, 0, 42082648259814, 0], [-6783942745199417, -6783942745199417, 0, 0], [0, 0, -36674517052788, 0], [4765519732463356, 4765519732463356, 0, 0], [0, 6777677017652282, 0, 0], [9814434094562240, 0, 0, 0], [0, 0, -136659743434690, 136659743434690], [0, -8759803239444457, 0, 0], [-2587443755953039, 0, 0, 0], [0, 0, 10410571463354, -10410571463354], [0, 623647888916111, 0, 0], [0, 0, 30418253514804, 0], [0, -7605212829693805, 0, 0], [0, 0, 175409756459336, -175409756459336], [0, 0, 100926214217676, 0], [-8882793699035848, 0, 0, 0], [0, 0, 0, 62900598554158], [0, -16855397659022077, 0, 0], [0, 0, 353473602959802, 0], [13624490340006293, 0, 0, 0], [0, 0, 0, -31355389473740], [-5234697480739631, -5234697480739631, 0, 0], [0, 0, 0, 3952874616244], [0, 1432321426867697, 0, 0], [0, 0, 193537090968570, 0], [0, -28336441531304305, 0, 0], [0, 0, -225133684728486, 0], [-23013498487447411, 0, 0, 0], [0, 0, 448111434495668, -448111434495668], [19939915893396721, 19939915893396721, 0, 0], [0, 0, 0, -77373807424040], [-7092801411645148, 0, 0, 0], [0, 0, 0, -167852253022556], [10966515926120363, 0, 0, 0], [0, 0, -640219292277070, 640219292277070], [0, 0, 0, 339828777269074], [0, 0, 653378789820246, 0], [0, 10124910962521919, 0, 0], [0, 0, -823128392170026, 0], [0, 0, 438594415276076, -438594415276076], [0, 0, 0, -226349036356838], [34856423459567453, 0, 0, 0], [-48158911713279614, -48158911713279614, 0, 0]];
    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_12_c_f();".
// 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_12_c_f(:prec:=4)
    chi := MakeCharacter_81_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_12_c_f();".
// 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_12_c_f( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_81_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<2,R![11209104, 0, 3348, 0, 1]>],Snew);
    return Vf;
end function;