Mode of #cas
expand
Multiplies out a polynomial, with a theorem that the expansion equals the input for all real values.
#cas [expand] eexpand multiplies an expression out so you can see its terms and their coefficients. The theorem is an identity for all real values of the variables, proved by Mathlib’s tactic ring, so it holds with no conditions at all.
It also knows the classical families of polynomials. Ask for ChebyshevT 5 x and the theorem is about Mathlib’s own Chebyshev polynomial Polynomial.Chebyshev.T, which is the one you want when the expansion goes into a proof.
Examples (13)#
Basic Examples (3)
A product in two variables:
#cas [expand] ((x + 1)^3 * (y - 2))
x^3*y - 2*x^3 + 3*x^2*y - 6*x^2 + 3*x*y - 6*x + y - 2Checked by Lean’s kernel: Identity with the expanded polynomial
∀ (x y : ℝ), (x + 1) ^ 3 * (y - 2) = x ^ 3 * y - 2 * x ^ 3 + 3 * x ^ 2 * y - 6 * x ^ 2 + 3 * x * y - 6 * x + y - 2
The certificate: 1 checked step
Identity with the expanded polynomial
∀ (x y : ℝ), (x + 1) ^ 3 * (y - 2) = x ^ 3 * y - 2 * x ^ 3 + 3 * x ^ 2 * y - 6 * x ^ 2 + 3 * x * y - 6 * x + y - 2
The computation
Ranked candidates (proposals, not proof)
expanded polynomial: x^3*y - 2*x^3 + 3*x^2*y - 6*x^2 + 3*x*y - 6*x + y - 2 [leafCount 39, conditions 0] input: (x + 1)^3*(y - 2) [leafCount 9, conditions 0]
The binomial theorem for :
#cas [expand] ((a + b)^4)
a^4 + 4*a^3*b + 6*a^2*b^2 + 4*a*b^3 + b^4Checked by Lean’s kernel: Identity with the expanded polynomial
∀ (a b : ℝ), (a + b) ^ 4 = a ^ 4 + 4 * a ^ 3 * b + 6 * a ^ 2 * b ^ 2 + 4 * a * b ^ 3 + b ^ 4
The certificate: 1 checked step
Identity with the expanded polynomial
∀ (a b : ℝ), (a + b) ^ 4 = a ^ 4 + 4 * a ^ 3 * b + 6 * a ^ 2 * b ^ 2 + 4 * a * b ^ 3 + b ^ 4
The computation
Ranked candidates (proposals, not proof)
expanded polynomial: a^4 + 4*a^3*b + 6*a^2*b^2 + 4*a*b^3 + b^4 [leafCount 33, conditions 0] input: (a + b)^4 [leafCount 5, conditions 0]
Rational coefficients stay exact:
#cas [expand] ((x - 1/2)^2 * (x + 2))
x^3 + x^2 - 7/4*x + 1/2Checked by Lean’s kernel: Identity with the expanded polynomial
∀ (x : ℝ), (x - 1 / 2) ^ 2 * (x + 2) = x ^ 3 + x ^ 2 - 7 / 4 * x + 1 / 2
The certificate: 1 checked step
Identity with the expanded polynomial
∀ (x : ℝ), (x - 1 / 2) ^ 2 * (x + 2) = x ^ 3 + x ^ 2 - 7 / 4 * x + 1 / 2
The computation
Ranked candidates (proposals, not proof)
expanded polynomial: x^3 + x^2 - 7/4*x + 1/2 [leafCount 17, conditions 0] input: (x - 1/2)^2*(x + 2) [leafCount 11, conditions 0]
Scope (4)
The Chebyshev polynomial . The theorem holds in every commutative ring:
#cas [expand] (ChebyshevT 5 x)
polynomial with integer coefficients
16*x^5 - 20*x^3 + 5*x- Domain
Polynomial.Chebyshev.T R 5, every commutative ring R : Type- Input (polynomial in x)
ChebyshevT 5 x
Checked by Lean’s kernel: Monomial expansion of ChebyshevT 5
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.T R 5 = 16 * Polynomial.X ^ 5 - 20 * Polynomial.X ^ 3 + 5 * Polynomial.X
The certificate: 1 checked step
Monomial expansion of ChebyshevT 5
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.T R 5 = 16 * Polynomial.X ^ 5 - 20 * Polynomial.X ^ 3 + 5 * Polynomial.X
The Legendre polynomial , with rational coefficients:
#cas [expand] (LegendreP 5 x)
polynomial with exact rational coefficients
63/8*x^5 - 35/4*x^3 + 15/8*x- Input (polynomial in x)
LegendreP 5 x
Checked by Lean’s kernel: Monomial expansion of the Legendre polynomial
∀ (x : ℝ), Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 5) = 63 / 8 * x ^ 5 - 35 / 4 * x ^ 3 + 15 / 8 * x
from CAS.Analysis.SpecialFunctions.legendre_eval_eq_sum_coeff
The certificate: 1 checked step
Monomial expansion of the Legendre polynomial
∀ (x : ℝ), Polynomial.eval x (CAS.Analysis.SpecialFunctions.legendre 5) = 63 / 8 * x ^ 5 - 35 / 4 * x ^ 3 + 15 / 8 * x
The computation
Checked coefficients
Coefficients of x^0, …, x^5: [0, 15/8, 0, -35/4, 0, 63/8] Guarantee: the displayed polynomial equals P_5 at every real x
The Hermite polynomials, in the physicists’ and the probabilists’ normalization:
#cas [expand] (HermiteH 5 x)
polynomial with integer coefficients
32*x^5 - 160*x^3 + 120*x- Domain
√2 ^ 5 Polynomial.hermite 5 (√2 x) (physicists'), x ∈ ℝ- Input (polynomial in x)
HermiteH 5 x
Checked by Lean’s kernel: Monomial expansion of HermiteH 5
∀ (x : ℝ), √2 ^ 5 * (Polynomial.aeval (√2 * x)) (Polynomial.hermite 5) = 32 * x ^ 5 - 160 * x ^ 3 + 120 * x
The certificate: 1 checked step
Monomial expansion of HermiteH 5
∀ (x : ℝ), √2 ^ 5 * (Polynomial.aeval (√2 * x)) (Polynomial.hermite 5) = 32 * x ^ 5 - 160 * x ^ 3 + 120 * x
#cas [expand] (HermiteHe 3 x)
polynomial with integer coefficients
x^3 - 3*x- Domain
Polynomial.hermite 3 (probabilists'), ℤ[X]- Input (polynomial in x)
HermiteHe 3 x
Checked by Lean’s kernel: Monomial expansion of HermiteHe 3
Polynomial.hermite 3 = Polynomial.X ^ 3 - 3 * Polynomial.X
The certificate: 1 checked step
Monomial expansion of HermiteHe 3
Polynomial.hermite 3 = Polynomial.X ^ 3 - 3 * Polynomial.X
A Chebyshev polynomial of the second kind and a Bernoulli polynomial:
#cas [expand] (ChebyshevU 2 x)
polynomial with integer coefficients
4*x^2 - 1- Domain
Polynomial.Chebyshev.U R 2, every commutative ring R : Type- Input (polynomial in x)
ChebyshevU 2 x
Checked by Lean’s kernel: Monomial expansion of ChebyshevU 2
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.U R 2 = 4 * Polynomial.X ^ 2 - 1
The certificate: 1 checked step
Monomial expansion of ChebyshevU 2
∀ (R : Type) [inst : CommRing R], Polynomial.Chebyshev.U R 2 = 4 * Polynomial.X ^ 2 - 1
#cas [expand] (BernoulliB 2 y)
polynomial with exact rational coefficients
y^2 - y + 1/6- Domain
Polynomial.bernoulli 2, y ∈ ℝ- Input (polynomial in y)
BernoulliB 2 y
Checked by Lean’s kernel: Monomial expansion of BernoulliB 2
∀ (y : ℝ), (Polynomial.aeval y) (Polynomial.bernoulli 2) = y ^ 2 - y + 1 / 6
The certificate: 1 checked step
Monomial expansion of BernoulliB 2
∀ (y : ℝ), (Polynomial.aeval y) (Polynomial.bernoulli 2) = y ^ 2 - y + 1 / 6
Applications (1)
The first expansion as a theorem. It holds for all real x and y, and only the three standard axioms are used:
theorem cube_times_linear (x y : ℝ) : (x + 1) ^ 3 * (y - 2) = x ^ 3 * y - 2 * x ^ 3 + 3 * x ^ 2 * y - 6 * x ^ 2 + 3 * x * y - 6 * x + y - 2 := by cas #print axioms cube_times_linear
cube_times_linear depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (2)
factor goes the other way:
#cas [factor] (2*x^3 - 3*x^2 + 1)
(x - 1)^2*(2*x + 1)Checked by Lean’s kernel: Identity with the factored polynomial
∀ (x : ℝ), 2 * x ^ 3 - 3 * x ^ 2 + 1 = (x - 1) ^ 2 * (2 * x + 1)
The certificate: 1 checked step
Identity with the factored polynomial
∀ (x : ℝ), 2 * x ^ 3 - 3 * x ^ 2 + 1 = (x - 1) ^ 2 * (2 * x + 1)
The computation
Ranked candidates (proposals, not proof)
factored polynomial: (x - 1)^2*(2*x + 1) [leafCount 11, conditions 0] input: 2*x^3 - 3*x^2 + 1 [leafCount 13, conditions 0]
collect groups the terms by the powers of one variable, with the other variables in the coefficients:
#cas [collect x] ((1 + a*x)^2 + b*x)
polynomial in x
a^2*x^2 + (2*a + b)*x + 1- Input (polynomial)
((1 + a*x)^2 + b*x)
Checked by Lean’s kernel: Identity with the collected form
∀ (x a b : ℝ), (1 + a * x) ^ 2 + b * x = a ^ 2 * x ^ 2 + (2 * a + b) * x + 1
The certificate: 1 checked step
Identity with the collected form
∀ (x a b : ℝ), (1 + a * x) ^ 2 + b * x = a ^ 2 * x ^ 2 + (2 * a + b) * x + 1
Possible Issues (3)
The argument of a function is not expanded:
#cas [expand] (sin (x + y))
sin(x + y)Checked by Lean’s kernel: Identity with the input
∀ (x y : ℝ), Real.sin (x + y) = Real.sin (x + y)The certificate: 1 checked step
Identity with the input
∀ (x y : ℝ), Real.sin (x + y) = Real.sin (x + y)
The computation
Ranked candidates (proposals, not proof)
input: sin(x + y) [leafCount 4, conditions 0]
trigExpand expands sines and cosines of sums:
#cas [trigExpand] (sin (x + y))
sin(x)*cos(y) + cos(x)*sin(y)Checked by Lean’s kernel: Identity with the trigonometric expansion
∀ (x y : ℝ), Real.sin (x + y) = Real.sin x * Real.cos y + Real.cos x * Real.sin yThe certificate: 1 checked step
Identity with the trigonometric expansion
∀ (x y : ℝ), Real.sin (x + y) = Real.sin x * Real.cos y + Real.cos x * Real.sin y
The computation
Ranked candidates (proposals, not proof)
trigonometric expansion: sin(x)*cos(y) + cos(x)*sin(y) [leafCount 11, conditions 0] input: sin(x + y) [leafCount 4, conditions 0]
A quotient is left as it is. together and apart rewrite rational functions:
#cas [expand] (1 / (x + 1) ^ 2)
1/(x + 1)^2Checked by Lean’s kernel: Identity with the input
∀ (x : ℝ), 1 / (x + 1) ^ 2 = 1 / (x + 1) ^ 2
The certificate: 1 checked step
Identity with the input
∀ (x : ℝ), 1 / (x + 1) ^ 2 = 1 / (x + 1) ^ 2
The computation
Ranked candidates (proposals, not proof)
input: 1/(x + 1)^2 [leafCount 7, conditions 0]
See Also
factor · collect · trigExpand · fullSimplify · coefficientList
