Field of Arbitrary Precision Complex Intervals

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): trac ticket #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)

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?
class sage.rings.complex_interval_field.ComplexIntervalField_class(prec=53)

Bases: sage.rings.ring.Field

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

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

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

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

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")
Element

alias of sage.rings.complex_interval.ComplexIntervalFieldElement

characteristic()

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

EXAMPLES:

sage: CIF.characteristic()
0
construction()

Returns 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
gen(n=0)

Return the generator of the complex (interval) field.

EXAMPLES:

sage: CIF.0
1*I
sage: CIF.gen(0)
1*I
is_exact()

The complex interval field is not exact.

EXAMPLES:

sage: CIF.is_exact()
False
is_field(proof=True)

Return True, since the complex numbers are a field.

EXAMPLES:

sage: CIF.is_field()
True
middle_field()

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
ngens()

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
pi()

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

EXAMPLES:

sage: ComplexIntervalField(100).pi()
3.14159265358979323846264338328?
prec()

Returns the precision of self (in bits).

EXAMPLES:

sage: CIF.prec()
53
sage: ComplexIntervalField(200).prec()
200
precision()

Returns the precision of self (in bits).

EXAMPLES:

sage: CIF.prec()
53
sage: ComplexIntervalField(200).prec()
200
random_element(*args, **kwds)

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()
0.15363619378561300? - 0.50298737524751780?*I
sage: CIF.random_element(10, 20)
18.047949821611205? + 10.255727028308920?*I

Passes extra positional or keyword arguments through:

sage: CIF.random_element(max=0, min=-5)
-0.079017286535590259? - 2.8712089896087117?*I
real_field()

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
scientific_notation(status=None)

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
to_prec(prec)

Returns 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
zeta(n=2)

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

Todo

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

INPUT:

  • n – an 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
sage.rings.complex_interval_field.is_ComplexIntervalField(x)

Check if x is a ComplexIntervalField.

EXAMPLES:

sage: from sage.rings.complex_interval_field import is_ComplexIntervalField as is_CIF
sage: is_CIF(CIF)
True
sage: is_CIF(CC)
False