Ticket #962 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[with patch, with positive revew] automatic precision extension for long decimal literals does very strange things

Reported by: cwitty Owned by: mhansen
Priority: major Milestone: sage-2.8.15
Component: basic arithmetic Keywords:
Cc: Author(s):
Report Upstream: Reviewer(s):
Merged in: Work issues:

Description

Long decimal literals become floating-point numbers whose precision depends on the length of the input literal in characters. See this script for some of the confusing (and, in my opinion, wrong) behavior that results.

sage: (1.10000000000000000000).prec()
73
sage: (1.10000000000000000000e0).prec()
79
sage: (1e-25).prec()
53
sage: (0.0000000000000000000000001).prec()
89
sage: (00000000.0000000000000000000000001).prec()
112

Attachments

962.patch Download (3.2 KB) - added by mhansen 2 years ago.
Initial version
962-2.patch Download (3.1 KB) - added by mhansen 2 years ago.
962-doctests.patch Download (27.4 KB) - added by mhansen 2 years ago.

Change History

Changed 2 years ago by malb

  • owner changed from somebody to cwitty

Changed 2 years ago by mhansen

  • owner changed from cwitty to mhansen
  • status changed from new to assigned
  • milestone changed from sage-2.8.9 to sage-2.8.10

Changed 2 years ago by mhansen

  • milestone changed from sage-2.8.10 to sage-2.9

Changed 2 years ago by mhansen

Initial version

Changed 2 years ago by mhansen

  • summary changed from automatic precision extension for long decimal literals does very strange things to [with patch] automatic precision extension for long decimal literals does very strange things

I posted an initial patch which fixes some of the major issues. I would like others to comment on it to make sure the final version of this patch does the "right thing" since it will break lots of doctests.

Changed 2 years ago by mhansen

Here is the behavior of the above examples after the patch:

sage: sage: (1.10000000000000000000).prec()
74
sage: sage: (1.10000000000000000000e0).prec()
74
sage: sage: (1e-25).prec()
87
sage: sage: (0.0000000000000000000000001).prec()
87
sage: sage: (00000000.0000000000000000000000001).prec()
87

Changed 2 years ago by cwitty

Actually, I think that all of the last three examples should give 53 (that is, leading zeroes shouldn't affect the precision). I think that matches the rules for significant figures I learned in grade school...

Changed 2 years ago by mabshoff

  • milestone changed from sage-2.9.1 to sage-2.8.13

Changed 2 years ago by was

NOT YET -- note that I think many doctests will (and should) break after applying this patch, so this isn't being posted to actually include in the next release. It's being posted for feedback. After people like it, then Mike will post an additional patch that fixes all failing doctests.

I also think I agree with Carl witty's remark above about significant figures.

Changed 2 years ago by cwitty

  • summary changed from [with patch] automatic precision extension for long decimal literals does very strange things to [with patch, with negative revew] automatic precision extension for long decimal literals does very strange things

Changed 2 years ago by cwitty

  • summary changed from [with patch, with negative revew] automatic precision extension for long decimal literals does very strange things to [with partial patch (deliberately breaks doctests), with negative revew] automatic precision extension for long decimal literals does very strange things

Changed 2 years ago by mhansen

Patch updated that now gives the following results:

sage: sage: sage: (1.10000000000000000000).prec()
74
sage: sage: sage: (1.10000000000000000000e0).prec()
74
sage: sage: sage: (1e-25).prec()
53
sage: sage: sage: (0.0000000000000000000000001).prec()
53
sage: sage: sage: (00000000.0000000000000000000000001).prec()
53

Changed 2 years ago by mhansen

Changed 2 years ago by cwitty

  • summary changed from [with partial patch (deliberately breaks doctests), with negative revew] automatic precision extension for long decimal literals does very strange things to [with partial patch (deliberately breaks doctests), with positive revew] automatic precision extension for long decimal literals does very strange things

Looks good to me! Thank you for making so many changes at my request.

Changed 2 years ago by mhansen

This causes the following doctest failures:

        sage -t  devel/sage-main/sage/modular/dirichlet.py
        sage -t  devel/sage-main/sage/gsl/dft.py
        sage -t  devel/sage-main/sage/functions/constants.py
        sage -t  devel/sage-main/sage/calculus/calculus.py
        sage -t  devel/sage-main/sage/calculus/wester.py
        sage -t  devel/sage-main/sage/interfaces/gp.py
        sage -t  devel/sage-main/sage/misc/functional.py
        sage -t  devel/sage-main/sage/rings/real_mpfr.pyx
        sage -t  devel/sage-main/sage/rings/fraction_field_element.py
        sage -t  devel/sage-main/sage/rings/rational.pyx
        sage -t  devel/sage-main/sage/rings/arith.py
        sage -t  devel/sage-main/sage/rings/integer.pyx
        sage -t  devel/sage-main/sage/rings/contfrac.py
        sage -t  devel/sage-main/sage/rings/qqbar.py
        sage -t  devel/sage-main/sage/rings/number_field/number_field.py
        sage -t  devel/sage-main/sage/rings/complex_number.pyx
        sage -t  devel/sage-main/sage/rings/complex_interval.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/real_roots.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/polynomial_element.pyx
        sage -t  devel/sage-main/sage/rings/polynomial/complex_roots.py
        sage -t  devel/sage-main/sage/rings/real_mpfi.pyx

I will post a patch in a bit fixing this.

Changed 2 years ago by cwitty

  • summary changed from [with partial patch (deliberately breaks doctests), with positive revew] automatic precision extension for long decimal literals does very strange things to [with patch, with positive revew] automatic precision extension for long decimal literals does very strange things

Excellent! I read through 962-doctests.patch (yes, I really did), and I only saw one issue: on real_mpfr.pyx line 21, we will need to change:

    2147483647.00000         # 32-bit

to

    2.14748364700000e9       # 32-bit

Changed 2 years ago by mhansen

The patches should be applied in this order: 1) 962-2.patch 2) 962-doctests.patch

Changed 2 years ago by mhansen

Changed 2 years ago by mabshoff

  • status changed from assigned to closed
  • resolution set to fixed

Merged in 2.8.15.alpha2.

Note: See TracTickets for help on using tickets.