From d1d7a594133e516b2e6baffa205932b421832fb8 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Mon, 16 Jan 2023 09:05:55 -0500 Subject: [PATCH 1/6] Add CRT two moduli solution --- src/algebra/chinese-remainder-theorem.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index 07d512ff9..de7a60266 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -37,6 +37,27 @@ $$\begin{align} (As above, assume that $m = m_1 m_2 \cdots m_k$ and $m_i$ are pairwise coprime). +## Solution for Two Moduli + +Consider a system of two equations for coprime $m_1, m_2$: + +$$ +\begin{align} + a &\equiv a_1 \pmod{m_1} \\ + a &\equiv a_2 \pmod{m_2} \\ +\end{align} +$$ + +We want to find a solution for $a \pmod{m_1 m_2}$. Using the [Extended Euclidean Algorithm](extended-euclid-algorithm.md) we can find Bézout coefficients $n_1, n_2$ such that + +$$n_1 m_1 + n_2 m_2 = 1$$ + +Then a solution will be + +$$a = a_1 n_2 m_2 + a_2 n_1 m_1$$ + +We can easily verify $a = a_1 (1 - n_1 m_1) + a_2 n_1 m_1 \equiv a_1 \pmod{m_1}$ and vice versa. + ## Garner's Algorithm Another consequence of the CRT is that we can represent big numbers using an array of small integers. For example, let $p$ be the product of the first $1000$ primes. From calculations we can see that $p$ has around $3000$ digits. From a82f4450adf9ebc0868ff7a3de0a9aa93132a143 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:01:29 -0500 Subject: [PATCH 2/6] Add CRT inductive solution --- src/algebra/chinese-remainder-theorem.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index de7a60266..061d39d3c 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -58,6 +58,13 @@ $$a = a_1 n_2 m_2 + a_2 n_1 m_1$$ We can easily verify $a = a_1 (1 - n_1 m_1) + a_2 n_1 m_1 \equiv a_1 \pmod{m_1}$ and vice versa. +## Solution for General Case + +### Inductive Solution + +As $m_1 m_2$ is coprime to $m_3$, we can inductively repeatedly apply the solution for two moduli for any number of moduli. For example, combine $a \equiv b_2 \pmod{m_1 m_2}$ and $a \equiv a_3 \pmod{m_3}$ to get $a \equiv b_3 \pmod{m_1 m_2 m_3}$, etc. + + ## Garner's Algorithm Another consequence of the CRT is that we can represent big numbers using an array of small integers. For example, let $p$ be the product of the first $1000$ primes. From calculations we can see that $p$ has around $3000$ digits. From 94eda352049065231959e0bac13f9083081bdb94 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:28:49 -0500 Subject: [PATCH 3/6] Add CRT direct construction --- src/algebra/chinese-remainder-theorem.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index 061d39d3c..104536168 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -64,6 +64,19 @@ We can easily verify $a = a_1 (1 - n_1 m_1) + a_2 n_1 m_1 \equiv a_1 \pmod{m_1}$ As $m_1 m_2$ is coprime to $m_3$, we can inductively repeatedly apply the solution for two moduli for any number of moduli. For example, combine $a \equiv b_2 \pmod{m_1 m_2}$ and $a \equiv a_3 \pmod{m_3}$ to get $a \equiv b_3 \pmod{m_1 m_2 m_3}$, etc. +### Direct Construction + +A direct construction similar to Lagrange interpolation is possible. Let $M_i = \prod_{i \neq j} m_j$, the product of all moduli but $m_i$. Again with the Extended Euclidean algorithm we can find $N_i, n_i$ such that + +$$N_i M_i + n_i m_i = 1$$ + +Then a solution to the system of congruences is + +$$a = \sum_{i=1}^k a_i N_i M_i$$ + +Observe $M_i$ is a multiple of $m_j$ for $i \neq j$, and + +$$a \equiv a_i N_i M_i \equiv a_i (1 - n_i m_i) \equiv a_i \pmod{m_i}$$ ## Garner's Algorithm From 52e3679a2e0ca9bf3d05e042f6e484fe1c2c85a3 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:33:24 -0500 Subject: [PATCH 4/6] =?UTF-8?q?Add=20CRT=20relationship=20between=20B?= =?UTF-8?q?=C3=A9zout=20and=20inverses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/algebra/chinese-remainder-theorem.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index 104536168..d1863db98 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -52,6 +52,8 @@ We want to find a solution for $a \pmod{m_1 m_2}$. Using the [Extended Euclidean $$n_1 m_1 + n_2 m_2 = 1$$ +Equivalently, $n_1 m_1 \equiv 1 \pmod{m_2}$ so $n_1 \equiv m_1^{-1} \pmod{m_2}$, and vice versa $n_2 \equiv m_2^{-1} \pmod{m_1}$. + Then a solution will be $$a = a_1 n_2 m_2 + a_2 n_1 m_1$$ From 0a38326ef42803f9097a157ee5c5fb01e6232978 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Mon, 16 Jan 2023 16:36:23 -0500 Subject: [PATCH 5/6] Fix vdots in system of equations --- src/algebra/chinese-remainder-theorem.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index d1863db98..4535a98a1 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -15,7 +15,7 @@ Let $m = m_1 \cdot m_2 \cdots m_k$, where $m_i$ are pairwise coprime. In additio $$\begin{align} a &\equiv a_1 \pmod{m_1} \\ a &\equiv a_2 \pmod{m_2} \\ - &\ldots \\ + & \vdots \\ a &\equiv a_k \pmod{m_k} \end{align}$$ @@ -31,7 +31,7 @@ is equivalent to the system of equations $$\begin{align} x &\equiv a_1 \pmod{m_1} \\ - &\ldots \\ + &\vdots \\ x &\equiv a_k \pmod{m_k} \end{align}$$ From 59fa07519a5bc8499b784b56e5923b34bdfdfa74 Mon Sep 17 00:00:00 2001 From: jxu <7989982+jxu@users.noreply.github.com> Date: Tue, 17 Jan 2023 18:40:58 -0500 Subject: [PATCH 6/6] Add CRT general solution note about inverses https://github.com/cp-algorithms/cp-algorithms/issues/1008#issuecomment-1383044632 --- src/algebra/chinese-remainder-theorem.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/algebra/chinese-remainder-theorem.md b/src/algebra/chinese-remainder-theorem.md index 4535a98a1..49ca3af21 100644 --- a/src/algebra/chinese-remainder-theorem.md +++ b/src/algebra/chinese-remainder-theorem.md @@ -76,6 +76,10 @@ Then a solution to the system of congruences is $$a = \sum_{i=1}^k a_i N_i M_i$$ +Again as $N_i \equiv M_i^{-1} \pmod{m_i}$, the solution is equivalent to + +$$a = \sum_{i=1}^k a_i M_i (M_i^{-1} \mod{m_i})$$ + Observe $M_i$ is a multiple of $m_j$ for $i \neq j$, and $$a \equiv a_i N_i M_i \equiv a_i (1 - n_i m_i) \equiv a_i \pmod{m_i}$$ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy