
// Make newform 3.21.b.a in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_b_Hecke();"
// 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_21_b_a();".
// 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_21_b_a();".
// 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 := [18153107947520, 0, 3059043456, 0, 116898, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, 6, 0, 0, 0, 0], [-6124748591104, -55742610560, -526987456, -2170562, -5728, -17], [36208166465536, 55871284352, 1299030208, 2170562, 5728, 17], [3062374295552, 493897505920, 263493728, 36271114, 2864, 373], [568520968810496, -4417563003776, 45284044352, -171474398, 475424, -1343]];
    Rf_basisdens := [1, 1, 64336896, 21445632, 1787136, 21445632];
    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_b();"
function MakeCharacter_3_b()
    N := 3;
    order := 2;
    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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_3_b_Hecke();"
function MakeCharacter_3_b_Hecke(Kf)
    N := 3;
    order := 2;
    char_gens := [2];
    char_values := [[-1, 0, 0, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 21;
    raw_aps := [[0, 1, 0, 0, 0, 0], [-687, 11, 1, 0, 0, 0], [0, 1285, 18, 0, 1, 0], [93267986, -718, 1371, -254, 0, -9], [0, 8548244, -233757, 1998, 500, -999], [2974646546, 353528, -794364, -23048, 0, 3060], [0, 898272248, 1561212, -11016, 12376, 5508], [-2493003365854, -26579442, 60264333, 2404830, 0, -223839], [0, -18110483664, 265230810, -2315196, -892528, 1157598], [0, 195662895343, -1845354258, 12939696, -15176733, -6469848], [-363817527580558, 276519002, -1212642105, -752072918, 0, -4403277], [-322390243694734, 26283007176, -56837616804, 1041495240, 0, 253004652], [0, 4202403991286, 9305272332, 14457312, 614546430, -7228656], [9699164583697346, -7946929378, 27437114181, 12411334126, 0, 41337081], [0, 36886807350312, 332805906108, -3389688648, -4391181368, 1694844324], [0, -35485218666663, -1466165547846, 12571022016, 3400757061, -6285511008], [0, 311917339598656, -519339050181, 8014643982, 25246677424, -4007321991], [-499851590896924078, -15016706392, 447038332140, 514036556968, 0, 4620554172], [748025994981699746, -3362690393530, 6555496959921, -1022574156266, 0, -40604301387], [0, -882000267190312, -5902832524554, 50107575996, 10290997720, -25053787998], [2623067634043766306, 6446424530016, -13864797508464, 349476812640, 0, 62925012432], [2946656791850633906, 38430845316698, -82816142246457, 1884677901610, 0, 373291881651], [0, 4668747826236388, 33211441735497, -79368666102, 1309341600228, 39684333051], [0, -12091673108792186, -104697531834984, 740780534808, -816260936434, -370390267404], [37206722707591399106, -101589021149896, 187419319206276, -44084040669512, 0, -1348824646476], [0, 11647305040161285, -1502937879110550, 11312733924720, -7135594847615, -5656366962360], [75054746961784383506, -456795514972030, 1076420780753331, 91872497390674, 0, -3378916829457], [0, 184775981171560440, 590563362974103, -4141384024122, 4854733557960, 2070692012061], [180427224707257783826, 3494096691144, 49311251720028, 70732368983496, 0, 687282089580], [0, -253788308246927156, 1832644455112080, -12870394367760, 14938418857180, 6435197183880], [288522123575021353586, 5242672104831978, -12165175379166849, -819835081664838, 0, 40952194658955], [0, -816901683653652408, 13524964819673769, -119460288175686, -54970010759560, 59730144087843], [0, -549507931587248666, -19962349281247788, 174770268992496, 70679911185582, -87385134496248], [1371841497781449552386, 896752522164614, -2312316183130287, -427583908333994, 0, 4344153831765], [0, -4288142153324509375, -29043072312567030, 262157087995200, 156056326602765, -131078543997600], [-565335199578431119918, 22303225167668498, -48317556521944725, 776646670889698, 0, 213702517023687], [-2307490378271838453934, -1157725771660168, -1933557240910524, -5554082642549384, 0, -62146374205644], [-6771835292429022219934, 31362718401631518, -66325338092695419, 3101468358339822, 0, 319112840370105], [0, 969329267434288768, 170532786785358006, -1391003804070756, 84768032820064, 695501902035378], [0, -1485610795634273869, 9363617894689758, -213975992601216, -924136955908777, 106987996300608], [0, 17342321322564759968, 355420639180377477, -2631888817335054, 1980341548564912, 1315944408667527], [13854835911550996165682, -177172484328004872, 397495258857332100, 10800105412123128, 0, -1540484989961868], [0, -30260352757904605304, -687436500792474648, 6015041909698032, 2410616179768680, -3007520954849016], [-15596880113641210369534, -131732035810091488, 289479965574284976, 498204540587296, 0, -1215128067310224], [0, -56514310673232406403, 673813824246103914, -5296410417940848, 1683331025905049, 2648205208970424], [28575171103948015766546, 202595933108394834, -437115175387911477, 9273531089599266, 0, 1961754298129575], [-76929473810150108343838, -1105871813634915178, 2412660572884390665, -17520436321387418, 0, -10401780092187987], [37749790949609326487666, 630068970851505146, -1560741324928379529, -221077206901819190, 0, 3786960777311907], [0, -129739694849424617884, 2067997723085762181, -21619543187794590, -31043154123960028, 10809771593897295], [83935332766153604450546, 2283730547591747384, -4895102710766551452, 144517781798351416, 0, 22483780827686100], [0, -1235986505841753502, 3595365128629659744, -24323872838328072, 35556365487377722, 12161936419164036], [0, -43609282214070330216, -6020419050291031524, 48364302461310648, -8008683402321544, -24182151230655324], [71444636911254181575362, -2832917029085305408, 5691948025150777440, -651390220424522048, 0, -32262104162128032], [0, 372720889187553996220, -11978324078273700705, 95353033853241990, -21829470283599940, -47676516926620995], [0, -444623700595820173000, 14355095439555571752, -120455464322686032, -15569081980598952, 60227732161343016], [0, -465466397190724336536, -4568623641771851466, 45577273542709500, 53834171870408488, -22788636771354750], [0, 1063705825694890737147, 1414837231482843918, -20259811437978816, -58151658790643457, 10129905718989408], [1716802294612109203439282, -6424506830107224198, 14638881042052398135, 671161308117780042, 0, -53271717796198557], [-1637258348762549446212814, 9899387558363205128, -20216126577663283524, 1871415872924655112, 0, 108988920660072780], [0, 46253523461693173262, -5159779822280349216, 41931025409768904, -3620013055190410, -20965512704884452], [-503746237090316645351614, 13375316972241432854, -30435638697326128119, -1345963872298876442, 0, 111382899073542189], [0, -3855078891019884328395, -27260687320947306198, 223902924796644912, -3137886564163855, -111951462398322456], [-1799879703436736424068254, 19322894325270440502, -42149649535668149319, 314526496976256006, 0, 181827970576358301], [0, 4965968187338419423784, 55488722862082425498, -423737638286822172, 222477767235196200, 211868819143411086], [-3121914959839830929253214, -5293131862955555512, 8270201092735300476, -4152764752931657528, 0, -87462005702659380], [0, 473034094365221555103, -31480271209296670266, 334892595097175904, 511621060833900115, -167446297548587952], [968283963426888604231682, 54642146057237880038, -116264815409932497375, 4524006336697331638, 0, 547834744388288997], [9647709255860478034533506, -74796689686207671784, 174343657106907534036, 12670109332353970840, 0, -575246114387534268], [0, 8043348507561124662972, -57550137440447068857, 215160776676089622, -1744894615239009988, -107580388338044811], [22575224534453042145205586, 63764693920254826904, -147279729959939956812, -9126188236472659304, 0, 505912089664649700], [0, -20646185163946161005768, -105119003634655054752, 1002980226389623776, 930171881760235224, -501490113194811888], [0, 16450117149398434688296, -241646694444123685506, 1993473231641246412, 31127955571541864, -996736615820623206], [-1114700554824642722271694, -288570907280692732390, 638363784655610045031, 6344640428525371114, 0, -2613206174557105197], [20923123537834013141089586, 151205766908692619576, -323803516620578694684, 9942378877444273720, 0, 1492112460982749012], [-54361740897913668340375294, -338746310649037164594, 743521666023687250413, 200739157889827998, 0, -3134681217510623487], [0, -55972066306192698926072, 10671678205478296056, 489425467629026448, 3896492917911389416, -244712733814513224], [0, 12148267017686215808789, -264285961922694899934, 1341277835025856608, -5628928053725184559, -670638917512928304], [-433164112889303013684334, 250966557628253865384, -572257049231483033364, -26720542058666683992, 0, 2076351996014696124], [0, -4415569945513348352640, 903479072021659238580, -8442317960673970680, -6792364455568233280, 4221158980336985340], [62562683882521111833842786, 161251946140880909408, -347493665925875656752, 7901095579243731040, 0, 1566231867778931856], [0, 22816115721619411642172, 570085537218862096413, -5655465220068343566, -6502971501080091492, 2827732610034171783], [83103469609873708700045042, -136395419412920053672, 262043954269352741460, -46263992411171915432, 0, -1691290850223073788], [0, 14760713144983681147992, -1168720278640657029396, 12515736472470344664, 19552316820249435960, -6257868236235172332], [-93739324682420877514807294, -155721891146890296936, 255696088248070449876, -106792076678406802152, 0, -2430684887271269436], [-117770726907381629681516974, 723325809968193805106, -1604025665773131966117, -20764999322256557822, 0, 6505192691166085623], [0, -138343348768550862814300, 598342795533353776743, -9533852193851206218, -31112235889975987708, 4766926096925603109], [0, -26562742841995916008180, -4523122625657551219980, 36346528348301274840, -5945523963274795940, -18173264174150637420], [157216151513309919486272546, -813779277695771889568, 2163293461894870005456, 468620747939632445536, 0, -3195912312556846704], [0, -415868695902279257263901, -1329157887219199103562, 11643878862614434608, 4754077477136372295, -5821939431307217304], [-67764503811897988576226254, -1792961464122040697302, 3765982768567673036511, -209261241282930543878, 0, -18539099124120104085], [0, -57567774569498580154292, 5458023849245316224481, -43825748639612495526, 7399743862911001004, 21912874319806247763], [0, -492060878640194067350832, 4629401965027215473112, -38369624919172177104, -1805970147344669168, 19184812459586088552], [-227212686700462263380780014, 3804000937321408170306, -7830014510804321873709, 642605229635712344850, 0, 41172279323677041807], [0, 928193866370803761385216, -5618454167811656421873, 48004969028954388822, 11897198289238990000, -24002484514477194411], [-263429670099372175425675934, 3936727452865282614038, -9324261650690843125047, -850756918914242275610, 0, 28573801240287410541], [0, 411457550149968146159192, 2034357644924585437626, -27920802205581163164, -75445545725195882600, 13960401102790581582], [0, 594288050364992770976751, 6845830975978604973414, -68166814523393716128, -79802054922985085341, 34083407261696858064], [0, -239122849746254343307322, -21743381008961759981484, 166527638773959006576, -83904049884763371250, -83263819386979503288], [259129433677698976402730306, 2582253316619349569406, -4595956137662115826539, 1329089346796291249230, 0, 36216135772367044617], [2056602460050582956319583442, 4325932048102307358792, -8625114861364454036580, 1077396441067652966472, 0, 50030819344166299308], [-1249273529878545529669592734, -12019868719954047871906, 25999136617956208687461, -468990021722285142482, 0, -115637580941447527911], [0, 482453263590848808520955, 30650278487651468051670, -266347637476923067632, -95053303655260259201, 133173818738461533816], [0, -1508539430783289900532596, -3109143472773362611191, 18949523068846538730, -44820912217139341972, -9474761534423269365], [0, -4094378061598268299113878, 11219854997369929032828, -99502254432839244816, -48314939790002178462, 49751127216419622408], [-886498370406576000306903358, 6208405844803444770710, -14638423773028097396535, -1259282554811702392730, 0, 45825215648071688685], [1012211550599161588888071746, -11629504107906870225672, 24987738379435823044836, -661111822929417869448, 0, -113801999359595260140], [0, -355095928271262864653256, -40963840978524808377825, 365185871861377386006, 189235691812919112328, -182592935930688693003], [0, 5326789175298557578297260, -45832282737123181935672, 364942975957014824352, -82872842130326709828, -182471487978507412176], [0, -1629932831275552191873200, -25942422565598642204310, 170579999957477984100, -289830698375837063120, -85289999978738992050], [1123206900298476130335554402, -8589538464349798372768, 24812228554926562696080, 7402299630818006400352, 0, -10992952162331407152], [3386294715704347772977273586, -13793402064865901781718, 29167868796504401147871, -1366740912077510325254, 0, -140371694230957519509], [-1971765345684477889402716814, 29045388759876529870248, -71296100261716406331924, -9381858530742923041368, 0, 182069724343829692860], [0, 2249350797104529684269658, -106338433276685014045848, 891522019029206156904, 110082890853529667666, -445761009514603078452], [4859461796468061357977314946, -6921369329430539099386, 12827148712932052627473, -2931407702050299802154, 0, -91229416958155915755], [-759726284350047559869507118, 20812505201988384179490, -42221995158086714386845, 4282623629860711457010, 0, 232362303998602737375], [0, -6441659856144487504590204, -65667640665124656837108, 421817097903048819432, -800936848328012515340, -210908548951524409716], [-3246416954826079359242339614, 16529506104049427083262, -36536129925497481455979, -326541210276020442674, 0, 150027452720124135561], [0, -626256952322053020548928, 109930204257286281207966, -839580187604146139988, 440067303521251399968, 419790093802073069994], [0, 4839823415343356340104467, 82328079536674701393654, -646620932547547275024, 209090901785983748791, 323310466273773637512], [0, 6601007798763108255038096, 222157969064701531921629, -1826116677320793177438, 15821820568064492384, 913058338660396588719], [7044523143065637951232399922, 56993147881782037099112, -122911920822295179453300, 2676880450281188638312, 0, 552500262333918756828], [-4327240086776702639483774014, -79305478438322856790984, 184588743780994985222916, 13105585499597026949560, 0, -612961971654868794828], [0, -408176390765286976137179, -97019387842103391392550, 647733222705464623440, -1017766737966079980255, -323866611352732311720], [0, -15643714638746099991265412, 36065097220910686155891, -122923734929923839282, 1173881301495829982396, 61461867464961919641], [30325570980258963345451381922, -38227078031401811036818, 87244527024812729106525, 4167717531466040549182, 0, -315364449073479356367], [0, 15888733282914224406176775, 148983121662997167732510, -1574344007119733403600, -2349981955669468933605, 787172003559866701800], [-19332745366524810000575713294, 26588915968383650657288, -40635271462867256318532, 21988089270313350843400, 0, 449787085543490754636], [0, 32189858276507706041961872, -156091189817617724226132, 1487710400696421713784, 1370312437055417444368, -743855200348210856892], [20029279106384502603870498386, -70072425385244867119582, 136360944211585515370851, -21611297028181584451598, 0, -848923355679874551585], [-58854946450650909310727492014, 12239499905779076220344, -31781603275123524506844, -6110938805099995201352, 0, 56745936117398898324], [14849853524797840230502504226, 186247838586294781620774, -393558372677815777574847, 18809580410893784667126, 0, 1898679805529523761925], [0, -27393734003146944781983760, 432132409231638886532790, -3854782118781999182628, -2012423233354111897584, 1927391059390999591314], [5227498014051810719403449522, -271458340445628065125942, 638521454790372307228815, 53157361284440893630618, 0, -2021305362603584921253], [35809582920207506706444596786, 449303932072623131139672, -989292325803537602892204, -4121141213452632554664, 0, 4122062878325652764676], [0, 6644770572476992519607554, -419145637102637383570572, 4249646876972182920768, 5399247691637935627930, -2124823438486091460384], [-42337448428822166611943901694, 97785378666833355574208, -191994439638059597756832, 28042934058954812797120, 0, 1165076969683223781216], [0, -59982862886941387997066179, -19231088767575133781574, -333777264718208271696, -3321390357268746599591, 166888632359104135848], [-35841868805967949973388866014, 171040358633686007676686, -372895343603148617702259, 3032964218891185144030, 0, 1611790026412751785377], [0, -30916067332953702696050113, 327776054171846563371294, -2156815264252881102768, 3651277753617861632499, 1078407632126440551384], [0, -27651803695247747685649914, 384057671259594289134204, -4325739472077266884608, -7862204144321868741426, 2162869736038633442304], [151650865583678656292929583042, -334850942854922345359842, 708793322788242160156485, -32298788453867155786002, 0, -3399534549155458343943], [0, 49870560867611263749112673, -1170508104764336681399214, 10093065064336690659216, 3099961141809512983085, -5046532532168345329608], [-55067400356019539118964121134, -184842289587032622048574, 327487229232134313383571, -97000021552370408966510, 0, -2609651029068546583473], [0, -49278680537800810027129864, 234640427886812102841315, -939094135882561688130, 6696693909837825429640, 469547067941280844065], [110005126625074429385993044946, -28726569951326125927752, 169835150836071703279908, 132574703584269564475320, 0, 961556792897624430996], [0, 39258100838991872645336104, 1874148273904300601250726, -13503895080069993480612, 12968056759766466297576, 6751947540034996740306], [-5675212794486455208726539854, -495933086555761251852520, 1188713857247883608442996, 124654655966161069227544, 0, -3437763246200001690972], [0, -17854217787641628787024590, -459417574184873807410308, 3069231463188688359888, -4805886189302676204662, -1534615731594344179944], [-66971964237641883024499065214, 318769727543633533214126, -765234665688643561403907, -81573775477383416780162, 0, 2196258815428241818833], [0, 81248862145898619770525064, 765893436958721998580832, -3863269136134397316960, 16472568717688484698344, 1931634568067198658480], [-140828397605947196756508794734, -1311137247668849950153672, 2960619824468344008342756, 103533486724870284075832, 0, -11181516305036848759980], [0, 33391281550499271776880092, 970971325652345756258304, -7010688379435578218736, 6620704863940166815660, 3505344189717789109368], [-106860953285599873743926768734, -817688441883100061581266, 1794772458891562334542461, 497296942459971676158, 0, -7566584675376297128751], [0, -39595206385579085577627816, -1363885385226016582912806, 7645442210120565717156, -24164675372020436015464, -3822721105060282858578], [-93204893967195820454334718654, -672241328272854452995138, 1612976863102058137448181, 171038004762710040052366, 0, -4640771513982818638359], [0, -141568730550390850255838616, -2508720525211903447369212, 19214966885649238011528, -9672336033640057164920, -9607483442824619005764], [-130461495776991503145108901294, 1378909295557066673300034, -3197563398411905985967917, -213049930821391320832494, 0, 10794994117922919930255], [0, 143961056296562883651248588, 6918950882892022789439052, -59462636144483774612664, -16986633814597545888868, 29731318072241887306332], [-68549484857611994282804600734, 1748072539895197059978216, -3419387066005624673661204, 517234354328209637464680, 0, 20975063835401913865212], [0, 50683853526324305074765371, 968971484896111324294902, -10782170427005842312368, -18947901221394362036545, 5391085213502921156184], [0, 58597576027687931468793352, 1101335242766723849122749, -1606927178743715987838, 50338532808297908700024, 803463589371857993919], [0, 338481113576739768409539802, -3351069625229197558424532, 22591051311825155820816, -33680938380135618121966, -11295525655912577910408], [-480522894798429200723308723054, -2085520928780924716595710, 4629577320317234999929971, 65814833025083013324754, 0, -18700982368109645400657], [0, 208251335759605563666158988, -3730503286964942199870309, 36317801750292538838046, 37894979205311181608460, -18158900875146269419023], [0, 497542887492296242793421256, 6708553785432392217964956, -52530738926100885021960, 18114944772840815988712, 26265369463050442510980], [0, 116797517721449530935917528, -9961959270745338678233118, 79481155848170237955828, -16944379732925264811112, -39740577924085118977914], [-329117360727985423972519303438, -6283056762745897514167062, 13713676921736011669315455, -92038450842395983580742, 0, -59028659385076791645813], [446762925888142493394685982066, -1778719422256639672243096, 3463718386654657821671436, -545688704782994914725272, 0, -21522297472589209138596]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3_21_b_a();".
// 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_21_b_a(:prec:=6)
    chi := MakeCharacter_3_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 21));
    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_21_b_a();".
// 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_21_b_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,21,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;