Opened 5 years ago

Closed 5 years ago

#22553 closed defect (fixed)

pynac bug -- evaluation of arctan2 fails with traceback

Reported by: was Owned by:
Priority: major Milestone: sage-7.6
Component: calculus Keywords:
Cc: paulmasson, rws Merged in:
Authors: Ralf Stephan, Jeroen Demeyer Reviewers: Jeroen Demeyer, Paul Masson
Report Upstream: N/A Work issues:
Branch: a41922c (Commits, GitHub, GitLab) Commit: a41922c5d1b46725962e13ecb8d71f353d94abe3
Dependencies: Stopgaps:

Status badges


~/Sara$ sage-develop
│ SageMath version 7.6.beta5, Release Date: 2017-02-26               │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
sage: arctan2(1.5,-1.300000000000001)
AssertionError                            Traceback (most recent call last)
<ipython-input-1-ccfa336aad7e> in <module>()
----> 1 arctan2(RealNumber('1.5'),-RealNumber('1.300000000000001'))
/projects/sage/sage-dev/src/sage/symbolic/function.pyx in sage.symbolic.function.BuiltinFunction.__call__ (/projects/sage/sage-dev/src/build/cythonized/sage/symbolic/function.cp
    994             res = self._evalf_try_(*args)
    995             if res is None:
--> 996                 res = super(BuiltinFunction, self).__call__(
    997                         *args, coerce=coerce, hold=hold)
/projects/sage/sage-dev/src/sage/symbolic/function.pyx in sage.symbolic.function.Function.__call__ (/projects/sage/sage-dev/src/build/cythonized/sage/symbolic/function.cpp:6589)
    489                     (<Expression>args[0])._gobj, hold)
    490         elif self._nargs == 2:
--> 491             res = g_function_eval2(self._serial, (<Expression>args[0])._gobj,
    492                     (<Expression>args[1])._gobj, hold)
    493         elif self._nargs == 3:
/projects/sage/sage-dev/src/sage/libs/pynac/pynac.pyx in sage.libs.pynac.pynac.py_atan2 (/projects/sage/sage-dev/src/build/cythonized/sage/libs/pynac/pynac.cpp:21075)()
   1790     if P is float and parent(y) is not float:
   1791         P = RR
-> 1792     assert P is parent(y)
   1793     if P is ZZ:
   1794         P = RR

In fact, pretty much any high precision input (even just padding with zeros) breaks this:

sage: atan2(2.1000000000000000000000000000000000000,-1.20000000000000000000000000000000)
AssertionError                            Traceback (most recent call last)

Reported by: Sara Billey

Change History (12)

comment:1 Changed 5 years ago by paulmasson

  • Cc paulmasson added

comment:2 Changed 5 years ago by kcrisman

  • Cc rws added

comment:3 Changed 5 years ago by rws

This was introduced in #21371. Not Pynac but its Python interface to Sage's numeric functions.

comment:4 Changed 5 years ago by rws

  • Branch set to u/rws/pynac_bug____evaluation_of_arctan2_fails_with_traceback

comment:5 Changed 5 years ago by rws

  • Authors set to Ralf Stephan
  • Commit set to 64e05e5bd2ea685ebbf020cf110c803632f56a45
  • Status changed from new to needs_review

New commits:

64e05e522553: remove assert

comment:6 Changed 5 years ago by jdemeyer

Why not use

from sage.structure.element cimport coercion_model

P = coercion_model.common_parent(x, y)

comment:7 Changed 5 years ago by jdemeyer

  • Reviewers set to Jeroen Demeyer
  • Status changed from needs_review to needs_work

I'll make that change and some further changes.

comment:8 Changed 5 years ago by jdemeyer

  • Branch changed from u/rws/pynac_bug____evaluation_of_arctan2_fails_with_traceback to u/jdemeyer/pynac_bug____evaluation_of_arctan2_fails_with_traceback

comment:9 Changed 5 years ago by jdemeyer

  • Commit changed from 64e05e5bd2ea685ebbf020cf110c803632f56a45 to a41922c5d1b46725962e13ecb8d71f353d94abe3
  • Status changed from needs_work to needs_review

New commits:

a41922cMinor fixes to py_atan2

comment:10 Changed 5 years ago by paulmasson

Jeroen, nice work on this. I've been devising ways to get around this assertion error for some time so it's nice to be rid of it. This is an elegant solution and the code cleanup looks good.

A run of make ptestlong produced the following errors:

sage -t --long src/sage/libs/ppl.pyx  # Timed out after testing finished
sage -t --long src/sage/misc/  # 3 doctests failed

The ppl.pyx error went away on a subsequent test of just that file. Strangely enough, so did the errors, so I guess we're good to go.

comment:11 Changed 5 years ago by paulmasson

  • Authors changed from Ralf Stephan to Ralf Stephan, Jeroen Demeyer
  • Reviewers changed from Jeroen Demeyer to Jeroen Demeyer, Paul Masson
  • Status changed from needs_review to positive_review

comment:12 Changed 5 years ago by vbraun

  • Branch changed from u/jdemeyer/pynac_bug____evaluation_of_arctan2_fails_with_traceback to a41922c5d1b46725962e13ecb8d71f353d94abe3
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.