lean4-htt/tests/lean/run/sharecommon_mpz.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 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.

import Lean
open Lean Meta Tactic Grind
def runGrind (x : GrindM α) : MetaM α := do
GrindM.run x (← mkParams {})
@[noinline] def mkA (x : Nat) := x + 1
def tst (a b : Nat) : GrindM Unit := do
IO.println a
IO.println b
let a ← shareCommon (mkNatLit a)
let b ← shareCommon (mkNatLit b)
IO.println (isSameExpr a b)
/--
info: 1000000000000000000000000001
1000000000000000000000000001
true
-/
#guard_msgs (info) in
run_meta do
let a := mkA 1000000000000000000000000000
let b := 1000000000000000000000000001
runGrind (tst a b)
/--
info: 1001
1001
true
-/
#guard_msgs (info) in
run_meta do
let a := mkA 1000
let b := 1001
runGrind (tst a b)
def tst2 (a b : Nat) : IO Unit := do
IO.println a
IO.println b
let (a, b) := ShareCommon.shareCommon' (mkNatLit a, mkNatLit b)
IO.println (isSameExpr a b)
/--
info: 1000000000000000000000000001
1000000000000000000000000001
true
-/
#guard_msgs (info) in
run_meta do
let a := mkA 1000000000000000000000000000
let b := 1000000000000000000000000001
tst2 a b