Opened 12 years ago
Closed 10 years ago
#9953 closed defect (duplicate)
int(symbolic expr) off by 1
Reported by: | Harald Schilly | Owned by: | Burcin Erocal |
---|---|---|---|
Priority: | critical | Milestone: | sage-duplicate/invalid/wontfix |
Component: | symbolics | Keywords: | |
Cc: | Fredrik Johansson, Karl-Dieter Crisman, Zafeirakis Zafeirakopoulos, Michael Orlitzky | Merged in: | |
Authors: | Reviewers: | Burcin Erocal | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
Problem, last digit is either 6 or 7. In short:
fermat(n) = 2**2**n + 1 fermat(9) gives ....4097 but: int(fermat(9)) gives ...4096L. Same with: long(fermat(9)). int(2**2**9 +1) gives ...4097L
Burcin says: int(x) for a symbolic expression x just calls int(x.n(prec=100)). We lose that 1 in the approximation.
full example in 4.5.2:
sage: fermat(n) = 2**2**n + 1 sage: fermat(9) 134078079299425970995740249982058461274793658205923933777\ 235614437217640300735469768018742981669034276900318581864\ 86050853753882811946569946433649006084097 sage: int(fermat(9)) 134078079299425970995740249982058461274793658205923933777\ 235614437217640300735469768018742981669034276900318581864\ 86050853753882811946569946433649006084096L sage: long(fermat(9)) 134078079299425970995740249982058461274793658205923933777\ 235614437217640300735469768018742981669034276900318581864\ 86050853753882811946569946433649006084096L sage: int(2**2**9 +1) 134078079299425970995740249982058461274793658205923933777\ 235614437217640300735469768018742981669034276900318581864\ 86050853753882811946569946433649006084097L
Attachments (1)
Change History (9)
comment:1 Changed 12 years ago by
Cc: | Karl-Dieter Crisman added |
---|
Changed 12 years ago by
Attachment: | 9953.patch added |
---|
comment:2 Changed 12 years ago by
Status: | new → needs_work |
---|
comment:3 Changed 12 years ago by
The current patch won't work for 0 or negative numbers (the log2 breaks). This can be easily fixed, but dealing with cases like
sage: f = 1-1/10**100 sage: int(f) 0 sage: int(SR(f)) 1
where the precision needed to get the right result isn't a function of the size is a little trickier. Maybe fast-path the common cases and then fall back on the existing floor/ceil logic?
comment:5 Changed 11 years ago by
Cc: | Zafeirakis Zafeirakopoulos added |
---|
comment:6 Changed 10 years ago by
Cc: | Michael Orlitzky added |
---|
comment:7 Changed 10 years ago by
Milestone: | sage-5.1 → sage-duplicate/invalid/wontfix |
---|---|
Reviewers: | → Burcin Erocal |
Status: | needs_work → positive_review |
#12968 has a patch with a positive review which fixes this. We should close this as a duplicate.
comment:8 Changed 10 years ago by
Resolution: | → duplicate |
---|---|
Status: | positive_review → closed |
I don't want to work on this much, but I believe that this patch should fix the problem. If someone wants to add some doctests and polish it a bit, go for it.