
// Make newform 3.28.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_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_3_28_a_b();".
// 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_3_28_a_b();".
// 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 := [-7500, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0], [-63, 126]];
    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_3_a();"
function MakeCharacter_3_a()
    N := 3;
    order := 1;
    char_gens := [2];
    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_3_a_Hecke(Kf)
    return MakeCharacter_3_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 := 28;
    raw_aps := [[10791, -1], [-1594323, 0], [-885973050, -17600], [184832599952, -17982144], [37881167834124, -8106238336], [-51510539588794, 115885051776], [17345805789573954, 4829442960000], [55810238279321108, -2814081001344], [-1446371537909693976, -179372064257408], [14979776236661403486, 3892545677477312], [5183731628527747016, 9437537521608768], [-1851830454409762434658, -4481515500954624], [740907464239739017386, 542569103438555008], [4889389311728690124620, -353437120018359936], [44747499259404870161760, 1793036388464342912], [212835637912300906738374, 80486970344586432], [184709384821690065146412, 81153339396537869824], [462566698714446372624710, 32446692922463744256], [2075853337277606974066484, -35699013212104788480], [4880227927935433768834392, -739151259346737409920], [14224978173820037578704794, 619525988484801057792], [-24776610949337750872115560, 2262423523592910807360], [-60236704101614367963173868, -440202825764870246272], [102822026104848566528492778, 21608558186896399716096], [-739169503200204797418213886, 29604352496406812087040], [374656364835202851753051414, -125132094704585421295936], [-756325580152198271123618080, -115091320453140323578176], [-640816064864604484139463300, 60770876718285608009472], [-173001379698316724301450682, 511010102680258271400576], [2289134519980816975425628722, -550147159723967380458752], [11776738020726377039097941624, 881201286154570339719360], [61712937868055134274976326580, -941109032178825250386944], [-22575490762609752834038401494, 5477611006945619085129344], [8351981826721339003795657532, -9977991995419726492440576], [-116436108992440203273906198666, -8225419094509650805806272], [-181018376101636544998293968608, 24596917357833082708372800], [283537208897482818616500176966, 7616300023566425917845504], [-135230619317078461754076337852, -73130215904293036961070720], [710908885275428686391745037992, -33366079457000119511366144], [1735611638055959495378337830622, 84532048046383541198324288], [2844214993931368482186474432420, 134241706557032618798031360], [-1267090251089550656337111925474, 65128578674803213563658368], [2018382160003508000074557999744, -569374525673806850537453056], [-1293878754294495564724106780158, 123023183225495073825788928], [4714636788955002138969178731798, -454058559929543316078545472], [-465381186864947824122832245856, 721373867017309739025321408], [-8863224191927219117776359395644, -2045535783081755747835244032], [-7746180400496239912882889049544, -1369840601050763623017850944], [-20103056183070490571058025423548, 9557628520414987851207391616], [77966480707440010164899177990222, -3388689872107624520038348416], [104586015272461886644949689185690, -3178251041305701332374722816], [-35466248124409866079925025510192, -14076851822580102376074938624], [120684818227204637542849697067314, -1733621366981080546561149696], [-63159841665176859379568063456388, -14842273827264322859424301440], [21122424087291489144273283437570, 9822792853810623297213171712], [-449128345274861048103642211183032, -15415594469916770809887953920], [-59887808987128448334486071840082, 3923611550535985648593333696], [-1171069095054878409351252021717976, 9528776269991912034376426944], [843946789532753827106829764616638, -23201291417421943622176947072], [853187465529599970336267347315658, -46155757595711898129206545408], [1017270329650897818326511242873036, -102763753246249219732141062144], [-13635052517672601628893604006122, -40663350591716676176586954560], [967911433619415575546488070509220, 140939359891909637590876073472], [-4371938451805786168425838576529256, 25742224148213983417754247424], [4952168403631679037982956980599658, 56916290053774366916628787200], [1875973452868247531230900588119390, 398624316601662148410449676992], [-4814802148316597840713150840596388, -171890975747157070075539943680], [-12086588790170132359656027058298062, 332959630349993322999718407168], [30497999439404477085419020685532444, 453400075814729134297241265280], [-9368714741705863174115881206740314, 2349951100567891933756882252032], [-6663730402410459648369818985819774, -1991805843099109531472729344], [16650688173006260847264315622179192, -2241125564643540337416748611456], [31558913324359639618629044506702808, 3171031292792572272887248991808], [-13375357068149885582135960255032210, -5001051721182849176242038564096], [81680245639906887656119117206484220, -166859078924827667618382890880], [33487724316026136608965043564617728, 7839520254018403763023149537280], [-10438400726906469086221044724820538, 2321453550713682175793715884864], [-18622715706674379235113136621630090, 5439838153678413699685528772352], [-93904586591489008026801328286874270, -6509146657086338542051801752704], [-112620481157745115782365018981122198, -9258946275454850222485011622656], [62248417818739693906318852254217668, 31380683829519428837604747136], [77170259460331588332110758874852078, 7853897232826868250530906527872], [-106153075447089490580166061615327104, -47183593763219328303566192168832], [124729087515379972847941538778599378, -1827080155007033099808472358400], [361749677810925081952976889167306480, 30428436195306246883513365685440], [160554555533824049763411416176195836, 32559220408134903422252099616896], [263937588174196815417599718174220434, 59840730404168388241149443676288], [386292755600839379681163295605856442, 106876252861462970637315562964736], [-922559349221067586111338456301607298, 38097125629586126761872130026560], [-537414077614746533925488198193718360, -84066840008694885640673091157056], [-704936021834740816917804117519420300, 1423868612116194049714353151872], [-340142625261937670259278177863264080, -26984038731368646436927644054400], [116159375613914488853911997296879664, 216888793442635112414858338747200], [-2867569531440203644781464924046243460, 45217746696159618909573092636416], [-2448097837950529401150773164117723612, -234530338529269541428206370504704], [-1554717415549306454310414676274245944, -5579279236221152307485700833664], [-1599772962721139972758528258535871138, 312144651785886676767953341330624], [4181163591718366334627083242083565066, 37492140147993198329591489163648], [-101191520534484075029245281831720820, 62692462691770805063434160843904], [289974495003149584597031464224004886, -606148145263745440656671632563072], [-6980804326498935661563077570302080028, -189975996954432977586915466076544], [-12900120411348099933757689661510678146, -414991196626889018158944032806080], [3772076165194519695848463230982472692, -1061993018930711752409077414865792], [-19944675954971509266802877700179734182, 518704947187733594624863533451136], [2130027986006862777931340081582977484, 1884833567175046912469276782258944], [5548805704289566673807606229436797314, -1880111937327930377041539130214400], [4380671841100968964341232043717668380, -1102533192822519465772709139635968], [-7923683058258198102791168576656289070, -784717278845988342668480476667136], [15502499906794073510922032219611682184, -1947149600036653729381155015949952], [-369702592212421329969678412002563446, -433345602024523602279983542150656], [31010363997110488949892799493090981144, -1725926406472733059955194037064000], [23261057838820561499982726244024370942, 209236607943641231546103305050368], [-39925935182958062276989480675690167174, 4850912212556730102929631852404224], [10815769140344249459321028013337474012, -2868288751930039548462163075309056], [27829146147151465452219853341874414592, 4020275966339617042705267128171840], [-71433283012862034975206043231966241134, -2625087231834511996537234116410752], [41132995134342676919989019499454873220, 3178512137227931230116233651347584], [22801362823426686053256223099761743064, -8624436128061190134816927952091520], [-24340915165941782225146399082295680802, 4499588069399897146150571779850560], [93030546601036541727142923598288634340, 5388985045605790667171365196576000], [86608377016006482811030137900473705582, 9671793641082841564306231164472320], [74873008896578554189508015516774092514, -15456134298709860944578570264393728], [114638131149064149459576188098353807558, -13197845969222823933359152924430272], [112929113307306894403509106646677884108, 5101667217473682746716961309877120], [-259292818467025350378729471513687364396, -10403800910205376922049362815241856], [140800402685845417866404792190475099230, 18120541020607094217308626756038336], [225238313439388272722226938502600717038, 884569542097887193434366982398336], [34050282315814614161548157837663032704, -17556801251055993717999088049803392], [43792797997770757634447943439943569376, -25902869707539941541903186832449216], [106038177094636207610933378374808108150, -22456989849252675920166240967218816], [-241145737273954495222632251673690228748, 24864230923180519964655404644833024], [76799533601186242523731417893192681480, 70678395549826987781100284350868224], [-208225883330362229913115557842830623496, -72906514913505027701902924940089536], [557782284413844395892976961093206131326, 41841671253220284108177759133532544], [-1336752421604247243314550199462169575302, 13895470438628341032900795900122752], [-1509678600533121897409174898024033065726, 11288524171239962704459240605347328], [-187510632010756220973981433816467929322, -18052463065376270915614280466461760], [921878706640479054424242177982247655860, -8311989376267450304294868802270848], [-1116152570319355682901453539557460015730, 48502472593931762921518151488935232], [-1202361689204244149224713692369695649910, -75687421989614106807980607318353280], [118716570587059571356244047242445751372, -158480026339190127609573104473088640], [-3295358387425670983692659966997780504282, 91187940529980484143651153972934592], [-1915171695871655638619143857120758109088, -15816532125057506536465816191525312], [3670248969881707693489066882388150789004, -21750732563254492424587533472899840], [927605022060467534850661182216317215670, -11377229070057781880144682362367360], [781077597420159742102817992410618018360, 161803063050174360256722265473614720], [1960993871040525717909586538611529273198, -31387341177890544206512940884968960], [-795352271902452236419306450613496093510, 89353144048184980413744977799208832], [-683818848006834039312858723150461514340, -563835010994657398860882967226551680], [2722309742075541411626750068334785452960, -257661442960422137866968509059508736], [1421673157108674050027924038573429411862, -564887606121845163957789331609238784], [-2321305011616150630284531467675037361902, -158011880338880153494246776523734528], [-349636906599152500349742192080200977580, 688112158014535802601369678908413824], [801860585213627264340253617235569539640, -388669007673067613047018863980146688], [-3533716215741966042885107263700403763060, 348687752725119207123571364649677952], [9544824575546327688400568178609429832752, 212084313503891716763453851730842880], [-13843772724940617749330441032898686889920, -294856491388087973956312277246139840], [-9259777770373240685778549146277931087662, 33667925905850560034598194589366656], [-2967773029584941337995173714541469778822, -1383746913150151902287470897102636032], [12869845464615774499878498086023477542366, 1225725172004871140245429688707674688], [931748543048941744645403817844289374116, -700982500896816491060669975125505536], [-290798859838562612731518479681718573414, 205644907740605135438461389453269376], [6349619101377250826994967489762609960064, 780808295263635289817951331171360960], [7667566745940250487062232427746141738796, -1781382297200676488109026823385936512], [-39693213007618309689178102632084164224926, 410354656627823969534982059040941440], [-28241485018694565575216758190418529124136, -380308204879442505697232147620546048], [-284119415282211156514280274535663502488, 80763044913224692373413438432176960], [21209690309102885139698345832296694488126, -3335009721262238924340692065820718336]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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