Re: Modular Arithmetic



In article <wood-1207060725250001@xxxxxxxxxxxxxxxxxxxxxxxx>,
wood@xxxxxxxxxxxxxxxx (J. B. Wood) wrote:

Hello, all. Can the result of the expression

N mod M

where N and M are integers with M > N ever be negative? Most references
I've come across (including the Excel MOD function) will give the result
(remainder) in this case as N but a least one paper I've read would
interpret the result as N-M. This appears to imply "multiply M by 1 and
subtract the result from N."
I'm wondering if there is one accepted math definition to cover this
case. Thanks for your time and comment. Sincerely,


There are two different but related usages of mod.

In math, we say that two integers, a and b, are congruent mod n, if n
divides the difference of a and b.

So for example 2 and 7 are congruent mod 5, because 5 divides 7 - 2.

It would also be true that, for example, 12 = 2 (mod 5) or 22 = -3 (mod
5) for the same reason.

[note ... in books, the '=' is written with three horizontal bars to
indicate equivalence rather than equality.]

Now, in computer programming, there is a mod operator that returns the
result of an expression ... so that mod(12, 5) = 2.

In math, mod is an equivalence relation ... it's a function that returns
true or false, given a pair of numbers and a modulus.

In programming, mod is a function that returns a numerical value.

So it's true that in excel or in programming languages, 12 mod 5 = 2,
always, and never -3.

But in math, 12 = -3 (mod 5) because 5 divides 12 - (-3).
.



Relevant Pages

  • Re: Question for corn powered computer
    ... Not much in the way of references. ... applicable to the current science unit. ... English class spelling test will also cover some of the math terms, ... historical context. ...
    (comp.sys.ibm.ps2.hardware)
  • Re: So... Lerentz Contractions are *physical* not observered?
    ... 1+1=2 is falsified by the experimental evidence in my references. ... jem transforms are valid and you still can't do it. ... Still no math, jem? ...
    (sci.physics.relativity)
  • Re: So... Lerentz Contractions are *physical* not observered?
    ... haven't read any of the references, there is nothing I can do for you ... there is nothing I can do for you <SHRUG> ... jem transforms are valid and you still can't do it. ... Still no math, jem? ...
    (sci.physics.relativity)
  • Re: TAOCP prerequisite
    ... By which I'm sure you mean Knuth's "The Art of Computer Programming", ... "Concrete Mathematics": ... math he uses so effectively in this area was new to him when he started ... TAoCP (despite, I'll add, being an extremely bright and hard-working fellow ...
    (sci.math)
  • Re: A Mathematicians Lament
    ... good math background is critical to being a good programmer. ... programming classes taught by a math teacher. ... for TRUE mathematics, which is more about structure and relationships ... bodes well for his future in computer programming. ...
    (rec.sport.football.college)