What is the order of operations for testing congruency mod(x)

207 Views Asked by At

I'm reading the Wiki page on congruence relation and am trying to figure out

"Do I take the mod(x) before or after the addition or multiplication operation"

BTW - When I tried to figure this out on my own, I realized that n in mod n would be congruent all it's factors, but if n was prime (say 3 or 5) I wasn't sure of the order of operations for doing simple algebra.

Can someone fill in the blanks of what a sample a` (prime) value would be on the right hand side of the congruent sign?

1

There are 1 best solutions below

5
On BEST ANSWER

The $a$ in the equation $$a\equiv b \pmod n\tag{*}$$ is simply the integer $a$. The congruence above establishes a relationship between the forms of $a$ and $b$. We say that two integers are congruent to each other modulo $n$ precisely when $n\mid a-b$. From this, it follows that for a fixed integer $a$, we can write the set of all integers congruent to $a$ modulo $n$ as $$[a]_n = \{a,\ a\pm n,\ a\pm 2n,\ a\pm 3n,\ \cdots\}$$ The set $[a]_n$ is called the congruence class of $a$ modulo $n$. The total number of distinct congruence classes is finite. In fact, $$\{[0]_n,\ [1]_n,\ \cdots,\ [n-1]_n\}\tag{**}$$ forms the complete set of congruence classes.

In this language, equation $*$ says that $a$ and $b$ belong in the same congruence class. Modular arithmetic is really an algebraic system working with congruence classes of integers rather than the integers themselves. When working with equations in modular arithmetic, we are therefore free to replace any integer with any member of its congruence class. Since any integer necessarily belongs to one of the congruence classes in equation $**$, we typically pick one of the integers between $0$ and $n-1$ as a representative of the congruence class. This representative is the remainder of the number when divided by $n$ or the value of the modulo operator $a \% n$.

In practice, we always reduce any formula in terms of these (or other convenient) representatives.

Let's look at an example with some arbitrary numbers. We know that $849 \equiv 9 \pmod {10}$ and $3483 \equiv 3 \pmod {10}$ and so we are free to replace $849$ by $9$ and $3483$ by $3$ in any equations where they occur. For example so we can say that $$849 + 3483 \equiv 9 + 3 \equiv 12 \equiv 2\pmod{10}$$ or that $$849\times 3483 \equiv 9\times 3 \equiv 27 \equiv 7\pmod{10}$$ When viewed in this manner, the question of "order" disappears. It doesn't matter whether you add first and then reduce or reduce first and then add because the underlying congruence classes do not change but rather your choice of integers representing them.