Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check coprimality of moduli in CRT_basis() #36457

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
cs.append((v * Mm) % M)
return cs


def CRT_vectors(X, moduli):
Expand Down