MeijerG.jl

MeijerG.jl computes the Meijer G-function

\[G_{p,q}^{m,n}\left(z\;\middle|\;\begin{matrix}a_1,\ldots,a_p \\ b_1,\ldots,b_q\end{matrix}\right)\]

using residue-based expansions through HypergeometricFunctions.jl and SpecialFunctions.jl.

Features

  • Supports Float64, BigFloat, and complex versions.
  • Supports both full-index and split-parameter calling conventions.
  • Includes a formatter macro to convert Julia meijerg() calls to plaintext, LaTeX and Wolfram Mathematica compatible forms.
  • Uses automatic reductions for common special cases and perturbation for confluent poles.
  • Three exported evaluation modes:
    • meijerg(...): Recommended polyalgorithm API with reductions, perturbation handling, and Slater fallback
    • meijerg_slater(...): Pure Slater residue evaluation without reductions or perturbation
    • meijerg_contour(...): Numerical contour-integral evaluation of the Mellin-Barnes definition

Quick usage

using MeijerG

x = 0.3
v = meijerg((), (), (0,), (), -x)  # Returns exp(x)
v-exp(x)
0.0
using MeijerG

y = 0.7
v = sqrt(pi) * meijerg((), (), (0.5,), (0,), y^2/4)
v-sin(y)
-1.1102230246251565e-16

We support two input modes, one aligning with the mathematical convention and one which aligns with how other software such as Wolfram Mathematica handles Meijer-G function input:

using MeijerG

# Split form: meijerg((), (), (0,), (), -x)
# Full form:  meijerg(a, b, m, n, z) with a=(), b=(0,), m=1, n=0
x = 0.3
v_split = meijerg((), (), (0,), (), -x)
v_full  = meijerg((), (0,), 1, 0, -x)
v_split - v_full
0.0

Real vs. complex inputs

Following Julia conventions like sqrt and HypergeometricFunctions.jl, this package does not auto-promote real inputs to complex branches.

using HypergeometricFunctions

try
  HypergeometricFunctions._₂F₁(1/2, 1/2, 1, 2.0)
catch err
  typeof(err)
end
DomainError
using MeijerG

try
  meijerg((), (1, 0), 2, 0, -1.0)
catch err
  typeof(err)
end
DomainError

Pass complex input explicitly when you want the complex branch:

using MeijerG

meijerg((), (1, 0), 2, 0, -1.0 + 0im)
-0.33625230062486183 + 1.811834419191979im
using MeijerG, ComplexPhasePortrait, ColorSchemes, Images

# Define periodic viridis colormap
function periodic_colormap(colors)
  base = [RGB(c.r, c.g, c.b) for c in colors]
  return vcat(base, base[end-1:-1:2])
end
viridis_colormap = periodic_colormap(ColorSchemes.viridis.colors)

# Evaluation grid and target function
xs = range(-5.0, 5.0; length=1000)
ys = range(-5.0, 5.0; length=1000)
Z  = [x + im*y for y in ys, x in xs]
f(z) = meijerg((1/2,1/2,-1/4,3.0), (0.0,1/2,5,-3/2), 2, 1, z)

# Generate image
img = Images.clamp01nan.(portrait(f.(Z), PTcgrid, colormap=viridis_colormap))

# Apply a simple disk mask
h, w = size(img)
cy, cx = (h + 1) / 2, (w + 1) / 2
r2 = (min(h, w) / 2)^2
disk_logo = [
  (x - cx)^2 + (y - cy)^2 <= r2 ? RGBA(img[y, x], 1) : RGBA(1, 1, 1, 0)
  for y in 1:h, x in 1:w
]

# Save an deploy logo
save("assets/logo.png", disk_logo);
┌ Warning: Runtime invalidation was disabled, but the CPU info is out-of-date.
│ Will continue with incorrect CPU name (from build time).
└ @ HostCPUFeatures ~/.julia/packages/HostCPUFeatures/ZTXz4/src/cpu_info.jl:71