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
1 answer

What is the default accuracy for the mpmath function hyperu?

Computation of the Tricomi confluent hypergeometric function can be ill-conditioned when it uses the sum of two 1F1 functions, as they can be nearly equal in size but opposite in sign. The mpmath function "hyperu" uses arbitrary precision internally…
tcp
  • 31
  • 3
1
vote
1 answer

Python: symbolic use of hyp2f1 with sympy

In Python, I want to use the hypergeometric function hyp2f1 while keeping at least one symbolic argument. However, there is a TypeError cannot create mpf from d where d is the (last) argument of the hypergeometric function. Someone asked a similar…
Vinsanity
  • 13
  • 2
1
vote
1 answer

Interoperability between C++ Boost Multiprecision and Python's mpmath

I have experience working with both Boost Multiprecision and with Python's mpmath, separately. When it gets to making both communicate (for example to create Python extensions in C++), my attempts have always involved some sort of wasteful…
AndraSol
  • 65
  • 6
1
vote
1 answer

Probability values of arbitrary precision in SymPy

I am trying to compute some simple probabilities in Sympy, but I keep getting numerical errors. How could I change this code to use arbitrary precision in mpmath? from sympy import * from sympy.stats import Binomial, density, P from mpmath import…
linhares
  • 504
  • 6
  • 17
1
vote
1 answer

Is there a faster way of combining functions containing mpf (mpmath floats) with numpy arrays?

I was having problems with the accuracy of floats in Python. I need high accuracy because I want to use explicitly written spherical bessel functions J_n (x), which deviate (especially for n>5) from their theoretical values at low x values if numpy…
Edi
  • 13
  • 4
1
vote
1 answer

Python: AttributeError: 'mpc' (or 'mpf') object has no attribute 'arcsin'

I was trying to use Jacobi elliptical function from mpmath, but getting the error for the simple code given below: import numpy as np import scipy.integrate as spi from scipy import special as sp import matplotlib.pyplot as plt from math import…
deltasata
  • 377
  • 1
  • 4
  • 21
1
vote
2 answers

How to input a float as a string of '0' and '1' characters with the bitstring package?

I want to use the packages bitstring and mpmath (or any other way to guarantee an arbitrarily set output precision and specified rounding mode) to calculate values of rcp, sqrt, sin, cos, ln, exp,... on float inputs given as binary bitstrings and…
1
vote
1 answer

np.roots() causing 'float() argument must be a string or a number' with mp.mpc type problems

I was getting this error: > float() argument must be a string or a number So, why does this happen?(I tried commands like np.asarray() but it keeps failing). mp.mpc(cmath.rect(a,b)))
user6621849
1
vote
1 answer

Octave: ImportError when using symbolic package

I first built Octave from source using: $brew install --build-from-source octave Then I installed the symbolic package from within octave using: $pkg install -forge symbolic After that I did: $pkg load symbolic On using syms function it gave…
1
vote
0 answers

mpmath: data type not understood

I am having an issue with mpmath. I am trying to reproduce a plot from the examples in the documentation. I suspect the issue is a namespace clash, but I can't get it to work. Here is my code and the error: from pylab import * from matplotlib import…
kevinea
  • 119
  • 1
  • 9
1
vote
1 answer

sympy and mpmath give "TypeError: cannot create mpf" when using the erf() function within solveset()

I have 4 input variables (floats): Xmax Xmin percentage mode and I want to solve the following (rather long) equation for s: > (1/2+1/2*erf((log(Xmax)-(log(mode)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(Xmin)-(log(mode)+s**2))/(sqrt(2)*s))) -…
cachemoi
  • 343
  • 2
  • 13
1
vote
1 answer

Solving a symbolic sympy with mpmath mpc types

Basically what the title states. I'm getting what I think to be numerical errors propagating in my code, so am attempting to improve by changing all the types to mpcs, with a high precision. However, some of my calculations are symbolic and sympy…
Jibbity jobby
  • 1,255
  • 2
  • 12
  • 26
1
vote
1 answer

How to pass a float as string to mpmath in python?

I get some trouble, if I want to pass a float to mpmath.mpf and find the root with mp.findroot. The problem continues the story of a previous question: Polynomial function cannot be solved by Python sympy import sympy omega =…
Aloex
  • 103
  • 8
1
vote
1 answer

I am trying to run factorization algorithms in python. I am having problems with the syntax of mpmath and possibly need to use numpy

The mpmath library appears to be installed along with the rest of python been trying: from mpmath import * then think x= mpf (65455213.0) etc could be miles off. Ultimately I need very accurate operations on very long numbers, time is not the…
Kev88
  • 21
  • 5
1
vote
1 answer

Have I encountered a limit to mpmath's floating-point precision?

mpmath purports to support "arbitrary-precision floating-point arithmetic." And yet . . . >>> import mpmath >>> 1 + mpmath.erf(-5.921) mpf('1.1102230246251565e-16') >>> 1 + mpmath.erf(-5.922) # I expect a smaller positive number…
abcd
  • 10,215
  • 15
  • 51
  • 85