| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="next" href="module-random.html" /> |
| 13 | <link rel="prev" href="module-math.html" /> |
| 14 | <link rel="parent" href="misc.html" /> |
| 15 | <link rel="next" href="module-random.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>5.8 cmath -- Mathematical functions for complex numbers</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="5.7 math " |
| 25 | href="module-math.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" |
| 28 | href="misc.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="5.9 random " |
| 31 | href="module-random.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-math.html">5.7 math </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="module-random.html">5.9 random </A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION007800000000000000000"> |
| 56 | 5.8 <tt class="module">cmath</tt> -- |
| 57 | Mathematical functions for complex numbers</A> |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | <A NAME="module-cmath"></A> |
| 62 | |
| 63 | <P> |
| 64 | This module is always available. It provides access to mathematical |
| 65 | functions for complex numbers. The functions are: |
| 66 | |
| 67 | <P> |
| 68 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 69 | <td><nobr><b><tt id='l2h-1278' xml:id='l2h-1278' class="function">acos</tt></b>(</nobr></td> |
| 70 | <td><var>x</var>)</td></tr></table></dt> |
| 71 | <dd> |
| 72 | Return the arc cosine of <var>x</var>. |
| 73 | There are two branch cuts: |
| 74 | One extends right from 1 along the real axis to ∞, continuous |
| 75 | from below. |
| 76 | The other extends left from -1 along the real axis to -∞, |
| 77 | continuous from above. |
| 78 | </dl> |
| 79 | |
| 80 | <P> |
| 81 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 82 | <td><nobr><b><tt id='l2h-1279' xml:id='l2h-1279' class="function">acosh</tt></b>(</nobr></td> |
| 83 | <td><var>x</var>)</td></tr></table></dt> |
| 84 | <dd> |
| 85 | Return the hyperbolic arc cosine of <var>x</var>. |
| 86 | There is one branch cut, extending left from 1 along the real axis |
| 87 | to -∞, continuous from above. |
| 88 | </dl> |
| 89 | |
| 90 | <P> |
| 91 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 92 | <td><nobr><b><tt id='l2h-1280' xml:id='l2h-1280' class="function">asin</tt></b>(</nobr></td> |
| 93 | <td><var>x</var>)</td></tr></table></dt> |
| 94 | <dd> |
| 95 | Return the arc sine of <var>x</var>. |
| 96 | This has the same branch cuts as <tt class="function">acos()</tt>. |
| 97 | </dl> |
| 98 | |
| 99 | <P> |
| 100 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 101 | <td><nobr><b><tt id='l2h-1281' xml:id='l2h-1281' class="function">asinh</tt></b>(</nobr></td> |
| 102 | <td><var>x</var>)</td></tr></table></dt> |
| 103 | <dd> |
| 104 | Return the hyperbolic arc sine of <var>x</var>. |
| 105 | There are two branch cuts, extending left from ±<code>1j</code> to |
| 106 | ±-∞<code>j</code>, both continuous from above. |
| 107 | These branch cuts should be considered a bug to be corrected in a |
| 108 | future release. |
| 109 | The correct branch cuts should extend along the imaginary axis, |
| 110 | one from <code>1j</code> up to ∞<code>j</code> and continuous from the |
| 111 | right, and one from -<code>1j</code> down to -∞<code>j</code> and |
| 112 | continuous from the left. |
| 113 | </dl> |
| 114 | |
| 115 | <P> |
| 116 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 117 | <td><nobr><b><tt id='l2h-1282' xml:id='l2h-1282' class="function">atan</tt></b>(</nobr></td> |
| 118 | <td><var>x</var>)</td></tr></table></dt> |
| 119 | <dd> |
| 120 | Return the arc tangent of <var>x</var>. |
| 121 | There are two branch cuts: |
| 122 | One extends from <code>1j</code> along the imaginary axis to |
| 123 | ∞<code>j</code>, continuous from the left. |
| 124 | The other extends from -<code>1j</code> along the imaginary axis to |
| 125 | -∞<code>j</code>, continuous from the left. |
| 126 | (This should probably be changed so the upper cut becomes continuous |
| 127 | from the other side.) |
| 128 | </dl> |
| 129 | |
| 130 | <P> |
| 131 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 132 | <td><nobr><b><tt id='l2h-1283' xml:id='l2h-1283' class="function">atanh</tt></b>(</nobr></td> |
| 133 | <td><var>x</var>)</td></tr></table></dt> |
| 134 | <dd> |
| 135 | Return the hyperbolic arc tangent of <var>x</var>. |
| 136 | There are two branch cuts: |
| 137 | One extends from 1 along the real axis to ∞, continuous |
| 138 | from above. |
| 139 | The other extends from -1 along the real axis to -∞, |
| 140 | continuous from above. |
| 141 | (This should probably be changed so the right cut becomes continuous from |
| 142 | the other side.) |
| 143 | </dl> |
| 144 | |
| 145 | <P> |
| 146 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 147 | <td><nobr><b><tt id='l2h-1284' xml:id='l2h-1284' class="function">cos</tt></b>(</nobr></td> |
| 148 | <td><var>x</var>)</td></tr></table></dt> |
| 149 | <dd> |
| 150 | Return the cosine of <var>x</var>. |
| 151 | </dl> |
| 152 | |
| 153 | <P> |
| 154 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 155 | <td><nobr><b><tt id='l2h-1285' xml:id='l2h-1285' class="function">cosh</tt></b>(</nobr></td> |
| 156 | <td><var>x</var>)</td></tr></table></dt> |
| 157 | <dd> |
| 158 | Return the hyperbolic cosine of <var>x</var>. |
| 159 | </dl> |
| 160 | |
| 161 | <P> |
| 162 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 163 | <td><nobr><b><tt id='l2h-1286' xml:id='l2h-1286' class="function">exp</tt></b>(</nobr></td> |
| 164 | <td><var>x</var>)</td></tr></table></dt> |
| 165 | <dd> |
| 166 | Return the exponential value <code>e**<var>x</var></code>. |
| 167 | </dl> |
| 168 | |
| 169 | <P> |
| 170 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 171 | <td><nobr><b><tt id='l2h-1287' xml:id='l2h-1287' class="function">log</tt></b>(</nobr></td> |
| 172 | <td><var>x</var><big>[</big><var>, base</var><big>]</big><var></var>)</td></tr></table></dt> |
| 173 | <dd> |
| 174 | Returns the logarithm of <var>x</var> to the given <var>base</var>. |
| 175 | If the <var>base</var> is not specified, returns the natural logarithm of <var>x</var>. |
| 176 | There is one branch cut, from 0 along the negative real axis to |
| 177 | -∞, continuous from above. |
| 178 | |
| 179 | <span class="versionnote">Changed in version 2.4: |
| 180 | <var>base</var> argument added.</span> |
| 181 | |
| 182 | </dl> |
| 183 | |
| 184 | <P> |
| 185 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 186 | <td><nobr><b><tt id='l2h-1288' xml:id='l2h-1288' class="function">log10</tt></b>(</nobr></td> |
| 187 | <td><var>x</var>)</td></tr></table></dt> |
| 188 | <dd> |
| 189 | Return the base-10 logarithm of <var>x</var>. |
| 190 | This has the same branch cut as <tt class="function">log()</tt>. |
| 191 | </dl> |
| 192 | |
| 193 | <P> |
| 194 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 195 | <td><nobr><b><tt id='l2h-1289' xml:id='l2h-1289' class="function">sin</tt></b>(</nobr></td> |
| 196 | <td><var>x</var>)</td></tr></table></dt> |
| 197 | <dd> |
| 198 | Return the sine of <var>x</var>. |
| 199 | </dl> |
| 200 | |
| 201 | <P> |
| 202 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 203 | <td><nobr><b><tt id='l2h-1290' xml:id='l2h-1290' class="function">sinh</tt></b>(</nobr></td> |
| 204 | <td><var>x</var>)</td></tr></table></dt> |
| 205 | <dd> |
| 206 | Return the hyperbolic sine of <var>x</var>. |
| 207 | </dl> |
| 208 | |
| 209 | <P> |
| 210 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 211 | <td><nobr><b><tt id='l2h-1291' xml:id='l2h-1291' class="function">sqrt</tt></b>(</nobr></td> |
| 212 | <td><var>x</var>)</td></tr></table></dt> |
| 213 | <dd> |
| 214 | Return the square root of <var>x</var>. |
| 215 | This has the same branch cut as <tt class="function">log()</tt>. |
| 216 | </dl> |
| 217 | |
| 218 | <P> |
| 219 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 220 | <td><nobr><b><tt id='l2h-1292' xml:id='l2h-1292' class="function">tan</tt></b>(</nobr></td> |
| 221 | <td><var>x</var>)</td></tr></table></dt> |
| 222 | <dd> |
| 223 | Return the tangent of <var>x</var>. |
| 224 | </dl> |
| 225 | |
| 226 | <P> |
| 227 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 228 | <td><nobr><b><tt id='l2h-1293' xml:id='l2h-1293' class="function">tanh</tt></b>(</nobr></td> |
| 229 | <td><var>x</var>)</td></tr></table></dt> |
| 230 | <dd> |
| 231 | Return the hyperbolic tangent of <var>x</var>. |
| 232 | </dl> |
| 233 | |
| 234 | <P> |
| 235 | The module also defines two mathematical constants: |
| 236 | |
| 237 | <P> |
| 238 | <dl><dt><b><tt id='l2h-1294' xml:id='l2h-1294'>pi</tt></b></dt> |
| 239 | <dd> |
| 240 | The mathematical constant <em>pi</em>, as a real. |
| 241 | </dd></dl> |
| 242 | |
| 243 | <P> |
| 244 | <dl><dt><b><tt id='l2h-1295' xml:id='l2h-1295'>e</tt></b></dt> |
| 245 | <dd> |
| 246 | The mathematical constant <em>e</em>, as a real. |
| 247 | </dd></dl> |
| 248 | |
| 249 | <P> |
| 250 | Note that the selection of functions is similar, but not identical, to |
| 251 | that in module <tt class="module"><a href="module-math.html">math</a></tt><a id='l2h-1296' xml:id='l2h-1296'></a>. The reason for having |
| 252 | two modules is that some users aren't interested in complex numbers, |
| 253 | and perhaps don't even know what they are. They would rather have |
| 254 | <code>math.sqrt(-1)</code> raise an exception than return a complex number. |
| 255 | Also note that the functions defined in <tt class="module">cmath</tt> always return a |
| 256 | complex number, even if the answer can be expressed as a real number |
| 257 | (in which case the complex number has an imaginary part of zero). |
| 258 | |
| 259 | <P> |
| 260 | A note on branch cuts: They are curves along which the given function |
| 261 | fails to be continuous. They are a necessary feature of many complex |
| 262 | functions. It is assumed that if you need to compute with complex |
| 263 | functions, you will understand about branch cuts. Consult almost any |
| 264 | (not too elementary) book on complex variables for enlightenment. For |
| 265 | information of the proper choice of branch cuts for numerical |
| 266 | purposes, a good reference should be the following: |
| 267 | |
| 268 | <P> |
| 269 | <div class="seealso"> |
| 270 | <p class="heading">See Also:</p> |
| 271 | |
| 272 | <div class="seetext"><p>Kahan, W: Branch cuts for complex elementary functions; |
| 273 | or, Much ado about nothing's sign bit. In Iserles, A., |
| 274 | and Powell, M. (eds.), <em class="citetitle" |
| 275 | >The state of the art in |
| 276 | numerical analysis</em>. Clarendon Press (1987) pp165-211.</p></div> |
| 277 | </div> |
| 278 | |
| 279 | <DIV CLASS="navigation"> |
| 280 | <div class='online-navigation'> |
| 281 | <p></p><hr /> |
| 282 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 283 | <tr> |
| 284 | <td class='online-navigation'><a rel="prev" title="5.7 math " |
| 285 | href="module-math.html"><img src='../icons/previous.png' |
| 286 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 287 | <td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services" |
| 288 | href="misc.html"><img src='../icons/up.png' |
| 289 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 290 | <td class='online-navigation'><a rel="next" title="5.9 random " |
| 291 | href="module-random.html"><img src='../icons/next.png' |
| 292 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 293 | <td align="center" width="100%">Python Library Reference</td> |
| 294 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 295 | href="contents.html"><img src='../icons/contents.png' |
| 296 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 297 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 298 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 299 | <td class='online-navigation'><a rel="index" title="Index" |
| 300 | href="genindex.html"><img src='../icons/index.png' |
| 301 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 302 | </tr></table> |
| 303 | <div class='online-navigation'> |
| 304 | <b class="navlabel">Previous:</b> |
| 305 | <a class="sectref" rel="prev" href="module-math.html">5.7 math </A> |
| 306 | <b class="navlabel">Up:</b> |
| 307 | <a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A> |
| 308 | <b class="navlabel">Next:</b> |
| 309 | <a class="sectref" rel="next" href="module-random.html">5.9 random </A> |
| 310 | </div> |
| 311 | </div> |
| 312 | <hr /> |
| 313 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 314 | </DIV> |
| 315 | <!--End of Navigation Panel--> |
| 316 | <ADDRESS> |
| 317 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 318 | </ADDRESS> |
| 319 | </BODY> |
| 320 | </HTML> |