Mode of #cas

reduce

A polynomial equation or inequality reduced to an equivalent union of intervals, with a theorem.

#cas [reduce x] (lhs < rhs)
reduces an equation, disequation or comparison of polynomials in x to an equivalent condition on x, a union of intervals whose endpoints are the real roots of lhs - rhs, and proves the equivalence. The relation may be =, ≠, <, ≤, > 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 lhs−rhs. The rational ones are written exactly. Each of the others is named ρ0, ρ1, … and located in a rational interval of width at most 10−20.

Details and Options

  • For an affine relation, and for an equation of degree at most 2, the theorem is ∀ x : ℝ, rel ↔ P x for the printed condition P x. Otherwise it is ∃ ρ, (bounds on ρ 0, ρ 1, …) ∧ ∀ x : ℝ, rel ↔ P x, and ∃ ρ is dropped when every root is rational. The theorem may write the relation and the condition in an equivalent form: x^3 - x ≥ 0 as x ≤ x ^ 3, and a closed interval as an open one together with its endpoints.
  • The two sides are polynomials in x alone with rational coefficients, of any degree. The search for the real roots works with cells, intervals with no root or exactly one, and a relation that needs more than 1024 cells is refused.
  • A quotient p / q compared with 0 is reduced through the product p * q, which has the same sign as p / q under Lean’s convention p / 0 = 0.
  • A relation that holds for every x gives True, and one that holds for none gives False.
  • There are no options. In a proof, cas proves a sign condition that holds for every x, such as ∀ x : ℝ, 0 < x ^ 2 - x + 1, but not the equivalence of the report.

Examples (14)#

Basic Examples (3)

An affine inequality:

In[1]:=
#cas [reduce x] (-2 * x + 3 ≤ 7)
Out[1]=

equivalent real solution predicate

x≥−2
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
  1. Complete solution predicate for every real value

    ∀ (x : ℝ), -2 * x + 3 ≤ 7 ↔ x ≥ -2

    Checked by Lean’s kernel

The computation
  • Guarantee: the input and output are equivalent for every real value

A quadratic with rational roots, with the theorem:

In[2]:=
#cas [reduce x] (x^2 - 3*x + 2 > 0)
Out[2]=

equivalent condition on the real roots

x<1∨2<x
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
  1. Solution set for every real value

    ∀ (x : ℝ), 0 < x ^ 2 - 3 * x + 2 ↔ x < 1 ∨ 2 < x

    Checked by Lean’s kernel

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:

In[3]:=
#cas [reduce x] (x^2 < 2)
Out[3]=

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
  1. 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

    Checked by Lean’s kernel

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:

In[4]:=
#cas [reduce x] (x^3 - x ≥ 0)
Out[4]=

equivalent condition on the real roots

−1≤x≤0∨1≤x
-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
  1. Solution set for every real value

    ∀ (x : ℝ), x ≤ x ^ 3 ↔ (-1 < x ∧ x < 0 ∨ 1 < x) ∨ x = -1 ∨ x = 0 ∨ x = 1

    Checked by Lean’s kernel

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:

In[5]:=
#cas [reduce x] ((x - 1)^2 * (x + 2) ≤ 0)
Out[5]=

equivalent condition on the real roots

x≤−2∨x=1
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
  1. Solution set for every real value

    ∀ (x : ℝ), (x - 1) ^ 2 * (x + 2) ≤ 0 ↔ x < -2 ∨ x = -2 ∨ x = 1

    Checked by Lean’s kernel

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:

In[6]:=
#cas [reduce x] (x^5 - x - 1 < 0)
Out[6]=

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
  1. Solution set for every real value

    ∃ ρ,
      (116730397826141868425 / 10 ^ 20 < ρ 0 ∧ ρ 0 < 116730397826141868426 / 10 ^ 20) ∧
        ∀ (x : ℝ), x ^ 5 - x < 1 ↔ x < ρ 0

    Checked by Lean’s kernel

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:

In[7]:=
#cas [reduce x] ((x - 1) / (x + 2) > 0)
Out[7]=

equivalent condition on the real roots

x<−2∨1<x
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
  1. Solution set for every real value

    ∀ (x : ℝ), 0 < (x - 1) / (x + 2) ↔ x < -2 ∨ 1 < x

    Checked by Lean’s kernel

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:

In[8]:=
#cas [reduce x] (x^2 + 1 > 0)
Out[8]=

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
  1. Solution set for every real value

    ∀ (x : ℝ), 0 < x ^ 2 + 1 ↔ True

    Checked by Lean’s kernel

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:

In[9]:=
theorem reduce_positive : ∀ x : ℝ, 0 < x ^ 2 - x + 1 := by
  cas

#print axioms reduce_positive
Out[9]=

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

Properties and Relations (2)

The endpoint ρ0 of x5−x−1<0 is the real root that roots encloses:

In[10]:=
#cas [roots x] (x ^ 5 - x - 1 = 0)
Out[10]=

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
  1. 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)

    Checked by Lean’s kernel · CAS.Polynomial.RealRoot.of_exprRootCheck

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 x2<2 are the solutions of x2=2, which solve writes with square roots:

In[11]:=
#cas [solve x] (x ^ 2 = 2)
Out[11]=

equivalent real solution predicate

x=2∨x=−2
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
  1. Complete solution predicate for every real value

    ∀ (x : ℝ), x ^ 2 = 2 ↔ x = √2 ∨ x = -√2

    Checked by Lean’s kernel

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:

In[12]:=
#cas [reduce x] (x^2 + 1)
Out[12]=

Error

expected a real equation or comparison

Only polynomial relations and quotients compared with 0 are reduced:

In[13]:=
#cas [reduce x] (sin x > 0)
Out[13]=

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:

In[14]:=
#cas [reduce x] ((x - 1) * (x - 2) * (x - 3) * (x - 4) > 0)
Out[14]=

equivalent condition on the real roots

x<1∨2<x<3∨4<x
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
  1. Solution set for every real value

    ∀ (x : ℝ), 0 < (x - 1) * (x - 2) * (x - 3) * (x - 4) ↔ x < 1 ∨ 2 < x ∧ x < 3 ∨ 4 < x

    Checked by Lean’s kernel

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]

See Also

solve · roots · minimize · cas