
// Make newform 637.6.a.a in Magma, downloaded from the LMFDB on 26 June 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_637_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_637_6_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_637_6_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 := [-4, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_637_a();"
function MakeCharacter_637_a()
    N := 637;
    order := 1;
    char_gens := [248, 197];
    v := [1, 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_637_a_Hecke( : Kf := Kf)
    return MakeCharacter_637_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 := 6;
    raw_aps := [[-2, -1], [17, -6], [1, 40], [0, 0], [-230, 84], [169, 0], [1379, -128], [142, 28], [-604, -1416], [-382, -48], [-3636, -448], [-9349, 1840], [-2944, -1952], [3569, -4718], [-151, -9670], [-25268, 6816], [15134, 8668], [-5640, 9296], [-35062, 196], [31865, 3666], [-46486, 18560], [-22780, -9736], [28896, 17920], [-70006, 23504], [-11982, 58720], [-50788, -34496], [33336, -51472], [-127876, 39440], [-84533, 8320], [53858, 23648], [60032, -120592], [54035, -61290], [-180468, 56384], [-170109, 6814], [-265250, 131872], [397989, 35538], [-16310, -28560], [-221836, -1496], [-50568, -62056], [45212, 163952], [-276835, -76414], [175168, -39456], [-378754, 60364], [149440, -316880], [402481, 103056], [102510, -292100], [-487707, -148470], [-102497, 62790], [-704696, 231472], [-348033, -313016], [-144451, 302520], [701555, -338538], [-307186, -149824], [1335912, -370488], [-419617, 62992], [-422124, -299976], [-616248, -91632], [190905, -58550], [284572, 279504], [-1790506, 21296], [-125220, 546096], [-1732271, 677056], [267462, 52252], [1581098, 134756], [-2203959, 218136], [454494, -956160], [1486580, -844216], [-2483953, 136024], [-3550387, 381730], [-534999, -581144], [-154228, -739344], [-2022768, 165432], [-827106, 1831308], [886540, -957840], [-2123552, 2075280], [1159231, -608874], [-116494, 206880], [2805958, -1055232], [431912, 703376], [3488556, 379824], [1247097, -2137382], [-140229, 1662328], [3727851, -1005098], [876977, -329192], [-1458702, -2352060], [-2994181, -111690], [7548710, 158048], [-2511766, -327968], [-4687171, 352], [2979176, 1431864], [1499228, 641088], [941673, 2241290], [-4076728, 4664], [-2764607, 257762], [5940512, 10400], [9471402, 211972], [-3361490, 4620128], [-1314255, 590216], [-1515580, -2637872], [6016297, -2206896], [6410647, -2744858], [-6203671, 3943328], [353015, -337194], [1400383, 3262032], [1017643, -5938914], [-4349666, 2152560], [4510308, -4329672], [7763670, -2283552], [-2230726, -41404], [3870595, -5581744], [-8806994, 3485100], [8682826, 1864000], [5033088, -4638544], [1710724, 1442840], [-1456735, -3188998], [3413694, -7530176], [4123590, -7748068], [-5879710, 8470244], [-18120, 2080928], [-331372, 3996368], [9705306, 1285728], [-10751851, -975376], [-6101212, -6335936], [-12296308, -667032], [-7523400, 4985872], [-16343468, -1973760], [-2099978, 2519296], [7789538, -11683692], [9150458, -1685804], [7102507, 6902120], [5273796, 710152], [6142691, 5219118], [10314808, 2457696], [11693316, -4085136], [-12434598, -512832], [11800512, -642432], [3652997, -6950504], [882752, 57856], [12274586, 803840], [12512543, 1167032], [-30528492, 2319848], [-14096681, 4201640], [15515282, -4851516], [18038458, -4350060], [5194918, 5779984], [-3062864, -849880], [8984847, 1678840], [6400242, 759104], [28360412, 4837568], [-15282617, -820882], [170937, 941560], [21383595, -1835680], [9398003, 5559302], [-12890632, 7084464], [-14679611, 18332058], [26925374, 5923020], [10490744, -12662912], [9206836, 1711952], [-41534038, 4463008], [-25861081, 14244712], [6445546, -11952300], [-12348793, 21492064], [-12583347, -12369766], [-17000755, -8547734], [-1663950, -9953776], [-21542379, 16141466], [-15446682, 404540], [-26268902, -2105984], [-8583758, 2765808], [-16985402, 2463776], [-28658270, 11318820], [-19005581, 17417776], [-18368672, -6150944], [43924712, 1650944], [22487514, 3773972], [-42414015, 1444504], [-8244140, 15223320], [-11827922, 27866336], [-1305716, -17384424], [33014476, -6288320], [4578784, 15490760], [5310436, 9306416], [20044678, -16107152], [48874118, -5786352], [-33118924, 4050160], [-404574, 16411744], [24917710, -13128416], [33220762, 13409700], [13225164, -19924912], [-1951920, -13149512], [24970699, -22762600], [-52097652, -7606296], [13746359, 6736342], [47227346, 11651584], [-50451077, 10130742], [51748910, 3901024], [19957600, 23873552], [74141248, 9863488], [-78502180, 9808928], [63706506, 1320244], [-66847785, 5746376], [6640580, 3972312], [-49405441, -728160], [24477903, -34069080], [6396984, 19619360], [9214430, -32895232], [-47264469, 18739086], [22476804, 25632816], [20271322, 1349584], [-26495583, -10100422], [59177798, -16886368], [-49783498, 24778736], [45775348, -10599624], [47752618, 7373796], [-23497325, -35207338], [16717400, -12019344], [-3651140, -20994248], [2624947, 25082184], [-44636044, -18756848], [-17864207, -26742624], [-107267868, -12085552], [73160803, 13622382], [325236, -1578832], [-38197907, -15551710], [32595905, 45483810], [15475826, 36467136], [-56490151, -4729368], [-18053800, -14628672], [71968358, 29057900], [-6796694, 58245140], [84684286, 28537648], [5613500, 13638096], [-28736192, -43205128], [-56201949, -24399072], [65668133, 18539690], [-43408683, -7186582], [64278306, -53076496], [37349509, 8869304], [-4401392, 45117576], [-127372638, 16187684], [16964822, -2951652], [-9628297, -12156098], [-9907096, -24084656], [-542047, 34353896], [7966546, 45471904], [131650432, 9115088], [30723039, -52064898], [-68933372, -2813512], [154301598, -10570260], [-56816290, -8380212], [-57845821, -14199448], [-23195066, -9140208], [-23498503, -64949062], [-69606751, 59383520], [153645980, 14016800], [-17532626, -14966452], [-23204532, 53045632], [66484958, -20554276], [80741808, -42519664], [-16113938, -5580368], [20381324, -40554328], [97068589, -36709814], [-84063197, -36546544], [-99040326, -29897872], [-53426184, 22153632], [44801515, 19155910], [52207443, -21074976], [36449708, -23920048], [-52451892, 22084136], [109509804, -69004128], [118046552, 31083728], [-13429286, -89081836], [130025630, 25435504], [-193921564, 20011800], [82209202, -62230528], [113480632, -50709496], [-150107854, 72366628], [88538482, 22512640], [115811892, -64075808], [-48968815, -17386718], [-162992704, 16170496], [22660977, -15047526], [-180898238, 29801124], [59912610, 79959872], [-121735396, 7615880], [18028670, 20146380], [796217, -54310040], [-40032539, 125764768], [-12562811, -31960054], [-91190330, 134807744], [-95001732, -80049008], [53196975, -49958418], [39792440, 23333792], [-94608842, 21693516], [57124390, 96137040], [93385076, 41748496], [-93636210, 27907692], [74727516, -8343648], [97442441, -100611918], [-3525626, -15471844], [-178435663, -22469024], [-123106693, 60641352], [-47359514, 126435932], [-2092068, 19235776], [204165695, -30366386], [37247064, 26797248], [-308434887, 31155682], [183109396, 12693728], [-68393948, -58779136], [-104862796, 79490608], [188309872, -12929952], [-7031203, 99255360], [59159423, -67356336], [-32779340, -30536432], [206006613, -25680894], [-110145013, -51737840], [227644414, -8153316], [173263672, -41899928], [240330344, -70221248], [26509782, -143694720], [-224600300, -53161008], [89560576, 30254240], [-183715680, -14693536], [13576561, -28406670], [72854384, 61099264], [-238559842, 47304384], [54183650, -88892924], [191584768, -4037488], [233743760, -87140528], [-19200036, -133561488], [-101440294, 178848576], [78804624, -8587488], [185312532, -74103416], [-166140504, 30539248], [-116895008, -28982800], [28100120, 102605936], [129947634, 38149920], [-155835524, 50310288], [23334784, -41625024], [24553206, -16231380], [295983319, -39422184], [-300789845, 46674088], [291319857, -44687904], [19614158, -72124276], [233629501, 110682648], [25945853, 33436178], [184534562, -101634144], [-329065440, 69998672], [-93069749, -68060314], [152720458, 32935904], [-153374810, 91912188], [-167597298, -97679216], [251995271, 60531152], [83961424, -132666896], [407366434, 142000], [-161066730, -118847776], [28422663, 76178750], [70785254, -72893556], [-35922453, 152574536], [278460037, 19735050], [91268182, -182187168], [-278768294, 87700160], [-242923730, -26132788], [-161112172, -15861336], [301586388, -111818800], [31921873, 68491104], [215679699, 113742000], [510796288, 6221720], [-209451007, -61976952], [118310335, -224823674], [32294609, -199864582], [471790259, -50594994], [-106039010, -57273712], [-6732504, 67583504], [317981006, 7288112], [206805594, -157444220], [36499054, 81287740], [118251556, 16973936], [140515542, -128266496], [38173210, -129061120], [12837598, -30138752], [62641830, -36932400], [42108004, -154930944], [-336725710, 130023552], [-112348280, 154977104], [133150161, -173571966], [-310043489, -10662738], [102211984, -188191632], [-236706410, 231637644], [-304684604, 5058200], [-68326742, 105824256], [-532285861, 23162208], [-194037886, -32791900], [-475070589, -3847194], [-227348013, 61273526], [-254859543, 66102800], [545217287, 60695094], [-20002445, -38110296], [-605917532, 20082528], [205673795, 107589328], [-137749179, 201011264], [59184050, -113567968], [248158521, -98390606], [-107961704, 26556848], [-413029517, -96914456], [661095378, -71783036], [331426809, -22061272], [-408290712, 140107552], [-35158314, 99862828], [120827008, -148883792], [285386983, 79234112], [248334126, -112332880], [-131252101, -186724170], [370821449, -214992886], [66455977, 180615896], [-205656668, 94538560], [323139829, -75096846], [-128623448, 31544416], [297154838, -6641088], [475814702, 107853484], [-18020924, 208691264], [541940354, -160930016], [-354941088, 99903960], [303101697, 95092434], [379461628, -126842368], [-169184030, -170843712], [-65108771, -31807022], [-125764952, -98246240], [98584152, 205405552], [-463301642, 129814140]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_637_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_637_6_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_637_6_a_a(:prec:=2)
    chi := MakeCharacter_637_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_637_6_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_637_6_a_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_637_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![2, 5, 1]>,<3,R![43, -28, 1]>],Snew);
    return Vf;
end function;