Opened 4 years ago
Last modified 4 years ago
#24378 closed defect
complex_root_of uses inexact index — at Version 13
Reported by: | jdemeyer | Owned by: | |
---|---|---|---|
Priority: | blocker | Milestone: | sage-8.2 |
Component: | symbolics | Keywords: | |
Cc: | rws, charpent | Merged in: | |
Authors: | Ralf Stephan | Reviewers: | |
Report Upstream: | N/A | Work issues: | |
Branch: | u/rws/doctest_failures_related_to_sympy_crootof (Commits, GitHub, GitLab) | Commit: | a93662faed523eb117f4ce0197b3178855849fd2 |
Dependencies: | Stopgaps: |
Description (last modified by )
When numerically evaluating complex_root_of(a, k)
, the index k
is passed as floating-point number:
sage: complex_root_of(x^8-1, 7).n(2) --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-4-4eba84b7c14c> in <module>() ----> 1 complex_root_of(x**Integer(8)-Integer(1), Integer(7)).n(Integer(2)) /home/patchbot/sage-patchbot/src/sage/structure/element.pyx in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131)() 863 0.666666666666667 864 """ --> 865 return self.numerical_approx(prec, digits, algorithm) 866 867 N = deprecated_function_alias(13055, n) /home/patchbot/sage-patchbot/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36209)() 5818 kwds = {'parent': R, 'algorithm': algorithm} 5819 try: -> 5820 x = x._convert(kwds) 5821 except TypeError: # numerical approximation for real number failed 5822 pass # try again with complex /home/patchbot/sage-patchbot/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663)() 1257 sig_on() 1258 try: -> 1259 res = self._gobj.evalf(0, kwds) 1260 finally: 1261 sig_off() /home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.pyc in _evalf_(self, poly, index, parent, algorithm) 2920 print("index: {}".format(index)) 2921 print("type(index): {}".format(type(index))) -> 2922 sobj = CRootOf(Poly(poly._sympy_()), int(index)) 2923 return sobj.n(ceil(prec*3/10))._sage_() 2924 /home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sympy/polys/rootoftools.pyc in __new__(cls, f, x, index, radicals, expand) 130 if index < -degree or index >= degree: 131 raise IndexError("root index out of [%d, %d] range, got %d" % --> 132 (-degree, degree - 1, index)) 133 elif index < 0: 134 index += degree IndexError: root index out of [-8, 7] range, got 8
When gmpy2
is installed, the index is even passed as complex number:
sage -t --long src/sage/functions/other.py ********************************************************************** File "src/sage/functions/other.py", line 2862, in sage.functions.other.Function_crootof Failed example: c.n() Exception raised: Traceback (most recent call last): File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 517, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 920, in compile_and_execute exec(compiled, globs) File "<doctest sage.functions.other.Function_crootof[1]>", line 1, in <module> c.n() File "sage/structure/element.pyx", line 865, in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131) return self.numerical_approx(prec, digits, algorithm) File "sage/symbolic/expression.pyx", line 5824, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36286) x = x._convert(kwds) File "sage/symbolic/expression.pyx", line 1259, in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663) res = self._gobj.evalf(0, kwds) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.py", line 2920, in _evalf_ sobj = CRootOf(Poly(poly._sympy_()), int(index)) File "sage/rings/complex_number.pyx", line 1058, in sage.rings.complex_number.ComplexNumber.__int__ (build/cythonized/sage/rings/complex_number.c:10918) raise TypeError("can't convert complex to int; use int(abs(z))") TypeError: can't convert complex to int; use int(abs(z)) ********************************************************************** File "src/sage/functions/other.py", line 2864, in sage.functions.other.Function_crootof Failed example: c.n(100) Exception raised: Traceback (most recent call last): File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 517, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 920, in compile_and_execute exec(compiled, globs) File "<doctest sage.functions.other.Function_crootof[2]>", line 1, in <module> c.n(Integer(100)) File "sage/structure/element.pyx", line 865, in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131) return self.numerical_approx(prec, digits, algorithm) File "sage/symbolic/expression.pyx", line 5824, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36286) x = x._convert(kwds) File "sage/symbolic/expression.pyx", line 1259, in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663) res = self._gobj.evalf(0, kwds) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.py", line 2920, in _evalf_ sobj = CRootOf(Poly(poly._sympy_()), int(index)) File "sage/rings/complex_number.pyx", line 1058, in sage.rings.complex_number.ComplexNumber.__int__ (build/cythonized/sage/rings/complex_number.c:10918) raise TypeError("can't convert complex to int; use int(abs(z))") TypeError: can't convert complex to int; use int(abs(z)) ********************************************************************** File "src/sage/functions/other.py", line 2866, in sage.functions.other.Function_crootof Failed example: (c^6 + c + 1).n(100) < 1e-25 Exception raised: Traceback (most recent call last): File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 517, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 920, in compile_and_execute exec(compiled, globs) File "<doctest sage.functions.other.Function_crootof[3]>", line 1, in <module> (c**Integer(6) + c + Integer(1)).n(Integer(100)) < RealNumber('1e-25') File "sage/structure/element.pyx", line 865, in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131) return self.numerical_approx(prec, digits, algorithm) File "sage/symbolic/expression.pyx", line 5824, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36286) x = x._convert(kwds) File "sage/symbolic/expression.pyx", line 1259, in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663) res = self._gobj.evalf(0, kwds) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.py", line 2920, in _evalf_ sobj = CRootOf(Poly(poly._sympy_()), int(index)) File "sage/rings/complex_number.pyx", line 1058, in sage.rings.complex_number.ComplexNumber.__int__ (build/cythonized/sage/rings/complex_number.c:10918) raise TypeError("can't convert complex to int; use int(abs(z))") TypeError: can't convert complex to int; use int(abs(z)) ********************************************************************** File "src/sage/functions/other.py", line 2908, in sage.functions.other.Function_crootof._evalf_ Failed example: complex_root_of(x^2-2, 1).n() Exception raised: Traceback (most recent call last): File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 517, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 920, in compile_and_execute exec(compiled, globs) File "<doctest sage.functions.other.Function_crootof._evalf_[0]>", line 1, in <module> complex_root_of(x**Integer(2)-Integer(2), Integer(1)).n() File "sage/structure/element.pyx", line 865, in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131) return self.numerical_approx(prec, digits, algorithm) File "sage/symbolic/expression.pyx", line 5824, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36286) x = x._convert(kwds) File "sage/symbolic/expression.pyx", line 1259, in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663) res = self._gobj.evalf(0, kwds) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.py", line 2920, in _evalf_ sobj = CRootOf(Poly(poly._sympy_()), int(index)) File "sage/rings/complex_number.pyx", line 1058, in sage.rings.complex_number.ComplexNumber.__int__ (build/cythonized/sage/rings/complex_number.c:10918) raise TypeError("can't convert complex to int; use int(abs(z))") TypeError: can't convert complex to int; use int(abs(z)) ********************************************************************** 2 items had failures: 3 of 5 in sage.functions.other.Function_crootof 1 of 3 in sage.functions.other.Function_crootof._evalf_ [622 tests, 4 failures, 17.27 s] sage -t --long src/sage/interfaces/sympy.py ********************************************************************** File "src/sage/interfaces/sympy.py", line 617, in sage.interfaces.sympy._sympysage_crootof Failed example: (sols[0]+1)._sage_().n() Exception raised: Traceback (most recent call last): File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 517, in _run self.compile_and_execute(example, compiler, test.globs) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 920, in compile_and_execute exec(compiled, globs) File "<doctest sage.interfaces.sympy._sympysage_crootof[6]>", line 1, in <module> (sols[Integer(0)]+Integer(1))._sage_().n() File "sage/structure/element.pyx", line 865, in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8131) return self.numerical_approx(prec, digits, algorithm) File "sage/symbolic/expression.pyx", line 5824, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:36286) x = x._convert(kwds) File "sage/symbolic/expression.pyx", line 1259, in sage.symbolic.expression.Expression._convert (build/cythonized/sage/symbolic/expression.cpp:10663) res = self._gobj.evalf(0, kwds) File "/home/patchbot/sage-patchbot/local/lib/python2.7/site-packages/sage/functions/other.py", line 2920, in _evalf_ sobj = CRootOf(Poly(poly._sympy_()), int(index)) File "sage/rings/complex_number.pyx", line 1058, in sage.rings.complex_number.ComplexNumber.__int__ (build/cythonized/sage/rings/complex_number.c:10918) raise TypeError("can't convert complex to int; use int(abs(z))") TypeError: can't convert complex to int; use int(abs(z)) ********************************************************************** 1 item had failures: 1 of 8 in sage.interfaces.sympy._sympysage_crootof [218 tests, 1 failure, 3.27 s]
Change History (13)
comment:1 Changed 4 years ago by
- Cc charpent added
comment:2 Changed 4 years ago by
- Description modified (diff)
- Summary changed from Doctest failures related to sympy to Doctest failures related to sympy CRootOf
comment:3 Changed 4 years ago by
- Branch set to u/rws/doctest_failures_related_to_sympy_crootof
comment:4 follow-ups: ↓ 6 ↓ 10 Changed 4 years ago by
- Commit set to a93662faed523eb117f4ce0197b3178855849fd2
- Status changed from new to needs_review
comment:5 Changed 4 years ago by
Do you have an idea why this depends on the system?
comment:6 in reply to: ↑ 4 Changed 4 years ago by
Replying to rws:
That exact arguments are made inexact is a bug in itself. But that they are made complex (EDIT: in some machines) is beyond me.
Do you know where this happens? It seems to me that it is Pynac doing this.
comment:7 Changed 4 years ago by
- Description modified (diff)
comment:8 Changed 4 years ago by
Some sympy behavior depends on the presence/absence of gmpy2. We had this trouble before the upgrade.
comment:9 Changed 4 years ago by
- Description modified (diff)
- Summary changed from Doctest failures related to sympy CRootOf to complex_root_of uses inexact index
comment:10 in reply to: ↑ 4 Changed 4 years ago by
Replying to rws:
That exact arguments are made inexact is a bug in itself.
Right, this ticket should just fix that.
comment:11 Changed 4 years ago by
- Status changed from needs_review to needs_work
comment:12 Changed 4 years ago by
- Description modified (diff)
comment:13 Changed 4 years ago by
- Description modified (diff)
That exact arguments are made inexact is a bug in itself. But that they are made complex (EDIT: in some machines) is beyond me.
New commits:
24378: Doctest failures related to sympy