12.11 Complex Numbers

Module: sage.rings.complex_number

Author: William Stein (2006-01-26): complete rewrite

Module-level Functions

is_ComplexNumber( x)

Class: ComplexNumber

class ComplexNumber
A complex number.

sage: C = ComplexField()
sage: I = C.0
sage: b = 1.5 + 2.5*I
sage: loads(b.dumps()) == b
True
ComplexNumber( self, parent, real, [imag=None])

Functions: acos,$  $ acosh,$  $ agm,$  $ arg,$  $ argument,$  $ asin,$  $ asinh,$  $ atan,$  $ atanh,$  $ conjugate,$  $ cos,$  $ cosh,$  $ cotan,$  $ dilog,$  $ exp,$  $ gamma,$  $ gamma_inc,$  $ imag,$  $ log,$  $ multiplicative_order,$  $ norm,$  $ order,$  $ prec,$  $ real,$  $ sin,$  $ sinh,$  $ sqrt,$  $ square_root,$  $ str,$  $ tan,$  $ tanh,$  $ zeta

acos( self)

sage: (1+I).acos()
0.90455689430238140 - 1.0612750619050357*I

acosh( self)

sage: (1+I).acosh()
1.0612750619050357 + 0.90455689430238140*I

agm( self, right)

sage: (1+I).agm(2-I)
1.6278054848727066 + 0.13682754839736855*I

arg( self)

Same as argument.

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

argument( self)

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

sage: i = CC.0
sage: (i^2).argument()
3.1415926535897931
sage: (1+i).argument()
0.78539816339744828
sage: i.argument()
1.5707963267948966
sage: (-i).argument()
-1.5707963267948966
sage: (RR('-0.001') - i).argument()
-1.5717963264615635

asin( self)

sage: (1+I).asin()
0.66623943249251527 + 1.0612750619050357*I

asinh( self)

sage: (1+I).asinh()
1.0612750619050357 + 0.66623943249251527*I

atan( self)

sage: (1+I).atan()
1.0172219678978514 + 0.40235947810852507*I

atanh( self)

sage: (1+I).atanh()
0.40235947810852507 + 1.0172219678978514*I

conjugate( self)

Return the complex conjugate of this complex number.

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

cos( self)

sage: (1+I).cos()
0.83373002513114902 - 0.98889770576286506*I

cosh( self)

sage: (1+I).cosh()
0.83373002513114902 + 0.98889770576286506*I

cotan( self)

sage: (1+I).cotan()
0.21762156185440268 - 0.86801414289592493*I
sage: i = ComplexField(200).0
sage: (1+i).cotan()
0.21762156185440268136513424360523807352075436916785404091068128 -
0.86801414289592494863584920891627388827343874994609327121115055*I   #
32-bit
0.21762156185440268136513424360523807352075436916785404091068128 -
0.86801414289592494863584920891627388827343874994609327121115055*I   #
64-bit
sage: i = ComplexField(220).0
sage: (1+i).cotan()
0.21762156185440268136513424360523807352075436916785404091068124239250 -
0.86801414289592494863584920891627388827343874994609327121115071646235*I   
# 32-bit
0.21762156185440268136513424360523807352075436916785404091068124239250 -
0.86801414289592494863584920891627388827343874994609327121115071646235*I  
# 64-bit

exp( self)

Compute exp(z).

sage: i = ComplexField(300).0
sage: z = 1 + i
sage: z.exp()
1.4686939399158851571389675973266042613269567366290087227976756763109369658
595121387227244973 +
2.2873552871788423912081719067005018089555862566683556809386581141036471601
893454092673448521*I   # 32-bit
1.4686939399158851571389675973266042613269567366290087227976756763109369658
595121387227244973 +
2.2873552871788423912081719067005018089555862566683556809386581141036471601
893454092673448521*I   # 64-bit

gamma( self)

Return the Gamma function evaluated at this complex number.

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

gamma_inc( self, t)

Return the incomplete Gamma function evaluated at this complex number.

sage: C, i = ComplexField(30).objgen()
sage: (1+i).gamma_inc(2 + 3*i)
0.0020969148645 - 0.059981913655*I
sage: (1+i).gamma_inc(5)
-0.0013781309353 + 0.0065198200246*I
sage: C(2).gamma_inc(1 + i)
0.70709209610 - 0.42035364080*I
sage: gamma_inc(2, 1 + i)    
0.70709209610 - 0.42035364080*I
sage: gamma_inc(2, 5)
0.040427681994512805

imag( self)

Return imaginary part of self.

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

log( self)

Complex logarithm of z with branch chosen as follows: Write z = rho*exp(i*theta) with -pi <= theta < pi. Then log(z) = log(rho) + i*theta.

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

multiplicative_order( self)

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

sage: C, i = ComplexField().objgen()
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))/2; w
0.50000000000000000 + 0.86602540378443860*I
sage: abs(w)
0.99999999999999989
sage: w.multiplicative_order()
Traceback (most recent call last):
...
NotImplementedError: order of 0.50000000000000000 + 0.86602540378443860*I
not known

prec( self)

Return square root, which is a complex number.

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

real( self)

Return real part of self.

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

sin( self)

sage: (1+I).sin()
1.2984575814159773 + 0.63496391478473613*I

sinh( self)

sage: (1+I).sinh()
0.63496391478473613 + 1.2984575814159773*I

sqrt( self)

sage: C, i = ComplexField(30).objgen()
sage: i.sqrt()
0.70710678119 + 0.70710678119*I
sage: (1+i).sqrt()
1.0986841135 + 0.45508986060*I
sage: (C(-1)).sqrt()
1.0000000000*I
sage: i = ComplexField(200).0
sage: i.sqrt()
0.70710678118654752440084436210484903928483593768847403658833981 +
0.70710678118654752440084436210484903928483593768847403658833981*I   #
32-bit
0.70710678118654752440084436210484903928483593768847403658833981 +
0.70710678118654752440084436210484903928483593768847403658833981*I   #
64-bit

square_root( self)

Return square root, which is a complex number.

sage: i = ComplexField(100).0
sage: (-i).sqrt()
0.70710678118654752440084436210459 - 0.70710678118654752440084436210459*I

tan( self)

sage: (1+I).tan()
0.27175258531951174 + 1.0839233273386946*I

tanh( self)

sage: (1+I).tanh()
1.0839233273386946 + 0.27175258531951174*I

zeta( self)

Return the Riemann zeta function evaluated at this complex number.

sage: i = ComplexField(30).gen()
sage: z = 1 + i
sage: z.zeta()
0.58215805981 - 0.92684856430*I
sage: zeta(z)
0.58215805981 - 0.92684856430*I

Special Functions: __abs__,$  $ __cmp__,$  $ __complex__,$  $ __float__,$  $ __int__,$  $ __invert__,$  $ __long__,$  $ __neg__,$  $ __pos__,$  $ __pow__,$  $ __rdiv__,$  $ _add_,$  $ _div_,$  $ _mul_,$  $ _pari_,$  $ _pari_init_,$  $ _repr_,$  $ _sub_

__invert__( self)

Return the multiplicative inverse.

sage: a = ~(5+I)
sage: a * (5+I)
1.0000000000000002 + 0.000000000000000027755575615628914*I

__pow__( self, right)

sage: C, i = ComplexField(20).objgen()
sage: a = i^2; a
-1.0000000
sage: a.parent()
Complex Field with 20 bits of precision
sage: a = (1+i)^i; a
0.42882919 + 0.15487170*I
sage: (1+i)^(1+i)
0.27395725 + 0.58370113*I
sage: a.parent()
Complex Field with 20 bits of precision
sage: i^i
0.20787954
sage: (2+i)^(0.5)
1.4553471 + 0.34356070*I

_pari_init_( self)

This is only for the gp interpreter; can lose precision.

See About this document... for information on suggesting changes.