Skip to the content.
← Index Next: Decision procedures →

Throughout this book, a lemma name has typically been hunted for by hand. In practice, searching by memory or by grep is rarely necessary. Two tactics perform this search automatically:

Both are search tools, not proof techniques. The proof they find is a normal term, exactly like one that could have been written by hand. It is completely standard practice to try out a proof with exact?/apply?, inspect what it suggests, and paste in the concrete result, rather than leaving the search tactic itself in the finished proof. They are slower to re-run, and in a growing file, their result can silently change if the environment changes.

example (a b : Nat) (h : a = b) : b = a := by
  exact?
  -- reports a working closing term (verified on this book's toolchain to be
  -- `exact Nat.add_right_cancel (congrFun (congrArg HAdd.hAdd (id (Eq.symm h))) a)`,
  -- not the shorter `h.symm` a human would write — see below)

Mathematical reading. This is the formal version of “this is standard — cite the relevant lemma.” The goal $b = a$ under hypothesis $h : a = b$ is closed by symmetry of equality, $h^{\mathrm{sym}}$, and that is what a human proof would cite. exact? performs a library search: it scans the whole collection of proved theorems for a term that matches the goal type, and reports a citation that works. But its search order does not always surface the shortest or most idiomatic one. The verified output above shows this directly: a correct but needlessly roundabout term, found before the simpler Eq.symm was. It automates finding a closing term, not necessarily the most readable one; simplifying the reported term by hand (here, to h.symm) afterward is still worth doing before the proof is considered finished.


← Index Next: Decision procedures →
Try Lean
Lean playground · v1.4.18