
// Make newform 234.6.a.h in Magma, downloaded from the LMFDB on 22 December 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_234_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_234_6_a_h();".
// 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_234_6_a_h();".
// 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 := [-212, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-2, 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_234_a();"
function MakeCharacter_234_a()
    N := 234;
    order := 1;
    char_gens := [209, 145];
    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_234_a_Hecke(Kf)
    return MakeCharacter_234_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], [-37, -1], [79, 3], [114, 8], [-169, 0], [73, -43], [-1258, -20], [1540, 36], [-906, 88], [1336, -126], [8873, -59], [-5740, 154], [-2071, -73], [12677, -135], [2440, 266], [11786, 152], [48348, -134], [36174, -92], [17803, -1073], [23062, -1028], [26188, 352], [19068, 378], [52066, -940], [53150, 1908], [140792, 1218], [38936, 1856], [115668, -1364], [120153, 13], [-158074, -2500], [-78360, 688], [59731, -6351], [39120, 1974], [114397, -4737], [-38214, 7572], [12537, 3897], [-464506, 444], [146904, 6494], [-90820, 2878], [-30600, -9398], [-210533, 6509], [63700, -2002], [-585342, 338], [551236, 4534], [466717, 3293], [-31038, -13402], [53157, 18191], [-425219, 3929], [825180, -11262], [103507, -277], [-189023, 23305], [831185, -18935], [-265230, -25176], [1018096, -1660], [-90059, -2275], [-722788, 21280], [-213844, -7622], [1990731, -3593], [142312, -15298], [-798094, 13164], [-649924, -23656], [164619, 12383], [-122418, 64184], [-29030, -12802], [-216771, 70493], [7146, 34116], [-158552, -52766], [-48267, -19675], [-1531533, 5145], [-1161779, 45057], [-882224, -54218], [-3067260, -31170], [-569254, 29466], [-1836504, -55750], [941420, 10478], [1135219, -78049], [-1329114, 29232], [1449546, 11048], [4889804, 20002], [-3014168, 2514], [4669081, 29867], [1343177, 98549], [-3019767, 7521], [-878035, -56551], [1654326, -131998], [-3046731, -25905], [-1878486, -5716], [1974650, 10664], [3474431, 91027], [-5874700, -57214], [-900956, 29496], [1813061, 26185], [2652284, 21510], [1816919, 76065], [4889260, -15498], [3164850, 78794], [2707598, 67248], [-1550821, 8155], [-727620, -124116], [-5570469, 109067], [-2566633, 145709], [-2519483, -20539], [6229311, 11209], [-3463725, 30671], [4728195, -70875], [2977418, -284048], [-2655544, -101698], [-11197698, -2168], [13914294, 10382], [16163911, 26715], [-9972366, 42330], [-5307542, -265952], [11651084, 13626], [149232, -171122], [-6488571, 74893], [-4842542, 237448], [5290174, -209108], [2180266, -237746], [-5785020, -232254], [5063036, -284204], [703918, -218732], [-5471809, -231517], [-13657888, 72850], [7139416, -262262], [8577788, -285802], [-4291880, -37858], [6625486, -170948], [7190114, 194174], [-2699250, -189542], [-6191137, 211959], [13204200, -50466], [121409, -194535], [10361840, -9776], [10142784, -194274], [2390026, -266668], [1130292, 457134], [-7206121, 135107], [-9033260, 355042], [-3652238, -560356], [4251003, 464763], [24666960, 104666], [-24323117, 244455], [-31307606, -139690], [-4347478, -475160], [-17218302, -58316], [-10792620, 389014], [6091523, 640547], [-6864758, 22060], [-32024444, -27212], [-18760755, -526963], [4075387, -657277], [5993689, 279593], [-12283621, 422549], [34034360, -174972], [-44219827, 20323], [7914690, 245370], [15438464, 108244], [-689816, -453178], [-26682434, -476356], [29830101, 179477], [16733394, 399600], [-11760325, 654455], [33707129, 437637], [-15041587, -241169], [-18560226, 229584], [-39200719, 327533], [13385742, -191322], [44457054, 67064], [19116378, -938248], [-17250226, -454540], [8244730, -1003660], [23255143, 200759], [-31169656, -464736], [15388028, 65582], [-16420026, 937674], [34921123, -195905], [14468304, -122074], [29484714, 622652], [25848820, -407556], [15242648, -830958], [4857308, 1349266], [4113548, -252048], [895998, 1136872], [14392238, 775472], [-31511504, 990346], [368786, 159108], [11500798, -264060], [16588210, -1061968], [2038456, 616930], [-30562444, -867578], [2025359, 1131083], [5452064, -616730], [15107575, 1001013], [30337050, 170524], [-43416067, 505179], [32282414, 1186072], [-15811860, -1301074], [-45895436, 201798], [2474432, -365842], [-63406406, -298622], [14192899, 499319], [14934948, 111104], [-38233293, 903947], [-4392813, -151625], [-8828356, 62502], [362046, -772764], [14624433, 1027981], [35772268, 506276], [59158078, -921712], [1005399, -648111], [76341358, -6092], [4088854, 275156], [-13458324, 1847552], [26951078, 591708], [18116263, 324347], [-34176548, 1178718], [417116, 272648], [48637697, -482623], [18808328, 1053102], [-18932099, 1599221], [4755096, -75914], [-74734959, -117391], [-43563600, 971046], [-76514567, -1293267], [41365961, 51079], [33439474, 70828], [94809675, 1025959], [6806632, -2239564], [-52803678, -312434], [30154970, -128312], [-18532298, -406068], [50899508, 2003612], [12716532, 1127262], [-37156401, -2496337], [-69034997, -361223], [-13523527, 1901657], [71590158, 1471012], [-32325567, 1425569], [-51031368, 2619852], [-56106270, 823114], [-71723674, -976088], [82218865, -1180041], [-59100008, -2175988], [123771939, 555251], [5031722, -1183348], [59271088, 412472], [-24339883, -1838427], [26222456, 1542618], [85763578, 1072672], [16263434, -3336242], [49332881, -1108587], [-82258194, 1457344], [-47789757, 3002747], [36770309, 1739373], [40270992, -1422490], [-27590010, 1328300], [130377624, -233910], [37943294, 818532], [154361116, -813358], [34607866, 657768], [-108940196, 895092], [-9207469, -1500431], [-46316249, 1375], [-152043498, 895432], [98166884, 415522], [107337365, 1386239], [-1268001, 292571], [116844904, -1090170], [106810536, 2487150], [-1661752, -1205870], [36859148, -1229998], [-71075258, 96060], [78115706, -2449880], [119488532, 1190460], [-11000786, -319568], [-181410116, 375254], [59560746, 334468], [90954322, -314080], [29537000, 3503522], [66740553, -4134033], [-70914296, 3070980], [-120676507, -1098659], [75321482, 43226], [-60349354, -4346124], [-83457608, -4542370], [-86502158, -167330], [-24922205, -21989], [15415297, 1055745], [98178511, -2713997], [153497478, 2275528], [-190481968, 1387450], [140602655, -736027], [-77658940, -2901638], [27864082, 594240], [-27151074, 3972532], [-123381400, 3081790], [234211154, 942586], [-76973008, 2404766], [-232970135, -52877], [17099558, 4291056], [-85151507, 900097], [-225142249, -2042629], [-211766522, 685922], [200406180, 589804], [-103764849, 4487149], [-35477740, 2400366], [162718911, -2224975], [-39133936, -4064570], [-88265504, -1842134], [5872088, 1020250], [142008224, 701044], [-47567687, -6272919], [-86946757, -5593565], [-109151836, -403708], [-9965273, -1799409], [-63628673, -4452125], [3604954, -3542404], [-107076412, -341086], [-268023164, -1959050], [118251978, -3860192], [289942692, 1084616], [-51146668, 4382870], [48417020, 3888958], [12616357, -5440811], [-150462308, 5322618], [-230511646, -782944], [-92465602, 1091984], [-193700212, -1422290], [224304464, 4961808], [-151475848, -6385930], [66888442, 6989304], [-34187492, -2375142], [-318353860, 92088], [-24267116, -4097506], [408827044, 1441678], [233099428, -2314446], [-21355214, 7237864], [145870304, 4714334], [-116919812, 653318], [-18642830, 3245158], [-64688627, -4119007], [-165496825, -266993], [43064651, -7757169], [225520606, -3837222], [177028761, -6693455], [300873115, -1479131], [27188398, 897036], [160039844, -4445886], [228583127, 1269431], [-75747022, -4721372], [-78517322, -240804], [245504158, 1620468], [-285564205, -2486417], [135089136, -1789288], [-316425574, -3952700], [211574574, 2158908], [6947251, 6554051], [242145746, -1477316], [323247199, 3116939], [-456700225, -766493], [129509566, -187860], [-441740038, -651080], [-256739270, -1312902], [-119683352, 638694], [135112948, 3920368], [-63960813, 3584671], [-152388199, -4002167], [-230533796, 4524978], [-77591325, -10374489], [240407873, 5476603], [267569223, 6300745], [-28406695, -10447603], [277129250, -4344344], [195509752, 3655772], [741502, -1159456], [180526318, 1956056], [216231298, 6215966], [-275164288, 1113570], [-34645770, -1808264], [280051670, 5562440], [-24132690, 3511656], [-68825590, 3581084], [269179888, 433358], [4255046, -5959776], [68119588, 4970778], [-413071123, -844919], [-178041637, 12451579], [239550788, -9030750], [-379941542, -232544], [181613612, -368920], [-128060150, 5668304], [-179747887, -645855], [311350642, 744392], [-447813235, -4071729], [-472456503, 1971597], [-153007421, -10625085], [-232875451, 5656033], [-292982391, -876707], [238515284, -10606364], [122488863, -1789317], [-155578919, -6671163], [144635206, 531972], [256747357, 7706205], [-54649436, 4591306], [-343415143, -1906295], [-384427690, 1235094], [-499718597, 748683], [-278646620, -1731262], [147857262, 4824928], [-257131164, -1686570], [342038467, -8173125], [-112592934, 5177568], [322146101, 5080415], [-458381663, -3385041], [211275619, 12082483], [-561638880, 6675498], [-128700321, -2166789], [-183279680, -4958652], [-538623066, 7250328], [-15844530, 5443458], [-444501672, -6708662], [-95787146, 435612], [857135724, 1137546], [-57955935, -15146949], [5379824, -4105830], [623108858, 1193556], [-405822373, -2664235], [427282532, 1718290], [-79477444, -6774910], [241219670, 2333934]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_234_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_234_6_a_h();".
// 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_234_6_a_h(:prec:=2)
    chi := MakeCharacter_234_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_234_6_a_h();".
// 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_234_6_a_h( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_234_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<5,R![-578, 73, 1]>,<7,R![-11186, -155, 1]>],Snew);
    return Vf;
end function;