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
0
votes
0 answers

Looking for equivalent of python's mpmath for scala/spark

Is there anything similar to mpmath for scala? More precisily, the only features of mpmath that I'm using are factorial (this is faster than factorial from python's math and works with big numbers) and binomial coefficient computations and setting…
elfinorr
  • 189
  • 3
  • 12
0
votes
2 answers

Convert a sympy poly with imaginary powers to an mpmath mpc

I have a sympy poly that looks like: Poly(0.764635937801645*I**4 + 7.14650839258644*I**3 - 0.667712176660315*I**2 - 2.81663805543677*I - 0.623299856233272, I, domain='RR') I'm converting to mpc using the following code: a = val.subs('I',1.0j) b =…
Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26
0
votes
1 answer

How to manage "TypeError" message when plotting functions defined in mpmath module instead of scipy?

For the purpose of my problem, I have to use gamma functions from mpmath module rather than scipy. However, I am using matplotlib.pyplot to plot my functions when the variable is taken from a numpy array and the y-values are supposed to be produced…
Rebel
  • 472
  • 8
  • 25
0
votes
1 answer

"TypeError" message while performing quad integration method of scipy.integrate with mpmath functions

I am trying to calculate two integrals using scipy.integrate.quad. However, since gamma functions with negative first parameter are not defined in scipy, I had to choose the version from mpmath. After running the following code, from scipy.integrate…
Rebel
  • 472
  • 8
  • 25
0
votes
1 answer

In python mpmath v. 0.19, the invertlaplace() command can't be found

I've installed mpmath release 0.19 in Anaconda on my Windows computer and am using Spyder. I ran runtests() and everything was listed as OK. I can't get the 2017 invertlaplace() function to work, though. It seems that python can't find the command,…
Eric Rasmusen
  • 66
  • 1
  • 5
0
votes
1 answer

mpmath laplace inverse function in python

I am trying to find the laplace inverse of an expression for which all but one variable are already defined at the time of declaration: from numpy import * import mpmath as mp p0 = 1 E = 2 c= 3 L = 4 x = 2.5 t = linspace(1,5,10) ulaplace = [] def…
user32882
  • 5,094
  • 5
  • 43
  • 82
0
votes
1 answer

Why mpmath slower than gsl on the same precision? And Which results are right?

I simplely test the clausen function of mpmath and gsl. The code is below: mp.prec = 53 time_begin = time.time() print "mpmath results:" print clsin(2,3.1415926535897327) print "time1:" print (time.time() - time_begin) time_begin = time.time() print…
Star
  • 59
  • 7
0
votes
1 answer

Does sympy/mpmath cache results and what speed implications would that have?

I performed the following calculation: from sympy import mpmath as mp mp.besseljzero(1000, 100) which understandably took some time > 10s if not more (didn't time it). Subsequent calls were significantly faster which made me think it caches the…
evan54
  • 3,585
  • 5
  • 34
  • 61
0
votes
2 answers

How to solve a generalized eigenvalue Problem for multiprecision in Python

I want to solve a generalized eigenvalue problem for multiprecision in Python ( A.C = (lam).B.C where A and B are 3000x3000 matrices and C is 3000x1 vector. (lam) is the eigenvalue.). So I have installed MPMATH. But I can't find a Python program for…
0
votes
1 answer

pickle/mpmath/python - pickling with different backends

https://code.google.com/p/mpmath/issues/detail?id=239 I have experienced the problem of pickling mpmath data with a python backend and trying to retrieve them with a gmp backend. This results in an error: ValueError: invalid digits This is in…
evan54
  • 3,585
  • 5
  • 34
  • 61
0
votes
2 answers

python / mpmath - How to get the real values of a complex matrix?

I am trying to get the real values of a complex valued matrix. import mpmath as mp A = mp.matrix([[1+1j, 2+2j],[3+2j, 4+2j]]) I've tried both: mp.re(A) np.real(A) but neither work. I've also tried looking for information here but haven't found…
evan54
  • 3,585
  • 5
  • 34
  • 61
0
votes
1 answer

Sympy/mpmath/gmpy error while using multiprocessing

EDIT: This is a sympy bug. I have moved the discussion to https://github.com/sympy/sympy/issues/7457 I have a Python program that uses sympy to perform some core functionality that involves taking the intersection of a line and a shape. This…
Chinmay Kanchi
  • 62,729
  • 22
  • 87
  • 114
0
votes
1 answer

numpy.allclose and multiprecision with mpmath

In my python code, I regularly verify some calculations using numpy.allclose. On the other hand, apart from these checks the implementation is able to deal with multiprecision (mpmath.mpc) numbers. If I want to run my verification code for the…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
-1
votes
1 answer

How to find roots of a complex function with python?

I'm working with a complex function whose coordinate is omega. I formed it as follows: from sympy import * def alpha(n, rho, l): return n**2 + (2*rho + 2)*n + 2*rho + 1 def beta(n, rho, l): return -(2*n**2 + (8*rho + 2)*n + 8*rho**2 +…
Ramos
  • 9
  • 4
-1
votes
1 answer

why does mpmath throw an error when i trying to plug in the Chudnovsky algorithm?

im trying to use the Chudnovsky algorithm in mpmath for python and so i wrote this code: from mpmath import * import csv mp.dps = 100; mp.pretty = True x = mpf(426880)*sqrt(10005)*(nsum(lambda q:…
1 2 3
11
12