Post Reply 
is Python-syntax-in-CAS less accurate than PPL?
09-28-2018, 07:48 PM
Post: #1
is Python-syntax-in-CAS less accurate than PPL?
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-962...#pid104888

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-28-2018, 08:44 PM (This post was last modified: 09-28-2018 08:57 PM by Albert Chan.)
Post: #2
RE: is Python-syntax-in-CAS less accurate than PPL?
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
Find all posts by this user
Quote this message in a reply
09-28-2018, 11:18 PM
Post: #3
RE: is Python-syntax-in-CAS less accurate than PPL?
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
09-28-2018, 11:31 PM
Post: #4
RE: is Python-syntax-in-CAS less accurate than PPL?
(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.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
09-28-2018, 11:45 PM
Post: #5
RE: is Python-syntax-in-CAS less accurate than PPL?
(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 ?
Find all posts by this user
Quote this message in a reply
09-29-2018, 05:37 AM (This post was last modified: 09-29-2018 05:39 AM by parisse.)
Post: #6
RE: is Python-syntax-in-CAS less accurate than PPL?
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.
Find all posts by this user
Quote this message in a reply
09-29-2018, 05:51 PM (This post was last modified: 09-29-2018 05:54 PM by StephenG1CMZ.)
Post: #7
RE: is Python-syntax-in-CAS less accurate than PPL?
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.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
10-01-2018, 05:47 AM
Post: #8
RE: is Python-syntax-in-CAS less accurate than PPL?
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
10-01-2018, 06:12 AM
Post: #9
RE: is Python-syntax-in-CAS less accurate than PPL?
(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).
Find all posts by this user
Quote this message in a reply
10-01-2018, 11:42 AM
Post: #10
RE: is Python-syntax-in-CAS less accurate than PPL?
(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.
Find all posts by this user
Quote this message in a reply
10-01-2018, 11:58 AM (This post was last modified: 10-01-2018 03:20 PM by Albert Chan.)
Post: #11
RE: is Python-syntax-in-CAS less accurate than PPL?
(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 ...
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)