Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit b9aadfd

Browse files
committed
31029: adapt sage library code to cypari2 version 2.1.2
1 parent 0b18fd0 commit b9aadfd

File tree

7 files changed

+50
-22
lines changed

7 files changed

+50
-22
lines changed

src/sage/libs/pari/convert_sage.pyx

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ cpdef gen_to_sage(Gen z, locals=None):
144144
sage: a.parent()
145145
Complex Field with 64 bits of precision
146146
147+
sage: z = pari('1 + 1.0*I'); z
148+
1 + 1.00000000000000*I
149+
sage: a = gen_to_sage(z); a
150+
1.00000000000000000 + 1.00000000000000000*I
151+
sage: a.parent()
152+
Complex Field with 64 bits of precision
153+
154+
sage: z = pari('1.0 + 1*I'); z
155+
1.00000000000000 + I
156+
sage: a = gen_to_sage(z); a
157+
1.00000000000000000 + 1.00000000000000000*I
158+
sage: a.parent()
159+
Complex Field with 64 bits of precision
160+
147161
Converting polynomials::
148162
149163
sage: f = pari('(2/3)*x^3 + x - 5/7 + y')
@@ -233,16 +247,20 @@ cpdef gen_to_sage(Gen z, locals=None):
233247
cdef GEN g = z.g
234248
cdef long t = typ(g)
235249
cdef long tx, ty
236-
cdef Gen real, imag
250+
cdef Gen real, imag, prec, xprec, yprec
237251
cdef Py_ssize_t i, j, nr, nc
238252

239253
if t == t_INT:
240254
return Integer(z)
241255
elif t == t_FRAC:
242256
return Rational(z)
243257
elif t == t_REAL:
244-
prec = prec_words_to_bits(z.precision())
245-
return RealField(prec)(z)
258+
prec = z.bitprecision()
259+
if typ(prec.g) == t_INFINITY:
260+
sage_prec = 53
261+
else:
262+
sage_prec = prec
263+
return RealField(sage_prec)(z)
246264
elif t == t_COMPLEX:
247265
real = z.real()
248266
imag = z.imag()
@@ -251,17 +269,20 @@ cpdef gen_to_sage(Gen z, locals=None):
251269
if tx in [t_INTMOD, t_PADIC] or ty in [t_INTMOD, t_PADIC]:
252270
raise NotImplementedError("No conversion to python available for t_COMPLEX with t_INTMOD or t_PADIC components")
253271
if tx == t_REAL or ty == t_REAL:
254-
xprec = real.precision() # will be 0 if exact
255-
yprec = imag.precision() # will be 0 if exact
256-
if xprec == 0:
257-
prec = prec_words_to_bits(yprec)
258-
elif yprec == 0:
259-
prec = prec_words_to_bits(xprec)
272+
xprec = real.bitprecision() # will be infinite if exact
273+
yprec = imag.bitprecision() # will be infinite if exact
274+
if typ(xprec.g) == t_INFINITY:
275+
if typ(yprec.g) == t_INFINITY:
276+
sage_prec = 53
277+
else:
278+
sage_prec = yprec
279+
elif typ(yprec.g) == t_INFINITY:
280+
sage_prec = xprec
260281
else:
261-
prec = max(prec_words_to_bits(xprec), prec_words_to_bits(yprec))
282+
sage_prec = max(xprec, yprec)
262283

263-
R = RealField(prec)
264-
C = ComplexField(prec)
284+
R = RealField(sage_prec)
285+
C = ComplexField(sage_prec)
265286
return C(R(real), R(imag))
266287
else:
267288
K = QuadraticField(-1, 'i')

src/sage/matrix/matrix1.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ cdef class Matrix(Matrix0):
8686
sage: b = pari(a); b
8787
[1.000000000, 2.000000000; 3.000000000, 1.000000000] # 32-bit
8888
[1.00000000000000, 2.00000000000000; 3.00000000000000, 1.00000000000000] # 64-bit
89-
sage: b[0][0].precision() # in words
90-
3
9189
"""
9290
from sage.libs.pari.all import pari
9391
return pari.matrix(self._nrows, self._ncols, self._list())

src/sage/rings/fraction_field.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,11 @@ def _element_constructor_(self, x, y=None, coerce=True):
661661
# Below, v is the variable with highest priority,
662662
# and the x[i] are rational functions in the
663663
# remaining variables.
664+
d = x.poldegree()
665+
if d.type() == 't_INFINITY':
666+
return self.zero()
664667
v = self._element_class(self, x.variable(), 1)
665-
x = sum(self(x[i]) * v**i for i in range(x.poldegree() + 1))
668+
x = sum(self(x[i]) * v**i for i in range(d + 1))
666669

667670
def resolve_fractions(x, y):
668671
xn = x.numerator()

src/sage/rings/number_field/number_field.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6729,7 +6729,7 @@ def units(self, proof=None):
67296729
"""
67306730
Return generators for the unit group modulo torsion.
67316731
6732-
ALGORITHM: Uses PARI's :pari:`bnfunit` command.
6732+
ALGORITHM: Uses PARI's :pari:`bnfinit` command.
67336733
67346734
INPUT:
67356735
@@ -6795,8 +6795,8 @@ def units(self, proof=None):
67956795
except AttributeError:
67966796
pass
67976797

6798-
# get PARI to compute the units
6799-
B = self.pari_bnf(proof).bnfunit()
6798+
# get PARI to compute the fundamental units
6799+
B = self.pari_bnf(proof).bnf_get_fu()
68006800
B = tuple(self(b, check=False) for b in B)
68016801
if proof:
68026802
# cache the provable results and return them
@@ -6811,7 +6811,7 @@ def unit_group(self, proof=None):
68116811
"""
68126812
Return the unit group (including torsion) of this number field.
68136813
6814-
ALGORITHM: Uses PARI's :pari:`bnfunit` command.
6814+
ALGORITHM: Uses PARI's :pari:`bnfinit` command.
68156815
68166816
INPUT:
68176817

src/sage/rings/number_field/number_field_element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ cdef class NumberFieldElement(FieldElement):
18011801
raise ValueError("L (=%s) must be a relative number field with base field K (=%s) in rnfisnorm" % (L, K))
18021802

18031803
rnf_data = K.pari_rnfnorm_data(L, proof=proof)
1804-
x, q = self.__pari__().rnfisnorm(rnf_data)
1804+
x, q = pari.rnfisnorm(rnf_data, self)
18051805
return L(x, check=False), K(q, check=False)
18061806

18071807
def _mpfr_(self, R):

src/sage/rings/number_field/unit_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def __init__(self, number_field, proof=True, S=None):
324324
self.__pS = pS = [P.pari_prime() for P in S]
325325

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

330330
# compute the additional S-unit generators:

src/sage/rings/polynomial/multi_polynomial_ring.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ def __call__(self, x, check=True):
379379
sage: f = pari(a*d)
380380
sage: B(f)
381381
a*d
382+
sage: f = pari(a*d - (a+1)*d*e^3 + a*d^2)
383+
sage: B(f)
384+
(-a - 1)*d*e^3 + a*d^2 + a*d
382385
383386
sage: A.<a,b> = PolynomialRing(QQ)
384387
sage: B.<d,e> = PolynomialRing(A)
@@ -525,8 +528,11 @@ def __call__(self, x, check=True):
525528
# univariate polynomials. Below, v is the variable
526529
# with highest priority, and the x[i] are expressions
527530
# in the remaining variables.
531+
d = x.poldegree()
532+
if d.type() == 't_INFINITY':
533+
return self.zero()
528534
v = self.gens_dict_recursive()[str(x.variable())]
529-
return sum(self(x[i]) * v ** i for i in range(x.poldegree() + 1))
535+
return sum(self(x[i]) * v ** i for i in range(d + 1))
530536

531537
if isinstance(x, dict):
532538
return MPolynomial_polydict(self, x)

0 commit comments

Comments
 (0)