Mode of #cas

polynomialQuotient

Gives the quotient of a division of polynomials in one variable, with a theorem about Mathlib’s / in ℚ[X].

#cas [polynomialQuotient] (p, q)
gives the quotient s of the division of the polynomial p by the nonzero polynomial q and proves p / q = s ∧ p % q = r in Mathlib’s ℚ[X].

polynomialQuotient gives you the quotient of polynomial long division. The report prints the quotient, and the theorem under it is the one of polynomialQuotientRemainder, which states the quotient and the remainder together, about Mathlib’s / and % on ℚ[X]. So the theorem has the remainder in it even when you only asked for the quotient.

Details and Options

  • The theorem is p / q = s ∧ p % q = r in ℚ[X], with the variable read as Polynomial.X, proved as for polynomialQuotientRemainder.
  • The quotient s satisfies p=sq+r with degr<degq. It is exact, p=sq, when the remainder is 0.
  • The divisor q is nonzero. Mathlib’s division is total, with p / 0 = 0, and a zero divisor is refused.
  • The tactic cas proves p / q = s goals in ℚ[X].
  • There are no options.

Examples (9)#

Basic Examples (2)

The division of x4−1 by x2+1 is exact:

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

quotient

x2−1
x^2 - 1
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x^4 - 1, x^2 + 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X ^ 4 - 1) / (Polynomial.X ^ 2 + 1) = Polynomial.X ^ 2 - 1 ∧
  (Polynomial.X ^ 4 - 1) % (Polynomial.X ^ 2 + 1) = 0
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X ^ 4 - 1) / (Polynomial.X ^ 2 + 1) = Polynomial.X ^ 2 - 1 ∧
      (Polynomial.X ^ 4 - 1) % (Polynomial.X ^ 2 + 1) = 0

    Checked by Lean’s kernel


A divisor that is not monic can give fractions:

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

quotient

12x2+14x+18
1/2*x^2 + 1/4*x + 1/8
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x^3 + 1, 2*x - 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
    Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
  (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
        Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
      (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)

    Checked by Lean’s kernel

Scope (1)

When the divisor has the larger degree, the quotient is 0:

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

quotient

0
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x + 1, x^2 + 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X + 1) / (Polynomial.X ^ 2 + 1) = 0 ∧
  (Polynomial.X + 1) % (Polynomial.X ^ 2 + 1) = Polynomial.X + 1
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X + 1) / (Polynomial.X ^ 2 + 1) = 0 ∧
      (Polynomial.X + 1) % (Polynomial.X ^ 2 + 1) = Polynomial.X + 1

    Checked by Lean’s kernel

Applications (1)

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

In[4]:=
open Polynomial in
theorem quotient_by_quadratic : (X ^ 4 - 1 : ℚ[X]) / (X ^ 2 + 1) = X ^ 2 - 1 := by
  cas

#print axioms quotient_by_quadratic
Out[4]=

quotient_by_quadratic depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (3)

polynomialRemainder gives the other part of the division. Here it is 98, so x3+1=(12x2+14x+18)(2x−1)+98:

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

remainder

98
9/8
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x^3 + 1, 2*x - 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
    Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
  (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
        Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
      (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)

    Checked by Lean’s kernel


polynomialQuotientRemainder gives both:

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

[quotient, remainder]

[12x2+14x+18, 98]
[1/2*x^2 + 1/4*x + 1/8, 9/8]
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x^3 + 1, 2*x - 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
    Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
  (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X ^ 3 + 1) / (2 * Polynomial.X - 1) =
        Polynomial.C (1 / 2) * Polynomial.X ^ 2 + Polynomial.C (1 / 4) * Polynomial.X + Polynomial.C (1 / 8) ∧
      (Polynomial.X ^ 3 + 1) % (2 * Polynomial.X - 1) = Polynomial.C (9 / 8)

    Checked by Lean’s kernel


For real numbers, cancel divides out the common factor of (x2−1)/(x−1). Lean’s division of reals is total (1/0=0), so the result comes with the conditions x−1≠0 and x≠0:

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

cancelled

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

Checked by Lean’s kernel: Identity with the cancelled form

∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x
The certificate: 1 checked step
  1. Identity with the cancelled form

    ∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x

    Checked by Lean’s kernel

Possible Issues (1)

Mathlib sets p / 0 = 0, and a zero divisor is refused:

In[8]:=
#cas [polynomialQuotient] (x^2, 0)
Out[8]=

Error

polynomialQuotient: division by the zero polynomial

Neat Examples (1)

Dividing x5−1 by x−1 gives the geometric sum 1+x+x2+x3+x4:

In[9]:=
#cas [polynomialQuotient] (x^5 - 1, x - 1)
Out[9]=

quotient

x4+x3+x2+x+1
x^4 + x^3 + x^2 + x + 1
Domain
x ↦ X in ℚ[X]
Input (polynomials)
(x^5 - 1, x - 1)

Checked by Lean’s kernel: Statement in ℚ[X]

(Polynomial.X ^ 5 - 1) / (Polynomial.X - 1) =
    Polynomial.X ^ 4 + Polynomial.X ^ 3 + Polynomial.X ^ 2 + Polynomial.X + 1 ∧
  (Polynomial.X ^ 5 - 1) % (Polynomial.X - 1) = 0
The certificate: 1 checked step
  1. Statement in ℚ[X]

    (Polynomial.X ^ 5 - 1) / (Polynomial.X - 1) =
        Polynomial.X ^ 4 + Polynomial.X ^ 3 + Polynomial.X ^ 2 + Polynomial.X + 1 ∧
      (Polynomial.X ^ 5 - 1) % (Polynomial.X - 1) = 0

    Checked by Lean’s kernel

See Also

polynomialRemainder · polynomialQuotientRemainder · polynomialGCD · apart