EXPAND
This function expands symbolic expressions by distributing products and expanding powers into sums of terms.
A typical expansion follows distributive algebra, for example:
(a+b)^2 = a^2 + 2ab + b^2
The result is returned as an expanded symbolic expression string.
Excel Usage
=EXPAND(expression)
expression(str, required): Expression to expand.
Returns (str): String representation of the expanded expression.
Example 1: Expand a squared binomial
Inputs:
| expression |
|---|
| (x + 1)**2 |
Excel formula:
=EXPAND("(x + 1)**2")
Expected output:
"x**2 + 2*x + 1"
Example 2: Expand product of two binomials
Inputs:
| expression |
|---|
| (x + 2)*(x - 3) |
Excel formula:
=EXPAND("(x + 2)*(x - 3)")
Expected output:
"x**2 - x - 6"
Example 3: Expand a cubic binomial expression
Inputs:
| expression |
|---|
| (x - y)**3 |
Excel formula:
=EXPAND("(x - y)**3")
Expected output:
"x**3 - 3*x**2*y + 3*x*y**2 - y**3"
Example 4: Expand mixed symbolic terms
Inputs:
| expression |
|---|
| (a + b)*(c + d) |
Excel formula:
=EXPAND("(a + b)*(c + d)")
Expected output:
"a*c + a*d + b*c + b*d"
Python Code
from sympy import sympify
from sympy import expand as sympy_expand
def expand(expression):
"""
Expand products and powers in a symbolic expression.
See: https://docs.sympy.org/latest/modules/core.html#sympy.core.function.expand
This example function is provided as-is without any representation of accuracy.
Args:
expression (str): Expression to expand.
Returns:
str: String representation of the expanded expression.
"""
try:
normalized_expression = expression.replace("^", "**")
expr = sympify(normalized_expression)
result = sympy_expand(expr)
return str(result)
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Expression to expand.