Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active June 14, 2023 09:59
Show Gist options
  • Save Hermann-SW/f17e58b2df76b64da63e50e7402765e0 to your computer and use it in GitHub Desktop.
Save Hermann-SW/f17e58b2df76b64da63e50e7402765e0 to your computer and use it in GitHub Desktop.
Python script for testing making use of cypari2 if available
from sympy import gcd, I
try:
import cypari2
pari = cypari2.Pari()
gen_to_python = cypari2.convert.gen_to_python
except ImportError:
cypari2 = None
if cypari2 is None:
def to_sum2sqs(sqrtm1, p):
return gcd(p, sqrtm1 + I).as_real_imag()
else:
def to_sum2sqs(sqrtm1, p):
print("pari")
[M, V] = pari.halfgcd(sqrtm1, p)
return gen_to_python(V[1]), gen_to_python(M[1, 0])
def to_sqrtm1(xy, p):
return xy[0] * pow(xy[1], -1, p) % p
@Hermann-SW
Copy link
Author

Hermann-SW commented Jun 14, 2023

Type "help", "copyright", "credits" or "license" for more information.
>>> from cypari2_ import *
>>> to_sqrtm1((6, -5), 61)
11
>>> to_sum2sqs(11, 61)
pari
(6, -5)
>>> to_sqrtm1(to_sum2sqs(11, 61), 61)
pari
11
>>> to_sum2sqs(to_sqrtm1((6, -5), 61), 61)
pari
(6, -5)
>>> 

Does not neccessarily result in identity:

>>> to_sum2sqs(to_sqrtm1((5, 6), 61), 61)
pari
(6, -5)
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment