adding real literal and real number of high precision
When Sage is adding a real literal to a real number of high precision, shouldn't it calculate the sum in the high precision ring? Instead, Sage seems to calculate in double precision:
RF=RealField(150); RF
Real Field with 150 bits of precision
RF(0.9 + RF(1e-18))
0.90000000000000002220446049250313080847263336
RF(1.0+ RF(1e-18))
1.0000000000000000000000000000000000000000000
RF(1+ RF(1e-18))
1.0000000000000000010000000000000000000000000
I'm trying to use high precision arithmetic (2658 bits) in Sage to verify some results produced by the high precision semidefinite program solver sdpa_gmp. Sage's treatment of real literals in these calculations has made me anxious about the possibility that I'm overlooking other ways in which the calculations might be unreliable.
Is there anywhere an explanation of Sage's treatment of real literals in high precision arithmetic?
Added: Immediately after posting this question, the list of Related Questions in the sidebar pointed me to question/327/set-global-precision-for-reals where I learned that 'RealNumber = RF' would make all real literals lie in the high precision ring. Still, I wonder why the default behavior is to discard precision that is present in the original real literal.
thanks, Daniel Friedan
thanks for
I'm sure there are technical answers, but I think the basic answer is just that we would go to the *lesser* precision, to be sure we are right, when we combine two numbers of different precision. That makes sense to me. `0.9` and friends are default 53-bit precision, while `1` is an `Integer` and so has arbitrarily high precision and preserves what you want.
There seem to be inconsistencies: RF(.5 + .4 ) 0.90000000000000002220446049250313080847263336 RF(.3+.7) 1.0000000000000000000000000000000000000000000 If .4 and .5 are added as double precision, why not .3 and .7 ?
EDIT: my previous comment missed the point of your question. The computation is actually done in double precision both times, but RF(RDF(1.0)) = 1.0000000000000000000000000000000000000000000 while RF(RDF(0.9)) = 0.90000000000000002220446049250313080847263336. Which makes the second addition look like it was done in RF all along.
But RF(RDF(0.3))= 0.29999999999999998889776975374843459576368332 and RF(RDF(0.7))= 0.69999999999999995559107901499373838305473328 so how can RF(0.3+0.7)= 1.0000000000000000000000000000000000000000000 if the addition is being done in double precision?