Mode of #cas
findRoot
A certified simple root of a function in an interval, to a chosen number of decimals, with a uniqueness theorem.
#cas [findRoot x in [a, b]] fg = h.#cas (digits := d) [findRoot x in [a, b]] fFor an equation such as I don’t need a formula. I need a root I can trust, in an interval I chose, and that is what findRoot gives you.
The search is simple. SymLean samples f at 65 equally spaced points of the interval and narrows the first sign change from the left by bisection. The check is the part that matters. The kernel verifies opposite signs at the two ends of a small interval, and an enclosure of the derivative that has one sign on it, so the interval holds exactly one root. The sign change alone would only give existence, and the derivative is what gives uniqueness.
Examples (15)#
Basic Examples (2)
The root of , with the theorem that it is the only one within of the printed value:
#cas [findRoot x in [0, 1]] (cos x = x)
certified simple root
x = 0.7390851332 ± 10^-10- Domain
x ∈ [0, 1]- Input (equation in ℝ)
(cos x = x)
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (7390851331 / 10 ^ 10) (7390851333 / 10 ^ 10) ∧ Real.cos x = x
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (7390851331 / 10 ^ 10) (7390851333 / 10 ^ 10) ∧ Real.cos x = x
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [0.7390851331, 0.7390851333], within 10^-10 of 0.7390851332: endpoint signs and a derivative of one sign, checked by the kernel
An expression stands for the equation :
#cas [findRoot x in [1, 2]] (x^2 - 2)
certified simple root
x = 1.4142135624 ± 10^-10- Domain
x ∈ [1, 2]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (14142135623 / 10 ^ 10) (14142135625 / 10 ^ 10) ∧ x ^ 2 - 2 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (14142135623 / 10 ^ 10) (14142135625 / 10 ^ 10) ∧ x ^ 2 - 2 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [1.4142135623, 1.4142135625], within 10^-10 of 1.4142135624: endpoint signs and a derivative of one sign, checked by the kernel
Scope (3)
A logarithm, on an interval of positive numbers:
#cas [findRoot x in [1, 3]] (log x + x - 2)
certified simple root
x = 1.5571455990 ± 10^-10- Domain
x ∈ [1, 3]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (15571455989 / 10 ^ 10) (15571455991 / 10 ^ 10) ∧ Real.log x + x - 2 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (15571455989 / 10 ^ 10) (15571455991 / 10 ^ 10) ∧ Real.log x + x - 2 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [1.5571455989, 1.5571455991], within 10^-10 of 1.5571455990: endpoint signs and a derivative of one sign, checked by the kernel
The root of between 2 and 4 is :
#cas [findRoot x in [2, 4]] (sin x)
certified simple root
x = 3.1415926536 ± 10^-10- Domain
x ∈ [2, 4]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (31415926535 / 10 ^ 10) (31415926537 / 10 ^ 10) ∧ Real.sin x = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (31415926535 / 10 ^ 10) (31415926537 / 10 ^ 10) ∧ Real.sin x = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [3.1415926535, 3.1415926537], within 10^-10 of 3.1415926536: endpoint signs and a derivative of one sign, checked by the kernel
The interval may be wide, with a large endpoint:
#cas [findRoot x in [0, 10^200]] (x - 1)
certified simple root
x = 1.0000000000 ± 10^-10- Domain
x ∈ [0, 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (9999999999 / 10 ^ 10) (10000000001 / 10 ^ 10) ∧ x - 1 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (9999999999 / 10 ^ 10) (10000000001 / 10 ^ 10) ∧ x - 1 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [0.9999999999, 1.0000000001], within 10^-10 of 1.0000000000: endpoint signs and a derivative of one sign, checked by the kernel
Options (2)
(digits := 20) gives 20 decimal places, here of :
#cas (digits := 20) [findRoot x in [0, 2]] (exp x - 3)
certified simple root
x = 1.09861228866810969140 ± 10^-20- Domain
x ∈ [0, 2]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (109861228866810969139 / 10 ^ 20) (109861228866810969141 / 10 ^ 20) ∧ Real.exp x - 3 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (109861228866810969139 / 10 ^ 20) (109861228866810969141 / 10 ^ 20) ∧ Real.exp x - 3 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [1.09861228866810969139, 1.09861228866810969141], within 10^-20 of 1.09861228866810969140: endpoint signs and a derivative of one sign, checked by the kernel
At most 30 places:
#cas (digits := 30) [findRoot x in [1, 2]] (x^2 - 2)
certified simple root
x = 1.414213562373095048801688724210 ± 10^-30- Domain
x ∈ [1, 2]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (1414213562373095048801688724209 / 10 ^ 30) (1414213562373095048801688724211 / 10 ^ 30) ∧ x ^ 2 - 2 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (1414213562373095048801688724209 / 10 ^ 30) (1414213562373095048801688724211 / 10 ^ 30) ∧ x ^ 2 - 2 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [1.414213562373095048801688724209, 1.414213562373095048801688724211], within 10^-30 of 1.414213562373095048801688724210: endpoint signs and a derivative of one sign, checked by the kernel
Applications (2)
Bounds on the root in a proof. cas proves them, and only the three standard axioms are used:
theorem findRoot_cos : ∃ x : ℝ, Real.cos x = x ∧ 0.739 < x ∧ x < 0.74 := by cas #print axioms findRoot_cos
findRoot_cos depends on the axioms propext, Classical.choice, Quot.sound.
Uniqueness on the whole interval needs a derivative of one sign on it, and on :
example : ∃! x : ℝ, x ∈ Set.Icc (0 : ℝ) 1 ∧ Real.cos x = x := by cas
Lean accepts the proof.
Properties and Relations (1)
For a polynomial, roots finds every real root at once, here both square roots of 2:
#cas (digits := 40) [roots x] (x^2 = 2)
all 2 real solutions; enclosed ones by 40 decimals, truncated
-1.4142135623730950488016887242096980785696, 1.4142135623730950488016887242096980785696- Input (polynomial equation)
(x^2 = 2)
Checked by Lean’s kernel: Complete list of real solutions
((∃! x,
x ∈
Set.Ioo (-14142135623730950488016887242096980785697 / 10 ^ 40)
(-14142135623730950488016887242096980785696 / 10 ^ 40) ∧
x ^ 2 - 2 = 0) ∧
∃! x,
x ∈
Set.Ioo (14142135623730950488016887242096980785696 / 10 ^ 40)
(14142135623730950488016887242096980785697 / 10 ^ 40) ∧
x ^ 2 - 2 = 0) ∧
∀ (x : ℝ),
x ^ 2 - 2 = 0 →
x ∈
Set.Ioo (-14142135623730950488016887242096980785697 / 10 ^ 40)
(-14142135623730950488016887242096980785696 / 10 ^ 40) ∨
x ∈
Set.Ioo (14142135623730950488016887242096980785696 / 10 ^ 40)
(14142135623730950488016887242096980785697 / 10 ^ 40)from CAS.Polynomial.RealRoot.of_exprRootCheck
The certificate: 1 checked step
Complete list of real solutions
((∃! x, x ∈ Set.Ioo (-14142135623730950488016887242096980785697 / 10 ^ 40) (-14142135623730950488016887242096980785696 / 10 ^ 40) ∧ x ^ 2 - 2 = 0) ∧ ∃! x, x ∈ Set.Ioo (14142135623730950488016887242096980785696 / 10 ^ 40) (14142135623730950488016887242096980785697 / 10 ^ 40) ∧ x ^ 2 - 2 = 0) ∧ ∀ (x : ℝ), x ^ 2 - 2 = 0 → x ∈ Set.Ioo (-14142135623730950488016887242096980785697 / 10 ^ 40) (-14142135623730950488016887242096980785696 / 10 ^ 40) ∨ x ∈ Set.Ioo (14142135623730950488016887242096980785696 / 10 ^ 40) (14142135623730950488016887242096980785697 / 10 ^ 40)
The computation
Certified isolation
Square-free polynomial of degree 2, Cauchy bound 3, 6 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
Possible Issues (3)
A double root does not change sign. Find the root of the derivative, or use roots for a polynomial:
#cas [findRoot x in [-1, 1]] (x^2)
Error
findRoot: no sign change of the expression at 65 equally spaced points of [-1, 1]; a root of even multiplicity, or two roots closer than the sample spacing, has no certificate here
At a triple root the derivative vanishes too, and the sign near the root cannot be decided:
#cas [findRoot x in [-1, 1]] (x^3)
Error
findRoot: the sign change could not be narrowed below [-1/34359738368, 7/274877906944] (interval evaluation does not decide the sign near the root); ask for fewer digits
changes sign at its pole and has no root. Choose an interval without poles:
#cas [findRoot x in [0, 2]] (1 / (x - 1))
Error
findRoot: the derivative cannot be evaluated on [9999999999/10000000000, 10000000001/10000000000], where the sign changes; the expression may have a singularity there rather than a root
Neat Examples (2)
The omega constant, the root of :
#cas [findRoot x in [0, 1]] (x * exp x - 1)
certified simple root
x = 0.5671432904 ± 10^-10- Domain
x ∈ [0, 1]
Checked by Lean’s kernel: Unique root in the interval
∃! x, x ∈ Set.Icc (5671432903 / 10 ^ 10) (5671432905 / 10 ^ 10) ∧ x * Real.exp x - 1 = 0
The certificate: 1 checked step
Unique root in the interval
∃! x, x ∈ Set.Icc (5671432903 / 10 ^ 10) (5671432905 / 10 ^ 10) ∧ x * Real.exp x - 1 = 0
The computation
Certified root
Sign change found by interval sampling and bisection (not proof) Unique root in [0.5671432903, 0.5671432905], within 10^-10 of 0.5671432904: endpoint signs and a derivative of one sign, checked by the kernel
The same root as a goal:
example : ∃ x ∈ Set.Icc (0 : ℝ) 1, x * Real.exp x = 1 := by cas
Lean accepts the proof.
