
// Make newform 27.7.d.a in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_27_d();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_27_d_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_27_7_d_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_27_7_d_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 := [1982464, -1272832, 870720, -174032, 66932, -2412, 4610, -2, 75, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [38990423194624, 24758157183040, 303080290496, -1662748272772, 20243577060, -339533226, 1123354358, -11157967, 4480309, 5928919], [-38990423194624, 13065193910816, -303080290496, 1662748272772, -20243577060, 339533226, -1123354358, 11157967, -4480309, -5928919], [1178713975026976, -82870605445664, 46556189231168, -3665101155628, 3109617595980, -52155727758, 42631129082, -1713976261, 688220647, -9684923], [-112526238150656, -2960661889116224, 309769419173840, -228122766558052, 8289398823516, -15759840319002, 4959213290, -258824546191, 4504997485, -3461507741], [-9358563268702208, -247883787191899712, 24655545675519824, -19890741704909188, -346140289804356, -1384446245763690, -13971656353030, -22437956373703, 161056711573, -301534626821], [-278089336893715072, -21510646254101248, -28091608583134376, -19899503053280492, -5233881275671536, -1185087940044102, -92268001192520, -17892439228289, -1071624020857, -228970339285], [934989218885514496, -438995832667976192, 206189758524868592, -18842417040821140, 7056859532042268, -2664105725232018, 81874683465962, -45444196783291, 1735301772337, -680904382841], [761607762821734400, -280830061440619264, 143733596616975448, -9465337088444252, 6242802927799104, -1377579395474046, 85319366526208, -24218221634837, 1468396024739, -357064666657], [1468153012199075840, -805271759552407552, 314020064100693472, -47715295575658388, 8188936742890116, -4933627466855202, 80258730986950, -82073042998211, 2091348988481, -1183320135805]];
    Rf_basisdens := [1, 25215567395904, 12607783697952, 12607783697952, 4437939861679104, 4437939861679104, 554742482709888, 1109484965419776, 554742482709888, 1109484965419776];
    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_27_d();"
function MakeCharacter_27_d()
    N := 27;
    order := 6;
    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_27_d_Hecke();"
function MakeCharacter_27_d_Hecke(Kf)
    N := 27;
    order := 6;
    char_gens := [2];
    char_values := [[0, 0, 0, 0, -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 := 7;
    raw_aps := [[0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [29, -1, -1, -2, 15, -1, 0, -1, 0, 0], [-18, 9, 18, -1, -17, -1, -2, -3, 0, -1], [-38, 8, 0, 5, 32, -5, 10, 4, -8, 4], [8, -168, -91, 0, 130, -14, -16, -8, -5, 5], [1626, -13, -27, -14, 3258, -28, 4, 1, -3, 6], [442, 262, -289, -27, 0, 0, 7, -17, 10, 0], [-7201, -14, -187, -28, -3626, -14, 0, 51, 14, 14], [5563, -785, 0, 168, -5582, -168, 6, -13, 26, -13], [-5, 1148, 471, 0, 5294, -206, 10, 5, -70, 70], [1402, -671, 374, -297, 0, 0, 253, -32, -221, 0], [-30245, -189, 1982, -378, -14756, -189, 0, -733, 71, 71], [-17631, 1658, 3316, 416, -17343, 416, -423, -711, 0, -135], [8704, 1311, 0, -461, -9417, 461, 812, 99, -198, 99], [-22606, 261, 498, 237, -45130, 474, 735, 694, -41, 82], [135287, 14, 6182, 28, 67281, 14, 0, 725, 117, 117], [-3567, 14267, 28534, 152, -3600, 152, 606, 639, 0, 573], [-170, -28849, -13842, 0, -40672, 1165, 340, 170, 284, -284], [-131444, 13535, 12012, -1523, -263078, -3046, -1751, -1656, 95, -190], [86144, 10275, -12489, -2214, 0, 0, 240, -255, 15, 0], [91467, -6557, -13114, -5674, 91844, -5674, -1501, -1878, 0, -1124], [-195424, -24401, 0, -189, 196775, 189, -48, 1303, -2606, 1303], [-167870, -60017, -61698, -1681, -335294, -3362, 809, 586, -223, 446], [56412, -13456, -26912, 8993, 53826, 8993, 3597, 6183, 0, 1011], [-113190, 52119, 0, 1387, 117317, -1387, -6007, -1880, 3760, -1880], [2198, 369, 2141, 0, -236993, 3913, -4396, -2198, 4753, -4753], [-129068, 26424, 30273, 3849, -264152, 7698, -6459, -3451, 3008, -6016], [46426, -30359, 26336, -4023, 0, 0, 1363, -7310, 5947, 0], [411141, -5821, 93809, -11642, 202441, -5821, 0, 6259, 446, 446], [350236, 34246, -14806, 19440, 0, 0, -6266, 10666, -4400, 0], [-483054, 1645, -180877, 3290, -235753, 1645, 0, -11548, -3593, -3593], [-110002, -305114, 0, -10581, 88262, 10581, 23007, 1267, -2534, 1267], [4237, 178388, 102312, 0, 432341, 26236, -8474, -4237, -1837, 1837], [1971486, -5190, 19115, -10380, 987846, -5190, 0, -4206, 10317, 10317], [2000553, -109775, -219550, -20608, 2003348, -20608, -13483, -16278, 0, -10688], [-13371, 331777, 153139, 0, 16971, -25499, 26742, 13371, -13008, 13008], [963304, -103946, 84668, -19278, 0, 0, -13976, 16060, -2084, 0], [1493800, 15155, 414689, 30310, 742727, 15155, 0, 8346, -5129, -5129], [-2398080, 7763, 0, 15089, 2396431, -15089, -4709, -6358, 12716, -6358], [-759788, 146756, 119364, -27392, -1517048, -54784, 13420, 12156, -1264, 2528], [2319622, -49541, 80240, 30699, 0, 0, 4141, -14666, 10525, 0], [50456, -147635, 0, -43869, -34711, 43869, -5472, 10273, -20546, 10273], [1593, 28981, 46018, 0, 3451080, 63055, -3186, -1593, -5211, 5211], [-971404, -282704, -301272, -18568, -1932640, -37136, 18452, 13368, -5084, 10168], [-4394630, 177205, -223294, -46089, 0, 0, 22069, -10508, -11561, 0], [58659, -848084, -456263, 0, -2826852, -64442, -117318, -58659, 19200, -19200], [-6102918, -19881, -39762, 179, -6157007, 179, -5870, 48219, 0, -59959], [4021770, 25436, 0, 20141, -3985052, -20141, -26546, 10172, -20344, 10172], [-81583, -528591, -243139, 0, -4851719, 42313, 163166, 81583, -24614, 24614], [493080, -92914, -65745, 27169, 937332, 54338, -89831, -65417, 24414, -48828], [-8368363, 10144, -156751, 20288, -4232624, 10144, 0, 96885, 8048, 8048], [-1047015, 355144, 710288, -97528, -1051975, -97528, 10280, 15240, 0, 5320], [7474724, 588178, 552045, -36133, 14874164, -72266, -114745, -77103, 37642, -75284], [-6294896, -55614, -391840, -111228, -3144839, -55614, 0, -5218, 2762, 2762], [7254399, 185517, 0, 28666, -7178452, -28666, -58207, 17740, -35480, 17740], [2608398, -1110435, -1092042, 18393, 5230710, 36786, 171591, 164634, -6957, 13914], [-2414872, 636438, -504354, 132084, 0, 0, -22074, 41358, -19284, 0], [-8375436, -807831, -1615662, -223903, -8334377, -223903, -43805, -84864, 0, -2746], [-1758705, -712963, 0, 107516, 1799488, -107516, 8542, 49325, -98650, 49325], [98054, -76263, -102853, 0, -9267215, -129443, -196108, -98054, -9221, 9221], [5607583, -85295, 972971, -170590, 2844213, -85295, 0, -80843, -51402, -51402], [-11153182, -409350, 61509, -347841, 0, 0, 67965, -51411, -16554, 0], [-10728331, 65964, -10813, 131928, -5323366, 65964, 0, -81599, 32110, 32110], [15338367, 690656, 1381312, 286922, 15342411, 286922, -117798, -121842, 0, -113754], [-647807, 304461, 0, -80906, 828354, 80906, -193612, -13065, 26130, -13065], [-18138951, 1309371, 2618742, 126008, -18238394, 126008, 144589, 244032, 0, 45146], [131150, 3514722, 1571594, 0, -6582005, -371534, -262300, -131150, 27496, -27496], [-24343198, 91309, 2598140, 182618, -12174242, 91309, 0, 5286, 78014, 78014], [-14942862, -1454435, -2908870, 368555, -15072259, 368555, 206909, 336306, 0, 77512], [-9242610, 3090586, 0, -193557, 9041010, 193557, 289479, 87879, -175758, 87879], [3478668, 4015234, 3999582, -15652, 6869964, -31304, 154664, 198350, 43686, -87372], [28654089, -1502405, -3004810, -82096, 28890662, -82096, -139435, -376008, 0, 97138], [201726, 2425930, 1199617, 0, -18346788, -26696, -403452, -201726, 233145, -233145], [-85736, -3125723, 2924249, -201474, 0, 0, 141148, -127085, -14063, 0], [-13743366, -254659, 751709, -509318, -6702947, -254659, 0, -337472, 49589, 49589], [-12757096, -2088613, 0, 9953, 12712911, -9953, 90631, 46446, -92892, 46446], [15998710, -1655417, 1738334, 82917, 0, 0, 3595, 103084, -106679, 0], [10484925, 41761, -1243732, 83522, 5210588, 41761, 0, 63749, -199829, -199829], [252634, 641930, 324354, 0, 12692099, 6778, -505268, -252634, -81772, 81772], [-31360071, 57876, -2477755, 115752, -15867504, 57876, 0, 374937, 4320, 4320], [43856865, 518165, 1036330, -340360, 43481562, -340360, 362850, 738153, 0, -12453], [22849300, -5279310, -5229354, 49956, 45609676, 99912, 417864, 462326, 44462, -88924], [17859688, 1170157, -1997005, -826848, 0, 0, -247526, 144337, 103189, 0], [4542819, 1782677, 3565354, -740818, 4766886, -740818, 5655, -218412, 0, 229722], [23740161, -2379970, 0, -244852, -23045819, 244852, -897173, -202831, 405662, -202831], [-41964358, -1073779, -1178421, -104642, -84160906, -209284, -847184, -731089, 116095, -232190], [-6849756, -960836, -1921672, 200489, -7297858, 200489, 108677, 556779, 0, -339425], [-36057911, -1416491, 0, 644790, 37012018, -644790, -1106136, -152029, 304058, -152029], [-252419, -193990, 483609, 0, -25420714, 1161208, 504838, 252419, 107030, -107030], [8282744, 2783824, 3697437, 913613, 16658216, 1827226, 521261, 474897, -46364, 92728], [-18431853, 8484873, 0, -274802, 17846900, 274802, 685541, 100588, -201176, 100588], [-34759160, -3673124, 4300928, 627804, 0, 0, 211246, 138052, -349298, 0], [19677235, -10270, 13116020, -20540, 9827423, -10270, 0, 22389, -27797, -27797], [696997, -127984, -587664, 0, 46633481, -1047344, -1393994, -696997, 386195, -386195], [-607196, 3243161, 2528718, -714443, -1194698, -1428886, -221399, -231246, -9847, 19694], [173298786, 170446, -8597569, 340892, 86745662, 170446, 0, -192538, 28117, 28117], [-64701908, 4048630, 4119297, 70667, -128673212, 141334, 910823, 545521, -365302, 730604], [83498882, -1368795, 158790, -1210005, 0, 0, 827745, -608448, -219297, 0], [-48912986, 3087670, -1642684, 1444986, 0, 0, -524654, -417776, 942430, 0], [18722706, -2348596, -4697192, 924659, 18415266, 924659, 297846, 605286, 0, -9594], [-8997818, 522503, 1312836, 790333, -18061358, 1580666, 1776163, 1809024, 32861, -65722], [-24442140, -97757, -9911272, -195514, -11971744, -97757, 0, -498652, 423916, 423916], [-93027799, -8389064, 0, 636498, 94178363, -636498, -910686, 239878, -479756, 239878], [-77936, -5450251, -4252542, 0, -19458466, -3054833, 155872, 77936, -435922, 435922], [75863732, 7217781, -5666901, 1550880, 0, 0, 691566, 44745, -736311, 0], [93484445, 10659876, 0, 1744624, -92643029, -1744624, -622717, 218699, -437398, 218699], [-23845630, -6570831, -6839610, -268779, -46126738, -537558, 1969983, 1187722, -782261, 1564522], [-70047656, -167893, 14727929, -335786, -34408825, -167893, 0, -1230006, -348497, -348497], [87044832, -1628784, -3257568, -1730179, 87701014, -1730179, -449363, -1105545, 0, 206819], [418784, 6568299, 3545993, 0, 114238177, 523687, -837568, -418784, -586685, 586685], [-134217634, -8780547, 8423310, -357237, 0, 0, 685365, -1124184, 438819, 0], [-106579267, -1125587, 1374140, -2251174, -51981488, -1125587, 0, -2616291, 59315, 59315], [11261292, 3524070, 7048140, -634351, 11202178, -634351, -1275800, -1216686, 0, -1334914], [221273212, -9474734, 9941996, 467262, 0, 0, -429872, 535804, -105932, 0], [22644549, 14161146, 0, -424346, -24007243, 424346, 1377290, 14596, -29192, 14596], [296714, 21158127, 11215880, 0, -34091762, 1273633, -593428, -296714, 622270, -622270], [148181044, 1232466, 1320918, 88452, 296455564, 176904, -1156008, -1202746, -46738, 93476], [137741499, -463159, 12417419, -926318, 67501813, -463159, 0, 2737873, 246074, 246074], [43112839, -9176041, 0, -644206, -42497278, 644206, -139787, 475774, -951548, 475774], [-2369729, -12209605, -5958159, 0, 215126795, 293287, 4739458, 2369729, -526816, 526816], [-104559777, -7276427, -14552854, 3341498, -104348092, 3341498, 224288, 12603, 0, 435973], [47257866, -17260259, 0, 1113315, -47289921, -1113315, -776211, -808266, 1616532, -808266], [18843964, 28155148, 30284979, 2129831, 37087696, 4259662, 734315, 1034431, 300116, -600232], [-31252464, -10221151, -20442302, 309053, -32604459, 309053, 1688916, 3040911, 0, 336921], [-39850822, -18786285, -19065786, -279501, -82280806, -559002, 6909, 1296490, 1289581, -2579162], [50475330, 7238049, 14476098, 3641291, 48036553, 3641291, 2391745, 4830522, 0, -47032], [-84027416, -12025270, -13151982, -1126712, -167997380, -2253424, -1771088, -1799814, -28726, 57452], [-38531901, 3816609, 7633218, -407218, -38424062, -407218, -1089605, -1197444, 0, -981766], [-1160372, -13846744, -6996285, 0, -147065500, -145826, 2320744, 1160372, -326143, 326143], [148075924, 9172537, -4164793, 5007744, 0, 0, 145894, 1146913, -1292807, 0], [196822374, -276591, 8728865, -553182, 99277893, -276591, 0, -1733412, -103851, -103851], [306738, -20137943, -11541701, 0, 48914649, -2945459, -613476, -306738, 629631, -629631], [-11359126, 4909260, -9565896, -4656636, 0, 0, -658068, 52608, 605460, 0], [-111412912, 4413440, -1596133, 8826880, -55155756, 4413440, 0, -1101400, 317511, 317511], [1437023, -3141885, -2462755, 0, 289171423, -1783625, -2874046, -1437023, -1475828, 1475828], [-59283574, -40324633, -40684542, -359909, -118509742, -719818, 390469, 361766, -28703, 57406], [73878, -40615643, -18567581, 0, -192488331, 3480481, -147756, -73878, -1212621, 1212621], [-330892318, -2963166, -39943255, -5926332, -165474688, -2963166, 0, 57058, 223651, 223651], [-102092418, 7920783, 10613727, 2692944, -202343742, 5385888, 1713222, 792675, -920547, 1841094], [-136669562, -19280924, 19395107, 114183, 0, 0, -1160831, -405449, 1566280, 0], [18836837, -51378757, 0, -585670, -17051976, 585670, -3186104, -1401243, 2802486, -1401243], [-135595, 28816302, 13600925, 0, 228173494, -1614452, 271190, 135595, 700330, -700330], [251310716, -1893646, -3713784, -1820138, 503588156, -3640276, -164198, -647560, -483362, 966724], [-165252722, 16185319, -16957546, -772227, 0, 0, 398011, -1714340, 1316329, 0], [37506610, -225065, 0, -3015579, -40571759, 3015579, 2416434, -648715, 1297430, -648715], [200964327, -4774673, -9549346, 3360458, 200423918, 3360458, 658016, 1198425, 0, 117607], [247398827, 11415429, 0, 703168, -250338092, -703168, 4552934, 1613669, -3227338, 1613669], [-3587532, -38611367, -16319696, 0, -357508956, 5971975, 7175064, 3587532, -2414028, 2414028], [-202583516, 16895604, 19724658, 2829054, -405661688, 5658108, -36270, 211058, 247328, -494656], [1782596, -63461064, -31606951, 0, 142873390, 247162, -3565192, -1782596, 920611, -920611], [178990434, -746737, 1331442, 2078179, 359682978, 4156358, 1562029, 710974, -851055, 1702110], [28763158, -10859348, 11638919, 779571, 0, 0, -337019, 1807315, -1470296, 0], [-300321521, 2120662, 20061755, 4241324, -149146212, 2120662, 0, -2029097, 426912, 426912], [375570369, 22559654, 45119308, 5491424, 374974677, 5491424, -270783, 324909, 0, -866475], [-177189905, -42415665, 0, 842770, 180771498, -842770, -4069747, -488154, 976308, -488154], [-329290840, 21197298, -26472126, -5274828, 0, 0, 6495222, -4951662, -1543560, 0], [-68017969, 22097093, 0, -3118156, 68480760, 3118156, 345634, 808425, -1616850, 808425], [200967718, 27822589, -30591898, -2769309, 0, 0, 2771581, 878200, -3649781, 0], [253724655, -5878703, 17429657, -11757406, 126305471, -5878703, 0, 1113713, -1208144, -1208144], [-72852420, 21921496, 0, -1241745, 64004970, 1241745, 8609460, -237990, 475980, -237990], [-163110474, -20017013, -25708311, -5691298, -325860726, -11382596, -9114772, -9294883, -180111, 360222], [1158353, 12530022, 3444005, 0, -329901194, -5642012, -2316706, -1158353, -1931666, 1931666], [-170650180, -17084643, -20373774, -3289131, -345603922, -6578262, 581961, 2733742, 2151781, -4303562], [-490458832, 2222774, 16791218, 4445548, -247337805, 2222774, 0, 4216778, -2993328, -2993328], [-526571053, -25921267, 0, 4405046, 533508312, -4405046, -6840527, 96732, -193464, 96732], [47757068, -52344960, 52677546, 332586, 0, 0, -1657356, -1981050, 3638406, 0], [-281025822, -15736959, -31473918, -8429557, -283221071, -8429557, 1392589, 3587838, 0, -802660]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_27_d_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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