NOTES | HOME
$$ \newcommand{\RR}{\mathbb{R}} \newcommand{\GG}{\mathbb{G}} \newcommand{\PP}{\mathbb{P}} \newcommand{\PS}{\mathcal{P}} \newcommand{\SS}{\mathbb{S}} \newcommand{\NN}{\mathbb{N}} \newcommand{\ZZ}{\mathbb{Z}} \newcommand{\CC}{\mathbb{C}} \newcommand{\HH}{\mathbb{H}} \newcommand{\ones}{\mathbb{1\hspace{-0.4em}1}} \newcommand{\alg}[1]{\mathfrak{#1}} \newcommand{\mat}[1]{ \begin{pmatrix} #1 \end{pmatrix} } \renewcommand{\bar}{\overline} \renewcommand{\hat}{\widehat} \renewcommand{\tilde}{\widetilde} \newcommand{\inv}[1]{ {#1}^{-1} } \newcommand{\eqdef}{\overset{\text{def}}=} \newcommand{\block}[1]{\left(#1\right)} \newcommand{\set}[1]{\left\{#1\right\}} \newcommand{\abs}[1]{\left|#1\right|} \newcommand{\trace}[1]{\mathrm{tr}\block{#1}} \newcommand{\norm}[1]{ \left\| #1 \right\| } \newcommand{\argmin}[1]{ \underset{#1}{\mathrm{argmin}} } \newcommand{\argmax}[1]{ \underset{#1}{\mathrm{argmax}} } \newcommand{\st}{\ \mathrm{s.t.}\ } \newcommand{\sign}[1]{\mathrm{sign}\block{#1}} \newcommand{\half}{\frac{1}{2}} \newcommand{\inner}[1]{\langle #1 \rangle} \newcommand{\dd}{\mathrm{d}} \newcommand{\ddd}[2]{\frac{\partial #1}{\partial #2} } \newcommand{\db}{\dd^b} \newcommand{\ds}{\dd^s} \newcommand{\dL}{\dd_L} \newcommand{\dR}{\dd_R} \newcommand{\Ad}{\mathrm{Ad}} \newcommand{\ad}{\mathrm{ad}} \newcommand{\LL}{\mathcal{L}} \newcommand{\Krylov}{\mathcal{K}} \newcommand{\Span}[1]{\mathrm{Span}\block{#1}} \newcommand{\diag}{\mathrm{diag}} \newcommand{\tr}{\mathrm{tr}} \newcommand{\sinc}{\mathrm{sinc}} \newcommand{\cat}[1]{\mathcal{#1}} \newcommand{\Ob}[1]{\mathrm{Ob}\block{\cat{#1}}} \newcommand{\Hom}[1]{\mathrm{Hom}\block{\cat{#1}}} \newcommand{\op}[1]{\cat{#1}^{op}} \newcommand{\hom}[2]{\cat{#1}\block{#2}} \newcommand{\id}{\mathrm{id}} \newcommand{\Set}{\mathbb{Set}} \newcommand{\Cat}{\mathbb{Cat}} \newcommand{\Hask}{\mathbb{Hask}} \newcommand{\lim}{\mathrm{lim}\ } \newcommand{\funcat}[1]{\left[\cat{#1}\right]} \newcommand{\natsq}[6]{ \begin{matrix} & #2\block{#4} & \overset{#2\block{#6}}\longrightarrow & #2\block{#5} & \\ {#1}_{#4} \hspace{-1.5em} &\downarrow & & \downarrow & \hspace{-1.5em} {#1}_{#5}\\ & #3\block{#4} & \underset{#3\block{#6}}\longrightarrow & #3\block{#5} & \\ \end{matrix} } \newcommand{\comtri}[6]{ \begin{matrix} #1 & \overset{#4}\longrightarrow & #2 & \\ #6 \hspace{-1em} & \searrow & \downarrow & \hspace{-1em} #5 \\ & & #3 & \end{matrix} } \newcommand{\natism}[6]{ \begin{matrix} & #2\block{#4} & \overset{#2\block{#6}}\longrightarrow & #2\block{#5} & \\ {#1}_{#4} \hspace{-1.5em} &\downarrow \uparrow & & \downarrow \uparrow & \hspace{-1.5em} {#1}_{#5}\\ & #3\block{#4} & \underset{#3\block{#6}}\longrightarrow & #3\block{#5} & \\ \end{matrix} } \newcommand{\cone}[1]{\mathcal{#1}} $$

Modular Arithmetic

A few results in modular arithmetic.

Greatest Common Divisors

For all integers \(a, b \in \ZZ\) there exists a unique positive integer \(d = \gcd(a, b) \in \NN\) such that:

Note: “greatest” is in the sense of the order relationship “is divisible by”.

Euclid’s Algorithm

Given the Eulidean division \(a = b q + r, 0 \leq r < b\), one can easily show that \(\gcd(a, b) = \gcd(b, r)\) by showing that \(\gcd(a, b)\) divides \(\gcd(b, r)\) and conversely. This gives a simple algorithm for computing \(\gcd(a, b)\) using successive Euclidean divisions:

\[r_{k-1} = r_k q_{k+1} + r_{k+1},\ 0\leq r_{k+1} < r_k\]

The last non-zero remainder is the GCD.

Bezout’s Theorem

Let \(a, b \in \ZZ\) be two integers, then the following holds:

\[d = \gcd(a, b) \Rightarrow \exists\, x, y \in \ZZ \mid ax + by = d\]

Let \(S =\left\{ ax + by \mid x, y \in \ZZ \right\} = a\ZZ + b\ZZ\) and \(c\) a common divisor of \(a, b\). Then for any \(n \in S\), \(c\) divides \(n\):

\[n = ax + by = pcx + qcy = c(px + qy)\]

Now, all we need to find is an element of \(S\) that divides \(a, b\) to prove the result. Let us consider the smallest positive integer \(d > 0 \in S\) and the Euclidean division of \(n \in S\) by \(d\):

\[(a x' + b y') = n = qd + r\]

We may rewrite \(r\) as:

\[r = ax' + by' - qd = a(x' - qx) + b(y' - qy)\]

so that \(r \in S\). By the definition of \(d\), we are left with the only possibility \(r = 0\), otherwise we would have found a smaller positive element in \(S\). Therefore, \(d\) divides \(n\) for all \(n \in S\). In particular, \(a, b \in S\) so \(d\) is a common divisor of \(a, b\) that lies in \(S\), which concludes the proof.

Note: we just shown that \(S = a\ZZ + b\ZZ = \gcd(a, b)\ZZ\). This shows that converse of the theorem is false, but that the following holds: if \(a x + by = d\), then \(\gcd(a, b)\) divides \(d\).

Extended Euclid’s Algorithm

Rather than discarding the \(q_k\) in Euclid’s algorithm, one can exploit them to construct Bezout’s decomposition. The \(k\)-th iteration is given by:

\[r_{k-1} = r_k q_{k+1} + r_{k+1},\ 0\leq r_{k+1} < r_k\]

Now, assuming we have the decomposition \(r_k = s_k a + t_k b\), we obtain the new decomposition for \(r_{k+1}\) as:

\[r_{k+1} = r_{k-1} - r_k q_{k+1} = a\underbrace{\block{s_{k-1} - s_k q_{k+1}}}_{s_{k+1}} + b \underbrace{\block{t_{k-1} - t_k q_{k+1}}}_{t_{k+1}}\]

Euclid’s algorithm starts with \(s_0 = 1, t_0 = 0, s_1 = 0, t_1 = 1\).

Coprime Integers

Two integers \(a, b \in \ZZ\) are said coprimes if and only if \(\gcd(a, b) = 1\). In this case, Bezout’s theorem works both ways: \(a, b\) are coprimes if and only if there exists integers \(x, y\) such that \(ax + by = 1\).

The Bezout decomposition gives the modular inverses: \(y = \inv{b} \mod a\) and \(x = \inv{a} \mod b\)

Chinese Remainder Theorem

Let \(\block{n_i}_{i\leq k}\) be \(k\) pairwise coprime integers, then there exists an integer \(x\) such that, for any \(k\) integers \(\block{a_i}_{i\leq k}\), the following holds:

\[x = a_i \mod n_i,\ \forall\, i \leq k\]

Moreover, \(x\) is unique modulo \(n = \prod_i n_i\). In other words, given remainders modulo coprime integers, it is possible to “reconstruct” the initial integer \(x\).

The reconstruction goes as follows: let us consider \(\hat{n}_i = \frac{n}{n_i}\), then we have \(\gcd\block{n_i, \hat{n_i}} = 1\) and by Bezout’s theorem, there exists \(u_i, v_i\) such that:

\[1 = u_i n_i + \underbrace{v_i \hat{n}_i}_{e_i}\]

So we have \(e_i = 1 \mod n_i\), and also \(e_i = 0 \mod n_j\) for \(j \neq i\) since \(n_j\) appears in \(\hat{n}_i\)1. Finally, the \(e_i\) provide a basis for expressing the solution as:

\[x = \sum_i a_i e_i\]

TODO

Notes

  1. Alternatively, one may consider \(e_i = \hat{n}_i^{-1} \hat{n}_i\) where the inverse is taken modulo \(n_i\).