Skip to content

Commit 7909a2f

Browse files
author
Release Manager
committed
gh-40223: Implement algorithm=generic_small and algorithm=hybrid for elliptic curve points The main purpose of this is to be able to do the following (from doctest) sage: # needs sage.rings.finite_rings sage: p = next_prime(2^256) sage: q = next_prime(p) sage: E = EllipticCurve(GF(660*p*q-1), [1, 0]) sage: P = E.lift_x(11) * p * q sage: P.order() # not tested (pari will try to factor p*q which takes forever) sage: P.order(algorithm='generic_small') 330 sage: P.order() # works due to caching 330 Also fix some minor issues. It might be preferable to upstream this to pari as well. Also, this improvement idea can be applied more generally, namely to `order_from_multiple`. However, that complicate the implementation somewhat. I decide to leave that for later, if there is interest. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #40223 Reported by: user202729 Reviewer(s): John Cremona, Sahil Jain, user202729
2 parents 2e2d1cf + f0cbb9e commit 7909a2f

File tree

3 files changed

+241
-52
lines changed

3 files changed

+241
-52
lines changed

src/sage/groups/generic.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ def bsgs(a, b, bounds, operation='*', identity=None, inverse=None, op=None):
458458
AUTHOR:
459459
460460
- John Cremona (2008-03-15)
461+
462+
TESTS:
463+
464+
Ensures Python integers work::
465+
466+
sage: from sage.groups.generic import bsgs
467+
sage: b = Mod(2,37); a = b^20
468+
sage: bsgs(b, a, (0r, 36r))
469+
20
461470
"""
462471
Z = integer_ring.ZZ
463472

@@ -477,6 +486,8 @@ def bsgs(a, b, bounds, operation='*', identity=None, inverse=None, op=None):
477486
raise ValueError("identity, inverse and operation must be given")
478487

479488
lb, ub = bounds
489+
lb = Z(lb)
490+
ub = Z(ub)
480491
if lb < 0 or ub < lb:
481492
raise ValueError("bsgs() requires 0<=lb<=ub")
482493

@@ -1405,7 +1416,9 @@ def order_from_bounds(P, bounds, d=None, operation='+',
14051416
- ``P`` -- a Sage object which is a group element
14061417
14071418
- ``bounds`` -- a 2-tuple ``(lb,ub)`` such that ``m*P=0`` (or
1408-
``P**m=1``) for some ``m`` with ``lb<=m<=ub``
1419+
``P**m=1``) for some ``m`` with ``lb<=m<=ub``. If ``None``,
1420+
gradually increasing bounds will be tried (might loop infinitely
1421+
if the element has no torsion).
14091422
14101423
- ``d`` -- (optional) a positive integer; only ``m`` which are
14111424
multiples of this will be considered
@@ -1434,6 +1447,8 @@ def order_from_bounds(P, bounds, d=None, operation='+',
14341447
sage: b = a^4
14351448
sage: order_from_bounds(b, (5^4, 5^5), operation='*')
14361449
781
1450+
sage: order_from_bounds(b, None, operation='*')
1451+
781
14371452
14381453
sage: # needs sage.rings.finite_rings sage.schemes
14391454
sage: E = EllipticCurve(k, [2,4])
@@ -1451,6 +1466,15 @@ def order_from_bounds(P, bounds, d=None, operation='+',
14511466
sage: order_from_bounds(w, (200, 250), operation='*')
14521467
23
14531468
"""
1469+
if bounds is None:
1470+
lb = 1
1471+
ub = 256
1472+
while True:
1473+
try:
1474+
return order_from_bounds(P, (lb, ub), d, operation, identity, inverse, op)
1475+
except ValueError:
1476+
lb = ub + 1
1477+
ub *= 16
14541478
from operator import mul, add
14551479

14561480
if operation in multiplication_names:

0 commit comments

Comments
 (0)