# WolframAlpha's problems with equations involving the floor operation

The whole story began when I was developing an easy way to solve complex equations involving mix-up of absolute value, floor, ceiling, rounding, and other functions, as well as polynomials embedded in them.

When I was pretty much done, I started solving different equations like that. I came up with couple equations. One of them is:

$$|x^2 + 3x| + \lfloor2x^2\rfloor + x = 5$$

I ended up with eight numbers. I expected six of them to be extraneous, and two of them to work. However, it turned out, none of the eight numbers worked. So I concluded there are no solutions. Just to be sure, I opened up Wolfram Alpha and wanted to see if there is a solution: http://www.wolframalpha.com/input/?i=abs(x%5E2+%2B+3x)+%2B+floor(2x%5E2)+%2B+x+%3D+5

Wolfram Alpha spitted out $x=2\sqrt{2} - 2$.

I checked the solution that WA gave me, but to my surprise it didn't work! If I plugged it inside wolfram alpha for $x$, it worked, but when I did it on paper, it didn't!

Out of curiosity, I typed in this equation in Wolfram Alpha:

$$\lfloor2x^2\rfloor = x+2$$

And, now I was even more surprised. WA gave me solution $-1$, which IS total NONSENSE. It can be checked here: http://www.wolframalpha.com/input/?i=floor(2x%5E2)+%3D+x%2B2 . Obviously $-1$ doesn't work in that equation.

Most important problem: So, I know that Wolfram Alpha gave me the wrong answer for the second equation, however I am still not sure about the first one. Is the solution WA gave for the first equation correct, or am I right about that there is no solution?

I was indeed "hallucinating". One of the eight numbers I got was actually the solution Wolfram Alpha gave me, although I got it in a different form, and somehow it didn't work when I tested it.

Still, the bug present in the second equation needs to be fixed, I'll report it.

• Looks like a bug in WA to me. They probably don't get a lot of people trying to solve equations involving floor functions. Note that although $-1$ doesn't work, $-0.999999999999999$ is very close to working; likely the $-1$ is actually rounding. – Qiaochu Yuan Jun 3 '17 at 1:44
• This question belongs on the Mathematica.stackexchange site, not this site. – David G. Stork Jun 3 '17 at 2:07
• @DavidG.Stork actually not, because I asked "Is the solution WA gave for the first equation correct, or am I right about that there is no solution?" which asked for verification of mathematical solution. – KKZiomek Jun 3 '17 at 2:08
• $\texttt{Mathematica}$ has the same problems with those kind of functions. – Felix Marin Jun 10 '17 at 2:39
• See my W & A attempt. I wrote $\texttt{Solve[Abs[x^2 + 3 x] + Floor[2 x^2] + x == 5,x]}$ – Felix Marin Jun 10 '17 at 2:48

What's happening (for the second one) is that, for example

$$\lfloor 2(-0.99)^2 \rfloor - (-0.99) = \lfloor 1.9602 \rfloor + 0.99 = 1.99 \approx 2.$$

So what WolframAlpha does, when trying to solve numerically, is get $-0.9999\dots$ (to some chosen precision) which is very close as long as there are only a finite number of '9's. It then rounds (when printing) and gets $-1$ which is no longer a solution.

The first one is a solution:

\begin{align} &\qquad |(2\sqrt 2 - 2)^2 + 3(2\sqrt 2 - 2)| + \lfloor 2(2\sqrt 2 - 2)^2 \rfloor + (2\sqrt 2 - 2) \\ &= |6 - 2\sqrt 2| + \lfloor 1.37 \rfloor + (2\sqrt 2 - 2) \\ &= 5. \end{align}

• I don't think that's what Wolfram Alpha does, although I would agree with you that the floor function gets crazy with discontinuity. – KKZiomek Jun 3 '17 at 1:47
• By the way I still need an answer to the last part of my question: "Is the solution WA gave for the first equation correct, or am I right about that there is no solution?" – KKZiomek Jun 3 '17 at 1:48
• Likely it isn't literally computing a limit but arriving at an approximate solution like $-0.999999999999$ and then displaying it as $-1$. Perhaps it defaults to printing floating point numbers to a certain number of decimal places which causes that number to round to $-1$. – Erick Wong Jun 3 '17 at 1:52
• Sorry, wasn't trying to claim that WA was taking a limit. – Trevor Gunn Jun 3 '17 at 1:54
• @KKZiomek I also agree that $2\sqrt2 - 2$ is a solution. Can you explain what you believe the LHS is for that value of $x$? – Erick Wong Jun 3 '17 at 1:55

The function is discontinuous, but if you specify the proper range (e.g., $x > -10$ or $x<20$, to avoid an infinite number of discontinuities), then Mathematica gives the unique solution directly:

Solve[Abs[x^2 + 3 x] + Floor[2 x^2] + x == 5 && x > -10, x]


(*

{{x -> -2 + 2 Sqrt[2]}}

*)

Interestingly, there is no solution for $x<0$:

Solve[Abs[x^2 + 3 x] + Floor[2 x^2] + x == 5 && x < 0, x]


(*

{}

*)

as can be seen by this graph of $|x^2 + 3 x| + \lfloor 2 x^2 \rfloor + x - 5$:

Also, when I enter the equation in free-form WolframAlpha form in Mathematica the unique answer is returned.

Let's solve the first equation, $$f(x) = |x^2+3x| + \lfloor 2x^2 \rfloor + x = 5.$$ We note that when $x \le -3$, the LHS exceeds $5$, since $x^2 + 3x = x(x+3) \ge 0$, and $$\lfloor 2x^2 \rfloor + x - 5 > 2x^2 + x - 6 = (x+2)(2x-3) > 0.$$ When $x \ge 1$, the LHS again exceeds $5$, since in this case $f$ is clearly increasing and we have $f(x) \ge f(1) = 1+3+2+1 = 7 > 5$. So now let us restrict our attention to the interval $x \in (-3, 1)$. On the interval $[0,1/\sqrt{2})$ we have $$f(x) = x^2 + 3x + 0 + x = x^2 + 4x,$$ thus $$f(x) - 5 = (x-1)(x+5)$$ and this admits no roots. On the interval $[1/\sqrt{2},1)$ we have $$f(x) - 5 = x^2 + 4x - 4$$ which admits the unique root in this interval $$\boxed{x = 2(\sqrt{2}-1)}.$$ The negative case is handled similarly, noting that $|x^2 + 3x| = -(x^2 + 3x)$ whenever $-3 < x < 0$, and since $$\lfloor 2x^2 \rfloor = k, \quad x \in \left(-\sqrt{(k+1)/2}, -\sqrt{k/2}\right],$$ we have $$f(x) - 5 = -x^2 - 2x + k-5 = -(x + 1 + \sqrt{k-4})(x + 1 - \sqrt{k-4}).$$ Thus we seek integers $4 \le k \le 8$ such that $-\sqrt{k+1} < -\sqrt{2}(1 \pm \sqrt{k-4}) \le -\sqrt{k}$, or equivalently, $$0 \le k \pm 4\sqrt{k-4} - 6 < 1.$$ Simple trial evaluations yield no such $k$; therefore, the boxed solution is unique.

In Mathematica, the single command

Reduce[Abs[x^2 + 3 x] + Floor[2 x^2] + x == 5, x, Reals]


yields the solution

x == -2 + 2 Sqrt[2].


Typing in

Reduce[Floor[2 x^2] == x + 2, x, Reals]


gives

False


as expected.