Skip to content

Commit d03ee30

Browse files
author
Release Manager
committed
gh-40300: Make discrete_log accept ord=oo The code is intended to do so, but this path cannot be executed when the user explistly pass `ord=oo`, only when the element naturally has infinite order. You can argue that `oo` is a multiple of every positive integer as well, so nothing particularly wrong with doing that. Related to this part of code: #40223 ### 📝 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. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] 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: #40300 Reported by: user202729 Reviewer(s): Travis Scrimshaw
2 parents 5e63d40 + 8ae79b0 commit d03ee30

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/sage/groups/generic.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ def bsgs(a, b, bounds, operation='*', identity=None, inverse=None, op=None):
385385
arguments are provided automatically; otherwise they must be
386386
provided by the caller.
387387
388+
.. SEEALSO::
389+
390+
- :func:`discrete_log` for a potentially faster algorithm by combining
391+
Pohlig-Hellman with baby-step adjacent-step;
392+
- :func:`order_from_bounds` to find the exact order instead of just some
393+
multiple of the order.
394+
388395
INPUT:
389396
390397
- ``a`` -- group element
@@ -694,7 +701,10 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
694701
695702
- ``a`` -- group element
696703
- ``base`` -- group element (the base)
697-
- ``ord`` -- integer (multiple of order of base, or ``None``)
704+
- ``ord`` -- integer (multiple of order of base, ``None``, or
705+
:mod:`oo <sage.rings.infinity>``); if this is
706+
:mod:`oo <sage.rings.infinity>`, then it explicitly does
707+
not use this, for example when factorizing the order is difficult
698708
- ``bounds`` -- a priori bounds on the log
699709
- ``operation`` -- string: ``'*'``, ``'+'``, other
700710
- ``identity`` -- the group's identity
@@ -864,6 +874,14 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
864874
sage: discrete_log(u, g, algorithm='rho')
865875
123456789
866876
877+
Pass ``ord=oo`` to avoid attempts to factorize the group order::
878+
879+
sage: p, q = next_prime(2^128), next_prime(2^129)
880+
sage: a = mod(2, p*q*124+1)
881+
sage: discrete_log(a^100, a, bounds=(1, 500)) # not tested (takes very long, but pari.addprimes(p) makes it faster)
882+
sage: discrete_log(a^100, a, ord=oo, bounds=(1, 500))
883+
100
884+
867885
TESTS:
868886
869887
Random testing::
@@ -917,6 +935,7 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
917935
lb, ub = map(integer_ring.ZZ, bounds)
918936
if (op is None or identity is None or inverse is None or ord is None) and operation not in addition_names + multiplication_names:
919937
raise ValueError("ord, op, identity, and inverse must all be specified for this operation")
938+
from sage.rings.infinity import Infinity
920939
if ord is None:
921940
if operation in multiplication_names:
922941
try:
@@ -928,11 +947,10 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
928947
ord = base.additive_order()
929948
except Exception:
930949
ord = base.order()
931-
else:
950+
elif ord != Infinity:
932951
ord = integer_ring.ZZ(ord)
933952
try:
934-
from sage.rings.infinity import Infinity
935-
if ord == +Infinity:
953+
if ord == Infinity:
936954
return bsgs(base, a, bounds, identity=identity, inverse=inverse, op=op, operation=operation)
937955
if base == power(base, 0) and a != base:
938956
raise ValueError

0 commit comments

Comments
 (0)