AUTHORS:
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
Bases: sage.rings.ring.Field
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
Return the algebraic closure of self (which is itself).
EXAMPLES:
sage: CC
Complex Field with 53 bits of precision
sage: CC.algebraic_closure()
Complex Field with 53 bits of precision
sage: CC = ComplexField(1000)
sage: CC.algebraic_closure() is CC
True
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
Return True, since the complex numbers are a field.
EXAMPLES:
sage: CC.is_field()
True
Return False, since the complex numbers are infinite.
EXAMPLES:
sage: CC.is_finite()
False
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]
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
Return a primitive -th root of unity.
INPUT:
OUTPUT: a complex n-th root of unity.