Questions tagged [mpmath]

Mpmath is a Python library for arbitrary-precision floating-point arithmetic.

Mpmath is a pure-Python library for multiprecision floating-point arithmetic. It provides an extensive set of transcendental functions, unlimited exponent sizes, complex numbers, interval arithmetic, numerical integration and differentiation, root-finding, linear algebra, and much more. Almost any calculation can be performed just as well at 10-digit or 1000-digit precision, and in many cases mpmath implements asymptotically fast algorithms that scale well for extremely high precision work. Mpmath internally uses Python's builtin long integers by default, but automatically switches to GMP/MPIR for much faster high-precision arithmetic if gmpy is installed or if mpmath is imported from within Sage.

Mpmath is free (BSD license) and easy to install or include in other software due to being written entirely in Python with no additional required dependencies. It runs on Python 2.5 or higher, including Python 3.x. It can be used as a library, interactively via the Python interpreter, or via SymPy which uses it for numerical evaluation of symbolic expressions. Mpmath is also a standard component of Sage which uses it for special function evaluation.

If matplotlib is available, mpmath also provides a convenient plotting interface.

169 questions
2
votes
4 answers

What does mpf in the mpmath mean?

x in the following has the value: [mpf('0.0') mpf('0.10000000000000001') mpf('0.20000000000000001') mpf('0.30000000000000004') mpf('0.40000000000000002') mpf('0.5') mpf('0.60000000000000009') mpf('0.70000000000000007') mpf('0.80000000000000004')…
an offer can't refuse
  • 4,245
  • 5
  • 30
  • 50
2
votes
2 answers

Python Sympy Arbitrary Approximation to Arbitrary Sympy Expression?

I find myself wanting to use approxmations provided as part of the mpmath package, but getting confused on exactly what they are supposed to be doing: http://docs.sympy.org/dev/modules/mpmath/calculus/approximation.html What exactly is the…
D A
  • 3,130
  • 4
  • 25
  • 41
2
votes
1 answer

Finding the roots of a simple polynomial with mpmath

I'm trying to use mpmath.polyroots to find the roots of a simple polynomial with integer coefficients x*(x-4)**3, which when expanded has the coefficient vector of [1, -12, 48, 64, 0]. The following code fails: import mpmath p = [ 1, -12, 48, -64,…
Hooked
  • 84,485
  • 43
  • 192
  • 261
2
votes
1 answer

Mpmath.meijerg: Order of arguments

I'm currently looking at the mpmath documentation for Meijerg. It says mpmath.meijerg(a_s, b_s, z, r=1, **kwargs) Evaluates the Meijer G-function, defined as for an appropriate choice of the contour L (see references). There are p…
FooBar
  • 15,724
  • 19
  • 82
  • 171
2
votes
1 answer

Implementation of derivatives of Jacobi theta function

I am looking for an implementation of the derivative of the Jacobi theta functions for python. I found this http://mpmath.googlecode.com/svn/trunk/doc/build/functions/elliptic.html#jtheta However, the derivative is computed with respect to the wrong…
Jonathan Lindgren
  • 1,192
  • 3
  • 14
  • 31
2
votes
1 answer

How to make mpmath function return python float?

I would like to convert an mpmath function to a function that can work on numpy arrays. Let's say I have for example the following A=np.linspace(0,1,100) besseli_vec = numpy.frompyfunc(mpmath.besseli, 2, 1) Y=besseli_vec(0, A) However, now the…
Jonathan Lindgren
  • 1,192
  • 3
  • 14
  • 31
2
votes
3 answers

Python mpmath not arbitrary precision?

I'm trying to continue on my previous question in which I'm trying to calculate Fibonacci numbers using Benet's algorithm. To work with arbitrary precision I found mpmath. However the implementation seems to fail above certain value. For instance…
Ropstah
  • 17,538
  • 24
  • 120
  • 194
2
votes
1 answer

Sympy: using lambdify to evaluate expression over 1d array and return root at each element

I'm having trouble getting my head around the following numerical evaluation. I have a function with two variables, r and gamma. I now wish to plot the root of that function as a function of gamma from 0 to 500. I know how to use lambdify to…
Kokomoking
  • 363
  • 1
  • 4
  • 5
2
votes
2 answers

Precision loss numpy - mpmath

I use numpy and mpmath in my Python programm. I use numpy, because it allows an easy access to many linear algebra operations. But because numpy's solver for linear equations is not that exact, i use mpmath for more precision operations. After i…
dalvo
  • 47
  • 2
  • 7
2
votes
2 answers

python logarithm incorrectly calculated very small complex numbers

I need to use python to calculate the logarithms of objects of the form log( 1 - n0 - n1*1j) where n0 and n1 are very small numbers ~ 1.0e-27 and 1j is the the imaginary number. Using cmath.log gives the wrong answer print cmath.log( 1.0 - 1e-27 -…
2
votes
1 answer

How do arbitrary-precision libraries like mpmath evaluate simple trigonometric functions?

I ask for a brief explanation, pointing out the various acceleration methods involved. This is just for mere curiosity. For example the mpmath website tells that the exponential function formula is used for operations in the complex plane, but for…
user2464424
  • 1,536
  • 1
  • 14
  • 28
1
vote
1 answer

sympy - can't make nsolve method work

I did this code: from scitools.std import * from sympy import * x=Symbol('x') #Integral function #def f(x): --> I also tried this # return exp(-x**2) f=exp(-x**2) intac=integrate(f,(x,0,1)) print(nsolve(f,x,1)) The interpreter…
George
  • 5,808
  • 15
  • 83
  • 160
1
vote
1 answer

mpmath stopped working with the high precisions

I'm using jupyter notebook with anaconda on windows (reinstalled to the current version after several attempts). Somehow the mpmath library stopped working. Consider the following code import mpmath as mp mp.dps=530 mp.mpf(1) / mp.mpf(6) But the…
1
vote
1 answer

Python Sympy and mpmath give different results

I did an evaluation of mpmath and sympy and found inconsistencies, which I cannot resolve. I believe mpmath gives correct results. Please, can somebody help in resolving this? import sympy as sp import mpmath as mp # Set the desired precision to…
Samson
  • 123
  • 5
1
vote
1 answer

How to combine scipy interp1d with mpmath quadosc

I have a density function (from quantum mechanics calculations) to be multiplied with the spherical Bessel function with a momentum grid (momentum q 1d array, real space distance r 1d array, so need to calculate jn(q*r) 2d array). The product will…