Ask Your Question

Theo Bendit's profile - activity

2022-05-13 11:42:56 +0200 marked best answer Incorrect rounding at low precision

I'm trying to use Sage to implement a slightly modified bisection algorithm on a certain function, and at each step, displaying the interval endpoints as well as the function at these endpoints. I don't need much precision for the latter numbers; I just want an indication of the size and sign of these numbers. However, the numerical_approx() function is giving me weird responses when I specify the number of digits. For example, the following calculation (which is the function value at the greater endpoint, in the final step of the algorithm)

numerical_approx(1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288)

evaluates to

1.64597827478907e-7

which appears to be "reasonable", though I don't know for certain. However, when I write,

numerical_approx(1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288,digits=3)

it evaluates to

-0.0000160

which is clearly unreasonable: it's the wrong sign and it's too large. Further more, these endpoints come back to this same number a lot, despite how the input changes. At one point, in the middle of this string of -0.0000160s, Sage estimates 0.000, just once, and goes back to -0.0000160.

Changing the precision to 4 and 5 does seem to improve the situation (correct sign, more reasonable magnitude), but the significant digits are all different!

So, my questions are:

  1. What is going wrong here?
  2. Can I fix it?
  3. What methods could I use to be certain that these approximations have 3 correct significant figures?
2022-05-13 11:42:56 +0200 received badge  Scholar (source)
2022-05-13 11:42:45 +0200 commented answer Incorrect rounding at low precision

Actually, I think I just answered my own question.

2022-05-13 11:39:19 +0200 commented answer Incorrect rounding at low precision

Thank you for the answer! The RIF command strikes me as particularly handy. There is something unsettling about this tho

2022-05-13 02:21:38 +0200 received badge  Supporter (source)
2022-05-12 16:23:51 +0200 received badge  Student (source)
2022-05-12 14:45:31 +0200 asked a question Incorrect rounding at low precision

Incorrect rounding at low precision I'm trying to use Sage to implement a slightly modified bisection algorithm on a cer