1 | | ~~"""~~ |

2 | | ~~SEA: Schoof, Elkies, Atkins point counting~~ |

3 | | |

4 | | ~~Interface to the GP SEA implementation of Christophe Doche and Sylvain~~ |

5 | | ~~Duquesne.~~ |

6 | | ~~"""~~ |

7 | | |

8 | | ~~#*****************************************************************************~~ |

9 | | ~~# Copyright (C) 2005 William Stein <wstein@gmail.com>~~ |

10 | | ~~#~~ |

11 | | ~~# Distributed under the terms of the GNU General Public License (GPL)~~ |

12 | | ~~#~~ |

13 | | ~~# This code is distributed in the hope that it will be useful,~~ |

14 | | ~~# but WITHOUT ANY WARRANTY; without even the implied warranty of~~ |

15 | | ~~# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU~~ |

16 | | ~~# General Public License for more details.~~ |

17 | | ~~#~~ |

18 | | ~~# The full text of the GPL is available at:~~ |

19 | | ~~#~~ |

20 | | ~~# http://www.gnu.org/licenses/~~ |

21 | | ~~#*****************************************************************************~~ |

22 | | |

23 | | ~~from sage.interfaces.gp import Gp~~ |

24 | | ~~from sage.rings.all import Integer~~ |

25 | | |

26 | | ~~gp = None~~ |

27 | | ~~def ellsea(E, p, early_abort=False):~~ |

28 | | ~~ """~~ |

29 | | ~~ INPUT:~~ |

30 | | ~~ E -- list of 5 integers that defines an elliptic curve~~ |

31 | | ~~ p -- prime number~~ |

32 | | ~~ early_abort -- bool (default: False); if True an early abort~~ |

33 | | ~~ technique is used and the computation is~~ |

34 | | ~~ interrupted as soon as a small divisor of the~~ |

35 | | ~~ order is detected. The function then returns~~ |

36 | | ~~ 0. This is useful for ruling out curves whose~~ |

37 | | ~~ cardinality is divisible by a small prime.~~ |

38 | | ~~ """~~ |

39 | | ~~ global gp~~ |

40 | | ~~ if gp is None:~~ |

41 | | ~~ gp = Gp(script_subdirectory='SEA')~~ |

42 | | ~~ gp.eval('allocatemem();allocatemem();allocatemem();allocatemem();allocatemem();allocatemem()')~~ |

43 | | ~~ gp.read("sea.gp")~~ |

44 | | |

45 | | ~~ gp.eval('E = ellinit(%s*Mod(1,%s));'%(E,p))~~ |

46 | | ~~ N = gp.eval("ellsea(E,%s,0,%s)"%(p,int(early_abort)))~~ |

47 | | ~~ if N.find("*") != -1:~~ |

48 | | ~~ raise RuntimeError, "Error: '%s'"%N~~ |

49 | | ~~ return Integer(N)~~ |