Mode of #cas
polynomialQuotientRemainder
Gives the quotient and the remainder of a division of polynomials in one variable, with a theorem about Mathlib’s / and % in ℚ[X].
#cas [polynomialQuotientRemainder] (p, q)p / q = s ∧ p % q = r in Mathlib’s ℚ[X].polynomialQuotientRemainder is polynomial long division with a proof attached. The output is the pair with and , and the theorem is about Mathlib’s / and % on ℚ[X].
For the proof we divide by the monic polynomial , where is the leading coefficient of . The identity and the degree bound determine the quotient and the remainder by Mathlib’s Polynomial.div_modByMonic_unique, and Polynomial.div_def and Polynomial.mod_def relate them to / and %.
Examples (9)#
Basic Examples (1)
A division by . The quotient has fractions as coefficients:
#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)
Scope (2)
The zero polynomial divided by :
#cas [polynomialQuotientRemainder] (0, x + 1)
[quotient, remainder]
[0, 0]- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(0, x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
0 / (Polynomial.X + 1) = 0 ∧ 0 % (Polynomial.X + 1) = 0
The certificate: 1 checked step
Statement in ℚ[X]
0 / (Polynomial.X + 1) = 0 ∧ 0 % (Polynomial.X + 1) = 0
When the divisor has the larger degree, the quotient is and the remainder is the dividend:
#cas [polynomialQuotientRemainder] (x + 1, x^2 + 1)
[quotient, remainder]
[0, x + 1]- 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 / and %, one part at a time. Only the three standard axioms are used:
open Polynomial in theorem division_by_linear : (X ^ 3 + 1 : ℚ[X]) / (2 * X - 1) = C (1 / 2) * X ^ 2 + C (1 / 4) * X + C (1 / 8) ∧ (X ^ 3 + 1 : ℚ[X]) % (2 * X - 1) = C (9 / 8) := ⟨by cas, by cas⟩ #print axioms division_by_linear
division_by_linear depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (3)
polynomialQuotient prints the quotient alone:
#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)
polynomialRemainder prints the remainder alone:
#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)
apart splits off the polynomial part of a rational function. For it is the quotient of by , and the remainder stays over :
#cas [apart] (x^3/(x^2+1))
partial fractions over the written factors, refined by gcds
x - x/(x^2 + 1)- Input (rational function)
(x^3/(x^2+1))- Conditions
Checked by Lean’s kernel: Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → x ^ 3 / (x ^ 2 + 1) = x - x / (x ^ 2 + 1)
The certificate: 1 checked step
Identity with the partial fraction decomposition
∀ (x : ℝ), x ^ 2 + 1 ≠ 0 → x ^ 3 / (x ^ 2 + 1) = x - x / (x ^ 2 + 1)
Possible Issues (1)
The divisor must be nonzero:
#cas [polynomialQuotientRemainder] (x^2, 0)
Error
polynomialQuotientRemainder: division by the zero polynomial
Neat Examples (1)
Dividing by leaves :
#cas [polynomialQuotientRemainder] (x^10 - 1, x^3 - 1)
[quotient, remainder]
[x^7 + x^4 + x, x - 1]- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^10 - 1, x^3 - 1)
Checked by Lean’s kernel: Statement in ℚ[X]
(Polynomial.X ^ 10 - 1) / (Polynomial.X ^ 3 - 1) = Polynomial.X ^ 7 + Polynomial.X ^ 4 + Polynomial.X ∧ (Polynomial.X ^ 10 - 1) % (Polynomial.X ^ 3 - 1) = Polynomial.X - 1
The certificate: 1 checked step
Statement in ℚ[X]
(Polynomial.X ^ 10 - 1) / (Polynomial.X ^ 3 - 1) = Polynomial.X ^ 7 + Polynomial.X ^ 4 + Polynomial.X ∧ (Polynomial.X ^ 10 - 1) % (Polynomial.X ^ 3 - 1) = Polynomial.X - 1
See Also
polynomialQuotient · polynomialRemainder · polynomialGCD · apart
