Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to cypari2 #1

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions realalg/algebraic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
from math import log10 as log
from numbers import Integral

import cypari as cp
import sympy as sp
try:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently of the installation procedure, this try/except in the code is an improvement!

import cypari2
cp = cypari2.Pari()
except ImportError:
try:
import cypari
cp = cypari.pari
except ImportError:
raise Exception("You need to install cypari or cypari2 to use the realalg module. Try pip install cypari2.")

from .interval import Interval

sp_x = sp.Symbol('x')
cp_x = cp.pari('x')
cp_x = cp('x')

def log_plus(x):
''' Return the height of the number ``x``. '''
Expand All @@ -24,7 +32,7 @@ def sp_polynomial(coefficients):

def cp_polynomial(coefficients):
''' Return the cypari polynomial with the given coefficients. '''
return cp.pari(' + '.join('{}*x^{}'.format(coefficient, index) for index, coefficient in enumerate(coefficients)))
return cp(' + '.join('{}*x^{}'.format(coefficient, index) for index, coefficient in enumerate(coefficients)))

class RealNumberField(object):
''' Represents the NumberField QQ(lmbda) = QQ[x] / << f(x) >> where lmbda is a real root of f(x). '''
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

from setuptools import setup, find_packages

# We need one of cypari or cypari2 to interface with PARI. Since we do not
# want to lock in the user to either version explicitly, we do not add a
# dependency here but complain at runtime if neither can be found.
requirements = [
'cypari',
'sympy',
]

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deps =
hypothesis
pytest
pytest-cov
cypari
commands =
py.test {posargs}

Expand Down