Arbitrary precision floating point complex numbers using GNU MPFR#
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
Vincent Delecroix (2010-01): plot function
Niles Johnson (2010-08): Issue #3893:
random_element()
should pass on*args
and**kwds
.Travis Scrimshaw (2012-10-18): Added documentation for full coverage
Vincent Klein (2017-11-14) : add __mpc__() to class ComplexNumber. ComplexNumber constructor support gmpy2.mpc parameter.
- sage.rings.complex_mpfr.ComplexField(prec=53, names=None)[source]#
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
>>> from sage.all import * >>> ComplexField() Complex Field with 53 bits of precision >>> ComplexField(Integer(100)) Complex Field with 100 bits of precision >>> ComplexField(Integer(100)).base_ring() Real Field with 100 bits of precision >>> i = ComplexField(Integer(200)).gen() >>> i**Integer(2) -1.0000000000000000000000000000000000000000000000000000000000
See also
ComplexBallField
(complex numbers with rigorous error bounds)
- class sage.rings.complex_mpfr.ComplexField_class(prec=53)[source]#
Bases:
ComplexField
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
>>> from sage.all import * >>> C = ComplexField(); C Complex Field with 53 bits of precision >>> Q = RationalField() >>> C(Integer(1)/Integer(3)) 0.333333333333333 >>> C(Integer(1)/Integer(3), Integer(2)) 0.333333333333333 + 2.00000000000000*I >>> C(RR.pi()) 3.14159265358979 >>> 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()) Traceback (most recent call last): ... TypeError: cannot convert nonconstant polynomial
>>> from sage.all import * >>> Q = RationalField() >>> C(Integer(1)/Integer(3)) 0.333333333333333 >>> S = PolynomialRing(Q, 'x') >>> C(S.gen()) Traceback (most recent call last): ... TypeError: cannot convert nonconstant polynomial
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
>>> from sage.all import * >>> CC = ComplexField(Integer(10)); CC(Integer(1)/Integer(3), Integer(2)/Integer(3)) 0.33 + 0.67*I >>> CC Complex Field with 10 bits of precision >>> CC = ComplexField(Integer(100)); CC Complex Field with 100 bits of precision >>> z = CC(Integer(1)/Integer(3), Integer(2)/Integer(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
>>> from sage.all import * >>> loads(z.dumps()) == z True >>> loads(CC.dumps()) == CC True >>> k = ComplexField(Integer(100)) >>> 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
>>> from sage.all import * >>> CC = ComplexField(Integer(200)) >>> CC.is_field() True >>> CC.characteristic() 0 >>> CC.precision() 200 >>> CC.variable_name() 'I' >>> CC == ComplexField(Integer(200)) True >>> CC == ComplexField(Integer(53)) False >>> CC == RealNumber('1.1') False
See also
ComplexField()
(constructor)ComplexBallField
(complex numbers with rigorous error bounds)
- algebraic_closure()[source]#
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
>>> from sage.all import * >>> CC Complex Field with 53 bits of precision >>> CC.algebraic_closure() Complex Field with 53 bits of precision >>> CC = ComplexField(Integer(1000)) >>> CC.algebraic_closure() is CC True
- characteristic()[source]#
Return the characteristic of \(\CC\), which is 0.
EXAMPLES:
sage: ComplexField().characteristic() 0
>>> from sage.all import * >>> ComplexField().characteristic() 0
- construction()[source]#
Return the functorial construction of
self
, namely the 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
>>> from sage.all import * >>> c, S = CC.construction(); S Real Field with 53 bits of precision >>> CC == c(S) True
- gen(n=0)[source]#
Return the generator of the complex field.
EXAMPLES:
sage: ComplexField().gen(0) 1.00000000000000*I
>>> from sage.all import * >>> ComplexField().gen(Integer(0)) 1.00000000000000*I
- is_exact()[source]#
Return whether or not this field is exact, which is always
False
.EXAMPLES:
sage: ComplexField().is_exact() False
>>> from sage.all import * >>> ComplexField().is_exact() False
- ngens()[source]#
The number of generators of this complex field as an \(\RR\)-algebra.
There is one generator, namely
sqrt(-1)
.EXAMPLES:
sage: ComplexField().ngens() 1
>>> from sage.all import * >>> ComplexField().ngens() 1
- pi()[source]#
Return \(\pi\) as a complex number.
EXAMPLES:
sage: ComplexField().pi() 3.14159265358979 sage: ComplexField(100).pi() 3.1415926535897932384626433833
>>> from sage.all import * >>> ComplexField().pi() 3.14159265358979 >>> ComplexField(Integer(100)).pi() 3.1415926535897932384626433833
- prec()[source]#
Return the precision of this complex field.
EXAMPLES:
sage: ComplexField().prec() 53 sage: ComplexField(15).prec() 15
>>> from sage.all import * >>> ComplexField().prec() 53 >>> ComplexField(Integer(15)).prec() 15
- precision()[source]#
Return the precision of this complex field.
EXAMPLES:
sage: ComplexField().prec() 53 sage: ComplexField(15).prec() 15
>>> from sage.all import * >>> ComplexField().prec() 53 >>> ComplexField(Integer(15)).prec() 15
- random_element(component_max=1, *args, **kwds)[source]#
Return a uniformly distributed random number inside a square centered on the origin (by default, the square \([-1,1] \times [-1,1]\)).
Passes additional arguments and keywords to underlying real field.
EXAMPLES:
sage: CC.random_element().parent() is CC True sage: re, im = CC.random_element() sage: -1 <= re <= 1, -1 <= im <= 1 (True, True) sage: CC6 = ComplexField(6) sage: CC6.random_element().parent() is CC6 True sage: re, im = CC6.random_element(2^-20) sage: -2^-20 <= re <= 2^-20, -2^-20 <= im <= 2^-20 (True, True) sage: re, im = CC6.random_element(pi^20) # needs sage.symbolic sage: bool(-pi^20 <= re <= pi^20), bool(-pi^20 <= im <= pi^20) # needs sage.symbolic (True, True)
>>> from sage.all import * >>> CC.random_element().parent() is CC True >>> re, im = CC.random_element() >>> -Integer(1) <= re <= Integer(1), -Integer(1) <= im <= Integer(1) (True, True) >>> CC6 = ComplexField(Integer(6)) >>> CC6.random_element().parent() is CC6 True >>> re, im = CC6.random_element(Integer(2)**-Integer(20)) >>> -Integer(2)**-Integer(20) <= re <= Integer(2)**-Integer(20), -Integer(2)**-Integer(20) <= im <= Integer(2)**-Integer(20) (True, True) >>> re, im = CC6.random_element(pi**Integer(20)) # needs sage.symbolic >>> bool(-pi**Integer(20) <= re <= pi**Integer(20)), bool(-pi**Integer(20) <= im <= pi**Integer(20)) # needs sage.symbolic (True, True)
Passes extra positional or keyword arguments through:
sage: CC.random_element(distribution='1/n').parent() is CC True
>>> from sage.all import * >>> CC.random_element(distribution='1/n').parent() is CC True
- scientific_notation(status=None)[source]#
Set or return the scientific notation printing flag.
If this flag is
True
then complex numbers with this space as parent print using scientific notation.EXAMPLES:
sage: C = ComplexField() sage: C((0.025, 2)) 0.0250000000000000 + 2.00000000000000*I sage: C.scientific_notation(True) sage: C((0.025, 2)) 2.50000000000000e-2 + 2.00000000000000e0*I sage: C.scientific_notation(False) sage: C((0.025, 2)) 0.0250000000000000 + 2.00000000000000*I
>>> from sage.all import * >>> C = ComplexField() >>> C((RealNumber('0.025'), Integer(2))) 0.0250000000000000 + 2.00000000000000*I >>> C.scientific_notation(True) >>> C((RealNumber('0.025'), Integer(2))) 2.50000000000000e-2 + 2.00000000000000e0*I >>> C.scientific_notation(False) >>> C((RealNumber('0.025'), Integer(2))) 0.0250000000000000 + 2.00000000000000*I
- to_prec(prec)[source]#
Return 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
>>> from sage.all import * >>> CC.to_prec(Integer(10)) Complex Field with 10 bits of precision >>> CC.to_prec(Integer(100)) Complex Field with 100 bits of precision
- zeta(n=2)[source]#
Return a primitive \(n\)-th root of unity.
INPUT:
n
– an integer (default: 2)
OUTPUT: a complex \(n\)-th root of unity.
EXAMPLES:
sage: C = ComplexField() sage: C.zeta(2) -1.00000000000000 sage: C.zeta(5) 0.309016994374947 + 0.951056516295154*I
>>> from sage.all import * >>> C = ComplexField() >>> C.zeta(Integer(2)) -1.00000000000000 >>> C.zeta(Integer(5)) 0.309016994374947 + 0.951056516295154*I
- class sage.rings.complex_mpfr.ComplexNumber[source]#
Bases:
FieldElement
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
>>> from sage.all import * >>> I = CC.gen(0) >>> b = RealNumber('1.5') + RealNumber('2.5')*I >>> loads(b.dumps()) == b True
- additive_order()[source]#
Return the additive order of
self
.EXAMPLES:
sage: CC(0).additive_order() 1 sage: CC.gen().additive_order() +Infinity
>>> from sage.all import * >>> CC(Integer(0)).additive_order() 1 >>> CC.gen().additive_order() +Infinity
- agm(right, algorithm='optimal')[source]#
Return the Arithmetic-Geometric Mean (AGM) of
self
andright
.INPUT:
right
(complex) – another complex numberalgorithm
(string, default"optimal"
) – the algorithm to use (see below).
OUTPUT:
(complex) A value of the AGM of
self
andright
. Note that this is a multi-valued function, and the algorithm used affects the value returned, as follows:"pari"
: Call the pari:agm function from the PARI library."optimal"
: Use the AGM sequence such that at each stage \((a,b)\) is replaced by \((a_1,b_1)=((a+b)/2,\pm\sqrt{ab})\) where the sign is chosen so that \(|a_1-b_1|\le|a_1+b_1|\), or equivalently \(\Re(b_1/a_1)\ge 0\). The resulting limit is maximal among all possible values."principal"
: Use the AGM sequence such that at each stage \((a,b)\) is replaced by \((a_1,b_1)=((a+b)/2,\pm\sqrt{ab})\) where the sign is chosen so that \(\Re(b_1)\ge 0\) (the so-called principal branch of the square root).
The values \(AGM(a,0)\), \(AGM(0,a)\), and \(AGM(a,-a)\) are all taken to be 0.
EXAMPLES:
sage: a = CC(1,1) sage: b = CC(2,-1) sage: a.agm(b) 1.62780548487271 + 0.136827548397369*I sage: a.agm(b, algorithm="optimal") 1.62780548487271 + 0.136827548397369*I sage: a.agm(b, algorithm="principal") 1.62780548487271 + 0.136827548397369*I sage: a.agm(b, algorithm="pari") # needs sage.libs.pari 1.62780548487271 + 0.136827548397369*I
>>> from sage.all import * >>> a = CC(Integer(1),Integer(1)) >>> b = CC(Integer(2),-Integer(1)) >>> a.agm(b) 1.62780548487271 + 0.136827548397369*I >>> a.agm(b, algorithm="optimal") 1.62780548487271 + 0.136827548397369*I >>> a.agm(b, algorithm="principal") 1.62780548487271 + 0.136827548397369*I >>> a.agm(b, algorithm="pari") # needs sage.libs.pari 1.62780548487271 + 0.136827548397369*I
An example to show that the returned value depends on the algorithm parameter:
sage: a = CC(-0.95,-0.65) sage: b = CC(0.683,0.747) sage: a.agm(b, algorithm="optimal") -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="principal") 0.338175462986180 - 0.0135326969565405*I sage: a.agm(b, algorithm="pari") # needs sage.libs.pari -0.371591652351761 + 0.319894660206830*I sage: a.agm(b, algorithm="optimal").abs() 0.490319232466314 sage: a.agm(b, algorithm="principal").abs() 0.338446122230459 sage: a.agm(b, algorithm="pari").abs() # needs sage.libs.pari 0.490319232466314
>>> from sage.all import * >>> a = CC(-RealNumber('0.95'),-RealNumber('0.65')) >>> b = CC(RealNumber('0.683'),RealNumber('0.747')) >>> a.agm(b, algorithm="optimal") -0.371591652351761 + 0.319894660206830*I >>> a.agm(b, algorithm="principal") 0.338175462986180 - 0.0135326969565405*I >>> a.agm(b, algorithm="pari") # needs sage.libs.pari -0.371591652351761 + 0.319894660206830*I >>> a.agm(b, algorithm="optimal").abs() 0.490319232466314 >>> a.agm(b, algorithm="principal").abs() 0.338446122230459 >>> a.agm(b, algorithm="pari").abs() # needs sage.libs.pari 0.490319232466314
- algdep(n, **kwds)[source]#
Return an irreducible polynomial of degree at most \(n\) which is approximately satisfied by this complex number.
ALGORITHM: Uses the PARI C-library pari:algdep command.
INPUT: Type
algdep?
at the top level prompt. All additional parameters are passed onto the top-levelalgdep()
command.EXAMPLES:
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^2 - x + 1 sage: p(z) 1.11022302462516e-16
>>> from sage.all import * >>> C = ComplexField() >>> z = (Integer(1)/Integer(2))*(Integer(1) + sqrt(RealNumber('3.0')) *C.gen(0)); z 0.500000000000000 + 0.866025403784439*I >>> p = z.algdep(Integer(5)); p x^2 - x + 1 >>> p(z) 1.11022302462516e-16
- algebraic_dependency(n, **kwds)[source]#
Return an irreducible polynomial of degree at most \(n\) which is approximately satisfied by this complex number.
ALGORITHM: Uses the PARI C-library pari:algdep command.
INPUT: Type
algdep?
at the top level prompt. All additional parameters are passed onto the top-levelalgdep()
command.EXAMPLES:
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^2 - x + 1 sage: p(z) 1.11022302462516e-16
>>> from sage.all import * >>> C = ComplexField() >>> z = (Integer(1)/Integer(2))*(Integer(1) + sqrt(RealNumber('3.0')) *C.gen(0)); z 0.500000000000000 + 0.866025403784439*I >>> p = z.algdep(Integer(5)); p x^2 - x + 1 >>> p(z) 1.11022302462516e-16
- arccos()[source]#
Return the arccosine of
self
.EXAMPLES:
sage: (1+CC(I)).arccos() # needs sage.libs.pari 0.904556894302381 - 1.06127506190504*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arccos() # needs sage.libs.pari 0.904556894302381 - 1.06127506190504*I
- arccosh()[source]#
Return the hyperbolic arccosine of
self
.EXAMPLES:
sage: (1+CC(I)).arccosh() # needs sage.libs.pari 1.06127506190504 + 0.904556894302381*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arccosh() # needs sage.libs.pari 1.06127506190504 + 0.904556894302381*I
- arccoth()[source]#
Return the hyperbolic arccotangent of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).arccoth() # needs sage.libs.pari 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).arccoth() # needs sage.libs.pari 0.40235947810852509365018983331 - 0.55357435889704525150853273009*I
- arccsch()[source]#
Return the hyperbolic arccosecant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).arccsch() # needs sage.libs.pari 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).arccsch() # needs sage.libs.pari 0.53063753095251782601650945811 - 0.45227844715119068206365839783*I
- arcsech()[source]#
Return the hyperbolic arcsecant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).arcsech() # needs sage.libs.pari 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).arcsech() # needs sage.libs.pari 0.53063753095251782601650945811 - 1.1185178796437059371676632938*I
- arcsin()[source]#
Return the arcsine of
self
.EXAMPLES:
sage: (1+CC(I)).arcsin() # needs sage.libs.pari 0.666239432492515 + 1.06127506190504*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arcsin() # needs sage.libs.pari 0.666239432492515 + 1.06127506190504*I
- arcsinh()[source]#
Return the hyperbolic arcsine of
self
.EXAMPLES:
sage: (1+CC(I)).arcsinh() # needs sage.libs.pari 1.06127506190504 + 0.666239432492515*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arcsinh() # needs sage.libs.pari 1.06127506190504 + 0.666239432492515*I
- arctan()[source]#
Return the arctangent of
self
.EXAMPLES:
sage: (1+CC(I)).arctan() # needs sage.libs.pari 1.01722196789785 + 0.402359478108525*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arctan() # needs sage.libs.pari 1.01722196789785 + 0.402359478108525*I
- arctanh()[source]#
Return the hyperbolic arctangent of
self
.EXAMPLES:
sage: (1+CC(I)).arctanh() # needs sage.libs.pari 0.402359478108525 + 1.01722196789785*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).arctanh() # needs sage.libs.pari 0.402359478108525 + 1.01722196789785*I
- arg()[source]#
See
argument()
.EXAMPLES:
sage: i = CC.0 sage: (i^2).arg() 3.14159265358979
>>> from sage.all import * >>> i = CC.gen(0) >>> (i**Integer(2)).arg() 3.14159265358979
- argument()[source]#
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
>>> from sage.all import * >>> i = CC.gen(0) >>> (i**Integer(2)).argument() 3.14159265358979 >>> (Integer(1)+i).argument() 0.785398163397448 >>> i.argument() 1.57079632679490 >>> (-i).argument() -1.57079632679490 >>> (RR('-0.001') - i).argument() -1.57179632646156
- conjugate()[source]#
Return the complex conjugate of this complex number.
EXAMPLES:
sage: i = CC.0 sage: (1+i).conjugate() 1.00000000000000 - 1.00000000000000*I
>>> from sage.all import * >>> i = CC.gen(0) >>> (Integer(1)+i).conjugate() 1.00000000000000 - 1.00000000000000*I
- cos()[source]#
Return the cosine of
self
.EXAMPLES:
sage: (1+CC(I)).cos() 0.833730025131149 - 0.988897705762865*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).cos() 0.833730025131149 - 0.988897705762865*I
- cosh()[source]#
Return the hyperbolic cosine of
self
.EXAMPLES:
sage: (1+CC(I)).cosh() 0.833730025131149 + 0.988897705762865*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).cosh() 0.833730025131149 + 0.988897705762865*I
- cot()[source]#
Return the cotangent of
self
.EXAMPLES:
sage: # needs sage.libs.pari sage: (1+CC(I)).cot() 0.217621561854403 - 0.868014142895925*I sage: i = ComplexField(200).0 sage: (1+i).cot() 0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I sage: i = ComplexField(220).0 sage: (1+i).cot() 0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I
>>> from sage.all import * >>> # needs sage.libs.pari >>> (Integer(1)+CC(I)).cot() 0.217621561854403 - 0.868014142895925*I >>> i = ComplexField(Integer(200)).gen(0) >>> (Integer(1)+i).cot() 0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I >>> i = ComplexField(Integer(220)).gen(0) >>> (Integer(1)+i).cot() 0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I
- coth()[source]#
Return the hyperbolic cotangent of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).coth() # needs sage.libs.pari 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).coth() # needs sage.libs.pari 0.86801414289592494863584920892 - 0.21762156185440268136513424361*I
- csc()[source]#
Return the cosecant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).csc() # needs sage.libs.pari 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).csc() # needs sage.libs.pari 0.62151801717042842123490780586 - 0.30393100162842645033448560451*I
- csch()[source]#
Return the hyperbolic cosecant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).csch() # needs sage.libs.pari 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).csch() # needs sage.libs.pari 0.30393100162842645033448560451 - 0.62151801717042842123490780586*I
- dilog()[source]#
Return 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() # needs sage.libs.pari 1.64493406684823 sage: float(pi^2/6) # needs sage.symbolic 1.6449340668482262
>>> from sage.all import * >>> a = ComplexNumber(Integer(1),Integer(0)) >>> a.dilog() # needs sage.libs.pari 1.64493406684823 >>> float(pi**Integer(2)/Integer(6)) # needs sage.symbolic 1.6449340668482262
sage: b = ComplexNumber(0,1) sage: b.dilog() # needs sage.libs.pari -0.205616758356028 + 0.915965594177219*I
>>> from sage.all import * >>> b = ComplexNumber(Integer(0),Integer(1)) >>> b.dilog() # needs sage.libs.pari -0.205616758356028 + 0.915965594177219*I
sage: c = ComplexNumber(0,0) sage: c.dilog() # needs sage.libs.pari 0.000000000000000
>>> from sage.all import * >>> c = ComplexNumber(Integer(0),Integer(0)) >>> c.dilog() # needs sage.libs.pari 0.000000000000000
- eta(omit_frac=False)[source]#
Return the value of the Dedekind \(\eta\) function on
self
, intelligently computed using \(\mathbb{SL}(2,\ZZ)\) transformations.The \(\eta\) function is
\[\eta(z) = e^{\pi i z / 12} \prod_{n=1}^{\infty}(1-e^{2\pi inz})\]INPUT:
self
– element of the upper half plane (if not, raises aValueError
).omit_frac
– (bool, default:False
), ifTrue
, omit the \(e^{\pi i z / 12}\) factor.
OUTPUT: a complex number
ALGORITHM: Uses the PARI C library.
EXAMPLES:
First we compute \(\eta(1+i)\):
sage: i = CC.0 sage: z = 1 + i; z.eta() # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I
>>> from sage.all import * >>> i = CC.gen(0) >>> z = Integer(1) + i; z.eta() # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I
We compute eta to low precision directly from the definition:
sage: pi = CC(pi) # otherwise we will get a symbolic result. # needs sage.symbolic sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # needs sage.libs.pari sage.symbolic ....: for n in range(1,10)) 0.742048775836565 + 0.198831370229911*I
>>> from sage.all import * >>> pi = CC(pi) # otherwise we will get a symbolic result. # needs sage.symbolic >>> exp(pi * i * z / Integer(12)) * prod(Integer(1) - exp(Integer(2)*pi*i*n*z) # needs sage.libs.pari sage.symbolic ... for n in range(Integer(1),Integer(10))) 0.742048775836565 + 0.198831370229911*I
The optional argument allows us to omit the fractional part:
sage: z.eta(omit_frac=True) # needs sage.libs.pari 0.998129069925959 sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # needs sage.libs.pari sage.symbolic 0.998129069925958 + 4.59099857829247e-19*I
>>> from sage.all import * >>> z.eta(omit_frac=True) # needs sage.libs.pari 0.998129069925959 >>> prod(Integer(1) - exp(Integer(2)*pi*i*n*z) for n in range(Integer(1),Integer(10))) # needs sage.libs.pari sage.symbolic 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() # needs sage.libs.pari Traceback (most recent call last): ... ValueError: value must be in the upper half plane
>>> from sage.all import * >>> z = CC(Integer(1)) >>> z.eta() # needs sage.libs.pari Traceback (most recent call last): ... ValueError: value must be in the upper half plane
You can also use functional notation:
sage: eta(1 + CC(I)) # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I
>>> from sage.all import * >>> eta(Integer(1) + CC(I)) # needs sage.libs.pari 0.742048775836565 + 0.198831370229911*I
- exp()[source]#
Compute \(e^z\) or \(\exp(z)\).
EXAMPLES:
sage: i = ComplexField(300).0 sage: z = 1 + i sage: z.exp() 1.46869393991588515713896759732660426132695673662900872279767567631093696585951213872272450 + 2.28735528717884239120817190670050180895558625666835568093865811410364716018934540926734485*I
>>> from sage.all import * >>> i = ComplexField(Integer(300)).gen(0) >>> z = Integer(1) + i >>> z.exp() 1.46869393991588515713896759732660426132695673662900872279767567631093696585951213872272450 + 2.28735528717884239120817190670050180895558625666835568093865811410364716018934540926734485*I
- gamma()[source]#
Return the Gamma function evaluated at this complex number.
EXAMPLES:
sage: i = ComplexField(30).0 sage: (1 + i).gamma() # needs sage.libs.pari 0.49801567 - 0.15494983*I
>>> from sage.all import * >>> i = ComplexField(Integer(30)).gen(0) >>> (Integer(1) + i).gamma() # needs sage.libs.pari 0.49801567 - 0.15494983*I
- gamma_inc(t)[source]#
Return the incomplete Gamma function evaluated at this complex number.
EXAMPLES:
sage: # needs sage.libs.pari sage: C, i = ComplexField(30).objgen() sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10 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: CC(2).gamma_inc(5) 0.0404276819945128
>>> from sage.all import * >>> # needs sage.libs.pari >>> C, i = ComplexField(Integer(30)).objgen() >>> (Integer(1)+i).gamma_inc(Integer(2) + Integer(3)*i) # abs tol 2e-10 0.0020969149 - 0.059981914*I >>> (Integer(1)+i).gamma_inc(Integer(5)) -0.0013781309 + 0.0065198200*I >>> C(Integer(2)).gamma_inc(Integer(1) + i) 0.70709210 - 0.42035364*I >>> CC(Integer(2)).gamma_inc(Integer(5)) 0.0404276819945128
- imag()[source]#
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
>>> from sage.all import * >>> i = ComplexField(Integer(100)).gen(0) >>> z = Integer(2) + Integer(3)*i >>> x = z.imag(); x 3.0000000000000000000000000000 >>> x.parent() Real Field with 100 bits of precision >>> z.imag_part() 3.0000000000000000000000000000
- imag_part()[source]#
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
>>> from sage.all import * >>> i = ComplexField(Integer(100)).gen(0) >>> z = Integer(2) + Integer(3)*i >>> x = z.imag(); x 3.0000000000000000000000000000 >>> x.parent() Real Field with 100 bits of precision >>> z.imag_part() 3.0000000000000000000000000000
- is_NaN()[source]#
Check if
self
is not-a-number.EXAMPLES:
sage: CC(1, 2).is_NaN() False sage: CC(NaN).is_NaN() True sage: CC(NaN,2).log().is_NaN() True
>>> from sage.all import * >>> CC(Integer(1), Integer(2)).is_NaN() False >>> CC(NaN).is_NaN() True >>> CC(NaN,Integer(2)).log().is_NaN() True
- is_imaginary()[source]#
Return
True
ifself
is imaginary, i.e., has real part zero.EXAMPLES:
sage: CC(1.23*i).is_imaginary() True sage: CC(1+i).is_imaginary() False
>>> from sage.all import * >>> CC(RealNumber('1.23')*i).is_imaginary() True >>> CC(Integer(1)+i).is_imaginary() False
- is_infinity()[source]#
Check if
self
is \(\infty\).EXAMPLES:
sage: CC(1, 2).is_infinity() False sage: CC(0, oo).is_infinity() True
>>> from sage.all import * >>> CC(Integer(1), Integer(2)).is_infinity() False >>> CC(Integer(0), oo).is_infinity() True
- is_integer()[source]#
Return
True
ifself
is an integer.EXAMPLES:
sage: CC(3).is_integer() True sage: CC(1,2).is_integer() False
>>> from sage.all import * >>> CC(Integer(3)).is_integer() True >>> CC(Integer(1),Integer(2)).is_integer() False
- is_negative_infinity()[source]#
Check if
self
is \(-\infty\).EXAMPLES:
sage: CC(1, 2).is_negative_infinity() False sage: CC(-oo, 0).is_negative_infinity() True sage: CC(0, -oo).is_negative_infinity() False
>>> from sage.all import * >>> CC(Integer(1), Integer(2)).is_negative_infinity() False >>> CC(-oo, Integer(0)).is_negative_infinity() True >>> CC(Integer(0), -oo).is_negative_infinity() False
- is_positive_infinity()[source]#
Check if
self
is \(+\infty\).EXAMPLES:
sage: CC(1, 2).is_positive_infinity() False sage: CC(oo, 0).is_positive_infinity() True sage: CC(0, oo).is_positive_infinity() False
>>> from sage.all import * >>> CC(Integer(1), Integer(2)).is_positive_infinity() False >>> CC(oo, Integer(0)).is_positive_infinity() True >>> CC(Integer(0), oo).is_positive_infinity() False
- is_real()[source]#
Return
True
ifself
is real, i.e., has imaginary part zero.EXAMPLES:
sage: CC(1.23).is_real() True sage: CC(1+i).is_real() False
>>> from sage.all import * >>> CC(RealNumber('1.23')).is_real() True >>> CC(Integer(1)+i).is_real() False
- is_square()[source]#
This function always returns true as \(\CC\) is algebraically closed.
EXAMPLES:
sage: a = ComplexNumber(2,1) sage: a.is_square() True
>>> from sage.all import * >>> a = ComplexNumber(Integer(2),Integer(1)) >>> a.is_square() True
\(\CC\) is algebraically closed, hence every element is a square:
sage: b = ComplexNumber(5) sage: b.is_square() True
>>> from sage.all import * >>> b = ComplexNumber(Integer(5)) >>> b.is_square() True
- log(base=None)[source]#
Complex logarithm of \(z\) with branch chosen as follows: Write \(z = \rho e^{i \theta}\) with \(-\pi < \theta \leq \pi\). Then \(\log(z) = \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
>>> from sage.all import * >>> a = ComplexNumber(Integer(2),Integer(1)) >>> a.log() 0.804718956217050 + 0.463647609000806*I >>> log(a.abs()) 0.804718956217050 >>> a.argument() 0.463647609000806
sage: b = ComplexNumber(float(exp(42)),0) sage: b.log() # abs tol 1e-12 41.99999999999971
>>> from sage.all import * >>> b = ComplexNumber(float(exp(Integer(42))),Integer(0)) >>> b.log() # abs tol 1e-12 41.99999999999971
sage: c = ComplexNumber(-1,0) sage: c.log() 3.14159265358979*I
>>> from sage.all import * >>> c = ComplexNumber(-Integer(1),Integer(0)) >>> c.log() 3.14159265358979*I
The option of a base is included for compatibility with other logs:
sage: c = ComplexNumber(-1,0) sage: c.log(2) 4.53236014182719*I
>>> from sage.all import * >>> c = ComplexNumber(-Integer(1),Integer(0)) >>> c.log(Integer(2)) 4.53236014182719*I
If either component (real or imaginary) of the complex number is NaN (not a number), log will return the complex NaN:
sage: c = ComplexNumber(NaN,2) sage: c.log() NaN + NaN*I
>>> from sage.all import * >>> c = ComplexNumber(NaN,Integer(2)) >>> c.log() NaN + NaN*I
- multiplicative_order()[source]#
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() Traceback (most recent call last): ... NotImplementedError: order of element not known
>>> from sage.all import * >>> C = ComplexField(names=('i',)); (i,) = C._first_ngens(1) >>> i.multiplicative_order() 4 >>> C(Integer(1)).multiplicative_order() 1 >>> C(-Integer(1)).multiplicative_order() 2 >>> C(i**Integer(2)).multiplicative_order() 2 >>> C(-i).multiplicative_order() 4 >>> C(Integer(2)).multiplicative_order() +Infinity >>> w = (Integer(1)+sqrt(-RealNumber('3.0')))/Integer(2); w 0.500000000000000 + 0.866025403784439*I >>> abs(w) 1.00000000000000 >>> w.multiplicative_order() Traceback (most recent call last): ... NotImplementedError: order of element not known
- norm()[source]#
Return the norm of this complex number.
If \(c = a + bi\) is a complex number, then the norm of \(c\) is defined as the product of \(c\) and its complex conjugate:
\[\text{norm}(c) = \text{norm}(a + bi) = c \cdot \overline{c} = 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
>>> from sage.all import * >>> a = ComplexNumber(Integer(2),Integer(1)) >>> a.norm() 5.00000000000000 >>> b = ComplexNumber(RealNumber('4.2'),Integer(0)) >>> b.norm() 17.6400000000000 >>> b**Integer(2) 17.6400000000000
- nth_root(n, all=False)[source]#
The \(n\)-th root function.
INPUT:
all
– bool (default:False
); ifTrue
, 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]
>>> from sage.all import * >>> a = CC(Integer(27)) >>> a.nth_root(Integer(3)) 3.00000000000000 >>> a.nth_root(Integer(3), all=True) [3.00000000000000, -1.50000000000000 + 2.59807621135332*I, -1.50000000000000 - 2.59807621135332*I] >>> a = ComplexField(Integer(20))(Integer(2),Integer(1)) >>> [r**Integer(7) for r in a.nth_root(Integer(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]
- plot(**kargs)[source]#
Plots this complex number as a point in the plane
The accepted options are the ones of
point2d()
. Typepoint2d.options
to see all options.Note
Just wraps the sage.plot.point.point2d method
EXAMPLES:
You can either use the indirect:
sage: z = CC(0,1) sage: plot(z) # needs sage.plot Graphics object consisting of 1 graphics primitive
>>> from sage.all import * >>> z = CC(Integer(0),Integer(1)) >>> plot(z) # needs sage.plot Graphics object consisting of 1 graphics primitive
or the more direct:
sage: z = CC(0,1) sage: z.plot() # needs sage.plot Graphics object consisting of 1 graphics primitive
>>> from sage.all import * >>> z = CC(Integer(0),Integer(1)) >>> z.plot() # needs sage.plot Graphics object consisting of 1 graphics primitive
- prec()[source]#
Return precision of this complex number.
EXAMPLES:
sage: i = ComplexField(2000).0 sage: i.prec() 2000
>>> from sage.all import * >>> i = ComplexField(Integer(2000)).gen(0) >>> i.prec() 2000
- real()[source]#
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
>>> from sage.all import * >>> i = ComplexField(Integer(100)).gen(0) >>> z = Integer(2) + Integer(3)*i >>> x = z.real(); x 2.0000000000000000000000000000 >>> x.parent() Real Field with 100 bits of precision >>> z.real_part() 2.0000000000000000000000000000
- real_part()[source]#
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
>>> from sage.all import * >>> i = ComplexField(Integer(100)).gen(0) >>> z = Integer(2) + Integer(3)*i >>> x = z.real(); x 2.0000000000000000000000000000 >>> x.parent() Real Field with 100 bits of precision >>> z.real_part() 2.0000000000000000000000000000
- sec()[source]#
Return the secant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).sec() # needs sage.libs.pari 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).sec() # needs sage.libs.pari 0.49833703055518678521380589177 + 0.59108384172104504805039169297*I
- sech()[source]#
Return the hyperbolic secant of
self
.EXAMPLES:
sage: ComplexField(100)(1,1).sech() # needs sage.libs.pari 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I
>>> from sage.all import * >>> ComplexField(Integer(100))(Integer(1),Integer(1)).sech() # needs sage.libs.pari 0.49833703055518678521380589177 - 0.59108384172104504805039169297*I
- sin()[source]#
Return the sine of
self
.EXAMPLES:
sage: (1+CC(I)).sin() 1.29845758141598 + 0.634963914784736*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).sin() 1.29845758141598 + 0.634963914784736*I
- sinh()[source]#
Return the hyperbolic sine of
self
.EXAMPLES:
sage: (1+CC(I)).sinh() 0.634963914784736 + 1.29845758141598*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).sinh() 0.634963914784736 + 1.29845758141598*I
- sqrt(all=False)[source]#
The square root function, taking the branch cut to be the negative real axis.
INPUT:
all
– bool (default:False
); ifTrue
, 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
>>> from sage.all import * >>> C = ComplexField(Integer(30), names=('i',)); (i,) = C._first_ngens(1) >>> i.sqrt() 0.70710678 + 0.70710678*I >>> (Integer(1)+i).sqrt() 1.0986841 + 0.45508986*I >>> (C(-Integer(1))).sqrt() 1.0000000*I >>> (Integer(1) + RealNumber('1e-100')*i).sqrt()**Integer(2) 1.0000000 + 1.0000000e-100*I >>> i = ComplexField(Integer(200)).gen(0) >>> i.sqrt() 0.70710678118654752440084436210484903928483593768847403658834 + 0.70710678118654752440084436210484903928483593768847403658834*I
- str(base=10, istr='I', **kwds)[source]#
Return a string representation of
self
.INPUT:
base
– (default: 10) base for outputistr
– (default:I
) String representation of the complex unit**kwds
– other arguments to pass to thestr()
method of the real numbers in the real and imaginary parts.
EXAMPLES:
sage: # needs sage.symbolic sage: a = CC(pi + I*e); a 3.14159265358979 + 2.71828182845905*I sage: a.str(truncate=True) '3.14159265358979 + 2.71828182845905*I' sage: a.str() '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' sage: CC(0) 0.000000000000000 sage: CC.0.str(istr='%i') '1.0000000000000000*%i'
>>> from sage.all import * >>> # needs sage.symbolic >>> a = CC(pi + I*e); a 3.14159265358979 + 2.71828182845905*I >>> a.str(truncate=True) '3.14159265358979 + 2.71828182845905*I' >>> a.str() '3.1415926535897931 + 2.7182818284590451*I' >>> a.str(base=Integer(2)) '11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I' >>> CC(RealNumber('0.5') + RealNumber('0.625')*I).str(base=Integer(2)) '0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I' >>> a.str(base=Integer(16)) '3.243f6a8885a30 + 2.b7e151628aed2*I' >>> a.str(base=Integer(36)) '3.53i5ab8p5fc + 2.puw5nggjf8f*I' >>> CC(Integer(0)) 0.000000000000000 >>> CC.gen(0).str(istr='%i') '1.0000000000000000*%i'
- tan()[source]#
Return the tangent of
self
.EXAMPLES:
sage: (1+CC(I)).tan() 0.271752585319512 + 1.08392332733869*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).tan() 0.271752585319512 + 1.08392332733869*I
- tanh()[source]#
Return the hyperbolic tangent of
self
.EXAMPLES:
sage: (1+CC(I)).tanh() 1.08392332733869 + 0.271752585319512*I
>>> from sage.all import * >>> (Integer(1)+CC(I)).tanh() 1.08392332733869 + 0.271752585319512*I
- zeta()[source]#
Return the Riemann zeta function evaluated at this complex number.
EXAMPLES:
sage: i = ComplexField(30).gen() sage: z = 1 + i sage: z.zeta() # needs sage.libs.pari 0.58215806 - 0.92684856*I sage: zeta(z) # needs sage.libs.pari 0.58215806 - 0.92684856*I sage: CC(1).zeta() Infinity
>>> from sage.all import * >>> i = ComplexField(Integer(30)).gen() >>> z = Integer(1) + i >>> z.zeta() # needs sage.libs.pari 0.58215806 - 0.92684856*I >>> zeta(z) # needs sage.libs.pari 0.58215806 - 0.92684856*I >>> CC(Integer(1)).zeta() Infinity
- class sage.rings.complex_mpfr.RRtoCC[source]#
Bases:
Map
EXAMPLES:
sage: from sage.rings.complex_mpfr import RRtoCC sage: RRtoCC(RR, CC) Natural map: From: Real Field with 53 bits of precision To: Complex Field with 53 bits of precision
>>> from sage.all import * >>> from sage.rings.complex_mpfr import RRtoCC >>> RRtoCC(RR, CC) Natural map: From: Real Field with 53 bits of precision To: Complex Field with 53 bits of precision
- sage.rings.complex_mpfr.cmp_abs(a, b)[source]#
Return \(-1\), \(0\), or \(1\) according to whether \(|a|\) is less than, equal to, or greater than \(|b|\).
Optimized for non-close numbers, where the ordering can be determined by examining exponents.
EXAMPLES:
sage: from sage.rings.complex_mpfr import cmp_abs sage: cmp_abs(CC(5), CC(1)) 1 sage: cmp_abs(CC(5), CC(4)) 1 sage: cmp_abs(CC(5), CC(5)) 0 sage: cmp_abs(CC(5), CC(6)) -1 sage: cmp_abs(CC(5), CC(100)) -1 sage: cmp_abs(CC(-100), CC(1)) 1 sage: cmp_abs(CC(-100), CC(100)) 0 sage: cmp_abs(CC(-100), CC(1000)) -1 sage: cmp_abs(CC(1,1), CC(1)) 1 sage: cmp_abs(CC(1,1), CC(2)) -1 sage: cmp_abs(CC(1,1), CC(1,0.99999)) 1 sage: cmp_abs(CC(1,1), CC(1,-1)) 0 sage: cmp_abs(CC(0), CC(1)) -1 sage: cmp_abs(CC(1), CC(0)) 1 sage: cmp_abs(CC(0), CC(0)) 0 sage: cmp_abs(CC(2,1), CC(1,2)) 0
>>> from sage.all import * >>> from sage.rings.complex_mpfr import cmp_abs >>> cmp_abs(CC(Integer(5)), CC(Integer(1))) 1 >>> cmp_abs(CC(Integer(5)), CC(Integer(4))) 1 >>> cmp_abs(CC(Integer(5)), CC(Integer(5))) 0 >>> cmp_abs(CC(Integer(5)), CC(Integer(6))) -1 >>> cmp_abs(CC(Integer(5)), CC(Integer(100))) -1 >>> cmp_abs(CC(-Integer(100)), CC(Integer(1))) 1 >>> cmp_abs(CC(-Integer(100)), CC(Integer(100))) 0 >>> cmp_abs(CC(-Integer(100)), CC(Integer(1000))) -1 >>> cmp_abs(CC(Integer(1),Integer(1)), CC(Integer(1))) 1 >>> cmp_abs(CC(Integer(1),Integer(1)), CC(Integer(2))) -1 >>> cmp_abs(CC(Integer(1),Integer(1)), CC(Integer(1),RealNumber('0.99999'))) 1 >>> cmp_abs(CC(Integer(1),Integer(1)), CC(Integer(1),-Integer(1))) 0 >>> cmp_abs(CC(Integer(0)), CC(Integer(1))) -1 >>> cmp_abs(CC(Integer(1)), CC(Integer(0))) 1 >>> cmp_abs(CC(Integer(0)), CC(Integer(0))) 0 >>> cmp_abs(CC(Integer(2),Integer(1)), CC(Integer(1),Integer(2))) 0
- sage.rings.complex_mpfr.create_ComplexNumber(s_real, s_imag=None, pad=0, min_prec=53)[source]#
Return the complex number defined by the strings
s_real
ands_imag
as an element ofComplexField(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 at least 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
>>> from sage.all import * >>> ComplexNumber('2.3') 2.30000000000000 >>> ComplexNumber('2.3','1.1') 2.30000000000000 + 1.10000000000000*I >>> ComplexNumber(Integer(10)) 10.0000000000000 >>> ComplexNumber(Integer(10),Integer(10)) 10.0000000000000 + 10.0000000000000*I >>> ComplexNumber(RealNumber('1.000000000000000000000000000'),Integer(2)) 1.00000000000000000000000000 + 2.00000000000000000000000000*I >>> ComplexNumber(Integer(1),RealNumber('2.000000000000000000000')) 1.00000000000000000000 + 2.00000000000000000000*I
sage: sage.rings.complex_mpfr.create_ComplexNumber(s_real=2,s_imag=1) 2.00000000000000 + 1.00000000000000*I
>>> from sage.all import * >>> sage.rings.complex_mpfr.create_ComplexNumber(s_real=Integer(2),s_imag=Integer(1)) 2.00000000000000 + 1.00000000000000*I
- sage.rings.complex_mpfr.is_ComplexNumber(x)[source]#
Return
True
ifx
is a complex number. In particular, ifx
is of theComplexNumber
type.EXAMPLES:
sage: from sage.rings.complex_mpfr import is_ComplexNumber sage: a = ComplexNumber(1, 2); a 1.00000000000000 + 2.00000000000000*I sage: is_ComplexNumber(a) doctest:warning... DeprecationWarning: The function is_ComplexNumber is deprecated; use 'isinstance(..., ComplexNumber)' instead. See https://github.com/sagemath/sage/issues/38128 for details. True sage: b = ComplexNumber(1); b 1.00000000000000 sage: is_ComplexNumber(b) True
>>> from sage.all import * >>> from sage.rings.complex_mpfr import is_ComplexNumber >>> a = ComplexNumber(Integer(1), Integer(2)); a 1.00000000000000 + 2.00000000000000*I >>> is_ComplexNumber(a) doctest:warning... DeprecationWarning: The function is_ComplexNumber is deprecated; use 'isinstance(..., ComplexNumber)' instead. See https://github.com/sagemath/sage/issues/38128 for details. True >>> b = ComplexNumber(Integer(1)); b 1.00000000000000 >>> is_ComplexNumber(b) True
Note that the global element
I
is a number field element, of typesage.rings.number_field.number_field_element_quadratic.NumberFieldElement_gaussian
, while elements of the classComplexField_class
are of typeComplexNumber
:sage: # needs sage.symbolic sage: c = 1 + 2*I sage: is_ComplexNumber(c) False sage: d = CC(1 + 2*I) sage: is_ComplexNumber(d) True
>>> from sage.all import * >>> # needs sage.symbolic >>> c = Integer(1) + Integer(2)*I >>> is_ComplexNumber(c) False >>> d = CC(Integer(1) + Integer(2)*I) >>> is_ComplexNumber(d) True
- sage.rings.complex_mpfr.late_import()[source]#
Import the objects/modules after build (when needed).
- sage.rings.complex_mpfr.make_ComplexNumber0(fld, mult_order, re, im)[source]#
Create a complex number for pickling.
EXAMPLES:
sage: a = CC(1 + I) sage: loads(dumps(a)) == a # indirect doctest True
>>> from sage.all import * >>> a = CC(Integer(1) + I) >>> loads(dumps(a)) == a # indirect doctest True
- sage.rings.complex_mpfr.set_global_complex_round_mode(n)[source]#
Set the global complex rounding mode.
Warning
Do not call this function explicitly. The default rounding mode is
n = 0
.EXAMPLES:
sage: sage.rings.complex_mpfr.set_global_complex_round_mode(0)
>>> from sage.all import * >>> sage.rings.complex_mpfr.set_global_complex_round_mode(Integer(0))