Modulo and infinity, why is $x\bmod\infty$ equal to $x$ for binary operations on integers and $x \in \Bbb Z$?

2.2k Views Asked by At

Disclaimer: I am a programmer and my mathematical skills are those of Discrete Mathematics as taught at universities. I am interested in the mathematical background of how we can define $x\bmod\infty$, to understand essentially why, in programming language design we make the choices the way we do.

I believe in mathematics you call this the binary modulo operation, where the operator returns the remainder of integer division.

I thought it's such a simply question that I was surprised I couldn't find the answer at Math SE, so perhaps it isn't a mathematical question to begin with. A little background: yesterday we had a discussion at the XSLT 3.0 WG about a certain edge case and its expected outcome, and we seemed to remember that $x\bmod\infty = x$. But none of us was quick to find this definitively described anywhere.

Essentially, I am wondering about the reason why:

$$x\bmod\infty = x$$

With my limited skilss, I deduct that, in $x\bmod y$, as soon as $y$ gets bigger than $x$ it will always return $x$, so this should also be true for infinity, right? In other words, I think that:

$$\lim_{n\to\infty}x\bmod n = x, x \in \Bbb Z$$

And while we are at it, would this hold too?

$$x\bmod-\infty = x$$ $$0\bmod\infty = 0$$ $$0\bmod-\infty = 0$$ $$\infty\bmod\infty = \infty$$ $$-\infty\bmod\infty = -\infty$$ $$\infty\bmod-\infty = \infty$$ $$-\infty\bmod-\infty = -\infty$$

And the following seems logical, though I haven't found it definitively either:

$$\infty \bmod x = NaN$$ $$-\infty \bmod x = NaN$$

1

There are 1 best solutions below

1
On

Let's consider $x\bmod t$, for $t>0$; one of the used definitions for real $t>0$ is $$ x\bmod t=x-t\left\lfloor\frac{x}{t}\right\rfloor $$ If $0\le x<t$, we have $0\le x/t<1$, so $\lfloor x/t\rfloor=0$ and $x\bmod t=x$.

If $-t<x<0$, we have $-1<x/t<0$, so $\lfloor x/t\rfloor=0=-1$ and $$ x\bmod t=x+t $$

Thus you see that the definition $x\bmod\infty=x$ would only be reasonable for $x\ge0$.

However, if you use “truncated division”, the definition $x\bmod\infty=x$ would also be reasonable for $x<0$.

See Modulo operation on Wikipedia for the different definitions of the mod operation. You'll also see that different programming languages use different conventions. In any case the definition $x\bmod \infty=x$ for $x\ge0$ fits any of the conventions.