maths.binomial_expansion ======================== .. py:module:: maths.binomial_expansion Functions --------- .. autoapisummary:: maths.binomial_expansion.binomial_expansion Module Contents --------------- .. py:function:: 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: https://en.wikipedia.org/wiki/Binomial_theorem 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