Real intervals with a fixed absolute precision#

class sage.rings.real_interval_absolute.Factory[source]#

Bases: UniqueFactory

create_key(prec)[source]#

The only piece of data is the precision.

create_object(version, prec)[source]#

Ensures uniqueness.

class sage.rings.real_interval_absolute.MpfrOp[source]#

Bases: object

This class is used to endow absolute real interval field elements with all the methods of (relative) real interval field elements.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R(1).sin()
0.841470984807896506652502321631?
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R(Integer(1)).sin()
0.841470984807896506652502321631?
class sage.rings.real_interval_absolute.RealIntervalAbsoluteElement[source]#

Bases: FieldElement

Create a RealIntervalAbsoluteElement.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(50)
sage: R(1)
1
sage: R(1/3)
0.333333333333334?
sage: R(1.3)
1.300000000000000?
sage: R(pi)
3.141592653589794?
sage: R((11, 12))
12.?
sage: R((11, 11.00001))
11.00001?

sage: R100 = RealIntervalAbsoluteField(100)
sage: R(R100((5,6)))
6.?
sage: R100(R((5,6)))
6.?
sage: RIF(CIF(NaN))
[.. NaN ..]
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(50))
>>> R(Integer(1))
1
>>> R(Integer(1)/Integer(3))
0.333333333333334?
>>> R(RealNumber('1.3'))
1.300000000000000?
>>> R(pi)
3.141592653589794?
>>> R((Integer(11), Integer(12)))
12.?
>>> R((Integer(11), RealNumber('11.00001')))
11.00001?

>>> R100 = RealIntervalAbsoluteField(Integer(100))
>>> R(R100((Integer(5),Integer(6))))
6.?
>>> R100(R((Integer(5),Integer(6))))
6.?
>>> RIF(CIF(NaN))
[.. NaN ..]
abs()[source]#

Return the absolute value of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R(1/3).abs()
0.333333333333333333333333333334?
sage: R(-1/3).abs()
0.333333333333333333333333333334?
sage: R((-1/3, 1/2)).abs()
1.?
sage: R((-1/3, 1/2)).abs().endpoints()
(0, 1/2)
sage: R((-3/2, 1/2)).abs().endpoints()
(0, 3/2)
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R(Integer(1)/Integer(3)).abs()
0.333333333333333333333333333334?
>>> R(-Integer(1)/Integer(3)).abs()
0.333333333333333333333333333334?
>>> R((-Integer(1)/Integer(3), Integer(1)/Integer(2))).abs()
1.?
>>> R((-Integer(1)/Integer(3), Integer(1)/Integer(2))).abs().endpoints()
(0, 1/2)
>>> R((-Integer(3)/Integer(2), Integer(1)/Integer(2))).abs().endpoints()
(0, 3/2)
absolute_diameter()[source]#

Return the diameter self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(1/4).absolute_diameter()
0
sage: a = R(pi)
sage: a.absolute_diameter()
1/1024
sage: a.upper() - a.lower()
1/1024
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(1)/Integer(4)).absolute_diameter()
0
>>> a = R(pi)
>>> a.absolute_diameter()
1/1024
>>> a.upper() - a.lower()
1/1024
contains_zero()[source]#

Return whether self contains zero.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(10).contains_zero()
False
sage: R((10,11)).contains_zero()
False
sage: R((0,11)).contains_zero()
True
sage: R((-10,11)).contains_zero()
True
sage: R((-10,-1)).contains_zero()
False
sage: R((-10,0)).contains_zero()
True
sage: R(pi).contains_zero()
False
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(10)).contains_zero()
False
>>> R((Integer(10),Integer(11))).contains_zero()
False
>>> R((Integer(0),Integer(11))).contains_zero()
True
>>> R((-Integer(10),Integer(11))).contains_zero()
True
>>> R((-Integer(10),-Integer(1))).contains_zero()
False
>>> R((-Integer(10),Integer(0))).contains_zero()
True
>>> R(pi).contains_zero()
False
diameter()[source]#

Return the diameter self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(1/4).absolute_diameter()
0
sage: a = R(pi)
sage: a.absolute_diameter()
1/1024
sage: a.upper() - a.lower()
1/1024
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(1)/Integer(4)).absolute_diameter()
0
>>> a = R(pi)
>>> a.absolute_diameter()
1/1024
>>> a.upper() - a.lower()
1/1024
endpoints()[source]#

Return the left and right endpoints of self, as a tuple.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(1/4).endpoints()
(1/4, 1/4)
sage: R((1,2)).endpoints()
(1, 2)
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(1)/Integer(4)).endpoints()
(1/4, 1/4)
>>> R((Integer(1),Integer(2))).endpoints()
(1, 2)
is_negative()[source]#

Return whether self is definitely negative.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R(10).is_negative()
False
sage: R((10,11)).is_negative()
False
sage: R((0,11)).is_negative()
False
sage: R((-10,11)).is_negative()
False
sage: R((-10,-1)).is_negative()
True
sage: R(pi).is_negative()
False
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R(Integer(10)).is_negative()
False
>>> R((Integer(10),Integer(11))).is_negative()
False
>>> R((Integer(0),Integer(11))).is_negative()
False
>>> R((-Integer(10),Integer(11))).is_negative()
False
>>> R((-Integer(10),-Integer(1))).is_negative()
True
>>> R(pi).is_negative()
False
is_positive()[source]#

Return whether self is definitely positive.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(10).is_positive()
True
sage: R((10,11)).is_positive()
True
sage: R((0,11)).is_positive()
False
sage: R((-10,11)).is_positive()
False
sage: R((-10,-1)).is_positive()
False
sage: R(pi).is_positive()
True
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(10)).is_positive()
True
>>> R((Integer(10),Integer(11))).is_positive()
True
>>> R((Integer(0),Integer(11))).is_positive()
False
>>> R((-Integer(10),Integer(11))).is_positive()
False
>>> R((-Integer(10),-Integer(1))).is_positive()
False
>>> R(pi).is_positive()
True
lower()[source]#

Return the lower bound of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(50)
sage: R(1/4).lower()
1/4
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(50))
>>> R(Integer(1)/Integer(4)).lower()
1/4
midpoint()[source]#

Return the midpoint of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R(1/4).midpoint()
1/4
sage: R(pi).midpoint()
7964883625991394727376702227905/2535301200456458802993406410752
sage: R(pi).midpoint().n()
3.14159265358979
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R(Integer(1)/Integer(4)).midpoint()
1/4
>>> R(pi).midpoint()
7964883625991394727376702227905/2535301200456458802993406410752
>>> R(pi).midpoint().n()
3.14159265358979
mpfi_prec()[source]#

Return the precision needed to represent this value as an mpfi interval.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10)
sage: R(10).mpfi_prec()
14
sage: R(1000).mpfi_prec()
20
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10))
>>> R(Integer(10)).mpfi_prec()
14
>>> R(Integer(1000)).mpfi_prec()
20
sqrt()[source]#

Return the square root of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R(2).sqrt()
1.414213562373095048801688724210?
sage: R((4,9)).sqrt().endpoints()
(2, 3)
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R(Integer(2)).sqrt()
1.414213562373095048801688724210?
>>> R((Integer(4),Integer(9))).sqrt().endpoints()
(2, 3)
upper()[source]#

Return the upper bound of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(50)
sage: R(1/4).upper()
1/4
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(50))
>>> R(Integer(1)/Integer(4)).upper()
1/4
sage.rings.real_interval_absolute.RealIntervalAbsoluteField(*args, **kwds)[source]#

This field is similar to the RealIntervalField except instead of truncating everything to a fixed relative precision, it maintains a fixed absolute precision.

Note that unlike the standard real interval field, elements in this field can have different size and experience coefficient blowup. On the other hand, it avoids precision loss on addition and subtraction. This is useful for, e.g., series computations for special functions.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10); R
Real Interval Field with absolute precision 2^-10
sage: R(3/10)
0.300?
sage: R(1000003/10)
100000.300?
sage: R(1e100) + R(1) - R(1e100)
1
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10)); R
Real Interval Field with absolute precision 2^-10
>>> R(Integer(3)/Integer(10))
0.300?
>>> R(Integer(1000003)/Integer(10))
100000.300?
>>> R(RealNumber('1e100')) + R(Integer(1)) - R(RealNumber('1e100'))
1
class sage.rings.real_interval_absolute.RealIntervalAbsoluteField_class[source]#

Bases: Field

This field is similar to the RealIntervalField except instead of truncating everything to a fixed relative precision, it maintains a fixed absolute precision.

Note that unlike the standard real interval field, elements in this field can have different size and experience coefficient blowup. On the other hand, it avoids precision loss on addition and subtraction. This is useful for, e.g., series computations for special functions.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(10); R
Real Interval Field with absolute precision 2^-10
sage: R(3/10)
0.300?
sage: R(1000003/10)
100000.300?
sage: R(1e100) + R(1) - R(1e100)
1
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(10)); R
Real Interval Field with absolute precision 2^-10
>>> R(Integer(3)/Integer(10))
0.300?
>>> R(Integer(1000003)/Integer(10))
100000.300?
>>> R(RealNumber('1e100')) + R(Integer(1)) - R(RealNumber('1e100'))
1
absprec()[source]#

Returns the absolute precision of self.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
sage: R = RealIntervalAbsoluteField(100)
sage: R.absprec()
100
sage: RealIntervalAbsoluteField(5).absprec()
5
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import RealIntervalAbsoluteField
>>> R = RealIntervalAbsoluteField(Integer(100))
>>> R.absprec()
100
>>> RealIntervalAbsoluteField(Integer(5)).absprec()
5
sage.rings.real_interval_absolute.shift_ceil(x, shift)[source]#

Return \(x / 2^s\) where \(s\) is the value of shift, rounded towards \(+\infty\). For internal use.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import shift_ceil
sage: shift_ceil(15, 2)
4
sage: shift_ceil(-15, 2)
-3
sage: shift_ceil(32, 2)
8
sage: shift_ceil(-32, 2)
-8
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import shift_ceil
>>> shift_ceil(Integer(15), Integer(2))
4
>>> shift_ceil(-Integer(15), Integer(2))
-3
>>> shift_ceil(Integer(32), Integer(2))
8
>>> shift_ceil(-Integer(32), Integer(2))
-8
sage.rings.real_interval_absolute.shift_floor(x, shift)[source]#

Return \(x / 2^s\) where \(s\) is the value of shift, rounded towards \(-\infty\). For internal use.

EXAMPLES:

sage: from sage.rings.real_interval_absolute import shift_floor
sage: shift_floor(15, 2)
3
sage: shift_floor(-15, 2)
-4
>>> from sage.all import *
>>> from sage.rings.real_interval_absolute import shift_floor
>>> shift_floor(Integer(15), Integer(2))
3
>>> shift_floor(-Integer(15), Integer(2))
-4