Expand
Details and Options
- Expand works only on positive integer powers.
- Expand applies only to the top level in expr.
- Expand[expr,Modulus->p] expands expr reducing the result modulo p. »
- Expand automatically threads over lists in expr, as well as equations, inequalities and logic functions.
- Expand takes the following options:
-
Modulus 0 modulus to assume for integers Trig False whether to do trigonometric as well as algebraic transformations
Examples
open all close allBasic Examples (3)
Scope (16)
Basic Uses (9)
Expand[(x + y) ^ 2(x - y) ^ 2]Expand[(x + y) ^ 2 / (x - y) ^ 2]Expand expressions involving trig functions:
Expand[(Sin[x] + Cos[x]) ^ 2]Expand expressions involving transcendental functions:
Expand[(x ^ s + 2E ^ -x) ^ 3]Expand expressions involving arbitrary functions:
Expand[(f[Subscript[x, 1]] + f[Subscript[x, 2]]) ^ 3]Expand does not go into subexpressions:
Expand[Sqrt[(1 + x) ^ 2]]In contrast, ExpandAll does:
ExpandAll[Sqrt[(1 + x) ^ 2]]Expand applies to the numerator only:
Expand[(x + y) ^ 2 / (z + y) ^ 2]ExpandAll applies to both the numerator and denominator:
ExpandAll[(x + y) ^ 2 / (z + y) ^ 2]Verify the equality of an expanded polynomial and its factored form:
1 + 5 x + 10 x^2 + 10 x^3 + 5 x^4 + x^5 == Expand[(x + 1) ^ 5]Expand accepts polynomials with real or complex coefficients as inputs:
Expand[(x + I)(x - I)]Expand threads over lists:
Expand[Table[(x + 1) ^ n, {n, 3}]]Expand threads over equations and inequalities:
Expand[1 < (x + y) ^ 2 < 2]Advanced Uses (7)
Apply Expand to a polynomial over the integers modulo
:
Expand[(2y + 3x) ^ 6, Modulus -> 4]Expand a polynomial over a finite field:
ℱ = FiniteField[17, 3];Expand[(ℱ[123]x - ℱ[345])(ℱ[567]x - ℱ[789])]Apply Expand to a trigonometric expression:
Expand[(Sin[2x] + x) ^ 2, Trig -> True]Polynomials with high-order powers are expanded efficiently:
Expand[(x + y + z) ^ 1000]//LengthLeave parts free of x unexpanded:
Expand[(a + b) ^ 2(1 + x) ^ 2, x]Leave parts free of 1+x unexpanded:
Expand[(1 + x) ^ 2 + (2 + x) ^ 2, 1 + x]Leave anything not matching x[_] unexpanded:
Expand[(a[1] + a[2])(x[1] + x[2]) ^ 2, x[_]]Options (3)
Applications (3)
Calculate the characteristic polynomial of a diagonal matrix:
(matrix = DiagonalMatrix[{1, -1, 1, -1}])//MatrixFormThe characteristic polynomial is the determinant of the following matrix:
matrix - x * IdentityMatrix[4]//MatrixFormExpand the product of diagonal elements to get the characteristic polynomial:
Expand[(1 - x)(-1 - x)(1 - x)(-1 - x)]This can be directly computed using the CharacteristicPolynomial function:
CharacteristicPolynomial[matrix , x]Cyclotomic polynomials are monic, with integer coefficients, and are irreducible over the rational numbers.
cyclo[n_] := Times@@Table[If[GCD[k, n] == 1, (x - (-1) ^ (2k / n)), 1], {k, 1, n}]The 16th cyclotomic polynomial is given below:
cyclo[16]Use Expand to show that it has integer coefficients:
Expand[%]These polynomials can be directly computed using the Cyclotomic function:
Cyclotomic[16, x]Expand can be used to verify that two expressions are equal:
Cos[3x] == 4Cos[x] ^ 3 - 3Cos[x]Expand[%, Trig -> True]Properties & Relations (4)
Many functions give results in unexpanded form:
prod = Product[x + i, {i, 6}]Apply Expand:
Expand[prod]Apply Expand to a polynomial:
Expand[(1 + x + y)(2 - x) ^ 3]Factor is essentially the inverse of Expand:
Factor[%]When no powers are involved, Distribute gives the same results as Expand:
Distribute[(1 + x)(2 + x)(3 + x)] === Expand[(1 + x)(2 + x)(3 + x)]Direct application of the distributive law often generates far more terms than are needed:
Distribute[Factor[x ^ 6 - 1], Plus, Times, List, Times]Total[%]Use NonCommutativeExpand to expand noncommutative polynomials:
NonCommutativeExpand[(a + 2b)**(3a + 4b)]Specify names for addition and multiplication operations:
alg = NonCommutativeAlgebra[<|"Multiplication" -> mult, "Addition" -> add|>];NonCommutativeExpand[mult[add[a, 2b], add[3a, 4b]], alg]Neat Examples (3)
Stylize a binomial expansion involving two emojis:
Style[Expand[(☺ + ☹) ^ 5], 20]Expand a binomial raised to a large power:
Expand[(1 + x) ^ 100]Create a nested pattern corresponding to an additive cellular automaton (rule 60):
Column[Table[CoefficientList[Expand[(1 + x) ^ t, Modulus -> 2], x], {t, 0, 31}]]Related Links
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0) ▪ 2007 (6.0) ▪ 2023 (13.3)
Text
Wolfram Research (1988), Expand, Wolfram Language function, https://reference.wolfram.com/language/ref/Expand.html (updated 2023).
CMS
Wolfram Language. 1988. "Expand." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/Expand.html.
APA
Wolfram Language. (1988). Expand. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Expand.html
BibTeX
@misc{reference.wolfram_2026_expand, author="Wolfram Research", title="{Expand}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/Expand.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_expand, organization={Wolfram Research}, title={Expand}, year={2023}, url={https://reference.wolfram.com/language/ref/Expand.html}, note=[Accessed: 12-June-2026]}