
// Make newform 33.8.a.e in Magma, downloaded from the LMFDB on 18 April 2024.
// 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_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_33_8_a_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 := [28880, -1544, -510, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-254, -6, 1, 0], [1352, -340, -11, 1]];
    Rf_basisdens := [1, 1, 1, 6];
    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)
    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+1)]];
    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 := [[4, -1, 0, 0], [27, 0, 0, 0], [74, 10, 0, 1], [230, -32, -2, -2], [1331, 0, 0, 0], [-514, 206, -28, 15], [8000, 842, -14, -21], [-3430, 810, -126, 43], [27864, 3414, 12, -149], [-25452, -3254, -110, -349], [-7016, 3832, 744, 532], [-126982, 8708, -364, -610], [180316, 13602, 310, -1477], [-56034, 25034, 2814, 119], [496912, 11674, 3428, 1677], [250110, -74378, -3908, 1883], [348820, -54068, -11944, 582], [1016210, -66010, 56, -1057], [439412, -36688, -1048, 3760], [1378400, 62262, 4004, -7581], [1425918, -94460, 8684, -6122], [-1925610, -18508, -10722, 16], [909448, -186716, 19220, 16670], [1121490, 107288, -18280, 6580], [414422, -269112, -13116, 27384], [5464172, -228070, 51058, 20891], [4829476, -191544, 25340, -25104], [-10084088, 43644, -45092, -11598], [-6141978, 675398, -61476, -14733], [-1340994, 487540, -20300, -25354], [-14505522, 308348, 53718, 51004], [1325844, -653080, 96824, 87532], [-10088266, -1200640, 46972, 9644], [-17338694, -361510, -239174, -2661], [-16799096, -1277190, 234814, -74489], [-19363730, -1135468, 176830, -83264], [-2513986, -472468, 165728, 170206], [154248, -172628, 187892, 55234], [37974572, 3016776, 3908, -153288], [-52335476, 1587298, -244246, -80185], [49039468, 1751812, -192616, 211634], [-76351346, -2248548, -64024, 132926], [18697448, -1707286, -478676, 246365], [-68574614, 1153028, 284752, -155190], [-22110620, -66030, 196282, 492431], [98749328, -4183932, -317760, -208934], [-9510398, -2565786, -39646, 376033], [-52425508, 4108084, -933020, -297002], [115943744, 566340, -300388, 15174], [-75079998, -7151336, -465628, 41328], [-52002068, 7945050, 221782, 79287], [59213428, 902776, 1158260, 792896], [-83225978, 5582144, 608692, -192636], [100229452, 6759436, 422672, 372574], [25402274, 7621024, -375840, -244880], [-136696116, -8638372, -1198132, -633982], [273056478, -6145186, 679364, -390681], [82394994, 5622516, 70234, -1234068], [178189086, 13399314, -144140, 178649], [-144666596, -4547618, 260990, -379591], [40317734, -915934, -589978, -971109], [-110650872, 2508002, -754594, 1173067], [305144482, 3552378, 764426, 1042203], [-155782616, 2010094, 4293356, -1381369], [-292648426, 29552764, 264868, -825382], [196528874, -34422130, 1100608, -78309], [-163205968, -27902796, 3167700, 951350], [-656272330, 14583372, 2360892, 1307226], [-12278584, -21409356, -3506884, 457166], [-238786374, 3732018, 103288, -2861267], [-186912918, 95392, 4217800, -174952], [245342584, -50075572, -3709800, -28602], [475391452, 45042844, -15228, -643910], [230265354, -40566646, -4048560, -2975103], [6197144, 10592020, -5264468, -353858], [-451554840, 10902454, 783556, 2437491], [897118234, -13759302, -1571216, -580599], [543447458, -20386320, 1209948, 358724], [-337633978, -46925648, 40500, 2768220], [-422625826, 63790160, 1357076, -2399380], [-954252276, -43796684, 5731336, 879930], [152573326, 34150200, 1179248, -86596], [-304684228, 134701452, 330500, -804750], [304750102, -66721444, -467492, 4812834], [768972730, 31534840, -6569454, 3688462], [-1675490380, -88613100, 5172296, -1553014], [-716986838, -50133724, -4867632, -4540390], [1004184286, -61803992, -9312396, -986808], [231896224, -9052054, 16904334, -443393], [1237256212, -40327096, -1748588, -5098008], [810228020, -68666528, -7409064, -1980856], [332640028, 94951044, 405508, 7926622], [2062221624, -91932988, -7079544, 1136962], [-839969496, -30200012, -5151956, -11488178], [754401964, 58959256, 1338720, 350108], [340492588, 43846808, -15499020, 6206640], [71826590, 136233550, 9364116, 14361647], [1795530350, 97567112, -11050364, 705448], [2086394270, 19676514, 5825166, -3783549], [-2616706578, 26759782, -2819692, -3614789], [-1270182194, 20398718, 9580174, -3658583], [3137013016, 258350586, -15958010, 4517759], [-4893246300, 49619312, 1391624, 5173632], [2216333824, -54135550, -508278, -7584113], [-4220826906, -132514602, -5831954, 10084101], [-2412015406, -186792492, 3286296, -2553878], [-1617381132, 66351540, -4895400, 10408778], [-2100467980, -41595090, 407726, -17421839], [-3745568880, 130457414, -11580124, 8072187], [-1998274270, -138498200, 8280520, 23265356], [-4116548186, 36625364, -16791554, -3095648], [-857756806, -79688362, 16144808, -6887897], [5783447886, -163769740, -1810948, -11293442], [-1063869848, 539789580, -17056804, -12951894], [3675777200, 72660600, 22163736, -12759772], [-1271830566, -285323980, -22640224, -11593934], [-1885573976, 236913212, 15562516, 26132314], [308697320, -353173898, 23990604, 10644315], [7586560006, 113763266, -8522220, 1484961], [-10271902860, -30599792, 2860408, 15144736], [4070982822, 196061356, -6798208, 5138014], [-1018306902, -16994748, 34858864, 5063658], [4356959892, -469663606, -15087718, 2097835], [619882580, -102989332, -23130488, -25851322], [-1693140272, 152583596, -7999988, -12639734], [-146798928, -270083606, -6697298, 27088719], [-7892515758, 417018568, -14695948, -14199112], [5920710704, -253590658, -26283956, -10994849], [2287230232, 369975396, 2103512, -10748030], [-5206543242, 12243846, -21286052, 12423571], [107998334, -176689990, 43447478, -4793561], [3490515096, 507522684, 33015000, -25386274], [7177437472, -524317200, -10886416, -3114712], [-8885280706, -391332832, 41339648, 1728016], [2682069928, 419273258, -76439550, 11256427], [-3542152462, 132556332, 29250792, -1017690], [1817275454, 101188806, 69952364, 17132115], [2673308174, -910796750, -3523610, 27544195], [8214538930, -21627086, -12103984, -12180651], [8942213080, 670975318, 21897530, -415135], [5513953186, 41679110, 13761946, 29387145], [2724519500, 284039330, 10596850, -19560849], [17054136196, -175516220, -31640124, -8905602], [-7899057384, -461455260, 15590412, -13394282], [-4745503694, -593659348, 37381876, -19019166], [-1147375928, -955447630, 8932164, -13069863], [-9264642174, -284531002, -59954688, -76284425], [-3511787904, -25426530, -43020318, 29565373], [-119121952, -292985924, 70269028, -23487078], [8895250920, 246410, 12222956, -32095619], [-7820536206, 88810954, 54182960, 37591905], [-3162208170, 694730540, 89107004, -25438966], [899943828, -200875224, 14113192, -27528676], [1269622480, -457928308, 82660608, 53580398], [6789258280, 980677476, -331156, 19406710], [-1554382096, 1473628278, -75727492, -38557125], [13433463034, -1309391796, -43765414, 29329160], [2026938862, -1006998120, -61385156, -82936248], [-1821095894, -2006377264, 53150128, -6232520], [11418386052, 402662122, -112221614, 20908787], [-23471812708, 616519848, 56646128, -4122348], [-36417011392, 407727214, 33246690, 30086245], [-1880862170, 535796948, -32925338, -43892184], [-6343725796, 325012580, -10695584, 31749866], [-6359717330, 244441088, -61404036, -93586580], [7815878592, 234970486, 8121652, -144546493], [24122758248, -682612440, -36286952, -33125092], [-19463009142, -804251454, 48060592, -25900563]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_33_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_33_8_a_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_33_8_a_e(:prec:=4)
    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_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_33_8_a_e( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_33_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,8,sign)));
    Vf := Kernel([<2,R![14736, 5416, -426, -15, 1]>],Snew);
    return Vf;
end function;