mersenneforum.org  

Go Back   mersenneforum.org > Math Stuff > Computer Science & Computational Number Theory > PARI/GP

Reply
 
Thread Tools
Old 2020-03-21, 19:40   #1
Andrew99
 
Aug 2019

11 Posts
Default 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.
Andrew99 is offline   Reply With Quote
Old 2020-03-22, 02:45   #2
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

22×5×293 Posts
Default

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.
CRGreathouse is offline   Reply With Quote
Old 2020-03-22, 02:57   #3
Andrew99
 
Aug 2019

11 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
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
Andrew99 is offline   Reply With Quote
Old 2020-03-22, 03:04   #4
Andrew99
 
Aug 2019

11 Posts
Default

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 <module>
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.
Andrew99 is offline   Reply With Quote
Old 2020-03-22, 05:43   #5
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

22·5·293 Posts
Default

Quote:
Originally Posted by Andrew99 View Post
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.
CRGreathouse is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two variable functions enzocreti enzocreti 7 2020-02-28 08:50
Posting log files or other text files Xyzzy Forum Feedback 3 2018-12-30 19:37
Inverse of functions Raman Math 5 2011-04-13 23:29
Return to failure functions devarajkandadai Miscellaneous Math 3 2009-02-08 14:54
Busted functions Dougy Miscellaneous Math 4 2006-02-22 20:59

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

Sun Jun 7 04:11:29 UTC 2020 up 74 days, 1:44, 0 users, load averages: 1.72, 1.57, 1.31

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.