- #1
fog37
- 1,569
- 108
- TL;DR Summary
- Understand if Modulo and Modulus in math and computer programming are related and how...
Hello,
I an clear on how the modulo operator ##%##, also called the remainder operator, is used in programming. It gives the remainder of the integer division. For example, ##5 % 2 = 1## because the divisor 2 fits 2 wholly times into the dividend 5 leaving behind a reminder of 1.
## 6% 3 =0## because the remainder is 0.
However, when learning about modular arithmetic in math, I learned that modulus ##N## means that only the integer numbers from ##0## to ##N-1## are available. For example, modulus ##5## means that all the possible numbers we can work with are ##0,1,2,3,4##. Any other number ##X## outside this range wraps up back into this range of numbers as a congruent number to one of numbers in the range.
A simple hack is to add or subtract from the number ##X## an integer number of the modulus ##N## until we get back into the range ##0,1,2,3,4##. For example, 10 (modulus 5) is congruent to 10-(2-5)=0 (modulus 5).
Example: ##10## and ##0## are equivalent/congruent numbers if considered modulus 5: $$ 10 \equiv 0 mod(5)$$. There are two ways to assess if two numbers are congruent mod ##N##:
a) if divided by the modulus ##N##, the numbers give the same reminder. Ex: 10/5 gives reminder 0 and 0/5 gives reminder 0 as well.
b) if the difference between the two numbers ##10## and ##0## is equal to an integer multiple of the modulus ##N##. Ex: 10-0=2(5).
All that said, I believe that in computer programming, the use of the modulo operator ##%## really gives the congruent number that is in the range of numbers of the modulus. For example, 5%2 means that we are working with modulus 2 so the only possible numbers are 0 and 1, and the number 5 is congruent to number 1... So ##5%2## really gives as a result a number that is congruent to the divisor and not really the reminder.
I guess I am confused on the relation between the modulus and the modulo and if and how they are the same thing...
Thanks!
I an clear on how the modulo operator ##%##, also called the remainder operator, is used in programming. It gives the remainder of the integer division. For example, ##5 % 2 = 1## because the divisor 2 fits 2 wholly times into the dividend 5 leaving behind a reminder of 1.
## 6% 3 =0## because the remainder is 0.
However, when learning about modular arithmetic in math, I learned that modulus ##N## means that only the integer numbers from ##0## to ##N-1## are available. For example, modulus ##5## means that all the possible numbers we can work with are ##0,1,2,3,4##. Any other number ##X## outside this range wraps up back into this range of numbers as a congruent number to one of numbers in the range.
A simple hack is to add or subtract from the number ##X## an integer number of the modulus ##N## until we get back into the range ##0,1,2,3,4##. For example, 10 (modulus 5) is congruent to 10-(2-5)=0 (modulus 5).
Example: ##10## and ##0## are equivalent/congruent numbers if considered modulus 5: $$ 10 \equiv 0 mod(5)$$. There are two ways to assess if two numbers are congruent mod ##N##:
a) if divided by the modulus ##N##, the numbers give the same reminder. Ex: 10/5 gives reminder 0 and 0/5 gives reminder 0 as well.
b) if the difference between the two numbers ##10## and ##0## is equal to an integer multiple of the modulus ##N##. Ex: 10-0=2(5).
All that said, I believe that in computer programming, the use of the modulo operator ##%## really gives the congruent number that is in the range of numbers of the modulus. For example, 5%2 means that we are working with modulus 2 so the only possible numbers are 0 and 1, and the number 5 is congruent to number 1... So ##5%2## really gives as a result a number that is congruent to the divisor and not really the reminder.
I guess I am confused on the relation between the modulus and the modulo and if and how they are the same thing...
Thanks!