Ask Your Question

Revision history [back]

To get a reliable interval, you can use the real interval field :

sage: a = 1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288
sage: RIF(a).endpoints()
(1.64597823149037e-7, 1.64597830476510e-7)

So, your first result seems correct.

Now, regarding your low precision result, let us observe the following:

sage: b = a.numerical_approx(digits=3)
sage: b
-0.0000610
sage: R = b.parent()
sage: R
Real Field with 14 bits of precision

The computation of the numerical value of the symbolic expression is done within the "field" R of floating-point numbers with only 14 bits of precision, meaning that every number is converted in R and the operations are done within R, in particular, number with large precision get rounded:

sage: R(2427673471984599040)
2.43e18

Since your symbolic expression has differences, and several coefficients get rounded, there is no reason why the sign must be preserved.

If you do the computation by hand, you can check:

sage: 1/R(2427673471984599040)*(R(1530627)*sqrt(R(4630419677705)) - R(4630419677705))*(sqrt(R(4630419677705)) - R(482051)) + R(482051)/R(524288)
-0.0000610

Now, if you only want to keep the 3 digits of precision, you can first do the computation within a field of large precision, and round afterwards:

sage: a.numerical_approx().numerical_approx(3)
1.8e-7

or

sage: R(a.numerical_approx())
1.65e-7

or

sage: R(RR(a))
1.65e-7

To get a reliable interval, you can use the real interval field RIF:

sage: a = 1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288
sage: RIF(a).endpoints()
(1.64597823149037e-7, 1.64597830476510e-7)

So, your first result seems correct.

Now, regarding your low precision result, let us observe the following:

sage: b = a.numerical_approx(digits=3)
sage: b
-0.0000610
sage: R = b.parent()
sage: R
Real Field with 14 bits of precision

The computation of the numerical value of the symbolic expression is done within the "field" R of floating-point numbers with only 14 bits of precision, meaning that every number is converted in R and the operations are done within R, in particular, number with large precision get rounded:

sage: R(2427673471984599040)
2.43e18

Since your symbolic expression has differences, and several coefficients get rounded, there is no reason why the sign must be preserved.

If you do the computation by hand, you can check:

sage: 1/R(2427673471984599040)*(R(1530627)*sqrt(R(4630419677705)) - R(4630419677705))*(sqrt(R(4630419677705)) - R(482051)) + R(482051)/R(524288)
-0.0000610

Now, if you only want to keep the 3 digits of precision, you can first do the computation within a field of large precision, and round afterwards:

sage: a.numerical_approx().numerical_approx(3)
1.8e-7

or

sage: R(a.numerical_approx())
1.65e-7

or

sage: R(RR(a))
1.65e-7

To get a reliable interval, you can use the real interval field RIF:

sage: a = 1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288
sage: RIF(a).endpoints()
(1.64597823149037e-7, 1.64597830476510e-7)

So, your first result seems correct.

Now, regarding your low precision result, let us observe the following:

sage: b = a.numerical_approx(digits=3)
sage: b
-0.0000610
sage: R = b.parent()
sage: R
Real Field with 14 bits of precision

The computation of the numerical value of the symbolic expression is done within the "field" R of floating-point numbers with only 14 bits of precision, meaning that every number apperaing in the symbolic expression is converted in R and then the operations are done within R, in particular, number numbers with large precision get rounded:

sage: R(2427673471984599040)
2.43e18

Since your symbolic expression has differences, and several coefficients get rounded, there is no reason why the sign must be preserved.

If you do the computation by hand, you can check:

sage: 1/R(2427673471984599040)*(R(1530627)*sqrt(R(4630419677705)) - R(4630419677705))*(sqrt(R(4630419677705)) - R(482051)) + R(482051)/R(524288)
-0.0000610

Now, if you only want to keep the 3 digits of precision, you can first do the computation within a field of large precision, and round afterwards:

sage: a.numerical_approx().numerical_approx(3)
1.8e-7

or

sage: R(a.numerical_approx())
1.65e-7

or

sage: R(RR(a))
1.65e-7

To get a reliable interval, you can use the real interval field RIF:

sage: a = 1/2427673471984599040*(1530627*sqrt(4630419677705) - 4630419677705)*(sqrt(4630419677705) - 482051) + 482051/524288
sage: RIF(a).endpoints()
(1.64597823149037e-7, 1.64597830476510e-7)

So, your first result seems correct.

Now, regarding your low precision result, let us observe the following:

sage: b = a.numerical_approx(digits=3)
sage: b
-0.0000610
sage: R = b.parent()
sage: R
Real Field with 14 bits of precision

The computation of the numerical value of the symbolic expression is done within the "field" R of floating-point numbers with only 14 bits of precision, meaning that every number apperaing in the symbolic expression is converted in R and then the operations are done within R, in particular, numbers with large precision get rounded:

sage: R(2427673471984599040)
2.43e18

Since your symbolic expression has differences, and several coefficients get rounded, there is no reason why the sign must be preserved.

If you do the computation by hand, you can check:

sage: 1/R(2427673471984599040)*(R(1530627)*sqrt(R(4630419677705)) - R(4630419677705))*(sqrt(R(4630419677705)) - R(482051)) + R(482051)/R(524288)
-0.0000610

Now, if you only want to keep the 3 digits of precision, you can first do the computation within a field of large precision, and round afterwards:

sage: a.numerical_approx().numerical_approx(3)
1.8e-7
a.numerical_approx().numerical_approx(digits=3)
1.65e-7

or

sage: R(a.numerical_approx())
1.65e-7

or

sage: R(RR(a))
1.65e-7