Module: sage.rings.complex_field
Field of Arbitrary Precision Complex Numbers
Author: William Stein (2006-01-26): complete rewrite
Module-level Functions
| [prec=53], [names=None]) |
Return the complex field with real and imaginary parts having prec *bits* of precision.
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
| x) |
| ) |
Class: ComplexField_class
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(RQDF.pi()) 3.14159265358979 sage: C(RQDF.log2(), RQDF.e()) 0.693147180559945 + 2.71828182845905*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()) Traceback (most recent call last): ... TypeError: unable to coerce to a ComplexNumber
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
| self, [prec=53]) |
Functions: characteristic,
construction,
gen,
is_exact,
is_field,
is_finite,
ngens,
pi,
prec,
precision,
random_element,
scientific_notation,
zeta
| self) |
Returns the functorial construction of self, namely, algebraic closure of the real field with the same precision.
sage: c, S = CC.construction(); S Real Field with 53 bits of precision sage: CC == c(S) True
| self) |
Return True, since the complex numbers are a field.
sage: CC.is_field() True
| self) |
Return False, since the complex numbers are infinite.
sage: CC.is_finite() False
| self, [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]).
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]
| self, [n=2]) |
Return a primitive
-th root of unity.
Input:
Special Functions: __call__,
__cmp__,
__init__,
__reduce__,
_coerce_impl,
_latex_,
_real_field,
_repr_
| self, x, [im=None]) |
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()
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for '+': 'Complex Field with 53
bits of precision' and 'Number Field in I with defining polynomial x^2 + 1'
| self, x) |
Return the canonical coerce of x into this complex field, if it is defined, otherwise raise a TypeError.
The rings that canonicaly coerce to the MPFS 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
sage: ComplexField(200)(1) + RealField(90)(1) 2.0000000000000000000000000
See About this document... for information on suggesting changes.