Mode of #cas
polynomialRemainder
Gives the remainder of a division of polynomials in one variable, with a theorem about Mathlib’s % in ℚ[X].
#cas [polynomialRemainder] (p, q)p / q = s ∧ p % q = r in Mathlib’s ℚ[X].polynomialRemainder gives you the remainder of polynomial long division. It is also a divisibility test, since q divides p exactly when the remainder is . The report prints the remainder, and the theorem under it is the one of polynomialQuotientRemainder, which states the quotient and the remainder together, about Mathlib’s / and % on ℚ[X].
Examples (8)#
Basic Examples (2)
The remainder shows that divides :
#cas [polynomialRemainder] (x^5 + x + 1, x^2 + x + 1)
remainder
0- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^5 + x + 1, x^2 + x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
(Polynomial.X ^ 5 + Polynomial.X + 1) / (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 + 1 ∧ (Polynomial.X ^ 5 + Polynomial.X + 1) % (Polynomial.X ^ 2 + Polynomial.X + 1) = 0
The certificate: 1 checked step
Statement in ℚ[X]
(Polynomial.X ^ 5 + Polynomial.X + 1) / (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 + 1 ∧ (Polynomial.X ^ 5 + Polynomial.X + 1) % (Polynomial.X ^ 2 + Polynomial.X + 1) = 0
A remainder of a division by a linear polynomial is a number:
#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)
Applications (1)
The second example as a theorem about Mathlib’s %. The remainder is the constant polynomial C (9 / 8), and only the three standard axioms are used:
open Polynomial in theorem remainder_by_linear : (X ^ 3 + 1 : ℚ[X]) % (2 * X - 1) = C (9 / 8) := by cas #print axioms remainder_by_linear
remainder_by_linear depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (3)
polynomialQuotient gives the quotient of the first example:
#cas [polynomialQuotient] (x^5 + x + 1, x^2 + x + 1)
quotient
x^3 - x^2 + 1- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^5 + x + 1, x^2 + x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
(Polynomial.X ^ 5 + Polynomial.X + 1) / (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 + 1 ∧ (Polynomial.X ^ 5 + Polynomial.X + 1) % (Polynomial.X ^ 2 + Polynomial.X + 1) = 0
The certificate: 1 checked step
Statement in ℚ[X]
(Polynomial.X ^ 5 + Polynomial.X + 1) / (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 3 - Polynomial.X ^ 2 + 1 ∧ (Polynomial.X ^ 5 + Polynomial.X + 1) % (Polynomial.X ^ 2 + Polynomial.X + 1) = 0
The remainder of by is its value at :
#cas [polynomialRemainder] (x^3 + 1, x - 2)
remainder
9- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^3 + 1, x - 2)
Checked by Lean’s kernel: Statement in ℚ[X]
(Polynomial.X ^ 3 + 1) / (Polynomial.X - 2) = Polynomial.X ^ 2 + 2 * Polynomial.X + 4 ∧ (Polynomial.X ^ 3 + 1) % (Polynomial.X - 2) = 9
The certificate: 1 checked step
Statement in ℚ[X]
(Polynomial.X ^ 3 + 1) / (Polynomial.X - 2) = Polynomial.X ^ 2 + 2 * Polynomial.X + 4 ∧ (Polynomial.X ^ 3 + 1) % (Polynomial.X - 2) = 9
open Polynomial in example : (X ^ 3 + 1 : ℚ[X]).eval 2 = 9 := by cas
Lean accepts the proof.
When the remainder is , the divisor is a gcd of the two. Here it is monic, and polynomialGCD gives it back:
#cas [polynomialGCD] (x^5 + x + 1, x^2 + x + 1)
monic gcd
x^2 + x + 1- Domain
x ↦ X in ℚ[X]- Input (polynomials)
(x^5 + x + 1, x^2 + x + 1)
Checked by Lean’s kernel: Statement in ℚ[X]
gcd (Polynomial.X ^ 5 + Polynomial.X + 1) (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 2 + Polynomial.X + 1
The certificate: 1 checked step
Statement in ℚ[X]
gcd (Polynomial.X ^ 5 + Polynomial.X + 1) (Polynomial.X ^ 2 + Polynomial.X + 1) = Polynomial.X ^ 2 + Polynomial.X + 1
Possible Issues (1)
Mathlib sets p % 0 = p, and a zero divisor is refused:
#cas [polynomialRemainder] (x^2, 0)
Error
polynomialRemainder: division by the zero polynomial
Neat Examples (1)
The remainder of by is :
#cas [polynomialRemainder] (x^10 - 1, x^3 - 1)
remainder
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 · polynomialQuotientRemainder · polynomialGCD · member
