Ticket #13615: isogeny_genus_0.patch

File isogeny_genus_0.patch, 42.5 KB (added by cremona, 6 years ago)
  • sage/schemes/elliptic_curves/isogeny_genus_0.py

    # HG changeset patch
    # User Kiminori Tsukazaki <kiminori.t@gmail.com>
    # Date 1374461068 -3600
    # Node ID 23db6a27e4cb490accc5630eefc0be6ff4db16e8
    # Parent  68e26eb8c8d77af38c65cbe6f745919dc5852853
    [mq]: isogeny_genus_0
    
    diff --git a/sage/schemes/elliptic_curves/isogeny_genus_0.py b/sage/schemes/elliptic_curves/isogeny_genus_0.py
    a b  
    11431143    [isog.set_pre_isomorphism(iso) for isog in isogs]
    11441144   
    11451145    return isogs
     1146
     1147@cached_function
     1148def hyperelliptic_isogeny_data(l):
     1149    data = {}
     1150    Zu = PolynomialRing(ZZ,'u')
     1151    Zuv = PolynomialRing(ZZ,['u','v'])
     1152    Zxuv = PolynomialRing(ZZ,['x','u','v'])
     1153    x,u,v = Zxuv.gens()
     1154    if l == 11:
     1155        data['hyper_poly'] = Zu([-7, 12, 2, -16, 1])
     1156        data['A2'] = Zu([-33, 55])
     1157        data['A4'] = Zuv(Zu([-135, 738, -183])+v*Zu([-180]))
     1158        data['A6'] = Zuv(Zu([1890, 2646, -11466, 1330]) + v*Zu([-1836, 1332]))
     1159        data['alpha'] = Zu([-6750, 24300, 40095, -187407, 132066, 133056, -177408, 69630, -12716, 1188, -55, 1])
     1160        data['beta'] = Zu([0, -12150, 27135, 10665, -48573, 29313, -7187, 843, -47, 1])
     1161        #beta factors as (u - 15) * (u - 6) * (u - 3) * (u - 1) * u * (u**2 - 12*u - 9) * (u**2 - 10*u + 5)
     1162        return data
     1163    if l == 17:
     1164        data['hyper_poly'] = Zu([-8, 4, -3, -10, 1])
     1165        data['A2'] = Zu([68, -204, 136])
     1166        data['A4'] = Zuv(Zu([60, 720, -2595, 2250, -435]) + v*Zu([-360, 792, -432]))
     1167        data['A6'] = Zuv(Zu([-8512, 22608, -5064, -57528, 87288, -43704, 4912] ) + v*Zu( [2520, -15372, 28098, -20160, 4914]))
     1168        data['alpha'] = Zu([16000, -67200, 2720, 557600, -1392232, 1073992, 1104830, -3131026, 2450210, 73746, -1454945, 1110355, -424065, 95659, -13243, 1105, -51, 1])
     1169        data['beta'] = Zu([0, 22400, -105920, 146208, 111616, -593800, 680948, -102282, -457950, 468035, -219274, 58549, -9374, 889, -46, 1])
     1170        #beta factors as (u - 10) * (u - 5) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 10*u + 7) * (u**2 - 6*u - 4) * (u**2 - 4*u + 2) * (u**3 - 9*u**2 + 8*u - 4)
     1171        data['endo'] = 17*x**8 + 17*(-4*u + 4)*v*x**6 + 17*(4*u + 6)*v**2*x**4 + 17*(4*u + 4)*v**3*x**2 + (-4*u + 1)*v**4
     1172        data['endo_u'] = 1
     1173        return data
     1174    if l == 19:
     1175        data['hyper_poly'] = Zu([-8, 20, -8, -8, 1])
     1176        data['A2'] = Zu([-114, 57, 171])
     1177        data['A4'] = Zuv(Zu([-1020, 444, 2733, 726, -543]) + v*Zu([-180, -720, -540]))
     1178        data['A6'] = Zuv(Zu([-10080, 21816, 54324, -37386, -86742, -20070, 6858]) + v*Zu([-2968, -13748, -11284, 6356, 6860]))
     1179        data['alpha'] = Zu([16000, -22400, -337440, 475456, 1562104, -1988616, -3025294, 3245960, 2833014, -2420087, -1140950, 932406, 129580, -180443, 21090, 11153, -4066, 570, -38, 1])
     1180        data['beta'] = Zu([0, 33600, -8160, -292400, 23472, 791244, 39282, -847909, -47024, 392654, -24046, -82469, 19162, 4833, -2652, 446, -34, 1])
     1181        #beta factors as (u - 7) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 8*u - 4) * (u**2 - 6*u - 15) * (u**2 - 5*u - 5) * (u**2 - 5*u + 2) * (u**2 - 2*u - 4) * (u**2 + u - 1)
     1182        data['endo'] = 19*x**9 + 19*(-12*u - 24)*v*x**6 + 19*(-24*u - 24)*v**2*x**3 + (96*u - 224)*v**3
     1183        data['endo_u'] = -1
     1184        return data
     1185    if l == 23:
     1186        data['hyper_poly'] = Zu([-7, 10, -11, 2, 2, -8, 1])
     1187        data['A2'] = Zu([69, -230, 253])
     1188        data['A4'] = Zuv(Zu([405, 180, -930, 2820, -795]) + v*Zu([360, -792]))
     1189        data['A6'] = Zuv(Zu([-15498, 34020, -36918, -8120, 51114, -72492, 12166]) + v*Zu([-1080, 7704, -24840, 12168]))
     1190        data['alpha'] = Zu([-6750, 48600, -83835, -170775, 1115109, -2492280, 2732814, -116403, -4877702, 8362616, -6612454, 302266, 5423124, -6447728, 3209696, 336674, -1470068, 953856, -336927, 74221, -10465, 920, -46, 1])
     1191        data['beta'] = Zu( [0, 12150, -72495, 168588, -144045, -254034, 930982, -1256170, 604358, 693650, -1563176, 1271974, -225188, -444070, 421050, -184350, 47754, -7696, 759, -42, 1])
     1192        #beta factors as (u - 5) * (u - 3) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 8*u + 3) * (u**2 - 6*u - 9) * (u**3 - 7*u**2 + 3*u - 5) * (u**3 - 7*u**2 + 7*u - 3) * (u**4 - 4*u**3 - 1)
     1193        return data
     1194    if l == 29:
     1195        data['hyper_poly'] = Zu([-7, 8, 8, 2, -12, -4, 1])
     1196        data['A2'] = Zu([-174, -232, 348, 406])
     1197        data['A4'] = Zuv(Zu([-1215, -3096, 132, 7614, 6504, -360, -1263] ) + v*Zu( [180, -720, -2160, -1260]))
     1198        data['A6'] = Zuv(Zu([-18900, -63504, 24696, 285068, 285264, -185136, -506268, -275520, 504, 24388] ) + v*Zu( [4482, -2448, -59868, -94968, -18144, 48276, 24390]))
     1199        data['alpha'] = Zu([-6750, -12150, 281880, 570024, -1754181, -5229135, 2357613, 19103721, 9708910, -31795426, -38397537, 19207947, 54103270, 9216142, -37142939, -18871083, 14041394, 10954634, -3592085, -3427365, 853818, 622398, -189399, -53679, 26680, -580, -1421, 319, -29, 1])
     1200        data['beta'] = Zu([0, -24300, -57510, 257850, 839187, -373185, -3602119, -2371192, 5865017, 8434433, -2363779, -10263744, -2746015, 5976011, 3151075, -2093854, -1356433, 569525, 299477, -129484, -28279, 19043, -895, -1076, 273, -27, 1])
     1201        #beta factors as (u - 3) * (u - 1) * u * (u + 1) * (u + 2) * (u**2 - 6*u + 2) * (u**2 - 5*u - 5) * (u**2 - 5*u + 3) * (u**2 - 3*u - 9) * (u**2 - u - 3) * (u**2 - u - 1) * (u**2 + u - 1) * (u**3 - 4*u**2 - 6*u - 5) * (u**4 - 2*u**3 - 5*u**2 - 4*u - 1)
     1202        data['endo'] = 29*x**14 + 29*(-14*u + 3)*v*x**12 + 29*(-20*u + 73)*v**2*x**10 + 29*(-58*u + 115)*v**3*x**8 + 29*(-56*u + 59)*v**4*x**6 + 29*(30*u + 1)*v**5*x**4 + 29*(12*u - 5)*v**6*x**2 + (2*u + 5)*v**7
     1203        data['endo_u'] = -1
     1204        return data
     1205    if l == 31:
     1206        data['hyper_poly'] = Zu([-3, -14, -11, 18, 6, -8, 1])
     1207        data['A2'] = Zu([558, 837, -1488, 465])
     1208        data['A4'] = Zuv(Zu([-4140, -12468, 15189, 16956, -27054, 11184, -1443]) + v*Zu([2160, -7560, 6120, -1440]))
     1209        data['A6'] = Zuv(Zu([71280, 592056, -108324, -2609730, 2373048, 1282266, -2793204, 1530882, -356976, 29790]) + v*Zu([-81312, 181664, 294728, -868392, 701400, -238840, 29792]))
     1210        data['alpha'] = Zu([108000, 475200, -7053120, -27353408, 90884374, 303670296, -665806437, -1361301729, 3259359840, 2249261823, -9368721606, 2279583264, 13054272515, -12759480061, -4169029296, 14390047139, -7803693550, -2988803682, 6239473912, -3296588360, 134066754, 908915598, -685615437, 294482733, -87483178, 18983315, -3052818, 361336, -30659, 1767, -62, 1])
     1211        data['beta'] = Zu([0, 712800, 1216080, -18430560, -15262464, 168899202, -12931221, -720077416, 624871714, 1239052988, -2259335558, 68648452, 2679085427, -2318039014, -229246628, 1710545918, -1243026758, 211524870, 296674626, -291810274, 145889932, -48916468, 11793961, -2085662, 269348, -24778, 1540, -58, 1])
     1212        #beta factors as (u - 3) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 8*u + 11) * (u**2 - 7*u + 2) * (u**2 - 5*u - 2) * (u**2 - 5*u + 5) * (u**2 - 4*u - 4) * (u**2 - 4*u - 1) * (u**2 - 2*u - 1) * (u**2 - u - 1) * (u**3 - 9*u**2 + 21*u - 15) * (u**4 - 8*u**3 + 8*u**2 + 12*u - 9)
     1213        data['endo'] = 31*x**15 + 31*(-66*u + 86)*v*x**12 + 31*(168*u + 280)*v**2*x**9 + 31*(576*u + 1792)*v**3*x**6 + 31*(384*u + 896)*v**4*x**3 + (-3072*u - 2048)*v**5
     1214        data['endo_u'] = 2
     1215        return data
     1216    if l == 41:
     1217        data['hyper_poly'] = Zu([-8, -20, -15, 8, 20, 10, -8, -4, 1])
     1218        data['A2'] = Zu([328, 656, -656, -1148, 820])
     1219        data['A4'] = Zuv(Zu([-1380, -4008, 1701, 10872, 6144, -18378, -2160, 9732, -2523]) + v*Zu([720, -1440, -2160, 5400, -2520]))
     1220        data['A6'] = Zuv(Zu([4480, 155616, 16080, -550720, -343968, 832680, 938632, -621648, -1468608, 953920, 427632, -413016, 68920]) + v*Zu([-14616, 6804, 96390, -2016, -324324, 184464, 260568, -276192, 68922]))
     1221        data['alpha'] = Zu([16000, 67200, -465760, -2966432, -1742664, 20985112, 46140990, -31732934, -217030548, -147139488, 436080674, 745775322, -271341362, -1542677562, -605560447, 1832223375, 1772593672, -1270633050, -2400692229, 343522723, 2179745361, 282422801, -1503727029, -421357697, 879637411, 261059095, -462271351, -61715127, 193718727, -24135265, -49355103, 20512341, 3613289, -4706595, 1099661, 163057, -162483, 46617, -7544, 738, -41, 1])
     1222        data['beta'] = Zu([0, 44800, 167040, -447040, -2734272, -1104272, 13488360, 21067652, -24681704, -83929974, -8986886, 169059382, 127641266, -196479899, -283039783, 124573790, 366614063, -12946368, -332987597, -58867672, 241909907, 60568430, -155045647, -17919564, 79114945, -12025938, -24060781, 11190142, 1979597, -2931764, 750233, 110144, -122263, 37484, -6439, 666, -39, 1])
     1223        #beta factors as (u - 5) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 5*u + 5) * (u**2 - 3*u - 7) * (u**2 - 2*u - 4) * (u**2 - 2*u - 1) * (u**2 - u - 1) * (u**2 - 2) * (u**2 + u - 1) * (u**3 - 3*u**2 - 5*u - 2) * (u**3 - 2*u**2 - 2*u - 1) * (u**4 - 6*u**3 + 5*u**2 + 2*u - 1) * (u**4 - 5*u**3 + u**2 + 4) * (u**4 - 4*u**3 + 2)
     1224        data['endo'] = 41*x**20 + 41*(-12*u - 22)*v*x**18 + 41*(-252*u - 247)*v**2*x**16 + 41*(-176*u - 424)*v**3*x**14 + 41*(464*u - 254)*v**4*x**12 + 41*(1688*u - 868)*v**5*x**10 + 41*(1720*u - 1190)*v**6*x**8 + 41*(528*u - 232)*v**7*x**6 + 41*(16*u + 29)*v**8*x**4 + 41*(20*u + 10)*v**9*x**2 + (4*u + 5)*v**10
     1225        data['endo_u'] = 1
     1226        return data
     1227    if l == 47:
     1228        data['hyper_poly'] = Zu([-11, 28, -38, 30, -13, -16, 19, -24, 11, -6, 1])
     1229        data['A2'] = Zu([376, -1504, 2209, -1598, 1081])
     1230        data['A4'] = Zuv(Zu([2400, -4080, -1440, 18000, -26355, 34740, -22050, 12900, -3315]) + v*Zu([1152, -3384, 3672, -3312]))
     1231        data['A6'] = Zuv(Zu([-119504, 606336, -1505280, 2109392, -1509360, -515808, 2920702, -4614012, 4334322, -3260312, 1571442, -622428, 103822]) + v*Zu([2016, 48384, -235872, 438984, -627480, 503496, -311976, 103824]))
     1232        data['alpha'] = Zu([-65536, 688128, -2502656, -96256, 38598656, -187217920, 508021120, -845669120, 552981696, 1469334304, -5945275904, 11705275552, -14673798654, 9100068184, 8421580132, -34288012648, 56657584158, -60426283952, 36612252089, 9942017442, -60791892299, 93046207239, -92028642340, 59196883097, -10454018992, -33364599371, 57280402355, -57873890484, 41879296232, -20241250112, 2065827049, 8435506655, -11611941072, 10182603298, -7040645261, 4071881378, -2013138357, 856757031, -313468474, 97893151, -25770006, 5617769, -990431, 136864, -14194, 1034, -47, 1])
     1233        data['beta'] = Zu([0, 114688, -1114112, 4854784, -11205632, 7426048, 42663936, -182555136, 394092544, -508851472, 213245648, 743315936, -2203729384, 3409478688, -3280008936, 1139839970, 2576264698, -6272528962, 8005203155, -6671665088, 2744569094, 1996771588, -5520074039, 6637395180, -5455622885, 3028415830, -601645255, -1012737914, 1632999370, -1525982346, 1093778952, -644352392, 319489974, -134176208, 47566499, -14083902, 3424200, -667810, 101271, -11438, 901, -44, 1])
     1234        #beta factors as (u - 4) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 5*u + 2) * (u**2 - 2*u - 1) * (u**3 - 5*u**2 + 5*u - 7) * (u**3 - 4*u**2 + 3*u - 4) * (u**3 - 4*u**2 + 3*u - 1) * (u**3 - 3*u**2 + 2*u - 4) * (u**3 - 2*u**2 + 2*u - 2) * (u**3 + u + 1) * (u**4 - 4*u**3 - 2*u**2 - 4) * (u**5 - 5*u**4 + 5*u**3 - 11*u**2 + 6*u - 4) * (u**6 - 4*u**5 + 2*u**4 - 4*u**3 - u**2 + 4*u - 2)
     1235        return data
     1236    if l == 59:
     1237        data['hyper_poly'] = Zu([-8, -4, 20, -24, -3, 40, -62, 40, 3, -28, 22, -8, 1])
     1238        data['A2'] = Zu([590, -1475, -295, 4130, -4425, 1711])
     1239        data['A4'] = Zuv(Zu([-2460, 8844, -3843, -20718, 57153, -50418, -12600, 72762, -69339, 30978, -5223]) + v*Zu([900, 360, -7560, 10800, -5220]))
     1240        data['A6'] = Zuv(Zu([25760, -373560, 568020, 1147870, -4634370, 5318070, 1631996, -14270202, 21535998, -14119408, -2820102, 14275410, -13535292, 6790074, -1847898, 205378]) + v*Zu([-23688, 27972, 183708, -696024, 721980, 453600, -1925028, 2039184, -1027404, 205380]))
     1241        data['alpha'] = Zu([16000, -67200, -783520, 5573376, -5127336, -60792184, 241324042, -170978932, -1262437160, 4310971231, -3953349811, -10887235780, 41679530185, -51342089572, -33068562195, 230682514316, -372641172307, 121615007703, 682044179678, -1549365239197, 1373184591667, 614906882627, -3566756201696, 4920423266916, -2342393877496, -3589340274442, 8772457933356, -8488557160148, 1742977715620, 7131088674129, -11643540780203, 8512399456274, -315658868113, -6917286294515, 8713332734648, -5190227733987, -54249978263, 3397583328372, -3658171840037, 1987950394792, -179519591637, -748989116551, 800595050760, -459184355769, 134398080099, 28871590941, -64236756338, 46651654354, -23352309386, 9059054346, -2830320860, 721829600, -150487052, 25475079, -3452149, 365800, -29205, 1652, -59, 1])
     1242        data['beta'] = Zu([0, -56000, 320800, 391440, -7693120, 21125500, 11515130, -204780145, 486681785, -102547033, -2147060784, 5552726794, -4419031758, -9431888681, 33728080307, -42367773552, -2994127157, 105330637610, -188172973931, 127559513693, 123083802224, -421097252069, 490425751691, -161944881372, -408669953969, 799965143719, -668167261718, 69589638764, 563644022562, -787681290965, 505670881115, 2900924856, -364669742737, 407962360532, -223582547975, 9985786664, 102435489491, -105519055992, 58212400117, -14331637533, -6742538722, 10205452686, -6853903214, 3244679736, -1188153136, 347102566, -81626216, 15409226, -2307408, 268126, -23322, 1429, -55, 1])
     1243        #beta factors as (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 4*u - 1) * (u**2 - 3*u - 5) * (u**2 - 3*u - 2) * (u**2 - 3*u + 1) * (u**2 - u - 1) * (u**3 - 6*u**2 + 10*u - 7) * (u**3 - 5*u**2 + 7*u - 5) * (u**3 - 3*u**2 + 2*u - 1) * (u**3 - u**2 + 1) * (u**4 - 5*u**3 + 4*u**2 - 1) * (u**4 - 4*u**3 + 3*u**2 + 2*u - 4) * (u**4 - 3*u**3 - u - 1) * (u**4 - u**3 + 2*u - 1) * (u**5 - 6*u**4 + 10*u**3 - 11*u**2 + 8*u - 4) * (u**6 - 5*u**5 + 5*u**4 - 5*u**2 + 5*u - 5)
     1244        return data
     1245    if l == 71:
     1246        data['hyper_poly'] = Zu([-7, 6, -27, 40, -58, 66, -66, 40, 15, -48, 66, -66, 37, -10, 1])
     1247        data['A2'] = Zu([213, -1420, 4260, -4970, 9940, -9088, 2485])
     1248        data['A4'] = Zuv(Zu([2565, -10008, 18024, -26532, 23208, 7584, -104418, 189432, -251736, 275148, -182232, 60144, -7563]) + v*Zu([720, -4320, 7560, -20160, 23040, -7560]))
     1249        data['A6'] = Zuv(Zu([-69930, 382536, -1898568, 5206124, -11813256, 23115792, -35705670, 44318064, -41531952, 20674360, 23881872, -77986944, 114989770, -124612152, 103122936, -59431204, 21485688, -4294416, 357910]) + v*Zu([18576, -53856, 57672, 161856, -961920, 3199176, -5706288, 8032896, -9352584, 6786720, -2505888, 357912]))
     1250        data['alpha'] = Zu([-6750, 97200, -603855, 2263977, -4854483, -2486349, 75190491, -399596520, 1441975423, -4089818964, 9450153463, -17516526653, 23635982289, -11859874932, -53385529273, 230566737711, -585283867605, 1136695427037, -1753961304140, 2020891913264, -1147488305875, -1930304898882, 8102336330029, -17218530732347, 27006964902986, -32365758791872, 25902000374138, -468390635342, -46332664858222, 107139839089502, -162234735929274, 182582147217312, -140033523896938, 22513210292184, 152367877270246, -334009986053250, 451855980915164, -443144048889720, 284518400252142, -11142427766850, -289840331821002, 512373447321402, -576967281819172, 466024421705696, -230395084854230, -36287337331916, 241209603962570, -330646545417814, 304702155703516, -205131886553392, 87504290135653, 5131997859077, -54867900326127, 66216047255551, -54817285755105, 36239054778472, -20052219750661, 9464634765852, -3841191816845, 1343947848527, -405138280373, 104923131180, -23228729413, 4364552115, -689157169, 90223321, -9613968, 812240, -52327, 2414, -71, 1])
     1251        data['beta'] = Zu([0, 12150, -163215, 1115640, -5311143, 18820224, -50700172, 99823812, -102454041, -183909134, 1354660714, -4462311942, 10695310224, -20015395554, 28262441676, -23240987282, -17879387475, 124501604946, -315187724212, 564766450688, -765154573538, 705985549104, -115433273216, -1206098873334, 3175185881748, -5228317292044, 6292310032120, -5077451367560, 719644756530, 6451571564682, -14460150103020, 19999710623352, -19681838601268, 11819712227412, 2180981559572, -17790742756618, 29025463386612, -31179247603548, 23207078145510, -8345354986332, -7468523752270, 18486966963350, -21719818051100, 17831212433536, -10100011266030, 2336962513536, 2906983627184, -4989755986066, 4711466210012, -3361479243242, 1952316811463, -948555371584, 389878900245, -136099552242, 40341734984, -10121407164, 2136756509, -376218102, 54551634, -6399080, 591884, -41538, 2078, -66, 1])
     1252        #beta factors as (u - 3) * (u - 2) * (u - 1) * u * (u + 1) * (u**2 - 5*u + 5) * (u**2 - 3*u + 1) * (u**2 - 2*u - 1) * (u**2 - u - 1) * (u**3 - 5*u**2 + 5*u - 3) * (u**3 - 4*u**2 - 1) * (u**3 - 2*u**2 - 1) * (u**4 - 6*u**3 + 7*u**2 + 6*u - 9) * (u**4 - 5*u**3 + 4*u**2 + u + 3) * (u**4 - 5*u**3 + 6*u**2 - 3*u + 5) * (u**4 - 4*u**3 + u**2 - 4*u + 1) * (u**4 - 4*u**3 + 2*u**2 - u + 1) * (u**4 - 2*u**3 - 3*u**2 - 2*u - 1) * (u**4 - 2*u**3 + u - 1) * (u**6 - 5*u**5 + 8*u**4 - 7*u**3 + 6*u**2 - 3*u + 1) * (u**8 - 6*u**7 + 9*u**6 - 2*u**5 + 2*u**3 - 9*u**2 + 2*u - 1)
     1253        return data
     1254
     1255@cached_function
     1256def Psi2(l):
     1257    """
     1258
     1259    INPUT:
     1260
     1261    - ``l`` -- either 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
     1262
     1263    OUTPUT:
     1264
     1265    The generic l-kernel polynomial.
     1266
     1267    """
     1268    if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]:
     1269        raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1270
     1271    data = hyperelliptic_isogeny_data(l)
     1272    R = PolynomialRing(QQ,['x','u'])
     1273    x, u = R.gens()
     1274    L = PolynomialRing(R,'y')
     1275    y = L.gen()
     1276    K = R.extension(y**2-R(data['hyper_poly']),name = 'v')
     1277    v = K.gen()
     1278    from sage.categories.homset import Hom
     1279    h = Hom(K,K)(-v)
     1280
     1281    A = K(data['A4'])
     1282    B = K(data['A6'])
     1283    Abar = h(A)*l**2
     1284    Bbar = -h(B)*l**3
     1285    s1 = K(data['A2'])
     1286
     1287    d = (l-1)//2
     1288    s = [1]
     1289    t = [d,s1,((1-10*d)*A - Abar)*(1/QQ(30))]
     1290    t += [((1-28*d)*B - 42*t[1]*A - Bbar)*(1/QQ(70))]
     1291    c = [0,6*t[2] + 2*A*t[0],10*t[3] + 6*A*t[1] + 4*B*t[0]]
     1292    for n in range(2,d):
     1293        k = sum(c[i]*c[n-i] for i in range(1,n))
     1294        c += [(3*k-(2*n-1)*(n-1)*A*c[n-1]-(2*n-2)*(n-2)*B*c[n-2])*(1/QQ((n-1)*(2*n+5)))]
     1295    for n in range(3,d):
     1296        t += [(c[n]-(4*n-2)*A*t[n-1]-(4*n-4)*B*t[n-2])*(1/QQ(4*n+2))]
     1297    for n in range(1,d+1):
     1298        s += [(-1/QQ(n))*sum((-1)**i*t[i]*s[n-i] for i in range(1,n+1))]
     1299    psi = sum((-1)**i*s[i]*x**(d-i) for i in range(0,d+1))
     1300    R = PolynomialRing(QQ,['x','u','v'])
     1301    return R(psi)
     1302
     1303
     1304def isogenies_prime_degree_genus_plus_0(E, l):
     1305    """
     1306    Returns list of ``l`` -isogenies with domain ``E``.
     1307
     1308    INPUT:
     1309
     1310    - ``E`` -- an elliptic curve.
     1311
     1312    - ``l`` -- either None or 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
     1313
     1314    OUTPUT:
     1315
     1316    (list) When ``l`` is None a list of all isogenies of degree 11, 17, 19, 23,
     1317    29, 31, 41, 47, 59, or 71, otherwise a list of isogenies of the given degree.
     1318
     1319    .. note::
     1320
     1321       This function would normally be invoked indirectly via
     1322       ``E.isogenies_prime_degree(l)``, which automatically calls the appropriate function.
     1323
     1324    EXAMPLES::
     1325
     1326        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_genus_plus_0
     1327
     1328        sage: E = EllipticCurve('121a1')
     1329        sage: isogenies_prime_degree_genus_plus_0(E, 11)
     1330        [Isogeny of degree 11 from Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 30*x - 76 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 305*x + 7888 over Rational Field]
     1331
     1332        sage: E = EllipticCurve([1, 1, 0, -660, -7600])
     1333        sage: isogenies_prime_degree_genus_plus_0(E, 17)
     1334        [Isogeny of degree 17 from Elliptic Curve defined by y^2 + x*y = x^3 + x^2 - 660*x - 7600 over Rational Field to Elliptic Curve defined by y^2 + x*y = x^3 + x^2 - 878710*x + 316677750 over Rational Field]
     1335
     1336        sage: E = EllipticCurve([0, 0, 1, -1862, -30956])
     1337        sage: isogenies_prime_degree_genus_plus_0(E, 19)
     1338        [Isogeny of degree 19 from Elliptic Curve defined by y^2 + y = x^3 - 1862*x - 30956 over Rational Field to Elliptic Curve defined by y^2 + y = x^3 - 672182*x + 212325489 over Rational Field]
     1339
     1340        sage: K = QuadraticField(-295,'a')
     1341        sage: a = K.gen()
     1342        sage: E = EllipticCurve_from_j(-484650135/16777216*a + 4549855725/16777216)
     1343        sage: isogenies_prime_degree_genus_plus_0(E, 23)
     1344        [Isogeny of degree 23 from Elliptic Curve defined by y^2 = x^3 + (-14460494784192904095/140737488355328*a+270742665778826768325/140737488355328)*x + (37035998788154488846811217135/590295810358705651712*a-1447451882571839266752561148725/590295810358705651712) over Number Field in a with defining polynomial x^2 + 295 to Elliptic Curve defined by y^2 = x^3 + (-5130542435555445498495/140737488355328*a+173233955029127361005925/140737488355328)*x + (-1104699335561165691575396879260545/590295810358705651712*a+3169785826904210171629535101419675/590295810358705651712) over Number Field in a with defining polynomial x^2 + 295]
     1345
     1346        sage: K = QuadraticField(-199,'a')
     1347        sage: a = K.gen()
     1348        sage: E = EllipticCurve_from_j(94743000*a + 269989875)
     1349        sage: isogenies_prime_degree_genus_plus_0(E, 29)
     1350        [Isogeny of degree 29 from Elliptic Curve defined by y^2 = x^3 + (-153477413215038000*a+5140130723072965125)*x + (297036215130547008455526000*a+2854277047164317800973582250) over Number Field in a with defining polynomial x^2 + 199 to Elliptic Curve defined by y^2 = x^3 + (251336161378040805000*a-3071093219933084341875)*x + (-8411064283162168580187643221000*a+34804337770798389546017184785250) over Number Field in a with defining polynomial x^2 + 199]
     1351
     1352        sage: K = QuadraticField(253,'a')
     1353        sage: a = K.gen()
     1354        sage: E = EllipticCurve_from_j(208438034112000*a - 3315409892960000)
     1355        sage: isogenies_prime_degree_genus_plus_0(E, 31)
     1356        [Isogeny of degree 31 from Elliptic Curve defined by y^2 = x^3 + (4146345122185433034677956608000*a-65951656549965037259634800640000)*x + (-18329111516954473474583425393698245080252416000*a+291542366110383928366510368064204147260129280000) over Number Field in a with defining polynomial x^2 - 253 to Elliptic Curve defined by y^2 = x^3 + (200339763852548615776123686912000*a-3186599019027216904280948275200000)*x + (7443671791411479629112717260182286294850207744000*a-118398847898864757209685951728838895495168655360000) over Number Field in a with defining polynomial x^2 - 253]
     1357
     1358        sage: E = EllipticCurve_from_j(GF(5)(1))
     1359        sage: isogenies_prime_degree_genus_plus_0(E, 41)
     1360        [Isogeny of degree 41 from Elliptic Curve defined by y^2 = x^3 + x + 2 over Finite Field of size 5 to Elliptic Curve defined by y^2 = x^3 + x + 3 over Finite Field of size 5, Isogeny of degree 41 from Elliptic Curve defined by y^2 = x^3 + x + 2 over Finite Field of size 5 to Elliptic Curve defined by y^2 = x^3 + x + 3 over Finite Field of size 5]
     1361
     1362        sage: K = QuadraticField(5,'a')
     1363        sage: a = K.gen()
     1364        sage: E = EllipticCurve_from_j(184068066743177379840*a - 411588709724712960000)
     1365        sage: isogenies_prime_degree_genus_plus_0(E, 47)
     1366        [Isogeny of degree 47 from Elliptic Curve defined by y^2 = x^3 + (454562028554080355857852049849975895490560*a-1016431595837124114668689286176511361024000)*x + (-249456798429896080881440540950393713303830363999480904280965120*a+557802358738710443451273320227578156598454035482869042774016000) over Number Field in a with defining polynomial x^2 - 5 to Elliptic Curve defined by y^2 = x^3 + (39533118442361013730577638493616965245992960*a-88398740199669828340617478832005245173760000)*x + (214030321479466610282320528611562368963830105830555363061803253760*a-478586348074220699687616322532666163722004497458452316582576128000) over Number Field in a with defining polynomial x^2 - 5]
     1367
     1368        sage: K = QuadraticField(-66827,'a')
     1369        sage: a = K.gen()
     1370        sage: E = EllipticCurve_from_j(-98669236224000*a + 4401720074240000)
     1371        sage: isogenies_prime_degree_genus_plus_0(E, 59)   # long time (25s, 2012)
     1372        [Isogeny of degree 59 from Elliptic Curve defined by y^2 = x^3 + (2605886146782144762297974784000*a+1893681048912773634944634716160000)*x + (-116918454256410782232296183198067568744071168000*a+17012043538294664027185882358514011304812871680000) over Number Field in a with defining polynomial x^2 + 66827 to Elliptic Curve defined by y^2 = x^3 + (-25125660899199083720535404527484928000*a-6327148599909127875668412155100659712000)*x + (-1197186521943291638242049193401511283464564457793912832000*a-121120755853676988879960565040225568460861222428113633280000) over Number Field in a with defining polynomial x^2 + 66827]
     1373
     1374        sage: E = EllipticCurve_from_j(GF(13)(5))
     1375        sage: isogenies_prime_degree_genus_plus_0(E, 71)
     1376        [Isogeny of degree 71 from Elliptic Curve defined by y^2 = x^3 + x + 4 over Finite Field of size 13 to Elliptic Curve defined by y^2 = x^3 + 10*x + 7 over Finite Field of size 13, Isogeny of degree 71 from Elliptic Curve defined by y^2 = x^3 + x + 4 over Finite Field of size 13 to Elliptic Curve defined by y^2 = x^3 + 10*x + 7 over Finite Field of size 13]
     1377
     1378    """
     1379    if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
     1380        raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1381    F = E.base_ring()
     1382    j = E.j_invariant()
     1383    if F.characteristic() in [2, 3, l]:
     1384        raise NotImplementedError, "11, 17, 19, 23, 29, 31, 41, 47, 59, and 71-isogenies are not yet implemented in characteristic 2 and 3, and when the characteristic is the same as the degree of the isogeny."
     1385    if j == F(0):
     1386        return isogenies_prime_degree_genus_plus_0_j0(E, l)
     1387    if j == F(1728):
     1388        return isogenies_prime_degree_genus_plus_0_j1728(E, l)
     1389       
     1390    if l!= None:
     1391        Fu = PolynomialRing(F,'u')
     1392        u = Fu.gen()
     1393        Fuv = PolynomialRing(F,['u','v'])
     1394        Fxuv = PolynomialRing(F,['x','u','v'])
     1395        X = u
     1396        data = hyperelliptic_isogeny_data(l)
     1397        a = Fu(data['alpha'])
     1398        b = Fu(data['beta'])
     1399        f = Fu(data['hyper_poly'])
     1400        P = a
     1401        Q = Fu((a**2 - f*b**2)/Fu(4))
     1402        u_list = (j**2-P*j+Q).roots(multiplicities=False)
     1403
     1404        S = []
     1405        for u0 in u_list:
     1406            if b(u0) == 0:
     1407                S += [[u0,v0] for v0 in (X**2-f(u0)).roots(multiplicities=False)]
     1408            else:
     1409                S += [[u0,(2*j-a(u0))/b(u0)]]
     1410        if len(S) == 0:
     1411            return []
     1412        S.sort()
     1413
     1414        c4, c6 = E.c_invariants()
     1415        b2 = E.b2()
     1416        kernels = []
     1417
     1418        psi = Fxuv(Psi2(l))
     1419        for u0, v0 in S:
     1420            A4 = Fuv(data['A4'])(u0,v0) #non-zero since j!=0
     1421            A6 = Fuv(data['A6'])(u0,v0) #non-zero since j!=1728
     1422            T = (c4*A6)/(2*c6*A4)
     1423            kernels += [psi((36*X+3*b2)*T,u0,v0).monic()]
     1424        isogs = [E.isogeny(ker) for ker in kernels]
     1425        return isogs
     1426
     1427    if l == None:
     1428        return sum([isogenies_prime_degree_genus_plus_0(E, l) for l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71]],[])
     1429
     1430
     1431def isogenies_prime_degree_genus_plus_0_j0(E, l):
     1432    """
     1433    Returns a list of ``l`` -isogenies  with domain ``E`` when the
     1434    j-invariant is 0.
     1435
     1436    INPUT:
     1437
     1438    - ``E`` -- an elliptic curve with j-invariant 0.
     1439
     1440    - ``l`` -- 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71. 
     1441
     1442    OUTPUT:
     1443
     1444    (list) a list of all isogenies of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
     1445
     1446    .. note::
     1447
     1448       This implementation requires that the characteristic is not 2, 3 or ``l``.
     1449
     1450    .. note::
     1451
     1452       This function would normally be invoked indirectly via ``E.isogenies_prime_degree(l)``.
     1453
     1454    EXAMPLES::
     1455
     1456        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_genus_plus_0_j0
     1457
     1458        sage: u = polygen(QQ)
     1459        sage: K.<a> = NumberField(u^4+228*u^3+486*u^2-540*u+225)
     1460        sage: E = EllipticCurve(K,[0,-121/5*a^3-20691/5*a^2-29403/5*a+3267])
     1461        sage: isogenies_prime_degree_genus_plus_0_j0(E,11)
     1462        [Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-121/5*a^3-20691/5*a^2-29403/5*a+3267) over Number Field in a with defining polynomial x^4 + 228*x^3 + 486*x^2 - 540*x + 225 to Elliptic Curve defined by y^2 = x^3 + (-44286*a^2+178596*a-32670)*x + (-17863351/5*a^3+125072739/5*a^2-74353653/5*a-682803) over Number Field in a with defining polynomial x^4 + 228*x^3 + 486*x^2 - 540*x + 225, Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-121/5*a^3-20691/5*a^2-29403/5*a+3267) over Number Field in a with defining polynomial x^4 + 228*x^3 + 486*x^2 - 540*x + 225 to Elliptic Curve defined by y^2 = x^3 + (-3267*a^3-740157*a^2+600039*a-277695)*x + (-17863351/5*a^3-4171554981/5*a^2+3769467867/5*a-272366523) over Number Field in a with defining polynomial x^4 + 228*x^3 + 486*x^2 - 540*x + 225]
     1463
     1464        sage: E = EllipticCurve(GF(5^6,'a'),[0,1])
     1465        sage: isogenies_prime_degree_genus_plus_0_j0(E,17)
     1466        [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 1 over Finite Field in a of size 5^6 to Elliptic Curve defined by y^2 = x^3 + 2 over Finite Field in a of size 5^6]
     1467    """
     1468    if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
     1469        raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1470    F = E.base_field()
     1471    if E.j_invariant() != 0:
     1472        raise ValueError, "j-invariant must be 0."
     1473    if F.characteristic() in [2,3,l]:
     1474        raise NotImplementedError, "Not implemented in characteristic 2, 3 or l."
     1475
     1476    Fu = PolynomialRing(F,'u')
     1477    u = Fu.gen()
     1478    Fuv = PolynomialRing(F,['u','v'])
     1479    Fxuv = PolynomialRing(F,['x','u','v'])
     1480    X = u
     1481    data = hyperelliptic_isogeny_data(l)
     1482    a = Fu(data['alpha'])
     1483    b = Fu(data['beta'])
     1484    f = Fu(data['hyper_poly'])
     1485    Q = Fu((a**2 - f*b**2)/Fu(4))
     1486    u_list = Q.roots(multiplicities=False)
     1487    c6, b2 = E.c6(), E.b2()
     1488    kernels = []
     1489
     1490    if l % 3 == 1 and F(-3).is_square():
     1491        p = F(-3).sqrt()
     1492        endo = Fxuv(data['endo'])
     1493        kernels += [endo(36*X+3*b2,p,-54*c6).monic(), endo(36*X+3*b2,-p,-54*c6).monic()]
     1494
     1495    S = []
     1496    for u0 in u_list:
     1497        if l % 3 == 1 and u0 == F(data['endo_u']):
     1498            continue
     1499        if b(u0) == 0:
     1500            S += [[u0,v0] for v0 in (X**2-f(u0)).roots(multiplicities=False)]
     1501        else:
     1502            S += [[u0,-a(u0)/b(u0)]]
     1503    if len(S)==0 and len(kernels) == 0:
     1504        return []
     1505    S.sort()
     1506
     1507    psi = Fxuv(Psi2(l))
     1508    for u0,v0 in S:
     1509        A6 = Fuv(data['A6'])(u0,v0) # non-zero since j!=1728
     1510        kernels += [psi((36*X+3*b2)*T,u0,v0).monic() for T in (X**3-A6/(-54*c6)).roots(multiplicities=False)]
     1511    isogs = [E.isogeny(ker) for ker in kernels]
     1512    return isogs
     1513
     1514
     1515def isogenies_prime_degree_genus_plus_0_j1728(E, l):
     1516    """
     1517    Returns a list of ``l`` -isogenies  with domain ``E`` when the
     1518    j-invariant is 1728.
     1519
     1520    INPUT:
     1521
     1522    - ``E`` -- an elliptic curve with j-invariant 0.
     1523
     1524    - ``l`` -- 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71. 
     1525
     1526    OUTPUT:
     1527
     1528    (list) a list of all isogenies of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71.
     1529
     1530    .. note::
     1531
     1532       This implementation requires that the characteristic is not 2, 3 or ``l``.
     1533
     1534    .. note::
     1535
     1536       This function would normally be invoked indirectly via ``E.isogenies_prime_degree(l)``.
     1537
     1538    EXAMPLES::
     1539
     1540        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_genus_plus_0_j1728
     1541
     1542        sage: u = polygen(QQ)
     1543        sage: K.<a> = NumberField(u^6 - 522*u^5 - 10017*u^4 + 2484*u^3 - 5265*u^2 + 12150*u - 5103)
     1544        sage: E = EllipticCurve(K,[-75295/1335852*a^5+13066735/445284*a^4+44903485/74214*a^3+17086861/24738*a^2+11373021/16492*a-1246245/2356,0])
     1545        sage: isogenies_prime_degree_genus_plus_0_j1728(E,11)
     1546        [Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-75295/1335852*a^5+13066735/445284*a^4+44903485/74214*a^3+17086861/24738*a^2+11373021/16492*a-1246245/2356)*x over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103 to Elliptic Curve defined by y^2 = x^3 + (9110695/1335852*a^5-1581074935/445284*a^4-5433321685/74214*a^3-3163057249/24738*a^2+1569269691/16492*a+73825125/2356)*x + (-3540460*a^3+30522492*a^2-7043652*a-5031180) over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103, Isogeny of degree 11 from Elliptic Curve defined by y^2 = x^3 + (-75295/1335852*a^5+13066735/445284*a^4+44903485/74214*a^3+17086861/24738*a^2+11373021/16492*a-1246245/2356)*x over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103 to Elliptic Curve defined by y^2 = x^3 + (9110695/1335852*a^5-1581074935/445284*a^4-5433321685/74214*a^3-3163057249/24738*a^2+1569269691/16492*a+73825125/2356)*x + (3540460*a^3-30522492*a^2+7043652*a+5031180) over Number Field in a with defining polynomial x^6 - 522*x^5 - 10017*x^4 + 2484*x^3 - 5265*x^2 + 12150*x - 5103]
     1547    """
     1548    if not l in [11, 17, 19, 23, 29, 31, 41, 47, 59, 71, None]:
     1549        raise ValueError, "Isogenies must be of degree 11, 17, 19, 23, 29, 31, 41, 47, 59, or 71."
     1550    F = E.base_ring()
     1551    if E.j_invariant() != 1728:
     1552        raise ValueError, "j-invariant must be 1728."
     1553    if F.characteristic() in [2,3,l]:
     1554        raise NotImplementedError, "Not implemented in characteristic 2, 3 or l."
     1555
     1556    Fu = PolynomialRing(F,'u')
     1557    u = Fu.gen()
     1558    Fuv = PolynomialRing(F,['u','v'])
     1559    Fxuv = PolynomialRing(F,['x','u','v'])
     1560    X = u
     1561    data = hyperelliptic_isogeny_data(l)
     1562    a = Fu(data['alpha'])
     1563    b = Fu(data['beta'])
     1564    f = Fu(data['hyper_poly'])
     1565    P = a
     1566    Q = Fu((a**2 - f*b**2)/Fu(4))
     1567    u_list = (1728**2-P*1728+Q).roots(multiplicities=False)
     1568    c4, b2 = E.c4(), E.b2()
     1569    kernels = []
     1570
     1571    if l % 4 == 1 and  F(-1).is_square():
     1572        i = F(-1).sqrt()
     1573        endo = Fxuv(data['endo'])
     1574        kernels += [endo(X,i,-27*c4).monic(), endo(X,-i,-27*c4).monic()]
     1575
     1576    S = []
     1577    for u0 in u_list:
     1578        if l % 4 == 1 and u0 == F(data['endo_u']):
     1579            continue
     1580        if b(u0) == 0:
     1581            S += [[u0,v0] for v0 in (X**2-f(u0)).roots(multiplicities=False)]
     1582        else:
     1583            S += [[u0,(2*1728-a(u0))/b(u0)]]
     1584    if len(S)==0 and len(kernels) == 0:
     1585        return []
     1586    S.sort()
     1587
     1588    psi = Fxuv(Psi2(l))
     1589    for u0,v0 in S:
     1590        A4 = Fuv(data['A4'])(u0,v0) # non-zero since j!=0
     1591        kernels += [psi((36*X+3*b2)*T,u0,v0).monic() for T in (X**2-A4/(-27*c4)).roots(multiplicities=False)]
     1592    isogs = [E.isogeny(ker) for ker in kernels]
     1593    return isogs
     1594
     1595def least_semi_primitive(p):
     1596    """
     1597    Returns the smallest semi-primitive root modulo p, i.e., the smallest multiplicative generator of the group (ZZ/pZZ)/{1,-1}.
     1598
     1599    INPUT:
     1600
     1601    - ``p`` -- a prime. 
     1602
     1603    OUTPUT:
     1604
     1605    the smallest semi-primitive root modulo p, i.e., the smallest multiplicative generator of the group (ZZ/pZZ)/{1,-1}.
     1606
     1607    .. note::
     1608
     1609       This function would normally be invoked indirectly via ``E.isogenies_prime_degree_general(l)``.
     1610
     1611    EXAMPLES::
     1612
     1613        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import least_semi_primitive
     1614        sage: least_semi_primitive(5)
     1615        2
     1616        sage: least_semi_primitive(13)
     1617        2
     1618        sage: least_semi_primitive(17)
     1619        3
     1620        sage: least_semi_primitive(73)
     1621        5
     1622        sage: least_semi_primitive(997)
     1623        7
     1624    """
     1625    if not p.is_prime():
     1626        raise ValueError, "p is not prime"
     1627
     1628    def is_semi_primitive(a,p):
     1629        from sage.rings.finite_rings.integer_mod_ring import Integers
     1630        d = Integers(p)(a).multiplicative_order()
     1631        if p%4==1:
     1632            return (d==p-1)
     1633        else:
     1634            return d >= (p-1)/2
     1635   
     1636    a = 2
     1637    while not is_semi_primitive(a,p):
     1638        a += 1
     1639    return a
     1640
     1641
     1642def isogenies_prime_degree_general(E, l):
     1643    """
     1644    Returns a list of ``l`` -isogenies  with domain ``E``.
     1645
     1646    INPUT:
     1647
     1648    - ``E`` -- an elliptic curve.
     1649
     1650    - ``l`` -- a prime. 
     1651
     1652    OUTPUT:
     1653
     1654    (list) a list of all isogenies of degree l.
     1655
     1656    EXAMPLES::
     1657
     1658        sage: from sage.schemes.elliptic_curves.isogeny_genus_0 import isogenies_prime_degree_general
     1659        sage: E = EllipticCurve_from_j(GF(2^6,'a')(1))
     1660        sage: isogenies_prime_degree_general(E, 7)
     1661        [Isogeny of degree 7 from Elliptic Curve defined by y^2 + x*y = x^3 + 1 over Finite Field in a of size 2^6 to Elliptic Curve defined by y^2 + x*y = x^3 + x over Finite Field in a of size 2^6]
     1662        sage: E = EllipticCurve_from_j(GF(3^12,'a')(2))
     1663        sage: isogenies_prime_degree_general(E, 17)
     1664        [Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2 over Finite Field in a of size 3^12 to Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2*x over Finite Field in a of size 3^12, Isogeny of degree 17 from Elliptic Curve defined by y^2 = x^3 + 2*x^2 + 2 over Finite Field in a of size 3^12 to Elliptic Curve defined by y^2 = x^3 + 2*x^2 + x + 2 over Finite Field in a of size 3^12]
     1665        sage: E = EllipticCurve('50a1')
     1666        sage: isogenies_prime_degree_general(E, 3)
     1667        [Isogeny of degree 3 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 126*x - 552 over Rational Field]
     1668        sage: isogenies_prime_degree_general(E, 5)
     1669        [Isogeny of degree 5 from Elliptic Curve defined by y^2 + x*y + y = x^3 - x - 2 over Rational Field to Elliptic Curve defined by y^2 + x*y + y = x^3 - 76*x + 298 over Rational Field]
     1670        sage: E = EllipticCurve([0, 0, 1, -1862, -30956])
     1671        sage: isogenies_prime_degree_general(E, 19)
     1672        [Isogeny of degree 19 from Elliptic Curve defined by y^2 + y = x^3 - 1862*x - 30956 over Rational Field to Elliptic Curve defined by y^2 + y = x^3 - 672182*x + 212325489 over Rational Field]
     1673        sage: E = EllipticCurve([0, -1, 0, -6288, 211072])
     1674        sage: isogenies_prime_degree_general(E, 37)  # long time (10s)
     1675        [Isogeny of degree 37 from Elliptic Curve defined by y^2 = x^3 - x^2 - 6288*x + 211072 over Rational Field to Elliptic Curve defined by y^2 = x^3 - x^2 - 163137088*x - 801950801728 over Rational Field]
     1676        sage: E = EllipticCurve([-3440, 77658])
     1677        sage: isogenies_prime_degree_general(E, 43)  # long time (16s)
     1678        [Isogeny of degree 43 from Elliptic Curve defined by y^2 = x^3 - 3440*x + 77658 over Rational Field to Elliptic Curve defined by y^2 = x^3 - 6360560*x - 6174354606 over Rational Field]
     1679    """
     1680    if not l.is_prime():
     1681        raise ValueError, "l is not prime"
     1682    psi_l = E.division_polynomial(l)
     1683    factors = [h for h,e in psi_l.factor() if (l-1)/2 % h.degree() == 0]
     1684    a = least_semi_primitive(l)
     1685    m = E.multiplication_by_m(a, x_only=True)
     1686    F = psi_l.parent()
     1687    x = F.gen()
     1688    ker = []
     1689    from sage.rings.arith import gcd
     1690    from sage.misc.all import prod
     1691    def mult(f):
     1692        return gcd(F(f(m([x,0])).numerator()),psi_l).monic()
     1693    while len(factors) > 0:
     1694        f = factors[0]
     1695        factors.remove(f)
     1696        d = f.degree()
     1697        S = [f]
     1698        for i in range((l-1)/(2*d)-1):
     1699            g = mult(S[i])
     1700            S.append(g)
     1701            if g in factors:
     1702                factors.remove(g)
     1703        if mult(S[-1]) == f:
     1704            ker.append(prod(S))
     1705    isogs = [E.isogeny(k) for k in ker]
     1706    return isogs