You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
doc: move the deftech key prefixes to the mvcgen documents
The vcgen chapter and tutorial define and reference their technical
terms under the plain keys. The mvcgen chapter and tutorial carry an
"mvcgen " prefix on their deftech keys, and their tech references name
those keys explicitly, so each document pair links within itself.
Verified with ./generate-html.sh on nightly-2026-08-19.
Copy file name to clipboardExpand all lines: Manual/MVCGen.lean
+25-25Lines changed: 25 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ tag := "mvcgen-tactic"
40
40
:::
41
41
42
42
The {tactic}`mvcgen` tactic implements a _monadic verification condition generator_:
43
-
It breaks down a goal involving a program written using Lean's imperative {keywordOf Lean.Parser.Term.do}`do` notation into a number of smaller {tech}_verification conditions_ ({deftech}[VCs]) that are sufficient to prove the goal.
43
+
It breaks down a goal involving a program written using Lean's imperative {keywordOf Lean.Parser.Term.do}`do` notation into a number of smaller {tech (key := "mvcgen verification conditions")}_verification conditions_ ({deftech (key := "mvcgen VCs")}[VCs]) that are sufficient to prove the goal.
44
44
In addition to a reference that describes the use of {tactic}`mvcgen`, this chapter includes a {ref "mvcgen-tactic-tutorial" (remote := "tutorials")}[tutorial] that can be read independently of the reference.
45
45
46
46
In order to use the {tactic}`mvcgen` tactic, {module}`Std.Tactic.Do` must be imported and the namespace {namespace}`Std.Do` must be opened.
@@ -52,18 +52,18 @@ In order to use the {tactic}`mvcgen` tactic, {module}`Std.Tactic.Do` must be imp
52
52
53
53
The workflow of {tactic}`mvcgen` consists of the following:
54
54
55
-
1. Monadic programs are re-interpreted according to a {tech}[predicate transformer semantics].
55
+
1. Monadic programs are re-interpreted according to a {tech (key := "mvcgen predicate transformer semantics")}[predicate transformer semantics].
56
56
An instanceof {name}`WP` determines the monad's interpretation.
57
-
Each program is interpreted as a mapping from arbitrary {tech}[postconditions] to the {tech}[weakest precondition] that would ensure the postcondition.
57
+
Each program is interpreted as a mapping from arbitrary {tech (key := "mvcgen postconditions")}[postconditions] to the {tech (key := "mvcgen weakest precondition")}[weakest precondition] that would ensure the postcondition.
58
58
This step is invisible to most users, but library authors who want to enable their monads to work with {tactic}`mvcgen` need to understand it.
59
59
2. Programs are composed from smaller programs.
60
60
Each statement in a {keywordOf Lean.Parser.Term.do}`do`-block is associated with a predicate transformer, and there are general-purpose rules for combining these statements with sequencing and control-flow operators.
61
-
A statement with its pre- and postconditions is called a {tech}_Hoare triple_.
62
-
In a program, the postcondition of each statement should suffice to prove the precondition of the next one, and loops require a specified {deftech}_loop invariant_, which is a statement that must be true at the beginning of the loop and at the end of each iteration.
63
-
Designated {tech}_specification lemmas_ associate functions with Hoare triples that specify them.
61
+
A statement with its pre- and postconditions is called a {tech (key := "mvcgen Hoare triple")}_Hoare triple_.
62
+
In a program, the postcondition of each statement should suffice to prove the precondition of the next one, and loops require a specified {deftech (key := "mvcgen loop invariant")}_loop invariant_, which is a statement that must be true at the beginning of the loop and at the end of each iteration.
63
+
Designated {tech (key := "mvcgen specification lemmas")}_specification lemmas_ associate functions with Hoare triples that specify them.
64
64
3. Applying the weakest-precondition semantics of a monadic program to a desired proof goal results in the precondition that must hold in order to prove the goal.
65
65
Any missing steps such as loop invariants or proofs that a statement's precondition implies its postcondition become new subgoals.
66
-
These missing steps are called the {deftech}_verification conditions_.
66
+
These missing steps are called the {deftech (key := "mvcgen verification conditions")}_verification conditions_.
67
67
The {tactic}`mvcgen` tactic performs this transformation, replacing the goal with its verification conditions.
68
68
During this transformation, {tactic}`mvcgen` uses specification lemmas to discharge proofs about individual statements.
69
69
4. After supplying loop invariants, many verification conditions can in practice be discharged automatically.
@@ -72,10 +72,10 @@ The workflow of {tactic}`mvcgen` consists of the following:
72
72
73
73
# Predicate Transformers
74
74
75
-
A {deftech}_predicate transformer semantics_ is an interpretation of programs as functions from predicates to predicates, rather than values to values.
76
-
A {deftech}_postcondition_ is an assertion that holds after running a program, while a {deftech}_precondition_ is an assertion that must hold prior to running the program in order for the postcondition to be guaranteed to hold.
75
+
A {deftech (key := "mvcgen predicate transformer semantics")}_predicate transformer semantics_ is an interpretation of programs as functions from predicates to predicates, rather than values to values.
76
+
A {deftech (key := "mvcgen postcondition")}_postcondition_ is an assertion that holds after running a program, while a {deftech (key := "mvcgen precondition")}_precondition_ is an assertion that must hold prior to running the program in order for the postcondition to be guaranteed to hold.
77
77
78
-
The predicate transformer semantics used by {tactic}`mvcgen` transforms postconditions into the {deftech}_weakest preconditions_ under which the program will ensure the postcondition.
78
+
The predicate transformer semantics used by {tactic}`mvcgen` transforms postconditions into the {deftech (key := "mvcgen weakest preconditions")}_weakest preconditions_ under which the program will ensure the postcondition.
79
79
An assertion $`P` is weaker than $`P'` if, in all states, $`P'` suffices to prove $`P`, but $`P` does not suffice to prove $`P'`.
80
80
Logically equivalent assertions are considered to be equal.
81
81
@@ -291,7 +291,7 @@ Just as {name}`SPred` represents predicate over states, {name}`SVal` represents
291
291
292
292
## Assertions
293
293
294
-
The language of assertions about monadic programs is parameterized by a {deftech}_postcondition shape_, which describes the inputs to and outputs from a computation in a given monad.
294
+
The language of assertions about monadic programs is parameterized by a {deftech (key := "mvcgen postcondition shape")}_postcondition shape_, which describes the inputs to and outputs from a computation in a given monad.
295
295
Preconditions may mention the initial values of the monad's state, while postconditions may mention the returned value, the final values of the monad's state, and must furthermore account for any exceptions that could have been thrown.
296
296
The postcondition shape of a given monad determines the states and exceptions in the monad.
297
297
{name}`PostShape.pure` describes a monad in which assertions may not mention any states, {name}`PostShape.arg` describes a state value, and {name}`PostShape.except` describes a possible exception.
@@ -321,7 +321,7 @@ Syntactic sugar for a nested sequence of product constructors, terminating in {l
321
321
universe u v
322
322
variable {m : Type u → Type v} {ps : PostShape.{u}} [WP m ps] {P : Assertion ps} {α : Type u} {prog : m α} {Q' : α → Assertion ps}
323
323
```
324
-
Postconditions for programs that might throw exceptions come in two varieties. The {deftech}_total correctness interpretation_ {lean}`⦃P⦄ prog ⦃⇓ r => Q' r⦄` asserts that, given {lean}`P` holds, then {lean}`prog` terminates _and_ {lean}`Q'` holds for the result. The {deftech}_partial correctness interpretation_ {lean}`⦃P⦄ prog ⦃⇓? r => Q' r⦄` asserts that, given {lean}`P` holds, and _if_ {lean}`prog` terminates _then_ {lean}`Q'` holds for the result.
324
+
Postconditions for programs that might throw exceptions come in two varieties. The {deftech (key := "mvcgen total correctness interpretation")}_total correctness interpretation_ {lean}`⦃P⦄ prog ⦃⇓ r => Q' r⦄` asserts that, given {lean}`P` holds, then {lean}`prog` terminates _and_ {lean}`Q'` holds for the result. The {deftech (key := "mvcgen partial correctness interpretation")}_partial correctness interpretation_ {lean}`⦃P⦄ prog ⦃⇓? r => Q' r⦄` asserts that, given {lean}`P` holds, and _if_ {lean}`prog` terminates _then_ {lean}`Q'` holds for the result.
325
325
:::
326
326
327
327
@@ -375,7 +375,7 @@ Syntactic sugar for {name}`PostCond.imp`
375
375
## Predicate Transformers
376
376
377
377
A predicate transformer is a function from postconditions for some postcondition state into assertions for that state.
378
-
The function must be {deftech}_conjunctive_, which means it must distribute over {name}`PostCond.and`.
378
+
The function must be {deftech (key := "mvcgen conjunctive")}_conjunctive_, which means it must distribute over {name}`PostCond.and`.
379
379
380
380
{docstring PredTrans}
381
381
@@ -412,7 +412,7 @@ For example, {name}`PredTrans.pushArg` is typically used for state monads, but c
412
412
413
413
### Weakest Preconditions
414
414
415
-
The {tech}[weakest precondition] semantics of a monad are provided by the {name}`WP` type class.
415
+
The {tech (key := "mvcgen weakest precondition")}[weakest precondition] semantics of a monad are provided by the {name}`WP` type class.
416
416
Instances of {name}`WP` determine the monad's postcondition shape and provide the logical rules for interpreting the monad's operations as a predicate transformer in its postcondition shape.
417
417
418
418
{docstring WP}
@@ -531,7 +531,7 @@ tag := "mvcgen-adequacy"
531
531
532
532
Monads that can be invoked from pure code typically provide a invocation operator that takes any required input state as a parameter and returns either a value paired with an output state or some kind of exceptional value.
533
533
Examples include {name}`StateT.run`, {name}`ExceptT.run`, and {name}`Id.run`.
534
-
{deftech}_Adequacy lemmas_ provide a bridge between statements about invocations of monadic programs and those programs' {tech}[weakest precondition] semantics as given by their {name}`WP` instances.
534
+
{deftech (key := "mvcgen Adequacy lemmas")}_Adequacy lemmas_ provide a bridge between statements about invocations of monadic programs and those programs' {tech (key := "mvcgen weakest precondition")}[weakest precondition] semantics as given by their {name}`WP` instances.
535
535
They show that a property about the invocation is trueif its weakest precondition is true.
536
536
537
537
{docstring Id.of_wp_run_eq}
@@ -548,7 +548,7 @@ They show that a property about the invocation is true if its weakest preconditi
548
548
549
549
## Hoare Triples
550
550
551
-
A {deftech}_Hoare triple_{citep hoare69}[] consists of a precondition, a program, and a postcondition.
551
+
A {deftech (key := "mvcgen Hoare triple")}_Hoare triple_{citep hoare69}[] consists of a precondition, a program, and a postcondition.
552
552
Running the program in a state for which the precondition is true results in a state where the postcondition is true.
{deftech}_Specification lemmas_ are designated theorems that associate Hoare triples with functions.
575
-
When {tactic}`mvcgen` encounters a function, it checks whether there are any registered specification lemmas and attempts to use them to discharge intermediate {tech}[verification conditions].
574
+
{deftech (key := "mvcgen Specification lemmas")}_Specification lemmas_ are designated theorems that associate Hoare triples with functions.
575
+
When {tactic}`mvcgen` encounters a function, it checks whether there are any registered specification lemmas and attempts to use them to discharge intermediate {tech (key := "mvcgen verification conditions")}[verification conditions].
576
576
If there is no applicable specification lemma, then the connection between the statement's pre- and postconditions will become a verification condition.
577
577
Specification lemmas allow compositional reasoning about libraries of monadic code.
578
578
@@ -590,7 +590,7 @@ spec $[$_:prio]?
590
590
:::
591
591
592
592
Universally-quantified variables in specification lemmas can be used to relate input states to output states and return values.
593
-
These variables are referred to as {deftech}_schematic variables_.
593
+
These variables are referred to as {deftech (key := "mvcgen schematic variables")}_schematic variables_.
The {tech}[specification lemmas] for {name}`ForIn.forIn` and {name}`ForIn'.forIn'` take parameters of type {name}`Invariant`, and {tactic}`mvcgen` ensures that invariants are not accidentally generated by other automation.
633
+
The {tech (key := "mvcgen specification lemmas")}[specification lemmas] for {name}`ForIn.forIn` and {name}`ForIn'.forIn'` take parameters of type {name}`Invariant`, and {tactic}`mvcgen` ensures that invariants are not accidentally generated by other automation.
634
634
635
635
{docstring Invariant}
636
636
@@ -658,7 +658,7 @@ This type is not a traditional zipper, in which the prefix is reversed for effic
658
658
# Verification Conditions
659
659
660
660
The {tactic}`mvcgen` tactic converts a goal that's expressed in terms of {name}`SPred` and weakest preconditions to a set of invariants and verification conditions that, together, suffice to prove the original goal.
661
-
In particular, {tech}[Hoare triples] are defined in terms of weakest preconditions, so {tactic}`mvcgen` can be used to prove them.
661
+
In particular, {tech (key := "mvcgen Hoare triples")}[Hoare triples] are defined in terms of weakest preconditions, so {tactic}`mvcgen` can be used to prove them.
662
662
663
663
:::leanSection
664
664
```lean -show
@@ -682,7 +682,7 @@ The verification conditions for a goal are generated as follows:
682
682
8. Depending on the tactic's configuration parameters, {tactic}`mvcgen_trivial` and {tactic}`mleave` are attempted in each verification condition.
683
683
:::
684
684
685
-
Verification condition generation can be improved by defining appropriate {tech}[specification lemmas] for a library.
685
+
Verification condition generation can be improved by defining appropriate {tech (key := "mvcgen specification lemmas")}[specification lemmas] for a library.
686
686
The presence of good specification lemmas results in fewer generated verification conditions.
687
687
Additionally, ensuring that the {tech}[simp normal form] of terms is suitable for pattern matching, and that there are sufficient lemmas in the default simp set to reduce every possible term to that normal form, can lead to more conditionals and pattern matches being eliminated.
688
688
@@ -697,11 +697,11 @@ Once the basic instances are provided, the next step is to prove an {ref "mvcgen
697
697
This lemmashouldshowthattheweakestpreconditionforrunningthemonadiccomputationandassertingadesiredpredicateisinfactsufficienttoprovethepredicate.
Eachoftheseshouldbeprovidedwith a {tech}[specification lemma].
700
+
Eachoftheseshouldbeprovidedwith a {tech (key := "mvcgen specification lemma")}[specification lemma].
701
701
It may additionally be useful to make the internals of the state private, and export a carefully-designed set of assertion operators.
702
702
703
703
The specification lemmas for the library's primitive operators should ideally be precise specifications of the operators as predicate transformers.
704
-
While it's often easier to think in terms of how the operator transforms an input state into an output state, {tech}[verification condition] generation will work more reliably when postconditions are completely free.
704
+
While it's often easier to think in terms of how the operator transforms an input state into an output state, {tech (key := "mvcgen verification condition")}[verification condition] generation will work more reliably when postconditions are completely free.
705
705
This allows automation to instantiate the postcondition with the exact precondition of the next statement, rather than needing to show an entailment.
706
706
In other words, specifications that specify the precondition as a function of the postcondition work better in practice than specifications that merely relate the pre- and postconditions.
Next, each operator in the library should be provided with a specification lemma.
831
831
There is only one: {name}`log`.
832
-
For new monads, these proofs must often break the abstraction boundaries of {tech}[Hoare triples] and weakest preconditions; the specifications that they provide can then be used abstractly by clients of the library.
832
+
For new monads, these proofs must often break the abstraction boundaries of {tech (key := "mvcgen Hoare triples")}[Hoare triples] and weakest preconditions; the specifications that they provide can then be used abstractly by clients of the library.
833
833
```lean
834
834
theoremlog_spec {x : β} :
835
835
⦃ fun s => ⌜s = s'⌝ ⦄ log x ⦃ ⇓ () s => ⌜s = s'.push x⌝ ⦄ := by
0 commit comments