Mode of #cas
coefficient
Gives the coefficient of a power of one variable in a polynomial, with a theorem about Mathlib’s Polynomial.coeff.
#cas [coefficient x k] ex ^ k in the polynomial e and proves it about Mathlib’s Polynomial.coeff.coefficient reads off one coefficient of a polynomial without making you keep the whole expansion. The theorem is about Mathlib’s polynomials: x is read as Polynomial.X, and the statement is P.coeff k = c.
Any other variable enters as a constant. For and the theorem is ∀ y : ℝ, ((X + C y) ^ 3).coeff 2 = 3 * y, in , with inside the polynomial as the constant C y.
Examples (10)#
Basic Examples (2)
The coefficient of in . The other variable stays in the coefficient:
#cas [coefficient x 2] ((x + y)^3)
coefficient of x^2
3*y- Domain
x ↦ X in ℝ[X], parameters in ℝ- Input (polynomial)
((x + y)^3)
Checked by Lean’s kernel: Statement about the polynomial
∀ (y : ℝ), ((Polynomial.X + Polynomial.C y) ^ 3).coeff 2 = 3 * y
The certificate: 1 checked step
Statement about the polynomial
∀ (y : ℝ), ((Polynomial.X + Polynomial.C y) ^ 3).coeff 2 = 3 * y
A binomial coefficient, :
#cas [coefficient x 2] ((x + 1)^5)
coefficient of x^2
10- Domain
x ↦ X in ℚ[X]- Input (polynomial)
((x + 1)^5)
Checked by Lean’s kernel: Statement about the polynomial
((Polynomial.X + 1) ^ 5).coeff 2 = 10
The certificate: 1 checked step
Statement about the polynomial
((Polynomial.X + 1) ^ 5).coeff 2 = 10
Scope (1)
The factor of comes in with its third power, :
#cas [coefficient x 3] ((1 + 2*x)^5)
coefficient of x^3
80- Domain
x ↦ X in ℚ[X]- Input (polynomial)
((1 + 2*x)^5)
Checked by Lean’s kernel: Statement about the polynomial
((1 + 2 * Polynomial.X) ^ 5).coeff 3 = 80
The certificate: 1 checked step
Statement about the polynomial
((1 + 2 * Polynomial.X) ^ 5).coeff 3 = 80
Applications (1)
The binomial coefficient as a theorem about Polynomial.coeff. Only the three standard axioms are used:
open Polynomial in theorem binomial_coefficient_two : ((X + 1) ^ 5 : ℚ[X]).coeff 2 = 10 := by cas #print axioms binomial_coefficient_two
binomial_coefficient_two depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (3)
coefficientList gives all the coefficients at once, the constant term first:
#cas [coefficientList x] ((x + 1)^3 - x/2)
coefficients, constant term first
[1, 5/2, 3, 1]- Domain
x ↦ X in ℚ[X]- Input (polynomial)
((x + 1)^3 - x/2)
Checked by Lean’s kernel: Statement about the polynomial
∀ (k : ℕ), ((Polynomial.X + 1) ^ 3 - Polynomial.C (1 / 2) * Polynomial.X).coeff k = [1, 5 / 2, 3, 1].getD k 0
The certificate: 1 checked step
Statement about the polynomial
∀ (k : ℕ), ((Polynomial.X + 1) ^ 3 - Polynomial.C (1 / 2) * Polynomial.X).coeff k = [1, 5 / 2, 3, 1].getD k 0
collect shows every coefficient in place:
#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
exponent gives the degree. The terms cancel here:
#cas [exponent x] ((x + 1)^3 - x^3)
degree
2- Domain
x ↦ X in ℚ[X]- Input (polynomial)
((x + 1)^3 - x^3)
Checked by Lean’s kernel: Statement about the polynomial
((Polynomial.X + 1) ^ 3 - Polynomial.X ^ 3).natDegree = 2
The certificate: 1 checked step
Statement about the polynomial
((Polynomial.X + 1) ^ 3 - Polynomial.X ^ 3).natDegree = 2
Possible Issues (3)
A quotient by a term with a variable is refused:
#cas [coefficient x 1] (1/x)
Error
coefficient: the expression is not a polynomial (it divides by a term with a variable)
Lean’s total division makes equal to for and to at . It is not a polynomial, and it is refused:
#cas [coefficient x 0] (1 / (1 + x * (1 / x)))
Error
coefficient: the expression is not a polynomial (it divides by a term with a variable)
The tactic cas refuses a wrong coefficient and gives the right one:
open Polynomial in example : ((X + 1) ^ 5 : ℚ[X]).coeff 2 = 5 := by cas
Error
cas: the coefficient is 10, not 5
See Also
coefficientList · collect · exponent · expand
