python libraries
|
04-20-2021, 11:49 AM
Post: #1
|
|||
|
|||
python libraries
Goodmorning everyone.
In the HP PRIME calculator, how do you import python libraries? For example: how do I import the scipy library, or the numpy library? Best regards, Roberto. |
|||
04-20-2021, 05:21 PM
Post: #2
|
|||
|
|||
RE: python libraries
Standard libraries aren't compatible AFAIK, but KhiCAS includes facsimiles of Numpy, Scipi and MatPlotLib so maybe Bernard might be willing to share them with the HP team (not that MatPlotLib is required).
|
|||
04-21-2021, 02:20 PM
Post: #3
|
|||
|
|||
RE: python libraries
Inside Khicas, Numpy compatibility is provided by a Pythons script file that translate some Numpy commands into linalg commands (linalg is a native library I wrote for MicroPython). Unfortunately, Numpy would not be compatible because HP Micropython version is too old, version 1.12 at least is required. My personal opinion about Numpy is that it's more complicated to use than call natively Prime or Xcas commands.
Matplotlib compatibility inside KhiCAS is done using a native graphic library I wrote for Micropython. Matplotl requires that micropython is linked with giac, which also means that graphic knows how to draw on the Prime. I believe the best here is to get Casio matplotlib Python file and replace the basic graphic casioplot calls with HP Prime calls. |
|||
04-22-2021, 11:17 AM
Post: #4
|
|||
|
|||
RE: python libraries
Hello,
Using the con kit, you can add files to an app (a python derivated app in this case). Then you can use the files using import fileName Of course, only pure python files will be supported. Modules that rely on a native library will not work as there is no native support in Prime. If your aim is to do math, I would suggest that you use the build in calculator features, which are very well designed and work well together and work well with the calculator UI and keyboard. Are they python libraries that would be beneficial to add to prime that I could add? 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. |
|||
04-22-2021, 12:44 PM
Post: #5
|
|||
|
|||
RE: python libraries
(04-22-2021 11:17 AM)cyrille de brébisson Wrote: Hello, Numpy, Pandas, Scipi and Patsy would be my request but as Bernard mentions, some may lack compatibility due to the version of MicroPython that's currently being utilised on the Prime. On reflection, I also like Bernards idea of utilising his Casio customisation of MatPlotLib with HP draw calls as it would provide greater flexibility. Plotly is my favourite math/sci/stats oriented graphics package but I'm not sure whether there's much within it that can be converted for calculator use cases. I'm making an assumption that any math functions that are pure python will be more performant than math functions that involve roundtrips via PPL/CAS (this seemed to be evidenced by the TI Planet post). |
|||
04-22-2021, 01:07 PM
Post: #6
|
|||
|
|||
RE: python libraries
Scipy has a lot of functions that are not in the Prime CAS like Lambert W and Airy. It would be nice to have them available.
-road |
|||
04-22-2021, 01:28 PM
Post: #7
|
|||
|
|||
RE: python libraries
(04-22-2021 11:17 AM)cyrille de brébisson Wrote: Are they python libraries that would be beneficial to add to prime that I could add? It would help if we could import the time module so the monotonic time functions would be accessible. Tom L Cui bono? |
|||
04-22-2021, 03:07 PM
Post: #8
|
|||
|
|||
RE: python libraries
(04-22-2021 01:07 PM)roadrunner Wrote: Scipy has a lot of functions that are not in the Prime CAS like Lambert W and Airy. It would be nice to have them available. LambertW is available in giac and has it's own implentation. Airy_Ai and Bi are in giac but they are using GSL for numeric evaluation. |
|||
04-22-2021, 04:11 PM
Post: #9
|
|||
|
|||
RE: python libraries | |||
04-22-2021, 04:24 PM
Post: #10
|
|||
|
|||
RE: python libraries
Although the "HP PRIME" G2 calculator is very fast, when it calculates the integral to obtain the "Studentize q Rance distribution CDF" function, it takes about 33 seconds. Is there a way, with Python, to reduce the computation time of this function?
#cas Studentized_Range_q_P_Value(q,k,ν):= BEGIN LOCAL funzione; funzione:=(√(2*π)*k*ν^(ν/2))/ (Gamma(ν/2)*2^(ν/2-1))*∫(s^(ν-1)* e^((-ν*s^2/2))/(√(2*π))*∫(e^((-z^2)/2)/ (√(2*π))*(normald_cdf(0,1,z+q*s)- normald_cdf(0,1,z))^(k-1),z, -(∞),+∞),s,0,+∞); RETURN 1-funzione; END; #end This is one of the reasons why I asked if HP PRIME can "import" the Scipy library, Numpy or scipy.integrate (see https://www.youtube.com/watch?v=lzp48-AzUO0). Best regards, Roberto |
|||
04-22-2021, 04:38 PM
Post: #11
|
|||
|
|||
RE: python libraries
(04-22-2021 03:07 PM)parisse Wrote: LambertW is available in giac and has it's own implentation. Airy_Ai and Bi are in giac but they are using GSL for numeric evaluation. Yet again I find myself salivating for the standalone version of XCAS/GIAC on the Prime. For those who feel we already have the majority of the meaningful stuff in the native CAS, let's not forget that your ace Longfloat library is also available, which beats Swissmicros claim of the DM42 as being the worlds most precise calculator (and by some margin too if one wishes)! One of the reasons I still turn to the 50g so much is Longfloat (a different author I believe). But that really is the tortoise to the XCAS Longfloat hare on a modern ARM processor... |
|||
04-22-2021, 06:58 PM
Post: #12
|
|||
|
|||
RE: python libraries
(04-22-2021 04:24 PM)robmio Wrote: Although the "HP PRIME" G2 calculator is very fast, when it calculates the integral to obtain the "Studentize q Rance distribution CDF" function, it takes about 33 seconds. Is there a way, with Python, to reduce the computation time of this function?I don't think that any Python scientific library is faster than my own adaptive numeric integration algorithm with the same accuracy (for multiple integrals Monte-Carlo like methods will be much faster but much less accurate). You can try to optimize your call. For example if your bounds are infinity (something that is impossible with a non-CAS language like Python), the CAS will do a change of variable to have finite boundaries, and this might slow down the computation compared to taking reasonable finite boundaries, e.g. z=-10.0 to 10.0 in the inner integral. You could try: Code:
Of course this will be much slower than a good implementation of a special function using for example series expansion for some range of arguments, and asymptotic expansion for other ranges, or Tchebyscheff polynomial approximations, etc. And MicroPython is not Python, porting any (large) library to MicroPython to the Prime would require work. It's much easier to port a C library with the same functionnalities, for example blas+lapack instead of numpy. |
|||
04-23-2021, 05:13 AM
Post: #13
|
|||
|
|||
RE: python libraries
(04-22-2021 06:58 PM)parisse Wrote: And MicroPython is not Python, porting any (large) library to MicroPython to the Prime would require work. It's much easier to port a C library with the same functionnalities, for example blas+lapack instead of numpy. I always understood MicroPython to be closely related to Cython but Cyrille did ask. |
|||
04-23-2021, 05:51 AM
Post: #14
|
|||
|
|||
RE: python libraries
I should have said: MicroPython is not CPython. Cython is a tool for CPython, i.e. translating existing Python code to C for speed reasons and make the bindings. The reason behind is that Python interpreters are slow, for example compared to Javascript interpreters, and are really slow compared to native code. Cython is a way for Python programmers who do not want to learn a compiled language to improve the speed of their code. I'm not convinced it's a good idea, some developers like Python a lot because they have a lot of tools easily available, but the drawback is that complexity is hidden, and auto-translating code that has bad complexity to C will not make the complexity any better. And even if your code has the right complexity, it has probably a style that once translated will not be full optimized.
But anyway that's not what would have to be done here: numpy is a collection of CPython bindings to existing C code (blas+lapack). Porting it to MicroPython means a complete rewrite of the bindings. Below is a partial listing of the code I'm using to emulate some Numpy commands. As you can see it is really MicroPython code, I don't think you can automatically get this from CPython code. Code:
|
|||
04-23-2021, 09:23 AM
(This post was last modified: 04-23-2021 09:26 AM by jonmoore.)
Post: #15
|
|||
|
|||
RE: python libraries
Bernard, out of interest. How much of Numpy and Scipi did you 'clone' for the Ndless version of XCAS/Giac? And on the subject of Cython/Cpython, don't the developers of SageMath use the optimisations you discuss in your last post to optimise certain aspects of SageMath inclusive of those that utilise Giac?
|
|||
04-23-2021, 10:54 AM
Post: #16
|
|||
|
|||
RE: python libraries
(04-23-2021 09:23 AM)jonmoore Wrote: Bernard, out of interest. How much of Numpy and Scipi did you 'clone' for the Ndless version of XCAS/Giac?It's hard to answer, because I do not know numpy and scipy myself. I just looked at some scripts for schools and tried to make them compatible. A little bit like Python syntax in Xcas, but I tested much less, because in the meantime I decided it was not worth the time required to have something more compatible. The guys who have imposed Python as the unique langage in French highschools are mostly closed-minded, they will probably never consider Xcas to be an alternative to Python for programming in math classes despite my efforts. And if are already using Xcas, it's much easier to run the native commands of Xcas than using all these Python modules. Quote:And on the subject of Cython/Cpython, don't the developers of SageMath use the optimisations you discuss in your last post to optimise certain aspects of SageMath inclusive of those that utilise Giac?Giac is interfaced to CPython with Cython, independently from Sage, you can import giacpy from Python if you install giacpy. I don't know if all C libraries are interfaced using cython inside Sagemath, probably. My opinion is that Sagemath "Python as a common basis" choice is wrong, because if you want to use their code inside your code, then you must interface with Python. It means that C libraries inside Sagemaths can not talk together unless they have their own interface. Inside Sage, at the Python level, you can choose one algorithm or another one, but once you are in non Python code (e.g. Maxima code because Sage does not have calculus itself, or C code because Python is slow), you can not benefit from other parts of the whole system (for example your C code can not benefit from other C libraries included in Sage unless you wrote your own interface to these other C libraries, or Maxima code does not benefit from fast linear algebra). You must write Python code to benefit from Sage and it will be useful to Python programmers only. I believe that the choice should have been to make C libraries talk together, because it does not make assumptions on the caller language. |
|||
04-23-2021, 11:08 AM
Post: #17
|
|||
|
|||
RE: python libraries | |||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)