Tactic
cega using
Proves a goal from a certificate that you built once, by the certificate’s own soundness theorem.
cega using cSome 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.
Examples (9)#
Basic Examples (1)
The examples on this page run after open CAS.Certificate.
A certificate for on , whose sound field cega proves once:
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:
example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) 1 := by cega using cosineEnclosure
Lean accepts the proof.
Scope (2)
A smaller domain. The inclusion comes from a hypothesis:
example (s : Set ℝ) (hs : s ⊆ Set.Icc 0 1) : EnclosedOn Real.cos s (1 / 2 : ℝ) 1 := by cega using cosineEnclosure
Lean accepts the proof.
Wider endpoints, . The certificate is widened, and the comparisons and are proved by arithmetic:
example : EnclosedOn Real.cos (Set.Icc 0 1) (0 : ℝ) 2 := by cega using cosineEnclosure
Lean accepts the proof.
Applications (1)
The enclosure as a step in an ordinary proof. Only the three standard axioms are used:
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
half_le_cos depends on the axioms propext, Classical.choice, Quot.sound.
Properties and Relations (2)
cega? confirms the call, and names the route:
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.
enclose computes an enclosure from scratch, where cega using reuses one:
#cas [enclose x in [0, 1]] (cos x)
certified interval in ℝ
[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
Enclosure of the input
∀ x ∈ Set.Icc 0 1, 0.540302 ≤ Real.cos x ∧ Real.cos x ≤ 1
Upper bound of the input
∀ x ∈ Set.Icc 0 1, Real.cos x ≤ 1
Absolute bound of the input
∀ x ∈ Set.Icc 0 1, |Real.cos x| ≤ 1
Center and radius of the input
∀ x ∈ Set.Icc 0 1, |Real.cos x - 0.770151| ≤ 229849 / 1000000
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)
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)
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)
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)
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:
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
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 certificateA certificate can’t prove more than its own bounds, and tighter ones are refused:
example : EnclosedOn Real.cos (Set.Icc 0 1) (1 / 2 : ℝ) (9 / 10) := by cega using cosineEnclosure
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 becomes one residual certificate. The function is the defect of as a solution of , combined with its derivative under the weights and , with arbitrary amplitudes , and a symbolic tolerance:
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.
Lean accepts the proof.
