Opened 12 years ago
Closed 5 years ago
#9937 closed defect (invalid)
PARI real precision is broken in many ways
Reported by: | jdemeyer | Owned by: | was |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | interfaces | Keywords: | pari gp real precision set_real_precision |
Cc: | Merged in: | ||
Authors: | Reviewers: | Jeroen Demeyer | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
The following do not work as they should (try these examples with a freshly started copy of Sage, such that everything is default).
This is definately a bug with the initialization of the precision:
# Default: 2 significant words (while we really should get only 1) sage: pari('Pi').debug() [&=0000000004fc9620] REAL(lg=4):0400000000000004 (+,expo=1):6000000000000001 c90fdaa22168c234 c4c6628b80dc1cd1 # Change precision and then change it back: we get 1 word sage: n = pari.get_real_precision(); pari.set_real_precision(100); pari.set_real_precision(n); sage: pari('Pi').debug() [&=00000000012bf200] REAL(lg=3):0400000000000003 (+,expo=1):6000000000000001 c90fdaa22168c235
set_real_precision()
seems to affect essentially only the precision for evaluating strings in PARI and not much else:
sage: pari.set_real_precision(50); sage: pari('Euler') # Precision changes 0.57721566490153286060651209008240243104215933593992 sage: pari.euler() # Precision does NOT change 0.5772156649015328607
This last behaviour is actually documented in sage/libs/pari/gen.pyx
:
Unless otherwise indicated in the docstring, most Pari functions that return inexact objects use the precision of their arguments to decide the precision of the computation. However, if some of these arguments happen to be exact numbers (integers, rationals, etc.), an optional parameter indicates the precision (in bits) to which these arguments should be converted before the computation. If this precision parameter is missing, the default precision of 53 bits is used.
In other words, the default precision is an unchangable 53 bits. I would expect set_real_precision()
to change this. This is also trivial to implement since the global variable prec
is already there (and initialized once and for all to 53).
Attachments (1)
Change History (17)
comment:1 Changed 12 years ago by
- Description modified (diff)
comment:2 Changed 12 years ago by
- Description modified (diff)
- Keywords set_real_precision added
comment:3 follow-up: ↓ 4 Changed 12 years ago by
comment:4 in reply to: ↑ 3 Changed 12 years ago by
Replying to cremona:
There's a lot of relevant information written by Alex Ghitza and me a couple of years ago in the file gen.pyx. Yes, it is counterintuitive; but not undocumented.
I know it is documented (although not too clearly), but the question is: does it make sense? (In my opinion: no).
comment:5 Changed 12 years ago by
More precisely: this is counter-intuitive:
sage: pari.set_real_precision(100); sage: pari('Euler') # Precision changes 0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495 sage: pari.euler() # Precision does NOT change 0.5772156649015328607
comment:6 Changed 11 years ago by
- Description modified (diff)
comment:7 Changed 11 years ago by
- Description modified (diff)
comment:8 Changed 11 years ago by
- Status changed from new to needs_work
comment:9 Changed 11 years ago by
- Description modified (diff)
comment:10 Changed 11 years ago by
- Dependencies set to #11130, #11321
- Description modified (diff)
- Milestone changed from sage-4.7.2 to sage-pending
comment:11 Changed 11 years ago by
- Dependencies changed from #11130, #11321 to #11130, #11321, #11130, #11321, #11904
comment:12 Changed 11 years ago by
- Dependencies changed from #11130, #11321, #11130, #11321, #11904 to #11854, #11130, #11321, #11130, #11321, #11904
comment:13 Changed 11 years ago by
- Dependencies changed from #11854, #11130, #11321, #11130, #11321, #11904 to #11854, #11130, #11321, #11891, #11890, #11836, #11904
comment:14 Changed 11 years ago by
- Dependencies changed from #11854, #11130, #11321, #11891, #11890, #11836, #11904 to #11854, #11130, #11321, #11891, #11890, #11836, #11952, #11904
comment:15 Changed 10 years ago by
- Dependencies #11854, #11130, #11321, #11891, #11890, #11836, #11952, #11904 deleted
Changed 10 years ago by
comment:16 Changed 5 years ago by
- Milestone changed from sage-pending to sage-duplicate/invalid/wontfix
- Resolution set to invalid
- Reviewers set to Jeroen Demeyer
- Status changed from needs_work to closed
There's a lot of relevant information written by Alex Ghitza and me a couple of years ago in the file gen.pyx. Yes, it is counterintuitive; but not undocumented.