
// Make newform 207.6.a.b in Magma, downloaded from the LMFDB on 26 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_207_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_207_6_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_207_6_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 := [12, -13, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [-1, 2, 0], [-9, 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_207_a();"
function MakeCharacter_207_a()
    N := 207;
    order := 1;
    char_gens := [47, 28];
    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_207_a_Hecke(Kf)
    return MakeCharacter_207_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 := [[1, -1, 0], [0, 0, 0], [21, 3, -2], [-87, 17, -4], [-37, -3, -28], [-324, 45, -99], [269, 57, 146], [498, 40, 200], [529, 0, 0], [704, 745, -523], [-1471, -914, 479], [2053, -1117, 1662], [3258, -1171, 1847], [-4510, 2050, -1150], [-7613, 682, 1021], [-7006, -4444, -534], [-17710, -934, -1980], [-23320, 1322, -42], [-21949, -4323, -1436], [-31515, 1628, -2227], [-26170, 3241, -21], [20036, -4778, -6662], [-9839, -5867, 13758], [-4304, 5964, -8666], [-90313, 3351, 618], [31728, -12994, 19752], [-65969, -15245, 9228], [109224, -9642, -3924], [-86144, -3040, -10808], [74289, 13717, -23138], [124061, 29636, -11939], [-90613, 11974, -2443], [88046, -28814, -9750], [209739, 4094, -10235], [208624, 7174, -28106], [199723, 38612, -35221], [-118734, 698, 44356], [-56545, -21558, 7033], [97810, 68874, -65144], [-157066, 23872, 50448], [-147837, 264, -38577], [49521, 21479, -38086], [-207871, -124285, 71738], [175840, -27437, -47769], [-433882, -22561, -5179], [-69545, -65399, 116714], [-228682, 3498, -82656], [-358732, -16600, 40828], [279819, 134895, -85694], [-294624, 128700, 21396], [230806, -13039, -79149], [258599, 262, 107677], [-1018057, -42023, -25696], [79821, 58521, -63834], [-691306, 119789, -143629], [-310792, 98882, 28526], [182104, 42593, 150693], [-204360, -33280, 128944], [31278, -64871, 80263], [-673853, -132737, 129390], [-901887, 80211, 163080], [-647514, 90926, 121956], [-758666, 276926, -110464], [1452917, -233680, -148167], [-1672160, -189160, -21814], [-587304, 279198, 115164], [-1080697, -408514, 92625], [-510008, 71412, -357774], [-1000884, -83004, 374344], [2594438, 209157, -96069], [-1023774, 252075, -443579], [1066512, 310586, -98854], [1268739, -127225, -172816], [777313, -264909, -176070], [1641536, 64120, -490362], [672644, -434192, -61412], [-3026178, -170066, -154152], [1844378, 387563, -252899], [4210501, 354495, -82964], [-1618570, -248375, 171567], [-1002484, 118228, 335954], [-1465635, -3719, 177080], [567938, -226774, 180228], [-1152413, 754985, -166084], [4205515, -36526, 276373], [-2500731, 229152, 257721], [2020430, 550668, -305104], [1243011, -35133, 401034], [1143538, 174099, -414179], [814924, 698520, -534372], [2453402, -118628, -180768], [52129, -1004707, 862740], [1354043, -505306, -569039], [4749221, 329514, 154919], [5006115, -282316, 501667], [1723172, 1200258, -656674], [875034, -705617, 457977], [4628244, 16608, 377682], [4386799, 551123, 337114], [-297710, -398587, 11095], [-1912593, 106750, -1248439], [-3454726, -814298, -698308], [-296030, -191882, -1049150], [-4657811, -337505, 1148676], [2629177, 29561, 1575022], [-865808, -1204629, -574645], [-2371059, -1911384, 1501437], [3777866, 555588, -474628], [1588744, -1104736, 9144], [-3104060, -342849, 487523], [410570, -1191746, 837820], [-4798415, -2565059, 525428], [3999208, 1217146, -1613312], [-2289800, 1054952, 1283050], [1982530, -836290, -1644100], [5690944, -1786852, 462554], [-2192805, 522833, 76748], [4505219, -615506, -1545823], [-11610390, -412467, 520039], [5440233, -370571, -1658330], [7174528, -10078, -1117914], [-9133112, 289325, 642985], [-11225160, -445470, -31254], [4912303, -346572, 569603], [4307264, 845212, -730472], [6524129, 368325, 488348], [-3454819, 31829, -2349468], [1514804, 1778612, -732064], [-5928711, 1615839, 60054], [-2285655, 1714653, 1939496], [1435857, -538080, -1023587], [9735643, 1676567, -593900], [-5535462, -620550, -109280], [-6865147, -4188713, 2134534], [-10751030, 1244707, -686123], [6818103, -1092183, -2168496], [6750186, 250606, 1596748], [6894668, 1255128, -3333522], [4646346, -3325600, 389298], [-11750958, 135016, 1006140], [5378461, 1971794, 309491], [-19574158, 2009688, -1710328], [2620355, 1241860, 2502707], [-8631668, 2320404, -4770710], [-1343116, 2484166, -160276], [8931549, -3054447, 2098524], [-19618228, 1966762, -3065116], [5227014, -1101559, 2486043], [10109231, 2738964, -98649], [-11246855, 1732670, -570161], [-13466624, -3196754, 1251312], [125743, 3569875, -3707858], [-21185420, -3509760, 795912], [14898113, -3498556, 596633], [940276, -3791746, 4539376], [12820778, -3321768, -2810602], [13050329, 5188813, -2561056], [-11824384, 2912147, -2598097], [-24762635, 2044395, -230776], [-19573809, -1950569, 3034140], [-5526891, -3273380, 1277509], [8878356, -4735134, 120320], [-3821431, -488180, 2928545], [16874744, 3699846, 2146088], [-24205935, -5204549, 3798708], [-23367878, 1193004, 1633786], [4529584, 1485560, 922000], [-10445238, 3017984, 4436608], [-199896, 3525342, -1854660], [20127048, 922903, -4632101], [25313825, 4572955, -4904720], [-51914024, 359363, 1141623], [21779665, -296379, 3908492], [-29386218, -1916970, -966066], [32201221, 1220588, 3623973], [5456743, 2907551, 1317730], [-5738765, 3972950, -1099703], [-2958916, -5373773, 3722291], [5565024, -2242374, 5216430], [16684215, 2245703, 2843164], [33600779, 2872858, -3112987], [43270222, 1576770, -884218], [-26360742, 1238445, -967201], [-14062266, -5016996, 7299540], [-18679347, -796245, 5718774], [5590001, 4490821, -2094844], [3825240, -6170098, 6503636], [6834412, 532582, -8372824], [7426804, -645145, -1682741], [-15442632, 661728, -3901056], [-30999354, 3273447, -5422731], [38807758, -5670, -2885320], [5158797, -5848913, 5255336], [49645934, -1500004, -1141264], [-40508227, 5501923, -6604308], [18437264, 10815012, -7099834], [13529279, -2243187, 1405600], [-10017358, -6379174, 6575260], [-29583172, -3521572, 4312850], [50813049, 7688242, 453507], [-9171040, 8321364, -5783188], [-11824684, 3758556, 3916176], [22719050, -2491183, 5885659], [27812871, 701541, -4780776], [15115644, -9000408, 13510194], [-44754072, -12951427, 5417553], [17073951, 6150873, -7033494], [10264451, -5482238, 1311337], [-17736538, 3542793, 1071311], [-18157427, -13819528, 1435657], [2674690, 968251, 971237], [22709762, -3123159, 6886475], [-13514462, -679270, 2658992], [34201904, 10782206, -7378584], [62157380, 8961056, -2115460], [23921342, 8251806, -2468310], [-1240865, -2774968, -5886437], [21807940, 9269885, -4093667], [-2656807, 6684535, -5724166], [3827014, -9259799, 8748559], [55508342, -2868057, -7461843], [-17063003, -5136601, -4575314], [52645066, -4036841, -11924807], [31934047, -2493481, 6867720], [-39183051, 6509040, 11515481], [10992562, 9538103, -1767791], [8131065, -2283409, 6579756], [-9429237, 7973536, 4933455], [-68384984, 3676298, -2914210], [27790124, -388132, 12652928], [-2359726, 3160320, -9821616], [38343015, 12441975, -1719382], [56197475, -12700271, 284954], [-83510454, -18745608, 9319288], [-11939778, -9881502, 13115182], [32439219, -4070201, 9393408], [-97431048, 8802416, -6138926], [-120838707, 2578347, -4563038], [102448405, -3827312, -7766955], [-98376557, -13929560, 2665959], [59347194, 11570346, -4036858], [-38563283, -7034398, 1633591], [-116027591, -1856838, 8422059], [-2136600, 2996785, -10732891], [-99890562, -1004112, -2070880], [68908827, 10820370, -11167163], [15364063, 6259012, 8864759], [28857308, 3262978, -3964116], [-45926538, 2615280, 2817288], [-68171645, -8853851, -890058], [44772549, 18332049, -8534252], [26178035, -19372223, 24323508], [-68756054, 12899548, -19939794], [-88957683, -13996467, 3322422], [22454146, 12490052, 329212], [-25183321, -6613792, 15787539], [50790967, 1676493, -6421086], [-46038687, 2329047, 901464], [-54490934, 7614831, -21250111], [-3132398, -16879507, 3659959], [123894746, 20618606, -5618340], [-32340126, 4478118, -11673618], [5947242, 14223328, 13003456], [39211645, -3152455, -2102924], [61351374, -18471392, 16530928], [65558032, -336322, -16324364], [123788247, -995703, 7289198], [43544534, 5589362, 3929390], [-5886966, 10245160, -5363348], [127567790, 8082119, -1640731], [3812960, 14273019, 10887511], [43918184, -25081122, -16711740], [10552802, 14112954, 5966718], [61198389, 23732525, -18376376], [-35598656, 14213691, 15499479], [-68237497, 20649844, -248377], [-104538690, 2401834, 1524048], [88424842, 11717516, 5773152], [72136869, -13161293, 17060024], [-46852996, -9893212, 11364750], [-74871039, 14040866, 23477883], [27869795, 153345, 25137994], [26588833, 4429615, -6448730], [86247410, -5056484, -14862818], [17957918, -7496946, 16221904], [-105003390, 12528858, -17260968], [-95980142, 20585952, -2470204], [23848908, 2527018, 21446226], [24148026, 6224818, -28237072], [1898784, 4338154, 2865652], [-223933564, 4861142, -2102542], [-125268707, 11259445, 13154314], [-42214246, -2854324, 13421636], [103906432, 14188090, -10166892], [-121607122, -18918479, 24971031], [44132982, 36672440, -331782], [-28627029, -26314229, 17567108], [31517940, -16222845, -11138541], [8993023, 21753104, -27770917], [-86250389, -22418674, 21974069], [103565439, 35208191, -17370614], [-21611248, 2677698, 11218718], [-22112713, -21904545, 12167940], [79011317, 5173862, 17616959], [-201746692, 13064552, 15299770], [-212287206, 2462959, 2706053], [-107848080, -43231156, 15364116], [35950326, 25373914, -18366092], [40941831, -28130079, -17189786], [90067618, -11363568, -16928980], [-27110045, -39228166, 20536357], [88212836, -109166, -9361450], [-116806571, 17766869, 29214878], [-75852863, -12455388, 25708149], [87514642, -10977364, 2797042], [-75698241, 9735779, -20512318], [-212918473, -25616716, 12261983], [81371589, 306792, 17590561], [-268454894, 8312994, -1503210], [-20557416, 29726399, -3404445], [-209578920, -14583840, 19374338], [-84297551, 2928457, 834234], [-142354958, -17885311, -6311677], [65639190, -18130730, 51208184], [-99949975, 12243583, -27592456], [-138782076, -30206388, -2959230], [108902305, -20053929, 9038076], [-118818529, -40391366, 26876309], [-200178055, -21825857, 5914970], [40902685, 32877781, 14211360], [80521002, 44350917, -19278321], [124986678, 59672577, -37708233], [-66005937, -25162958, 4145017], [-338040935, -4885594, 13068307], [-48247672, 25949950, -14296644], [-128412843, -16484366, 23398719], [124401943, 38299757, -16419506], [-37159953, 39166251, -56175210], [159468002, -16830833, 11106341], [-14855458, 39373114, -43958380], [29231146, 2104843, 8100813], [64684282, 13941802, 31542414], [-49680596, 33971110, 7772644], [-264016700, -21294694, -9012338], [-133642317, 29061009, 39100434], [-202293130, -25375030, -16936636], [107992400, 20622157, -17762935], [67927488, 24806924, -32707276], [79841376, -23027814, 11110930], [267175955, -5912083, 24220962], [73608745, 38001258, 7506947], [-134226902, 37366321, 44265719], [142040110, -12850688, 16043616], [-268841770, 16285872, 11004138], [37334723, 25587099, 7494616], [253084590, 837876, -6514572], [-145487871, 8809689, -33012192], [-33032003, 25625251, -15234956], [-67966982, -18629825, -22702383], [-122272194, 16065858, 10241788], [22948933, -20373089, 53073950], [-56346252, -41735199, -5387579], [-43595199, -31179894, 27808803], [98350161, 11373303, -32797928], [193571831, -26571238, 42626685], [53731478, 26264749, -52346793], [144624118, -3493255, -18263929], [21511749, -33168157, -15500642], [287012226, 31081056, -34822860], [-283157471, -32152314, -6165601], [231312096, 1213500, 26975196], [-91290057, 610602, -12830943], [310505401, 17972245, -21343476], [-227628230, -32688294, 637160], [89768960, -64631195, -3390823], [153614001, 30554550, 37760075], [217855959, -851375, -37669334], [86009800, 16017122, 4731836], [-394265214, 9522582, 29112730], [-153044452, -93953171, 60818641], [173756249, 544739, -39582114], [-17297044, -9339382, -57835984], [-133690388, -822988, -67277024], [206953728, -6361233, -19179717], [-197711583, -16948943, -13076258], [243844763, -49019612, 11553347], [12404199, 22775942, -54552739], [61015930, -25901016, -42947832], [-251262237, 37320305, -18303176], [-14535437, -35051833, 25919504], [3136291, -23858657, -11950326], [136826054, 57111580, -21187444], [-423953073, 25570938, 29623365], [95249708, 90722128, -9129232], [-162053035, 22380289, 34438232], [-271117223, 44114187, -56056528], [-93686970, -25359430, 1179916], [-118950997, -47394025, 56831826], [129488901, -6535307, -30812518], [-246503956, -33326034, 20357668], [188588602, 62029295, -21072983], [184832758, 27825023, 1847857], [-410827261, -34614329, 21649208], [62324629, -11495879, 14699538], [339174554, -34019287, 14314635], [-134865927, -25008518, -5625077], [137890942, -75311328, 67571670], [-441213690, -2887993, 49242873], [-31844009, 29629879, 36425450], [105591612, 10121028, 78382024], [76633608, -26762539, -84862007], [70475312, -6898861, -80192289], [46249931, 19408745, -78466924], [-96636294, -4065048, 714664], [273728156, -20689486, -10733288], [64277682, 35469959, -87108871], [-16479412, -24219392, 15106596], [-128678134, -13982754, 65122308], [109691844, -29619180, -19043178], [401741342, -17078918, 66546184], [150131849, -82094399, 34289840], [24440748, -93570340, 5632156], [-495625384, 29247700, -52471884], [-52846672, -38377180, 13205696], [-100600736, 57142911, -12823197], [21137120, -103381801, -24702205], [188174646, -82850268, 58848256], [-296330020, 40901710, 49288632], [-271759893, -11060724, -10640473], [59569769, 47806192, -107310403]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_207_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_207_6_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_207_6_a_b(:prec:=3)
    chi := MakeCharacter_207_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_207_6_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_207_6_a_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_207_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<2,R![8, -48, -4, 1]>],Snew);
    return Vf;
end function;