Mode of #cas
coefficientList
Gives the coefficients of a polynomial in one variable, constant term first, with a theorem about Mathlib’s Polynomial.coeff.
#cas [coefficientList x] ek is P.coeff k for every k.coefficientList gives all the coefficients of a polynomial, in order. The list starts with the constant term, so the entry at position is the coefficient of , and the theorem says exactly that: ∀ k, P.coeff k = [c₀, …, c_d].getD k 0. One statement covers every , even past the end of the list, where getD reads , which is the coefficient there.
Examples (10)#
Basic Examples (2)
The coefficients of :
#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
With parameters, the coefficients are symbolic:
#cas [coefficientList x] (a*x^2 + b*x + c)
coefficients, constant term first
[c, b, a]- Domain
x ↦ X in ℝ[X], parameters in ℝ- Input (polynomial)
(a*x^2 + b*x + c)
Checked by Lean’s kernel: Statement about the polynomial
∀ (a b c : ℝ) (k : ℕ), (Polynomial.C a * Polynomial.X ^ 2 + Polynomial.C b * Polynomial.X + Polynomial.C c).coeff k = [c, b, a].getD k 0
The certificate: 1 checked step
Statement about the polynomial
∀ (a b c : ℝ) (k : ℕ), (Polynomial.C a * Polynomial.X ^ 2 + Polynomial.C b * Polynomial.X + Polynomial.C c).coeff k = [c, b, a].getD k 0
Scope (1)
Zero coefficients are listed:
#cas [coefficientList x] (x^3 + 1)
coefficients, constant term first
[1, 0, 0, 1]- Domain
x ↦ X in ℚ[X]- Input (polynomial)
(x^3 + 1)
Checked by Lean’s kernel: Statement about the polynomial
∀ (k : ℕ), (Polynomial.X ^ 3 + 1).coeff k = [1, 0, 0, 1].getD k 0
The certificate: 1 checked step
Statement about the polynomial
∀ (k : ℕ), (Polynomial.X ^ 3 + 1).coeff k = [1, 0, 0, 1].getD k 0
Applications (2)
The list statement gives each coefficient by specializing . Only the three standard axioms are used:
open Polynomial in theorem coefficients_of_cube (h : ∀ k, ((X + 1) ^ 3 : ℚ[X]).coeff k = [1, 3, 3, 1].getD k 0) : ((X + 1) ^ 3 : ℚ[X]).coeff 1 = 3 := h 1 #print axioms coefficients_of_cube
coefficients_of_cube depends on the axioms propext, Classical.choice, Quot.sound.
The tactic cas proves the single coefficient directly:
open Polynomial in example : ((X + 1) ^ 3 : ℚ[X]).coeff 1 = 3 := by cas
Lean accepts the proof.
Properties and Relations (3)
coefficient gives one entry of the list:
#cas [coefficient x 1] ((x + 1)^3 - x/2)
coefficient of x^1
5/2- Domain
x ↦ X in ℚ[X]- Input (polynomial)
((x + 1)^3 - x/2)
Checked by Lean’s kernel: Statement about the polynomial
((Polynomial.X + 1) ^ 3 - Polynomial.C (1 / 2) * Polynomial.X).coeff 1 = 5 / 2
The certificate: 1 checked step
Statement about the polynomial
((Polynomial.X + 1) ^ 3 - Polynomial.C (1 / 2) * Polynomial.X).coeff 1 = 5 / 2
exponent gives the degree. With a parameter in the leading coefficient, the theorem has the hypothesis that this coefficient is not zero:
#cas [exponent x] (a*x^2 + x + 1)
degree
2- Domain
x ↦ X in ℝ[X], parameters in ℝ- Input (polynomial)
(a*x^2 + x + 1)- Conditions
Checked by Lean’s kernel: Statement about the polynomial
∀ (a : ℝ), a ≠ 0 → (Polynomial.C a * Polynomial.X ^ 2 + Polynomial.X + 1).natDegree = 2
The certificate: 1 checked step
Statement about the polynomial
∀ (a : ℝ), a ≠ 0 → (Polynomial.C a * Polynomial.X ^ 2 + Polynomial.X + 1).natDegree = 2
interpolatingPolynomial builds a polynomial from its values:
#cas [interpolatingPolynomial x] [(0, 1), (1, 3), (2, 7)]
polynomial of degree at most 2
x^2 + x + 1- Domain
x ↦ X in ℚ[X]- Input (points)
(0, 1), (1, 3), (2, 7)
Checked by Lean’s kernel: Values and degree in ℚ[X]
Polynomial.eval 0 (Polynomial.X ^ 2 + Polynomial.X + 1) = 1 ∧ Polynomial.eval 1 (Polynomial.X ^ 2 + Polynomial.X + 1) = 3 ∧ Polynomial.eval 2 (Polynomial.X ^ 2 + Polynomial.X + 1) = 7 ∧ (Polynomial.X ^ 2 + Polynomial.X + 1).natDegree ≤ 2
The certificate: 1 checked step
Values and degree in ℚ[X]
Polynomial.eval 0 (Polynomial.X ^ 2 + Polynomial.X + 1) = 1 ∧ Polynomial.eval 1 (Polynomial.X ^ 2 + Polynomial.X + 1) = 3 ∧ Polynomial.eval 2 (Polynomial.X ^ 2 + Polynomial.X + 1) = 7 ∧ (Polynomial.X ^ 2 + Polynomial.X + 1).natDegree ≤ 2
Possible Issues (2)
The mode reads coefficients of polynomials only:
#cas [coefficientList x] (x + 1/x)
Error
coefficientList: the expression is not a polynomial (it divides by a term with a variable)
The zero polynomial is refused:
#cas [coefficientList x] (0)
Error
coefficientList: the polynomial is zero
