lean4-htt/tests/lean/run/grind_nested_proofs.lean
Leonardo de Moura fbfb0757ca
feat: grind interactive mode basic tactics (#10677)
This PR implements the basic tactics for the new `grind` interactive
mode. While many additional `grind` tactics will be added later, the
foundational framework is already operational. The following `grind`
tactics are currently implemented: `skip`, `done`, `finish`, `lia`, and
`ring`.
This PR also removes the notion of `grind` fallback procedure since it
is subsumed by the new framework. Examples:
```lean
example (x y : Nat) : x ≥ y + 1 → x > 0 := by
  grind => skip; lia; done

open Lean Grind

example [CommRing α] (a b c : α)
  : a + b + c = 3 →
    a^2 + b^2 + c^2 = 5 →
    a^3 + b^3 + c^3 = 7 →
    a^4 + b^4 + c^4 = 9 := by
  grind => ring
```
2025-10-06 01:08:26 +00:00

54 lines
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module
meta import Lean.Meta.Tactic.Grind
#exit -- TODO: reenable after we add support for running code in interactive mode
def f (α : Type) [Add α] (a : α) := a + a + a
open Lean Meta Grind in
meta def fallback : Fallback := do
let nodes ← filterENodes fun e => return e.self.isAppOf ``Lean.Grind.nestedProof
trace[Meta.debug] "{nodes.toList.map (·.self)}"
let nodes ← filterENodes fun e => return e.self.isApp && e.self.isAppOf ``GetElem.getElem
let [_, n, _] := nodes.toList | unreachable!
trace[Meta.debug] "{← getEqc n.self}"
(← get).mvarId.admit
set_option trace.Meta.debug true
set_option grind.debug true
set_option grind.debug.proofs true
/-
Recall that array access terms, such as `a[i]`, have nested proofs.
The following test relies on `grind` `nestedProof` wrapper to
detect equalities between array access terms.
-/
/--
trace: [Meta.debug] [i < a.size, j < a.size, j < b.size]
[Meta.debug] [a[j], b[j], a[i]]
-/
#guard_msgs (trace) in
example (i j : Nat) (a b : Array Nat) (h1 : j < a.size) (h : j < b.size) (h2 : i ≤ j) : a[i] < a[j] + b[j] → i = j → a = b → False := by
grind -mbtc on_failure fallback
/--
trace: [Meta.debug] [i < a.size, j < a.size, j < b.size]
[Meta.debug] [a[j], a[i]]
-/
#guard_msgs (trace) in
example (i j : Nat) (a b : Array Nat) (h1 : j < a.size) (h : j < b.size) (h2 : i ≤ j) : a[i] < a[j] + b[j] → i = j → False := by
grind -mbtc on_failure fallback
namespace Test
opaque p : Prop
axiom hp : p
opaque h : p → Prop
example : h (@Lean.Grind.nestedProof p hp) → p := by
grind
example : h hp → p := by
grind
end Test