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

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Calculation
AI Thread Summary
The discussion centers around calculating the modulo of -3 divided by 26, with the conclusion that the result is 23, derived from the formula (26 - 3) mod 26. Participants explore different definitions of the remainder, noting that for negative integers, the remainder can differ from the intuitive approach. There is debate over whether the remainder should be -3 or 23, with the consensus leaning towards 23 as the standard non-negative result in modular arithmetic. The conversation also touches on the notation used in computer science versus traditional mathematics, emphasizing the importance of clarity in expressing modular relationships. Overall, the modulo operation for negative numbers can yield unique results based on the defined approach.
shivajikobardan
Messages
637
Reaction score
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
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?
 
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 <br /> \left\lfloor - \frac{3}{26} \right\rfloor = -1\qquad\mbox{or}\qquad-\left\lfloor \frac{3}{26} \right\rfloor = 0? If you use the first definition, then the remainder is <br /> R(x) = x - 26\left\lfloor \frac{x}{26}\right\rfloor and you would have R(-3) = -3 - 26(-1) = 23. Alternatively if you use the second approach then <br /> R(x) = x - 26\operatorname{sgn}(x)\left\lfloor \frac{|x|}{26}\right\rfloor and you would get R(-3) = -3.
 
  • Like
Likes topsquark
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.
 
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
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
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
Yes i wrote the paranthesis wrong thanks
 
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
Back
Top