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.

133 questions
11
votes
2 answers

How to mpf an array?

I have: import numpy as np from mpmath import * mpf(np.array(range(0,600))) But it won't let me do it: TypeError: cannot create mpf from array So what should I be doing? Essentially I'm going to have use this array and multiply element-wise with…
Rapid
  • 1,202
  • 1
  • 12
  • 24
7
votes
5 answers

Is there a scaled complementary error function in python available?

In matlab there is a special function which is not available in any of the collections for the Python I know (numpy, scipy, mpmath, ...). Probably there are other places where functions like this one may be found? UPD For all who think that the…
Misha
  • 532
  • 6
  • 19
6
votes
1 answer

Interoperability between Numpy and MpMath in Python

I have a numpy array A with mpf elements that have decimal precision 100. Is this precision cast away if I decide to take the numpy dot product of A with itself? If this is the case, is there any way to convert a numpy array to an mpmath matrix, so…
Jing
  • 183
  • 1
  • 2
  • 6
6
votes
3 answers

Proper way to make functions extensible by the user

What is the proper way in Python to allow the user to extend the types on which a function can operate without altering the original code of the function? Suppose I have a module with a my_module.foo() function that was originally written to work on…
bluescarni
  • 3,767
  • 1
  • 17
  • 32
5
votes
2 answers

sympy installed, however sympy.mpmath not found

I want to use the jacobDN function in sympy, so I download it and python setup.py install it, successfully. When I want to use it as in the documentation does: >>> from sympy.mpmath import * Traceback (most recent call last): File "", line…
an offer can't refuse
  • 2,814
  • 3
  • 22
  • 40
5
votes
1 answer

How to properly cast mpmath matrix to numpy ndarray ( and mpmath.mpf to float)

I'm working with mpmath python library to gain precision during some computations, but i need to cast the result in a numpy native type. More precisely i need to cast an mpmath matrix (that contains mpf object types) in an numpy.ndarray (that…
5
votes
3 answers

Element-wise operations in mpmath

I am looking to perform element-wise mpmath operations on Python arrays. For example, import mpmath as mpm x = mpm.arange(0,4) y = mpm.sin(x) # error Alternatively, using mpmath matrices x = mpm.matrix([0,1,2,3]) y = mpm.sin(x) …
Doubt
  • 1,003
  • 2
  • 14
  • 25
4
votes
0 answers

Laplace transform using numerical integration in Python has very poor precision

I have written a function to compute the Laplace transform of a function using scipy.integrate.quad. It is not a very sophisticated function and currently performs poorly on the probability density function of an Erlang distribution. I have included…
4
votes
1 answer

Difficulties in evaluating mpmath gammainc function

I am playing with the python library mpmath, in particular evaluating the incomplete gamma function. This is part of a root finding routine but its evaluation is extremely slow for some combinations of complex-valued arguments. import mpmath as…
linello
  • 7,476
  • 14
  • 53
  • 98
4
votes
1 answer

Python: mpmath lose precision when divide large number

I came across a π algorithm called Chudnovsky algorithm. A Python implementation is showed on Wikipedia which use decimal package comes with Python. But recently when I test Gauss Legendre algorithm I found mpmath package runs much more efficient…
Page David
  • 1,042
  • 1
  • 10
  • 23
4
votes
1 answer

evaluating a sympy function at an arbitrary-precision floating point

Given a sympy symbolic function, for example x=symbols("x") h=sin(x) when one calls h.subs(x, mpf('1.0000000000000000000000000000000000000000000001')) sympy returns a floating point number. The return value is not an mpf. Is there a convenient…
Ryan Budney
  • 308
  • 1
  • 6
  • 15
4
votes
1 answer

Changing Figure Size in Sympy.mpmath.plot

I hope this question isn't too elementary. I've searched extensively for a solution but haven't discovered one yet. I've recently begun using Jupyter Notebook with Sympy to take notes and do my homework in my Calculus II class (and what a HUGE…
tommytwoeyes
  • 453
  • 4
  • 19
4
votes
1 answer

How to use JIT in python with mpmath / gmpy effectively?

This is my first attempt to use JIT for python and this is the use case I want to speed up. I read a bit about numba and it seemed simple enough but the following code didn't provide any speedup. Please excuse any obvious mistakes I may be making. I…
evan54
  • 2,959
  • 1
  • 25
  • 50
3
votes
0 answers

vectorize incomplete gamma function with negative arguments

I am using mpmaths incomplete gamma function with negative z, and complex integration bounds a, b. See documentation: docs This can't be done with scipy's incomplete gamma function. I benched marked mpmath against Mathematica and got the same…
Sebastiano1991
  • 667
  • 7
  • 23
3
votes
1 answer

Upper limit of precision in mpmath-python

When in python and mpmath one's code starts with from mpmath import mp mp.dps =200 My question is whether -depending on one's hardware- does there exist an upper limit to mp.dps and how can one find this uper limit.
user12067036
1
2 3
8 9