
// Make newform 7.18.a.a in Magma, downloaded from the LMFDB on 25 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_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_7_18_a_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 := [1104138, -4009, -2290, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [207760, -6952, -212, 6], [650154, -22418, -670, 20], [2842512, -109274, -2950, 92]];
    Rf_basisdens := [1, 11, 11, 11];
    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 := [[46, -1, 0, 0], [-698, -3, 0, -1], [69566, 1771, 221, 52], [-5764801, 0, 0, 0], [152602550, 150010, -318461, 31331], [-2132155022, -6849207, 462453, 36390], [-11932351902, 16746054, -8375390, 555152], [-35659734506, 87270735, 9745486, 4447751], [40142497110, -376221900, 101259227, -1768247], [616609271414, -1793451854, -251466414, -52681980], [767848596936, 1165354878, 36824854, -347010076], [-13396340222670, -53823793086, 970827468, 99636330], [-21181553651354, 64936057106, 5222728372, -5513852878], [3677999420330, 23951745822, 14847177241, -4197464791], [27553161942252, -188732568510, 19966217388, 7206957066], [-128935518926094, 977472557976, -69056865178, -26283508622], [-694238182085574, 634424349111, 88742514916, 47539009337], [-833191017514130, -1747652384013, -247703088623, -94969117000], [-383759417007578, 3732034496124, 76852088101, -174327188857], [183086233368420, -3423863344884, -438248307062, 413995235498], [-437441731508478, 9594916136196, 911803706720, 25993847500], [460114239375032, 8061280041324, -2540371606304, 849241518020], [-12311671546522218, -31702291419357, 3397711630546, 182904861695], [-34647233180359306, 33233402684896, 1732334285366, -943293898310], [18280437970873134, -162293480683194, 14653681206752, -1599012381470], [76780036105558186, 115249556858531, 2304641465763, 2816189543334], [-70958920809917560, 15801990299466, -30991088659282, -3383142399536], [21368461505161262, 128770722610000, 27969433249169, 1222248171223], [88545063510709002, -273221465364234, 12589791439680, -21325275015534], [-159308848192302712, -224637889209530, -76242070142803, 363802081261], [-24991561534865514, -672720755106504, 131450033542403, -26684975228531], [-1227948436614112186, -529995366244745, -85635336295250, 16523587084127], [-1015165635849790134, -231859747839492, 283995431087156, 105161275239808], [-412641622206617886, 64007151962457, -576446058911834, -13783952591971], [-1221330231423401658, 5456374901587428, -200071053369612, 295222264883640], [1775021327971610042, 6757249254172536, -471505595938583, 28580018322743], [1444043671069984810, -7752754505260191, -380821119900271, 29724597873202], [-649727375674404926, 68788736846934, 796788566422625, -273689912036471], [-184355193854347732, -24857938757432954, 26383217472868, 141170417379326], [3153080339804036146, 2450698300384301, -3225012143775071, -460998592232218], [-5887388472124436402, 26206945742614880, -1640789115477827, 90922578066299], [-203347129867058810, 2635694980725801, 807719322216403, -701661776712712], [7220017100617198676, 5050745556690988, 974736148420470, 1511520215375166], [-10432832062396223308, 19610975725357482, -393642005922825, 1307584911836319], [14908532306313724130, -15602416604500388, -3220186392682094, -1168427818987822], [14532251443566641808, 41317530158253654, 2773491507768534, -431686990219668], [-15371566729831497770, -99091889757037980, 13926301470389949, -1528142540145369], [-18048851678552767892, -101952253070729532, -15300106796650974, 1955896520434746], [94276020374841738630, -110073371911832145, -6159257106231954, 1925683446138375], [-66950234506509829462, 104730695971857093, -1949257262665895, 653551897662710], [11705113933212205482, 140140840651978872, 28774091388370104, 106951504977072], [90012658808513077458, 308312275460274612, -39592242637006307, -5897858523357193], [-43391531301991871386, -422428700435321922, -3680196541489124, 2128357381769966], [16281184750837233722, 73653446244767497, 36899115317814658, -18309453370857871], [-303020522792916907526, -54642212178807544, 10083107060238740, 12727363046894116], [219088897436998753796, 817886260972119724, 131942481056288298, 4352117891908842], [188336398323615484554, -720475866949648083, -62708454716243059, 3413487935677594], [-279362373812102468, -419918544371297088, 84029056009353750, 2908670579272698], [151910599844872352878, 50236756073667072, -28693016000752260, -2934249602577756], [-158039978874046353302, -484607689338431056, 132627212795622792, 4146833745723336], [311579181944163001042, -834549487498743753, 38717903941519448, 32500024715641765], [-592967448181666189478, 2480780302793201927, 26936164697880039, 32900296038846222], [-175023712724063801546, -821706846435417657, 199046622502838654, 91214899550983807], [-665323243072496106240, 2432723245454034984, 100355995467520308, -25072277261414940], [536151999320280235070, -2226602815580636382, -361464705709246648, -28268928079522130], [-1202951647173620294838, 5647155972666512220, -25470222490318758, 77676251821939914], [-261744975434522345638, -1592375523630465810, -161063297137666015, 228110699566966225], [863566293117419750452, 2538917580303068658, 353698892945110967, -45115575982899209], [-3902995083423245539982, -2762645435544956602, 387225640427211309, 13218347307906861], [-167623862995393195778, -3233213916814630683, 1253519856462188559, 198485409996333168], [-4011739530067116655066, -1165616227805808968, -982387132549284582, 11410663304503422], [1359573867687683364934, -2248473955279020352, -651216752109396881, -94096068079897831], [-252653312007091723620, 11911607222823494220, 970959154989601306, -383641536166155430], [4677291364141903311926, 4270243524055150980, 1637317093135864636, 471119277565463312], [5053771700215578790746, -6785292719845830918, 32975311220321309, -107991497436987143], [-5410049859853723764732, -7143064835183479614, 2000640539066372048, -52310908517572538], [8231011425128783430714, 19759851721149414810, 1828206318956177496, 108961064575790406], [-3091926657955548005922, 19603324503932623797, -3246166294733265305, 470393587419840584], [7312915672646341121592, 17064482046817181346, 3558014713680224329, -852886598683], [5095994289204685842890, -16676604988452753642, 198908559224751402, -401415294704268744], [-980022034613135791698, -21736920075355837263, -2635132090312508112, 164567041930188171], [1687869331576757494022, -10652454643815035544, -2553192780904565512, -1259046157728660800], [-16268642194041956966106, -7970931513560498604, 7194469008683564727, -861709156717438995], [-15376628625702097209230, -6731944785088655142, 990825744873759110, -770968123647175064], [301667064417669330564, 82091536514973656808, 4776086483294011478, 821987739227289202], [-6348148163485985237934, 47631812363658960540, -7052038445561970961, -781430651071064627], [19887894856610287020210, 54904495857150822936, 10650548556320337120, 746574315142605864], [4110897807906304671916, -81199314751019859462, -6216504941356830289, -2123785723674025577], [-17796324184179731937074, 18350976713167995017, -11250005147749603189, 1964940070454398624], [-96820568018563605812, 112132953647895812808, -8920908596510567186, 660726156307143482], [5835157363534696846566, -108779080349949656421, -1048186244550082630, 1365397945798155775], [5358710719083159839008, 50472397724019417662, -19642401710376696830, 290831180002438616], [-10484172294138207508970, 53930575304645673252, 10626902887856414995, -941775841852425439], [24616042409383109098978, -221434541643522540364, -5929808171841743993, -3688498308734063491], [67407854003217329282290, -67794132474615896748, -925679345556900261, 2719147741653451881], [-98146967076277239050844, 8687525938638021348, 12100689204174396138, -2413033368792090222], [13802157328726620664198, -260040137888137601611, 16385524358833940179, -3909814761749787268], [-85709416123495355733366, -54324690042446359422, -12272368706113082858, 4022539413296261648], [39578999063068983017674, 292914446226924178851, 1221224138677644920, -5484002477070177623], [117504190674920358332606, -111538482255024137892, -11050321328255333916, -3018448351249973136], [44890766781968365199794, 429980764393009511970, 11587238343822773501, -10359595032101818031], [-7821551249122237861702, 766463104190101722052, 7454231735756498658, -6008940220296964230], [-61601586091243569959746, -280711187093263673699, -14092566344065859492, -5846708252895967837], [-134648384757128089840144, 35041966275822637546, -75014354261381072343, 1439775235433067549], [44985054060728995563554, -740874871507121657070, 19571821028979959929, -3326589795290809915], [10548772849621003912270, -351135924868367172144, -92688721467605511498, 3288920081836979466], [12497507207407341957698, 714564354431580525901, -53644817064605096190, -9705939456773069475], [-65053508838493683368574, -170299680633981215940, -126992868906554602724, 11471552101870853912], [165312554197331281341216, -394581805369214589144, -75334849796594852524, 35902973473671238852], [-239647776329737340018514, -78020185922171946384, 77125627879604189506, -32024816319325877890], [195505254230046699831056, 686442785081514797328, -136359735740520541912, 16348816039446914632], [253090393930408535005150, -111426523772745942558, -31780367389954424958, 28183175279360255076], [-10963271168004053567700, -1573122699585556007934, 82664732033016651799, 34376887566646435655], [167247407338566656039338, -470645082631692342057, -130249419728779616500, -17032667084189320655], [224716256641649359503584, -569410404358716346116, -69142303938250999648, -36696038551550075468], [-30949659593673381520536, 702315776408676684090, -17050960106707989583, 3060997300923851461], [368404905323413895531222, 1790566024583447175837, 123659851833294090880, 17306497948754682719], [-411647525989327107283328, 697618744297434993446, -16299332441218667058, -16323277213614177372], [-235110993110120979482322, 495490568448018683022, -83100870277086319558, -46363291500537079856], [-33683977123414558041798, 1510348056744597244890, 16569322956477923041, -48206369341419803851], [148108121796069032215978, 10057925669613040575, 54885759028740449583, 99553461922755511662], [279046743427301910817978, 365780512758926858436, 152611392090302259528, -12221256233267246748], [471335927858070110694366, 92925550193962885953, -107287850007850111153, -20990465589268912220], [203497695656399017495134, 796356803113163129460, 99135412337476474565, 30299803553067275023], [613053116747109844328558, -225643562332030891713, 30651648178477531874, 128279974209511745827], [300610127528964214043214, 1551370443929330218902, -292973023791608161510, 46207331650563271240], [-1035677939353646905055190, -1225345300870200087222, 303116027082544337424, 23498520502187880030], [-1980499295447073693794916, 2414620930539026327214, -185662864291699187176, 59693013328936901218], [-144172368284738578567900, -4215270464561939468598, 77015000678343639780, 94475106990554572266], [660773158502140167816222, 2056170329701495129035, 360571519208946509553, -40617300754579454688], [221771111130712298127522, 4984548701789165850870, 280512100439533890065, -141308923675219815623], [-884736507644477190043794, 1870111819017538466328, 536726923683948304251, -227312480923863606411], [542819482791289740668542, -2438822004030224431500, -198683788572786349453, -237783205995744236111], [1352297314574151174144086, -1169711840657821241814, -371264585141446936082, 102996680278645172144], [-2353447232874814552515906, -5000073434500040057418, -77611318957548176492, -119380658775716156194], [736279215212257114061486, 4583928899311698196506, 606072192268122823084, 128956367007284659538], [-273424508130824890588442, -5467587248679882045169, 433218937291463544125, -24651044288817453344], [395937524114166181296550, 1548554860536372969123, 824368041327900349714, -223368415727665070017], [3477217390726860188823362, -4634266372804698279035, -263663238098480150919, 343332888820266567702], [1612652803394338719960060, -10462004747955678818334, 447698212103236718943, 6591375823517593695], [1866483001553585865226874, -1256193207999135488133, -98406367147852993968, -158902592758902248871], [619116513516734499156286, -21183030645402702280, 806291435331137663404, -336154718734967631268], [-1454816995745832487046172, 770891324190019596576, -968297817750000368610, 164259510989283069906], [3004461629314678349143350, 6442236575145272692224, -74335543806632601731, 37876766629901219867], [3506362994162702137636190, -7239097653135380215413, 800735629813556512657, -325184168990775988288], [6044734717754589631045640, -9403206165079956120686, -170485134693575911322, -303910340295242063248], [-3815705044063566327670870, 5444780507004380634549, 2013654908056611335457, 476129707813005551934], [-6485770874399289421406350, 6018443035295936659798, -1175552760505817111106, 535934224804547685828], [2724721961846380828436210, -9247769200524742919463, 1282360146690009233918, -358464874423822944251], [-6169572558436475561712132, -7004179216154898327516, -1832861641887536012382, -395534161136171901606], [-3061625084036314190518142, 22425954625409592463362, 1233551827788922009920, 786052520930252312214], [-2199678617676220867988298, 2226395699831693842116, 1969525800234937303534, -462228137784271821298], [-1002608096906146626910750, -34192658403620025129456, -618246594402310653113, -157438600245824485711], [3977508945220017959435236, 6009826549854485422610, 2970777534929359703356, -694160231802654819094], [771125586750006671794802, 20371466233462130491488, -4319540553963498822157, 30664255364074920853], [17354413843591395821312250, -13432327046192882497872, 56725669701025998661, 206163157621722712547], [17962571536033166888491604, 25119676662432510106464, -391857901670880049834, -87396034253083940198], [-4758482387390887193841542, -18066463001804968752802, -1714472778272100167890, -420382554490883772500], [-9172787312917621503035382, -3212089431586825379580, -3445003009470818462220, 993938205436190182296], [-6256313496752316832163966, 731515253836302177347, -4074582901478152198997, 1172312561506094786366], [-3441184468745026537625654, -31355048543507139819838, 706173956641540213169, 1319478864511579457245], [-2185169215335964278962654, 34389693527723261852888, 341317647548206746972, 470791391927975817996], [-2573494845191808707403602, 3777559019551493618220, -136370782310020712457, 2468504113617600556917], [-7785778553863966266247878, -29293777227144923294913, -8041605769564202493484, -609706681362410638175], [4608264664493554538319498, -35136506676689805154740, -2237260284925728720304, -2064534775308620541452], [-15908531063736724020286152, 59190733429020200694642, -434310332228455166778, 1691223691995918654384], [10986443049417559988014496, -61691653740330328061448, -1523327940663343723344, -1074388381334745411336], [32319508113254397151260142, 45815558936165877401511, -4668577714186170553687, -518494424112694505060]];
    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_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_7_18_a_a(:prec:=4)
    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_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_7_18_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,18,sign)));
    Vf := Kernel([<2,R![10531932160, 27034368, -236696, -186, 1]>],Snew);
    return Vf;
end function;