Bug 409472 - Wrong result coming from calculator and plotter
Summary: Wrong result coming from calculator and plotter
Status: REPORTED
Alias: None
Product: kalgebra
Classification: Applications
Component: general (show other bugs)
Version: 0.11
Platform: Fedora RPMs Linux
: NOR grave
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-03 18:28 UTC by Emanuele Spirito
Modified: 2022-07-22 05:32 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
You can see the wrong plot of the function x^(1/3) (33.36 KB, image/png)
2019-07-03 18:28 UTC, Emanuele Spirito
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Emanuele Spirito 2019-07-03 18:28:40 UTC
Created attachment 121313 [details]
You can see the wrong plot of the function x^(1/3)

SUMMARY
The software "KAlgebra" gives bad results both in the calculation mode and in the graphical mode

STEPS TO REPRODUCE
1. Open KAlgebra
2. Go to the section "2D plot"
3. Then try to plot the following function: f(x) = x^(1/3), by writing in the text box on the right, just below the word "Function". 
4. The result can be reproduced exactly in the same way by going to the section "Calculator" instead of "2D plot" and trying to calculate the following expression: (-2)^(1/3)

OBSERVED RESULT
The function plotted in the 2D plot is given in the attachment. For the calculator mode we find the result 0.629960524947 

EXPECTED RESULT
The value of the result in the calculator mode should be -1.25992105 so the result given was wrong both in the absolute value and in the sign. The correct function plotted in the 2D plot should have been an odd function and for x < 0 should be negative 

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Fedora 30
(available in About System)
KDE Plasma Version: 5.15.5
KDE Frameworks Version: 5.59.0
Qt Version: 5.12.1

ADDITIONAL INFORMATION
Comment 1 Christoph Feck 2019-07-25 10:50:14 UTC
(-2)^(1/3) isn't mathematically defined. What you want is -(2^(1/3)).
Comment 2 Christoph Feck 2019-07-25 10:53:53 UTC
Actually, a^b with a < 0 and b not integral usually gives a complex number. It's possible that the code just doesn't handle this.
Comment 3 David 2019-07-25 14:25:22 UTC
(In reply to Christoph Feck from comment #1)
> (-2)^(1/3) isn't mathematically defined. What you want is -(2^(1/3)).

This is actually not true. Given an odd function f(x)=xⁿ, n an odd integer or n a fraction a/b with b an odd integer, implies f(-x)=-f(x) ∀x in the domain of f. 
Hence saying "(-2)^(1/3) is -(2^(1/3))" does not add any further information  
to what the definition already says.
With regard to the calculator only, do you think is possible for kalgebra to use such a property to correctly & easily compute xⁿ for x<0?
Comment 4 David 2019-07-25 14:43:01 UTC
(In reply to Christoph Feck from comment #2)
> Actually, a^b with a < 0 and b not integral usually gives a complex number.
> It's possible that the code just doesn't handle this.

Sorry man, this isn't true either. Even thinking of the Complex set, you'd have that the cubic root of a negative Real number (that is, a complex of argument π) has 3 solutions, each 120° or 2π/3 from the others. 
In other words, √³(-x), x>0, has 3 solutions in C, one at π/3, one at π/3+2π/3=π, the last at 5π/3. The one at π clearly representing a negative Real number.
That has to be the solution to your problem, if you consider the problem from a C prospective. Considering the Real set as well, an odd function always accepts negative arguments because of the very definition of odd function.
Comment 5 Alexander Kernozhitsky 2020-03-07 21:36:49 UTC
It seems to be duplicate of https://bugs.kde.org/show_bug.cgi?id=402637.
Comment 6 Bob M 2022-07-22 05:32:14 UTC
I'm having a similar problem. 
y=3*x^2+6 and y=2*x^2+6 both plot as expected.

But y=1*(x^2+2),  y=2*(x^2+2),  y=3*(x^2+2) and y=4*(x^2+2) all plot incorrectly and overlap - showing the same result.

So if I expand the parentheses, they are correct, and if I leave kalgebra to do BODMAS, it fails.

There may be some undocumented limitation in using parentheses.