def gammaincc(a, x, dps=50, maxterms=10*10*10*10*10*10*10*10): """Compute gammaincc exactly like mpmath does but allow for more terms in hypercomb. See mpmath/functions/expintegrals.py#L187 in the mpmath github repository. """ with mp.workdps(dps): z, a = a, x if mp.isint(z): try: # mpmath has a fast integer path return mpf2float(mp.gammainc(z, a=a, regularized=True)) except mp.libmp.NoConvergence: pass nega = mp.fneg(a, exact=True) G = [z] # Use 2F0 series when possible; fall back to lower gamma representation try: def h(z): r = z-1 return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)] return mpf2float(mp.hypercomb(h, [z], force_series=True)) except mp.libmp.NoConvergence: def h(z): T1 = [], [1, z-1], [z], G, [], [], 0 T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a return T1, T2 return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms))
def gammaincc(a, x, dps=50, maxterms=10**8): """Compute gammaincc exactly like mpmath does but allow for more terms in hypercomb. See mpmath/functions/expintegrals.py#L187 in the mpmath github repository. """ with mp.workdps(dps): z, a = a, x if mp.isint(z): try: # mpmath has a fast integer path return mpf2float(mp.gammainc(z, a=a, regularized=True)) except mp.libmp.NoConvergence: pass nega = mp.fneg(a, exact=True) G = [z] # Use 2F0 series when possible; fall back to lower gamma representation try: def h(z): r = z-1 return [([mp.exp(nega), a], [1, r], [], G, [1, -r], [], 1/nega)] return mpf2float(mp.hypercomb(h, [z], force_series=True)) except mp.libmp.NoConvergence: def h(z): T1 = [], [1, z-1], [z], G, [], [], 0 T2 = [-mp.exp(nega), a, z], [1, z, -1], [], G, [1], [1+z], a return T1, T2 return mpf2float(mp.hypercomb(h, [z], maxterms=maxterms))
def idmap(self, *args): if self.spfunc_first: res = self.spfunc(*args) if np.isnan(res): return np.nan args = list(args) args[self.index] = res with mpmath.workdps(self.dps): res = self.mpfunc(*tuple(args)) # Imaginary parts are spurious res = mpf2float(res.real) else: with mpmath.workdps(self.dps): res = self.mpfunc(*args) res = mpf2float(res.real) args = list(args) args[self.index] = res res = self.spfunc(*tuple(args)) return res
def mp_wright_bessel(a, b, x, dps=50, maxterms=2000): """Compute Wright's generalized Bessel function as Series with mpmath. """ with mp.workdps(dps): a, b, x = mp.mpf(a), mp.mpf(b), mp.mpf(x) res = mp.nsum( lambda k: x**k / mp.fac(k) * rgamma_cached(a * k + b, dps=dps), [0, mp.inf], tol=dps, method='s', steps=[maxterms]) return mpf2float(res)
def gammainc(a, x, dps=50, maxterms=10**8): """Compute gammainc exactly like mpmath does but allow for more summands in hypercomb. See mpmath/functions/expintegrals.py#L134 in the mpmath github repository. """ with mp.workdps(dps): z, a, b = mp.mpf(a), mp.mpf(x), mp.mpf(x) G = [z] negb = mp.fneg(b, exact=True) def h(z): T1 = [mp.exp(negb), b, z], [1, z, -1], [], G, [1], [1 + z], b return (T1, ) res = mp.hypercomb(h, [z], maxterms=maxterms) return mpf2float(res)
def gammainc(a, x, dps=50, maxterms=10**8): """Compute gammainc exactly like mpmath does but allow for more summands in hypercomb. See mpmath/functions/expintegrals.py#L134 in the mpmath github repository. """ with mp.workdps(dps): z, a, b = mp.mpf(a), mp.mpf(x), mp.mpf(x) G = [z] negb = mp.fneg(b, exact=True) def h(z): T1 = [mp.exp(negb), b, z], [1, z, -1], [], G, [1], [1+z], b return (T1,) res = mp.hypercomb(h, [z], maxterms=maxterms) return mpf2float(res)