Python syntax time functions in cas
09-07-2019, 01:44 PM (This post was last modified: 09-07-2019 01:46 PM by Stevetuc.)
Post: #1
 Stevetuc Member Posts: 128 Joined: Jan 2014
Python syntax time functions in cas
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
https://tiplanet.org/forum/viewtopic.php...0&start=70

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
Code:
 #cas def timep: start = monotonic() wait(1) stop=monotonic() return stop-start #end

timep returns lambda NULL:monotonic

Any thoughts?
09-07-2019, 06:48 PM (This post was last modified: 09-07-2019 07:25 PM by jebem.)
Post: #2
 jebem Senior Member Posts: 1,311 Joined: Feb 2014
RE: Python syntax time functions in cas
Hi,

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() ?

Jose Mesquita

09-07-2019, 07:32 PM
Post: #3
 Stevetuc Member Posts: 128 Joined: Jan 2014
RE: Python syntax time functions in cas
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.
09-07-2019, 08:10 PM (This post was last modified: 09-08-2019 08:31 AM by StephenG1CMZ.)
Post: #4
 StephenG1CMZ Senior Member Posts: 784 Joined: May 2015
RE: Python syntax time functions in cas
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:MMS 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
TEVAL(this-code)/1_s
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..
Code:
  Def monotonic:  RETURN time()  Or: Def monotonic:  RETURN TICKS/1000.0 //not monotonic Or: Def monotonic:  RETURN Time() //not seconds - needs formatting Or: Def thiscode:  Wait(1) TEVAL(this code)

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

Stephen Lewkowicz (G1CMZ)
09-08-2019, 06:57 AM (This post was last modified: 09-08-2019 01:03 PM by Stevetuc.)
Post: #5
 Stevetuc Member Posts: 128 Joined: Jan 2014
RE: Python syntax time functions in cas
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:
time(seuil(0.008))
(See https://tiplanet.org/forum/viewtopic.php...0&start=70 for details)
09-09-2019, 06:12 AM
Post: #6
 parisse Senior Member Posts: 1,013 Joined: Dec 2013
RE: Python syntax time functions in cas
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.
09-09-2019, 11:42 AM
Post: #7
 compsystems Senior Member Posts: 1,164 Joined: Dec 2013
RE: Python syntax time functions in cas
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.

LO SUFICIENTEMENTE BUENO ES ENEMIGO DE LA EXCELENCIA.
 « Next Oldest | Next Newest »

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