Calculating Modulo for -3 and 26: Understanding the Remainder Calculation

  • Thread starter shivajikobardan
  • Start date
  • Tags
    Calculation
In summary: The simplest concept of a remainder is usually defined as a non-negative integer (although not always).In the usual case, we would have:$$-3 = (-1 \times 26) + 23$$As a simple analogy, I like to think in terms of a 12 hour clock.Clocks read hours as 1,2,3,4,5,6,7,8,9,10,11,12 only.Hence -3 hours would be 9 o'clock.
  • #1
shivajikobardan
674
54
Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.
 
Physics news on Phys.org
  • #2
shivajikobardan said:
Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.
What do you think it should be?
 
  • #3
shivajikobardan said:
Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.

Related question: What's the integer part of -3/26? Is it [tex]
\left\lfloor - \frac{3}{26} \right\rfloor = -1\qquad\mbox{or}\qquad-\left\lfloor \frac{3}{26} \right\rfloor = 0?[/tex] If you use the first definition, then the remainder is [tex]
R(x) = x - 26\left\lfloor \frac{x}{26}\right\rfloor[/tex] and you would have [tex]R(-3) = -3 - 26(-1) = 23.[/tex] Alternatively if you use the second approach then [tex]
R(x) = x - 26\operatorname{sgn}(x)\left\lfloor \frac{|x|}{26}\right\rfloor[/tex] and you would get [itex]R(-3) = -3[/itex].
 
  • Like
Likes topsquark
  • #4
PeroK said:
What do you think it should be?
I think it should be -3 itself. As it's not divisble by 26. Just like if it was 3%26, it'd be 3.
 
  • #5
shivajikobardan said:
Summary: calculating modulo i.e remainder when -3 divided by 26

The answer seems to be (26-3)mod26=23. But I'm not sure how? Is there some rule like that? I don't quite get it.
##a \equiv b ## (mod ## n ##) means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##. You can also phrase this as a and b have same remainer when dividing with n: a = pn + ra and b = qn + rb. But if ra = rb then you have that a-b = (p-q)n = kn i.e. a-b is an integer multiple of n.

Therefore, you can always add or subtract any integer muptiple of ##n## to either ##a## or ##b##, for instance
if ##a \equiv b ## (mod ## n ##) , then:
##a \equiv b + n ## (mod ## n ##)
##a + n\equiv b ## (mod ## n ##)
etc
So in your case, you can add 26 to -3, you can add 52, subtract 26, subtract 52 and so on, and still have the same remained when dividing with 23
 
Last edited:
  • Like
Likes topsquark
  • #6
shivajikobardan said:
I think it should be -3 itself. As it's not divisble by 26. Just like if it was 3%26, it'd be 3.
What are the possible answers for a "remainder" on division by 26? Is it the set ##\{-25, -24 \dots -1, 0, 1, \dots 24, 25\}##?

PS how is "remainder" defined?
 
  • Like
Likes malawi_glenn
  • #7
malawi_glenn said:
##a \equiv b ## mod##(n)## means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##.
I think you mean ##a \equiv b \pmod n ## means that ##(a-b)## is an integer multiple of ##n## i.e. ##a-b = kn## for some integer ##k##. The placing of the parentheses (in this case automatic through use of the \pmod symbol) is important.

However the OP is asking about something subtly different, the value of b where ## b = a \text{ mod } n ##. This is defined as the unique integer ## b \in \{0 \dots n-1\} ## for which ##a \equiv b \pmod n ## is true: for positive integers this is the same as the remainder on division by ## n ## but for negative integers this is not the case.
 
Last edited:
  • Like
Likes malawi_glenn, vela and topsquark
  • #8
Yes i wrote the paranthesis wrong thanks
 
  • #9
If we are talking about modular arithmetic, then technically ##-3## is the additive inverse of ##3##, which is ##23## in this case. So:$$-3 \equiv 23 \ (mod \ 26)$$The simpler concept of a remainder is usually defined as a non-negative integer (although not always). In the usual case, we would have:
$$-3 = (-1 \times 26) + 23$$
 
  • Like
Likes SammyS, FactChecker, topsquark and 1 other person
  • #10
As a simple analogy, I like to think in terms of a 12 hour clock.

Clocks read hours as 1,2,3,4,5,6,7,8,9,10,11,12 only.

Hence -3 hours would be 9 o'clock.
 
  • Like
Likes malawi_glenn and shivajikobardan
  • #11
1660752052057.png
 
  • Like
Likes shivajikobardan
  • #12
pbuk said:
However the OP is asking about something subtly different, the value of b where ## b = a \text{ mod } n ##. This is defined as the unique integer ## b \in \{0 \dots n-1\} ## for which ##a \equiv b \pmod n ## is true: for positive integers this is the same as the remainder on division by ## n ## but for negative integers this is not the case.

Never seen ## b = a \text{ mod } n ## in my life, that you use an equal sign that is.
I have seen it when you deal with equivalence classes though.

I have only seen it being stated like this
"Find the smallest positive integer ##x## that solves ##x \equiv -18 \pmod {12}##"
or
"What is the smallest positive remainder when -18 is divided by 12" or "principal remainder"
 
  • #13
malawi_glenn said:
Never seen ## b = a \text{ mod } n ## in my life, that you use an equal sign that is.
Really? Although it isn't on their profile, I believe the OP is studying computer science.
https://en.wikipedia.org/wiki/Modulo_operation
 
  • Like
Likes shivajikobardan
  • #15
Some programming languages use the % operator for modulo operations.

x = 25 % 15
 
  • Like
Likes shivajikobardan
  • #16
  • #17
shivajikobardan said:
yes it's CS. didn't know math and CS were different for modulo.
Writing a = b (mod n) is an abomination!
 
  • #18
malawi_glenn said:
Writing a = b (mod n) is an abomination!
Yes it would be, but no-one has done that. As I said, parentheses (and the equivalence relation vs equality) are important here to distinguish between the two forms.
 
  • #19
pbuk said:
Yes it would be, but no-one has done that. As I said, parentheses (and the equivalence relation vs equality) are important here to distinguish between the two forms.
You did so in post 7.
pbuk said:
However the OP is asking about something subtly different, the value of b where b=a mod n.
Never seen that notation.
 
  • #20
malawi_glenn said:
You did so in post 7.
No I didn't.

malawi_glenn said:
Never seen that notation.
You already said that in #12, which is why I explained it to you.
 
  • #21
shivajikobardan said:
yes it's CS. didn't know math and CS were different for modulo.
How a computer language works is at the discreption of the developers of that language. In Python, for example:
$$-3\%26 = 23$$Which is what I would have hoped.
 
  • Like
Likes malawi_glenn
  • #22
More correctly in Python the expression would be:

Python:
-3%26 == 23

as single equals is for assignment x-y ie assign the value of y to x.

and double equals is for equality as in x==y meaning the value of x is equal to the value of y

An example python program:

Python:
for x in range(-50,50):
    y=x%26
    print("%d  %d"%(x,y))

One thing to note in python is that the % operator takes on different uses depending on how it is used:
- as a modulo operator y=x%26
- as a format specifier as in %d for printing an integer
- as a string formatting operator to apply the tuple to the format string "%d %d"
 
  • Sad
  • Like
Likes malawi_glenn and PeroK
  • #23
This was my Python program:
Python:
print(-3%26)
 
  • Like
Likes malawi_glenn

FAQ: Calculating Modulo for -3 and 26: Understanding the Remainder Calculation

What is the definition of modulo?

Modulo, also known as the remainder calculation, is a mathematical operation that calculates the remainder after dividing one number by another.

How is modulo calculated?

To calculate the modulo of a number, you divide the first number by the second number, and the remainder is the result. For example, the modulo of 10 and 3 would be 1, as 10 divided by 3 is 3 with a remainder of 1.

What is the purpose of calculating modulo?

Calculating modulo is useful in a variety of applications, such as determining the day of the week, finding prime numbers, and creating unique identifiers in computer programming.

How is modulo different from division?

Modulo and division are similar operations, but they have different results. Division gives the quotient, or the result of the division, while modulo gives the remainder.

What is the result of calculating modulo for -3 and 26?

The result of calculating modulo for -3 and 26 is 23. This is because -3 divided by 26 has a remainder of 23.

Back
Top