Hi, what is the logic here (example from ginsh)?
real_part(sqrt(-3)); sqrt(-3) imag_part(sqrt(-3)); 0
real_part(sqrt(-1)); 0 imag_part(sqrt(-1)); 1
Greetings, Jan
On Tue, 8 Aug 2017 20:15:07 +0200, Jan Rheinländer <jrheinlaender@gmx.de> said:
JR> Hi, what is the logic here (example from ginsh)? >> real_part(sqrt(-3)); JR> sqrt(-3) >> imag_part(sqrt(-3)); JR> 0 >> real_part(sqrt(-1)); JR> 0 >> imag_part(sqrt(-1)); JR> 1 The problems seems to be in CLN library, since for the GiNaC::numeric object sqrt(-3), real_part() and imag_part() are simply calling cln::realpart() and cln::imagpart(). -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
On 08/09/2017 09:12 AM, Vladimir V. Kisil wrote:
On Tue, 8 Aug 2017 20:15:07 +0200, Jan Rheinländer <jrheinlaender@gmx.de> said:
JR> Hi, what is the logic here (example from ginsh)?
>> real_part(sqrt(-3)); JR> sqrt(-3) >> imag_part(sqrt(-3)); JR> 0
>> real_part(sqrt(-1)); JR> 0 >> imag_part(sqrt(-1)); JR> 1
The problems seems to be in CLN library, since for the GiNaC::numeric object sqrt(-3), real_part() and imag_part() are simply calling cln::realpart() and cln::imagpart().
sqrt(-1) straightly evaluates to I, which works. But sqrt(-3) isn't a numeric object. Rather, it is a power(-3,1/2). Seems to me like the logic in power::real_part() and power::imag_part() can be improved: https://www.ginac.de/ginac.git/?p=ginac.git;a=blob;f=ginac/power.cpp;h=26194... -richy. -- Richard B. Kreckel <https://in.terlu.de/~kreckel/>
On Wed, 9 Aug 2017 10:30:09 +0200, "Richard B. Kreckel" <kreckel@in.terlu.de> said: RK> sqrt(-1) straightly evaluates to I, which works. But sqrt(-3) RK> isn't a numeric object. Rather, it is a power(-3,1/2).
On my computer I have: sqrt(numeric(-3)).dbgprinttree(); pow(numeric(-3),numeric(1,2)).dbgprinttree(); both returning 1.7320508075688772936L0i (numeric) @0xbfcc45f0, hash=0x800d7056, flags=0x6 and power(numeric(-3),numeric(1,2)).dbgprinttree(); returning power @0xbfc551dc, hash=0x800cf188, flags=0x0, nops=2 -3 (numeric) @0x81748b38, hash=0x1, flags=0x7 1/2 (numeric) @0x81748bb8, hash=0x1, flags=0x7 RK> Seems to me like the logic in power::real_part() and RK> power::imag_part() can be improved: You are right, the power did it wrongly cout << power(numeric(-3),numeric(1,2)).real_part() << endl; // -> sqrt(-3) cout << power(numeric(-3),numeric(1,2)).imag_part() << endl; // -> 0 I will look into it. -- Vladimir V. Kisil http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://goo.gl/EaG2Vu Software: Geometry of cycles http://moebinv.sourceforge.net/
participants (3)
-
Jan Rheinländer
-
Richard B. Kreckel
-
Vladimir V. Kisil