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

Make sagemath with pari 2.17 more deterministic #4

Merged
merged 4 commits into from
Dec 24, 2024
Merged
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
3 changes: 1 addition & 2 deletions src/sage/calculus/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,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
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 (-a + 2)
Fractional ideal (-2*a - 1)
sage: g = f.conjugate(conj, new_ideal=ideal)
sage: g.domain().ideal()
Fractional ideal (-a + 2)
Fractional ideal (-2*a - 1)
"""
if self.domain().is_padic_base():
return DynamicalSystem_Berkovich(self._system.conjugate(M, adjugate=adjugate))
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
"""

def _get_pari_instance():
Expand Down
11 changes: 4 additions & 7 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 @@ -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
12 changes: 6 additions & 6 deletions src/sage/rings/finite_rings/residue_field.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ class ResidueField_generic(Field):

sage: # needs sage.rings.number_field
sage: I = QQ[i].factor(2)[0][0]; I
Fractional ideal (-I - 1)
Fractional ideal (I - 1)
sage: k = I.residue_field(); k
Residue field of Fractional ideal (-I - 1)
Residue field of Fractional ideal (I - 1)
sage: type(k)
<class 'sage.rings.finite_rings.residue_field.ResidueFiniteField_prime_modn_with_category'>

Expand Down Expand Up @@ -1007,7 +1007,7 @@ cdef class ReductionMap(Map):
sage: cr
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (-a + 1)
To: Residue field of Fractional ideal (a - 1)
sage: cr == r # not implemented
True
sage: r(2 + a) == cr(2 + a)
Expand Down Expand Up @@ -1038,7 +1038,7 @@ cdef class ReductionMap(Map):
sage: cr
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (-a + 1)
To: Residue field of Fractional ideal (a - 1)
sage: cr == r # not implemented
True
sage: r(2 + a) == cr(2 + a)
Expand Down Expand Up @@ -1070,7 +1070,7 @@ cdef class ReductionMap(Map):
sage: r = F.reduction_map(); r
Partially defined reduction map:
From: Number Field in a with defining polynomial x^2 + 1
To: Residue field of Fractional ideal (-a + 1)
To: Residue field of Fractional ideal (a - 1)

We test that calling the function also works after copying::

Expand All @@ -1082,7 +1082,7 @@ cdef class ReductionMap(Map):
Traceback (most recent call last):
...
ZeroDivisionError: Cannot reduce field element 1/2*a
modulo Fractional ideal (-a + 1): it has negative valuation
modulo Fractional ideal (a - 1): it has negative valuation

sage: # needs sage.rings.finite_rings
sage: R.<t> = GF(2)[]; h = t^5 + t^2 + 1
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/integer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5585,7 +5585,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
sage: 5.is_norm(K)
False
sage: n.is_norm(K, element=True)
(True, 4*beta + 6)
(True, -4*beta + 6)
sage: n.is_norm(K, element=True)[1].norm()
4
sage: n = 5
Expand Down
36 changes: 18 additions & 18 deletions src/sage/rings/number_field/S_unit_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ def defining_polynomial_for_Kp(prime, prec=106):
sage: from sage.rings.number_field.S_unit_solver import defining_polynomial_for_Kp
sage: K.<a> = QuadraticField(2)
sage: p2 = K.prime_above(7); p2
Fractional ideal (-2*a + 1)
Fractional ideal (2*a - 1)
sage: defining_polynomial_for_Kp(p2, 10)
x + 266983762

Expand Down Expand Up @@ -2170,23 +2170,23 @@ def construct_complement_dictionaries(split_primes_list, SUK, verbose=False):
sage: SUK = K.S_unit_group(S=K.primes_above(H))
sage: split_primes_list = [3, 7]
sage: actual = construct_complement_dictionaries(split_primes_list, SUK)
sage: expected = {3: {(1, 1, 0): [(1, 0, 0), (1, 1, 0)],
....: (1, 0, 0): [(1, 0, 0), (1, 1, 0)]},
....: 7: {(1, 1, 0): [(1, 0, 0), (1, 4, 4), (1, 2, 2)],
....: (1, 3, 2): [(1, 0, 0), (1, 4, 4), (1, 2, 2)],
....: (1, 5, 4): [(1, 0, 0), (1, 4, 4), (1, 2, 2)],
....: (1, 0, 4): [(1, 2, 4), (1, 4, 0), (1, 0, 2)],
....: (1, 2, 0): [(1, 2, 4), (1, 4, 0), (1, 0, 2)],
....: (1, 4, 2): [(1, 2, 4), (1, 4, 0), (1, 0, 2)],
....: (1, 1, 2): [(1, 1, 2), (1, 3, 4), (1, 5, 0)],
....: (1, 3, 4): [(1, 1, 2), (1, 3, 4), (1, 5, 0)],
....: (1, 5, 0): [(1, 1, 2), (1, 3, 4), (1, 5, 0)],
....: (1, 0, 2): [(1, 0, 4), (1, 4, 2), (1, 2, 0)],
....: (1, 2, 4): [(1, 0, 4), (1, 4, 2), (1, 2, 0)],
....: (1, 4, 0): [(1, 0, 4), (1, 4, 2), (1, 2, 0)],
....: (1, 0, 0): [(1, 5, 4), (1, 3, 2), (1, 1, 0)],
....: (1, 2, 2): [(1, 5, 4), (1, 3, 2), (1, 1, 0)],
....: (1, 4, 4): [(1, 5, 4), (1, 3, 2), (1, 1, 0)]}}
sage: expected = {3: {(0, 1, 0): [(0, 1, 0), (1, 0, 0)],
....: (1, 0, 0): [(0, 1, 0), (1, 0, 0)]},
....: 7: {(0, 1, 0): [(1, 0, 0), (1, 2, 2), (1, 4, 4)],
....: (0, 1, 2): [(0, 1, 2), (0, 3, 4), (0, 5, 0)],
....: (0, 3, 2): [(1, 0, 0), (1, 2, 2), (1, 4, 4)],
....: (0, 3, 4): [(0, 1, 2), (0, 3, 4), (0, 5, 0)],
....: (0, 5, 0): [(0, 1, 2), (0, 3, 4), (0, 5, 0)],
....: (0, 5, 4): [(1, 0, 0), (1, 2, 2), (1, 4, 4)],
....: (1, 0, 0): [(0, 1, 0), (0, 3, 2), (0, 5, 4)],
....: (1, 0, 2): [(1, 0, 4), (1, 2, 0), (1, 4, 2)],
....: (1, 0, 4): [(1, 0, 2), (1, 2, 4), (1, 4, 0)],
....: (1, 2, 0): [(1, 0, 2), (1, 2, 4), (1, 4, 0)],
....: (1, 2, 2): [(0, 1, 0), (0, 3, 2), (0, 5, 4)],
....: (1, 2, 4): [(1, 0, 4), (1, 2, 0), (1, 4, 2)],
....: (1, 4, 0): [(1, 0, 4), (1, 2, 0), (1, 4, 2)],
....: (1, 4, 2): [(1, 0, 2), (1, 2, 4), (1, 4, 0)],
....: (1, 4, 4): [(0, 1, 0), (0, 3, 2), (0, 5, 4)]}}
sage: all(set(actual[p][vec]) == set(expected[p][vec])
....: for p in [3, 7] for vec in expected[p])
True
tornaria marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/number_field/class_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ def gens_ideals(self):
Class group of order 68 with structure C34 x C2 of Number Field
in a with defining polynomial x^2 + x + 23899
sage: C.gens()
(Fractional ideal class (7, a + 5), Fractional ideal class (5, a + 3))
(Fractional ideal class (83, a + 21), Fractional ideal class (15, a + 8))
sage: C.gens_ideals()
(Fractional ideal (7, a + 5), Fractional ideal (5, a + 3))
(Fractional ideal (83, a + 21), Fractional ideal (15, a + 8))
"""
return self.gens_values()

Expand Down
Loading
Loading