ELI5: How does a congruence modulo work?
elementary number theory - Congruent Modulo $n$: definition - Mathematics Stack Exchange
math mode - How to write the congruence modulo n symbol? - TeX - LaTeX Stack Exchange
[Modular Arithmetic] Struggling with proof regarding congruence relation
Videos
I think I understand the basics of the modulo function. Assuming modulo 3 when counting up you'd go 0 > 1 > 2 > 0 ...
But then I see this equation:
a ≡ b (mod n)
And have trouble understanding it. I'm pretty sure it means that a and b have a congruent relationship when a modulo function of n is applied to them. But I'm not sure if this is correct, and what a congruent relationship is.
Thanks!
Mathematically, congruence modulo is an equivalence relation. We define:
Equivalently: When working in , any number
is congruent
to an integer
if there exists an integer
for which
.
Now, let's compare the "discrepancies" in the equivalences you note (which are, in fact, all true):
- Note, indeed, that
since
- And again, note that
since
It is often customary to express equivalence modulo , by choosing
in
to be such that
. But this choice is simply a representative of all the numbers which belong to the same equivalence class, denoted
,
:
E.g. If , then one of the following holds:
All the equations you wrote up there are correct. for any integer
. Computer scientists tend to say that the 'modulus operation' returns the smallest integer between
and what you're modding out by. Mathematicians take a slightly higher viewpoint, saying two numbers are considered the same if their difference is divisible by what you're modding out by.
But I would expect a different notation. Mathematically, . In computer science, I would expect to see
, or even
. (In particular, none of that equivalence relation / only up to equivalence stuff).
There are several ways, choose the one you prefer.
\documentclass{article}
\usepackage{amsmath}
\renewcommand{\arraystretch}{1.5} % just to make the lines spread out
\begin{document}
\begin{tabular}{lll}
\verb|$a\equiv b \pmod{n}$| & $a\equiv b \pmod{n}$ \\
\verb|$a\equiv b \mod{n}$| & $a\equiv b \mod{n}$ \\
\verb|$a\equiv b \pod{n}$| & $a\equiv b \pod{n}$ \\
\verb|$a\equiv b \bmod{n}$| & $a\equiv b \bmod{n}$ & (wrong)
\end{tabular}
\end{document}

Don't forget the braces: try a\equiv b \pmod 11 or a\equiv b \pmod pq and see why.
The last one is marked “wrong”, because the usage is improper: \bmod should be used for the “modulo” binary operation (the one that is often denoted by % in computing).
Use pmod n. It is known to work.