
// Make newform 882.6.a.bb in Magma, downloaded from the LMFDB on 26 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_882_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_882_6_a_bb();".
// 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_882_6_a_bb();".
// 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 := [-2400, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_882_a();"
function MakeCharacter_882_a()
    N := 882;
    order := 1;
    char_gens := [785, 199];
    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_882_a_Hecke(Kf)
    return MakeCharacter_882_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 := 6;
    raw_aps := [[-4, 0], [0, 0], [-26, -1], [0, 0], [-98, 5], [195, -11], [-160, -20], [865, 39], [-1616, -4], [-2260, 61], [-915, -164], [10319, -51], [4374, 66], [7883, 87], [16878, 156], [-24732, 225], [-28388, 41], [-33738, -32], [37693, 337], [3826, 1340], [1163, 875], [12813, 986], [410, -1769], [88176, 210], [65702, -1981], [-17750, 992], [-114923, 315], [70584, 1509], [-33611, -2975], [38, -3998], [-2733, -622], [70606, -1645], [-39172, 1174], [32645, 2753], [51660, -6378], [-81080, 7279], [165070, -7146], [-82516, 3480], [473782, 1124], [-216296, 5054], [-252030, 10098], [-335073, -695], [107202, 7638], [-583525, 5106], [612640, -9106], [-380264, 6564], [188060, 5934], [-581912, -1149], [-755970, 4653], [-418609, -10387], [293146, 8378], [699870, -4026], [-864494, -6945], [-554136, 13173], [-1151862, 888], [326244, -37038], [-978338, -23371], [-1597464, 7453], [-1797679, -993], [419476, 37658], [-1650163, 6329], [-1745256, -9801], [-858697, -18571], [-463442, 37706], [-1750591, 10742], [-323832, -47607], [393041, -5061], [774165, -40132], [-3040320, -8652], [-794002, -4504], [-534126, 42390], [-1473052, 28762], [-768821, -56160], [475, -45587], [4100701, 5947], [1314812, -51374], [-2569954, 10420], [775581, 61183], [-1483980, 6036], [937363, 68022], [-1690254, 31854], [-1223931, 33689], [-2248266, -48186], [-1693319, -98727], [655992, 23533], [380284, 34139], [-918622, -97130], [1017805, -14126], [606052, -81442], [4838149, -20381], [-381590, 65186], [-1494148, 56530], [230045, 121356], [-2258892, 125235], [291379, 155263], [-4455342, 35310], [2857146, 21081], [6146892, 17250], [2554687, -8943], [3918945, 36101], [-3484332, 116480], [7992506, -25319], [-495046, -185345], [9286698, 94398], [-2040021, -6433], [-3684583, -26800], [213248, 75523], [-682326, -37470], [-7400148, 4506], [-10510943, -14988], [6010755, 162172], [-7372254, -5182], [3572998, 16928], [11058731, -40717], [-5854384, -29823], [2207392, -119122], [5050909, 135525], [-11245914, 26376], [9132006, -163779], [-3885452, -123964], [12605, -53359], [-14745505, -5586], [-4646772, -28011], [-9933948, -22995], [9565483, 19989], [-6860608, 284233], [1117502, 31848], [5350458, 31824], [9179687, -268594], [10757091, -377381], [18723735, -54205], [-9573726, -116616], [13997487, 171746], [1716762, 430736], [10067552, -94160], [-4022095, 241514], [2178598, -38572], [15363096, -128846], [-6163800, -412023], [5217842, -615722], [-954928, 115646], [3845830, 42623], [14854552, -84632], [-10031166, 374901], [9397835, -268171], [2987516, 371560], [16119817, -323967], [1813824, -411786], [-38268536, -19254], [-1278814, -345212], [-8108390, -26618], [466392, 258942], [17630429, 25443], [7659882, 687954], [10961205, 709583], [5463384, -566070], [-28870523, -75149], [-9888306, -721860], [-5955839, 47484], [4237612, -174691], [-9011962, 33322], [-18883052, -373942], [21507377, -170418], [-15182580, -1269], [-2503086, -11796], [29755884, -257328], [-18564613, -503160], [5971681, 377745], [6915317, -668286], [-46456704, -24999], [53264, -215507], [-6745822, -55660], [-29630868, -489732], [-6434139, -1096], [-3716751, 1032190], [2242432, -278308], [12177933, -198991], [10300318, -303823], [-17299280, 354096], [41186125, -275451], [25233855, -372184], [48694160, 28555], [22874701, 654385], [-19830668, 453470], [-7747198, -504368], [42259596, 194097], [-40733586, -231508], [-4350137, 290919], [-7296231, 1203218], [44320398, -299766], [-33342433, 587744], [41438874, 480387], [-18204056, -681944], [37238540, 991714], [-40136460, -402117], [5138840, 410806], [3247451, 381819], [-38077298, -554420], [27608898, -728748], [-12233292, 243174], [-12844662, -122487], [13996275, 95077], [-28581494, 1095360], [12934542, -263408], [34834266, -169338], [21601074, -1351011], [-51925040, -434064], [-3521226, -294177], [14797956, 745080], [62644612, 538206], [6567623, -1421829], [-27492632, 903473], [6329268, -1118149], [-68557028, -749713], [-63289740, -1087836], [57780385, -84867], [1490272, -475907], [39482108, -700328], [-77686388, 731270], [-68452634, 580904], [21886801, -1189121], [-26766343, -819673], [28031118, 1655112], [-87972344, -199085], [-52202322, -893223], [-92344678, 1201854], [102949736, -454634], [-4364950, -726974], [-64773, 1036666], [-112533366, 290082], [20361945, 1114109], [16101908, 2328548], [-33906395, -680414], [-85923294, 564708], [-45887519, 1007577], [-8050746, 2630826], [-10434421, -700294], [66563154, -379779], [78300084, -994824], [50217358, 171830], [79557454, -1476706], [25204465, -1758801], [-81698447, -1770198], [-44892066, 432236], [-102308200, 601912], [-74544156, 287736], [-96514641, -968894], [-120841906, -616274], [-61943224, -285864], [34890984, -492168], [-102722663, -1582775], [3268632, -3008646], [37713090, -1189980], [-50568277, -232045], [134260160, -605381], [17391976, -1080997], [168708389, 394569], [-26936673, -1307195], [-51292358, 2096585], [104734834, -1093023], [-149068391, 1167415], [115846088, 123751], [6504263, -641605], [55201169, -461173], [-79200114, -425652], [110249873, -2505043], [42434670, 1226841], [80823802, -1935754], [-100233668, 1326424], [187836018, -404067], [61236009, 1908007], [-108732604, 1897530], [95429499, -33896], [-41221747, -3044796], [-107618602, -512323], [1403676, 1909900], [132705418, 500915], [-38934597, 279161], [69463651, 2045827], [-70947480, 2727288], [-109454424, -2788230], [-6101403, -1615234], [7353414, 2799138], [50812141, -2408601], [-1480668, -882782], [-65376290, 2708054], [118043049, -59674], [-202626782, -1368979], [81583945, -1285098], [191131698, 96930], [-146972772, -1586322], [-102833916, -2111649], [158284554, -367518], [35106724, 3661736], [2577719, -2316663], [9516150, 4696731], [193837333, 318987], [46118532, -3372510], [24426738, -2179662], [-108810465, 4628011], [-11466286, -4551016], [-13208418, -3609351], [88001932, 566101], [-33088212, -1282341], [153332915, -2872053], [-21805243, -5925507], [-45232102, 2792533], [243670123, 2081655], [-43898336, -4833490], [-83473225, 101559], [106781196, 4526550], [-48928450, -5615600], [-260912890, -1103390], [-125451616, -2004432], [47524520, -4255988], [81918151, -3006189], [141669894, 3785055], [-369889552, 41884], [162970159, -4360572], [-303743034, 1373058], [-53383499, -1015197], [259972519, 1128115], [-259264290, -1156287], [-6613619, -686357], [-45582166, 5074438], [-107500505, 2020902], [74013065, -2689623], [-287170939, 1917761], [-56074100, 4213622], [71427322, -395047], [964421, -2785959], [-11318486, 5087477], [201979869, -1210181], [45875822, -8142806], [161191885, 3561865], [23975302, -4789354], [216071418, 3057422], [194974204, -538030], [-108351365, 1166244], [-5890255, 1297634], [-298222213, -881649], [82935360, -188304], [-273656064, 65487], [19379919, -7203082], [303024426, -729465], [67759494, 8421987], [-44752277, -2910273], [137558300, 2579094], [135307290, -1401516], [-108318606, -1921539], [-293784068, -1805748], [43524458, 1526673], [-181012554, 964656], [-122015208, 2893663], [-39866261, 159751], [-26377678, 1150360], [-310283414, 3420464], [7248060, 6508545], [333591232, 1812356], [261667102, -1960648], [38843002, 5435332], [-157054858, 7634722], [177915878, -1219388], [-543703886, -567406], [39106337, 3437747], [-115551898, -6304227], [630744, 7772514], [26112315, -11204059], [-246177554, 2469907], [-80733260, -6923719], [285890501, -780277], [326871762, -1206276], [143880866, -3926945], [31756835, 3274805], [-228440579, 7928623], [-232887000, 8079504], [107433880, 6134168], [268748354, -5724205], [-359429644, 2327890], [-463998377, -785685], [458250768, 4297806], [162989828, 1305022], [-134904848, 164152], [157297284, -6396180], [34471052, -3783682], [-218639444, 4799126], [211124933, 6580659], [279138770, 44954], [-395177795, -6687749], [-384109486, -2648666], [123070985, 1748040], [26935278, -11948544], [129879076, 8890403], [-244623161, 1837359], [-468779182, -1848836], [83475354, 8429789], [-29053156, 13189715], [-18038494, -11560604], [188835345, -3143845], [74189362, 3065621], [-37594622, 3517158], [-136874028, -11460480], [91925272, -5393276], [-208984550, 9463964], [154644426, -5355735], [-554087915, -3191394], [-206521202, -3997736], [-261246132, -2468598], [302811781, 506253], [397213652, 6644557], [73918094, 12529427], [541334212, -5166481], [-68434256, -8933743], [-55682628, -7689286], [-162964615, -6955335], [382154738, -8376503], [128046778, -1438414], [42792629, -3299245], [326253804, 3960048], [111742720, -3459886], [465065800, -1046581], [126200437, -11519811], [-248345096, 5851214], [306214398, 7311339], [-489729494, 8996364], [-684814454, -3685168], [26208362, 6685075], [-16316952, 6394644], [417638724, 7140118], [466678232, 2644516]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_882_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_882_6_a_bb();".
// 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_882_6_a_bb(:prec:=2)
    chi := MakeCharacter_882_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_882_6_a_bb();".
// 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_882_6_a_bb( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_882_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-1698, 53, 1]>,<11,R![-50886, 191, 1]>],Snew);
    return Vf;
end function;