ProofMode.md 11.8 KB
Newer Older
1
2
3
Tactic overview
===============

4
5
Many of the tactics below apply to more goals than described in this document
since the behavior of these tactics can be tuned via instances of the type
Robbert Krebbers's avatar
Robbert Krebbers committed
6
classes in the file [proofmode/classes](proofmode/classes.v). Most notable, many
Robbert Krebbers's avatar
Robbert Krebbers committed
7
of the tactics can be applied when the to be introduced or to be eliminated
8
9
connective appears under a later, an update modality, or in the conclusion of a
weakest precondition.
10

11
12
13
14
15
Applying hypotheses and lemmas
------------------------------

- `iExact "H"`  : finish the goal if the conclusion matches the hypothesis `H`
- `iAssumption` : finish the goal if the conclusion matches any hypothesis
16
- `iApply pm_trm` : match the conclusion of the current goal against the
17
18
  conclusion of `pm_trm` and generates goals for the premises of `pm_trm`. See
  proof mode terms below.
19
20
21
22

Context management
------------------

23
- `iIntros (x1 ... xn) "ipat1 ... ipatn"` : introduce universal quantifiers
24
25
  using Coq introduction patterns `x1 ... xn` and implications/wands using proof
  mode introduction patterns `ipat1 ... ipatn`.
26
27
28
29
30
31
- `iClear (x1 ... xn) "selpat"` : clear the hypotheses given by the selection
  pattern `selpat` and the Coq level hypotheses/variables `x1 ... xn`.
- `iRevert (x1 ... xn) "selpat"` : revert the hypotheses given by the selection
  pattern `selpat` into wands, and the Coq level hypotheses/variables
  `x1 ... xn` into universal quantifiers. Persistent hypotheses are wrapped into
  the always modality.
32
- `iRename "H1" into "H2"` : rename the hypothesis `H1` into `H2`.
33
34
- `iSpecialize pm_trm` : instantiate universal quantifiers and eliminate
  implications/wands of a hypothesis `pm_trm`. See proof mode terms below.
35
36
37
38
- `iSpecialize pm_trm as #` : instantiate universal quantifiers and eliminate
  implications/wands of a hypothesis whose conclusion is persistent. In this
  case, all hypotheses can be used for proving the premises, as well as for
  the resulting goal.
39
40
- `iPoseProof pm_trm as "H"` : put `pm_trm` into the context as a new hypothesis
  `H`.
Robbert Krebbers's avatar
Robbert Krebbers committed
41
42
43
44
45
46
47
48
49
50
51
- `iAssert P with "spat" as "ipat"` : generates a new subgoal `P` and adds the
  hypothesis `P` to the current goal. The specialization pattern `spat`
  specifies which hypotheses will be consumed by proving `P`. The introduction
  pattern `ipat` specifies how to eliminate `P`.
  In case all branches of `ipat` start with a `#` (which causes `P` to be moved
  to the persistent context) or with an `%` (which causes `P` to be moved to the
  pure Coq context), then one can use all hypotheses for proving `P` as well as
  for proving the current goal.
- `iAssert P as %cpat` : assert `P` and eliminate it using the Coq introduction
  pattern `cpat`. All hypotheses can be used for proving `P` as well as for
  proving the current goal.
52
53
54
55
56
57
58
59
60
61
62
63
64
65

Introduction of logical connectives
-----------------------------------

- `iPureIntro` : turn a pure goal into a Coq goal. This tactic works for goals
  of the shape `■ φ`, `a ≡ b` on discrete COFEs, and `✓ a` on discrete CMRAs.

- `iLeft` : left introduction of disjunction.
- `iRight` : right introduction of disjunction.

- `iSplit` : introduction of a conjunction, or separating conjunction provided
  one of the operands is persistent.
- `iSplitL "H1 ... Hn"` : introduction of a separating conjunction. The
  hypotheses `H1 ... Hn` are used for the left conjunct, and the remaining ones
66
67
  for the right conjunct. Persistent hypotheses are ignored, since these do not
  need to be split.
68
69
70
71
72
73
74
- `iSplitR "H0 ... Hn"` : symmetric version of the above.
- `iExist t1, .., tn` : introduction of an existential quantifier.

Elimination of logical connectives
----------------------------------

- `iExFalso` : Ex falso sequitur quod libet.
Robbert Krebbers's avatar
Robbert Krebbers committed
75
76
77
78
79
80
81
82
83
84
- `iDestruct pm_trm as (x1 ... xn) "ipat"` : elimination of a series of
  existential quantifiers using Coq introduction patterns `x1 ... xn`, and
  elimination of an object level connective using the proof mode introduction
  pattern `ipat`.
  In case all branches of `ipat` start with a `#` (which causes the hypothesis
  to be moved to the persistent context) or with an `%` (which causes the
  hypothesis to be moved to the pure Coq context), then one can use all
  hypotheses for proving the premises of `pm_trm`, as well as for proving the
  resulting goal. Note that in this case the hypotheses still need to be
  subdivided among the spatial premises.
85
- `iDestruct pm_trm as %cpat` : elimination of a pure hypothesis using the Coq
86
87
88
  introduction pattern `cpat`. When using this tactic, all hypotheses can be
  used for proving the premises of `pm_trm`, as well as for proving the
  resulting goal.
89
90
91
92

Separating logic specific tactics
---------------------------------

93
94
95
- `iFrame (t1 .. tn) "selpat"` : cancel the Coq terms (or Coq hypotheses)
  `t1 ... tn` and Iris hypotheses given by `selpat` in the goal. The constructs
  of the selection pattern have the following meaning:
96
97
98
99
100
101
102

  + `%` : repeatedly frame hypotheses from the Coq context.
  + `#` : repeatedly frame hypotheses from the persistent context.
  + `★` : frame as much of the spatial context as possible.

  Notice that framing spatial hypotheses makes them disappear, but framing Coq
  or persistent hypotheses does not make them disappear.
103
104
105

  This tactic finishes the goal in case everything in the conclusion has been
  framed.
106
107
108
- `iCombine "H1" "H2" as "H"` : turns `H1 : P1` and `H2 : P2` into
  `H : P1 ★ P2`.

109
110
111
112
113
114
115
116
117
118
Modalities
----------

- `iModIntro` : introduction of a modality that is an instance of the
  `IntoModal` type class. Instances include: later, except 0, basic update and
  fancy update.
- `iMod pm_trm as (x1 ... xn) "ipat"` : eliminate a modality `pm_trm` that is
  an instance of the `ElimModal` type class. Instances include: later, except 0,
  basic update and fancy update.

119
120
The later modality
------------------
121

122
123
124
125
- `iNext n` : introduce `n` laters by stripping that number of laters from all
  hypotheses. If the argument `n` is not given, it strips one later if the
  leftmost conjuct is of the shape `▷ P`, or `n` laters if the leftmost conjuct
  is of the shape `▷^n P`.
126
127
128
129
- `iLöb as "IH" forall (x1 ... xn)` : perform Löb induction by generating a
  hypothesis `IH : ▷ goal`. The tactic generalizes over the Coq level variables
  `x1 ... xn`, the hypotheses given by the selection pattern `selpat`, and the
  spatial context.
130

Robbert Krebbers's avatar
Robbert Krebbers committed
131
132
Induction
---------
133

134
135
- `iInduction x as cpat "IH" forall (x1 ... xn) "selpat"` : perform induction on
  the Coq term `x`. The Coq introduction pattern is used to name the introduced
136
137
  variables. The induction hypotheses are inserted into the persistent context
  and given fresh names prefixed `IH`. The tactic generalizes over the Coq level
138
139
  variables `x1 ... xn`, the hypotheses given by the selection pattern `selpat`,
  and the spatial context.
Robbert Krebbers's avatar
Robbert Krebbers committed
140

141
142
143
Rewriting
---------

144
145
- `iRewrite pm_trm` : rewrite an equality in the conclusion.
- `iRewrite pm_trm in "H"` : rewrite an equality in the hypothesis `H`.
146
147
148
149

Iris
----

150
151
- `iInv N as (x1 ... xn) "ipat" "Hclose"` : open the invariant `N`, the update
  for closing the invariant is put in a hypothesis named `Hclose`.
152
153
154
155
156
157
158
159

Miscellaneous
-------------

- The tactic `done` is extended so that it also performs `iAssumption` and
  introduces pure connectives.
- The proof mode adds hints to the core `eauto` database so that `eauto`
  automatically introduces: conjunctions and disjunctions, universal and
160
161
  existential quantifiers, implications and wand, always, later and update
  modalities, and pure connectives.
162

163
164
165
166
167
168
169
170
171
172
173
174
Selection patterns
==================

Selection patterns are used to select hypotheses in the tactics `iRevert`,
`iClear`, `iFrame`, `iLöb` and `iInduction`. The proof mode supports the
following _selection patterns_:

- `H` : select the hypothesis named `H`.
- `%` : select the entire pure/Coq context.
- `#` : select the entire persistent context.
- `★` : select the entire spatial context.

175
176
177
178
179
Introduction patterns
=====================

Introduction patterns are used to perform introductions and eliminations of
multiple connectives on the fly. The proof mode supports the following
180
_introduction patterns_:
181

182
- `H` : create a hypothesis named `H`.
183
184
185
186
- `?` : create an anonymous hypothesis.
- `_` : remove the hypothesis.
- `$` : frame the hypothesis in the goal.
- `[ipat ipat]` : (separating) conjunction elimination.
Ralf Jung's avatar
Ralf Jung committed
187
- `[ipat|ipat]` : disjunction elimination.
188
- `[]` : false elimination.
Robbert Krebbers's avatar
Robbert Krebbers committed
189
190
- `%` : move the hypothesis to the pure Coq context (anonymously).
- `# ipat` : move the hypothesis to the persistent context.
191
- `> ipat` : eliminate a modality (if the goal permits).
192
193
194
195
196
197

Apart from this, there are the following introduction patterns that can only
appear at the top level:

- `{H1 ... Hn}` : clear `H1 ... Hn`.
- `{$H1 ... $Hn}` : frame `H1 ... Hn` (this pattern can be mixed with the
Robbert Krebbers's avatar
Robbert Krebbers committed
198
  previous pattern, e.g., `{$H1 H2 $H3}`).
Robbert Krebbers's avatar
Robbert Krebbers committed
199
200
- `!%` : introduce a pure goal (and leave the proof mode).
- `!#` : introduce an always modality (given that the spatial context is empty).
201
- `!>` : introduce a modality.
202
203
204
205
206
- `/=` : perform `simpl`.
- `*` : introduce all universal quantifiers.
- `**` : introduce all universal quantifiers, as well as all arrows and wands.

For example, given:
Ralf Jung's avatar
Ralf Jung committed
207

208
        ∀ x, x = 0 ⊢ □ (P → False ∨ □ (Q ∧ ▷ R) -★ P ★ ▷ (R ★ Q ∧ x = pred 2)).
Ralf Jung's avatar
Ralf Jung committed
209

210
You can write
Ralf Jung's avatar
Ralf Jung committed
211

Robbert Krebbers's avatar
Robbert Krebbers committed
212
        iIntros (x) "% !# $ [[] | #[HQ HR]] /= !>".
213
214

which results in:
Ralf Jung's avatar
Ralf Jung committed
215

216
217
218
        x : nat
        H : x = 0
        ______________________________________(1/1)
Robbert Krebbers's avatar
Robbert Krebbers committed
219
        "HQ" : Q
220
221
222
        "HR" : R
        --------------------------------------□
        R ★ Q ∧ x = 1
Ralf Jung's avatar
Ralf Jung committed
223
224


225
226
Specialization patterns
=======================
Ralf Jung's avatar
Ralf Jung committed
227

228
Since we are reasoning in a spatial logic, when eliminating a lemma or
229
hypothesis of type ``P_0 -★ ... -★ P_n -★ R``, one has to specify how the
230
hypotheses are split between the premises. The proof mode supports the following
231
_specification patterns_ to express splitting of hypotheses:
Ralf Jung's avatar
Ralf Jung committed
232

233
234
- `H` : use the hypothesis `H` (it should match the premise exactly). If `H` is
  spatial, it will be consumed.
235
236
237
238
- `[H1 ... Hn]` : generate a goal with the (spatial) hypotheses `H1 ... Hn` and
  all persistent hypotheses. The spatial hypotheses among `H1 ... Hn` will be
  consumed. Hypotheses may be prefixed with a `$`, which results in them being
  framed in the generated goal.
239
- `[-H1 ... Hn]`  : negated form of the above pattern.
240
241
242
- `>[H1 ... Hn]` : same as the above pattern, but can only be used if the goal
  is a modality, in which case the modality will be kept in the generated goal
  for the premise will be wrapped into the modality.
Robbert Krebbers's avatar
Robbert Krebbers committed
243
244
245
- `>[-H1 ... Hn]`  : negated form of the above pattern.
- `>` : shorthand for `>[-]` (typically used for the last premise of an applied
  lemma).
246
247
248
- `[#]` : This pattern can be used when eliminating `P -★ Q` with `P`
  persistent. Using this pattern, all hypotheses are available in the goal for
  `P`, as well the remaining goal.
249
250
251
- `[%]` : This pattern can be used when eliminating `P -★ Q` when `P` is pure.
  It will generate a Coq goal for `P` and does not consume any hypotheses.
- `*` : instantiate all top-level universal quantifiers with meta variables.
Ralf Jung's avatar
Ralf Jung committed
252

253
For example, given:
Ralf Jung's avatar
Ralf Jung committed
254

255
        H : □ P -★ P 2 -★ x = 0 -★ Q1 ∗ Q2
Ralf Jung's avatar
Ralf Jung committed
256

257
You can write:
Ralf Jung's avatar
Ralf Jung committed
258

259
        iDestruct ("H" with "[#] [H1 H2] [%]") as "[H4 H5]".
Ralf Jung's avatar
Ralf Jung committed
260

261
262
263
264
265
266
Proof mode terms
================

Many of the proof mode tactics (such as `iDestruct`, `iApply`, `iRewrite`) can
take both hypotheses and lemmas, and allow one to instantiate universal
quantifiers and implications/wands of these hypotheses/lemmas on the fly.
Ralf Jung's avatar
Ralf Jung committed
267

268
The syntax for the arguments of these tactics, called _proof mode terms_, is:
Ralf Jung's avatar
Ralf Jung committed
269

270
        (H $! t1 ... tn with "spat1 .. spatn")
Ralf Jung's avatar
Ralf Jung committed
271

272
273
274
275
Here, `H` can be both a hypothesis, as well as a Coq lemma whose conclusion is
of the shape `P ⊢ Q`. In the above, `t1 ... tn` are arbitrary Coq terms used
for instantiation of universal quantifiers, and `spat1 .. spatn` are
specialization patterns to eliminate implications and wands.
Ralf Jung's avatar
Ralf Jung committed
276

277
Proof mode terms can be written down using the following short hands too:
Ralf Jung's avatar
Ralf Jung committed
278

279
280
281
        (H with "spat1 .. spatn")
        (H $! t1 ... tn)
        H
Ralf Jung's avatar
Ralf Jung committed
282