Mode of #cas
polynomialLCM
Gives the monic lcm of two nonzero polynomials in one variable, with a theorem about Mathlib’s lcm in ℚ[X].
#cas [polynomialLCM] (p, q)lcm p q = l in Mathlib’s ℚ[X].You meet a polynomial lcm every time you put fractions over a common denominator. polynomialLCM computes it in , and the theorem is about Mathlib’s lcm in ℚ[X], the normalized lcm, which is monic.
The proof goes through the gcd. Both polynomials divide with explicit cofactors, the gcd comes with the certificate of polynomialGCD, and divides . From that, Mathlib’s gcd_mul_lcm shows that divides lcm p q.
Examples (8)#
Basic Examples (2)
The lcm of and is , expanded:
#cas [polynomialLCM] (x^2 - 1, x^2 - 2*x + 1)
monic lcm
x^3 - x^2 - x + 1- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^2 - 1, x^2 - 2*x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 - Polynomial.X + 1
The certificate: 1 checked step
Statement in ℚ[X]
lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 - Polynomial.X + 1
The two polynomials share the factor , so the lcm has degree and not :
#cas [polynomialLCM] (x^2 - 1, x^3 - 1)
monic lcm
x^4 + x^3 - x - 1- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^2 - 1, x^3 - 1)
Checked by Lean’s kernel: Statement in ℚ[X]
lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 3 - 1) = Polynomial.X ^ 4 + Polynomial.X ^ 3 - Polynomial.X - 1
The certificate: 1 checked step
Statement in ℚ[X]
lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 3 - 1) = Polynomial.X ^ 4 + Polynomial.X ^ 3 - Polynomial.X - 1
Scope (1)
The lcm is monic, so here it is and not :
#cas [polynomialLCM] (2*x + 1, 4*x^2 - 1)
monic lcm
x^2 - 1/4- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(2*x + 1, 4*x^2 - 1)
Checked by Lean’s kernel: Statement in ℚ[X]
lcm (2 * Polynomial.X + 1) (4 * Polynomial.X ^ 2 - 1) = Polynomial.X ^ 2 - Polynomial.C (1 / 4)
The certificate: 1 checked step
Statement in ℚ[X]
lcm (2 * Polynomial.X + 1) (4 * Polynomial.X ^ 2 - 1) = Polynomial.X ^ 2 - Polynomial.C (1 / 4)
Applications (2)
The first example as a theorem about Mathlib’s lcm. Only the three standard axioms are used:
open Polynomial in theorem lcm_of_quadratics : lcm (X ^ 2 - 1 : ℚ[X]) (X ^ 2 - 2 * X + 1) = X ^ 3 - X ^ 2 - X + 1 := by cas #print axioms lcm_of_quadratics
lcm_of_quadratics depends on the axioms propext, Classical.choice, Quot.sound.
together puts a sum of fractions over a common denominator. Here it is the lcm of the denominators and , in factored form:
#cas [together] (1/(x^2-1) + 1/(x-1))
common denominator
(x + 2)/((x - 1)*(x + 1))- Input (rational function)
(1/(x^2-1) + 1/(x-1))- Conditions
- ,
Checked by Lean’s kernel: Identity with the common-denominator form
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))
The certificate: 1 checked step
Identity with the common-denominator form
∀ (x : ℝ), x ^ 2 - 1 ≠ 0 → x - 1 ≠ 0 → 1 / (x ^ 2 - 1) + 1 / (x - 1) = (x + 2) / ((x - 1) * (x + 1))
Properties and Relations (1)
polynomialGCD gives the gcd of the first example. Its product with the lcm is :
#cas [polynomialGCD] (x^2 - 1, x^2 - 2*x + 1)
monic gcd
x - 1- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^2 - 1, x^2 - 2*x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
gcd (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) = Polynomial.X - 1
The certificate: 1 checked step
Statement in ℚ[X]
gcd (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) = Polynomial.X - 1
Possible Issues (2)
Mathlib’s lcm 0 p is , and a zero input is refused:
#cas [polynomialLCM] (0, x)
Error
polynomialLCM: the polynomials must be nonzero (lcm 0 p = 0)
The product is a common multiple of and , but not the least one. The tactic cas refuses it, with the lcm in its message:
open Polynomial in example : lcm (X ^ 2 - 1 : ℚ[X]) (X - 1) = X ^ 3 - X ^ 2 - X + 1 := by cas
Error
cas: the lcm is X^2 - 1, not X^3 - X^2 - X + 1
