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 pari 2.17, cypari 2.2.1 #38749

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f59ea66
Fix build with pari 2.17
antonio-rojas Oct 1, 2024
dee7334
Adapt new_gen_from_real_mpfr_element to pari 2.17 changes in precision
antonio-rojas Oct 2, 2024
34af90b
Update tests output for pari 2.17
antonio-rojas Oct 5, 2024
48f18f1
Account for random output in some tests
antonio-rojas Oct 6, 2024
ff1b011
Rename prec_words_to_bits to prec_pari_to_bits
antonio-rojas Oct 6, 2024
14dd562
Account for more pari 2.17 random output in some tests
antonio-rojas Oct 27, 2024
23ff7d6
Replace prec_pari_to_bits usage
antonio-rojas Oct 30, 2024
fbb32fd
Replace prec_pari_to_bits usage
antonio-rojas Oct 30, 2024
91db307
Merge remote-tracking branch 'upstream/develop' into pari-2.17
antonio-rojas Nov 16, 2024
51c045c
Fix doctests for pari 2.17 on 32-bit
tornaria Nov 6, 2024
a4d1efb
make reduced_basis() deterministic for pari 2.17
tornaria Nov 7, 2024
bcb9c3d
make pari_bnf() deterministic for pari 2.17
tornaria Nov 7, 2024
a5c65e1
Fix doctests for 'make pari_bnf() deterministic'
tornaria Nov 7, 2024
bb38ebf
Fix build with pari 2.17
antonio-rojas Oct 1, 2024
a723576
Adapt new_gen_from_real_mpfr_element to pari 2.17 changes in precision
antonio-rojas Oct 2, 2024
457daa5
Update tests output for pari 2.17
antonio-rojas Oct 5, 2024
6a374d3
Account for random output in some tests
antonio-rojas Oct 6, 2024
29d8cc2
Account for more pari 2.17 random output in some tests
antonio-rojas Oct 27, 2024
0861e82
Merge remote-tracking branch 'tornaria/pari-2.17' into pari-2.17
antonio-rojas Dec 24, 2024
2767669
Test output is no longer random
antonio-rojas Dec 24, 2024
e033512
Fix merge
antonio-rojas Dec 24, 2024
75f614f
fix test by sorting (fails on aarch64)
tornaria Dec 27, 2024
26f411e
fix two 32-bit tests
tornaria Dec 26, 2024
36cf809
Merge remote-tracking branch 'upstream/develop' into pari-2.17
antonio-rojas Jan 4, 2025
f5af542
Fix rebase
antonio-rojas Jan 4, 2025
ce1531d
Fix merge
antonio-rojas Jan 5, 2025
427c2ea
Update pari to 2.17.1
antonio-rojas Jan 7, 2025
252efcc
Update cypari to 2.2.1
antonio-rojas Jan 7, 2025
1570ab0
Restore SAGE_PARI_MAXVER
antonio-rojas Jan 7, 2025
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
11 changes: 6 additions & 5 deletions src/sage/arith/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,9 +2691,10 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds):

Any object which has a factor method can be factored like this::

sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field
sage: factor(122 - 454*i) # needs sage.rings.number_field
(-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4)
sage: # needs sage.rings.number_field
sage: K.<i> = QuadraticField(-1)
sage: f = factor(122 - 454*i); f
(-1) * (i - 1)^3 * (2*i - 1)^3 * (3*i + 2) * (i + 4)

To access the data in a factorization::

Expand Down Expand Up @@ -2776,7 +2777,7 @@ def radical(n, *args, **kwds):
ArithmeticError: radical of 0 is not defined
sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field
sage: radical(K(2)) # needs sage.rings.number_field
i + 1
i - 1

Tests with numpy and gmpy2 numbers::

Expand Down Expand Up @@ -3031,7 +3032,7 @@ def is_squarefree(n):
sage: is_squarefree(O(2))
False
sage: O(2).factor()
(-I) * (I + 1)^2
(I) * (I - 1)^2

This method fails on domains which are not Unique Factorization Domains::

Expand Down
3 changes: 1 addition & 2 deletions src/sage/calculus/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,7 @@ def nintegral(ex, x, a, b,
to high precision::

sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.565728500561051474934096410 E-127' # 32-bit
'2.5657285005610514829176211363206621657 E-127' # 64-bit
'2.5657285005610514829176211363206621657 E-127'
sage: old_prec = gp.set_real_precision(50)
sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.5657285005610514829173563961304957417746108003917 E-127'
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/quotient_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def gcd(self, other):
sage: R = ZZ.extension(x^2 + 1, names='i')
sage: i = R.1
sage: gcd(5, 3 + 4*i)
-i - 2
2*i - 1
sage: P.<t> = R[]
sage: gcd(t, i)
Traceback (most recent call last):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/doctest/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,11 @@ def create_doctests(self, namespace):

sage: import sys
sage: bitness = '64' if sys.maxsize > (1 << 32) else '32'
sage: gp.get_precision() == 38 # needs sage.libs.pari
sage: sys.maxsize == 2^63 - 1
False # 32-bit
True # 64-bit
sage: ex = doctests[20].examples[11]
sage: ((bitness == '64' and ex.want == 'True \n') # needs sage.libs.pari
sage: ((bitness == '64' and ex.want == 'True \n')
....: or (bitness == '32' and ex.want == 'False \n'))
True

Expand Down
4 changes: 2 additions & 2 deletions src/sage/dynamics/arithmetic_dynamics/berkovich_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ def conjugate(self, M, adjugate=False, new_ideal=None):

sage: # needs sage.rings.number_field
sage: ideal = A.ideal(5).factor()[1][0]; ideal
Fractional ideal (2*a + 1)
Fractional ideal (-2*a - 1)
sage: g = f.conjugate(conj, new_ideal=ideal)
sage: g.domain().ideal()
Fractional ideal (2*a + 1)
Fractional ideal (-2*a - 1)
"""
if self.domain().is_padic_base():
return DynamicalSystem_Berkovich(self._system.conjugate(M, adjugate=adjugate))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ def primes_of_bad_reduction(self, check=True):
sage: P.<x,y> = ProjectiveSpace(K,1)
sage: f = DynamicalSystem_projective([1/3*x^2+1/a*y^2, y^2])
sage: f.primes_of_bad_reduction() # needs sage.rings.function_field
[Fractional ideal (a), Fractional ideal (3)]
[Fractional ideal (-a), Fractional ideal (3)]

This is an example where ``check=False`` returns extra primes::

Expand Down
42 changes: 14 additions & 28 deletions src/sage/interfaces/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@
::

sage: gp("a = intnum(x=0,6,sin(x))")
0.03982971334963397945434770208 # 32-bit
0.039829713349633979454347702077075594548 # 64-bit
0.039829713349633979454347702077075594548
sage: gp("a")
0.03982971334963397945434770208 # 32-bit
0.039829713349633979454347702077075594548 # 64-bit
0.039829713349633979454347702077075594548
sage: gp.kill("a")
sage: gp("a")
a
Expand Down Expand Up @@ -375,8 +373,7 @@ def get_precision(self):
EXAMPLES::

sage: gp.get_precision()
28 # 32-bit
38 # 64-bit
38
"""
return self.get_default('realprecision')

Expand All @@ -396,15 +393,13 @@ def set_precision(self, prec):
EXAMPLES::

sage: old_prec = gp.set_precision(53); old_prec
28 # 32-bit
38 # 64-bit
38
sage: gp.get_precision()
57
sage: gp.set_precision(old_prec)
57
sage: gp.get_precision()
28 # 32-bit
38 # 64-bit
38
"""
return self.set_default('realprecision', prec)

Expand Down Expand Up @@ -520,8 +515,7 @@ def set_default(self, var, value):
sage: gp.set_default('realprecision', old_prec)
115
sage: gp.get_default('realprecision')
28 # 32-bit
38 # 64-bit
38
"""
old = self.get_default(var)
self._eval_line('default(%s,%s)' % (var, value))
Expand All @@ -547,8 +541,7 @@ def get_default(self, var):
sage: gp.get_default('seriesprecision')
16
sage: gp.get_default('realprecision')
28 # 32-bit
38 # 64-bit
38
"""
return eval(self._eval_line('default(%s)' % var))

Expand Down Expand Up @@ -773,8 +766,7 @@ def _exponent_symbol(self):
::

sage: repr(gp(10.^80)).replace(gp._exponent_symbol(), 'e')
'1.0000000000000000000000000000000000000e80' # 64-bit
'1.000000000000000000000000000e80' # 32-bit
'1.0000000000000000000000000000000000000e80'
"""
return ' E'

Expand All @@ -800,27 +792,23 @@ def new_with_bits_prec(self, s, precision=0):

sage: # needs sage.symbolic
sage: pi_def = gp(pi); pi_def
3.141592653589793238462643383 # 32-bit
3.1415926535897932384626433832795028842 # 64-bit
3.1415926535897932384626433832795028842
sage: pi_def.precision()
28 # 32-bit
38 # 64-bit
38
sage: pi_150 = gp.new_with_bits_prec(pi, 150)
sage: new_prec = pi_150.precision(); new_prec
48 # 32-bit
57 # 64-bit
sage: old_prec = gp.set_precision(new_prec); old_prec
28 # 32-bit
38 # 64-bit
38
sage: pi_150
3.14159265358979323846264338327950288419716939938 # 32-bit
3.14159265358979323846264338327950288419716939937510582098 # 64-bit
sage: gp.set_precision(old_prec)
48 # 32-bit
57 # 64-bit
sage: gp.get_precision()
28 # 32-bit
38 # 64-bit
38
"""
if precision:
old_prec = self.get_real_precision()
Expand Down Expand Up @@ -856,11 +844,9 @@ class GpElement(ExpectElement, sage.interfaces.abc.GpElement):
sage: loads(dumps(x)) == x
False
sage: x
1.047197551196597746154214461 # 32-bit
1.0471975511965977461542144610931676281 # 64-bit
1.0471975511965977461542144610931676281
sage: loads(dumps(x))
1.047197551196597746154214461 # 32-bit
1.0471975511965977461542144610931676281 # 64-bit
1.0471975511965977461542144610931676281

The two elliptic curves look the same, but internally the floating
point numbers are slightly different.
Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,7 @@ def _sage_repr(self):
::

sage: gp(10.^80)._sage_repr()
'1.0000000000000000000000000000000000000e80' # 64-bit
'1.000000000000000000000000000e80' # 32-bit
'1.0000000000000000000000000000000000000e80'
sage: mathematica('10.^80')._sage_repr() # optional - mathematica
'1.e80'

Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/mathematica.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@
Note that this agrees with what the PARI interpreter gp produces::

sage: gp('solve(x=1,2,exp(x)-3*x)')
1.512134551657842473896739678 # 32-bit
1.5121345516578424738967396780720387046 # 64-bit
1.5121345516578424738967396780720387046

Next we find the minimum of a polynomial using the two different
ways of accessing Mathematica::
Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/mathics.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@
Note that this agrees with what the PARI interpreter gp produces::

sage: gp('solve(x=1,2,exp(x)-3*x)')
1.512134551657842473896739678 # 32-bit
1.5121345516578424738967396780720387046 # 64-bit
1.5121345516578424738967396780720387046

Next we find the minimum of a polynomial using the two different
ways of accessing Mathics::
Expand Down
3 changes: 1 addition & 2 deletions src/sage/interfaces/maxima_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,8 +1489,7 @@ def nintegral(self, var='x', a=0, b=1,
high precision very quickly::

sage: gp('intnum(x=0,1,exp(-sqrt(x)))')
0.5284822353142307136179049194 # 32-bit
0.52848223531423071361790491935415653022 # 64-bit
0.52848223531423071361790491935415653022
sage: _ = gp.set_precision(80)
sage: gp('intnum(x=0,1,exp(-sqrt(x)))')
0.52848223531423071361790491935415653021675547587292866196865279321015401702040079
Expand Down
5 changes: 2 additions & 3 deletions src/sage/libs/pari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,11 @@
sage: e = pari([0,0,0,-82,0]).ellinit()
sage: eta1 = e.elleta(precision=50)[0]
sage: eta1.sage()
3.6054636014326520859158205642077267748 # 64-bit
3.605463601432652085915820564 # 32-bit
3.6054636014326520859158205642077267748
sage: eta1 = e.elleta(precision=150)[0]
sage: eta1.sage()
3.605463601432652085915820564207726774810268996598024745444380641429820491740 # 64-bit
3.60546360143265208591582056420772677481026899659802474544 # 32-bit
3.605463601432652085915820564207726774810268996598024745444380641430 # 32-bit
"""


Expand Down
15 changes: 7 additions & 8 deletions src/sage/libs/pari/convert_sage.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,16 @@ cpdef list pari_prime_range(long c_start, long c_stop, bint py_ints=False):
sage: pari_prime_range(2, 19)
[2, 3, 5, 7, 11, 13, 17]
"""
cdef long p = 0
cdef byteptr pari_prime_ptr = diffptr
cdef ulong i = 1
res = []
while p < c_start:
NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
while p < c_stop:
while pari_PRIMES[i] < c_start:
i+=1
while pari_PRIMES[i] < c_stop:
if py_ints:
res.append(p)
res.append(pari_PRIMES[i])
else:
z = <Integer>PY_NEW(Integer)
mpz_set_ui(z.value, p)
mpz_set_ui(z.value, pari_PRIMES[i])
res.append(z)
NEXT_PRIME_VIADIFF(p, pari_prime_ptr)
i+=1
return res
4 changes: 2 additions & 2 deletions src/sage/libs/pari/convert_sage_real_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cpdef Gen new_gen_from_real_mpfr_element(RealNumber self):

# We round up the precision to the nearest multiple of wordsize.
cdef int rounded_prec
rounded_prec = (self.prec() + wordsize - 1) & ~(wordsize - 1)
rounded_prec = nbits2prec(self.prec())

# Yes, assigning to self works fine, even in Cython.
if rounded_prec > prec:
Expand All @@ -48,7 +48,7 @@ cpdef Gen new_gen_from_real_mpfr_element(RealNumber self):
exponent = mpfr_get_z_exp(mantissa, self.value)

# Create a PARI REAL
pari_float = cgetr(2 + rounded_prec / wordsize)
pari_float = cgetr(rounded_prec)
pari_float[1] = evalexpo(exponent + rounded_prec - 1) + evalsigne(mpfr_sgn(self.value))
mpz_export(&pari_float[2], NULL, 1, wordsize // 8, 0, 0, mantissa)
mpz_clear(mantissa)
Expand Down
19 changes: 8 additions & 11 deletions src/sage/libs/pari/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
[4, 2]

sage: int(pari(RealField(63)(2^63 - 1))) # needs sage.rings.real_mpfr
9223372036854775807 # 32-bit
9223372036854775807 # 64-bit
9223372036854775807
sage: int(pari(RealField(63)(2^63 + 2))) # needs sage.rings.real_mpfr
9223372036854775810

Expand Down Expand Up @@ -1231,8 +1230,7 @@
sage: e.ellheight([1,0])
0.476711659343740
sage: e.ellheight([1,0], precision=128).sage()
0.47671165934373953737948605888465305945902294218 # 32-bit
0.476711659343739537379486058884653059459022942211150879336 # 64-bit
0.476711659343739537379486058884653059459022942211150879336
sage: e.ellheight([1, 0], [-1, 1])
0.418188984498861

Expand Down Expand Up @@ -1502,7 +1500,7 @@
sage: pari(-104).quadclassunit()
[6, [6], [Qfb(5, -4, 6)], 1]
sage: pari(109).quadclassunit()
[1, [], [], 5.56453508676047]
[1, [], [], 5.56453508676047, -1]
sage: pari(10001).quadclassunit() # random generators
[16, [16], [Qfb(10, 99, -5, 0.E-38)], 5.29834236561059]
sage: pari(10001).quadclassunit()[0]
Expand Down Expand Up @@ -1749,13 +1747,13 @@
sage: y = QQ['yy'].0; _ = pari(y) # pari has variable ordering rules
sage: x = QQ['zz'].0; nf = pari(x^2 + 2).nfinit()
sage: nf.nfroots(y^2 + 2)
[Mod(-zz, zz^2 + 2), Mod(zz, zz^2 + 2)]
[Mod(-zz, zz^2 + 2), Mod(zz, zz^2 + 2)]~
sage: nf = pari(x^3 + 2).nfinit()
sage: nf.nfroots(y^3 + 2)
[Mod(zz, zz^3 + 2)]
[Mod(zz, zz^3 + 2)]~
sage: nf = pari(x^4 + 2).nfinit()
sage: nf.nfroots(y^4 + 2)
[Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)]
[Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)]~

sage: nf = pari('x^2 + 1').nfinit()
sage: nf.nfrootsof1()
Expand Down Expand Up @@ -1806,12 +1804,11 @@
sage: e = pari([0,0,0,-82,0]).ellinit()
sage: eta1 = e.elleta(precision=50)[0]
sage: eta1.sage()
3.6054636014326520859158205642077267748 # 64-bit
3.605463601432652085915820564 # 32-bit
3.6054636014326520859158205642077267748
sage: eta1 = e.elleta(precision=150)[0]
sage: eta1.sage()
3.605463601432652085915820564207726774810268996598024745444380641429820491740 # 64-bit
3.60546360143265208591582056420772677481026899659802474544 # 32-bit
3.605463601432652085915820564207726774810268996598024745444380641430 # 32-bit
sage: from cypari2 import Pari
sage: pari = Pari()

Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16575,7 +16575,7 @@ cdef class Matrix(Matrix1):
....: -2*a^2 + 4*a - 2, -2*a^2 + 1, 2*a, a^2 - 6, 3*a^2 - a ])
sage: r,s,p = m._echelon_form_PID()
sage: s[2]
(0, 0, -3*a^2 - 18*a + 34, -68*a^2 + 134*a - 53, -111*a^2 + 275*a - 90)
(0, 0, 3*a^2 + 18*a - 34, 68*a^2 - 134*a + 53, 111*a^2 - 275*a + 90)
sage: r * m == s and r.det() == 1
True

Expand Down
8 changes: 4 additions & 4 deletions src/sage/modular/cusps_nf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,9 @@ def NFCusps_ideal_reps_for_levelN(N, nlists=1):
sage: from sage.modular.cusps_nf import NFCusps_ideal_reps_for_levelN
sage: NFCusps_ideal_reps_for_levelN(N)
[(Fractional ideal (1),
Fractional ideal (67, a + 17),
Fractional ideal (127, a + 48),
Fractional ideal (157, a - 19))]
Fractional ideal (67, -4/7*a^3 + 13/7*a^2 + 39/7*a - 43),
Fractional ideal (127, -4/7*a^3 + 13/7*a^2 + 39/7*a - 42),
Fractional ideal (157, -4/7*a^3 + 13/7*a^2 + 39/7*a + 48))]
sage: L = NFCusps_ideal_reps_for_levelN(N, 5)
sage: all(len(L[i]) == k.class_number() for i in range(len(L)))
True
Expand Down Expand Up @@ -1244,7 +1244,7 @@ def units_mod_ideal(I):
sage: I = k.ideal(5, a + 1)
sage: units_mod_ideal(I)
[1,
-2*a^2 - 4*a + 1,
2*a^2 + 4*a - 1,
...]
::
Expand Down
Loading
Loading