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)
gives the monic least common multiple l of the nonzero polynomials p and q and proves 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 ℚ[X], 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 l with explicit cofactors, the gcd g comes with the certificate of polynomialGCD, and g·l divides pq. From that, Mathlib’s gcd_mul_lcm shows that l divides lcm p q.

Details and Options

  • The theorem is lcm p q = l in ℚ[X], with the variable read as Polynomial.X. The two inputs have the same single variable.
  • The lcm is monic, so it can have fractions as coefficients when the inputs have integer ones.
  • The inputs are nonzero polynomials with rational coefficients in one variable. Mathlib sets lcm 0 p = 0, and a zero input is refused.
  • The product of the gcd and the lcm is pq divided by the leading coefficients of p and q.
  • The tactic cas proves lcm p q = l goals in ℚ[X], and it refuses a wrong lcm with the right one in its message.
  • There are no options.

Examples (8)#

Basic Examples (2)

The lcm of x2−1 and (x−1)2 is (x−1)2(x+1), expanded:

In[1]:=
#cas [polynomialLCM] (x^2 - 1, x^2 - 2*x + 1)
Out[1]=

monic lcm

x3−x2−x+1
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
  1. Statement in ℚ[X]

    lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) =
      Polynomial.X ^ 3 - Polynomial.X ^ 2 - Polynomial.X + 1

    Checked by Lean’s kernel


The two polynomials share the factor x−1, so the lcm has degree 4 and not 5:

In[2]:=
#cas [polynomialLCM] (x^2 - 1, x^3 - 1)
Out[2]=

monic lcm

x4+x3−x−1
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
  1. Statement in ℚ[X]

    lcm (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 3 - 1) =
      Polynomial.X ^ 4 + Polynomial.X ^ 3 - Polynomial.X - 1

    Checked by Lean’s kernel

Scope (1)

The lcm is monic, so here it is x2−14 and not 4x2−1:

In[3]:=
#cas [polynomialLCM] (2*x + 1, 4*x^2 - 1)
Out[3]=

monic lcm

x2−14
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
  1. Statement in ℚ[X]

    lcm (2 * Polynomial.X + 1) (4 * Polynomial.X ^ 2 - 1) = Polynomial.X ^ 2 - Polynomial.C (1 / 4)

    Checked by Lean’s kernel

Applications (2)

The first example as a theorem about Mathlib’s lcm. Only the three standard axioms are used:

In[4]:=
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
Out[4]=

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 x2−1 of the denominators x2−1 and x−1, in factored form:

In[5]:=
#cas [together] (1/(x^2-1) + 1/(x-1))
Out[5]=

common denominator

x+2(x−1)(x+1)
(x + 2)/((x - 1)*(x + 1))
Input (rational function)
(1/(x^2-1) + 1/(x-1))
Conditions
x2−1≠0, x−1≠0

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
  1. 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))

    Checked by Lean’s kernel

Properties and Relations (1)

polynomialGCD gives the gcd x−1 of the first example. Its product with the lcm is (x2−1)(x−1)2:

In[6]:=
#cas [polynomialGCD] (x^2 - 1, x^2 - 2*x + 1)
Out[6]=

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
  1. Statement in ℚ[X]

    gcd (Polynomial.X ^ 2 - 1) (Polynomial.X ^ 2 - 2 * Polynomial.X + 1) = Polynomial.X - 1

    Checked by Lean’s kernel

Possible Issues (2)

Mathlib’s lcm 0 p is 0, and a zero input is refused:

In[7]:=
#cas [polynomialLCM] (0, x)
Out[7]=

Error

polynomialLCM: the polynomials must be nonzero (lcm 0 p = 0)

The product (x2−1)(x−1)=x3−x2−x+1 is a common multiple of x2−1 and x−1, but not the least one. The tactic cas refuses it, with the lcm in its message:

In[8]:=
open Polynomial in
example : lcm (X ^ 2 - 1 : ℚ[X]) (X - 1) = X ^ 3 - X ^ 2 - X + 1 := by
  cas
Out[8]=

Error

cas: the lcm is X^2 - 1, not X^3 - X^2 - X + 1

See Also

polynomialGCD · together · factor · denominator