Tactic

cega?

Proves the goal as cega does, and suggests the call to keep in the proof.

cega?
proves the goal as cega does, and suggests the explicit call to keep in the proof.
cega? (options), cega? [fast], cega? [batch := n]
the same for the other forms of cega, with the same arguments.
cega? [enclose x in [a, b]] e
runs the explicit query, and names the bound that it proved.
cega? using c
the same for cega 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.

Details and Options

  • When the box route closed the goal, the suggestion is bare cega if FloatLib’s check proved the bound, and the query cega [enclose x in [a, b]] e with the box and the expression that the route used if the box query proved it. When FloatLib’s interval proved one inequality, the suggestion is that interval call. Each is suggested only if it closes the original goal. Otherwise the suggestion is the call as written.
  • Bare cega? runs the routes of bare cega, except the kernel certificate of a closed decidable proposition.
  • The line under the suggestion names the route: a box enclosure, a box query with the kind of bound it proved, FloatLib’s interval, quadrature of an integral, or a checked certificate. After cega? (options), cega? [fast] and cega? [batch := n] it only says that Lean checked the suggestion.
  • For a route that computes an enclosure, the line also names the arithmetic: arithmetic: exact rationals, or the format after cega? [use_floats] and cega? (arith := F). The suggestion then carries (arith := F), so that it computes in the same format wherever you paste it.
  • set_option cas.verbose true replaces that line by the full report, as for cas?.
  • cega? refuses the goals that cega refuses, with the same message.
  • cega? [batch := n] needs import CAS.Numerics.Tactic, like cega [batch := n].

Examples (17)#

Basic Examples (3)

A bound on a box, with the proof route shown below the suggestion:

In[1]:=
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.sin x ≤ 0.85 := by
  cega?
Out[1]=

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:

In[2]:=
example : Real.sqrt 2 ≤ 1.415 := by
  cega?
Out[2]=

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 x(1−x)≤14 on [0,1]:

In[3]:=
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
  cega?
Out[3]=

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:

In[4]:=
example : (3 / 11 : ℝ) ≤ Real.exp (-1) := by
  cega?
Out[4]=

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:

In[5]:=
example : |(∫ x in (0 : ℝ)..1, x ^ 2) - 1 / 3| ≤ 1 / 100 := by
  cega?
Out[5]=

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 x. The suggestion is that interval call:

In[6]:=
example (x : ℝ) : Real.sin x ≤ 1.5 := by
  cega?
Out[6]=

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:

In[7]:=
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
  cega? [enclose x in [0, 1]] (x * (1 - x))
Out[7]=

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:

In[8]:=
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))
Out[8]=

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:

In[9]:=
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * (1 - x) ≤ 1 / 4 := by
  cega? (depth := 3)
Out[9]=

Try this

cega (depth := 3)

Lean checked the suggested replacement against the original goal.
In[10]:=
example (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : x * x ≤ 1 := by
  cega? [fast]
Out[10]=

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:

In[11]:=
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.exp x ≤ 2.72 := by
  cega? [use_floats]
Out[11]=

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:

In[12]:=
example : ∀ i : Fin 10, i.val * i.val < 100 := by
  cega? [batch := 3]
Out[12]=

Try this

cega [batch := 3]

Lean checked the suggested replacement against the original goal.
In[13]:=
example : ∀ i : Fin 10, i.val * i.val < 100 := by
  cega? [fast, batch := 4]
Out[13]=

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:

In[14]:=
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
Out[14]=

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

Properties and Relations (2)

enclose prints the interval behind that query:

In[15]:=
#cas [enclose x in [0, 1]] (sin x)
Out[15]=

certified interval in ℝ

[0, 0.841471]
[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
  1. Enclosure of the input

    ∀ x ∈ Set.Icc 0 1, 0 ≤ Real.sin x ∧ Real.sin x ≤ 0.841471

    Checked by Lean’s kernel · CAS.Tactic.BoxInequality.mem_of_enclosedOn_box

  2. Upper bound of the input

    ∀ x ∈ Set.Icc 0 1, Real.sin x ≤ 0.841471

    Checked by Lean’s kernel · CAS.Tactic.BoxInequality.le_of_boundOn_box

  3. Absolute bound of the input

    ∀ x ∈ Set.Icc 0 1, |Real.sin x| ≤ 0.841471

    Checked by Lean’s kernel · CAS.Tactic.BoxInequality.abs_le_of_boundOn_abs_box

  4. Center and radius of the input

    ∀ x ∈ Set.Icc 0 1, |Real.sin x - 0.420735| ≤ 0.420736

    Checked by Lean’s kernel · CAS.Tactic.BoxInequality.abs_sub_le_of_approxOn_box

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

    Checked by Lean’s kernel · CAS.Continuum.RationalInterval.EnclosureAttempt.enclosedOn_of_interval_eq

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

    Checked by Lean’s kernel · CAS.Continuum.RationalInterval.EnclosureAttempt.boundOn_of_interval_eq

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

    Checked by Lean’s kernel · CAS.Continuum.RationalInterval.EnclosureAttempt.boundOn_abs_of_interval_eq

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

    Checked by Lean’s kernel · CAS.Continuum.RationalInterval.EnclosureAttempt.approxOn_center_of_interval_eq

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:

In[16]:=
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
Out[16]=

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 x, so there is no box:

In[17]:=
example (x : ℝ) : x * (1 - x) ≤ 1 / 4 := by
  cega?
Out[17]=

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 sin1>0.84:

In[18]:=
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.sin x ≤ 0.8 := by
  cega?
Out[18]=

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:

In[19]:=
example (x y : ℝ) (hx : 0 ≤ x) (hx' : x ≤ 1) (hy : 2 ≤ y) (hy' : y ≤ 3) :
    Real.exp (x * y) ≤ 21 := by
  cega?
Out[19]=

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