Mode of #cas
reduce
A polynomial equation or inequality reduced to an equivalent union of intervals, with a theorem.
#cas [reduce x] (lhs < rhs)=, ≠, <, ≤, > or ≥.reduce tells you exactly where a polynomial inequality holds. The answer is a union of intervals, and the theorem is an equivalence: the inequality holds on those intervals and nowhere else. The “nowhere else” is the half that a plot or a few test points can’t give you.
The endpoints are the real roots of . The rational ones are written exactly. Each of the others is named ρ0, ρ1, … and located in a rational interval of width at most .
Examples (14)#
Basic Examples (3)
An affine inequality:
#cas [reduce x] (-2 * x + 3 ≤ 7)
equivalent real solution predicate
x ≥ -2- Input (real relation)
(-2 * x + 3 ≤ 7)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), -2 * x + 3 ≤ 7 ↔ x ≥ -2
The certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), -2 * x + 3 ≤ 7 ↔ x ≥ -2
The computation
Guarantee: the input and output are equivalent for every real value
A quadratic with rational roots, with the theorem:
#cas [reduce x] (x^2 - 3*x + 2 > 0)
equivalent condition on the real roots
x < 1 ∨ 2 < x- Input (polynomial relation)
(x^2 - 3*x + 2 > 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), 0 < x ^ 2 - 3 * x + 2 ↔ x < 1 ∨ 2 < x
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), 0 < x ^ 2 - 3 * x + 2 ↔ x < 1 ∨ 2 < x
The computation
Certified roots
2 real roots of the polynomial, 1 cell; cuts [0, 3/2, 3]; signs [true, false, true]
Irrational endpoints are named ρ0 and ρ1:
#cas [reduce x] (x^2 < 2)
equivalent condition on the real roots
ρ0 < x < ρ1, where ρ0 = -1.41421356237309504880…, ρ1 = 1.41421356237309504880…- Input (polynomial relation)
(x^2 < 2)
Checked by Lean’s kernel: Solution set for every real value
∃ ρ, ((-141421356237309504881 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -141421356237309504880 / 10 ^ 20) ∧ 141421356237309504880 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 141421356237309504881 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 2 < 2 ↔ ρ 0 < x ∧ x < ρ 1
The certificate: 1 checked step
Solution set for every real value
∃ ρ, ((-141421356237309504881 / 10 ^ 20 < ρ 0 ∧ ρ 0 < -141421356237309504880 / 10 ^ 20) ∧ 141421356237309504880 / 10 ^ 20 < ρ 1 ∧ ρ 1 < 141421356237309504881 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 2 < 2 ↔ ρ 0 < x ∧ x < ρ 1
The computation
Certified roots
2 real roots of the polynomial, 6 cells; cuts [-3, -1767766952966368811/1250000000000000000, 3]; signs [true, false, true]
Scope (5)
A cubic, with a union of two intervals:
#cas [reduce x] (x^3 - x ≥ 0)
equivalent condition on the real roots
-1 ≤ x ≤ 0 ∨ 1 ≤ x- Input (polynomial relation)
(x^3 - x ≥ 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), x ≤ x ^ 3 ↔ (-1 < x ∧ x < 0 ∨ 1 < x) ∨ x = -1 ∨ x = 0 ∨ x = 1
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), x ≤ x ^ 3 ↔ (-1 < x ∧ x < 0 ∨ 1 < x) ∨ x = -1 ∨ x = 0 ∨ x = 1
The computation
Certified roots
3 real roots of the polynomial, 2 cells; cuts [-2, -1/2, 1/2, 2]; signs [false, true, false, true]
A double root, where the sign does not change, gives an isolated point:
#cas [reduce x] ((x - 1)^2 * (x + 2) ≤ 0)
equivalent condition on the real roots
x ≤ -2 ∨ x = 1- Input (polynomial relation)
((x - 1)^2 * (x + 2) ≤ 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), (x - 1) ^ 2 * (x + 2) ≤ 0 ↔ x < -2 ∨ x = -2 ∨ x = 1
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), (x - 1) ^ 2 * (x + 2) ≤ 0 ↔ x < -2 ∨ x = -2 ∨ x = 1
The computation
Certified roots
2 real roots of the polynomial, 1 cell; cuts [-3, -1/2, 2]; signs [false, true, true]
A quintic with one real root:
#cas [reduce x] (x^5 - x - 1 < 0)
equivalent condition on the real roots
x < ρ0, where ρ0 = 1.16730397826141868425…- Input (polynomial relation)
(x^5 - x - 1 < 0)
Checked by Lean’s kernel: Solution set for every real value
∃ ρ, (116730397826141868425 / 10 ^ 20 < ρ 0 ∧ ρ 0 < 116730397826141868426 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 5 - x < 1 ↔ x < ρ 0
The certificate: 1 checked step
Solution set for every real value
∃ ρ, (116730397826141868425 / 10 ^ 20 < ρ 0 ∧ ρ 0 < 116730397826141868426 / 10 ^ 20) ∧ ∀ (x : ℝ), x ^ 5 - x < 1 ↔ x < ρ 0
The computation
Certified roots
1 real root of the polynomial, 7 cells; cuts [0, 3]; signs [false, true]
A quotient, through the product of its numerator and denominator:
#cas [reduce x] ((x - 1) / (x + 2) > 0)
equivalent condition on the real roots
x < -2 ∨ 1 < x- Input (rational relation)
((x - 1) / (x + 2) > 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), 0 < (x - 1) / (x + 2) ↔ x < -2 ∨ 1 < x
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), 0 < (x - 1) / (x + 2) ↔ x < -2 ∨ 1 < x
The computation
Certified roots
2 real roots of the product of numerator and denominator, 1 cell; cuts [-3, -1/2, 2]; signs [true, false, true]
A relation that holds everywhere:
#cas [reduce x] (x^2 + 1 > 0)
equivalent condition on the real roots
True- Input (polynomial relation)
(x^2 + 1 > 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), 0 < x ^ 2 + 1 ↔ True
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), 0 < x ^ 2 + 1 ↔ True
The computation
Certified roots
0 real roots of the polynomial, 1 cell; cuts [0]; signs [true]
Applications (1)
A sign condition in a proof. cas proves it, and only the three standard axioms are used:
theorem reduce_positive : ∀ x : ℝ, 0 < x ^ 2 - x + 1 := by cas #print axioms reduce_positive
reduce_positive depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (2)
The endpoint ρ0 of is the real root that roots encloses:
#cas [roots x] (x ^ 5 - x - 1 = 0)
the only real solution, by 20 decimals, truncated
1.16730397826141868425- Input (polynomial equation)
(x ^ 5 - x - 1 = 0)
Checked by Lean’s kernel: Complete list of real solutions
(∃! x,
x ∈ Set.Ioo (116730397826141868425 / 10 ^ 20) (116730397826141868426 / 10 ^ 20) ∧ x ^ 5 - x - 1 = 0) ∧
∀ (x : ℝ), x ^ 5 - x - 1 = 0 → x ∈ Set.Ioo (116730397826141868425 / 10 ^ 20) (116730397826141868426 / 10 ^ 20)from CAS.Polynomial.RealRoot.of_exprRootCheck
The certificate: 1 checked step
Complete list of real solutions
(∃! x, x ∈ Set.Ioo (116730397826141868425 / 10 ^ 20) (116730397826141868426 / 10 ^ 20) ∧ x ^ 5 - x - 1 = 0) ∧ ∀ (x : ℝ), x ^ 5 - x - 1 = 0 → x ∈ Set.Ioo (116730397826141868425 / 10 ^ 20) (116730397826141868426 / 10 ^ 20)
The computation
Certified isolation
Square-free polynomial of degree 5, Cauchy bound 3, 7 cells Guarantee: the listed solutions are distinct, each rational is a solution, each decimal interval contains exactly one solution, and there are no other real solutions
The endpoints of are the solutions of , which solve writes with square roots:
#cas [solve x] (x ^ 2 = 2)
equivalent real solution predicate
x = sqrt(2) ∨ x = -sqrt(2)- Input (real relation)
(x ^ 2 = 2)
Checked by Lean’s kernel: Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 2 ↔ x = √2 ∨ x = -√2
The certificate: 1 checked step
Complete solution predicate for every real value
∀ (x : ℝ), x ^ 2 = 2 ↔ x = √2 ∨ x = -√2
The computation
Guarantee: the input and output are equivalent for every real value
Possible Issues (2)
A polynomial alone is not a relation. Write one, such as x^2 + 1 > 0:
#cas [reduce x] (x^2 + 1)
Error
expected a real equation or comparison
Only polynomial relations and quotients compared with 0 are reduced:
#cas [reduce x] (sin x > 0)
Error
supported fragment: polynomials with rational coefficients in one real variable; for other equations, #cas [findRoot x in [a, b]] (f = g) finds a certified root in an interval
Neat Examples (1)
The sign of a product of four factors alternates from one root to the next:
#cas [reduce x] ((x - 1) * (x - 2) * (x - 3) * (x - 4) > 0)
equivalent condition on the real roots
x < 1 ∨ 2 < x < 3 ∨ 4 < x- Input (polynomial relation)
((x - 1) * (x - 2) * (x - 3) * (x - 4) > 0)
Checked by Lean’s kernel: Solution set for every real value
∀ (x : ℝ), 0 < (x - 1) * (x - 2) * (x - 3) * (x - 4) ↔ x < 1 ∨ 2 < x ∧ x < 3 ∨ 4 < x
The certificate: 1 checked step
Solution set for every real value
∀ (x : ℝ), 0 < (x - 1) * (x - 2) * (x - 3) * (x - 4) ↔ x < 1 ∨ 2 < x ∧ x < 3 ∨ 4 < x
The computation
Certified roots
4 real roots of the polynomial, 1 cell; cuts [0, 3/2, 5/2, 7/2, 5]; signs [true, false, true, false, true]
