
// Make newform 33.8.a.c in Magma, downloaded from the LMFDB on 13 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_33_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_33_8_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_33_8_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
        poly := [-24, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-1, 3]];
    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_33_a();"
function MakeCharacter_33_a()
    N := 33;
    order := 1;
    char_gens := [23, 13];
    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_33_a_Hecke( : Kf := Kf)
    return MakeCharacter_33_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 := 8;
    raw_aps := [[0, 1], [-27, 0], [-90, -14], [-188, -42], [1331, 0], [-6642, 38], [-5218, 180], [5912, 2372], [-5808, -2050], [9938, -4564], [-24112, 184], [130494, 13104], [363062, 29712], [-848440, -7216], [-612368, 42642], [-1064818, -26758], [425476, 76380], [-444666, -172662], [-1631172, 2392], [-2749544, 3574], [-2665950, -118912], [-746548, -43494], [4553116, -255344], [3441562, -72992], [5189498, -481620], [3469226, 188164], [-5563296, 726364], [-17445508, 324872], [10398350, 75910], [-1149622, 1982600], [-15021892, -1829142], [26086420, 829912], [20564210, 68524], [-618704, -655092], [56110514, 492352], [14483524, -1881478], [-26749626, 820804], [3569148, 5035232], [34301344, -1786820], [27473890, -2986820], [-44891276, -4707116], [30672654, -7974220], [-30915232, -9950054], [-13184270, 9570876], [30568202, -3849996], [-195670744, -222652], [-110958360, 9752976], [47971624, 4362456], [-203750780, 7255024], [42653358, 20239140], [94832294, 6251624], [-165857672, -2282564], [102626314, -20352900], [210328252, -16901308], [-45342990, -10276784], [-343096832, -4146432], [333538582, 12843146], [-119817836, -23562442], [241821814, 21750306], [-179380514, -21572828], [-297061416, 29663408], [352767826, -1423520], [223639512, -25097876], [-159287408, 33420742], [-39202406, -33232528], [267996782, -58013994], [87754628, -50585096], [581438954, -37990488], [-741869324, 34917848], [-136884746, 9705022], [525583442, 1410728], [659466264, 25322908], [-259235560, 48435760], [-356684962, -72102674], [55468948, -11289744], [-1015186648, -34376042], [144221366, 35256530], [-84323290, -23250644], [-991939590, -60907708], [-741763710, 11239068], [-396330076, -47909516], [2309185278, 39607904], [495563080, 25038952], [-392048798, -23167560], [279682268, 3362818], [-628288652, -85003468], [-619949646, 62533940], [-2262068494, 83851220], [94787994, -58529352], [1513689208, -165684060], [-1105819188, -113492760], [-230121016, 227747248], [28361240, -44790180], [2093554652, -75722160], [-1417951564, -239507784], [-98546400, -210236468], [-2959496682, 160398378], [2433820802, 118443500], [847704152, 257073768], [1474417374, 106732046], [4295690896, 99223940], [2994411146, -226820976], [4932556396, -60911704], [1338973638, 1388436], [3897764968, 133036796], [-5718064294, 41324444], [-1281493356, -117414380], [4297922278, 43416852], [1028285104, 216998582], [-2128442534, 255683120], [-2496155348, -410391622], [-5222208642, 267883258], [-2061588926, 136527184], [6746753244, -55040792], [-3643266616, -15243752], [-1733822174, 414872068], [4560784948, 426932240], [3907118208, 3175886], [-7465731306, 245032894], [-5302800484, 186763512], [-4186897938, -41707948], [3543446722, -374328004], [2182172890, -451680740], [-9293746852, 168017116], [3681476500, -567169288], [2497865594, 126810280], [-2978948466, -130015916], [-723036928, 546345494], [-5716234968, -259096932], [-7584852146, 913743430], [7069291296, 300792424], [-7367745768, 359446636], [-11678146656, -476729608], [-9835308930, 783831928], [3796036182, -781657692], [-3077183422, 458957148], [-7002185522, -882243638], [4859633536, 1212738240], [12619885294, -462698982], [-19020651458, -11306792], [-1611506528, 19769448], [4228468106, 659467260], [-3158945920, 1574526152], [13285525764, -7105336], [-13260812906, -294877440], [8350948608, 143915242], [-10032233170, 702248706], [26334976734, -137614216], [8103771412, 451976560], [-13393536632, 1170529642], [-6918741930, -956328354], [21311829178, -155959848], [21822798172, -950591232], [-10984233864, -671345596], [2790769212, -2674196448], [-18291176576, -1053107858], [-25413046164, 1074297902], [-9559611142, -287362588], [17703064762, 1159797200], [27807574418, -347467660], [5067750676, 930710968], [724396446, 665910136], [-14803174700, 80770146], [-10506619564, 403854748], [-15676339926, -1533510660], [-27440688640, -204917242], [-8744785856, 2927981304], [41783447854, -788118682]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_33_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_33_8_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_33_8_a_c(:prec:=2)
    chi := MakeCharacter_33_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 8));
    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_33_8_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_33_8_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_33_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![-218, -1, 1]>],Snew);
    return Vf;
end function;