0

-- I checked the other similarly titled questions, they are not duplicates.

I was playing around, and noticed that in Excel if I did 5%(-4) (I used function of "=MOD(5,-4)") that the answer was -3. I didn't fully understand this. I checked google (-3), symbolab (1), bing (1), and chatGPT (-1). Of these, chatGPT is the only one that makes sense to me.

The other stackExchange questions had some explanations of mod, but I didn't fully understand them. And also I don't fully understand why there was a difference between sources.

Doragon
  • 133
  • 4
    There is a convention sometimes used for negative modulus which says the expression has the same sign as the modulus and is otherwise congruent to the remainder on division by the modulus. That works here since $5=-1\times(-4)+1=-2\times (-4)+(-3)$ and $-3\equiv 1\pmod {-4}$. To be sure: this convention is not universally used. – lulu Jun 11 '24 at 23:41
  • 1
    Wolfram Alpha appears to follow this convention as well. – lulu Jun 11 '24 at 23:42
  • 5
    ChatGPT is the only one which is wrong. Notice that all the other sources gave congruent answers. – Malady Jun 11 '24 at 23:47
  • 5
    As a general note: I would never use ChatGPT for math. Never. It just guesses. It grabs enough to make it look like the guesses are smart, but they seldom are. – lulu Jun 11 '24 at 23:48
  • 3
    There may be different conventions among different sources as to what $a%b$ means, but a rock-bottom absolute indispensable requirement is that if $a%b=c$ then there is an integer $d$ such that $a-c=bd$. – Gerry Myerson Jun 12 '24 at 00:07
  • 2
    There are three definitions (truncated, floored, and Euclidean) which differ if the dividend or the divisor is negative. This is explained in https://en.wikipedia.org/wiki/Modulo, and there is also a long list how different programming languages handle this. – Martin R Jun 12 '24 at 00:16
  • 2
    The essential facts about using a negative number as a modulus in modular arithmetic (including why the ChatGPT answer to this question was wrong) are covered in https://math.stackexchange.com/q/1284334/139123 ... The only reason I might not mark this as a duplicate is that you also want to know why the answer is sometimes given as $1$ and sometimes as $-3.$ – David K Jun 12 '24 at 01:12
  • 1
    I suggest to understand the behaviour of MOD together with its companion integer division function. According to Excel's support page, Excel defines MOD(n, d) = n - d*INT(n/d), so the MOD(5, -4) result is designed to work with integer division by INT(5/(-4)) (where INT is floor). – peterwhy Jun 12 '24 at 01:26
  • 1
    @lulu It might be worth putting your first comment as an answer. – Malady Jun 12 '24 at 01:35

0 Answers0