4

Consider the following limit:

$$\large\lim_{x\to 0^+}\frac{\lfloor x\rfloor}{\lfloor x\rfloor}$$

The domain of the function $f(x) = \frac{\lfloor x\rfloor}{\lfloor x\rfloor}$ is $\mathbb{R}-[0, 1)$. This shows that the limit of this function as $x$ approaches zero from right, does not exist because to calculate this limit, the function needs to be defined on an open interval such as $(0, 1)$, which, according to the domain of the function, is not the case.

Everything looks well and logical, but if you calculate this limit in Wolfram Mathematica, you will see: enter image description here

Why is this?! And, of course, in WolframAlpha.com, you will also see the same result.

You can also see this at HERE.

Why is this?

I realized that Mathematica and WolframAlpha incorrectly simplified $\frac{\lfloor x\rfloor}{\lfloor x\rfloor}$ to 1; why?? (While we know that this is incorrect because it is like saying that the two functions $f(x) = \frac{\lfloor x\rfloor}{\lfloor x\rfloor}$ and $g(x)=1$ are equal, which is not the case)

user444
  • 2,414
  • 1
  • 7
  • 28
  • 4
    Mathematica ignores removable singularities in some operations, e.g. In[12]:= a/a Out[12]= 1 – Greg Hurst Jan 08 '24 at 17:10
  • 3
    Mathematica simplifies Floor[x]/Floor[x] to 1 before even the Limit gets a chance to look at it. It is as if you wrote Limit[1, x -> 0, Direction -> "FromAbove"] which ofcourse is 1 – Nasser Jan 08 '24 at 17:12
  • 1
    @Nasser Yes but this is mathematically incorrect; because two functions $f(x) = \frac{\lfloor x\rfloor}{\lfloor x\rfloor}$ and $g(x)=1$ aren't equal. So we can't take the limit of $g(x)$ instead of $f(x)$, so I think that mathematica is doing it wrong. –  Jan 08 '24 at 17:26
  • @GregHurst Shouldn't the programming of mathematics and mathematical software in general be based on the laws of mathematics, while we know that such a thing is not completely mathematically correct and accurate? –  Jan 08 '24 at 17:31
  • 1
    Pretty much for the same reasons as here: https://mathematica.stackexchange.com/questions/57489/why-does-mathematica-simplify-x-x-to1 – Goofy Jan 08 '24 at 17:31
  • @Goofy I would really like to know the mathematica programmers reason for this because it is not mathematically correct. –  Jan 08 '24 at 17:38
  • 1
    Similar topics were discussed at this forum several times, but things haven't budged an inch. – user64494 Jan 08 '24 at 17:41
  • 1
    All CAS systems I know about have thing called automatic simplification. It is not just Mathematica. Here is your example in Maple and it does same thing as Wolfram Mathematica. Mathematica graphics – Nasser Jan 08 '24 at 17:45
  • 2
    My understanding is that such checking of domains creates a great deal of computational complexity. For the main uses of Mathematica, it's not worth it. But maybe someone from WRI can make a more definitive statement. I'd bet they discussed it before they released V1 even. – Goofy Jan 08 '24 at 17:46
  • 1
    As for why W|A gets it wrong, idk, other than they lazily feed it to Mma. W|A doesn't have to be as efficient as Mma (imo). But the workings of W|A are not what this site is about. -- One can express the correct solution, Limit[ConditionalExpression[1, Floor[x] != 0], x -> 0, Direction -> "FromAbove"]. I'm not sure how to get that to happen, though. At least not in an easy way. (Redefine division or power to include a domain condition is a potential approach. But redefining system functions messes up internal algorithms, so not "easy" imo.) – Goofy Jan 08 '24 at 17:53
  • 3
    A mathematical way to view Mma is that the basic structure of the arithmetical operations on expressions is a quotient algebra, not a model of analysis. Therefore $p(x)/p(x)$ is $1$ just as in ${\Bbb R}(x)$, but Mma does not limit $p$ to polynomials. The "algebra" is not a standard one and contains all Mathematica expressions. (Another difference is that every operation is defined, like division by zero.) – Goofy Jan 08 '24 at 20:02

2 Answers2

6

More of an extended comment than an answer...

While many people view Mathematica as a magic doer-of-all-things-mathematical, it is fundamentally a programming language. It's a programming language with specific execution rules. At some point in using Mathematica, understanding the paradigm of the underlying programming language becomes crucial to understanding results and to crafting good inputs.

The short explanation here is that Limit never actually encounters the expression Floor[x]/Floor[x]. If Limit had one of the Hold* attributes, then maybe it could be made to deal with these kinds of situations, but it doesn't. So, by the time Limit "sees" its arguments, the situation looks like this (as has been pointed out by Nasser):

Limit[1, x -> 0, Direction -> "FromAbove"]

(Side note, Trace is a very useful function to help you understand the evaluation process.)

Okay, you say, but Floor[x]/Floor[x] shouldn't be assumed to evaluate to 1. But Mathematica doesn't see functions, just expressions. You could make the same argument that a/a shouldn't evaluate to 1 (assuming that a itself is a symbol with no definitions attached), because we don't know that the "variable" a can't be 0, but it does in fact evaluate to 1. That's part of the evaluation rules.

All of this is entirely by design. It might be frustrating. It might be different than what you want or expect, but this is just an inherent part of how the language works and how Limit and Divide were designed.

There are going to be situations where you need to guide the language to do what you want. For example, you've said

The domain of the function ()=⌊⌋/⌊⌋ is ℝ−[0,1)

but there is no way for Mathematica to know that. To Mathematica, there are no actual functions, just expressions and evaluation rules. And there is no general way for it to infer constraints on expressions that you can always rely on. You as the designer of the program must provide a complete specification. Maybe something like this:

f[x_] := Piecewise[{{Floor[x]/Floor[x], x >= 1 || x < 0}}, Indeterminate]

Now we can try the limit:

Limit[f[x], x -> 0, Direction -> "FromAbove"]

This returns unchanged (from Limit's point of view, f[x] actually evaluated, replacing the Floor expression with just 1), which seems reasonable to me because now it's obvious that the limit expression was improper.

If there is any complaint to be had here, it's with Wolfram Alpha. It could maybe be argued that as an educational tool (if that is indeed its purpose) it should do some pre-parsing to inspect the input for problematic cases. But I'm not very familiar with Wolfram Alpha, so I can't really infer any design intentions.

lericr
  • 27,668
  • 1
  • 18
  • 64
  • 4
    Probably the most important takeaways are "while many people view Mathematica as a magic doer-of-all-things-mathematical, it is fundamentally a programming language" and "you need to guide the language to do what you want". I was once told that what one wants is one thing, what one tells the computer is another, and what the computer does is yet a different thing. All in all, any computer/programming language is a mindless machine/automaton made to run algorithms. Their correctness/setup/verification is the responsibility of the user. – corey979 Jan 08 '24 at 19:04
  • 1
    Agree --------- – lericr Jan 08 '24 at 19:43
  • 1
    @corey979 and others: Let us compare Reduce[a*x == b, x] which results in (b == 0 && a == 0) || (a != 0 && x == b/a) with the Maple's one: solve(a*x = b, x, parametric) which results in piecewise(a = 0, piecewise(b <> 0, [], [{x = x}]), a <> 0, [{x = b/a}]), where the case $a=0 \wedge b\neq 0$ is described. – user64494 Jan 08 '24 at 19:53
  • 5
    @user64494 I sincerely don't understand what point you're making. – lericr Jan 08 '24 at 20:52
  • 1
    @lericr: The bad result of Reduce[a*x == b, x] is caused by automatic simplification a||False to a. Don't hesitate to ask for further explanation in need – user64494 Jan 08 '24 at 23:39
  • 2
    @user64494 Why is the result of the Reduce "bad"? And if it's bad, then presumably your point is that Maple's is good, but I don't see how it's good (and I don't know enough about Maple to know that the semantics are even the same--are they?). And how is this relevant to the original post? – lericr Jan 08 '24 at 23:49
  • 1
    @lericr: You asked "Why is the result of the Reduce "bad"?". Does not describe the case $a=0 \wedge b\neq 0$. – user64494 Jan 09 '24 at 00:36
  • 2
    @user64494 That case is superfluous. Look, it depends on what you assume the semantics are. As far as I can tell, Mathematica is telling you the conditions a solution must satisfy, not the conditions that lead to non-solutions. Why doesn't Maple tell us that a is even && b is odd leads to no solutions? Look, I'm not an expert on these functions, so if there is a point here, I'd appreciate you being more explicit about it. To my unexpert eyes, this looks like a complete non-issue. – lericr Jan 09 '24 at 06:29
  • (And x is an integer) – lericr Jan 09 '24 at 07:04
2

As was already pointed out in one comment and in one answer that the result obtained was correct but incorrect was assumption of OP how Mathematica works or how it should work.

I just want to present another example of code that illustrates how Mathematica works in this case:

First notice that

FullSimplify[x^2 + 3 x + 1 - (x + 1)^2] === x

True

So we can use Floor[x^2 + 3 x + 1 - (x + 1)^2]] instead of one of Floor[x].

Table[Limit[Floor[x^2 + 3 x + 1 - (x + 1)^2]/Floor[x], x -> p, 
    Direction -> #] & /@ {"FromBelow", "FromAbove"}, {p, 0, 1, 1/10}]

{{1, Indeterminate}, {Indeterminate, Indeterminate}, {Indeterminate, 
  Indeterminate}, {Indeterminate, Indeterminate}, {Indeterminate, 
  Indeterminate}, {Indeterminate, Indeterminate}, {Indeterminate, 
  Indeterminate}, {Indeterminate, Indeterminate}, {Indeterminate, 
  Indeterminate}, {Indeterminate, Indeterminate}, {Indeterminate, 1}}

We see that the limit is Indeterminate inside interval (0,1). At 0 it exists only if taken limit from below and at 1 only if taken from above.

Now the same code just the expression inside limit is simplified at first:

Table[Limit[Floor[x^2 + 3 x + 1 - (x + 1)^2]/Floor[x] // FullSimplify,
     x -> p, Direction -> #] & /@ {"FromBelow", "FromAbove"}, {p, 0, 
  1, 1/10}]

{{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 
  1}, {1, 1}, {1, 1}}

So Mathematica works as it should in both cases.

azerbajdzan
  • 15,863
  • 1
  • 16
  • 48