From 9a4a464ce889e636c005c9dfc231655979c794e9 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Thu, 12 Oct 2023 12:03:38 +0200 Subject: [PATCH] check coprimality of moduli in CRT_basis() --- src/sage/arith/misc.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index aa0174580a1..5d3ef49f7c5 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -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)) @@ -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):