Arbitrary Precision Complex Numbers

AUTHORS:

  • William Stein (2006-01-26): complete rewrite
  • Joel B. Mohler (2006-12-16): naive rewrite into pyrex
  • William Stein(2007-01): rewrite of Mohler’s rewrite
class sage.rings.complex_number.CCtoCDF
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_call_()

EXAMPLES:

sage: from sage.rings.complex_number import CCtoCDF
sage: f = CCtoCDF(CC, CDF)
sage: f(CC.0)
1.0*I
sage: f(exp(pi*CC.0/4))
0.707106781187 + 0.707106781187*I
class sage.rings.complex_number.ComplexNumber

A floating point approximation to a complex number using any specified precision. Answers derived from calculations with such approximations may differ from what they would be if those calculations were performed with true complex numbers. This is due to the rounding errors inherent to finite precision calculations.

EXAMPLES:

sage: I = CC.0
sage: b = 1.5 + 2.5*I
sage: loads(b.dumps()) == b
True
__abs__()

Method for computing the absolute value or modulus of self

|a + bi| = sqrt(a^2 + b^2)

EXAMPLES: Note that the absolute value of a complex number with imaginary component equal to zero is the absolute value of the real component.

sage: a = ComplexNumber(2,1)
sage: abs(a)
2.23606797749979
sage: a.__abs__()
2.23606797749979
sage: float(sqrt(2^2 + 1^1))
2.2360679774997898
sage: b = ComplexNumber(42,0)
sage: abs(b)
42.0000000000000
sage: b.__abs__()
42.0000000000000
sage: b
42.0000000000000
__array_interface__
__complex__()

Method for converting self to type complex. Called by the complex function.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: complex(a)
(2+1j)
sage: type(complex(a))
<type 'complex'>
sage: a.__complex__()
(2+1j)
__eq__()
x.__eq__(y) <==> x==y
__float__()

Method for converting self to type float. Called by the float function. Note that calling this method returns an error since, in general, complex numbers cannot be coerced into floats.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: float(a)
...
TypeError: can't convert complex to float; use abs(z)
sage: a.__float__()
...
TypeError: can't convert complex to float; use abs(z)
__ge__()
x.__ge__(y) <==> x>=y
__getitem__()

Returns either the real or imaginary component of self depending on the choice of i: real (i=0), imaginary (i=1)

INPUTS:

  • i - 0 or 1
    • 0 - will return the real component of self
    • 1 - will return the imaginary component of self

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: a.__getitem__(0)
2.00000000000000
sage: a.__getitem__(1)
1.00000000000000
sage: b = CC(42,0)
sage: b
42.0000000000000
sage: b.__getitem__(1)
0.000000000000000
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__int__()

Method for converting self to type int. Called by the int function. Note that calling this method returns an error since, in general, complex numbers cannot be coerced into integers.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: int(a)
...
TypeError: can't convert complex to int; use int(abs(z))
sage: a.__int__()
...
TypeError: can't convert complex to int; use int(abs(z))
__invert__()

Return the multiplicative inverse.

EXAMPLES:

sage: I = CC.0
sage: a = ~(5+I)
sage: a * (5+I)
1.00000000000000
__le__()
x.__le__(y) <==> x<=y
__long__()

Method for converting self to type long. Called by the long function. Note that calling this method returns an error since, in general, complex numbers cannot be coerced into integers.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: long(a)
...
TypeError: can't convert complex to long; use long(abs(z))
sage: a.__long__()
...
TypeError: can't convert complex to long; use long(abs(z))
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
__neg__()

Method for computing the negative of self.

-(a + bi) = -a - bi

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: -a
-2.00000000000000 - 1.00000000000000*I
sage: a.__neg__()
-2.00000000000000 - 1.00000000000000*I
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pos__()

Method for computing the “positive” of self.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: +a
2.00000000000000 + 1.00000000000000*I
sage: a.__pos__()
2.00000000000000 + 1.00000000000000*I
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__rdiv__()

Returns the quotient of left with self, that is:

left/self

as a complex number.

INPUTS:

  • left - a complex number to divide by self

EXAMPLES:

sage: a = ComplexNumber(2,0)
sage: a.__rdiv__(CC(1))
0.500000000000000
sage: CC(1)/a
0.500000000000000
__reduce__()

Pickling support

EXAMPLES:

sage: a = CC(1 + I)
sage: loads(dumps(a)) == a
True
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
_add_()
_div_()
_interface_init_()

Returns self formatted as a string, suitable as input to another computer algebra system. (This is the default function used for exporting to other computer algebra systems.)

EXAMPLES:

sage: s1 = CC(exp(I)); s1
0.540302305868140 + 0.841470984807897*I
sage: s1._interface_init_()
'0.54030230586813977 + 0.84147098480789650*I'
sage: s1 == CC(gp(s1))
True
_latex_()

Method for converting self to a string with latex formatting. Called by the global function latex.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: a
2.00000000000000 + 1.00000000000000*I
sage: latex(a)
2.00000000000000 + 1.00000000000000i
sage: a._latex_()
'2.00000000000000 + 1.00000000000000i'
sage: b = ComplexNumber(7,4,min_prec=16)
sage: b
7.000 + 4.000*I
sage: latex(b)
7.000 + 4.000i
sage: b._latex_()
'7.000 + 4.000i'
_magma_init_()

EXAMPLES:

sage: magma(CC([1, 2])) # optional - magma
1.00000000000000 + 2.00000000000000*$.1
sage: v = magma(CC([1, 2])).sage(); v # optional - magma
1.00000000000000 + 2.00000000000000*I
sage: v.parent() # optional - magma
Complex Field with 53 bits of precision
_mpmath_()

Returns an mpmath version of this ComplexNumber.

Note

Currently, the rounding mode is ignored.

EXAMPLES:

sage: CC(1,2)._mpmath_()
mpc(real='1.0', imag='2.0')
_mul_()
_pari_()

Coerces self into a Pari complex object.

EXAMPLES: Coerce the object using the pari function:

sage: a = ComplexNumber(2,1)
sage: pari(a)
2.00000000000000 + 1.00000000000000*I
sage: type(pari(a))
<type 'sage.libs.pari.gen.gen'>
sage: a._pari_()
2.00000000000000 + 1.00000000000000*I
sage: type(a._pari_())
<type 'sage.libs.pari.gen.gen'>
_repr_()

Returns self formatted as a string.

EXAMPLES:

sage: a = ComplexNumber(2,1); a
2.00000000000000 + 1.00000000000000*I
sage: a._repr_()
'2.00000000000000 + 1.00000000000000*I'
_sage_input_()

Produce an expression which will reproduce this value when evaluated.

EXAMPLES:
sage: for prec in (2, 53, 200): ... fld = ComplexField(prec) ... var = polygen(fld) ... ins = [-20, 0, 1, -2^4000, 2^-4000] + [fld._real_field().random_element() for _ in range(3)] ... for v1 in ins: ... for v2 in ins: ... v = fld(v1, v2) ... _ = sage_input(fld(v), verify=True) ... _ = sage_input(fld(v) * var, verify=True) sage: x = polygen(CC) sage: for v1 in [-2, 0, 2]: ... for v2 in [-2, -1, 0, 1, 2]: ... print str(sage_input(x + CC(v1, v2))).splitlines()[1] x + CC(-2 - 2*I) x + CC(-2 - I) x - 2 x + CC(-2 + I) x + CC(-2 + 2*I) x - CC(2*I) x - CC(I) x x + CC(I) x + CC(2*I) x + CC(2 - 2*I) x + CC(2 - I) x + 2 x + CC(2 + I) x + CC(2 + 2*I) sage: from sage.misc.sage_input import SageInputBuilder sage: sib = SageInputBuilder() sage: sib_np = SageInputBuilder(preparse=False) sage: CC(-infinity)._sage_input_(sib, True) {unop:- {call: {atomic:RR}({atomic:Infinity})}} sage: CC(0, infinity)._sage_input_(sib, True) {call: {atomic:CC}({call: {atomic:RR}({atomic:0})}, {call: {atomic:RR}({atomic:Infinity})})} sage: CC(NaN, 5)._sage_input_(sib, True) {call: {atomic:CC}({call: {atomic:RR}({atomic:NaN})}, {call: {atomic:RR}({atomic:5})})} sage: CC(5, NaN)._sage_input_(sib, True) {call: {atomic:CC}({call: {atomic:RR}({atomic:5})}, {call: {atomic:RR}({atomic:NaN})})} sage: CC(12345)._sage_input_(sib, True) {atomic:12345} sage: CC(-12345)._sage_input_(sib, False) {unop:- {call: {atomic:CC}({atomic:12345})}} sage: CC(0, 12345)._sage_input_(sib, True) {call: {atomic:CC}({binop:* {atomic:12345} {atomic:I}})} sage: CC(0, -12345)._sage_input_(sib, False) {unop:- {call: {atomic:CC}({binop:* {atomic:12345} {atomic:I}})}} sage: CC(1.579)._sage_input_(sib, True) {atomic:1.579} sage: CC(1.579)._sage_input_(sib_np, True) {atomic:1.579} sage: ComplexField(150).zeta(37)._sage_input_(sib, True) {call: {call: {atomic:ComplexField}({atomic:150})}({binop:+ {atomic:0.98561591034770846226477029397621845736859851519} {binop:* {atomic:0.16900082032184907409303555538443060626072476297} {atomic:I}}})} sage: ComplexField(150).zeta(37)._sage_input_(sib_np, True) {call: {call: {atomic:ComplexField}({atomic:150})}({binop:+ {call: {call: {atomic:RealField}({atomic:150})}({atomic:‘0.98561591034770846226477029397621845736859851519’})} {binop:* {call: {call: {atomic:RealField}({atomic:150})}({atomic:‘0.16900082032184907409303555538443060626072476297’})} {atomic:I}}})}
_set_multiplicative_order()

Function for setting the ComplexNumber class attribute multiplicative_order of self.

INPUTS: n - an integer which will define the multiplicative order of self

EXAMPLES: Note that it is not advisable to explicitly call _set_multiplicative_order for explicitly declared complex numbers.

sage: a = ComplexNumber(2,1)
sage: a.multiplicative_order()
+Infinity
sage: a._set_multiplicative_order(5)
sage: a.multiplicative_order()
5
sage: a^5
-38.0000000000000 + 41.0000000000000*I
_sub_()
additive_order()

EXAMPLES:

sage: CC(0).additive_order()
1
sage: CC.gen().additive_order()
+Infinity
agm()

EXAMPLES:

sage: (1+CC(I)).agm(2-I)
1.62780548487271 + 0.136827548397369*I
algdep()

Returns a polynomial of degree at most n which is approximately satisfied by this complex number. Note that the returned polynomial need not be irreducible, and indeed usually won’t be if z is a good approximation to an algebraic number of degree less than n.

ALGORITHM: Uses the PARI C-library algdep command.

INPUT: Type algdep? at the top level prompt. All additional parameters are passed onto the top-level algdep command.

EXAMPLE:

sage: C = ComplexField()
sage: z = (1/2)*(1 + sqrt(3.0) *C.0); z
0.500000000000000 + 0.866025403784439*I
sage: p = z.algdep(5); p
x^5 + x^2
sage: p.factor()
(x + 1) * x^2 * (x^2 - x + 1)
sage: z^2 - z + 1
1.11022302462516e-16
algebraic_dependancy()

Returns a polynomial of degree at most n which is approximately satisfied by this complex number. Note that the returned polynomial need not be irreducible, and indeed usually won’t be if z is a good approximation to an algebraic number of degree less than n.

ALGORITHM: Uses the PARI C-library algdep command.

INPUT: Type algdep? at the top level prompt. All additional parameters are passed onto the top-level algdep command.

EXAMPLE:

sage: C = ComplexField()
sage: z = (1/2)*(1 + sqrt(3.0) *C.0); z
0.500000000000000 + 0.866025403784439*I
sage: p = z.algebraic_dependancy(5); p
x^5 + x^2
sage: p.factor()
(x + 1) * x^2 * (x^2 - x + 1)
sage: z^2 - z + 1
1.11022302462516e-16
arccos()

EXAMPLES:

sage: (1+CC(I)).arccos()
0.904556894302381 - 1.06127506190504*I
arccosh()

EXAMPLES:

sage: (1+CC(I)).arccosh()
1.06127506190504 + 0.904556894302381*I
arccoth()

EXAMPLES:

sage: ComplexField(100)(1,1).arccoth()
0.40235947810852509365018983331 - 0.55357435889704525150853273009*I
arccsch()

EXAMPLES:

sage: ComplexField(100)(1,1).arccsch()
0.53063753095251782601650945811 - 0.45227844715119068206365839783*I
arcsech()

EXAMPLES:

sage: ComplexField(100)(1,1).arcsech()
-0.53063753095251782601650945811 + 1.1185178796437059371676632938*I
arcsin()

EXAMPLES:

sage: (1+CC(I)).arcsin()
0.666239432492515 + 1.06127506190504*I
arcsinh()

EXAMPLES:

sage: (1+CC(I)).arcsinh()
1.06127506190504 + 0.666239432492515*I
arctan()

EXAMPLES:

sage: (1+CC(I)).arctan()
1.01722196789785 + 0.402359478108525*I
arctanh()

EXAMPLES:

sage: (1+CC(I)).arctanh()
0.402359478108525 + 1.01722196789785*I
arg()

Same as argument.

EXAMPLES:

sage: i = CC.0
sage: (i^2).arg()
3.14159265358979
argument()

The argument (angle) of the complex number, normalized so that -\pi < \theta \leq \pi.

EXAMPLES:

sage: i = CC.0
sage: (i^2).argument()
3.14159265358979
sage: (1+i).argument()
0.785398163397448
sage: i.argument()
1.57079632679490
sage: (-i).argument()
-1.57079632679490
sage: (RR('-0.001') - i).argument()
-1.57179632646156
conjugate()

Return the complex conjugate of this complex number.

EXAMPLES:

sage: i = CC.0
sage: (1+i).conjugate()
1.00000000000000 - 1.00000000000000*I
cos()

EXAMPLES:

sage: (1+CC(I)).cos()
0.833730025131149 - 0.988897705762865*I
cosh()

EXAMPLES:

sage: (1+CC(I)).cosh()
0.833730025131149 + 0.988897705762865*I
cotan()

EXAMPLES:

sage: (1+CC(I)).cotan()
0.217621561854403 - 0.868014142895925*I
sage: i = ComplexField(200).0
sage: (1+i).cotan()
0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I    
sage: i = ComplexField(220).0
sage: (1+i).cotan()
0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I
coth()

EXAMPLES:

sage: ComplexField(100)(1,1).coth()
0.86801414289592494863584920892 - 0.21762156185440268136513424361*I
csc()

EXAMPLES:

sage: ComplexField(100)(1,1).csc()
0.62151801717042842123490780586 - 0.30393100162842645033448560451*I
csch()

EXAMPLES:

sage: ComplexField(100)(1,1).csch()
0.30393100162842645033448560451 - 0.62151801717042842123490780586*I
dilog()

Returns the complex dilogarithm of self. The complex dilogarithm, or Spence’s function, is defined by

Li_2(z) = - \int_0^z \frac{\log|1-\zeta|}{\zeta} d(\zeta)

= \sum_{k=1}^\infty \frac{z^k}{k}

Note that the series definition can only be used for |z| < 1

EXAMPLES:

sage: a = ComplexNumber(1,0)
sage: a.dilog()
1.64493406684823
sage: float(pi^2/6)
1.6449340668482262
sage: b = ComplexNumber(0,1)
sage: b.dilog()
-0.205616758356028 + 0.915965594177219*I
sage: c = ComplexNumber(0,0)
sage: c.dilog()
0
eta()

Return the value of the Dedekind \eta function on self, intelligently computed using \mathbb{SL}(2,\ZZ) transformations.

INPUT:

  • self - element of the upper half plane (if not, raises a ValueError).
  • omit_frac - (bool, default: False), if True, omit the e^{\pi i z / 12} factor.

OUTPUT: a complex number

The \eta function is

\eta(z) = e^{\pi i z / 12} \prod_{n=1}^{\infty}(1-e^{2\pi inz})

ALGORITHM: Uses the PARI C library.

EXAMPLES:

First we compute \eta(1+i):

sage: i = CC.0
sage: z = 1+i; z.eta()
0.742048775836565 + 0.198831370229911*I

We compute eta to low precision directly from the definition.

sage: z = 1 + i; z.eta()
0.742048775836565 + 0.198831370229911*I
sage: pi = CC(pi)        # otherwise we will get a symbolic result.
sage: exp(pi * i * z / 12) * prod([1-exp(2*pi*i*n*z) for n in range(1,10)])
0.742048775836565 + 0.198831370229911*I

The optional argument allows us to omit the fractional part:

sage: z = 1 + i
sage: z.eta(omit_frac=True)
0.998129069925959 - 8.12769318...e-22*I
sage: prod([1-exp(2*pi*i*n*z) for n in range(1,10)])
0.998129069925958 + 4.59099857829247e-19*I

We illustrate what happens when z is not in the upper half plane.

sage: z = CC(1)
sage: z.eta()
...
ValueError: value must be in the upper half plane

You can also use functional notation.

sage: eta(1+CC(I))
0.742048775836565 + 0.198831370229911*I
exp()

Compute exp(z).

EXAMPLES:

sage: i = ComplexField(300).0
sage: z = 1 + i
sage: z.exp()
1.46869393991588515713896759732660426132695673662900872279767567631093696585951213872272450 + 2.28735528717884239120817190670050180895558625666835568093865811410364716018934540926734485*I
gamma()

Return the Gamma function evaluated at this complex number.

EXAMPLES:

sage: i = ComplexField(30).0
sage: (1+i).gamma()
0.49801567 - 0.15494983*I

TESTS:

sage: CC(0).gamma()
Infinity
sage: CC(-1).gamma()
Infinity
gamma_inc()

Return the incomplete Gamma function evaluated at this complex number.

EXAMPLES:

sage: C, i = ComplexField(30).objgen()
sage: (1+i).gamma_inc(2 + 3*i)
0.0020969149 - 0.059981914*I
sage: (1+i).gamma_inc(5)
-0.0013781309 + 0.0065198200*I
sage: C(2).gamma_inc(1 + i)
0.70709210 - 0.42035364*I
sage: gamma_inc(2, 1 + i)    
0.70709210 - 0.42035364*I
sage: gamma_inc(2, 5)
0.0404276819945128
imag()

Return imaginary part of self.

EXAMPLES:

sage: i = ComplexField(100).0
sage: z = 2 + 3*i
sage: x = z.imag(); x
3.0000000000000000000000000000
sage: x.parent()
Real Field with 100 bits of precision
sage: z.imag_part()
3.0000000000000000000000000000
imag_part()

Return imaginary part of self.

EXAMPLES:

sage: i = ComplexField(100).0
sage: z = 2 + 3*i
sage: x = z.imag(); x
3.0000000000000000000000000000
sage: x.parent()
Real Field with 100 bits of precision
sage: z.imag_part()
3.0000000000000000000000000000
is_imaginary()

Return True if self is imaginary, i.e. has real part zero.

EXAMPLES:

sage: CC(1.23*i).is_imaginary()
True
sage: CC(1+i).is_imaginary()
False
is_real()

Return True if self is real, i.e. has imaginary part zero.

EXAMPLES:

sage: CC(1.23).is_real()
True
sage: CC(1+i).is_real()
False
is_square()

This function always returns true as \CC is algebraically closed.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: a.is_square()
True

\CC is algebraically closed, hence every element is a square:

sage: b = ComplexNumber(5)
sage: b.is_square()
True
log()

Complex logarithm of z with branch chosen as follows: Write z = \rho e^{i \theta} with `-\pi <= \theta < pi. Then \mathrm{log}(z) = \mathrm{log}(\rho) + i \theta.

Warning

Currently the real log is computed using floats, so there is potential precision loss.

EXAMPLES:

sage: a = ComplexNumber(2,1)
sage: a.log()
0.804718956217050 + 0.463647609000806*I
sage: log(a.abs())
0.804718956217050
sage: a.argument()
0.463647609000806
sage: b = ComplexNumber(float(exp(42)),0)
sage: b.log()
41.99999999999971
multiplicative_order()

Return the multiplicative order of this complex number, if known, or raise a NotImplementedError.

EXAMPLES:

sage: C.<i> = ComplexField()
sage: i.multiplicative_order()
4
sage: C(1).multiplicative_order()
1
sage: C(-1).multiplicative_order()
2
sage: C(i^2).multiplicative_order()
2
sage: C(-i).multiplicative_order()
4
sage: C(2).multiplicative_order()
+Infinity
sage: w = (1+sqrt(-3.0))/2; w
0.500000000000000 + 0.866025403784439*I
sage: abs(w)
1.00000000000000
sage: w.multiplicative_order()
...
NotImplementedError: order of element not known
norm()

Returns the norm of this complex number. If c = a + bi is a complex number, then the norm of c is defined as

\text{norm}(c) = \text{norm}(a + bi) = a^2 + b^2

The norm of a complex number is different from its absolute value. The absolute value of a complex number is defined to be the square root of its norm. A typical use of the complex norm is in the integral domain \ZZ[i] of Gaussian integers, where the norm of each Gaussian integer c = a + bi is defined as its complex norm.

EXAMPLES:

This indeed acts as the square function when the imaginary component of self is equal to zero:

sage: a = ComplexNumber(2,1)
sage: a.norm()
5.00000000000000
sage: b = ComplexNumber(4.2,0)
sage: b.norm()
17.6400000000000
sage: b^2
17.6400000000000
nth_root()

The n-th root function.

INPUT:

  • all - bool (default: False); if True, return a list of all n-th roots.

EXAMPLES:

sage: a = CC(27)
sage: a.nth_root(3)
3.00000000000000
sage: a.nth_root(3, all=True)
[3.00000000000000, -1.50000000000000 + 2.59807621135332*I, -1.50000000000000 - 2.59807621135332*I]
sage: a = ComplexField(20)(2,1)
sage: [r^7 for r in a.nth_root(7, all=True)]
[2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0001*I, 2.0000 + 1.0001*I]
prec()

Return precision of this complex number.

EXAMPLES:

sage: i = ComplexField(2000).0
sage: i.prec()
2000
real()

Return real part of self.

EXAMPLES:

sage: i = ComplexField(100).0
sage: z = 2 + 3*i
sage: x = z.real(); x
2.0000000000000000000000000000
sage: x.parent()
Real Field with 100 bits of precision
sage: z.real_part()
2.0000000000000000000000000000
real_part()

Return real part of self.

EXAMPLES:

sage: i = ComplexField(100).0
sage: z = 2 + 3*i
sage: x = z.real(); x
2.0000000000000000000000000000
sage: x.parent()
Real Field with 100 bits of precision
sage: z.real_part()
2.0000000000000000000000000000
sec()

EXAMPLES:

sage: ComplexField(100)(1,1).sec()
0.49833703055518678521380589177 + 0.59108384172104504805039169297*I
sech()

EXAMPLES:

sage: ComplexField(100)(1,1).sech()
0.49833703055518678521380589177 - 0.59108384172104504805039169297*I
sin()

EXAMPLES:

sage: (1+CC(I)).sin()
1.29845758141598 + 0.634963914784736*I
sinh()

EXAMPLES:

sage: (1+CC(I)).sinh()
0.634963914784736 + 1.29845758141598*I
sqrt()

The square root function, taking the branch cut to be the negative real axis.

INPUT:

  • all - bool (default: False); if True, return a list of all square roots.

EXAMPLES:

sage: C.<i> = ComplexField(30)
sage: i.sqrt()
0.70710678 + 0.70710678*I
sage: (1+i).sqrt()
1.0986841 + 0.45508986*I
sage: (C(-1)).sqrt()
1.0000000*I
sage: (1 + 1e-100*i).sqrt()^2
1.0000000 + 1.0000000e-100*I
sage: i = ComplexField(200).0
sage: i.sqrt()
0.70710678118654752440084436210484903928483593768847403658834 + 0.70710678118654752440084436210484903928483593768847403658834*I
str()

Return a string representation of this number.

INPUTS:

  • base - The base to use for printing (default 10)
  • truncate - (default: True) Whether to print fewer digits than are available, to mask errors in the last bits.

EXAMPLES:

sage: a = CC(pi + I*e)
sage: a.str()
'3.14159265358979 + 2.71828182845905*I'
sage: a.str(truncate=False)
'3.1415926535897931 + 2.7182818284590451*I'
sage: a.str(base=2)
'11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I'
sage: CC(0.5 + 0.625*I).str(base=2)
'0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I'
sage: a.str(base=16)
'3.243f6a8885a30 + 2.b7e151628aed2*I'
sage: a.str(base=36)
'3.53i5ab8p5fc + 2.puw5nggjf8f*I'
tan()

EXAMPLES:

sage: (1+CC(I)).tan()
0.271752585319512 + 1.08392332733869*I
tanh()

EXAMPLES:

sage: (1+CC(I)).tanh()
1.08392332733869 + 0.271752585319512*I
zeta()

Return the Riemann zeta function evaluated at this complex number.

EXAMPLES:

sage: i = ComplexField(30).gen()
sage: z = 1 + i
sage: z.zeta()
0.58215806 - 0.92684856*I
sage: zeta(z)
0.58215806 - 0.92684856*I
class sage.rings.complex_number.RRtoCC
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_call_()

EXAMPLES:

sage: from sage.rings.complex_number import RRtoCC
sage: f = RRtoCC(RealField(100), ComplexField(10))
sage: f(1/3)
0.33
sage.rings.complex_number.create_ComplexNumber()

Return the complex number defined by the strings s_real and s_imag as an element of ComplexField(prec=n), where n potentially has slightly more (controlled by pad) bits than given by s.

INPUT:

  • s_real - a string that defines a real number (or something whose string representation defines a number)
  • s_imag - a string that defines a real number (or something whose string representation defines a number)
  • pad - an integer >= 0.
  • min_prec - number will have at least this many bits of precision, no matter what.

EXAMPLES:

sage: ComplexNumber('2.3')
2.30000000000000
sage: ComplexNumber('2.3','1.1')
2.30000000000000 + 1.10000000000000*I
sage: ComplexNumber(10)
10.0000000000000
sage: ComplexNumber(10,10)
10.0000000000000 + 10.0000000000000*I
sage: ComplexNumber(1.000000000000000000000000000,2)
1.00000000000000000000000000 + 2.00000000000000000000000000*I
sage: ComplexNumber(1,2.000000000000000000000)
1.00000000000000000000 + 2.00000000000000000000*I
sage: sage.rings.complex_number.create_ComplexNumber(s_real=2,s_imag=1)
2.00000000000000 + 1.00000000000000*I
sage.rings.complex_number.is_ComplexNumber()

Returns True if x is a complex number. In particular, if x is of the ComplexNumber type.

EXAMPLES:

sage: from sage.rings.complex_number import is_ComplexNumber
sage: a = ComplexNumber(1,2); a
1.00000000000000 + 2.00000000000000*I
sage: is_ComplexNumber(a)
True
sage: b = ComplexNumber(1); b
1.00000000000000
sage: is_ComplexNumber(b)
True

Note that the global element I is of type SymbolicConstant. However, elements of the class ComplexField_class are of type ComplexNumber:

sage: c = 1 + 2*I
sage: is_ComplexNumber(c)
False
sage: d = CC(1 + 2*I)
sage: is_ComplexNumber(d)
True
sage.rings.complex_number.make_ComplexNumber0()
sage.rings.complex_number.set_global_complex_round_mode()

Previous topic

Field of Arbitrary Precision Complex Numbers

Next topic

Field of Arbitrary Precision Real Intervals

This Page