What Happens When Negative Numbers Are Used in Mod Operations?

  • Thread starter Thread starter baby_1
  • Start date Start date
AI Thread Summary
The discussion clarifies how the modulus operation works with negative numbers, emphasizing that mod is defined as a relation rather than just an operator. When calculating -10 mod 27, the result is 17, as it is the unique number between 0 and 26 that satisfies the congruence condition. The conversation also highlights the distinction between mathematical definitions and programming implementations of the mod operation. Participants agree on the importance of understanding the underlying principles of modulus to correctly handle negative inputs. Overall, the thread provides a comprehensive explanation of the modulus operation with negative numbers.
baby_1
Messages
159
Reaction score
16
Hello
i know that it shows Remaining for example

5 mod 3=2
1 mod 3=1

but if i select negative number what does it do?

example:

-10 mod 27 =?

Thanks
 
Mathematics news on Phys.org
baby_1 said:
Hello
i know that it shows Remaining for example

5 mod 3=2
1 mod 3=1

but if i select negative number what does it do?

example:

-10 mod 27 =?

Thanks

In math, mod is defined as a relation, rather than an operator. So we would say

5 \equiv 2 (mod 3)

and

1 \equiv 1 (mod 3)

where the \equiv in this context is pronounced "is congruent to."

In other words a mod-n statement returns "true" or "false" when applied to pairs of numbers. The general rule is that

a \equiv b (mod n) if the number n divides a - b.

Now a lot of people come to mod from programming languages, where mod is not a relation, but is rather an operator, meaning that it returns a single value. That's the usage you've written, so we say

5 mod 3=2

and so forth.

But even though 5 \equiv 2 (mod 3), it's also true that 5 \equiv 47 (mod 3), right? Both 47 and 5 give the same remainder when divided by 3. [That's equivalent to the definition I gave earlier; but you should actually convince yourself of that]

So if someone asks us what is 5 mod 3, what should the answer be? The convention is that we take the unique number x such that 5 \equiv x (mod 3) and x is greater than or equal to 0, but less than 3.

With that background, what is the answer to -10 mod 27 = ?

Well, let's find x such that -10 \equiv = x (mod 27), and x is between 0 and 26 inclusive. A moment's thought will convince you that x = 17 is the right answer here. So

-10 mod 27 = 17

That's because

a) -10 - 17 is divisible by 27; and

b) 17 is the unique number with that property that's also between 0 and 26, inclusive.

That's a long answer but it's everything you need to know to make sense of this kind of problem.
 
Last edited:
baby_1 said:
Hello
i know that it shows Remaining for example

5 mod 3=2
1 mod 3=1

but if i select negative number what does it do?

example:

-10 mod 27 =?

Thanks

Maybe a quick way of answering is a=b mod c is equivalent to : c|(b-a) , or, the

remainder of dividing a by c is b*. And complement it with Stevel27's answer.

* This is a technical point, since we usually choose the remainder to be within

a given range, but we can add multiples.
 
Thanks Dear SteveL27 & Bacle2
you are my best teacher that dedicate your time to telling me the right answer.

Thanks again
 
Thanks, but I did only a minimal part.

That's how I like it, Stevel27 does 99%+ of the work and we split the credit in half ;) .
 
Bacle2 said:
Thanks, but I did only a minimal part.

That's how I like it, Stevel27 does 99%+ of the work and we split the credit in half ;) .

I don't mind. I got 99% of the cash reward :-)
 
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Thread 'Unit Circle Double Angle Derivations'
Here I made a terrible mistake of assuming this to be an equilateral triangle and set 2sinx=1 => x=pi/6. Although this did derive the double angle formulas it also led into a terrible mess trying to find all the combinations of sides. I must have been tired and just assumed 6x=180 and 2sinx=1. By that time, I was so mindset that I nearly scolded a person for even saying 90-x. I wonder if this is a case of biased observation that seeks to dis credit me like Jesus of Nazareth since in reality...
Thread 'Imaginary Pythagoras'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top