An interactive web application and Python computation engine for computing statistical moments of probability distributions.
Compute raw moments, central moments, variance, skewness, kurtosis, and more for both discrete and continuous random variables — with rigorous numerical methods, convergence acceleration, and real-time validation.
🚀 Try it now — no installation needed
📖 Read the documentation
| Feature | Details |
|---|---|
| Discrete RVs | Finite and infinite support, with 5-method convergence cascade |
| Continuous RVs | Domain-aware quadrature: Gauss-Laguerre, Gauss-Hermite, tanh-sinh |
| Exact results | SymPy symbolic integration for distributions without conditionals |
| High precision | mpmath arbitrary-precision mode above 12 decimal places |
| Parallel computation | All moment orders computed concurrently via ThreadPoolExecutor |
| Smart input | Auto-corrects ^, ` |
| Live validation | PMF sum and PDF integral checked before any moment is computed |
| 5 result tabs | Moments · Statistics · Distribution plot · Table (CSV) · Convergence |
Visit toful1.streamlit.app — no installation needed.
git clone https://github.com/pranava-ba/ToFUL.git
cd ToFUL
pip install -r requirements.txt
streamlit run app.pyAll three files — app.py, core.py, and toful_parser.py — must be in the same directory.
python -c "
import core, toful_parser, numpy as np
x, _, _ = core.parse_range_input('0,1,2,3,...')
vr = core.validate_drv_probabilities(
'0.3*(0.7**x) if x>=0 else 0', x[:200], True
)
print('Valid:', vr.is_valid, '| Sum:', round(vr.integral_or_sum, 6))
"
# Valid: True | Sum: 1.0| Field | Value |
|---|---|
| Variable type | Discrete (DRV) |
| Range | 0,1,2,3,... |
| PMF | 0.3 * (0.7 ** x) if x >= 0 else 0 |
| Moment reference | Origin (a = 0) |
| Max order | 4 |
Expected output:
| Moment | Value | Method |
|---|---|---|
| μ₁ | 2.333333 | term-magnitude |
| μ₂ | 13.222222 | term-magnitude |
| μ₃ | 111.222222 | term-magnitude |
| μ₄ | 1247.296296 | term-magnitude |
| Field | Value |
|---|---|
| Variable type | Continuous (CRV) |
| Lower bound | 0 |
| Upper bound | inf |
2 * exp(-2*x) if x >= 0 else 0 |
Expected output:
| Moment | Value | Method |
|---|---|---|
| μ₁ | 0.500000 | gauss-laguerre+quad |
| μ₂ | 0.500000 | gauss-laguerre+quad |
| μ₃ | 0.750000 | gauss-laguerre+quad |
| μ₄ | 1.500000 | gauss-laguerre+quad |
| Field | Value |
|---|---|
exp(-(x**2)/2) / sqrt(2*pi) |
|
| Bounds | -inf to inf |
Expected output:
| Moment | Value | Method |
|---|---|---|
| μ₁ | 0.000000 | sympy-exact |
| μ₂ | 1.000000 | sympy-exact |
| μ₃ | 0.000000 | sympy-exact |
| μ₄ | 3.000000 | sympy-exact |
The expression field accepts natural mathematical notation. Common auto-corrections applied by the parser:
| You type | Interpreted as |
|---|---|
0.3 * 0.7^x |
0.3 * 0.7**x |
e^(-2*x) |
exp(-2*x) |
2x |
2*x |
|x| |
abs(x) |
ln(x) |
log(x) |
√(x) |
sqrt(x) |
x ≤ 1 |
x <= 1 |
λ |
lam |
See the Input Syntax Guide for the complete reference.
ToFUL/
├── app.py Streamlit frontend (UI, layout, plots)
├── core.py Computation engine (moments, validation, convergence)
├── toful_parser.py Input normalisation pipeline (two-pass)
├── requirements.txt Runtime dependencies
└── docs/ Sphinx documentation source
├── conf.py
├── index.rst
├── getting-started/
├── user-guide/
├── examples/
├── theory/
├── api-reference/
└── troubleshooting/
- Term magnitude — last 10 terms all below tolerance
- Wynn ε-algorithm — recursive epsilon-table extrapolation
- Aitken Δ² — three-point partial-sum extrapolation
- Cohen-Villegas-Zagier — optimal for alternating series
- Geometric ratio bound — tail estimate from asymptotic ratio
| Domain | Method |
|---|---|
[0, ∞) |
Gauss-Laguerre quadrature (64 nodes) + quad cross-check |
(-∞, ∞) |
Gauss-Hermite quadrature (64 nodes) + quad cross-check |
Finite [a, b] |
SciPy adaptive Gauss-Kronrod |
| Any, precision > 12dp | mpmath tanh-sinh (arbitrary precision) |
| No conditionals | SymPy symbolic integration (exact) |
| Package | Purpose |
|---|---|
streamlit |
Web UI framework |
numpy |
Array operations, vectorised evaluation |
scipy |
Adaptive quadrature, Gauss nodes, special functions |
sympy |
Symbolic integration (optional but recommended) |
mpmath |
Arbitrary-precision arithmetic (optional) |
plotly |
Interactive distribution and moment plots |
pandas |
Results table and CSV export |
Full documentation is hosted on ReadTheDocs: toful-rtd.readthedocs.io
To build locally:
cd docs
pip install sphinx sphinx-rtd-theme
make html
# open docs/_build/html/index.htmlContributions are welcome. See CONTRIBUTING for the development setup, code style guide, and pull request process.
When reporting a numerical bug, include the exact Range and PMF/PDF strings, the moment order, and the analytical expected value.
MIT License — see LICENSE for details.
Built with Streamlit · NumPy · SciPy · SymPy · mpmath · Plotly