HP Forums
Python syntax time functions in cas - 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: Python syntax time functions in cas (/thread-13601.html)

Python syntax time functions in cas - Stevetuc - 09-07-2019 01:44 PM

Using python syntax in the cas,(how)is it possible to reference monotonic() or timed.monotonic functions?

I am trying to run some python benchmarks from

See final post on that page for listings.
Im having problems getting the 3rd listing in python syntax to return valid timings and it seems that monotonic(), which is a python time function , isnt recognised.

I also tried

def timep:
start = monotonic()
return stop-start

timep returns lambda NULL:monotonic

Any thoughts?

RE: Python syntax time functions in cas - jebem - 09-07-2019 06:48 PM


No expert here, curious to see what Parisse comments are.
I did a quick test and got the impression that monotonic() is not implemented.

There are some posts in this forum where Parisse said that a limited python parser was implemented in the HP Prime and that would be enough for the school students in most cases.
However I also remember Parisse commenting that all Prime functions could be used in a python style program.

So, maybe "time()" or TICKS() - without arguments - could be used instead of monotonic() ?

Note: edited to add TICKS()

RE: Python syntax time functions in cas - Stevetuc - 09-07-2019 07:32 PM

Thanks Jose
I can use time() or TICKS() but I wanted to try the monotonic() function since on the website I referenced, the code that was used to benchmark the prime uses monotonic, but I cannot get it to work.

I'll also post a query on that website, and it will be interesting if Parisse can comment.

RE: Python syntax time functions in cas - StephenG1CMZ - 09-07-2019 08:10 PM

I assume that monotonic is not implemented.

There are four alternatives that could be used on the HP Prime if you allow PPL syntax within Python syntax.

First, how important is it to you that the solution is always monotonic? For those unfamiliar with the term, it means that the solution is always positive (i.e. Unlike most Ticks implementations, which eventually wrap around from a large positive to a large negative). Is that a requirement of your solution, or just something in the original code? Put simply, will a simple Ticks suffice or do you need perfection?

The PPL syntax available is:

TEVAL(this-code): Monotonic. Time in seconds to execute this-code (a function or command).
TiCKS() : Non-monotonic. Result in milliseconds.
Time() : Monotonic (when used together with Date() ). Formatted HH:MMConfusedS result.
time() : undocumented. Possibly seconds since switch-on - if so, monotonic.
(Update: time() with no parameters seems to return a numbers of seconds, but time(this code) can also be used, like TEVAL)

The easiest solution may be to use time(), but I have not found any documentation on it.

An alternative solution is to use Ticks.
This will work with the rest of the code unmodified if you can accept errors when Ticks wraps. You could add code to check whether stop is greater than start.

TEVAL is monotonic but requires the code to be restructured. Expected syntax is
So you would need to wrap that Wait() inside the TEVAL.
The /1_s removes the units.

Time() is monotonic if used in conjunction with Date() (or if you avoid working at midnight) but the results are formatted as HHMMSS so the subtraction would need some parsing..
Def monotonic:
 RETURN time() 
Def monotonic:
 RETURN TICKS/1000.0 //not monotonic
Def monotonic:
 RETURN Time() //not seconds - needs formatting
Def thiscode:

TEVAL(this code)

Apologies for lower case/upper case difficulties: My spell checker is powerful.

RE: Python syntax time functions in cas - Stevetuc - 09-08-2019 06:57 AM

Thanks for the very informative post Stephen.
You are correct that im trying to run the original code, as it was posted on Tiplanet.org as the timing mechanism in a Python syntax benchmark comparing Prime to Mathworks and others.

I could not get the file to give valid timings and this led me to check monotonic() function.
I have posted requesting help on that website and will link any response back here.

Edit: well, its now cleared up.monotonic does not work in prime python syntax. It was left in the benchmark program though non functioning.
Timing was handled on the command line by calling function as:
(See https://tiplanet.org/forum/viewtopic.php?f=97&t=22870&start=70 for details)

RE: Python syntax time functions in cas - parisse - 09-09-2019 06:12 AM

monotonic is not available on the Prime (if you type monotonic on the commandline it is returned as an identifier, not as a commandname), the firmware is too old compared to the current source code of Giac (this is also unfortunately true for some Python-like syntaxic constructions).
You can run time(...) to get timings. A shortcut is to write your command followed by the Sto key and the , key, that's probably the easiest way to do benchmarking.

RE: Python syntax time functions in cas - compsystems - 09-09-2019 11:42 AM

Next month is 1 year of the latest version of the hp-prime firmware, possibly the version 1.5.0-63 or higher of Xcas is included.