Tactic
cega?
Proves the goal as cega does, and suggests the call to keep in the proof.
cega?cega does, and suggests the explicit call to keep in the proof.cega? (options), cega? [fast], cega? [batch := n]cega, with the same arguments.cega? [enclose x in [a, b]] ecega? using ccega using.When the enclosure query can prove a bound on a box, I like to keep the box in the proof. cega? can suggest cega [enclose x in [a, b]] e, so whoever reads the proof later sees what was enclosed, and where. If FloatLib’s direct bound refutation proves the goal, the suggestion uses bare cega, with an arithmetic option when needed.
Examples (17)#
Basic Examples (3)
A bound on a box, with the proof route shown below the suggestion:
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.sin x ≤ 0.85 := by cega?
Try this
cega Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: exact rationals.
A closed constant needs no binding:
example : Real.sqrt 2 ≤ 1.415 := by cega?
Try this
cega Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: exact rationals.
The sharp bound on :
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by cega?
Try this
cega [enclose x in [0, 1]] (x * (1 - x)) Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: exact rationals.
Scope (5)
A lower bound on a constant. Here the suggestion is plain cega:
example : (3 / 11 : ℝ) ≤ Real.exp (-1) := by cega?
Try this
cega Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: exact rationals.
A bound on an integral, by quadrature:
example : |(∫ x in (0 : ℝ)..1, x ^ 2) - 1 / 3| ≤ 1 / 100 := by cega?
Try this
cega Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked batch quadrature of an interval integral, arithmetic: exact rationals.
A bound on a trigonometric polynomial, which FloatLib’s interval proves from its coefficients with no bounds on . The suggestion is that interval call:
example (x : ℝ) : Real.sin x ≤ 1.5 := by cega?
Try this
interval
Lean checked the suggested replacement against the original goal. Selected route: CEGA route: interval evaluation of a real inequality (FloatLib's interval), arithmetic: exact rationals.The explicit query itself. The line under the suggestion says which bound it proved:
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by cega? [enclose x in [0, 1]] (x * (1 - x))
Try this
cega [enclose x in [0, 1]] (x * (1 - x)) Lean checked the suggested replacement against the original goal. Selected route: CEGA box query: upper bound, arithmetic: exact rationals.
The examples from here on run after open CAS.Certificate.
A certificate proposition, with options inside the query:
example : EnclosedOn (fun p : ℝ^1 ↦ p 0 / (1 + p 0)) {p : ℝ^1 | 0 ≤ p 0 ∧ p 0 ≤ 1} 0 (1 / 2) := by cega? (depth := 2) [enclose x in [0, 1]] (x / (1 + x))
Try this
cega (depth := 2) [enclose x in [0, 1]] (x / (1 + x)) Lean checked the suggested replacement against the original goal. Selected route: CEGA box query: enclosure after checked box refinement, arithmetic: exact rationals.
Options (3)
With options or a flag, the suggestion is the call as written:
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by cega? (depth := 3)
Try this
cega (depth := 3) Lean checked the suggested replacement against the original goal.
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * x ≤ 1 := by cega? [fast]
Try this
cega [fast]
Lean checked the suggested replacement against the original goal.With [use_floats] the suggestion names the format, and the line under it the arithmetic:
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.exp x ≤ 2.72 := by cega? [use_floats]
Try this
cega (arith := binary64)
Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: binary64 floating point.The batch forms:
example : ∀ i : Fin 10, i.val * i.val < 100 := by cega? [batch := 3]
Try this
cega [batch := 3] Lean checked the suggested replacement against the original goal.
example : ∀ i : Fin 10, i.val * i.val < 100 := by cega? [fast, batch := 4]
Try this
cega [fast, batch := 4] Lean checked the suggested replacement against the original goal.
Applications (1)
The suggestion replaces cega? in the theorem. Only the three standard axioms are used:
theorem cega_sin_bound (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.sin x ≤ 0.85 := by cega [enclose x in [0, 1]] (Real.sin x) #print axioms cega_sin_bound
cega_sin_bound depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (2)
enclose prints the interval behind that query:
#cas [enclose x in [0, 1]] (sin x)
certified interval in ℝ
[0, 0.841471]- Domain
x ∈ [0, 1] ⊆ ℝ- Upper bound
0.841471- Absolute bound
0.841471- Center and radius
≈0.420735 ± 0.420736
Checked by Lean’s kernel: Enclosure of the input
∀ x ∈ Set.Icc 0 1, 0 ≤ Real.sin x ∧ Real.sin x ≤ 0.841471
from CAS.Tactic.BoxInequality.mem_of_enclosedOn_box
The certificate: 8 checked steps
Enclosure of the input
∀ x ∈ Set.Icc 0 1, 0 ≤ Real.sin x ∧ Real.sin x ≤ 0.841471
Upper bound of the input
∀ x ∈ Set.Icc 0 1, Real.sin x ≤ 0.841471
Absolute bound of the input
∀ x ∈ Set.Icc 0 1, |Real.sin x| ≤ 0.841471
Center and radius of the input
∀ x ∈ Set.Icc 0 1, |Real.sin x - 0.420735| ≤ 0.420736
Certified enclosure
EnclosedOn (CAS.Exact.exprFn 𝕏[0].sin) (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦ [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate) (↑0 / ↑1) (↑286337738405724074564845076175058320435 / ↑340282366920938463463374607431768211456)
Certified upper bound
BoundOn (CAS.Exact.exprFn 𝕏[0].sin) (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦ [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate) (↑286337738405724074564845076175058320435 / ↑340282366920938463463374607431768211456)
Certified absolute bound
BoundOn (fun x ↦ |CAS.Exact.exprFn 𝕏[0].sin x|) (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦ [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate) (↑286337738405724074564845076175058320435 / ↑340282366920938463463374607431768211456)
Certified center and radius
ApproxOn (CAS.Exact.exprFn 𝕏[0].sin) (fun x ↦ ↑286337738405724074564845076175058320435 / ↑680564733841876926926749214863536422912) (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦ [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate) (↑286337738405724074564845076175058320435 / ↑680564733841876926926749214863536422912)
The computation
Coordinates: x Certified domain: x ∈ [0, 1] ⊆ ℝ
Certified numerical guarantee
Guarantee: the input lies in the output interval throughout the box Decimal preview: outward-rounded to 6 places where it is a bound Exact certified output: [0, 286337738405724074564845076175058320435/340282366920938463463374607431768211456]
cega using projects a certificate that you built yourself, and cega? names it:
noncomputable def cosineEnclosure : EnclosureCert ℝ (Set.Icc 0 1) where fn := Real.cos lo := 1 / 2 hi := 1 sound := by intro x hx obtain ⟨h0, h1⟩ := hx constructor <;> cega example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by cega? using cosineEnclosure
Try this
cega using cosineEnclosure Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked certificate.
Possible Issues (2)
cega? refuses what cega refuses. Here no hypothesis bounds , so there is no box:
example (x : ℝ) : x * (1 - x) ≤ 1 / 4 := by cega?
Error
cega box route: no rational bounds on `x` in the hypotheses; the route needs hypotheses `a ≤ x` and `x ≤ b`, `x ∈ Set.Icc a b`, or `|x| ≤ r` with rational literal endpoints
Other routes:
carrier search:
cega found no registered checked carrier or direct certificate matching the target
interval route:
interval needs a rational lower bound for x
Bare `cega` proves an ordinary real inequality (`f x ≤ c`, `f x < c`, `c ≤ f x`, `c < f x` (also with `≥` and `>`), `|f x| ≤ c`, `|f x| < c`, `a ≤ f x ∧ f x ≤ b` (also with `<`), `f x ∈ Set.Icc a b` (also `Set.Ioo`, `Set.Ico`, `Set.Ioc`), `f x ≤ g x`, `f x < g x`, and conjunctions of these, with `c`, `a`, `b` closed and every real variable bounded by hypotheses `a ≤ x` and `x ≤ b`, `x ∈ Set.Icc a b`, or `|x| ≤ r` with rational literal endpoints), a bound on an interval integral `∫ x in a..b, f x` with rational limits, a certificate goal (`EnclosedOn f s lo hi`, `BoundOn f s c`, `ApproxOn f g s ε`, `ResidualBound r s ε`) on a coordinate box or from a checked carrier in the local context or the goal, a closed decidable statement about floats, which `float_decide` decides, a real inequality that FloatLib's `interval` proves, on finite sums and norms too, and a closed goal that interval evaluation proves.A false bound. Here :
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.sin x ≤ 0.8 := by cega?
Error
cega box route: comparison with the stated bound: the certified value does not give the stated bound.
↑286337738405724074564845076175058320435 / ↑340282366920938463463374607431768211456 ≤ 0.8
Exact rational arithmetic did not close this comparison.
The query run was `cega [enclose x in [0, 1]]
(Real.sin
x)`; its certified upper bound 286337738405724074564845076175058320435/340282366920938463463374607431768211456 may be too weak for the stated bound. If the bound is true, a deeper subdivision or a higher precision may prove it, as in `cega (depth := 4)` or `cega (prec := 24)`. FloatLib's check, which `cega` tries first, evaluates at most 4096 pieces of the box and cuts a branch at most 32 times.The rest of the message
Subdivision to depth 2 (`cega (depth := 2) [enclose x in [0, 1]] (Real.sin x)`) did not prove it either:
cega box route: comparison with the stated bound: the certified value does not give the stated bound.
↑286337738405724074564845076175058320435 / ↑340282366920938463463374607431768211456 ≤ 0.8
Exact rational arithmetic did not close this comparison.
Other routes:
carrier search:
cega found no registered checked carrier or direct certificate matching the target
interval route:
interval could not certify: on the original box, the expression is enclosed by [-3784231770697581387/4611686018427387904, 1654908495459613035/9223372036854775808]; its upper endpoint does not establish ≤ 0.
Box: x in [0, 1]. Verification used subdivision depth 8. Try tighter input bounds, more subdivision, or higher approximation settings.
The coefficient route did not prove it either: interval: the coefficients alone give the range [-1, 1] for the polynomial, which does not prove the goal; a sharp bound takes a sum-of-squares certificate `(upper := h)`, which `scripts/coeff_cert.py` finds
Bare `cega` proves an ordinary real inequality (`f x ≤ c`, `f x < c`, `c ≤ f x`, `c < f x` (also with `≥` and `>`), `|f x| ≤ c`, `|f x| < c`, `a ≤ f x ∧ f x ≤ b` (also with `<`), `f x ∈ Set.Icc a b` (also `Set.Ioo`, `Set.Ico`, `Set.Ioc`), `f x ≤ g x`, `f x < g x`, and conjunctions of these, with `c`, `a`, `b` closed and every real variable bounded by hypotheses `a ≤ x` and `x ≤ b`, `x ∈ Set.Icc a b`, or `|x| ≤ r` with rational literal endpoints), a bound on an interval integral `∫ x in a..b, f x` with rational limits, a certificate goal (`EnclosedOn f s lo hi`, `BoundOn f s c`, `ApproxOn f g s ε`, `ResidualBound r s ε`) on a coordinate box or from a checked carrier in the local context or the goal, a closed decidable statement about floats, which `float_decide` decides, a real inequality that FloatLib's `interval` proves, on finite sums and norms too, and a closed goal that interval evaluation proves.Neat Examples (1)
A bound on a box in two variables:
example (x y : ℝ) (hx : 0 ≤ x) (hx' : x ≤ 1) (hy : 2 ≤ y) (hy' : y ≤ 3) : Real.exp (x * y) ≤ 21 := by cega?
Try this
cega Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked box enclosure of an ordinary inequality, arithmetic: exact rationals.
See Also
cega · cas? · cega using · enclose · Options
