Skip to content

Commit

Permalink
check coprimality of moduli in CRT_basis()
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyx4 committed Nov 10, 2023
1 parent ebef87a commit 67ef84e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3584,10 +3584,6 @@ def CRT_basis(moduli):
`a_i` is congruent to 1 modulo `m_i` and to 0 modulo `m_j` for
`j\not=i`.
.. note::
The pairwise coprimality of the input is not checked.
EXAMPLES::
sage: a1 = ZZ(mod(42,5))
Expand All @@ -3610,7 +3606,14 @@ def CRT_basis(moduli):
if n == 0:
return []
M = prod(moduli)
return [((xgcd(m,M//m)[2])*(M//m)) % M for m in moduli]
cs = []
for m in moduli:
Mm = M//m
d,_,v = xgcd(m,Mm)
if not d.is_one():
raise ValueError('moduli must be coprime')

Check warning on line 3614 in src/sage/arith/misc.py

View check run for this annotation

Codecov / codecov/patch

src/sage/arith/misc.py#L3614

Added line #L3614 was not covered by tests
cs.append(v * Mm % M)
return cs


def CRT_vectors(X, moduli):
Expand Down

0 comments on commit 67ef84e

Please sign in to comment.