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

log of NaN in RealField and ComplexField results in infinite loop #15388

Closed
pfili opened this issue Nov 9, 2013 · 17 comments
Closed

log of NaN in RealField and ComplexField results in infinite loop #15388

pfili opened this issue Nov 9, 2013 · 17 comments

Comments

@pfili
Copy link

pfili commented Nov 9, 2013

If you have a RealField or ComplexField NaN value and attempt to compute log, the fact that NaN is considered < 0 results in RealField.log calling ComplexField.log, but then ComplexField.log calls RealField.log again, but again on the values NaN for the absolute value. This results in an infinite loop. Example code for the code:

x = RealField()(NaN)
x.log() # Results in infinite loop

This patch fixes the log function in RealField and ComplexField to return NaN if fed a number which is NaN (in either the real or the imaginary coordinate).

CC: @sagetrac-atowsley

Component: numerical

Keywords: sage-days55

Author: Paul Fili, Adam Towsley

Reviewer: Benjamin Hutz

Merged: sage-5.13.beta3

Issue created by migration from https://trac.sagemath.org/ticket/15388

@pfili pfili added this to the sage-5.13 milestone Nov 9, 2013
@bhutz
Copy link

bhutz commented Nov 10, 2013

comment:3

A couple things

  1. the patch needs a commit message

  2. the patch name should be trac_15388_.patch

  3. Please add a doctest to each log function to demonstrate the fix

  4. lines 2063, 2064 which are commented out look like they can just be removed as they add no value to the code

@bhutz
Copy link

bhutz commented Nov 10, 2013

Reviewer: Ben Hutz

@bhutz
Copy link

bhutz commented Nov 10, 2013

comment:5

long doctest looks fine with this, so I'm happy with the code change, just make the minor changes suggested above.

Just to note, I had a few unrelated longtest failures on 5.12 that failed both with and without the patch.

sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/sage/tests/cmdline.py  # 11 doctests failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/sage/calculus/desolvers.py  # 8 doctests failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/doc/en/constructions/calculus.rst  # 4 doctests failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/doc/en/prep/Quickstarts/Differential-Equations.rst  # 2 doctests failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/sage/misc/interpreter.py  # 1 doctest failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/sage/misc/trace.py  # 2 doctests failed
sage -t --long /home/bhutz/sage/sage-5.12/devel/sage/sage/tests/interrupt.pyx  # Time out

@pfili
Copy link
Author

pfili commented Nov 10, 2013

comment:7

It is probably best not to have an example involving NaN in the log's documentation, as it is such a basic function and this case is rather exceptional. (Although we still want it to work in case a log appears in someone's code after an NaN has already appeared, as happened to us when we found this bug.)

@pfili
Copy link
Author

pfili commented Nov 10, 2013

comment:8

We have made the changes Ben suggested, except for adding a doctest, which seems undesirable as noted above.

@bhutz
Copy link

bhutz commented Nov 10, 2013

comment:10

This looks good.

@jdemeyer
Copy link

Work Issues: doctest

@jdemeyer
Copy link

comment:11

Replying to @pfili:

Although we still want it to work in case a log appears in someone's code after an NaN has already appeared, as happened to us when we found this bug.

Which is exactly why a doctest is needed.

@pfili
Copy link
Author

pfili commented Nov 12, 2013

comment:12

I have added a doctest that explains the behavior for NaN.

@bhutz
Copy link

bhutz commented Nov 12, 2013

comment:13

Ok. This still looks fine and now we have the doctests.

@jdemeyer
Copy link

comment:14

You should add a meaningful commit message (use hg qrefresh -e for that)

@jdemeyer
Copy link

Changed work issues from doctest to none

@pfili
Copy link
Author

pfili commented Nov 12, 2013

Fixes the behavior of log(NaN) in real and complex fields

@pfili
Copy link
Author

pfili commented Nov 12, 2013

comment:15

Attachment: trac_15388_nan_fix.patch.gz

Commit message has been added.

@bhutz
Copy link

bhutz commented Nov 13, 2013

comment:16

ok. still looks good, but with a commit message this time.

@jdemeyer
Copy link

Merged: sage-5.13.beta3

@jdemeyer
Copy link

Changed reviewer from Ben Hutz to Benjamin Hutz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants