
// Make newform 700.6.a.i in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_700_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_700_6_a_i();".
// 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_700_6_a_i();".
// 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 := [-210, -499, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-333, -1, 1]];
    Rf_basisdens := [1, 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_700_a();"
function MakeCharacter_700_a()
    N := 700;
    order := 1;
    char_gens := [351, 477, 101];
    v := [1, 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_700_a_Hecke(Kf)
    return MakeCharacter_700_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 := 6;
    raw_aps := [[0, 0, 0], [-2, -1, 0], [0, 0, 0], [-49, 0, 0], [-5, 11, -1], [2, -13, 2], [-14, -31, 2], [779, 6, 9], [-1225, 70, 1], [1359, -99, -15], [1957, -248, -17], [-3793, -64, -1], [3827, 142, 31], [-6171, 322, 31], [-7246, -113, 16], [-2496, -594, 6], [4108, -1840, -64], [9037, -110, -71], [2556, -2228, -8], [27392, 136, 184], [-160, 1772, -250], [-5277, -3919, 95], [28746, 960, 138], [-31861, -2870, 127], [58622, -931, -322], [-8187, -6732, -75], [18070, 5259, 300], [102584, -1094, -8], [-50093, 331, 193], [93593, -4424, 1], [97464, -3476, 592], [199911, 3522, 693], [102335, 6982, 367], [6146, 9774, -858], [-282840, 2700, 462], [341969, 1521, -495], [29674, 16164, -576], [-83358, 826, -2018], [70210, 17579, -976], [120268, -4531, 2204], [144460, 9992, -88], [336632, -15270, 114], [59111, 1975, -2657], [-278413, -1714, 323], [280443, 9810, -2289], [564038, 8556, 450], [593147, 13869, 435], [327900, 37147, 1222], [11856, -44805, 798], [144571, 44866, -341], [725960, -20774, -2222], [-420211, -64571, 2773], [812025, 21668, -1219], [-523310, 16466, -34], [250036, -33976, -910], [190158, 36078, -3306], [-372564, -29820, 258], [1117809, -42736, -397], [166228, -5028, -426], [-185465, 677, -1435], [-850880, -14715, -366], [993732, 20961, -636], [350620, -79035, -4722], [738227, 83698, -275], [-2138500, 4523, -6796], [1629220, -2272, -3466], [-637436, 94072, 5128], [-1150958, -55200, -2580], [-644979, -109770, 8991], [799463, 68328, 5739], [-1746108, 19485, 5232], [-1009388, 81608, -172], [-1758322, -24745, 4628], [535441, 121794, 12513], [1416700, -122000, 7984], [281730, 172428, -7410], [1049211, -43569, 11049], [-2716270, 101237, 5534], [-183465, -181893, 6129], [2896912, -181520, -3134], [-402084, 185364, -7632], [-489083, 164131, -65], [-1088283, 205923, 13233], [-3963810, 42100, -13784], [2536922, 89670, -4758], [2022841, 121658, -13477], [-2301749, -113263, -17695], [-2708347, 191102, 7025], [-3504844, 111850, 1246], [-1404959, -215592, -3021], [2525504, 205945, 4114], [1157439, -93762, -13311], [-2737842, -193670, -20162], [-4576923, 107793, -1407], [4183291, 137767, 20815], [4870508, 51229, -6326], [-1388290, 297268, 19048], [-2419263, 119544, 10725], [1900408, 418584, 396], [-1307881, -48003, 1353], [-6435877, 339596, 14597], [1329944, 215062, 36358], [3049188, -176256, 10008], [6561858, -159552, -11400], [-2846834, -189584, 5062], [210076, -154233, -11532], [-4844454, -11532, -47814], [-985476, 576471, 26724], [4763861, -225293, 17929], [3950150, 134976, 5604], [93264, -398651, 13438], [2442130, 170148, -33456], [-5776168, -173780, 10702], [7580641, -37310, -10709], [6279519, 38627, -7417], [-531366, 329088, -3960], [-608938, 100679, 39224], [3774386, -910184, -21410], [-9433151, 493028, 8261], [7907137, -585457, -5359], [-6076546, 613098, -6108], [-1307201, 547638, -5385], [4880160, -239349, -16908], [-2435399, -58780, -46393], [-5319350, 205216, 12850], [-2076765, -96231, 43125], [-3709967, 61501, -32609], [8063397, -103050, 45075], [-6754494, -398504, 9406], [6127206, 877903, -17210], [-7299477, 344987, -69049], [4570614, -65784, 88938], [4524895, -260879, 9139], [12569038, -436626, 13392], [5216951, 386620, 12463], [-2527946, 454192, 67516], [5781518, 46891, 4990], [18772834, 653019, -14268], [-1035888, -78771, -30792], [-7860281, 1285835, 73145], [3188244, 1161914, 38756], [12425029, 360167, -64537], [19990097, -517216, 20555], [-6626682, 363150, 11370], [-21628837, 451410, 24963], [-2679177, 322194, -15927], [3233438, -489028, 6644], [30520366, -189052, 9296], [-9465532, 784848, 9288], [2703693, 795684, -40401], [17202073, 436308, -68979], [15172488, 833046, -81978], [-1626247, -237280, -89497], [19802576, 10792, 21448], [-2066157, 286090, -51815], [18254754, 407424, 88662], [4954897, -2011571, -32711], [14876794, -1788562, -47236], [-3146760, -1235843, 119236], [14679453, -696486, 119241], [21698109, 797184, 24051], [-2065017, 889134, -72825], [-18531556, -134878, 22232], [3333, -164856, -112965], [-21518847, -681660, 63201], [3158764, 1124045, 73802], [-1503200, -214976, -18176], [33721888, -422847, -48168], [-34349707, 502455, 59379], [-31480836, -716928, -31770], [24541156, -410884, 83504], [19290908, -1437456, -30198], [-12908983, 565399, 93613], [8028688, -633204, 196758], [46233305, -255078, -8505], [6638980, 1133450, 26], [1360109, -553617, -174435], [20923143, 612351, -43059], [5793334, 448260, -153006], [-10471149, -2122390, 27947], [39317087, -1728412, -92443], [-32466617, 2261144, 46841], [26620115, 1482800, 9515], [-26664866, 1279616, 52184], [27359693, 1774132, 25183], [31837577, 1567492, -122735], [-8775598, 1772978, 21068], [-28514918, 726255, 47508], [-21634297, -2534205, 117129], [-1129999, -840056, -174605], [-19062338, -667212, -159048], [39829015, 2625194, -81691], [-26840921, -1768319, 180463], [12874867, -97762, -212365], [-40260834, 696816, 18678], [-13505172, -1603545, -172356], [-30672361, -399615, 134805], [13942439, -2638426, 69971], [-30091674, -250143, -123090], [7600338, -1197165, -69840], [-30978, -979464, -162192], [-23563554, 1904354, -16714], [9432880, -252984, 302418], [34451115, 3534500, -212125], [-12166789, -1692326, -41111], [27709742, 33409, -35702], [4968462, -2593786, -292786], [57301989, 31800, 107307], [-25793258, 4631708, 196460], [45986805, 1295324, 46403], [33115169, 2940986, -10651], [-18897126, -2485284, 127428], [-29178433, 3280184, 30629], [-19841076, 1506435, -332982], [93533256, -595950, 21708], [-14955473, 83026, -132629], [-58018853, -638322, 122565], [-62335579, 463774, -14435], [28249267, -779542, -184435], [50788322, -2073692, 45256], [-9073348, 832596, -35574], [7617150, 179378, 176414], [69166101, -3501225, -55773], [-60991072, -1734262, -154612], [5366260, 3850163, 229994], [-39843788, 4494400, -32918], [16112056, -1894435, 450644], [38432529, 3689835, -280107], [-31566154, -2189989, -229588], [-45864282, -2293632, -71970], [17353877, -2784814, -209899], [108184544, -830742, 42672], [71841738, 1625336, 19982], [-62722815, 3491547, 183495], [-82099448, -1281885, -259698], [87465172, -628669, 319982], [3002611, 2549026, 101119], [-28151726, -1256506, -352372], [7984399, 3423977, -471649], [-32388475, 4968598, 41995], [21693084, -3641580, -271656], [21875554, -2330972, 76954], [-96702648, -1785185, 260602], [11255090, 4727952, 1308], [85386100, -4820305, -272356], [-26227769, 387182, -309775], [-115955834, 450984, 116898], [-33095868, -1759986, 350628], [-21519107, -1677779, 80113], [25100823, -807138, 224985], [-47718133, -4365148, -204397], [-11727060, 151476, 559254], [-21809610, -7707864, 36234], [-27395374, 161406, -512436], [76681572, 4634748, 119598], [29310267, -2674377, -141105], [-58326472, 1464744, 46950], [27889092, -544520, -489440], [-138498, -1719429, 298446], [79472170, 2404671, -22890], [34579337, -5454850, 263231], [15207476, -1286846, -257660], [34310566, -6706862, -299012], [-23257204, 4989287, 362024], [143950760, -2057420, 83446], [-57552993, 886826, 317549], [60472839, 523455, 757269], [-85179810, -4118124, -182076], [-145855928, 806484, -241260], [33349281, 5453076, 297933], [45574087, 6433342, -173537], [18429191, -5479012, 440441], [-30528888, -3059195, -576140], [29862756, 1937516, -261676], [-143939676, -2808344, -281582], [-38608640, -2971641, -432606], [-22854520, -631856, -663236], [-141063394, -3861228, 235368], [84909415, -3593021, 513481], [-79436564, -2800786, -398260], [-29673222, -5044341, -548832], [-6431869, -9666063, 111063], [65564200, 7911656, 141584], [189185080, -1802768, 345766], [43722016, -752517, 121254], [165314385, -2052357, -52635], [88978489, 3348612, 155529], [-14065883, 3853892, 823145], [14659624, -560072, -24992], [95009184, 8717766, -432354], [79926421, 2199095, -307345], [225909032, -1900583, -214166], [-3052649, 125222, 246983], [29478687, -5186796, -415695], [-80976993, -8479340, -349601], [146839105, 5657894, 67373], [-4413100, -9668538, 205152], [137542962, 4033011, -387222], [88453954, 2678456, 312626], [21027902, 9390911, -245440], [71703508, 666585, -440160], [-97085254, 7724692, 195328], [-231379735, 5308071, 243573], [66597652, -5012404, -317008], [180255197, 7705185, -77703], [-80605901, -2676324, 668631], [-56399073, -812430, -284595], [16999080, 883394, -359062], [58355658, 8177520, -406506], [4595758, 3764202, 246984], [68268606, -2631120, -539574], [143962997, -6046871, -386429], [-58302294, 3872892, -113088], [147856578, -5501990, -44162], [90392373, -3780834, -650085], [83539629, -1312150, 790613], [-95411118, 5346990, 676542], [57512371, -3236485, 1076507], [-43119142, 6505385, 187898], [156606435, -8216241, 286413], [-20952188, 9319978, 248380], [63594357, 7348006, -294239], [20823936, -11841708, -265938], [-64858855, -10839784, 360779], [133349698, -4548628, -60820], [-179294618, 1042846, -790544], [-104161685, -5545343, 373483], [-77943498, 7323112, 790582], [123979299, -710364, 1044369], [22491387, -4956090, -512409], [-196884270, 6765104, -234148], [-63553155, 7136214, -494955], [-14615176, 5460378, -977436], [223961804, 7954885, -157682], [-148721794, -5716776, -14250], [-102031458, 1803735, 754200], [-36484451, -9654125, 207007], [113537538, 11130564, -203196], [-74942551, -4528920, -113955], [73336796, -14068057, -183490], [38267630, 7075424, -651652], [-206222056, 2180590, -241814], [-85279, -2465180, -384119], [-12527507, 15350383, 323689], [9764687, -2827292, -885761], [-56010068, -2936824, 416120], [16163724, -10339912, -1006798], [-89113447, -7538488, -19585], [50396801, 6505558, 1204999], [-52847722, -4468667, -272030], [3174424, -7240928, 537100], [66978797, -4459606, 422129], [47679815, 15053983, -378059], [-311787544, 5349983, -498094], [-203255691, 6700295, -403753], [120537100, -895144, 581762], [244310616, 11660214, -223476], [101699759, 7712782, -509315], [-139590105, -8452512, 211131], [173223578, -1637474, 1335082], [2083743, -6517298, 342307], [-111038308, -5451062, 992338], [-385242477, -10642620, 454833], [71527307, 630079, 511159], [-237125388, 1371424, 709528], [101446151, -1936984, 832979], [250606762, -5039275, 804998], [346991169, 5345458, 272023], [53847487, -154217, 1450201], [10903651, -13533361, -1242841], [150180501, 1795964, -104317], [-17310764, 7105292, 1259444], [-49329415, 8358145, -1307393], [-126113146, 16276158, -263682], [358745014, 13100892, -673164], [19530034, -10718692, 488882], [21114439, 10729487, -296593], [-335226194, 6513663, 43002], [318163402, 4031444, 185216], [39941610, 7678963, 1616398], [-113277920, -14012284, 784334], [-15902424, 3036864, -153450], [69237424, 5607288, -866904], [-64830704, 15069176, 895238], [-176855779, -15363264, -704661], [-46551404, -9027733, -2120506], [-377739481, -7519677, -959721], [-38279152, -8768869, 710804], [58247930, 7301528, -584158], [-157622538, 4092897, -1874280], [249651787, 5352811, -1116515], [313998382, 2941073, 260450], [434631347, -7012091, 83299], [-14721616, -13168168, -709204], [-311084093, 24665555, 579059], [17718218, 3551498, -434776], [87122817, 16853492, -884149], [-238210441, -1058630, -1506125], [-71816161, -9720669, 1513755], [-20272506, 21201132, 406056], [-389530151, -4846850, 156901], [36053128, -4710430, -758806], [46199555, 9746990, 2123357], [-268657422, 9448077, 1123074], [-23792628, 9913686, -634170], [-295033742, 13123786, 448186], [440152674, -6052616, -590288], [-324959447, 6968537, -1575301], [426610236, 6951016, 531664], [67442896, -315904, -327820], [-91581996, 574525, 106672], [413505356, 12386104, -1337498], [-32010747, 22891230, 186615], [-234481664, 13263664, -583388], [-135703551, 12170464, -742031], [324696772, -8142334, 375806], [169170579, 1939467, 1332699], [-233015518, -10605220, 892742], [-168406248, 20581284, -370890], [-49223050, -17424509, -1903508], [194112865, -18817285, 575003], [10656210, 7934860, -1867808], [550178406, -993750, 670302], [124851954, -33994704, -1636014], [-211605842, -17087373, -921654], [-39684924, 4908669, 1107204], [482015146, 17344664, -124966], [239137692, 20664072, -1919754], [289529929, 214600, 2501719], [-363023409, 16200288, -522699]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_700_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_700_6_a_i();".
// 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_700_6_a_i(:prec:=3)
    chi := MakeCharacter_700_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_700_6_a_i();".
// 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_700_6_a_i( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_700_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![-780, -487, 6, 1]>],Snew);
    return Vf;
end function;