mersenneforum.org How to Get C files of PARI Functions?
 Register FAQ Search Today's Posts Mark Forums Read

 2020-03-21, 19:40 #1 Andrew99   Aug 2019 11 Posts How to Get C files of PARI Functions? I want to use 4 specific functions of elliptic curve of PARI/GP found in the folder in \pari2.11.3\src\functions\elliptic_curves, this folder can be downloaded (Stable version: pari-2.11.3.tar.gz) from below link - https://pari.math.u-bordeaux.fr/download.html But these functions do not have .c extension, but it is known that, PARI is a C library. I want use these function to call from python, so I need C version of these functions. So, where or how can I get C version of these functions? PS: When I say 4 specific functions, it could be any 4 from that folder, and exactly 4 of them, I hope, it is not important which 4 because procedure is same for all functions, also, I don't want use .dll file which has all the function.
 2020-03-22, 02:45 #2 CRGreathouse     Aug 2006 11×13×41 Posts You can get the files from version control. Many of the functions, for example, are in src/basemath/elliptic.c. But it's not trivial to pull the functions into Python, because the numbers aren't stored in the same format -- Python doesn't use PARI GENs. (This doesn't apply if you stick strictly to functions taking long and ulong values, and returning the same or void, but that won't apply to many elliptic functions.) You might consider using one ofto simplify this for you. If not, I suggest using gp2c to wrap the whole process from a declared long or ulong to your desired output to get at least a rough draft.
2020-03-22, 02:57   #3
Andrew99

Aug 2019

11 Posts

Quote:
 Originally Posted by CRGreathouse You can get the files..... But it's not trivial to pull the functions into Python, because the numbers aren't stored in the same format -- Python doesn't use PARI GENs. (This doesn't apply if you stick strictly to functions taking long and ulong values, and returning the same or void, but that won't apply to many elliptic functions.) You might consider using one ofto simplify this for you. If not, I suggest using gp2c to wrap the whole process from a declared long or ulong to your desired output to get at least a rough draft.
The problem is I can't find any documentation on how to use cypari, I can't install cypari2 due to cysignals, pari-python is too old.

Could you plz guide me how to pass a vector/array into PARI using python by calling a finction of PARI through the use of ctypes?

And do you have any information about the documents on cypari? Thanks.

Last fiddled with by Andrew99 on 2020-03-22 at 02:57

 2020-03-22, 03:04 #4 Andrew99   Aug 2019 11 Posts We have something like below - import ctypes # load the library pari=ctypes.cdll.LoadLibrary("libpari.so") # set the right return type of the functions pari.stoi.restype = ctypes.POINTER(ctypes.c_long) pari.nextprime.restype = ctypes.POINTER(ctypes.c_long) # initialize the library pari.pari_init(2**19,0) def nextprime(v): g = pari.nextprime(pari.stoi(ctypes.c_long(v))) # nextprime(argument) is a PARI function return pari.itos(g) print( nextprime(456) ) For example I tried - h=(0,0,0, 4,6) pari.stoi.restype = ctypes.POINTER(ctypes.c_long*5) pari.ellinit.restype = ctypes.POINTER(ctypes.c_long) def ellinit(v): g = pari.ellinit(pari.stoi(ctypes.c_long(v)*5)) return pari.itos(g) print(ellinit(h)) I got below error - File "C:\Users\miron\Desktop\trash5\x\f.py", line 68, in print( ellinit(h) ) File "C:\Users\miron\Desktop\trash5\x\f.py", line 62, in ellinit g = pari.ellinit(pari.stoi(ctypes.c_long(v)*5)) TypeError: an integer is required (got type tuple) How do I pass a tuple/array/vector? Thanks.
2020-03-22, 05:43   #5
CRGreathouse

Aug 2006

11×13×41 Posts

Quote:
 Originally Posted by Andrew99 How do I pass a tuple/array/vector? Thanks.
This is not a simple question to answer for PARI in general (you get into issues of the stack and universal objects). But for what you are doing, the correct PARI code, I believe, is

Code:
retmkvec5(gen_0, gen_0, gen_0, utoipos(4), utoipos(6))
I'll let you translate that into the appropriate python code.

 Similar Threads Thread Thread Starter Forum Replies Last Post enzocreti enzocreti 7 2020-02-28 08:50 Xyzzy Forum Feedback 3 2018-12-30 19:37 Raman Math 5 2011-04-13 23:29 devarajkandadai Miscellaneous Math 3 2009-02-08 14:54 Dougy Miscellaneous Math 4 2006-02-22 20:59

All times are UTC. The time now is 04:56.

Fri Aug 7 04:56:10 UTC 2020 up 21 days, 42 mins, 1 user, load averages: 1.41, 1.76, 1.83