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 @@
`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 @@
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():
yyyyx4 marked this conversation as resolved.
Show resolved Hide resolved
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
yyyyx4 marked this conversation as resolved.
Show resolved Hide resolved


def CRT_vectors(X, moduli):
Expand Down
Loading