ramanujan_qft.mellin#

Product integrals \(\int_0^\infty x^{s-1}f(x)\,g(x)\,dx\) by Mellin residue summation, and the atlas of factors. User guide: Product integrals by Mellin residue summation.

ramanujan_qft.mellin.product_integral(f, g, s=1, dps=None, tol=None, max_terms=4000, return_info=False, continuation=False, max_dps=None)[source]#

Evaluate \(\int_0^\infty x^{s-1} f(x)\,g(x)\,dx\) by Mellin residue summation.

One factor is expanded in its Taylor series at \(x = 0\) (and the other at \(x = \infty\) when it has such an expansion), and the residue series

\[I(s) = \sum_n r_n\,M_g(s + p_n) + \sum_n q_n\,M_f(s - a_n)\]

is summed. Only expansions for which closing the Mellin-Barnes contour is legitimate are used (see the user guide), the existence of the integral is checked first, and the working precision is raised against cancellation.

Parameters:
  • f (MellinFunction) – Factors from the atlas: exponential(), gaussian(), bessel_j(), cosine(), sine(), inverse_power(), gaussian_bessel().

  • g (MellinFunction) – Factors from the atlas: exponential(), gaussian(), bessel_j(), cosine(), sine(), inverse_power(), gaussian_bessel().

  • s (number or str, default 1) – The Mellin variable; s=1 gives the plain integral. Complex values are allowed; strings are exact decimals.

  • dps (int, optional) – Decimal digits requested (default: mpmath.mp.dps). The result is rounded to dps digits.

  • tol (number, optional) – Relative accuracy target (default \(10^{-dps}\)).

  • max_terms (int, default 4000) – Largest number of residue terms per series.

  • return_info (bool, default False) – Also return a dict with the keys method (the expanded factor, and notes on Wynn acceleration or coinciding poles), error_estimate, terms and working_dps.

  • continuation (bool, default False) – Allow s outside the strip where the integral exists, and return the analytic continuation of \(I(s)\).

  • max_dps (int, optional) – Cap on the internal working precision (default max(20*dps, 1000)).

Return type:

mpmath.mpf or mpmath.mpc, or (value, dict) if return_info is true

Raises:
  • ValueError – If the integral does not exist for this s (the message gives the strip), or s is not finite.

  • SeriesConvergenceError – If no valid expansion reaches the accuracy target: the scales are at the convergence boundary \(\rho = 1\) (for example \(e^{-x}J_0(x)\)), or the series needs more than max_terms terms, or more than max_dps digits.

Notes

The method is the classical Mellin-convolution (Meijer-G / Slater) residue expansion; see the prior-art page of the documentation (Marichev 1983; Adamchik and Marichev 1990; Slater 1966; DLMF 2.5).

Examples

>>> product_integral(exponential(1), bessel_j(0, 3))      # 1/sqrt(10)
mpf('0.31622776601683794')
>>> v, info = product_integral(exponential(1), bessel_j(0, 3), dps=30, return_info=True)
>>> info['method'], info['terms'], info['working_dps']
('expand exp(-1 x)', 73, 45)
>>> product_integral(exponential(1), bessel_j(0, 1))
Traceback (most recent call last):
...
ramanujan_qft.mellin.SeriesConvergenceError: neither ordering of exp(-1 x) * J_0(1 x) is a convergent residue expansion (the scales are at the convergence boundary rho = 1, or the factors cannot be expanded). Use quadrature or a closed form.

Atlas#

ramanujan_qft.mellin.exponential(k)[source]#

The factor \(e^{-kx}\).

Parameters:

k (number or str) – Real, finite and positive.

Returns:

Mellin transform \(k^{-s}\Gamma(s)\); Gamma orders \(L = R = 1\), scale \(k\).

Return type:

MellinFunction

Examples

>>> product_integral(exponential(2), cosine(5))     # 2/29
mpf('0.068965517241379309')
ramanujan_qft.mellin.gaussian(a)[source]#

The factor \(e^{-ax^2}\).

Parameters:

a (number or str) – Real, finite and positive.

Returns:

Mellin transform \(\tfrac12 a^{-s/2}\Gamma(s/2)\); Gamma orders \(L = R = 1/2\), scale \(\sqrt{2a}\).

Return type:

MellinFunction

Examples

>>> product_integral(gaussian(1), cosine(3))        # sqrt(pi)/2 exp(-9/4)
mpf('0.093407630728565852')
ramanujan_qft.mellin.bessel_j(nu, b)[source]#

The factor \(J_\nu(bx)\).

Parameters:
  • nu (number or str) – Real order \(\nu > -1\), or a negative integer (mapped to \(J_{-n} = (-1)^n J_n\)).

  • b (number or str) – Real, finite and positive.

Returns:

Mellin transform \(2^{s-1} b^{-s}\,\Gamma(\tfrac{\nu+s}{2})/\Gamma(\tfrac{\nu-s}{2}+1)\); Gamma orders \(L = R = 1\), scale \(b\).

Return type:

MellinFunction

Raises:

ValueError – For a complex order, an order \(\le -1\) that is not an integer, or \(b \le 0\).

Examples

>>> product_integral(bessel_j(0, 2), cosine(1))     # 1/sqrt(3)
mpf('0.57735026918962573')
ramanujan_qft.mellin.cosine(b)[source]#

The factor \(\cos bx\).

Parameters:

b (number or str) – Real, finite and positive.

Returns:

Mellin transform \(b^{-s}\Gamma(s)\cos(\pi s/2)\); Gamma orders \(L = R = 1\), scale \(b\).

Return type:

MellinFunction

Examples

>>> product_integral(exponential(1), cosine(10**6), dps=20)     # 1/(1 + 10^12)
mpf('9.99999999999e-13')
ramanujan_qft.mellin.sine(b)[source]#

The factor \(\sin bx\).

Parameters:

b (number or str) – Real, finite and positive.

Returns:

Mellin transform \(b^{-s}\Gamma(s)\sin(\pi s/2)\); Gamma orders \(L = R = 1\), scale \(b\).

Return type:

MellinFunction

Examples

>>> product_integral(exponential(1), sine(2))       # 2/5
mpf('0.40000000000000002')
ramanujan_qft.mellin.inverse_power(m, v)[source]#

The factor \((x + m)^{-v}\).

It carries both its Taylor expansion at \(x = 0\) and its expansion \(\sum_n \binom{-v}{n} m^n x^{-v-n}\) at large \(x\).

Parameters:
  • m (number or str) – Real, finite and positive.

  • v (number or str) – Real, finite and positive.

Returns:

Mellin transform \(m^{s-v}\Gamma(s)\Gamma(v-s)/\Gamma(v)\); Gamma orders \(L = R = 0\), scale \(1/m\).

Return type:

MellinFunction

Examples

>>> product_integral(exponential(1), inverse_power(1, 1))      # e E1(1)
mpf('0.59634736232319407')
ramanujan_qft.mellin.gaussian_bessel(a, b, nu)[source]#

The factor \(e^{-ax^2}J_\nu(bx)\).

Its Mellin transform is known in closed form,

\[M(s) = \frac{(b/2)^\nu\,\Gamma(h)}{2\,a^{h}\,\Gamma(\nu+1)}\, {}_1F_1\!\left(h;\nu+1;-\frac{b^2}{4a}\right), \qquad h = \frac{s+\nu}{2},\]

but it is not expanded itself (\(L\) is undefined), so it must be paired with a factor that can be expanded against \(R = 1/2\), such as an exponential. This handles three-factor products like \(e^{-2x}e^{-x^2/2}J_1(100x)\).

Parameters:
  • a (number or str) – Real, finite and positive.

  • b (number or str) – Real, finite and positive.

  • nu (number or str) – Real order \(\nu > -1\).

Return type:

MellinFunction

Examples

>>> product_integral(exponential(2), gaussian_bessel("0.5", 1, 1))
mpf('0.072735927988686319')

Classes#

class ramanujan_qft.mellin.MellinFunction(name: str, build: ~typing.Callable[[], ~ramanujan_qft.mellin._Built], L: float | None, R: float, p0: object, tail: tuple, params: dict = <factory>)[source]#

Bases: object

A factor \(f(x)\) on \((0, \infty)\), described by its Mellin data.

Instances are created by the atlas constructors (exponential(), gaussian(), bessel_j(), cosine(), sine(), inverse_power(), gaussian_bessel()) and passed to product_integral(). Calling an instance evaluates the function: exponential(1)(2) is \(e^{-2}\).

name#

Display name, used in messages.

Type:

str

build#

Returns the Mellin data (function, transform, expansions, scale) at the current working precision. Its return type is internal, so defining new factors outside the package is not yet a stable interface.

Type:

callable

L, R

Gamma orders: the Taylor coefficients decay like \(c^p/\Gamma(p)^L\) and the Mellin transform grows like \(\Gamma(w)^R/c^w\). L is None for a factor that cannot be expanded.

Type:

number or None

p0#

Leading exponent of \(f\) at \(x = 0\).

Type:

number or str

tail#

Behaviour at \(x \to \infty\): ("fast",) for faster than any power, or ("power", alpha, frequency, phase) for \(x^{-\alpha}\cos(\omega x + \phi)\).

Type:

tuple

params#

The parameters as given, kept exact.

Type:

dict

Examples

>>> f = bessel_j(0, 3)
>>> f.name, f.L, f.R
('J_0(3 x)', 1, 1)
>>> f(1)
mpf('-0.26005195490193345')
exception ramanujan_qft.mellin.SeriesConvergenceError[source]#

Bases: ArithmeticError

No valid residue expansion reaches the requested accuracy.

Raised by product_integral() at the convergence boundary \(\rho = 1\), or when a valid series needs more than max_terms terms or more than max_dps digits. A subclass of ArithmeticError.