-1

I am trying to find the possible values of this expression.

(a mod 2*x)-(a mod x)

I suspect they might be 0 or x, but I'm really not sure. I can't seem to be able to write down a proper argument.

user1377000
  • 1,433
  • 3
  • 17
  • 29
  • http://math.stackexchange.com/ ? – Bernhard Barker Feb 12 '13 at 06:52
  • Agreed that math.se is the place to go. And yes, the possible values are 0 and x, assuming a and x are both positive. – DocMax Feb 12 '13 at 06:57
  • But could you tell me why? – user1377000 Feb 12 '13 at 07:00
  • Sure. Let `a` have the form `a = p*x + b`. Then `a mod x` is `b` and `a mod 2*x` is `b` if `p = 2*r` (`a = 2*r*x + b = (2*x)*r + b`) and `x+b` if `p = 2*r + 1` (`a = (2*r + 1)*x + b = 2*r*x + x + b = (2*x)*r + x + b`. Thus the difference is either `b - b = 0` or `(x + b) - b = x`. – DocMax Feb 12 '13 at 07:06
  • @DocMax, you could still make this comment an answer, even if you consider m.s.e the better place. Just to get this out of the "unanswered" list. – MvG Feb 12 '13 at 08:14
  • @MvG: Good point. Done. – DocMax Feb 12 '13 at 15:53

1 Answers1

1

You are correct that the possible values are 0 and x, assuming that both a and x are positive. The logic is as follows.

Let a have the form

a = p*x + b

Then it is easy to see that a mod x = b.

For a mod 2*x, if p = 2*r (p is even) then

a = 2*r*x + b = (2*x)*r + b

so that a mod 2*x = b and p = 2*r + 1 (p is odd) then

a = (2*r + 1)*x + b = 2*r*x + x + b = (2*x)*r + x + b

so that a mod 2*x = x + b. Combining these results, the difference is either b - b = 0 (when p is even) or (x + b) - b = x (when p is odd).

DocMax
  • 12,094
  • 7
  • 44
  • 44