Maxima distrib核心库cdf_binomial函数疑似Bug问题求助
Solution to Maxima cdf_binomial Substitution & Integration Error
Root Cause
The cdf_binomial(S, n, p) function in Maxima's distrib library uses the incomplete beta function beta_incomplete in its general formula. When S = n (e.g., S=4, n=4), this formula produces beta_incomplete(0, 5, 1-p)—an undefined expression. Direct substitution doesn't trigger the function's built-in edge case checks, but calling cdf_binomial(4,4,p) directly works because the function explicitly returns 1 when S equals n.
Fixes for Substitution Issues
- Direct Call (Simplest): Instead of substituting into the general form, call
cdf_binomialwith the specific value:cdf_binomial(4,4,p); /* Returns 1 without errors */ - Custom Piecewise Function: If you need to work with symbolic S, define a wrapper that handles edge cases:
Now substituting S=4 will work correctly:my_binom_cdf(S, n, p) := if S >= n then 1 else if S < 0 then 0 else cdf_binomial(S, n, p);subst([S=4], my_binom_cdf(S,4,p)); /* Returns 1 */
Fixes for Integration Issues
If you need to integrate the CDF over p up to 1:
- Explicit Edge Case Handling: When S=4, the integrand is 1, so the integral from
ato 1 is1 - a. For S < 4, use the standard integral ofcdf_binomial(S,4,p). - Use the Custom Piecewise Function: Integrate the wrapped function to automatically handle all cases:
This returns 1 when S >=4, and computes the correct integral for S <4.integrate(my_binom_cdf(S,4,p), p, 0, 1); - Symbolic Piecewise Definition: For fully symbolic work, use Maxima's
piecewisefunction:
Integrals or substitutions with this function will resolve correctly for all S values.symbolic_binom_cdf(S, n, p) := piecewise( [S >= n, 1], [S < 0, 0], [true, cdf_binomial(S, n, p)] );
内容的提问来源于stack exchange,提问作者ivo Welch
相关产品推荐
相关产品推荐

