Tactic

cega using

Proves a goal from a certificate that you built once, by the certificate’s own soundness theorem.

cega using c
proves the goal from the certificate c by its soundness theorem, restricted to the domain of the goal when that domain is smaller and weakened to the bounds of the goal when they are wider.

Some bounds take a while to prove, and I need them more than once. So I prove the bound once, store it in a certificate, and use it wherever it is needed with cega using. The function is not evaluated again: the proof is the certificate’s own theorem.

Details and Options

  • A certificate is one of the structures of SymLean that come with a soundness theorem: EnclosureCert, BoundCert, ApproxCert, ResidualCert, ModelApproxCert or QuadratureCert. A CertificateRoute to an enclosure, bound or residual certificate works too, as does a type registered with cega_carrier. An atlas enters through its toResidualCert or toApproxCert.
  • cega using c first tries the theorem c.sound as it is. When the goal asks for less, the certificate is weakened: an enclosure to wider endpoints, and a bound, an approximation, a residual or a quadrature certificate to a larger budget. The comparisons between the numbers of the certificate and those of the goal are proved by the arithmetic of cas. The numbers are read off the definition of the certificate, also through rules such as c.restrict or a.sub b. A certificate that is a hypothesis, or a definition that Lean may not unfold, has no numbers to read, and is used only as it is.
  • When the domain of the goal is smaller, the certificate is restricted to it, with the inclusion proved by assumption, simp_all or aesop, and then tried in the same way.
  • A term of any other type is refused. An ordinary proof goes in with exact.
  • The proof keeps every hypothesis and axiom that the proof of c uses, a native-evaluation axiom included. cega using checks that the theorem fits the goal, not how c was made, and #print axioms shows what your theorem depends on.
  • There are no options. The certificate propositions EnclosedOn, BoundOn and ApproxOn need open CAS.Certificate.

Examples (9)#

Basic Examples (1)

The examples on this page run after open CAS.Certificate.

A certificate for 12≤cosx≤1 on [0,1], whose sound field cega proves once:

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

cega using turns it into the theorem:

In[2]:=
example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by
  cega using cosineEnclosure
Out[2]=

Lean accepts the proof.

Scope (2)

A smaller domain. The inclusion comes from a hypothesis:

In[3]:=
example (s : Set ℝ) (hs : s ⊆ Set.Icc 0 1) : EnclosedOn Real.cos s (1 / 2 : ℝ) 1 := by
  cega using cosineEnclosure
Out[3]=

Lean accepts the proof.


Wider endpoints, 0≤cosx≤2. The certificate is widened, and the comparisons 0≤12 and 1≤2 are proved by arithmetic:

In[4]:=
example : EnclosedOn Real.cos (Set.Icc 0 1) (0 : ℝ) 2 := by
  cega using cosineEnclosure
Out[4]=

Lean accepts the proof.

Applications (1)

The enclosure as a step in an ordinary proof. Only the three standard axioms are used:

In[5]:=
theorem half_le_cos (x : ℝ) (h0 : 0 ≤ x) (h1 : x ≤ 1) : 1 / 2 ≤ Real.cos x := by
  have h : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by
    cega using cosineEnclosure
  exact (h x ⟨h0, h1⟩).1

#print axioms half_le_cos
Out[5]=

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

Properties and Relations (2)

cega? confirms the call, and names the route:

In[6]:=
example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by
  cega? using cosineEnclosure
Out[6]=

Try this

cega using cosineEnclosure

Lean checked the suggested replacement against the original goal. Selected route: CEGA route: checked certificate.

enclose computes an enclosure from scratch, where cega using reuses one:

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

certified interval in ℝ

[0.540302, 1]
[0.540302, 1]
Domain
x ∈ [0, 1] ⊆ ℝ
Upper bound
1
Absolute bound
1
Center and radius
≈0.770151 ± 0.229849

Checked by Lean’s kernel: Enclosure of the input

∀ x ∈ Set.Icc 0 1, 0.540302 ≤ Real.cos x ∧ Real.cos x ≤ 1

from CAS.Tactic.BoxInequality.mem_of_enclosedOn_box

The certificate: 8 checked steps
  1. Enclosure of the input

    ∀ x ∈ Set.Icc 0 1, 0.540302 ≤ Real.cos x ∧ Real.cos x ≤ 1

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

  2. Upper bound of the input

    ∀ x ∈ Set.Icc 0 1, Real.cos x ≤ 1

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

  3. Absolute bound of the input

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

    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.cos x - 0.770151| ≤ 229849 / 1000000

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

  5. Certified enclosure

    EnclosedOn (CAS.Exact.exprFn 𝕏[0].cos)
      (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦
        [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate)
      (↑183855347493651442427684920285310598403 / ↑340282366920938463463374607431768211456) (↑1 / ↑1)

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

  6. Certified upper bound

    BoundOn (CAS.Exact.exprFn 𝕏[0].cos)
      (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦
        [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate)
      (↑1 / ↑1)

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

  7. Certified absolute bound

    BoundOn (fun x ↦ |CAS.Exact.exprFn 𝕏[0].cos x|)
      (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦
        [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate)
      (↑1 / ↑1)

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

  8. Certified center and radius

    ApproxOn (CAS.Exact.exprFn 𝕏[0].cos)
      (fun x ↦ ↑524137714414589905891059527717078809859 / ↑680564733841876926926749214863536422912)
      (CAS.Continuum.RationalInterval.boxDomain fun coordinate ↦
        [CAS.Continuum.RationalInterval.ofBounds 0 1 ⋯].get coordinate)
      (↑156427019427287021035689687146457613053 / ↑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: [183855347493651442427684920285310598403/340282366920938463463374607431768211456, 1]

Possible Issues (2)

A proof is not a certificate. Here exact h closes the goal:

In[8]:=
example (h : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1) :
    EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by
  cega using h
Out[8]=

Error

cega expected a registered checked carrier or direct certificate proving the current semantic target:
  the term has the type
    EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2) 1
  which is no certificate

A certificate can’t prove more than its own bounds, and tighter ones are refused:

In[9]:=
example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) (9 / 10) := by
  cega using cosineEnclosure
Out[9]=

Error

cega expected a registered checked carrier or direct certificate proving the current semantic target:
  certificate enclosure weakening left arithmetic side conditions unresolved
    [1 ≤ 9 / 10]

Neat Examples (1)

From the library’s examples: an atlas of two patches covering [0,1] becomes one residual certificate. The function is the defect p′−p of p(x)=1+x+x2/2 as a solution of u′=u, combined with its derivative under the weights x and 1−x, with arbitrary amplitudes a, b and a symbolic tolerance:

In[10]:=
theorem weighted_defect_bound (a b eps : ℝ)
    (hright : |a| / 2 + |b| / 2 ≤ eps) :
    ResidualBound
      (fun x ↦ x * (a * defect x) + (1 - x) * (b * deriv defect x))
      (Set.Icc 0 1) eps := by
  have hleft : |a| / 16 + |b| / 2 ≤ eps := by linarith [abs_nonneg a]
  have h : ResidualBound (fun x ↦ ∑ j : Bool, weights j x • residuals a b j x)
      (Set.Icc 0 1) eps := by
    cega using (weightedAtlas a b eps hleft hright).toResidualCert
  simpa only [Fintype.sum_bool, weights, residuals, smul_eq_mul] using h

Quoted from CAS/Examples/Numerics/WeightedResidual.lean, which its own build compiles.

Out[10]=

Lean accepts the proof.

See Also

cega · cega? · enclose · cas using