1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
Mathematical constants
----------------------
Mpmath supports arbitrary-precision computation of various common (and less common) mathematical constants. These constants are implemented as lazy objects that can evaluate to any precision. Whenever the objects are used as function arguments or as operands in arithmetic operations, they automagically evaluate to the current working precision. A lazy number can be converted to a regular ``mpf`` using the unary ``+`` operator, or by calling it as a function::
>>> from mpmath import *
>>> mp.dps = 15
>>> pi
<pi: 3.14159~>
>>> 2*pi
mpf('6.2831853071795862')
>>> +pi
mpf('3.1415926535897931')
>>> pi()
mpf('3.1415926535897931')
>>> mp.dps = 40
>>> pi
<pi: 3.14159~>
>>> 2*pi
mpf('6.283185307179586476925286766559005768394338')
>>> +pi
mpf('3.141592653589793238462643383279502884197169')
>>> pi()
mpf('3.141592653589793238462643383279502884197169')
Exact constants
...............
The predefined objects :data:`j` (imaginary unit), :data:`inf` (positive infinity) and :data:`nan` (not-a-number) are shortcuts to :class:`mpc` and :class:`mpf` instances with these fixed values.
Pi (``pi``)
....................................
.. autoattribute:: mpmath.mp.pi
Degree (``degree``)
....................................
.. autoattribute:: mpmath.mp.degree
Base of the natural logarithm (``e``)
.....................................
.. autoattribute:: mpmath.mp.e
Golden ratio (``phi``)
......................
.. autoattribute:: mpmath.mp.phi
Euler's constant (``euler``)
............................
.. autoattribute:: mpmath.mp.euler
Catalan's constant (``catalan``)
................................
.. autoattribute:: mpmath.mp.catalan
Apery's constant (``apery``)
............................
.. autoattribute:: mpmath.mp.apery
Khinchin's constant (``khinchin``)
..................................
.. autoattribute:: mpmath.mp.khinchin
Glaisher's constant (``glaisher``)
..................................
.. autoattribute:: mpmath.mp.glaisher
Mertens constant (``mertens``)
..................................
.. autoattribute:: mpmath.mp.mertens
Twin prime constant (``twinprime``)
...................................
.. autoattribute:: mpmath.mp.twinprime
|