Opened 11 years ago

Last modified 7 years ago

#8074 needs_info defect

corner cases in RealField and real numbers

Reported by: jason Owned by: jkantor
Priority: major Milestone: sage-6.4
Component: numerical Keywords:
Cc: robertwb, was, jkantor, zimmerma, leif Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by jason)

What should these return?

sage: RR('inf').is_real()
True
sage: RR('nan').is_real()
True
sage: RR('inf').is_unit()
True
sage: RR('nan')==RR('nan')
True
sage: RR('nan').__nonzero__()
False
sage: RR('nan').__pow(0.5)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
^CERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "/home/grout/sage/local/lib/python2.6/site-packages/IPython/ultraTB.py", line 614, in text
    records = _fixed_getinnerframes(etb, context,self.tb_offset)
  File "/home/grout/sage/local/lib/python2.6/site-packages/IPython/ultraTB.py", line 230, in _fixed_getinnerframes
    records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/home/grout/sage/local/lib/python/inspect.py", line 942, in getinnerframes
    framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "/home/grout/sage/local/lib/python/inspect.py", line 902, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/home/grout/sage/local/lib/python/inspect.py", line 451, in getsourcefile
    if hasattr(getmodule(object, filename), '__loader__'):
  File "/home/grout/sage/local/lib/python/inspect.py", line 485, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "/home/grout/sage/local/lib/python2.6/site-packages/sage/interfaces/get_sigs.py", line 9, in my_sigint
    raise KeyboardInterrupt
KeyboardInterrupt

Unfortunately, your original traceback can not be constructed.
sage: RR('-inf').__pow(0.5)
+infinity
sage: sqrt(RR('-inf'))     
+infinity*I

Change History (15)

comment:1 Changed 11 years ago by jason

  • Milestone set to sage-4.3.2

comment:2 Changed 11 years ago by jason

  • Status changed from new to needs_info

comment:3 Changed 11 years ago by jason

And this:

sage: RR('nan').__nonzero__()
False

comment:4 Changed 11 years ago by jason

And another corner case:

sage: RR('nan')==RR('nan')
True

comment:5 follow-up: Changed 11 years ago by jason

Another one:

sage: RR('nan').__pow(0.5)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
^CERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "/home/grout/sage/local/lib/python2.6/site-packages/IPython/ultraTB.py", line 614, in text
    records = _fixed_getinnerframes(etb, context,self.tb_offset)
  File "/home/grout/sage/local/lib/python2.6/site-packages/IPython/ultraTB.py", line 230, in _fixed_getinnerframes
    records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/home/grout/sage/local/lib/python/inspect.py", line 942, in getinnerframes
    framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "/home/grout/sage/local/lib/python/inspect.py", line 902, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/home/grout/sage/local/lib/python/inspect.py", line 451, in getsourcefile
    if hasattr(getmodule(object, filename), '__loader__'):
  File "/home/grout/sage/local/lib/python/inspect.py", line 485, in getmodule
    if ismodule(module) and hasattr(module, '__file__'):
  File "/home/grout/sage/local/lib/python2.6/site-packages/sage/interfaces/get_sigs.py", line 9, in my_sigint
    raise KeyboardInterrupt
KeyboardInterrupt

Unfortunately, your original traceback can not be constructed.

comment:6 Changed 11 years ago by jason

sage: RR('-inf').__pow(0.5)
+infinity
sage: sqrt(RR('-inf'))     
+infinity*I

comment:7 Changed 11 years ago by jason

  • Description modified (diff)

comment:8 Changed 11 years ago by jason

  • Cc zimmerma added

Paul,

You are one of the best experts around on floating point issues. If you have time, could you comment on the corner cases listed in the description---do you agree with the current output of Sage, or should it be changed?

Thanks, Jason

(I put all of the corner cases from #7682 and from the comments on this ticket up in the description.)

comment:9 Changed 11 years ago by zimmerma

You are one of the best experts around on floating point issues...

thanks, you are putting pressure on me! I'll try to do my best...

One first problem is that is_real is not documented, thus I don't know what the intended semantics is or was. In MPFR there is no such function:

 -- Function: int mpfr_nan_p (mpfr_t OP)
 -- Function: int mpfr_inf_p (mpfr_t OP)
 -- Function: int mpfr_number_p (mpfr_t OP)
 -- Function: int mpfr_zero_p (mpfr_t OP)
     Return non-zero if OP is respectively NaN, an infinity, an ordinary
     number (i.e. neither NaN nor an infinity) or zero. Return zero
     otherwise.

About RR('inf').is_unit(), if one considers that x is a unit if 1/x is in RR, then since 1/inf = 0 is in RR, it should return true.

RR('nan')==RR('nan') should return False according to IEEE 754.

RR('nan').__pow(0.5) should return NaN (here NaN means "can be any real number").

RR('-inf').__pow(0.5) is ok according to the MPFR rules (here I assume that we try to stay in RR):

        * `pow(-Inf, Y)' returns plus infinity for Y positive and not
          an odd integer.

For sqrt(RR('-inf')) it depends on the semantics of the sqrt function. Apparently it extends to the complex plane (try sqrt(RR(-1))) thus the answer seems ok to me.

RR('nan').__nonzero__() is more difficult, since "NaN" means "can be any real", thus in particular it can be zero, thus the answer should be "maybe". If no ternary answer is possible, false seems the best one.

comment:10 Changed 11 years ago by leif

  • Cc leif added

comment:11 in reply to: ↑ 5 Changed 11 years ago by jdemeyer

Replying to jason:

sage: RR('nan').__pow(0.5)
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
...

Regardless of whatever the output of RR('nan').__pow(0.5) should be, it is a bug by itself that we don't get a decent exception here...

comment:12 Changed 8 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:13 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:14 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:15 Changed 7 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.