.. _troubleshooting-common: Common Errors ============= This page lists the most frequent error messages in ToFUL, explains what causes each one, and gives concrete fixes. .. contents:: On this page :local: :depth: 2 ---- Validation Errors ----------------- "PMF sums to X ≠ 1.0" ~~~~~~~~~~~~~~~~~~~~~~~ **What it means:** ToFUL evaluated your probability mass function over the given support and the total came out to a value other than 1. **Common causes and fixes:** *Wrong parameter value* .. code-block:: python # Bug — probabilities sum to 0.7, not 1.0 0.3 * (0.4 ** x) if x >= 0 else 0 # Fix — use the correct base: q = 1 - p 0.3 * (0.7 ** x) if x >= 0 else 0 *Forgotten normalising constant* .. code-block:: python # Bug — unnormalised Poisson (3 ** x) / factorial(x) if x >= 0 else 0 # Fix — include exp(-lambda) (exp(-3) * 3**x) / factorial(x) if x >= 0 else 0 *PMF defined only on a subset of the given range* If your range is ``1,2,3,4,5`` but the PMF returns 0 for some values, ensure probabilities over the non-zero values still sum to 1. *Finite range too narrow for an infinite-support distribution* If you entered a finite range like ``0,1,2,3,4,5`` for a Geometric distribution, only the probability in that window is summed — the tail is excluded. Use the infinite notation ``0,1,2,3,...`` instead. ---- "Negative probabilities detected at x = [...]" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **What it means:** The PMF returned a negative value at one or more support points. **Common causes:** * Sign error in the formula — check for an extra minus sign. * Condition in the ``if`` guard is inverted, causing the negative branch to fire when the positive one was intended. .. code-block:: python # Bug — returns negative for x > 0 -0.3 * (0.7 ** x) if x >= 0 else 0 # Fix 0.3 * (0.7 ** x) if x >= 0 else 0 ---- "PDF integrates to X ≠ 1.0" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **What it means:** Numerical integration of your PDF over the given bounds did not return 1.0 within the precision tolerance. **Common causes and fixes:** *Wrong bounds* .. code-block:: text # Bug — Exponential(2) integrated only to 5, missing most of the tail Lower: 0 Upper: 5 # Fix Lower: 0 Upper: inf *Missing guard* .. code-block:: python # Bug — evaluates e^x for x > 0, which grows without bound PDF: exp(-x) # Fix — restrict to the correct support PDF: exp(-x) if x >= 0 else 0 *Wrong normalising constant* Use the validation step to read off the actual integral, then divide your PDF by that value and recompute. ---- "Negative PDF value at x ≈ [...]" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ToFUL spot-checks 100 test points before integrating. If any evaluate negative, validation stops immediately. Ensure the PDF is non-negative everywhere on the support. If you are modelling a signed function for other purposes, ToFUL is not the right tool for that calculation. ---- Syntax Errors -------------- "Syntax error: invalid syntax (position N)" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The expression could not be parsed as valid Python after auto-correction. **Most common causes:** +------------------------+---------------------------------------------+ | What was typed | Fix | +========================+=============================================+ | ``x^2`` | Not an error — auto-corrected to ``x**2`` | +------------------------+---------------------------------------------+ | ``2^x`` | Not an error — auto-corrected to ``2**x`` | +------------------------+---------------------------------------------+ | ``f(x) = exp(-x)`` | Remove ``f(x) =`` — enter only the RHS | +------------------------+---------------------------------------------+ | ``exp[-x]`` | Use round brackets: ``exp(-x)`` | +------------------------+---------------------------------------------+ | ``P(X=x) = 0.5`` | Enter just the value: ``0.5`` | +------------------------+---------------------------------------------+ | ``x >= 0 and <= 1`` | Write: ``0 <= x <= 1`` | +------------------------+---------------------------------------------+ | ``lambda * exp(-x)`` | ``lambda`` is a Python keyword; use ``lam`` | +------------------------+---------------------------------------------+ *Unmatched brackets* Count opening and closing brackets. Each ``(`` must have a matching ``)`` and vice versa. .. code-block:: python # Bug — unmatched bracket exp(-2*x if x >= 0 else 0 # Fix exp(-2*x) if x >= 0 else 0 ---- Range Errors ------------ "Cannot parse range '...'" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The range string could not be converted to a list of numbers. **Common causes:** * Spaces without commas: ``1 2 3`` → use ``1,2,3`` * Non-numeric characters: ``x=0,1,2`` → use ``0,1,2`` * Decimal comma instead of decimal point (locale issue): ``1,5`` as "one point five" → use ``1.5`` "Lower bound must be strictly less than upper bound" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The lower and upper bounds you entered are equal or in the wrong order. Enter the smaller value as Lower and the larger as Upper. ---- Computation Errors ------------------ "Computation error: OverflowError" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A value exceeded the float64 range (approximately :math:`1.8 \times 10^{308}`). This typically happens when computing high-order moments of heavy-tailed distributions, or when a PMF formula produces very large intermediate values. **Fixes:** * Reduce the maximum moment order. * Use the ``gamma`` function instead of ``factorial`` for large arguments. * Reformulate the expression to avoid intermediate large numbers: .. code-block:: python # Bug — computes 100! internally, overflows factorial(100) / (factorial(x) * factorial(100-x)) # Fix — use log-space or gamma exp(log(gamma(101)) - log(gamma(x+1)) - log(gamma(101-x))) "Computation error: ZeroDivisionError" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Division by zero in the PMF or PDF expression. Check for a denominator that can be zero at any support point: .. code-block:: python # Bug — divides by x, which is 0 for the first support value 1 / x if x > 0 else 0.5 # Fix — guard the denominator 1 / x if x > 0 else 0 ---- Precision-Related Issues ------------------------- "Results appear as 0.0000 for all moments" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The moments are too small to show at the default display precision of 4. Increase **Display precision** to 8 or more to see the significant digits. "Convergence uncertain after N terms" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The series did not converge within the computed terms. See :doc:`convergence-issues` for a systematic approach. See also -------- * :doc:`debugging-functions` — step-by-step function debugging * :doc:`convergence-issues` — convergence-specific problems * :doc:`/getting-started/input-syntax` — complete syntax reference