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
1
vote
3 answers

Efficient multiple precision numerical arrays

Numpy is a library for efficient numerical arrays. mpmath, when backed by gmpy, is a library for efficient multiprecision numbers. How do I put them together efficiently? Or is it already efficient to just use a Numpy array with mpmath numbers? It…
leewz
  • 3,201
  • 1
  • 18
  • 38
1
vote
0 answers

mp array through a function

Hello people of StackExchange, I'm using the library mpmath for a project and I need some help with arrays, namely, passing them through functions. I have no problem creating an array with mpf elements. This code excerpt lets me do just…
1
vote
1 answer

ImportError: No module named mpmath. But mpmath has been installed. What's wrong?

I have anaconda installed and many libraries of python, between those mpmath. When I try to run powerlaw package I get the following error: -> 1466 from mpmath import erfc 1467 # from scipy.special import erfc 1468 from…
RM-
  • 986
  • 1
  • 13
  • 30
1
vote
1 answer

Elementwise operations in mpmath slow compared to numpy and its solution

I have some calculations that involve factorials that explode pretty fast so I resolved to use the arbitrary precision library mpmath. The code I have looks like this: import numpy as np import mpmath as mp import time a = np.linspace( 0,…
evan54
  • 3,585
  • 5
  • 34
  • 61
1
vote
1 answer

High precision multidimensional Newtons method with mpmath.findroot in Python

I am trying to solve a system of equations numerically to high precision using the multidimensional newtons method of mpmath.findroot. Here's an example system: def f(x_0, x_1, x_2, x_3, x_4, x_5, y_0, y_1, y_2, y_3, y_4, y_5, l_0, l_1,l_2, l_3,…
1
vote
1 answer

Speed issues, python not responding: Solving ODEs

f = odefun(lambda x,y: (x)/((x**2) + (y**2))**(3.0/2.0),0,1) for x in range(500): listx.append(f(x)) For a quick background I'm trying to do a gravitation/orbital simulation. I create two lists listx and listy then I put them into matplot and…
Matt
  • 3,508
  • 6
  • 38
  • 66
1
vote
1 answer

Adding legend to complex plot made with mpmath

I've been using the cplot command from the mpmath library to plot a complex function. It works pretty easily, all I have to do is write cplot(G_fit, [0.001, v_max], [-v_max, v_max], points = 100000) and I get a fairly smooth graph of my function…
Mr. G
  • 189
  • 1
  • 8
1
vote
3 answers

Fastest possible method for the arcsin function on small, arbitrary floating-point values

I need to calculate the arcsine function of small values that are under the form of mpmath's "mpf" floating-point bignums. What I call a "small" value is for example e/4/(10**7) = 0.000000067957045711476130884... Here is a result of a test on my…
user2464424
  • 1,536
  • 1
  • 14
  • 28
1
vote
2 answers

Speed Up python code (multiple integral calculations)

Is there a way to speed up this code: import mpmath as mp import numpy as np from time import time as epochTime def func(E): f = lambda theta: mp.sin(theta) * mp.exp(E * (mp.cos(theta**2) + \ …
rowman
  • 1,516
  • 1
  • 16
  • 26
0
votes
1 answer

Extend a specific version of Python (on Linux Ubuntu/Unity)

I recently got Ubuntu 11.10 and put several versions of Python on it, including EPD Python, Python 2.7 (standard) and Python 3.2. I'm primarily using the EPD distribution and wanted to extend it with the mpmath module. Basically that sounds very…
user1227298
  • 75
  • 1
  • 8
0
votes
0 answers

Is sympy evalf() using binary or decimal arithmetic?

I'm working on a numerical evaluation using the sympy evalf() package. Consider the mpmath library's introduction to precision and accuracy https://mpmath.org/doc/current/technical.html, where…
0
votes
0 answers

numpy allclose vs mpmath almosteq

abs(a - b) <= (atol + rtol * abs(b)) vs (abs(a - b) <= atol or abs(a - b) / max(abs(a), abs(b)) < rtol) Docs: numpy.allclose, mpmath.almosteq -- Source: numpy, mpmath How do these schemes differ? An obvious one is that allclose is and while…
OverLordGoldDragon
  • 1
  • 9
  • 53
  • 101
0
votes
0 answers

How to replace eval in python

I have the following code, where I'm using mpmath library for calculating different irrational numbers: for i in range(1, len(self.layer_sizes) - 1): z = np.dot(a, self.weights[i]) mp.dps = np.max(abs(z))+self.layer_windows[i] +…
0
votes
0 answers

Has automatic differenation been implemented in mpmath library?

I'm learning about the numerical differentiation and is trying out some examples with mpmath library. On it's documentation page, it suggested that the mpmath.diff used either method Supported methods are 'step' or 'quad': derivatives may be…
0
votes
0 answers

How to calculate the Automatic differentiation of an arbitrary function in python

I'm using the mpmath library to compute a self defined function f(x) and needed to compute its higher order derivatives. I found the Automatic differentiation on Wikipedia and found it useful. # Automatic Differentiation import math class Var: …