HP Forums
is Python-syntax-in-CAS less accurate than PPL? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: is Python-syntax-in-CAS less accurate than PPL? (/thread-11484.html)



is Python-syntax-in-CAS less accurate than PPL? - StephenG1CMZ - 09-28-2018 07:48 PM

I have just attempted an implementation of the Savage benchmark using Python-syntax-in-CAS.
The results seem to be less accurate than the version implemented in PPL.
Is a loss of accuracy in Pythonesque to be expected?
Or have a mis-coded something?
http://www.hpmuseum.org/forum/thread-9626-post-104888.html#pid104888


RE: is Python-syntax-in-CAS less accurate than PPL? - Albert Chan - 09-28-2018 08:44 PM

Hi, StephenG1CMZ

Python range(1, 2499) == [1, 2, ..., 2498]

BTW, noticed all other benchmarks does not do indirect lookup via math.xxx
To be fair, Python version should do likewise.

atan, tan, ... = math.atan, math.tan, ... before use it inside loop


RE: is Python-syntax-in-CAS less accurate than PPL? - StephenG1CMZ - 09-28-2018 11:18 PM

Oh, silly me - I adjusted the 0 and overlooked the upper limit.

My thoughts on including the "math" prefix were to ensure I was getting "Python" tan, rather than conceivably being given the PPL tan or the CAS tan.

In pure Python I believe it should be more efficient to import once before the FOR loop, but I haven't got that to compile yet on the Prime.


RE: is Python-syntax-in-CAS less accurate than PPL? - Tim Wessman - 09-28-2018 11:31 PM

(09-28-2018 11:18 PM)StephenG1CMZ Wrote:  Oh, silly me - I adjusted the 0 and overlooked the upper limit.

My thoughts on including the "math" prefix were to ensure I was getting "Python" tan, rather than conceivably being given the PPL tan or the CAS tan.

In pure Python I believe it should be more efficient to import once before the FOR loop, but I haven't got that to compile yet on the Prime.

I don't believe there is a"python tan". Really, it is wrapping around CAS objects and functions with a pre-parser wrapper that compiles it to equivalent CAS syntax. It probably is just the equivalent internally of tan(<approx_num>) and so on.


RE: is Python-syntax-in-CAS less accurate than PPL? - Albert Chan - 09-28-2018 11:45 PM

(09-28-2018 11:18 PM)StephenG1CMZ Wrote:  My thoughts on including the "math" prefix were to ensure I was getting "Python" tan,
rather than conceivably being given the PPL tan or the CAS tan.

Python will not get confused with tan = math.tan
Python local variables always have priority over globals (even if global tan exist).

Is it even possible to call PPL/CAS tan directly from Python code ?
What happened if all the "math." were removed ?


RE: is Python-syntax-in-CAS less accurate than PPL? - parisse - 09-29-2018 05:37 AM

Nothing, tan or math.tan is the same. You don't need all the math import or math. stuff, they are just here to improve compatibility for people who would like to run existing Python scripts or are comfortable with Python and want to write Xcas programs.
Floating point numbers are CAS floats, i.e. 48 bits of mantissa instead of 53, therefore you will not have full accuracy but almost, like in CAS.


RE: is Python-syntax-in-CAS less accurate than PPL? - StephenG1CMZ - 09-29-2018 05:51 PM

I have now corrected that incorrect range, and removed all the unneccesary "math" references.
http://www.hpmuseum.org/forum/thread-9626.html
The Python syntax now not only seems more accurate, but also faster than the PPL version, which was unexpected.


RE: is Python-syntax-in-CAS less accurate than PPL? - cyrille de brébisson - 10-01-2018 05:47 AM

Hello,

CAS uses 56 bit floating point numbers (64 bits with 8 bits being taken over for some other information). Thus leading to a somewhat low precision (the idea being that if you want precision, you can use integers)...

PPL uses 64 bits BCD reals with 12 digits of mantissa.

So, PPL will always have higher precision on floating points than the CAS... Python or otherwise.

Cyrille


RE: is Python-syntax-in-CAS less accurate than PPL? - parisse - 10-01-2018 06:12 AM

(10-01-2018 05:47 AM)cyrille de brébisson Wrote:  Hello,

CAS uses 56 bit floating point numbers (64 bits with 8 bits being taken over for some other information). Thus leading to a somewhat low precision (the idea being that if you want precision, you can use integers)...

Actually it's 59 (48 bits of mantissa).


RE: is Python-syntax-in-CAS less accurate than PPL? - John Keith - 10-01-2018 11:42 AM

(10-01-2018 05:47 AM)cyrille de brébisson Wrote:  Hello,

CAS uses 56 bit floating point numbers (64 bits with 8 bits being taken over for some other information). Thus leading to a somewhat low precision (the idea being that if you want precision, you can use integers)...

PPL uses 64 bits BCD reals with 12 digits of mantissa.

So, PPL will always have higher precision on floating points than the CAS... Python or otherwise.

Cyrille

That's why it would be really great if the Prime CAS had something like LongFloat or the variable-precision floats of NewRPL.


RE: is Python-syntax-in-CAS less accurate than PPL? - Albert Chan - 10-01-2018 11:58 AM

(10-01-2018 05:47 AM)cyrille de brébisson Wrote:  PPL will always have higher precision on floating points than the CAS... Python or otherwise.

Although PPL had 64 bits, roughly speaking, it got 12 * 3.322 ~ 40 bits precision.
Due to roundings in decimals, PPL probably had even less precision than 40 bits.

For this Savage test, Python simulation, CAS float precision ~ 42 bits, PPL ~ 37 bits.
StephenG1CMZ Android emulator produce similar numbers.

PPL may eventually be more accurate, but it take huge chain of calculations ...