
// Make newform 10.13.c.b in Magma, downloaded from the LMFDB on 18 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_10_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_10_c_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_10_13_c_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_10_13_c_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 := [392422062096, 0, 461169144, 0, 43009, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [0, -13932675324, 0, -669445, 0, -1], [1386948097080, 1028665029924, -33678765450, 669445, -1566090, 1], [-1386948097080, 1028665029924, 33678765450, 669445, 1566090, 1], [4830067523831040, -75714448599792, 820973089650, -9608375335, 22447290, -266983], [4830676363243800, 302815996373196, 820973089650, 38431493005, 22447290, 1067929]];
    Rf_basisdens := [1, 405892941840, 202946470920, 202946470920, 608839412760, 1217678825520];
    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_10_c();"
function MakeCharacter_10_c()
    N := 10;
    order := 4;
    char_gens := [7];
    v := [3];
    // 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_10_c_Hecke();"
function MakeCharacter_10_c_Hecke(Kf)
    N := 10;
    order := 4;
    char_gens := [7];
    char_values := [[0, 1, 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 := 13;
    raw_aps := [[32, 32, 0, 0, 0, 0], [49, -49, 1, 0, 0, 0], [2412, 2511, 5, 10, -1, -2], [-53685, -53699, 0, -31, 21, -7], [274744, 82, 1021, -1021, -164, -82], [-774227, 774565, -388, 0, -169, -507], [8525361, 8524769, 0, -25214, 888, -296], [-2434, 11094790, 40652, 40652, -2434, 4868], [17678893, -17702851, -147189, 0, 11979, 35937], [2066, 561953578, 258554, 258554, 2066, -4132], [-444881420, -35978, 560827, -560827, 71956, 35978], [291458451, 291487149, 0, 454626, -43047, 14349], [3785486842, 116744, 2235923, -2235923, -233488, -116744], [-2647929031, 2647589363, -1814987, 0, 169834, 509502], [-3084891849, -3084596667, 0, -6319551, -442773, 147591], [-14665660411, 14667090577, -11795358, 0, -715083, -2145249], [3534762, 6417291586, 17956488, 17956488, 3534762, -7069524], [48647380818, -2164256, -21266261, 21266261, 4328512, 2164256], [-608938723, -604371991, 0, 125943027, -6850098, 2283366], [154852574612, -5461898, 7622899, -7622899, 10923796, 5461898], [2116328009, -2124630813, -18251788, 0, 4151402, 12454206], [17669312, 115439724672, -114190768, -114190768, 17669312, -35338624], [11306465713, -11290607057, 434769245, 0, -7929328, -23787984], [-7790100, 284076200060, -50441340, -50441340, -7790100, 15580200], [112465008313, 112586171345, 0, -230537920, -181744548, 60581516], [92461489346, -60183728, -209056742, 209056742, 120367456, 60183728], [364278169661, -364276457211, -142514005, 0, -856225, -2568675], [-337200836815, -337403880735, 0, 649060127, 304565880, -101521960], [-66693078, -1736995653982, -371882109, -371882109, -66693078, 133386156], [41193105873, -41393139961, 424087166, 0, 100017044, 300051132], [-1356628168425, -1356704955515, 0, -108775603, 115180635, -38393545], [-962381633336, -253206302, -1069147367, 1069147367, 506412604, 253206302], [-146199837043, -145959209015, 0, 2317307764, -360942042, 120314014], [-338866678, 1990123732706, 806838728, 806838728, -338866678, 677733356], [954704006, 2446547836302, -1099832875, -1099832875, 954704006, -1909408012], [3218081257372, 43611470, -7427811565, 7427811565, -87222940, -43611470], [-6652403937945, -6653047658139, 0, 8535819504, 965580291, -321860097], [-2994348261231, 2993991676415, -1205266495, 0, 178292408, 534877224], [-10150517898317, -10149429631059, 0, 19928552197, -1632400887, 544133629], [-17935224781699, 17933700103629, -14701871170, 0, 762339035, 2287017105], [-1217380642, -2690788148890, 17373725096, 17373725096, -1217380642, 2434761284], [5598673601162, -1768869784, 19425840332, -19425840332, 3537739568, 1768869784], [20233213457852, 3785053902, -22134346701, 22134346701, -7570107804, -3785053902], [-1911275939471, 1915672951735, -46920017770, 0, -2198506132, -6595518396], [-510092158933, -510486210371, 0, -69446060558, 591077157, -197025719], [1412505308, -51035179874388, 25488392144, 25488392144, 1412505308, -2825010616], [-76750112735824, 2474034778, -10468957595, 10468957595, -4948069556, -2474034778], [16743842312773, -16758659593463, -2700878701, 0, 7408640345, 22225921035], [31267100709, 31664762905, 0, 161510506751, -596493294, 198831098], [-13056273906, -17700380312010, -27876296562, -27876296562, -13056273906, 26112547812], [69902818333609, -69900540822797, -16656334102, 0, -1138755406, -3416266218], [3923293944, -10073289128424, -13125735948, -13125735948, 3923293944, -7846587888], [-5200394243750, 1157938056, -57081028005, 57081028005, -2315876112, -1157938056], [-64283375542896, -8780545126, 189288728585, -189288728585, 17561090252, 8780545126], [-121514080105567, -121511502418687, 0, -214784586774, -3866530320, 1288843440], [-45839163147187, 45843983920237, 36962889519, 0, -2410386525, -7231159575], [-22602637974, 272055047719906, 86723259201, 86723259201, -22602637974, 45205275948], [243009002842956, 129915582, 3888676623, -3888676623, -259831164, -129915582], [-64295278141717, -64254654540803, 0, -56604907556, -60935401371, 20311800457], [175416378299562, -26030454440, -138092612405, 138092612405, 52060908880, 26030454440], [55326140045145, -55291298118109, -328050405391, 0, -17420963518, -52262890554], [-6980483433051, 6952434825825, 768839000280, 0, 14024303613, 42072910839], [35832597755301, 35846945590041, 0, -146351446245, -21521752110, 7173917370], [402231246323444, -70743667370, 429392434567, -429392434567, 141487334740, 70743667370], [-298169750327, 337478801251, 549240912818, 0, -19654525462, -58963576386], [-503294273903617, -503379515587979, 0, 207855604432, 127862526543, -42620842181], [-359768952164576, 46814193802, -774696172499, 774696172499, -93628387604, -46814193802], [204445200713609, 204485643141937, 0, -971215591160, -60663642492, 20221214164], [-849595111911679, -849475221660735, 0, -1486185264037, -179835376416, 59945125472], [80713150554, -1390881284521070, -524397785622, -524397785622, 80713150554, -161426301108], [-289666931161247, 289752952704175, 509702508512, 0, -43010771464, -129032314392], [-42224627844, 726981370677068, -869752678716, -869752678716, -42224627844, 84449255688], [2025554471797039, 2025541815400725, 0, 1446196482901, 18984594471, -6328198157], [-533930698217771, 533928980610905, 2940756139650, 0, 858803433, 2576410299], [8240285610, -1472623778428094, 331315748124, 331315748124, 8240285610, -16480571220], [2865571622221541, -2865712696048423, -894838116317, 0, 70536913441, 211610740323], [-94711327434, 57124416693054, -2226842418897, -2226842418897, -94711327434, 189422654868], [1152516312438647, 1152276762752517, 0, 2054731379318, 359324529195, -119774843065], [2381004710532042, 125349210776, 1897962228392, -1897962228392, -250698421552, -125349210776], [129744943412, -1542371629971420, 2500758040799, 2500758040799, 129744943412, -259489886824], [296935508158, 2477473299101958, -4138169515172, -4138169515172, 296935508158, -593871016316], [4583131694665802, 150295611560, 648685654955, -648685654955, -300591223120, -150295611560], [-2217302447380772, 12081373422, -5357994203385, 5357994203385, -24162746844, -12081373422], [-4720277489167167, 4720637459067071, -1634772038632, 0, -179984949952, -539954849856], [96328780292, -147643567628620, 2083100962124, 2083100962124, 96328780292, -192657560584], [-2224546425619399, 2224939808766611, 3068359010977, 0, -196691573606, -590074720818], [-506640312864, -3999710705876960, -5250478247643, -5250478247643, -506640312864, 1013280625728], [-2938624121373747, -2938927346242935, 0, 10079996968830, 454837303782, -151612434594], [-3739066227016142, -473377337088, 5996571908490, -5996571908490, 946754674176, 473377337088], [227328168710117, -227370983664647, 1380527173287, 0, 21407477265, 64222431795], [6543775170103453, 6543869860049641, 0, 2507603241567, -142034919282, 47344973094], [476356353000, 560424258275080, 13591516780860, 13591516780860, 476356353000, -952712706000], [11232265165609947, 11232284905862301, 0, 640131627801, -29610378531, 9870126177], [-20030383019671216, 239965958810, -1717459149643, 1717459149643, -479931917620, -239965958810], [471377135062, -2662699848763330, 5823423408604, 5823423408604, 471377135062, -942754270124], [6548625586611405, -6549978295537395, 6881211679683, 0, 676354462995, 2029063388985], [63133545738, 3006033294238594, 19161302856042, 19161302856042, 63133545738, -126267091476], [5421562692423714, 631212553024, 2107651228630, -2107651228630, -1262425106048, -631212553024], [3225977116665161, -3228197593535653, -17741798850287, 0, 1110238435246, 3330715305738], [26873733773092642, -214967767408, -4876422430006, 4876422430006, 429935534816, 214967767408], [5296271384057093, 5300104308756313, 0, 10787103119791, -5749387048830, 1916462349610], [-22298570053941953, -22300222001623243, 0, 10915712161718, 2477921521935, -825973840645], [11905757734839873, -11901905449783209, -5600538943167, 0, -1926142528332, -5778427584996], [1271816739860, 21461625945159812, 5087148006233, 5087148006233, 1271816739860, -2543633479720], [36180005833610408, 432804060002, -2518543663675, 2518543663675, -865608120004, -432804060002], [-4824527606224463, -4821992763726239, 0, -33718209768534, -3802263747336, 1267421249112], [-11010085192417911, -11011212562820367, 0, -1131745536573, 1691055603684, -563685201228], [-33302204893782351, 33297196821440407, 4536094923352, 0, 2504036170972, 7512108512916], [-2206960723228, 43979029842796948, -10123604584744, -10123604584744, -2206960723228, 4413921446456], [31487817394771418, -2213476191000, -12778393288629, 12778393288629, 4426952382000, 2213476191000], [30286832898928431, 30285047229251349, 0, 9933086346921, 2678504515623, -892834838541], [-1113180194482667, 1113057749203129, 11095850567336, 0, 61222639769, 183667919307], [-12855466312379051, -12851231553840583, 0, -52827625738450, -6352137807702, 2117379269234], [-4224966923310, 22802867366964810, -26972023795920, -26972023795920, -4224966923310, 8449933846620], [-33661233145216076, 2870703841430, -28084367812393, 28084367812393, -5741407682860, -2870703841430], [22761871159524458, 4107850935672, 7809413245275, -7809413245275, -8215701871344, -4107850935672], [2646940004359105, -2647492295218505, 105693129534173, 0, 276145429700, 828436289100], [-25106179677657237, -25101941134407683, 0, -80477467571671, -6357814874331, 2119271624777], [14288845306341581, -14286539122149739, 66517674978142, 0, -1153092095921, -3459276287763], [3509321919462, 12336549651492878, -25173260331564, -25173260331564, 3509321919462, -7018643838924], [-11419755900112582, 5317317519288, 8498396311227, -8498396311227, -10634635038576, -5317317519288], [12994956089930769, -12990231119625305, -92351656743440, 0, -2362485152732, -7087455458196], [-22805880364856037, -22805907058818979, 0, 94986543756082, 40040944413, -13346981471], [-9695363485151239, 9690514811683283, -57551964229931, 0, 2424336733978, 7273010201934], [47331230102805360, -7308927151334, -84232618211075, 84232618211075, 14617854302668, 7308927151334], [2480946342124594, 8681453348992, -90319042889189, 90319042889189, -17362906697984, -8681453348992], [-4932138510906, 13389587038701646, -40787724387858, -40787724387858, -4932138510906, 9864277021812], [13167084351144, -53988709753496312, 38505507019620, 38505507019620, 13167084351144, -26334168702288], [68863315056319523, 68852222552733517, 0, -1945663452551, 16638755379009, -5546251793003], [-45481759597809619, 45487076136439845, 17405550934406, 0, -2658269315113, -7974807945339], [-2510881683722, -58815641423703010, 92847680476336, 92847680476336, -2510881683722, 5021763367444], [64643344465397485, -64622522720080323, 65123751185335, 0, -10410872658581, -31232617975743], [-9816574089652356, 2843252089038, 46050299870403, -46050299870403, -5686504178076, -2843252089038], [101319852225316107, 101341328597229501, 0, 62109777628476, -32214557870091, 10738185956697], [57681580369161850, -11124701620856, 119503084073056, -119503084073056, 22249403241712, 11124701620856], [19785222102216, 16940183404120040, -19974435258648, -19974435258648, 19785222102216, -39570444204432], [-79838704204853003, 79817932880186281, 88528487272040, 0, 10385662333361, 31156987000083], [-111620887977379275, -111630573945962119, 0, -164829279295901, 14528952874266, -4842984291422], [-39467758973465537, -39482475129702667, 0, 93143908674176, 22074234355695, -7358078118565], [13410889401092, 84583369917510452, 261621288217652, 261621288217652, 13410889401092, -26821778802184], [95785254937238576, -12370113852614, -164379772579079, 164379772579079, 24740227705228, 12370113852614], [320657012805554482, -882228717664, 39611799236987, -39611799236987, 1764457435328, 882228717664], [-82764358020360019, 82796087197708093, -344885497937061, 0, -15864588674037, -47593766022111], [-230155353371869871, -230157653890586719, 0, -93753755983237, 3450778075272, -1150259358424], [13442019609890, 33416035114875962, -180764160057127, -180764160057127, 13442019609890, -26884039219780], [-9566953393164, -316522439781857500, 77742158850792, 77742158850792, -9566953393164, 19133906786328], [286480424325213093, -286495615661612351, 321526312207936, 0, 7595668199629, 22787004598887], [82782560766206981, 82792038061037977, 0, 167680873905772, -14215942246494, 4738647415498], [3874015411786, 307735331262937058, 93007697088904, 93007697088904, 3874015411786, -7748030823572], [-138753774569651787, 138736566201970081, -132375414720857, 0, 8604183840853, 25812551522559], [-219487989069530945, -219531094829244811, 0, 79793570560520, 64658639570799, -21552879856933], [-434737127664259526, 298334936104, 119545786381555, -119545786381555, -596669872208, -298334936104], [228846701223722241, -228877622068876361, 35611871849185, 0, 15460422577060, 46381267731180], [-71055038785393469, -71023495964855539, 0, 56304577561985, -47314230806895, 15771410268965], [65488430182336369, 65486415813847393, 0, 738280785249567, 3021552733464, -1007184244488], [-125518116174653836, 29483945708214, 198238680761355, -198238680761355, -58967891416428, -29483945708214], [14324254132212, 286168309170060260, 533316286095024, 533316286095024, 14324254132212, -28648508264424], [-63858951569248, -96828492647975456, -422995616999845, -422995616999845, -63858951569248, 127717903138496], [-35793837677465083, -35771691091532967, 0, -928655603487010, -33219878898174, 11073292966058], [391891725425170170, 1945288320472, -504367441321028, 504367441321028, -3890576640944, -1945288320472], [-257195962846709179, -257195075204020519, 0, -97779199287765, -1331464032990, 443821344330], [-262216810664609047, 262136297767281971, 538638722089378, 0, 40256448663538, 120769345990614], [-74526330577029437, -74605007746967795, 0, 88834449969165, 118015754907537, -39338584969179], [684459299875791608, 14773058368402, 454210618489225, -454210618489225, -29546116736804, -14773058368402], [177154481154031489, 177176556715646849, 0, 916159661254904, -33113342423040, 11037780807680], [-634425910831626243, 634448851916854469, 247096853580143, 0, -11470542614113, -34411627842339], [163676904015908884, -65798673759786, 554864523489015, -554864523489015, 131597347519572, 65798673759786], [73463818063560635, 73582600131118173, 0, 747344035898468, -178173101336307, 59391033778769]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_10_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_10_13_c_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_10_13_c_b(:prec:=6)
    chi := MakeCharacter_10_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 13));
    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_10_13_c_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_10_13_c_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_10_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,13,sign)));
    Vf := Kernel([<3,R![89215026326576928, -448013764587024, 1124902056996, -108468072, 43808, -296, 1]>],Snew);
    return Vf;
end function;