Skip to content

Commit

Permalink
Trac #31029: Upgrade: cypari2 2.1.2
Browse files Browse the repository at this point in the history
This is to upgrade cypari to 2.1.2 (which is compatible with pari 2.13
that is about to be upgraded too, see #30801)

- ​https://files.pythonhosted.org/packages/22/d9/4374baf5749257362f6d163
096f9f5a3fa2a6f231edbe0d61c7bdf281d6e/cypari2-2.1.2.tar.gz

URL: https://trac.sagemath.org/31029
Reported by: vdelecroix
Ticket author(s): Vincent Delecroix
Reviewer(s): Matthias Koeppe, John Palmieri
  • Loading branch information
Release Manager committed Jan 10, 2021
2 parents d4ae3c2 + b9aadfd commit 794d068
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 26 deletions.
7 changes: 4 additions & 3 deletions build/pkgs/cypari/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tarball=cypari2-VERSION.tar.gz
sha1=d3fc80e83bafa3c7e6eb5a779de9395d4242dddc
md5=9f431126112828c923f82e0393cbf317
cksum=2176941985
sha1=2a3039aa6bd690206cb58d4c39aef21e736eacf1
md5=6267c0dace847160763dc1777a390c0a
cksum=3639046443
upstream_url=https://pypi.io/packages/source/c/cypari2/cypari2-VERSION.tar.gz
2 changes: 1 addition & 1 deletion build/pkgs/cypari/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
2.1.2
45 changes: 33 additions & 12 deletions src/sage/libs/pari/convert_sage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ cpdef gen_to_sage(Gen z, locals=None):
sage: a.parent()
Complex Field with 64 bits of precision
sage: z = pari('1 + 1.0*I'); z
1 + 1.00000000000000*I
sage: a = gen_to_sage(z); a
1.00000000000000000 + 1.00000000000000000*I
sage: a.parent()
Complex Field with 64 bits of precision
sage: z = pari('1.0 + 1*I'); z
1.00000000000000 + I
sage: a = gen_to_sage(z); a
1.00000000000000000 + 1.00000000000000000*I
sage: a.parent()
Complex Field with 64 bits of precision
Converting polynomials::
sage: f = pari('(2/3)*x^3 + x - 5/7 + y')
Expand Down Expand Up @@ -233,16 +247,20 @@ cpdef gen_to_sage(Gen z, locals=None):
cdef GEN g = z.g
cdef long t = typ(g)
cdef long tx, ty
cdef Gen real, imag
cdef Gen real, imag, prec, xprec, yprec
cdef Py_ssize_t i, j, nr, nc

if t == t_INT:
return Integer(z)
elif t == t_FRAC:
return Rational(z)
elif t == t_REAL:
prec = prec_words_to_bits(z.precision())
return RealField(prec)(z)
prec = z.bitprecision()
if typ(prec.g) == t_INFINITY:
sage_prec = 53
else:
sage_prec = prec
return RealField(sage_prec)(z)
elif t == t_COMPLEX:
real = z.real()
imag = z.imag()
Expand All @@ -251,17 +269,20 @@ cpdef gen_to_sage(Gen z, locals=None):
if tx in [t_INTMOD, t_PADIC] or ty in [t_INTMOD, t_PADIC]:
raise NotImplementedError("No conversion to python available for t_COMPLEX with t_INTMOD or t_PADIC components")
if tx == t_REAL or ty == t_REAL:
xprec = real.precision() # will be 0 if exact
yprec = imag.precision() # will be 0 if exact
if xprec == 0:
prec = prec_words_to_bits(yprec)
elif yprec == 0:
prec = prec_words_to_bits(xprec)
xprec = real.bitprecision() # will be infinite if exact
yprec = imag.bitprecision() # will be infinite if exact
if typ(xprec.g) == t_INFINITY:
if typ(yprec.g) == t_INFINITY:
sage_prec = 53
else:
sage_prec = yprec
elif typ(yprec.g) == t_INFINITY:
sage_prec = xprec
else:
prec = max(prec_words_to_bits(xprec), prec_words_to_bits(yprec))
sage_prec = max(xprec, yprec)

R = RealField(prec)
C = ComplexField(prec)
R = RealField(sage_prec)
C = ComplexField(sage_prec)
return C(R(real), R(imag))
else:
K = QuadraticField(-1, 'i')
Expand Down
2 changes: 0 additions & 2 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ cdef class Matrix(Matrix0):
sage: b = pari(a); b
[1.000000000, 2.000000000; 3.000000000, 1.000000000] # 32-bit
[1.00000000000000, 2.00000000000000; 3.00000000000000, 1.00000000000000] # 64-bit
sage: b[0][0].precision() # in words
3
"""
from sage.libs.pari.all import pari
return pari.matrix(self._nrows, self._ncols, self._list())
Expand Down
5 changes: 4 additions & 1 deletion src/sage/rings/fraction_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,11 @@ def _element_constructor_(self, x, y=None, coerce=True):
# Below, v is the variable with highest priority,
# and the x[i] are rational functions in the
# remaining variables.
d = x.poldegree()
if d.type() == 't_INFINITY':
return self.zero()
v = self._element_class(self, x.variable(), 1)
x = sum(self(x[i]) * v**i for i in range(x.poldegree() + 1))
x = sum(self(x[i]) * v**i for i in range(d + 1))

def resolve_fractions(x, y):
xn = x.numerator()
Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -6745,7 +6745,7 @@ def units(self, proof=None):
"""
Return generators for the unit group modulo torsion.
ALGORITHM: Uses PARI's :pari:`bnfunit` command.
ALGORITHM: Uses PARI's :pari:`bnfinit` command.
INPUT:
Expand Down Expand Up @@ -6811,8 +6811,8 @@ def units(self, proof=None):
except AttributeError:
pass

# get PARI to compute the units
B = self.pari_bnf(proof).bnfunit()
# get PARI to compute the fundamental units
B = self.pari_bnf(proof).bnf_get_fu()
B = tuple(self(b, check=False) for b in B)
if proof:
# cache the provable results and return them
Expand All @@ -6827,7 +6827,7 @@ def unit_group(self, proof=None):
"""
Return the unit group (including torsion) of this number field.
ALGORITHM: Uses PARI's :pari:`bnfunit` command.
ALGORITHM: Uses PARI's :pari:`bnfinit` command.
INPUT:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ cdef class NumberFieldElement(FieldElement):
raise ValueError("L (=%s) must be a relative number field with base field K (=%s) in rnfisnorm" % (L, K))

rnf_data = K.pari_rnfnorm_data(L, proof=proof)
x, q = self.__pari__().rnfisnorm(rnf_data)
x, q = pari.rnfisnorm(rnf_data, self)
return L(x, check=False), K(q, check=False)

def _mpfr_(self, R):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/unit_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def __init__(self, number_field, proof=True, S=None):
self.__pS = pS = [P.pari_prime() for P in S]

# compute the fundamental units via pari:
fu = [K(u, check=False) for u in pK.bnfunit()]
fu = [K(u, check=False) for u in pK.bnf_get_fu()]
self.__nfu = len(fu)

# compute the additional S-unit generators:
Expand Down
8 changes: 7 additions & 1 deletion src/sage/rings/polynomial/multi_polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ def __call__(self, x, check=True):
sage: f = pari(a*d)
sage: B(f)
a*d
sage: f = pari(a*d - (a+1)*d*e^3 + a*d^2)
sage: B(f)
(-a - 1)*d*e^3 + a*d^2 + a*d
sage: A.<a,b> = PolynomialRing(QQ)
sage: B.<d,e> = PolynomialRing(A)
Expand Down Expand Up @@ -525,8 +528,11 @@ def __call__(self, x, check=True):
# univariate polynomials. Below, v is the variable
# with highest priority, and the x[i] are expressions
# in the remaining variables.
d = x.poldegree()
if d.type() == 't_INFINITY':
return self.zero()
v = self.gens_dict_recursive()[str(x.variable())]
return sum(self(x[i]) * v ** i for i in range(x.poldegree() + 1))
return sum(self(x[i]) * v ** i for i in range(d + 1))

if isinstance(x, dict):
return MPolynomial_polydict(self, x)
Expand Down

0 comments on commit 794d068

Please sign in to comment.