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

comparing Accurrate Dot Product with mpmath

This post is not a repost, which is related solely to mpmath. But this is mainly related to the comparison between different dot product algorithms. I have coded an accurate dot product in python in order to compute ill-conditioned dot products. x =…
0
votes
2 answers

Performing Dot Product using mpmath

I am looking for a correct implement of dot product using mpmath, but they give me different results, which I don't understand why. sum = mp.mpf(0.) …
0
votes
1 answer

mpmath library magnitude of number bug?

In the documentation of mpmath library page 8 it mentioned that There is no restriction on the magnitude of numbers >>> print(mpf(2)**32582657 - 1) 1.24575026015369e+9808357 and I checked that this code did work. However, in the same script I…
0
votes
0 answers

Fitting of mpmath.zeta using scipy.optimize.curve_fit with bounds encounters NaNs

This is a follow-up of my previous question. More information, including actual working example, can be found there. After doing some research I decided to post a new question rather than edit the previous one. I have written a python script that…
0
votes
1 answer

How to serialise an mpmath lambdified SymPy function containing Fresnel integrals?

I am using SymPy to generate some functions requiring the evaluation of Fresnel integrals and would like to save them to disk. When I sm.lambdify the expressions using the default ["scipy", "numpy"] modules, serialising them works with dill.dump()…
SebAndSeb
  • 15
  • 4
0
votes
1 answer

TypeError: cannot create mpf from x

I've checked multiple other answers for this error, but can't figure out why this is occuring. from sympy.solvers import nsolve from sympy import Symbol, log x = Symbol('x') u = nsolve(log(x/0.06) / (x-0.06) - 8,x) print(u) Traceback (most recent…
Jacob Wheeler
  • 53
  • 1
  • 8
0
votes
0 answers

Bessel function squence integration

Newbie in python, wondering what would be the best strategy for the below I have plotted the below function. z-n is an array (the n terms of a sequence in fact). Theta and r are mesh grids others are single values iv is the modified bessel function…
hecube
  • 1
  • 1
0
votes
1 answer

Casting numpy longdouble to mpmath.mpf

How can I cast np.longdouble to mpmath.mpf? import numpy as np import mpmath b = np.longdouble(1.0) a = mpmath.mpf(b) print (a)
Jakub
  • 1
  • 1
0
votes
1 answer

How to handle very small numbers (<1e-15) in Python, passed to Scipy/Numpy functions?

I would like to compute some scipy functions, such as: scipy.special.gammaincinv (https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.gammaincinv.html#scipy.special.gammaincinv). The challenge, however, is that one of the arguments I…
0
votes
0 answers

Why is vectorize so much slower with mpmath than just math

I'm trying to lower the error of my floating point calculation, to this end I wanted to use python mpmath to utilize the arbitrary precision of the library. But I notice that it is much slower than the math. Consider the program import math import…
Nitaa a
  • 121
  • 4
0
votes
0 answers

is there a way to retrieve the nodes automatically computed by mpmath.quad integration routine?

I am trying to calculate an integral with mpmath.quad. I basically have to calculate three moments of a distribution, call it f (pseudocode): integrate(f(x)/x, 0, infinity) integrate(f(x)*x, 0, infinity) integrate(f(x)ln(x)/x, 0, infinity) As far…
0
votes
1 answer

cannot create mpf from array error for Elliptic Integrals

I'm working on this code that requires the use of elliptic integrals to solve an equation as a function of time. Most of the code is pretty straight forward but it runs into an error on the final equation containing the elliptic integrals, reading…
0
votes
1 answer

Efficient way to compute the confluent Hypergeometric function for large arrays (~ 10^8 points) with complex parameters

I am working on a project related to gravitational lensing, for which I need to evaluate the confluent hypergeometric function 1F1(a,b,z) for an array z of length ~ 10^8 complex points, a = 1+0.48j and b = 1. I am looking for an efficient way to…
AstroNerd
  • 17
  • 1
0
votes
3 answers

How do I make mpmath generating more then 15 digits?

I cannot get mpmath to work as expected. Here is my code: import mpmath as mp from mpmath import * mp.dps=31 pi_30=mpf('3.141592653589793238462643383279') for i in range(20): print(round(pi_30,i)) It…
Intregal
  • 1
  • 2
0
votes
0 answers

RuntimeWarning: invalid value encountered in double_scalars and RuntimeWarning: overflow encountered in double_scalars

I am coding a newmark beta numerical dynamic equation solver but I got this error: d:\university\payan nameh\cssr python codes\newmarkbeta_method.py:46: RuntimeWarning: overflow encountered in double_scalars …
AMKH
  • 1
  • 1