
// Make newform 165.6.a.c in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_165_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_165_6_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_165_6_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 := [8, -26, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-17, -1, 1]];
    Rf_basisdens := [1, 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_165_a();"
function MakeCharacter_165_a()
    N := 165;
    order := 1;
    char_gens := [56, 67, 46];
    v := [1, 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_165_a_Hecke(Kf)
    return MakeCharacter_165_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 := 6;
    raw_aps := [[1, -1, 0], [-9, 0, 0], [25, 0, 0], [-14, -20, -6], [121, 0, 0], [90, -24, 44], [100, 236, -102], [-994, 172, -46], [-464, 688, 64], [-1840, 652, 330], [-4956, -56, -44], [-2130, -448, 648], [-2264, -1804, -330], [-11850, 1340, 618], [-7820, -1544, 364], [-7126, -360, -1196], [-1988, -4928, -2864], [8262, 432, -616], [4524, 3360, -64], [1552, -3376, 3576], [846, -1656, 1028], [-8130, -8252, -4202], [-15284, -5744, 2800], [-66838, 8896, 2640], [87090, -13696, -48], [-51080, -21204, 4202], [-9196, 2344, -12220], [86460, 6496, 12824], [53802, 17448, 11804], [-20794, 38600, -460], [95874, 5020, -12686], [-192028, -23232, -704], [48542, -4952, -10764], [-82874, -24052, 12866], [164, 11732, -1546], [-101962, -40284, -14250], [250998, -65696, -5576], [4696, -15000, 29164], [-417496, 70768, 11304], [-4176, 69436, -32182], [-240120, -8264, 12884], [-147074, -110512, 13304], [-657912, -3280, -3944], [54266, -53696, 20264], [-305832, -27972, -27654], [-208132, -37144, -38060], [-619250, 17100, -4334], [357612, -124504, -7740], [-103228, -48832, -4504], [418798, 88304, -31528], [-87464, 29652, -1786], [-49980, 304952, 12100], [-558642, 289736, 38508], [-326560, -43048, 43028], [123826, -347376, -16480], [-223344, -131520, 4896], [300098, 124120, -37356], [177938, 167356, 12746], [628378, -340776, 11620], [252920, -271884, -40490], [520422, 50876, 64554], [1793788, -112716, -11698], [679794, -152268, -56482], [-802412, -94296, -48676], [-1952366, 147504, -47624], [839734, -17328, 74984], [311556, 573792, -72280], [2653342, -4040, -21204], [-131340, 446288, -73472], [-74754, 205120, -190352], [951346, -545552, -53600], [372840, 597216, 17280], [-124412, -731208, 19516], [2353350, 235136, -67200], [-1565124, -427024, 184992], [-12328, -357328, -296128], [-2280834, -76112, 104264], [597638, 618432, -47976], [-2110266, 94456, -83260], [243862, 88168, -93684], [-2619544, -138280, 141956], [2162262, 765856, -179648], [-3566836, 151816, 4380], [-3279718, -251728, 97576], [113634, -293012, 190786], [1333080, 141336, 158772], [-411350, 116656, 373768], [-484506, -589096, 138012], [2837948, -1059884, -44394], [-352452, -845432, -356156], [-6191520, -141224, -125452], [-127316, 1374952, -260612], [1631704, -1795744, -39832], [2816320, -862408, 208836], [-996928, -209768, -179620], [2682888, 86992, 451400], [-679446, 634088, -356084], [-2104106, 795848, -420516], [852702, 1153132, -419438], [4861242, -889368, -247588], [1040934, -6516, -121678], [-4877108, 205476, 37910], [-3677120, 838152, -500332], [3818596, -986564, -516398], [9156682, -89884, 19574], [-3832894, 179232, 444768], [-5829688, -16520, -204060], [2922320, 1066996, -275178], [-8458300, -768984, -496964], [14345946, 80480, -69120], [-1067342, 230108, 290978], [-119154, -393680, 121336], [7292694, -1089992, -352564], [2632468, 2171808, 338536], [2628412, 2187912, 318004], [6021874, 115072, 501904], [-6404408, 2684744, 650492], [-7159504, 1600528, 203232], [-477446, 1171144, 515500], [-2714876, -3292800, 385088], [10707430, 248032, -236832], [635562, -4116768, -48712], [-6522712, -1322788, -248854], [-2059068, -2354496, -432576], [3298988, 1321152, 34248], [-965092, -194924, -738042], [-11681106, 3714992, 529272], [-16183528, 1216176, 179464], [-646248, 1051744, -413384], [77106, 3739352, 280116], [-13670630, 238324, -349362], [-1548612, -240344, -776740], [5380636, 4340248, 154236], [9718270, -655040, -680376], [-8842612, 3632044, 169050], [7113802, -2266800, 188872], [3743618, 4639048, -748932], [-9428562, 786780, 966410], [-9307266, 248928, -1411632], [651212, 3549836, 1312490], [7664830, -1578628, -74326], [-1029704, -3699540, -629350], [1664764, -3100744, 763292], [-12678756, 3296608, 707336], [-19217426, -555328, 772736], [-8758740, 4594072, -897676], [-13675394, -712016, -1020936], [3831284, 669788, -1029694], [-22269588, 1087216, 911728], [1368320, 4430976, 1612072], [13644886, 1701264, 168280], [-7319010, 1981608, 2144316], [-11208172, -3323984, 1118504], [-7285316, -2507896, -1825956], [-6389376, -3729848, -1938308], [-14530816, -3416320, -1631008], [5321258, 1108956, -396054], [14649870, -3544568, 883484], [22746298, 1370768, 746624], [16164160, 642348, 1706954], [16159588, 191280, -1427896], [8250196, 5818716, -2139070], [22930714, 2763356, 431426], [-1913916, 1871152, 16184], [15175198, -3342696, 2180972], [30266264, -1047744, 596584], [-12278852, -4340744, -1696788], [2517638, -4997216, 389936], [4251838, 3481640, 404252], [8330626, 4000904, 1105836], [-19817716, -5837504, 1716576], [-3968242, 9772864, 1160000], [-4937888, 6825424, 1089928], [27596262, 2035448, 3316956], [26721576, 6319744, -1689944], [-3230578, -8142056, -489468], [-27228542, -2436396, 2467150], [6057170, -6996120, -3661268], [-34744990, 3280300, 1392698], [8360918, 2864688, 116664], [-10989272, -2449168, -1180768], [-17450420, 8183216, 930696], [9200558, -6596672, -219256], [-24626820, 9627788, 482746], [-9754436, 4386376, 3001252], [-31331046, 2140600, 856868], [-13148574, -2528744, -4416188], [-19600728, 10373000, 3450300], [17347214, -433640, -355756], [-12796020, -8151640, -1220948], [15429082, 6755152, -3021000], [-24786868, 8943456, -1663400], [110736, -4333672, 408924], [26122238, -4440160, 1640240], [10080152, -5273416, -1204372], [10221586, 10271264, 904824], [74627626, -554192, -855240], [-4078050, -4009904, -2775488], [-19427892, -4849124, 4370738], [40286524, -2294040, 3498044], [-36549180, -7452316, -3264674], [-26894482, -4492764, -2252394], [19028406, 3966928, 5779552], [-50161490, -5684440, -846820], [-15261304, -11283288, -655652], [10486094, 7810656, 2368576], [-11550848, -8107216, 1709936], [-26857608, 5686136, 3559804], [1812260, 1151388, 1569730], [10511376, 432904, -4650236], [70346562, 74160, 3611552], [-52224766, -14440984, 1494092], [27616624, 11273264, -1100224], [-44085144, 7715448, -3228396], [24468296, 2389184, 983072], [-6394190, 11139568, -2090616], [21580110, -19141820, -2531138], [9397680, -3111692, -1024138], [-10480684, 11780136, 2642212], [-15959390, -23142120, 1746980], [4776714, 18319064, 191748], [115749206, 1971140, 14854], [-51550586, 15144696, 2072948], [50115780, -16755432, 972524], [-76151024, -6298136, 1522900], [59471814, -12346144, -2947200], [-24090042, -2074728, -645972], [31832244, 11376728, 8170180], [-102450410, 10567460, -73810], [-30041776, -18688680, 4095028], [55663766, -7422048, -699576], [37147414, 5007740, -169654], [24629350, -6297036, -7356386], [43865860, -7822244, -5024030], [25455444, -20276064, -2066800], [42940612, 23854856, -2752692], [-15078838, -1287856, 2011096], [22244148, -21882236, 556406], [608432, -2050280, -9179148], [71293380, 7304040, 5378460], [37809784, 5648680, -6537284], [79225890, -4759788, 5877422], [116615808, 3608176, 4316224], [-39427218, 19244736, -43792], [-41106600, -31447516, 3319870], [-55598520, -8804832, 1143696], [-95897928, -4062576, 2206256], [14084736, 20134984, -2912788], [-11570462, -8198764, 1694990], [83677844, 810760, 2051724], [-37344894, -5175528, -9084508], [49983360, -25937100, -9047274], [63608396, 6281752, 12273612], [-43364686, -26386832, 2309672], [-75675300, 16403556, 3159654], [-10180416, -10723608, 1968396], [-68828538, 15172992, 6656], [-16673534, -19248636, -8679098], [-73889330, 404848, -5853224], [-76306790, -1102384, -6537328], [98756606, -3914460, 6632334], [29766832, -19575576, 1907972], [-59273862, -15075400, 7606260], [-53361858, 15938656, 4588528], [-28963230, -16692720, -7909392], [4732688, -17273320, 11116156], [-2418894, 2993528, -993596], [-36057754, -5573048, 5681724], [75627114, 19711220, -4103970], [47388840, -18272804, -1213462], [-140840882, 23680352, 1180592], [-86786464, 17374104, 2456244], [-126721710, 1433360, -3513576], [80817466, 2096364, 4444210], [-96693850, 23203912, 851540], [82940344, -4527552, 1294792], [91710132, 7893984, -3831408], [-90309066, 24077520, 9470888], [109254082, -294480, -347816], [166758380, 7611088, 7721496], [80286456, -2533280, -6979504], [-95048076, 28206104, -2899620], [219072260, -564520, -1786588], [31657334, 24611040, -12907296], [-74126826, -18118116, 4002650], [65400068, 1029880, -2480940], [-42803278, 31235040, -7801632], [-68893000, -9210468, -404342], [100445068, -5274776, -8187276], [-37153976, -4589020, -5370978], [-106827162, -6818064, 1137000], [-8019792, 21050232, -3966492], [-119774976, 15303588, 2219070], [-13854348, -28944656, -14033176], [-45596770, -2914624, 5568736], [-126212628, -1868844, 5724630], [-11177956, -1524456, 4586028], [-63939006, 23329832, 2814316], [160049848, -40642136, -841700], [-100874358, 6364932, 1935110], [99745826, 2711200, 9528872], [106115596, -31865692, -771786], [-12167194, 29259316, 1606430], [101463840, 23761528, 1400612], [-151676952, 7811512, -1326260], [-206718166, 34605552, 5692680], [162699292, -342576, 9041288], [-97756770, -54187104, 14506304], [138716068, -13435256, 4395196], [163466990, 13123408, -3997768], [50349072, 24365520, 710328], [25422958, 23662576, 8535496], [-77159008, -15202124, 15401814], [74233340, -36008448, 11922816], [133758464, 7576928, 7147328], [136277846, -3993688, -8991716], [-137448084, 20916304, 4874984], [-188352848, 12527232, -400864], [-31040278, -3354704, -1322104], [88334708, -38211316, -12358966], [-126935610, 26626684, 6292906], [20708122, -14956480, -4392160], [105809396, 2618788, 4732062], [59217952, -14494624, 18957704], [-270832728, 3941460, 1921302], [-175600238, -20530624, -15732640], [153771232, 24563416, -4482420], [56692324, 12568288, 8249040], [-120801336, -3612608, -4659376], [-159324792, 5148028, 6320234], [-14830358, 21299432, 16158812], [-211302354, 27702720, 872064], [35010534, 11574580, 2542222], [22237028, 25480192, 6693240], [197629018, -34793948, -5436138], [-99545656, 19502616, -9589580], [304124798, -4798304, -6248656], [-301054008, 16052772, -7600674], [-116127510, -16664448, 14600672], [294358290, 34820668, -2528366], [-16179010, 35151296, -22373816], [-59817342, 9730400, 11021944], [-3847348, -22424988, 14296846], [-25445168, 53285504, 16272872], [159100506, -12052024, 2882044], [173299392, 4695912, -7276452], [-77116578, -78759664, 9049704], [-71256168, 5660120, 19548084], [-80002120, -46654480, 21653624], [185284706, -5059032, -7416980], [-22836074, 9922908, -29723702], [-33865654, 34796416, -4187296], [-94130510, -22431880, 19991556], [174361690, -65744628, -5190038], [83969550, 43155024, -154168], [89504780, -20681268, 22462138], [209335240, 13155376, 19541416], [-15032632, 49815528, 11370700], [-197193572, 5936444, 9555666], [190901724, -94508360, -15039268], [326967654, 14824512, -8605552], [-107324000, 10074436, -37466642], [-31100776, -29102416, -11448640], [66486984, -10214616, -8587572], [186507700, 13193264, 34788680], [180542458, 10194496, 25650288], [-141602004, -3797884, -21101066], [53334658, -79831348, -10055782], [386543674, 25982496, 3985696], [-134512412, -61459520, 6371296], [320347148, 15834064, 8446112], [-102456556, -48480344, -33221460], [137530120, 20164588, 4163530], [-40109254, -76102948, -5897558], [-317532138, -3420640, 3743640], [-54316376, -43176744, 21134228], [-47488428, 92710104, 10611636], [242298194, -36629744, -5168800], [-155034076, -51075732, -2753702], [211143670, 48102680, -14137348], [-334020138, 3207536, 19688680], [116378154, 71060880, -3135216], [-202029918, 77095500, 11770874], [178300588, -27507492, 22943666], [-158534166, 477108, -9437986], [176739404, 56831992, 2785788], [-202935028, -27405064, -21871988], [-239094610, -29228768, 16935800], [-110861570, -16395636, -11083358], [378578748, -41511608, -10453564], [230719938, -24372928, -13579200], [-276155726, 34115080, 21000556], [-266461992, 90281288, 9098572], [58737996, -94073632, -4496496], [93584948, -43813240, 31369436], [-186361506, -50031160, 3686244], [-226836426, 22398612, 14827454], [39819546, -85477248, -21099984], [-410139740, 18454048, -4346808], [205772744, 9483788, -814294], [161517342, 66783872, -2095152], [-179417930, 60242536, -11869100], [157111890, -67426820, -5855438], [-173914046, 34124992, -14135240], [39737852, 36567684, -3592034], [159538838, -57363740, -7019770], [-49592394, -11967104, -27245816], [394435840, 50872852, -18010394], [-689056844, 17351248, -5298840], [-121033888, 102415752, -6642212], [244050450, -8408720, -13229840], [264626116, -97980572, -17848922], [-23335556, -130145776, -10108536], [78079466, -54340812, -6364626], [-72321258, 14525880, -4963636], [-31186498, -57148672, -13261312], [184367868, 17663976, -20594196], [-64616452, 116840568, -7228932], [-636309558, -6098720, 2418824], [338607256, -2125488, 35727128], [-114523342, -54997928, -2779596], [-285822562, -48386672, -808888], [421387588, 78014872, -21907652], [-128851544, -15157240, -2118036], [-466129542, -33840704, 9287920], [-98612982, 6194760, -11985348], [-18670300, 61591248, 22707832], [-125542584, 64910420, 42865702], [127746084, 10788992, 4274424], [-50129596, -31056088, 39451196]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_165_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_165_6_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_165_6_a_c(:prec:=3)
    chi := MakeCharacter_165_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_165_6_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_165_6_a_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_165_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![18, -25, -2, 1]>],Snew);
    return Vf;
end function;