Do the parenthesis around modulo matter

Mod is not an operation$^1$!

This is a cause of confusion for many students I have started adopting a new notation to clarify this $$17\hspace {.1 cm}\overset{\displaystyle \equiv}{\tiny mod 5} \hspace {.1 cm} 103 $$ The point is that $\mod 5$ is something that modifies the equivalency and not one side or the other. It is no operation. The numbers $17$ and $103$ are in the same category if we are considering what their remainder is after we divide by $5$.

$1:$ Except when it is... The confusion here is that mod IS an operation whenever you talk to a computer scientist/programmer. It's just not an operation in the community of mathematicians.

To confuse the matter: Mathematicians also explore a mapping which is used in a slightly different way from these computer scientists/programmers. If you are interested you can read the comment thread below and I invite you to inquire.


Parentheses disambiguate closely related notations when used as in the first expression below

$$\begin{align} &a\, =\, b\bmod n\\[.2em] {\rm is\ it}\ \ \ \ &a = (b\bmod n)\ \ \ \ \ {\rm i.e.}\ \ \ a\, =\, {\rm remainder\ of}\ \ b\div n\\[.2em] {\rm or\ is\ it}\ \ \ \ &a = b\!\!\!\pmod{\! n} \ \ \ \ {\rm i.e.}\ \ \ n\ \ {\rm divides}\ \ a-b \end{align}$$

Insisting on the parentheses in the final expression removes the ambiguity. Some authors also believe the ambiguity is removed by using a congruence vs. equal sign, i.e. $\,a\equiv b\mod n\, $ but, alas, beginners often wrongly interpret this in operational form (2nd form above), esp. if it written with less whitespace $\,a\equiv b\bmod n.\,$ Some authors never use the operational form, which does eliminate the ambiguity (but may still prove confusing for beginners who use multiple textbooks).

Remark $ $ Despite some claims to the contrary, it is worth emphasis that the operational form of $\!\bmod\!$ is widely used in mathematics, e.g. in number theory and algebra, e.g. it plays a crucial role in the descent step in the Euclidean gcd algorithm

$$ |a|\ge |b|\,\Rightarrow\, \gcd(a,b) = \gcd(a\bmod b,\, b)$$

Similarly many (inductive) proofs and (recursive) algorithms in number theory and algebra are governed by an analogous (Euclidean) descent (via division with remainder). As such, it proves convenient to have notation for this ubiquitous remainder descent operation.

Also the notation enables (operational) expression of fundamental laws that might otherwise be greatly obfuscated. A nice example of this is the $\!\bmod\!$ Distributive Law

$$ ab\bmod ac\, =\, a(b\bmod c)$$

This can be viewed as an operational reformulation of CRT = Chinese Remainder Theorem. Being operational it often greatly simplifies computations. Here's a simple example from here

$$ 3^{\large 1+2n}\!\bmod 12\, =\, 3(3^{\large 2n}\!\bmod 4)\, =\, 3((-1)^{\large 2n}\!\bmod 4)\, =\, 3$$

Below we give an example using polynomial congruences $ $ (equivalent to $ $ Lagrange interpolation). If $\,f\,$ satisfies the congruences $\ \overbrace{f\equiv 0\pmod{x\!+\!2}}^{\large f(-2)\ =\ 0\ \ \ \ \ \ }\,\ $ and $\,\ \overbrace{f\equiv\color{#0a0}8\pmod{x\!-\!2}}^{\large f(2)\ =\ \color{#0a0}8\phantom{|^{|}}\ }\ $ then

$\qquad\ f\bmod x^2\!-\!4\,$ $=\, (x\!+\!2)\Bigg[\dfrac{f}{x\!+\!2}\bmod x\!-\!\color{#c00}2\Bigg]$ $ =\, \underbrace{(x\!+\!2)\left[\dfrac{f(\color{#c00}{2})}{\color{#c00}2\!+\!2}\right] =\, 2(x\!+\!2)}_{\large f\bmod x-\color{#c00}2\,\ =\,\ f(\color{#c00}{2})\,\,\ =\,\ \color{#0a0}8}$

Generally when we perform nontrivial calculation it often proves convenient to have notations for normal forms (such as canonical representatives of equivalence classes in quotient objects).