
// Make newform 7.18.a.b in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_7_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_7_18_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_7_18_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 := [584478460232, 30882981215, 70948970, -559376, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [61684487176, 52955726287, -199426527, -30823, 431], [1032327997240, 1193532057, -28704009, 7871, 57], [-900760238232, -5631802621, 18707757, 8901, -29]];
    Rf_basisdens := [1, 1, 46343808, 46343808, 6620544];
    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_7_a();"
function MakeCharacter_7_a()
    N := 7;
    order := 1;
    char_gens := [3];
    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_7_a_Hecke(Kf)
    return MakeCharacter_7_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 := 18;
    raw_aps := [[119, 1, 0, 0, 0], [-349, -13, 0, -1, 0], [322754, -492, 2, -32, 5], [5764801, 0, 0, 0, 0], [153269839, -209457, -110, 167, 7789], [122253920, -1585486, -2446, -36458, 32285], [1764599746, 16397248, -152524, -405416, -175678], [3671317451, 40799035, -247484, -3414817, -165782], [-43430390707, -809661639, 284378, 7338025, 1152449], [417516287538, -238179628, 9584324, -108225380, -18724246], [-2417943384676, -5491609572, -21062316, 107887332, 23835282], [3368357391548, 8754001278, -39481320, 622465734, 24668412], [-6532831756800, -8165306114, 5766808, -132422842, 375634108], [516409433069, 59424810821, -104814106, -600172595, -529798273], [14502781027898, -84727738142, 302097480, -2036762790, -656214348], [220545222127012, -283879045370, 238867676, 8416776166, 289156070], [33225756706741, -874090288795, -5115150744, 37022044137, 1319925828], [749300201510918, 1944360805584, 31413450, 7426079484, 5646911097], [-757858474494685, 3144234110763, -3580762290, -192073594629, 6733967619], [-776849931671214, -5199907668174, -5359474020, -271449957822, -26705809722], [1174574130486158, 6188961506164, -3621879392, -127638944764, -31656815024], [8684471390609876, -16059889034700, -4229721312, -238754303292, -57705245808], [7011972583073859, -2347593003469, -12867694228, -1163616412313, 127579455758], [-11675583295651192, 44827695797702, 130845881260, 1363894843142, 29864446126], [9508537489517528, 102890785456382, 361667667536, 1497406355158, -391538962360], [-30486136970419640, 43682653947570, -568183810082, 1585084749758, 173962949419], [-127458774490057264, -115599558116520, 304120361988, -3939622126416, -202176125622], [6069144164121443, 147301413697859, -1037520027290, -1066604129725, -1516683042689], [16080071844487340, -21912508984410, -574808475744, -7453590658434, 58937738832], [107230517998882881, -308950471464821, 746192124010, 12325269810467, -1613707422167], [-283923303461349775, 724263835752005, 2552496992378, 21437799002149, 7004803170833], [-334167127272386125, 1951017139184403, 25107607700, -28379618795657, -5641528462990], [1113857372655155986, -1635667924606776, -3005723022440, -14344114869064, 1772129355004], [-264322843375177495, 893041713255209, 802868438132, 20813314535077, 18170102247650], [1328558001312277574, 3761037188936976, -7425698061064, 39442585407328, 16486051104620], [525731954987506019, 1650039619028775, 5212413501630, -183354262162809, 13855570306107], [-219414999274385932, -1427924314321466, 6152339660554, -94538270043958, -22922144480231], [-1252560394526512291, 4071437448811485, 25056011655942, 487721206780293, -2403354911601], [2060939747864518182, -2773306471712378, -12015274795112, 603786095308526, 39260090212348], [11769907698849585152, 958154269318162, -12759676075254, 92028169124166, 13275402541593], [-1375093041145804073, -3264138787428641, 6225730781630, -44211673593953, -154865671018597], [6691576397663474606, -457887189170544, 24795621464862, 332662461463572, -106585181923893], [-10124318329086623266, 33025276848941782, 39181265679108, -61738475105370, -138592238107254], [-19917651348218189809, 14196414074758977, 46204146204942, 305552951031273, 29678075323779], [19400611519369311252, -1571442543322170, 118882848654900, 66387919142646, 93347625683394], [-17136158490965600260, 73293728208618996, 21503948055156, -496880596832292, 262406490024546], [-6633314548507238221, -108423027667158037, -105811447973314, 719902241075419, 151667987388251], [-20184436300443364030, -62822566851797718, -126358292403972, 584948969637210, -776545033451850], [45238071921174001771, 32312432340171339, 410176779428260, 5147262794016623, -327779872564646], [62209416771109035368, -75054901754007102, 264631146126522, 792602947391574, -511974900515631], [32803586657744131106, 116681345739801176, 121904836196800, -8762500356160456, 484453560910816], [-86787110002125859389, -43207550383581137, 902787156943750, -2007996341964001, 919797105246703], [51056853486371675276, 293524595028535218, -844294230612696, 1593323246781354, -177077862368796], [-152662970688693235779, 213060062951938461, -538236456944436, 1090397572562745, -1680123011396994], [106268580309978784958, 218056161318887340, 1572036929555048, 11090948934029452, 41019635704196], [-129510203209973409614, 252677596178359890, -793737221458148, 21189385333057250, 102147423057286], [-150807011822946094340, 830366938019162974, -494179990637758, 120695544722002, 4695525501075365], [-178113268445691272974, -285623302109892726, 1996795954190580, 17680953619410762, -576896441152350], [-33308085151268049910, -1147268284508844348, 196011373283688, -719209190063100, 5320914122200836], [-22045843985492158446, -134109484025562280, -178210278872944, -32470636561791080, -3613268658222616], [-235507890791952950239, -602662813979438175, 789748050285552, -25338746805915387, -4461232281716904], [329520768855752462016, -1651027682606683094, -1728784800616538, 48377272889474438, -1998462472649825], [-434313933167064537421, -782899800389857885, 977405932734452, -21609417541874297, 648298881718370], [-16357635957522333908, -405423049448958268, -1317269450886600, -27171905330604444, 12487982612180748], [368962501417150917812, -2348072465775081230, -7553657302310048, 64417504887287930, 32398956481072], [1093764063565728690308, 3095350981729706782, 2121979533931140, 49675072249758990, -8945165459252982], [-1969318494004312057243, -1871573675253673475, -4940357472234698, 19897551633833669, -8940535558085561], [678692692391132456927, -1271826748618160319, -1978938401342850, -25493505869544183, 51822795153419163], [-296722671946319123567, 3526644803286968969, -8339165517828834, -149506750688589135, 8607295829139723], [-723618215297651563618, -4922271001758061672, 3871238435269718, 19485661779776716, -15283643983299625], [329194501583619291148, -6201987710463688398, -7740136374946028, -163980737623768750, -8900069590106894], [-1529808508128308768803, 2715318254095887833, -6274501029092558, 351460617122416793, 12345010974700573], [-2408514123956724463054, -315148367597910326, -10935640556089940, 189610580328003098, -32954438687731346], [1952319869752662597374, -150417084009347384, -766300487509592, -221312362442750824, 26574902064112420], [-3108092820635811740947, 8822287835088723989, 11824067473184414, -433048592686648211, -611302203111733], [3771676019303534240534, 4851536258173449438, 27938691185801504, 329092022113084054, 46706205065984720], [-7114646565974691931424, 13735841086474370130, 4150515899292016, -149849563276901062, -354278934781352], [-492782565496416735850, -10286421590657296128, 41839562114143782, 35482611709078068, -38121381907761441], [7567141497035709949649, -14905966911231219237, -1352069336411566, -134892235153500701, 800451569665517], [-9182210208203044690174, 9415194571756455384, -3985652926470300, -195685332581158032, -32738336278083078], [-3141419634039697623393, -13245238475458382561, 86236748124371776, -512206452550605733, -115292404665221600], [5123213761290151032014, -19220290189145693496, 72135132988010976, 922621675459578408, 202142305243013040], [13256115608874382598497, 21364782069763267813, 75751704110988338, 278292228918530005, -15841127183514787], [-2746083668065208751958, 1607541712618711688, 11417876335747964, -32773340414278736, -137817133716573322], [-10538469296030075895598, -8200442660089972766, -23562875928825836, 633198166355985602, 249348421775155186], [17310357318661261562849, -38733362190441746711, -91063879697686326, 21006700819170873, 22683753518372409], [16689142195340647345122, -12321748907888321568, 85141175567345424, 1131665021248037184, -47632420275958872], [11747426289522530772551, -9213073670158766031, -22005410620286514, -662699643999860967, -66491754221175069], [5916873156005241755742, -28143162266446324216, 49223069396989550, -1858692579989889332, -125947987894550509], [25251027944074814242250, 12802862135210872770, -116025012704688300, -1699254320757354846, 136673235937672146], [23290722562914566502659, 96288991639222381811, -200336561130538388, -409602089005192921, 108897170503872334], [13334017268219701238656, -2546161420887978864, 257982691861803868, -1811658675631250920, -367590482288634074], [-38613749370204745933963, -36403801906252184591, 88427323418327146, 2615998031743253153, -577452916556788823], [18401650401474653108913, -103685526963540754871, -221374963370418086, -778869043166330887, 233565987334337185], [18808711290819715690349, 245212816860524408205, 231275174104422498, 1750845878421834813, -570591682433837835], [-33420792324964340717262, -43473190357800605598, -163651963382246580, 1625033193838114002, 581752310107247742], [86436392194096050211970, -172164772121544541524, -146456021342952418, -2999292655336177760, -759503287809565237], [57555050046946488679306, -136423899114197446928, -258255414590385508, 1933158346771179640, -672805830849218554], [-34298795405059639475515, -19331626172024522619, -108998823817713312, 5564688091886096793, 1162141695970896816], [38383688855495797441814, -29077535045541545672, -49314617051634440, -2450390878808536, 744066204310239724], [-11868529009745408164555, -245128983541266667147, 665895895438287182, 6189093716202517741, -1317364134748100797], [120739788612710941988260, 198602857831431776590, -687054558502983436, 3477234067433304862, 680679542135971490], [21812001254588957205895, 154944798250920635639, 74572186487059704, -3527820085373442525, 7384520987631660], [313854361217743845687641, 51144213440771762299, 390450518944590594, -4876840540068033117, 400728731997243045], [-49838024005124377526695, 164265198692956378609, -682317838029747770, -601755024970081687, -118325073191194961], [257976476947829386950464, 1122304849943398998, 291696536366684268, 9073827515058272598, 1580335230638912334], [60432546013838894079177, 337020449242611043049, 171271097279467388, 16043860295774489941, 73378180147777526], [-17940024502578282917206, -82646739448443231784, -2267981849749544, -17299273512146441848, 1052277190449704476], [-164670180359348164725764, -680332144493659643980, -994796583092045832, -8574061923081401964, 1598661117311691372], [-119812974009964766592700, -481429626843289027918, 573142734323241380, -29106802083748693838, 627900406694208026], [-143374895118647575962904, -123501657044411172824, 1076766015500891920, 5962960076677227176, -3391604177832617048], [-65879473547175548365366, 395086859427243996132, 691182873460560804, 248418477908755500, -3353076973889914854], [234324946440433942766559, 447265384925326328905, 2068271277464213614, 14981556654696756305, 1051259898965681779], [-80541779625834656756467, -1109863148027227179027, -423650389628718744, 6669593931053553297, -2249625576310348668], [-213442854268744593246292, -376260908151793987036, -707125580186488000, -19659848970448377548, -5424923387811169888], [115857407910149582394865, 368870378321451592971, -78406553969194814, -2943435881774998285, -707705090848600571], [314800628487533102076371, 768739089996340684067, 1185005883706443248, 30285386516478430735, -1100754932774393704], [-325937099004265374534044, 517769208320479978300, 163031799312719396, 4335560909248327396, -1772557350645163750], [-187455172697005894277818, -1001360529108326025240, 3679435094976552980, -31295321712104370080, 627147895005019058], [223758886132220431672953, 450324404710387768217, -4564549818229548538, -12761737776710806223, -5362537266956917105], [-543235638240076009997584, -151281280786667100374, -1161919653377974538, -4745953150218192922, -7398930267993712793], [-338465774223073489949266, 120814619658629420508, -230013748991944272, 58502155931310716652, -9081492240615703752], [316440960511392006929666, -806607735819150793340, 2101270007782073334, -41198963507449294296, -4757134994481981849], [1143228878280292464972667, 165039925576989433243, 5949811951996828478, -16526273428279571381, -8807231143245955429], [-212138123562249751654825, -1880764132025215409961, -2577944701366025556, 61056595972070429979, 5647158340096286382], [-359449255633128162772626, 2206720471744173336192, -4210634682872215020, -3225402287502016680, 11774527419646255410], [-315996713093163507058984, -525107615280527977878, 221339294688093216, -8147919086081999790, -9092339963250693744], [207200434641721279226114, 952639697246513328650, -10881393214928379248, 65183300631814660754, 160097009913212008], [-302254703923200067056478, -469966553503257869086, -3286762194102561064, 93034384284783237178, 22852092078755085212], [-1186107893252177151988450, 2799321860472260108904, 2050671947311865898, -60978163936569740748, -14282773440273652887], [816438460688341554842093, -1027221524785336097427, 2915445496339822566, -73189156724620469355, 8218844382125034687], [1363068491898150577195833, -970838835902408671835, 5119447088128748410, 93600709213392056837, 5126603829456093649], [1734187554754012222833797, 87242889013975429273, 12985627371520590106, 122218382858185801097, -4350378980572406111], [-2605939040364306191517490, 2597506903935074986280, 8485970989769437340, 55686372462927472528, 2292520817402168582], [-1604363116806972988851196, -4631655502832949988446, 5944296254218898552, 39115649018348870074, -16145355749306350228], [913262237337859524108296, -4684728518916196722258, 2263474834308857256, 125505571823082477462, -11234278717441760604], [-1686775064051841972680666, 3633642288474034707880, 1668544405281951170, -90696098964370715324, 350675365790753765], [917426711082707823079475, -977208165365727955869, -18529994712983830020, -135459545707198478025, -9215001873523945674], [1025735805658856501389248, -5502615497988612395294, 6449840730254309434, -116150231880156018442, -4296365753999054063], [1484749058903061402987247, -2134283412482122468391, 1277970288461901518, -53345889405197756063, -62896100724482982301], [3993429203327261066812229, 3453227187253270603365, 17471867629665536256, -99034132139986819143, 12921493615053982464], [-2922180236266484228189662, -3180488187406735162148, 20916928778723685000, -96079795970773461444, 40967246306443027284], [-1161176898982520591325046, 4454322676987258612410, -6211011390897834732, 88627262156332985082, 31581298116199919346], [-2852995606869218064495897, -5072638039086527623161, -10332395906299226130, -96217236533217791481, -9068295197210294829], [-864259261602173797123906, 7092252067816837928872, -713714408730857558, -175292426941630306444, -58142140790156183639], [-3385972217178223467684912, 1158132907213748747960, -20188854378163561228, 364598042208251824048, 32979409776134027042], [1731617105123480879768720, 13860339497289457250778, -18777459200478730326, -237273558093825617682, 11557820232056606121], [734639593116623242285030, 2513320125473201573196, 18913429354309458796, -567029759432973011548, 25937685620782039438], [7453942048761148281112289, 2087685309669940142001, -12248143711150687308, -3411721326733748019, -17410408293135535038], [220108367938174813789658, 16477559209959314545442, 31165785640604298700, -259743094037383154542, -50538134050155242498], [4508554338954592481331800, -10372124999038229282718, -4605242314554497664, -191925342789110598294, -65814853541729240448], [1230532858716171429724284, -19183451257292510805582, -25290740378184071364, 200090331919650299778, 16317953350677420246], [1225543360404719343712565, 11495852370573041506773, -15045219507705208566, 751590998692001827413, -13585691359450678119], [-1264790745958313521367758, 7946410269192961989330, 12383401556148113864, -591783759623617709558, -30964287839529690508], [-1524917929804109182023943, -2618487494007771120783, 47449297055342878914, 33966756679808444145, 8116121857524220965], [7300172120151947763350415, -14226977827996141755733, 40202450844069247094, 299239546586590193323, -40919320996879959481], [-3314075025363019591199326, -25085258692672774574382, 11505918798482513988, 176461854700492762386, -77379301199775172758], [482118446376168770620118, 2354036040679837759828, 20518556475613185996, 786364470127222663692, 44429131303649117502], [6891405240073480906667474, 4263847533666153698216, 33754829333485857704, -90696358990826792456, 69350268754745726948], [-10777556182266284550113096, -32316952892400538650886, 40552662057503426190, -246761556242206088250, -14291495054944983837], [-8298306931674364768849087, -18347481442428418934111, 9824144716435308582, -269305441827797753319, 38723533562119258335], [15777377746404177677442558, 12997267737947153586516, -68230133405899236936, -714114497820899226060, 35449403304547863756], [1321177160390582435596649, -6065157877951849759531, 26317648279255469186, 835290598520993858533, -75274763368285913371], [-18945838906122747804485539, -13542238230489298949347, 29328557784179699272, -164394402978578657599, 112761004182485383540], [11868637866982947392483014, 9711273314415185634212, -88500640630155707664, -66085196663105561772, 124657603908887595096], [-16526083703541400534135568, -14198513296104629598840, 45642502367797283284, 158328966290682503168, 29934034542149267026], [-5192891934586715235659848, -5046224129842249667976, 35254611189769941120, 196900718819590615128, -183819500258501923584], [5172900799341596952844346, -50633020340622506908884, -23300132379316125222, -401839802900519685720, 190786611344529738273]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7_18_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_7_18_a_b(:prec:=5)
    chi := MakeCharacter_7_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 18));
    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_7_18_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_7_18_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,18,sign)));
    Vf := Kernel([<2,R![-1167515043840, -8750693376, 253624680, -416814, -597, 1]>],Snew);
    return Vf;
end function;