Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bose-Fermi Integral Evaluator for SymPy

This package provides functionality to automatically recognize and evaluate a class of definite integrals frequently encountered in statistical physics, especially in the context of Bose-Einstein and Fermi-Dirac statistics. (Will probably be useful to about two people on the planet.)

These integrals have the general form:

$$ \int_0^\infty \frac{x^p}{e^{\alpha x + \mu} \pm 1} \mathrm{d}x $$

where:

  • $p$ is the power of the integration variable $x$,
  • $\alpha > 0$ is a scaling factor (inverse temperature),
  • $\mu$ is the chemical potential,
  • the $-$ sign corresponds to bosons (Bose-Einstein),
  • the $+$ sign corresponds to fermions (Fermi-Dirac).

The module recognizes such integrals symbolically and returns an exact result using known special functions (gamma, polylog, etc.), whenever possible.

--

Example

If we try to evaluate the following integral in Sympy, we won't get very far:

$$I := \int_0^\infty\frac{x^3}{e^x - 1}\mathrm{d}x$$

In [1]: from sympy import symbols, Integral, exp, oo
   ...: x = symbols('x')
   ...: I = Integral(x**3 / (exp(x) - 1), (x, 0, oo))
   ...: I.doit()
Out[1]: Integral(x**3/(exp(x) - 1), (x, 0, oo))

This is where our Bose-Fermi Integral Evaluator comes into play:

In [2]: from bosefermi import bose_fermi_integral
   ...: bose_fermi_integral(I)
Out[2]: pi**4/15

Result:

$$I = \frac{\pi^4}{15}$$

Performance

%%timeit
bose_fermi_integral(I)

1.37 ms ± 30.2 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

Physical Interpretation

This integral corresponds, up to a Gamma prefactor, to the standard Bose-Einstein or Fermi-Dirac integral defined in physics:

$$ B_k(\mu) = \frac{1}{\Gamma(k+1)} \int_0^\infty \frac{x^k}{e^{x + \mu} - 1} \mathrm{d}x \quad \text{(bosons)} $$

or

$$ F_k(\mu) = \frac{1}{\Gamma(k+1)} \int_0^\infty \frac{x^k}{e^{x + \mu} + 1} \mathrm{d}x \quad \text{(fermions)} $$


Supported Integrals

The following symbolic forms are supported:

Integral Result
$\int_0^\infty \frac{x^p}{e^x - 1} dx$ $\Gamma(p+1)\cdot\zeta(p+1)$
$\int_0^\infty \frac{x^p}{e^{\alpha x} - 1} dx$ $\Gamma(p+1)\cdot\zeta(p+1)/\alpha^{p+1}$
$\int_0^\infty \frac{x^p}{e^{x + \mu} - 1} dx$ $\Gamma(p+1)\cdot\mathrm{Li}_{p+1}(e^{-\mu})$
$\int_0^\infty \frac{x^p}{e^{\alpha x + \mu} - 1} dx$ $\Gamma(p+1)\cdot\mathrm{Li}_{p+1}(e^{-\mu})/\alpha^{p+1}$
$\int_0^\infty \frac{x^p}{e^x + 1} dx$ $\Gamma(p+1)\cdot\eta(p+1)$
$\int_0^\infty \frac{x^p}{e^{\alpha x} + 1} dx$ $\Gamma(p+1)\cdot\eta(p+1)/\alpha^{p+1}$
...

Installation

# For now, clone and use directly:
git clone https://github.com/klimanek/Bose-Fermi.git
cd Bose-Fermi
pip install -e .

Contributing & Integration

This package is designed for eventual integration into SymPy. Contributions are warmly welcome!

How to contribute:

  • Bug reports: Found an integral that should work but doesn't? Please report it!
  • New patterns: Know of related integrals from physics/mathematics? Let's add them!
  • Performance improvements: Optimizations in pattern matching are always appreciated.
  • SymPy integration: Help with integrating this into the main SymPy codebase.

Future SymPy integration:

We're actively working on integrating this functionality into SymPy's main integration engine. The goal is to make these evaluations available automatically when you call .doit() on supported integrals.

About

Bose-Fermi Integral Evaluator for SymPy

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages