Sage: Ticket #21614: Doctest fix for: Make atan2(0,0) return NaN
https://trac.sagemath.org/ticket/21614
<p>
Same with <code>tan</code> and <code>imag</code>:
</p>
<pre class="wiki">sage: real(sqrt(sin(x)))
sqrt(abs(sin(x)))*cos(1/2*arctan2(cos(real_part(x))*sinh(imag_part(x)), cosh(imag_part(x))*sin(real_part(x))))
sage: _.subs(x==0)
...
RuntimeError: arctan2_eval(): arctan2(0,0) encountered
</pre><p>
SymPy expands similarly but gives NaN on substitution instead of an exception.
</p>
<p>
This all would not be of concern if not 3d plotting would likely need real/imag parts of a function, their workaround <code>real(...,hold=True)</code> works perfectly but this is not the general solution that is needed.
</p>
<p>
One solution would be to return <code>NaN</code> instead of throwing up.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/21614
Trac 1.1.6rwsSat, 01 Oct 2016 07:22:58 GMTdescription changed; dependencies set
https://trac.sagemath.org/ticket/21614#comment:1
https://trac.sagemath.org/ticket/21614#comment:1
<ul>
<li><strong>dependencies</strong>
set to <em>pynac-0.6.91</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/21614?action=diff&version=1">diff</a>)
</li>
</ul>
TicketmmezzarobbaSat, 01 Oct 2016 09:39:45 GMT
https://trac.sagemath.org/ticket/21614#comment:2
https://trac.sagemath.org/ticket/21614#comment:2
<p>
I'm a bit uncomfortable with the idea of returning NaN for exact (as opposed to floating-point) input... But more importantly, my feeling is that we need to decide and <strong>document</strong> once and for all how symbolic functions should behave depending on the type, parent and value of their argument(s), based on the many examples you collected, instead of coming up with ad hoc solutions every time.
</p>
TicketrwsSat, 01 Oct 2016 12:54:38 GMT
https://trac.sagemath.org/ticket/21614#comment:3
https://trac.sagemath.org/ticket/21614#comment:3
<p>
Then make it known in that <strong>documentation</strong> that I just decided that symbolic NaN is to be returned whenever the result is not defined, not even complex infinity. That pertains to expressions, not relations. It could also be returned with <code>0/0</code>.
</p>
<p>
I think the SymPy folks have thought more about their ad hoc solution, and if I copy it it's not ad hoc, either.
</p>
<pre class="wiki">Not a Number.
This serves as a place holder for numeric values that are indeterminate.
Most operations on NaN, produce another NaN. Most indeterminate forms,
such as ``0/0`` or ``oo - oo` produce NaN. Two exceptions are ``0**0``
and ``oo**0``, which all produce ``1`` (this is consistent with Python's
float).
NaN is loosely related to floating point nan, which is defined in the
IEEE 754 floating point standard, and corresponds to the Python
``float('nan')``. Differences are noted below.
NaN is mathematically not equal to anything else, even NaN itself. This
explains the initially counter-intuitive results with ``Eq`` and ``==`` in
the examples below.
NaN is not comparable so inequalities raise a TypeError. This is in
constrast with floating point nan where all inequalities are false.
</pre>
TicketrwsSat, 01 Oct 2016 13:07:07 GMTbranch set
https://trac.sagemath.org/ticket/21614#comment:4
https://trac.sagemath.org/ticket/21614#comment:4
<ul>
<li><strong>branch</strong>
set to <em>u/rws/make_atan2_0_0__return_nan</em>
</li>
</ul>
TicketrwsSun, 02 Oct 2016 14:44:34 GMTdependencies changed; commit set
https://trac.sagemath.org/ticket/21614#comment:5
https://trac.sagemath.org/ticket/21614#comment:5
<ul>
<li><strong>commit</strong>
set to <em>fda5183e4f4cbf498d23744924694756ec5e9a51</em>
</li>
<li><strong>dependencies</strong>
changed from <em>pynac-0.6.91</em> to <em>#21623</em>
</li>
</ul>
<p>
New commits:
</p>
<table class="wiki">
<tr><td><a class="ext-link" href="https://git.sagemath.org/sage.git/commit?id=fda5183e4f4cbf498d23744924694756ec5e9a51"><span class="icon"></span>fda5183</a></td><td><code>21614: fix some real/imag part expansions</code>
</td></tr></table>
TicketmmezzarobbaMon, 03 Oct 2016 12:40:58 GMT
https://trac.sagemath.org/ticket/21614#comment:6
https://trac.sagemath.org/ticket/21614#comment:6
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21614#comment:3" title="Comment 3">rws</a>:
</p>
<blockquote class="citation">
<p>
Then make it known in that <strong>documentation</strong> that I just decided that symbolic NaN is to be returned whenever the result is not defined, not even complex infinity. That pertains to expressions, not relations. It could also be returned with <code>0/0</code>.
</p>
</blockquote>
<p>
Sorry if my comment came off as a criticism, that was not the intent. What I'm trying to say is that I find this kind of tickets hard to review, because I'm unable to tell if the change is actually an improvement (because it fixes a perceived issue) or a regression (typically because it introduces an inconsistency across different parts of Sage).
</p>
TicketrwsMon, 03 Oct 2016 13:03:46 GMT
https://trac.sagemath.org/ticket/21614#comment:7
https://trac.sagemath.org/ticket/21614#comment:7
<p>
It is very hard to keep an overview of all details that can appear in "symbolics" (minus algebra). There are some bright people leading the SymPy effort. I think it's a good start to follow them.
</p>
TicketrwsSun, 06 Nov 2016 14:26:39 GMTstatus, summary changed; author set
https://trac.sagemath.org/ticket/21614#comment:8
https://trac.sagemath.org/ticket/21614#comment:8
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>author</strong>
set to <em>Ralf Stephan</em>
</li>
<li><strong>summary</strong>
changed from <em>Make atan2(0,0) return NaN</em> to <em>Doctest fix for: Make atan2(0,0) return NaN</em>
</li>
</ul>
TicketjdemeyerFri, 11 Nov 2016 16:43:11 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/21614#comment:9
https://trac.sagemath.org/ticket/21614#comment:9
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Jeroen Demeyer</em>
</li>
</ul>
TicketvbraunSat, 12 Nov 2016 23:01:20 GMTstatus, branch changed; resolution set
https://trac.sagemath.org/ticket/21614#comment:10
https://trac.sagemath.org/ticket/21614#comment:10
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>branch</strong>
changed from <em>u/rws/make_atan2_0_0__return_nan</em> to <em>fda5183e4f4cbf498d23744924694756ec5e9a51</em>
</li>
</ul>
Ticket