Arbitrary precision complex intervals (parent class)

AUTHORS:

  • William Stein wrote complex_field.py.

  • William Stein (2006-01-26): complete rewrite

Then complex_field.py was copied to complex_interval_field.py and heavily modified:

  • Carl Witty (2007-10-24): rewrite for intervals

  • Niles Johnson (2010-08): Issue #3893: random_element() should pass on *args and **kwds.

  • Travis Scrimshaw (2012-10-18): Added documentation to get full coverage.

Note

The ComplexIntervalField differs from ComplexField in that ComplexIntervalField only gives the digits with exact precision, then a ? signifying that the last digit can have an error of +/-1.

sage.rings.complex_interval_field.ComplexIntervalField(prec=53, names=None)[source]

Return the complex interval field with real and imaginary parts having prec bits of precision.

EXAMPLES:

sage: ComplexIntervalField()
Complex Interval Field with 53 bits of precision
sage: ComplexIntervalField(100)
Complex Interval Field with 100 bits of precision
sage: ComplexIntervalField(100).base_ring()
Real Interval Field with 100 bits of precision
sage: i = ComplexIntervalField(200).gen()
sage: i^2
-1
sage: i^i
0.207879576350761908546955619834978770033877841631769608075136?
>>> from sage.all import *
>>> ComplexIntervalField()
Complex Interval Field with 53 bits of precision
>>> ComplexIntervalField(Integer(100))
Complex Interval Field with 100 bits of precision
>>> ComplexIntervalField(Integer(100)).base_ring()
Real Interval Field with 100 bits of precision
>>> i = ComplexIntervalField(Integer(200)).gen()
>>> i**Integer(2)
-1
>>> i**i
0.207879576350761908546955619834978770033877841631769608075136?
class sage.rings.complex_interval_field.ComplexIntervalField_class(prec=53)[source]

Bases: ComplexIntervalField

The field of complex (interval) numbers.

EXAMPLES:

sage: C = ComplexIntervalField(); C
Complex Interval Field with 53 bits of precision
sage: Q = RationalField()
sage: C(1/3)
0.3333333333333334?
sage: C(1/3, 2)
0.3333333333333334? + 2*I
>>> from sage.all import *
>>> C = ComplexIntervalField(); C
Complex Interval Field with 53 bits of precision
>>> Q = RationalField()
>>> C(Integer(1)/Integer(3))
0.3333333333333334?
>>> C(Integer(1)/Integer(3), Integer(2))
0.3333333333333334? + 2*I

We can also coerce rational numbers and integers into C, but coercing a polynomial will raise an exception:

sage: Q = RationalField()
sage: C(1/3)
0.3333333333333334?
sage: S.<x> = PolynomialRing(Q)
sage: C(x)
Traceback (most recent call last):
...
TypeError: cannot convert nonconstant polynomial
>>> from sage.all import *
>>> Q = RationalField()
>>> C(Integer(1)/Integer(3))
0.3333333333333334?
>>> S = PolynomialRing(Q, names=('x',)); (x,) = S._first_ngens(1)
>>> C(x)
Traceback (most recent call last):
...
TypeError: cannot convert nonconstant polynomial

This illustrates precision:

sage: CIF = ComplexIntervalField(10); CIF(1/3, 2/3)
0.334? + 0.667?*I
sage: CIF
Complex Interval Field with 10 bits of precision
sage: CIF = ComplexIntervalField(100); CIF
Complex Interval Field with 100 bits of precision
sage: z = CIF(1/3, 2/3); z
0.333333333333333333333333333334? + 0.666666666666666666666666666667?*I
>>> from sage.all import *
>>> CIF = ComplexIntervalField(Integer(10)); CIF(Integer(1)/Integer(3), Integer(2)/Integer(3))
0.334? + 0.667?*I
>>> CIF
Complex Interval Field with 10 bits of precision
>>> CIF = ComplexIntervalField(Integer(100)); CIF
Complex Interval Field with 100 bits of precision
>>> z = CIF(Integer(1)/Integer(3), Integer(2)/Integer(3)); z
0.333333333333333333333333333334? + 0.666666666666666666666666666667?*I

We can load and save complex numbers and the complex interval field:

sage: saved_z = loads(z.dumps())
sage: saved_z.endpoints() == z.endpoints()
True
sage: loads(CIF.dumps()) == CIF
True
sage: k = ComplexIntervalField(100)
sage: loads(dumps(k)) == k
True
>>> from sage.all import *
>>> saved_z = loads(z.dumps())
>>> saved_z.endpoints() == z.endpoints()
True
>>> loads(CIF.dumps()) == CIF
True
>>> k = ComplexIntervalField(Integer(100))
>>> loads(dumps(k)) == k
True

This illustrates basic properties of a complex (interval) field:

sage: CIF = ComplexIntervalField(200)
sage: CIF.is_field()
True
sage: CIF.characteristic()
0
sage: CIF.precision()
200
sage: CIF.variable_name()
'I'
sage: CIF == ComplexIntervalField(200)
True
sage: CIF == ComplexIntervalField(53)
False
sage: CIF == 1.1
False
sage: CIF = ComplexIntervalField(53)

sage: CIF.category()
Category of infinite fields
sage: TestSuite(CIF).run(skip='_test_gcd_vs_xgcd')
>>> from sage.all import *
>>> CIF = ComplexIntervalField(Integer(200))
>>> CIF.is_field()
True
>>> CIF.characteristic()
0
>>> CIF.precision()
200
>>> CIF.variable_name()
'I'
>>> CIF == ComplexIntervalField(Integer(200))
True
>>> CIF == ComplexIntervalField(Integer(53))
False
>>> CIF == RealNumber('1.1')
False
>>> CIF = ComplexIntervalField(Integer(53))

>>> CIF.category()
Category of infinite fields
>>> TestSuite(CIF).run(skip='_test_gcd_vs_xgcd')

See also

Element[source]

alias of ComplexIntervalFieldElement

characteristic()[source]

Return the characteristic of the complex (interval) field, which is 0.

EXAMPLES:

sage: CIF.characteristic()
0
>>> from sage.all import *
>>> CIF.characteristic()
0
construction()[source]

Return the functorial construction of this complex interval field, namely as the algebraic closure of the real interval field with the same precision.

EXAMPLES:

sage: c, S = CIF.construction(); c, S
(AlgebraicClosureFunctor,
 Real Interval Field with 53 bits of precision)
sage: CIF == c(S)
True
>>> from sage.all import *
>>> c, S = CIF.construction(); c, S
(AlgebraicClosureFunctor,
 Real Interval Field with 53 bits of precision)
>>> CIF == c(S)
True
gen(n=0)[source]

Return the generator of the complex (interval) field.

EXAMPLES:

sage: CIF.0
1*I
sage: CIF.gen(0)
1*I
>>> from sage.all import *
>>> CIF.gen(0)
1*I
>>> CIF.gen(Integer(0))
1*I
is_exact()[source]

The complex interval field is not exact.

EXAMPLES:

sage: CIF.is_exact()
False
>>> from sage.all import *
>>> CIF.is_exact()
False
is_field(proof=True)[source]

Return True, since the complex numbers are a field.

EXAMPLES:

sage: CIF.is_field()
True
>>> from sage.all import *
>>> CIF.is_field()
True
middle_field()[source]

Return the corresponding ComplexField with the same precision as self.

EXAMPLES:

sage: CIF.middle_field()
Complex Field with 53 bits of precision
sage: ComplexIntervalField(200).middle_field()
Complex Field with 200 bits of precision
>>> from sage.all import *
>>> CIF.middle_field()
Complex Field with 53 bits of precision
>>> ComplexIntervalField(Integer(200)).middle_field()
Complex Field with 200 bits of precision
ngens()[source]

The number of generators of this complex (interval) field as an \(\RR\)-algebra.

There is one generator, namely sqrt(-1).

EXAMPLES:

sage: CIF.ngens()
1
>>> from sage.all import *
>>> CIF.ngens()
1
pi()[source]

Return \(\pi\) as an element in the complex (interval) field.

EXAMPLES:

sage: ComplexIntervalField(100).pi()
3.14159265358979323846264338328?
>>> from sage.all import *
>>> ComplexIntervalField(Integer(100)).pi()
3.14159265358979323846264338328?
prec()[source]

Return the precision of self (in bits).

EXAMPLES:

sage: CIF.prec()
53
sage: ComplexIntervalField(200).prec()
200
>>> from sage.all import *
>>> CIF.prec()
53
>>> ComplexIntervalField(Integer(200)).prec()
200
precision()[source]

Return the precision of self (in bits).

EXAMPLES:

sage: CIF.prec()
53
sage: ComplexIntervalField(200).prec()
200
>>> from sage.all import *
>>> CIF.prec()
53
>>> ComplexIntervalField(Integer(200)).prec()
200
random_element(*args, **kwds)[source]

Create a random element of self.

This simply chooses the real and imaginary part randomly, passing arguments and keywords to the underlying real interval field.

EXAMPLES:

sage: CIF.random_element().parent() is CIF
True
sage: re, im = CIF.random_element(10, 20)
sage: 10 <= re <= 20
True
sage: 10 <= im <= 20
True
>>> from sage.all import *
>>> CIF.random_element().parent() is CIF
True
>>> re, im = CIF.random_element(Integer(10), Integer(20))
>>> Integer(10) <= re <= Integer(20)
True
>>> Integer(10) <= im <= Integer(20)
True

Passes extra positional or keyword arguments through:

sage: re, im = CIF.random_element(max=0, min=-5)
sage: -5 <= re <= 0
True
sage: -5 <= im <= 0
True
>>> from sage.all import *
>>> re, im = CIF.random_element(max=Integer(0), min=-Integer(5))
>>> -Integer(5) <= re <= Integer(0)
True
>>> -Integer(5) <= im <= Integer(0)
True
real_field()[source]

Return the underlying RealIntervalField.

EXAMPLES:

sage: R = CIF.real_field(); R
Real Interval Field with 53 bits of precision
sage: ComplexIntervalField(200).real_field()
Real Interval Field with 200 bits of precision
sage: CIF.real_field() is R
True
>>> from sage.all import *
>>> R = CIF.real_field(); R
Real Interval Field with 53 bits of precision
>>> ComplexIntervalField(Integer(200)).real_field()
Real Interval Field with 200 bits of precision
>>> CIF.real_field() is R
True
scientific_notation(status=None)[source]

Set or return the scientific notation printing flag.

If this flag is True then complex numbers with this space as parent print using scientific notation.

EXAMPLES:

sage: CIF((0.025, 2))
0.025000000000000002? + 2*I
sage: CIF.scientific_notation(True)
sage: CIF((0.025, 2))
2.5000000000000002?e-2 + 2*I
sage: CIF.scientific_notation(False)
sage: CIF((0.025, 2))
0.025000000000000002? + 2*I
>>> from sage.all import *
>>> CIF((RealNumber('0.025'), Integer(2)))
0.025000000000000002? + 2*I
>>> CIF.scientific_notation(True)
>>> CIF((RealNumber('0.025'), Integer(2)))
2.5000000000000002?e-2 + 2*I
>>> CIF.scientific_notation(False)
>>> CIF((RealNumber('0.025'), Integer(2)))
0.025000000000000002? + 2*I
to_prec(prec)[source]

Return a complex interval field with the given precision.

EXAMPLES:

sage: CIF.to_prec(150)
Complex Interval Field with 150 bits of precision
sage: CIF.to_prec(15)
Complex Interval Field with 15 bits of precision
sage: CIF.to_prec(53) is CIF
True
>>> from sage.all import *
>>> CIF.to_prec(Integer(150))
Complex Interval Field with 150 bits of precision
>>> CIF.to_prec(Integer(15))
Complex Interval Field with 15 bits of precision
>>> CIF.to_prec(Integer(53)) is CIF
True
zeta(n=2)[source]

Return a primitive \(n\)-th root of unity.

Todo

Implement ComplexIntervalFieldElement multiplicative order and set this output to have multiplicative order n.

INPUT:

  • n – integer (default: 2)

OUTPUT: a complex \(n\)-th root of unity

EXAMPLES:

sage: CIF.zeta(2)
-1
sage: CIF.zeta(5)
0.309016994374948? + 0.9510565162951536?*I
>>> from sage.all import *
>>> CIF.zeta(Integer(2))
-1
>>> CIF.zeta(Integer(5))
0.309016994374948? + 0.9510565162951536?*I