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)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.
Examples (9)#
Basic Examples (2)
The division of by is exact:
#cas [polynomialQuotient] (x^4 - 1, x^2 + 1)
quotient
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
Statement in ℚ[X]
(Polynomial.X ^ 4 - 1) / (Polynomial.X ^ 2 + 1) = Polynomial.X ^ 2 - 1 ∧ (Polynomial.X ^ 4 - 1) % (Polynomial.X ^ 2 + 1) = 0
A divisor that is not monic can give fractions:
#cas [polynomialQuotient] (x^3 + 1, 2*x - 1)
quotient
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
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)
Scope (1)
When the divisor has the larger degree, the quotient is :
#cas [polynomialQuotient] (x + 1, x^2 + 1)
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
Statement in ℚ[X]
(Polynomial.X + 1) / (Polynomial.X ^ 2 + 1) = 0 ∧ (Polynomial.X + 1) % (Polynomial.X ^ 2 + 1) = Polynomial.X + 1
Applications (1)
The first example as a theorem about Mathlib’s /. Only the three standard axioms are used:
open Polynomial in theorem quotient_by_quadratic : (X ^ 4 - 1 : ℚ[X]) / (X ^ 2 + 1) = X ^ 2 - 1 := by cas #print axioms quotient_by_quadratic
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 , so :
#cas [polynomialRemainder] (x^3 + 1, 2*x - 1)
remainder
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
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)
polynomialQuotientRemainder gives both:
#cas [polynomialQuotientRemainder] (x^3 + 1, 2*x - 1)
[quotient, remainder]
[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
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)
For real numbers, cancel divides out the common factor of . Lean’s division of reals is total (), so the result comes with the conditions and :
#cas [cancel] ((x^2-1)/(x-1) + 1/x)
cancelled
x + 1 + 1/x- Input (rational function)
((x^2-1)/(x-1) + 1/x)- Conditions
- ,
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
Identity with the cancelled form
∀ (x : ℝ), x - 1 ≠ 0 → x ≠ 0 → (x ^ 2 - 1) / (x - 1) + 1 / x = x + 1 + 1 / x
Possible Issues (1)
Mathlib sets p / 0 = 0, and a zero divisor is refused:
#cas [polynomialQuotient] (x^2, 0)
Error
polynomialQuotient: division by the zero polynomial
Neat Examples (1)
Dividing by gives the geometric sum :
#cas [polynomialQuotient] (x^5 - 1, x - 1)
quotient
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
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
See Also
polynomialRemainder · polynomialQuotientRemainder · polynomialGCD · apart
