Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Made the cardinality ignore the algorithm if known and added a doctest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Scrimshaw committed Jul 19, 2014
1 parent 0262f93 commit e058079
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/sage/schemes/elliptic_curves/ell_finite_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,27 +748,26 @@ def cardinality(self, algorithm='heuristic', extension_degree=1):
INPUT:
- ``algorithm`` - string (default: 'heuristic'), used
only for point counting over prime fields
- ``'heuristic'`` - use a heuristic to choose between
``'pari'`` and ``'bsgs'``.
- ``'heuristic'`` - use a heuristic to choose between
``'pari'`` and ``'bsgs'``
- ``'pari'`` - use the baby step giant step or SEA methods
as implemented in PARI via the C-library function ellap.
- ``'pari'`` - use the baby step giant step or SEA methods
as implemented in PARI via the C-library function ellap
- ``'bsgs'`` - use the baby step giant step method as
implemented in Sage, with the Cremona-Sutherland version
of Mestre's trick.
- ``'bsgs'`` - use the baby step giant step method as
implemented in Sage, with the Cremona-Sutherland version
of Mestre's trick
- ``'all'`` - (over prime fields only) compute cardinality
with all of PARI and bsgs; return result if they agree
or raise a RuntimeError if they do not.
- ``'all'`` - (over prime fields only) compute cardinality
with all of PARI and bsgs; return result if they agree
or raise a ``RuntimeError`` if they do not
- ``extension_degree`` - int (default: 1); if the
base field is `k=GF(p^n)` and extension_degree=d, returns
the cardinality of `E(GF(p^{n d}))`.
the cardinality of `E(GF(p^{n d}))`
OUTPUT: an integer
Expand All @@ -777,10 +776,10 @@ def cardinality(self, algorithm='heuristic', extension_degree=1):
Over prime fields, one of the above algorithms is used. Over
non-prime fields, the serious point counting is done on a standard
curve with the same j-invariant over the field GF(p)(j), then
lifted to the base_field, and finally account is taken of twists.
curve with the same `j`-invariant over the field `\GF{p}(j)`, then
lifted to the base field, and finally account is taken of twists.
For j=0 and j=1728 special formulas are used instead.
For `j = 0` and `j = 1728` special formulas are used instead.
EXAMPLES::
Expand Down Expand Up @@ -830,6 +829,14 @@ def cardinality(self, algorithm='heuristic', extension_degree=1):
Traceback (most recent call last):
...
ValueError: Algorithm is not known
If the cardinality has already been computed, then the ``algorithm``
keyword is ignored::
sage: EllipticCurve(GF(10007),[1,2,3,4,5]).cardinality(algorithm='pari')
10076
sage: EllipticCurve(GF(10007),[1,2,3,4,5]).cardinality(algorithm='foobar')
10076
"""
if extension_degree>1:
# A recursive call to cardinality() with
Expand All @@ -842,11 +849,10 @@ def cardinality(self, algorithm='heuristic', extension_degree=1):
return (self.frobenius()**extension_degree-1).norm()

# Now extension_degree==1
if algorithm != 'all':
try:
return self._order
except AttributeError:
pass
try:
return self._order
except AttributeError:
pass

k = self.base_ring()
q = k.cardinality()
Expand Down

0 comments on commit e058079

Please sign in to comment.