0

While messing with modulus in python,

lomod = [num % 27 for num in [i * 8 for i in range(27)]]

print('Unsorted:', lomod)

lomod.sort()

print('Sorted:', lomod)

I found something interesting.

For $a,b\in\mathbb{Z}$, and $a,b$ are relatively prime, and $0 \le x < b$, $A =ax\mod b$, then $A = \{0,1...,b-1\}$ with no repeating integers.

For example in the case of $a = 8, b=27$, for values of $x$ such that $0\le x < 27$

$A =8x\mod27$ , then

$A =$ [0, 8, 16, 24, 5, 13, 21, 2, 10, 18, 26, 7, 15, 23, 4, 12, 20, 1, 9, 17, 25, 6, 14, 22, 3, 11, 19]

sorted,

$A =$ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]

Which contains all values from $0$ to $26$ once.

However, I don't know how to prove this generally. Is there anyone that can help me?

Bill Dubuque
  • 272,048

1 Answers1

0

Let $x_1, x_2$ be integers, and assume they have the same remainder $r = ax_1 \bmod b = ax_2\bmod b$.

Then for some integer quotients $q_1, q_2$,

$$\begin{align*} ax_1 &= bq_1+r\\ ax_2 &= bq_2 + r\\ ax_1 - ax_2 &= bq_1 - bq_2\\ a(x_1 - x_2) &= b(q_1 - q_2)\\ \end{align*}$$

Since $a$ and $b$ are relatively prime, they share no factors. But the right hand side is a multiple of $b$, so $x_1-x_2$ is also a multiple of $b$.

If the range of $x_1$ and $x_2$ is between $0$ and $b-1$ inclusive, then

$$\begin{align*} -(b-1) \le x_1-x_2 &\le b-1\\ x_1 - x_2 &= 0b\\ x_1 &= x_2. \end{align*}$$

Or restating in contraposition, different $x_1 \ne x_2$ (in that range) lead to different remainders $ax_1\bmod b \ne ax_2\bmod b$.

peterwhy
  • 22,256
  • so basically you are proving that since x1 and x2 have to be the same for its remainder to be the same, there are no two x values that have the same remainder? – h4ppyturt1e Dec 06 '20 at 02:33
  • @h4ppyturt1e Right. Then there are $b$ different $x$s in range(b), and so there are $b$ different remainders. – peterwhy Dec 06 '20 at 02:36
  • when you say But the right hand side is a multiple of b, so x1-x2 is also a multiple of b., how did you come to that conclusion? Is it because a is a prime and therefore x1-x2 has to be the one that has a multiple of 27 in itself? – h4ppyturt1e Dec 06 '20 at 02:42
  • $a$ (e.g. 8) is not necessary prime, but is relatively prime to $b$. But otherwise you're right, that since $a$ has no factors of $b$, all the factors of $b$ comes from $(x_1-x_2)$. For a proof, see Euclid's lemma. – peterwhy Dec 06 '20 at 02:54
  • Please strive not to add more dupe answers to FAQs – Bill Dubuque Dec 06 '20 at 04:16