maths.binomial_expansion¶
Functions¶
|
Compute the value of (a + b)^n using the Binomial Theorem. |
Module Contents¶
- maths.binomial_expansion.binomial_expansion(a: float, b: float, n: int) int | float¶
Compute the value of (a + b)^n using the Binomial Theorem.
This function works for both positive and negative integer exponents. It raises a ZeroDivisionError if the base (a + b) is 0 and n is negative.
- Args:
a: First term (int or float). b: Second term (int or float). n: Exponent (must be integer).
- Returns:
The result of the binomial expansion (a + b)^n.
- Raises:
ZeroDivisionError: If a + b == 0 and n < 0.
- See Also:
- Examples:
>>> binomial_expansion(2, 3, 2) 25 >>> binomial_expansion(100, -4, 3) 884736 >>> binomial_expansion(2, 2, -2) 0.0625 >>> binomial_expansion(0, 0, 3) 0 >>> binomial_expansion(-2, 2, -1) Traceback (most recent call last): ... ZeroDivisionError: Cannot raise 0 to the negative power