# Two meanings of modulo? [duplicate]

In the following statement, it seems "mod" serves two separate functions.

$$(ab)\textrm{ mod } n \equiv \big((a\textrm{ mod } n)\cdot(b\textrm{ mod } n)\big)\textrm{ mod } n$$

• There is the use as a qualification of a statement about equivalence, as in the final "mod n": "these two expressions (LHS and RHS of $$\equiv$$) are equivalent mod n."
• There is the use as an operator applied to a single expression, as in all the other occurences.

Is there any ambiguity here? Any potential mathematical hazards that can arise from not being clear about the distinction?

EDIT - thinking on, I can see that the final "mod n" could be interpreted in either sense...)

• There's a difference between the way mathematicians and programmers use "mod". The former refers to an equivalence class, the latter to a remainder (the least positive member of the equivalence class). Both usages are fine, but the difference between them can cause some confusion.
– lulu
Oct 23, 2021 at 15:49
• So what about the mixture in the statement in the question - is it correct by the standards of either camp? Oct 23, 2021 at 15:52
• The statement I would prefer is that if $a\equiv A \pmod n$ and $b\equiv B\pmod n$ then $ab\equiv AB \pmod n$. good enough?
– lulu
Oct 23, 2021 at 15:54
• Nevertheless, your statement is also correct. (Follows by Lulu's comment.) Oct 23, 2021 at 16:04
• Wow, that was impressive for you to accurately locate and articulate that difference! Oct 23, 2021 at 16:14

## 1 Answer

It is customary to write the equivalence relation as $$a \equiv b \pmod m$$, with parenthesis around $$\bmod m$$ and a bigger space between $$a \equiv b$$ and $$\bmod m$$.

Even $$\TeX$$ (and $$\LaTeX$$ and MathJax) do that with the appropiate commands:

The equivalence relation a \equiv b \pmod n renders as $$a \equiv b \pmod n$$

The binary operation a = b \bmod n renders as $$a = b \bmod n$$

That usually suffices to avoid ambiguity since it wouldn't make sense to put parenthesis like that in the $$\bmod$$ operation.

The expression you have probably should be written like

$$(a b) \bmod n \equiv ((a \bmod n)\cdot(b \bmod n)) \pmod n$$

if the intention is that the three first $$\bmod$$'s denote the operation and the last one denotes the equivalence relation or

$$(a b) \bmod n = ((a \bmod n)\cdot(b \bmod n)) \bmod n$$

if the intention is that the four $$\bmod$$'s denote the operation (notice that in this case, one should use $$=$$ instead of $$\equiv$$).