Skip to content

Commit 75ec6cc

Browse files
committed
Simplify group generic algorithm
1 parent 94fe540 commit 75ec6cc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/sage/groups/generic.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,11 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
951951
ord = integer_ring.ZZ(ord)
952952
try:
953953
if ord == Infinity:
954-
return bsgs(base, a, bounds, identity=identity, inverse=inverse, op=op, operation=operation)
954+
if algorithm == 'bsgs':
955+
return bsgs(base, a, bounds, identity=identity, inverse=inverse, op=op, operation=operation)
956+
else:
957+
assert algorithm == 'lambda'
958+
return discrete_log_lambda(base, a, bounds, inverse=inverse, identity=identity, op=op, operation=operation)
955959
if base == power(base, 0) and a != base:
956960
raise ValueError
957961
f = ord.factor()
@@ -982,7 +986,8 @@ def discrete_log(a, base, ord=None, bounds=None, operation='*', identity=None, i
982986
c = bsgs(gamma, h, (0, temp_bound), inverse=inverse, identity=identity, op=op, operation=operation)
983987
elif algorithm == 'rho':
984988
c = discrete_log_rho(h, gamma, ord=pi, inverse=inverse, identity=identity, op=op, operation=operation)
985-
elif algorithm == 'lambda':
989+
else:
990+
assert algorithm == 'lambda'
986991
c = discrete_log_lambda(h, gamma, (0, temp_bound), inverse=inverse, identity=identity, op=op, operation=operation)
987992
l[i] += c * (pi**j)
988993
running_bound //= pi
@@ -1100,14 +1105,14 @@ def discrete_log_lambda(a, base, bounds, operation='*', identity=None, inverse=N
11001105
c += r
11011106
if mut:
11021107
H.set_immutable()
1103-
mem = {H}
1108+
mem = H
11041109
# second random walk
11051110
H = a
11061111
d = 0
11071112
while c - d >= lb:
11081113
if mut:
11091114
H.set_immutable()
1110-
if ub >= c - d and H in mem:
1115+
if ub >= c - d and H == mem:
11111116
return c - d
11121117
r, e = M[hash_function(H) % k]
11131118
H = mult(H, e)

0 commit comments

Comments
 (0)