Tactic

cas?

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

cas?
proves the goal as cas does, and suggests the call to keep in the proof.
cas? using h, cas? using [h₁, h₂], cas? [l₁, l₂]
the same for the other forms of cas, with the same arguments.
cas? [integrate primitive := F]
the same for a supplied primitive, also with using h inside the brackets.

I write cas? while a proof is still taking shape. It closes the goal as cas would, then tells me which route did it and what to write instead. When the box query proved a bound, the suggestion names the box and the expression, so the finished proof says what it checks. When FloatLib’s check proved it, the suggestion is bare cega, which runs that check again.

Details and Options

  • After the box route, the suggestion is bare cega when FloatLib’s check proved the bound, and cega [enclose x in [a, b]] e, with the box and the expression that the route used, when the box query proved it.
  • After the integration route, when it checked a primitive F written as an ordinary function, the suggestion is cas [integrate primitive := F].
  • Either one is suggested only when it closes the original goal with no error. Otherwise the suggestion is the call as written.
  • Lean runs the suggested call on the original goal before it shows it. The line under the suggestion names the route that closed the goal, and the InfoView, the editor panel where Lean shows its messages, shows that route with its checked evidence.
  • set_option cas.verbose true replaces that line by the full report, with the planner steps and the checked evidence. It is false by default.
  • cas? fails where cas fails, with the message of cas, and then suggests nothing.
  • The other options are those of cas.

Examples (14)#

Basic Examples (3)

A polynomial identity. The suggestion is plain cas, and the line under it names the route:

In[1]:=
example (x : ℝ) : (x + 1) ^ 2 = x ^ 2 + 2 * x + 1 := by
  cas?
Out[1]=

Try this

cas

Lean checked the suggested replacement against the original goal. Selected route: CAS route: ordinary Lean simplification/arithmetic.

A bound on a box. The route was the box route of cega, and FloatLib’s check proved the bound, so the suggestion is bare cega:

In[2]:=
example (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.exp x ≤ 3 := by
  cas?
Out[2]=

Try this

cega

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked CEGA box enclosure of an ordinary inequality.

A definite integral, by a search for an antiderivative:

In[3]:=
example : (∫ x in (0 : ℝ)..1, x * Real.exp x) = 1 := by
  cas?
Out[3]=

Try this

cas

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked integration, bounded antiderivative search.

Scope (4)

Evidence for a domain condition, as in cas using:

In[4]:=
example (x : ℝ) (hx : 0 < x) :
    deriv (fun t : ℝ ↦ t ^ (3 / 2 : ℝ)) x = (3 / 2 : ℝ) * x ^ (1 / 2 : ℝ) := by
  cas? using hx
Out[4]=

Try this

cas using hx

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked symbolic derivative.

Equation hypotheses as facts:

In[5]:=
example (x y : ℝ) (h₁ : x + y = 3) (h₂ : x - y = 1) : x = 2 := by
  cas? using [h₁, h₂]
Out[5]=

Try this

cas using [h₁, h₂]

Lean checked the suggested replacement against the original goal. Selected route: CAS route: polynomial consequences of equation hypotheses.

A definition to unfold:

In[6]:=
def square (x : ℝ) : ℝ := x * x

example (x : ℝ) : square (x + 1) = x ^ 2 + 2 * x + 1 := by
  cas? [square]
Out[6]=

Try this

cas [square]

Lean checked the suggested replacement against the original goal. Selected route: CAS route: ordinary Lean simplification/arithmetic.

A supplied primitive, with and without domain evidence:

In[7]:=
example : (∫ x in (0 : ℝ)..1, 2 * x) = 1 := by
  cas? [integrate primitive := fun x ↦ x ^ 2]
Out[7]=

Try this

cas [integrate primitive := fun x ↦ x ^ 2]

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked integration, explicit primitive verification.
In[8]:=
example (a b : ℝ) (h : ∀ t ∈ Set.uIcc a b, t ≠ 0) :
    (∫ t in a..b, Real.log t / t) = Real.log b ^ 2 / 2 - Real.log a ^ 2 / 2 := by
  cas? [integrate primitive := fun t ↦ Real.log t ^ 2 / 2 using h]
Out[8]=

Try this

cas [integrate primitive := fun t ↦ Real.log t ^ 2 / 2 using h]

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked integration, explicit primitive verification.

Options (1)

set_option cas.verbose true shows the full report under the suggestion:

In[9]:=
set_option cas.verbose true in
example (x : ℝ) : Real.sin x ^ 2 + Real.cos x ^ 2 = 1 := by
  cas?
Out[9]=

Try this

cas

[CAS.explanation] Proof evidence
  [CAS.explanation.checkedEvidence] Checked proof steps
    [CAS.explanation.checkedStep] final proof assigned to the original goal
      Proposition: Real.sin x ^ 2 + Real.cos x ^ 2 = 1
      Validation: completed proof checked by the elaborator; kernel check occurs when the declaration is accepted
  [CAS.explanation.plannerMetadata] Planner metadata (not proof)
    [CAS.explanation.plannerStep] CAS route: ordinary Lean simplification/arithmetic: selected

Applications (1)

The suggested call replaces cas?, and the theorem keeps it. Only the three standard axioms are used:

In[10]:=
theorem exp_le_three (x : ℝ) (h₀ : 0 ≤ x) (h₁ : x ≤ 1) : Real.exp x ≤ 3 := by
  cega

#print axioms exp_le_three
Out[10]=

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

Properties and Relations (2)

cega? does the same for cega:

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

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 limit, written with Mathlib’s filters. The statement is one that limit prints:

In[12]:=
open Filter Topology in
example : Tendsto (fun x : ℝ ↦ Real.sin x / x) (𝓝[≠] 0) (𝓝 1) := by
  cas?
Out[12]=

Try this

cas

Lean checked the suggested replacement against the original goal. Selected route: CAS route: theorem of a #cas command.

Possible Issues (2)

cas? fails where cas fails, with the message of cas:

In[13]:=
example (x : ℝ) : Real.sin x ^ 2 + Real.cos x ^ 2 = 2 := by
  cas?
Out[13]=

Error

cas could not prove this arithmetic relation. The statement may be false, or it may lie outside the supported normalization and arithmetic fragment
The rest of the message
Polynomial equation route:
  `grind` failed
  case grind
  x : ℝ
  h : ¬Real.sin x ^ 2 + Real.cos x ^ 2 = 2
  ⊢ False
  [grind] Goal diagnostics
    [facts] Asserted facts
      [prop] ¬Real.sin x ^ 2 + Real.cos x ^ 2 = 2
    [eqc] False propositions
      [prop] Real.sin x ^ 2 + Real.cos x ^ 2 = 2
    [eqc] Equivalence classes
      [eqc] {1, (Real.sin x ^ 2 + Real.cos x ^ 2 - 2) * (Real.sin x ^ 2 + Real.cos x ^ 2 - 2)⁻¹}
    [ematch] E-matching patterns
      [thm] Nat.pow_pos: [@HPow.hPow `[ℕ] `[ℕ] `[ℕ] `[instHPow] #2 #1]
      [thm] Nat.div_pow_of_pos: [@HPow.hPow `[ℕ] `[ℕ] `[ℕ] `[instHPow] #2 #1]
    [ring] Ring `ℝ`
      [basis] Basis
        [_] Real.sin x ^ 2 * (Real.sin x ^ 2 + Real.cos x ^ 2 - 2)⁻¹ +
                    Real.cos x ^ 2 * (Real.sin x ^ 2 + Real.cos x ^ 2 - 2)⁻¹ +
                  -2 * (Real.sin x ^ 2 + Real.cos x ^ 2 - 2)⁻¹ +
                -1 =
              0
    [limits] Thresholds reached
      [limit] maximum number of E-matching rounds has been reached, threshold: `(ematch := 0)`
      [limit] maximum number of case-splits has been reached, threshold: `(splits := 0)`
Checked identity route:
  cas could not identify the two sides: the checked normalizer does not reduce their difference to zero.
  Normalized difference:
    CAS.Verified.Expr.int (-1)
  canonical form route: the canonical rational form of the difference is not zero.
  Canonical difference:
    ((𝕏[0].sin.pow 2).add (𝕏[0].cos.pow 2)).sub (CAS.Verified.Expr.nat 2)
Elementary rewrite route:
  no elementary rewrite applies
Grind fallback:
  `grind` failed (`set_option trace.cas.fallback true` shows its diagnostics)

A resource limit is not a refutation. The message names a larger setting to try:

In[14]:=
example (x : ℝ) : x + 1 = 1 + x := by
  set_option maxRecDepth 12 in cas?
Out[14]=

Error

cas exceeded Lean's maximum recursion depth (the option maxRecDepth is 12; some routes run with a higher limit of their own). This is a resource limit, not a refutation of the goal. A larger setting may help: write `set_option maxRecDepth 48 in` before the tactic; or make the goal smaller.

Neat Examples (1)

An integral whose right side is F(b)−F(a) for F(t)=12log2t, with the condition t≠0 on the interval. The suggestion is cas using h:

In[15]:=
theorem log_div_integral_of_goal (a b : ℝ) (h : ∀ t ∈ Set.uIcc a b, t ≠ 0) :
    (∫ t in a..b, Real.log t / t) =
      Real.log b ^ 2 / 2 - Real.log a ^ 2 / 2 := by
  cas? using h
Out[15]=

Try this

cas using h

Lean checked the suggested replacement against the original goal. Selected route: CAS route: checked integration, direct interval calculus.

See Also

cas · cega? · cas using · cas [integrate primitive := F] · cega · Options