
// Make newform 54.12.a.g in Magma, downloaded from the LMFDB on 17 September 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_54_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_54_12_a_g();".
// 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_54_12_a_g();".
// 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 := [-27, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-108, 216]];
    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_54_a();"
function MakeCharacter_54_a()
    N := 54;
    order := 1;
    char_gens := [29];
    v := [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_54_a_Hecke( : Kf := Kf)
    return MakeCharacter_54_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 := 12;
    raw_aps := [[32, 0], [0, 0], [-1860, -5], [-3397, 44], [-416316, -539], [492317, 1612], [-2555532, 4289], [-11459635, -4784], [2631828, -38935], [-18767424, 41008], [-164429740, -96240], [-48283693, 135332], [-239326656, 295504], [66854552, -26520], [-2215856604, 160413], [-2377486008, 676858], [-4970268924, -2452747], [3029492255, -7032372], [-3386132335, 6427488], [-12790682712, 14830706], [7903812233, -13431672], [-14069510923, 16985764], [38603727240, 13470282], [19147792068, -22697179], [54645300437, 26613808], [102207198336, 16583456], [-15996016297, -169811148], [-10346223348, -35466785], [215534545274, -32689416], [130168425828, -195433107], [42887792828, 30174744], [263844785712, 451576060], [445093128636, 6307963], [182198298563, -207709480], [-1274824566024, 37023062], [537928719017, -72943404], [361949883830, -208982664], [-920635385965, 896212832], [-1699760571900, -708916491], [2379819110208, -1031677296], [-2515020319656, 910191886], [-84349437271, -2302539076], [2282203000860, -3575051341], [-1491871230361, -356477736], [-1221620818932, 3154372703], [-1162945364353, 1976022100], [-5993456216041, 4189839016], [-3721355456116, -5052346080], [10838875420968, -4951156782], [-12106241676334, 3991390032], [-2474267202000, -14532809348], [-939730974360, 13115413794], [4070475439889, 2208660488], [1196297485488, 13944119452], [-13703129698344, -16476498834], [-9639360301224, 4102977230], [-15607237072860, 1431635101], [-6002627080903, -27216026556], [13533922758146, 3472142136], [-28012724469984, 4640103016], [-17939058429952, 10141584792], [-10413324600972, 32884761089], [-13865077998160, 48503194488], [24097382218812, 16363203931], [38610510424763, -50869191736], [-22679879535336, 4223881214], [19111820472347, 27521010088], [93180649673501, -16752141088], [81795592096104, 684360354], [173427590068835, -5671164676], [-26986397430504, 45550149502], [139495515174396, -42952287477], [27287002591079, -28395274908], [-107534129160565, -94278110732], [-13814887042663, -23020803784], [2725749666048, 190788141760], [-87643382228292, 71421962747], [70939492656230, 75665374104], [-256419793266360, -115448480006], [-195213247535647, -80716341664], [-110190730427052, -101714799975], [28149168479765, -97876690516], [-384503045893164, -22606960519], [338044514617730, 108882652824], [-6428490832084, 489095423184], [88701326787912, 324995013498], [-584046020815092, -3469449633], [182838620349446, 17795964792], [48502601688516, -57240029147], [-613694178497629, -55591935188], [45217357540308, 412267150009], [527210629797048, 43911666054], [-666268414423693, 213667911652], [147247401297036, 184309472063], [-42468765189472, -746854652016], [292975287909300, -14639785263], [299202791069676, 549578432695], [111075907914828, 240186731375], [-467098374450751, 1008405814512], [232165551931589, 79093014596], [-987431973361573, -1068024349752], [-354077165433276, 675420517445], [-613716062305632, -674605389240], [87429255184500, 1987199234945], [807755056878149, -274514052856], [1347914282471219, -546637126920], [-1784323590436452, -471498050221], [1033085971404216, -367875962938], [418502388432576, 674985320816], [-538137162271894, 1702978551000], [812891945552651, -1060460804956], [-1144410039925009, -1152056766852], [-1445732117630196, 1056259950943], [-1668724977238411, -106496969040], [295096430010305, 253190348516], [-3211978026911880, 662741813110], [-2993209453823032, 213012943704], [1547319890119392, 2531483290008], [467987267597160, -2230155773278], [-1456470785621784, 1113056656514], [-57775915699057, -1464608192724], [-4223659763292925, -105288088064], [558637623607596, -3605476615993], [3969105126905232, 1475037012276], [513859193839256, 1530745250616], [1574273551836996, -2373913544315], [471638509620557, -6813898886108], [5261823421818840, -1089423457170], [-4714901926095676, -2205329968224], [-5772223424791414, 24965653992], [4770606707122160, -441141328920], [-3143516637950124, -3993583079463], [-505501809419971, -6198052366036], [-2177892953944891, 4426530909540], [3224258918359572, 4815891593865], [5433066801862127, -4258012844480], [-2148046849143720, 6316205074446], [-3035280714213979, -9141089087712], [-6731853532308240, -4143832549908], [-5638395077671608, -4635198360454], [863112726909416, -13418009035992], [4028010518311116, 11698189562063], [11880738366326513, 5784307747180], [-10487422606128300, 4192724495129], [304104711544553, 6933361900972], [9186145438108344, 2615074262790], [6608445083545595, -10602952593828], [8552855960696328, -7821816971670], [8981459912982743, -2382741820120], [739487770160580, -14901472595803], [-10732874342889565, 9459317446772], [-6061194002056788, 7678201958695], [9403293470544875, 12003563132152], [2236694926945368, 7264638771214], [7503417478328297, -12983537496176], [5422961162312592, -13539979914828], [12713014809562916, 2561048626176], [-11100109291649400, -9994995608694], [-22356892728162277, 7409748649832], [-10156683154534188, -27207229525831], [-327889458863364, 22936658644875], [8357525218964916, 12610805724561], [-18398796983936515, -13526704370724], [-15595050403747188, 4972337817279], [7364440489123704, -2189363477002], [-21408393400296708, -10632137432245], [1912852714470599, 15383967850884], [17728472225797358, -8512684377288], [-26382261289595155, -28433376039576], [4524197871407124, 11559355259209], [-13802369041325784, 33889343023186], [-4157418989123146, 27854654119944], [2820484803243108, -14877026536595], [804616495166381, 3576284775536], [29683699137316943, 22255528488148], [-53496457647570744, 17958146815706], [-39939920766869728, -32878127915160], [-45671638440550716, -7771026139803], [-10518819787285243, 16310507053204], [58858739799994022, 9020605312656], [-36142457007196291, 38698331931188], [-72768030721138632, -21736272452122], [6766336320303410, -33703195755576], [18272787274374012, -56772235056213], [-4821606098078352, -9015841278836], [-2380083954517416, -46007851978738], [-5170402897355743, 28181046142356], [-21327798027944857, -1104494558776], [-52894084528961947, 2477009018008], [-45458655660717660, -1126266941827], [53492655404836937, -37060975791320], [93613371175738536, 6338539074354], [29164231342858079, 32866832706848], [18942742943071044, 41259618506501], [21498431191913628, -99638835291373], [98076620940125916, -51432014289181], [35175375610518851, -62260122610280], [108735217965175793, 13060231171900], [4773179111989236, 63569584568033], [-26433599671810296, 62976713522858], [-51796037742767196, -12086683291011], [-150012664340191447, -536532515180], [124661748378509081, -34072688035580], [46037147563432877, -60205707505824], [-58602550103121456, 98834043624580], [-189914170722606936, 3534836991794], [-72677956929839647, -43756992652868], [-9666717199125612, 47860970565865], [106044605268792972, -78208466450881], [92238237352988153, 104704116707000], [-238804537867545481, -7665914227984], [-100128782388384708, -66322408154533], [-132349307225213155, -49879888668276], [-147726359771751660, 107999872942409], [-41116521730783056, 51594515591580], [122929160046343511, 8969197544208], [144952140820356116, -75199107854448], [5922065011894404, 224986159310421], [-126279479426142600, -51706477935434], [259162011680485080, -712107434578], [224821315372733729, 26083269480460], [-79287777947097460, 64177701158976], [180058807608480624, -65634339834356], [-57417765227111140, 28854667068720], [-65016103467642900, -122250688961289], [112289239412645783, -255837118111196], [260239196725287684, 98164572742773], [24165520000563492, 310185244654045], [-228500553724338361, 46279426714508], [-103914389606135484, -72734413580219], [23211208296891269, -361237553681716], [-78733144525091128, -54958565113536], [-170817621045780772, -50680705312248], [-320656027999754148, -119888193407933], [-56456345711999281, 391398673865216], [-69892352858571060, -349551047702321], [-109394927648082667, 312655328208712], [-42721073960782428, -268640040812547], [-161332042375891896, -193543089074118], [337012780928885640, 30156740925514], [-428144983412558376, -73416102042514], [452189548700502509, -18823765737576], [254008152087212681, 10267677478884], [-75137907590871181, 5420616537660], [131563064295771348, 13667419831289], [-134383878135416388, 369187836978619], [537886330460108021, -111021230271620], [-184016811983625024, -268343432942864], [24133168077100640, -54004979187552], [414306300230558064, -242033652947700], [89369745287360138, -214803834881064], [-702949079312527140, 50764523844579], [-381742919891395116, -195051024448903], [132782196613568693, -247130651911128], [283758857079914940, -234815726233413], [33909266057184828, 61208409568667], [-250767934349851951, -101215863841092], [-27668099459524144, -757327797963144], [58314220802899200, 300287889846336], [-330671349261952630, 381535652814024], [-60356314696083997, -87855645260876], [364681212029343852, 434555744359575], [463552282736408933, -13342662433452], [-323734986629626705, 325239841762220], [-149484813788030856, 64658832792502], [414519986313487904, 510612896129064], [-81191813707524492, -181708054741951], [153502778714185608, -400815269590326], [288973357950143528, 651685336176624], [642315458912190276, 81191922459141], [59173194097456847, -316278465723652], [722807432374544327, -379977818745784], [49004318156455238, -241619551253280], [-51353446294813051, 270099795108780], [-356911321700007730, -95682839457000], [-193327619300690569, -547251750129420], [473705707563862068, 825814820361265], [1210974060136122518, -153026456957928], [-950523563820968134, 127346249045352], [401149024073530224, -305704261490164], [132412264245739524, -325693891259531], [-117246565866238804, 456299833976328], [241761927591729312, 419002810090312], [-550991164959437053, -591385743712716], [-59072663268978913, 63765593819160], [-1351844751830275764, 265725835458159], [-905182325416236895, 320822475483112], [-206829438899471304, -205780273219738], [1115074612150066211, 81771909625476], [159850314181213740, -783840505933113], [-1850698655063399460, 268613151573987], [-865305999122622192, 146700529001620], [91113577502748024, 732515188975862], [-195364493164352832, 1354914771811056], [537428794981267814, -1458266040214992], [594463591830664416, 1032980271411992], [-36948048225606661, 138941460524188], [1111405568374462236, 9278773468019], [974578419222094512, 363041945226780], [5845825817177549, 474679293499672], [-333299980941900661, -1349471603181488], [2575855143547200, -745608200770800], [1217681172057334916, 189069949074384], [1537937183760038112, -424269486924008], [-513984611199798577, -1682825884958200], [211023979245224894, -77097416397384], [-2209065501005286708, -564728390646257], [2002202439288319061, -364525974575964], [819858544802274144, 1027162875663032], [1484048471253957803, 185372971222420], [-490404099979326108, 84115162865965], [-63654773886090576, -425306823352932], [-359886553344786864, -453060454766172], [1001037425362943939, 1821665639252488], [-465388714241270676, -2101637079386665], [-487155770915626186, -404591566118136], [315979738489365396, -1447463749466903], [-584057176001035260, 1453819446922229], [-1528797580216990834, 1406579425103784], [719817944925260460, 2256587032867431], [-2305138815516426223, -286629173141064], [101843084359075571, -1736361450173168], [2197504719350845416, -1106524655636798], [-2713063988214687148, 545750929579128], [-2722992321595540872, 1054251551836214], [-2117620641587628283, -163845863323288], [-1616587041357408328, 2173971792581352], [792492609907140152, -2737064663784000], [-1515752779097348292, 629339642103579], [550171783987124292, 854765040050629], [488201824561315469, 446974075876212], [-699947156814028944, 2918227378190348], [958789218102084401, 3085469487205268], [56384647048469328, -1391682285467676], [-2228431436862808048, 589927848927264], [706293986855800104, 2728035969249490], [3113739654852445355, 388517193787860], [-2902719988096848276, -498459612512489], [462081914585485478, -1215116108570472], [482499251007046076, -1041574174548408], [-178803193297338301, -1218008231975996], [2499094914275655996, 111581637270235], [727870251346088664, -1061512042679634], [-414145976858273011, -1943891016999700], [1398176240991447408, -3459031251690868], [703815834389770188, -364194325593521], [3117734555003495858, 2937022464637872], [-528454793923443040, 33560347780872], [3623658804569937480, -2068674271563334], [-2141414243310212964, -2330267112809645], [-4140354943808154883, -768534711034312], [2310775133103317297, 2195612422465000], [2391313765738356480, 2393097553073600], [1338801558801205964, 3275812799724480], [829170534405001283, 2337159174746604], [-919789945490082852, -4363278158965469], [-2568145455768824808, 355762781832510], [2882732070861311760, 1702474626864788], [-157339292826971184, 4519070978947844], [-1055283829608048456, 1784827257443590], [-259964513326488865, -2424979640140676], [2799966122180707920, 1747305786325540], [-1691091197643582648, -4042342110545670], [408126051870555444, -6565359735430159], [-513578302767743137, -3064464880976672], [7212672125616760007, 719381742064904], [-682830078596059260, -4058995175885227], [-1921374076625975509, 3308403767497156], [2276502786959593727, 3434047560367528], [-4183673306014948692, 1882728334208359], [67242640058771447, 5425515150450248], [-5954752706537281056, 3598947654449752], [1919518886867276976, -4572602081989732], [-1932952123640824309, 2532588913349572], [9185992292936161181, 857138609864884], [-902916042317673468, 1920754082924853], [4759811042531377824, 1219687896262344], [3749658779741162519, 5273172861885736], [-3478223696933990088, -4958284958361946], [-6590921845364445091, 2575444907853240], [4654327571633342364, 5061046090944403], [-3145766166830641920, 1191318591859520], [1690829301844343513, -56317329271588], [-2061988500555194520, 788190983415074], [-2614210625790563059, -3020135284508936], [-1800460201767913944, 3231871421154578], [-502458977025932476, -9097189152173976], [2708472429213083009, 1605558544301300], [-1371086571465835333, -1407951313753640], [10746313085729652924, -701006499455109], [2520336661937920958, 7481123181936864], [-10585822009213966656, 1556323980427376], [-3847117571462623068, -3268689558312067], [1783393911313063133, 3793265214086168], [4818452054717179860, -4238392690181895], [-7791993685059875767, 3394231184004144], [-823311528031019887, -2834883651654868], [295914401904001308, 5032247658475827], [-1150770429775782856, 1370399891058216], [4655665922092502448, -890750033366564], [-5261999313141152074, 8059149915507432], [-2495825155344316176, 5880441351753452], [752434839680568380, -1757289441234336], [4606118999144827104, -3556392757101288], [12467874226860284184, -4313490012723330], [-2171276965756426732, 7872507993737376], [-5103342228153521047, 8273601371280724], [5238750010724774376, -5691261767485118], [7371315920765760155, -1426136802424512], [963895227732019932, 9506745737646179], [-6675414389862246238, -9769953478910760], [-7136695607674546920, 6504835658420350], [5484082366126308852, -6135573663983135], [1024645661997512387, 2317274565377664], [7647908260055565401, 4376253723019352], [-8467552463052231756, 1564076826479825], [2731204730352251268, -5004807782351531], [1547639267979520337, 666954655418380], [9346254057115032384, -5876809852301552], [-2799309467972012280, -8824412476315862], [-3645290837589221748, 11334493587388159], [1208706618959058638, 4192468929928584], [6829428632439317172, -812732228563951], [5049669716031222192, 14775239030062428], [-2951214742985029270, 4432164706629432], [-4026188344052460480, -10515145489542064], [-10661302570187566956, 6088767388185385], [-13135827224703714840, 2611155031401666], [-10830623764062006808, 8156843791226568], [6432887448223411344, -6741432463722508]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_54_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_54_12_a_g();".
// 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_54_12_a_g(:prec:=2)
    chi := MakeCharacter_54_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 12));
    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_54_12_a_g();".
// 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_54_12_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_54_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,12,sign)));
    Vf := Kernel([<5,R![-28324800, 3720, 1]>],Snew);
    return Vf;
end function;