Bug 402637 - KAlgebra produces wrong output on functions like root(x, 3) or x^(1/3)
Summary: KAlgebra produces wrong output on functions like root(x, 3) or x^(1/3)
Status: RESOLVED FIXED
Alias: None
Product: kalgebra
Classification: Applications
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Aleix Pol
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-28 10:45 UTC by Alexander Kernozhitsky
Modified: 2020-03-16 18:11 UTC (History)
1 user (show)

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


Attachments
Screenshot (69.35 KB, image/png)
2018-12-28 10:45 UTC, Alexander Kernozhitsky
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kernozhitsky 2018-12-28 10:45:46 UTC
Created attachment 117143 [details]
Screenshot

SUMMARY


STEPS TO REPRODUCE
Try to make plots for functions like x^(1/3) or root(x, 3) in KAlgebra.

Also (-8)^(1/3) gives 1, not -2.

OBSERVED RESULT

See the screenshot attached.

EXPECTED RESULT

The function plot looks properly, and (-8)^(1/3) gives -2 as a result.

ADDITIONAL INFORMATION

This seems to be a bug in Qalculate, which is used by KAlgebra, because qalc gives the following as a result:

$ qalc 
> (-8)^(1/3)

  (-8)^(1 / 3) = approx. 1 + 1,7320508i
Comment 1 Alexander Kernozhitsky 2018-12-28 10:55:21 UTC
So, basically, there are two issues:

1) If qalculate returns complex number, KAlgebra uses only its real part, which produces wrong answer

2) root(-8;3) = -2 in qalculate, but seems that root(x;y) is implemented via x^(1/y) in KAlgrebra, so the same bug here.
Comment 2 Aleix Pol 2020-03-10 02:18:35 UTC
KAlgebra doesn't use qalc, yet we probably use the same API hence the same behaviour.
https://en.cppreference.com/w/cpp/numeric/complex/pow

Even wolfram shows it:
https://www.wolframalpha.com/input/?i=%28-8%29%5E%281%2F3%29&assumption=%22%5E%22+-%3E+%22Principal%22

Under the "decimal approximation" section.

Now this doesn't make much sense, will need to investigate further why it happens, brush off some knowledge I haven't used in a while...
Comment 3 MatFi 2020-03-10 20:09:31 UTC
> Even wolfram shows it:
>https://www.wolframalpha.com/input/?i=%28-8%29%5E%281%2F3%29&assumption=%22%5E%22+-%3E+%22Principal%22

depends on what sort of root you want to take (real or principal)
https://www.wolframalpha.com/input/?i=%28-8%29%5E%281%2F3%29&assumption=%22%5E%22+-%3E+%22Real%22

actually the situation is described here
https://mathworld.wolfram.com/nthRoot.html
Comment 4 Aleix Pol 2020-03-16 18:11:26 UTC
Git commit 02fe404a8ff550d3b39f758b24d7eb697788078f by Aleix Pol.
Committed on 16/03/2020 at 18:11.
Pushed by apol into branch 'master'.

Provide a realpower command

Allows getting results such as root(-8, 1/3)=-2, with root(-8,1/3) we
get the complex root which is less fun to work with.

M  +1    -0    analitza/CMakeLists.txt
M  +2    -0    analitza/analyzer.cpp
A  +47   -0    analitza/commands/realpower.cpp     [License: GPL (v2+)]
A  +33   -0    analitza/commands/realpower.h     [License: GPL (v2+)]
M  +5    -3    analitza/operations.cpp
M  +2    -1    analitza/tests/analitzatest.cpp
M  +2    -0    analitza/tests/builtintest.cpp
M  +3    -2    analitza/value.h

https://commits.kde.org/analitza/02fe404a8ff550d3b39f758b24d7eb697788078f