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 Oct 12, 2023
1 parent 2f1a76d commit 06955d9
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 @@ -3579,10 +3579,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 @@ -3605,7 +3601,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 3609 in src/sage/arith/misc.py

View check run for this annotation

Codecov / codecov/patch

src/sage/arith/misc.py#L3609

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


def CRT_vectors(X, moduli):
Expand Down

0 comments on commit 06955d9

Please sign in to comment.