Field of Arbitrary Precision Complex Numbers

AUTHORS:

  • William Stein (2006-01-26): complete rewrite
sage.rings.complex_field.ComplexField(prec=53, names=None)

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

EXAMPLES:

sage: ComplexField()
Complex Field with 53 bits of precision
sage: ComplexField(100)
Complex Field with 100 bits of precision
sage: ComplexField(100).base_ring()
Real Field with 100 bits of precision
sage: i = ComplexField(200).gen()
sage: i^2
-1.0000000000000000000000000000000000000000000000000000000000
class sage.rings.complex_field.ComplexField_class(prec=53)

An approximation to the field of complex numbers using floating point numbers with any specified precision. Answers derived from calculations in this approximation may differ from what they would be if those calculations were performed in the true field of complex numbers. This is due to the rounding errors inherent to finite precision calculations.

EXAMPLES:

sage: C = ComplexField(); C
Complex Field with 53 bits of precision
sage: Q = RationalField()
sage: C(1/3)
0.333333333333333
sage: C(1/3, 2)
0.333333333333333 + 2.00000000000000*I
sage: C(RR.pi())
3.14159265358979
sage: C(RR.log2(), RR.pi())
0.693147180559945 + 3.14159265358979*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.333333333333333
sage: S = PolynomialRing(Q, 'x')
sage: C(S.gen())
...
TypeError: unable to coerce to a ComplexNumber: <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_rational_dense'>

This illustrates precision.

sage: CC = ComplexField(10); CC(1/3, 2/3)
0.33 + 0.67*I
sage: CC
Complex Field with 10 bits of precision
sage: CC = ComplexField(100); CC
Complex Field with 100 bits of precision
sage: z = CC(1/3, 2/3); z
0.33333333333333333333333333333 + 0.66666666666666666666666666667*I

We can load and save complex numbers and the complex field.

sage: loads(z.dumps()) == z
True
sage: loads(CC.dumps()) == CC
True
sage: k = ComplexField(100)
sage: loads(dumps(k)) == k
True

This illustrates basic properties of a complex field.

sage: CC = ComplexField(200)
sage: CC.is_field()
True
sage: CC.characteristic()
0
sage: CC.precision()
200
sage: CC.variable_name()
'I'
sage: CC == ComplexField(200)
True
sage: CC == ComplexField(53)
False
sage: CC == 1.1
False
__call__(x=None, im=None)

EXAMPLES:

sage: CC(2)
2.00000000000000
sage: CC(CC.0)
1.00000000000000*I
sage: CC('1+I')
1.00000000000000 + 1.00000000000000*I
sage: CC(2,3)
2.00000000000000 + 3.00000000000000*I
sage: CC(QQ[I].gen())
1.00000000000000*I
sage: CC.gen() + QQ[I].gen()
...
TypeError: unsupported operand parent(s) for '+': 'Complex Field with 53 bits of precision' and 'Number Field in I with defining polynomial x^2 + 1'

In the absence of arguments we return zero:

sage: a = CC(); a
0
sage: a.parent()
Complex Field with 53 bits of precision
__cmp__(other)
__init__(prec=53)
__reduce__()
_coerce_map_from_(S)

The rings that canonically coerce to the MPFR complex field are:

  • This MPFR complex field, or any other of higher precision
  • Anything that canonically coerces to the mpfr real field with this prec

EXAMPLES:

sage: ComplexField(200)(1) + RealField(90)(1)
2.0000000000000000000000000
sage: parent(ComplexField(200)(1) + RealField(90)(1))
Complex Field with 90 bits of precision
sage: CC.0 + RLF(1/3)
0.333333333333333 + 1.00000000000000*I
sage: ComplexField(20).has_coerce_map_from(CDF)
True
sage: ComplexField(200).has_coerce_map_from(CDF)
False
_element_constructor_(x)

EXAMPLES:

sage: CC((1,2))
1.00000000000000 + 2.00000000000000*I
_latex_()
_magma_init_(magma)

Return a string representation of self in the Magma language.

EXAMPLES:

sage: magma(ComplexField(200)) # optional - magma
Complex field of precision 60
sage: 10^60 < 2^200 < 10^61
True
sage: s = magma(ComplexField(200)).sage(); s # optional - magma
Complex Field with 200 bits of precision
sage: 2^199 < 10^60 < 2^200
True
sage: s is ComplexField(200) # optional - magma
True
_real_field()
_repr_()
_sage_input_(sib, coerce)

Produce an expression which will reproduce this value when evaluated.

EXAMPLES:
sage: sage_input(CC, verify=True) # Verified CC sage: sage_input(ComplexField(25), verify=True) # Verified ComplexField(25) sage: k = (CC, ComplexField(75)) sage: sage_input(k, verify=True) # Verified (CC, ComplexField(75)) sage: sage_input((k, k), verify=True) # Verified CC75 = ComplexField(75) ((CC, CC75), (CC, CC75)) sage: from sage.misc.sage_input import SageInputBuilder sage: ComplexField(99)._sage_input_(SageInputBuilder(), False) {call: {atomic:ComplexField}({atomic:99})}
characteristic()
construction()

Returns the functorial construction of self, namely, algebraic closure of the real field with the same precision.

EXAMPLES:

sage: c, S = CC.construction(); S
Real Field with 53 bits of precision
sage: CC == c(S)
True
gen(n=0)
is_exact()
is_field()

Return True, since the complex numbers are a field.

EXAMPLES:

sage: CC.is_field()
True
is_finite()

Return False, since the complex numbers are infinite.

EXAMPLES:

sage: CC.is_finite()
False
ngens()
pi()
prec()
precision()
random_element(component_max=1)

Returns a uniformly distributed random number inside a square centered on the origin (by default, the square [-1,1]x[-1,1]).

EXAMPLES:

sage: [CC.random_element() for _ in range(5)]
[-0.306077326077253 - 0.0759291930543202*I, -0.838081254900233 - 0.207006276657392*I, -0.757827933063776 - 0.530834220505783*I, 0.918013195263849 - 0.805114150788948*I, 0.116924427170636 + 0.203592757069680*I]
sage: CC6 = ComplexField(6)
sage: [CC6.random_element(2^-20) for _ in range(5)]
[-5.7e-7 + 5.4e-7*I, 8.6e-7 + 9.2e-7*I, -5.7e-7 + 6.9e-7*I, -1.2e-7 - 6.9e-7*I, 2.7e-7 + 8.3e-7*I]
sage: [CC6.random_element(pi^20) for _ in range(5)]
[-5.0e9*I, 2.8e9 - 5.1e9*I, 2.7e8 + 6.3e9*I, 2.7e8 - 6.4e9*I, 6.7e8 + 1.7e9*I]
scientific_notation(status=None)
to_prec(prec)

Returns the complex field to the specified precision.

EXAMPLES:

sage: CC.to_prec(10)
Complex Field with 10 bits of precision
sage: CC.to_prec(100)
Complex Field with 100 bits of precision
zeta(n=2)

Return a primitive n-th root of unity.

INPUT:

  • n - an integer (default: 2)

OUTPUT: a complex n-th root of unity.

sage.rings.complex_field.is_ComplexField(x)
sage.rings.complex_field.late_import()

Previous topic

Field of Arbitrary Precision Real Numbers

Next topic

Arbitrary Precision Complex Numbers

This Page