Logical Verification

Table of Contents

Metaprogramming

You can extend Lean with custom tactics/tools; this is metaprogramming.

Tactics, tactic combinators

Combinators help if you have to do the same thing multiple times, or recover from failures.

The metaprogramming monad

meta lets a function call other metafunctions. Tactics have access to:

You can print stuff with tactic.trace. run_cmd can run a tactic.

For example, we can rewrite assumption which looks through all hypotheses in the context and succeeds if it finds one that works with the goal.

meta def exact_list : list expr → tactic unit
| [] := tactic.fail "no matching hypothesis in environment"
| (h :: hs) :=
    do { tactic.trace "trying",
        tactic.trace h,
        tactic.exact h }
    <|> exact_list hs

meta def my_assumption : tactic unit :=
do
    hs ← tactic.local_context,
    exact_list hs

The framework revolves around five main types:

Unelaborated expressions (pre-expressions) omit some information, elaborated expressions have everything.

We can create literal expressions:

Similar for names:

Antiquotation lets you embed existing expression into larger expression, using prefix %% and name from current context. You can also use them in pattern matching, like (%%a + %%b = %%c) ← tactic.target