Skip to content

Commit

Permalink
throw ValueError instead of TypeError when logarithm doesn't exist
Browse files Browse the repository at this point in the history
...because attempting to run this with unhashable elements throws the
same exception, which can cause confusion in higher-level algorithms.
  • Loading branch information
yyyyx4 committed Jan 27, 2024
1 parent 3dd953c commit fecafde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/sage/groups/additive_abelian/additive_abelian_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def discrete_log(self, x, gens=None):
sage: G.discrete_log(V([6, 4]))
Traceback (most recent call last):
...
TypeError: Not in group
ValueError: not in group
::
Expand Down Expand Up @@ -617,7 +617,7 @@ def _base(j, k, c):
if key in tab:
return tab[key] + vector(y)

raise TypeError('Not in group')
raise ValueError('not in group')

def _rec(j, k, c):

Expand Down Expand Up @@ -744,7 +744,7 @@ def _expand_basis_pgroup(p, alphas, vals, beta, h, rel):
beta_q *= p
try:
e = _discrete_log_pgroup(p, vals, alphas, -beta_q)
except TypeError:
except ValueError:

Check warning on line 747 in src/sage/groups/additive_abelian/additive_abelian_wrapper.py

View check run for this annotation

Codecov / codecov/patch

src/sage/groups/additive_abelian/additive_abelian_wrapper.py#L747

Added line #L747 was not covered by tests
continue
# step 6
_expand_basis_pgroup(p, alphas, vals, beta, h, list(e) + [p**v])
Expand Down Expand Up @@ -815,7 +815,7 @@ def basis_from_generators(gens, ords=None):
beta, ord_beta = pgens.pop()
try:
dlog = _discrete_log_pgroup(p, vals, alphas, beta)
except TypeError:
except ValueError:
pass
else:
continue
Expand All @@ -828,7 +828,7 @@ def basis_from_generators(gens, ords=None):
# assert beta_q == beta * p**v
try:
e = _discrete_log_pgroup(p, vals, alphas, -beta_q)
except TypeError:
except ValueError:
continue
_expand_basis_pgroup(p, alphas, vals, beta, val_beta, list(e) + [p**v])
# assert all(a.order() == p**v for a,v in zip(alphas, vals))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/fg_pid/fgp_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def __contains__(self, x):
try:
self(x)
return True
except TypeError:
except ValueError:
return False

def submodule(self, x):
Expand Down

0 comments on commit fecafde

Please sign in to comment.