ProofMode.md 15.9 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
6
7
8
classes in the file [proofmode/classes](proofmode/classes.v). Most notably, many
of the tactics can be applied when the connective to be introduced or to be eliminated
appears under a later, an update modality, or in the conclusion of a
9
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.
Ralf Jung's avatar
Ralf Jung committed
19
  If the applied term has more premises than given specialization patterns, the
20
  pattern is extended with `[] ... []`.  As a consequence, all unused spatial
Ralf Jung's avatar
Ralf Jung committed
21
  hypotheses move to the last premise.
22
23
24
25

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

26
- `iIntros (x1 ... xn) "ipat1 ... ipatn"` : introduce universal quantifiers
27
28
  using Coq introduction patterns `x1 ... xn` and implications/wands using proof
  mode introduction patterns `ipat1 ... ipatn`.
29
30
31
32
- `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
33
34
  `x1 ... xn` into universal quantifiers. Intuitionistic hypotheses are wrapped
  into the intuitionistic modality.
35
- `iRename "H1" into "H2"` : rename the hypothesis `H1` into `H2`.
36
37
- `iSpecialize pm_trm` : instantiate universal quantifiers and eliminate
  implications/wands of a hypothesis `pm_trm`. See proof mode terms below.
38
- `iSpecialize pm_trm as #` : instantiate universal quantifiers and eliminate
39
40
41
  implications/wands of a hypothesis `pm_trm` whose conclusion is persistent.
  All hypotheses can be used for proving the premises of `pm_trm`, as well as
  for the resulting main goal.
42
43
- `iPoseProof pm_trm as (x1 ... xn) "ipat"` : put `pm_trm` into the context and
  eliminates it. This tactic is essentially the same as `iDestruct` with the
44
  difference that when `pm_trm` is a non-universally quantified intuitionistic
45
  hypothesis, it will not throw the hypothesis away.
Robbert Krebbers's avatar
Robbert Krebbers committed
46
47
48
49
50
- `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
51
52
53
  to the intuitionistic 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.
Robbert Krebbers's avatar
Robbert Krebbers committed
54
55
56
- `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.
57
58
59
60
61

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

- `iPureIntro` : turn a pure goal into a Coq goal. This tactic works for goals
62
  of the shape `⌜φ⌝`, `a ≡ b` on discrete COFEs, and `✓ a` on discrete CMRAs.
63
64
65
66
67
68
69
70

- `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
71
72
  for the right conjunct. Intuitionistic hypotheses are ignored, since these do
  not need to be split.
73
74
75
76
77
78
79
- `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
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
85
  to be moved to the intuitionistic context) or with an `%` (which causes the
Robbert Krebbers's avatar
Robbert Krebbers committed
86
87
88
89
  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.
90
- `iDestruct pm_trm as %cpat` : elimination of a pure hypothesis using the Coq
91
92
93
  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.
94

95
Separation logic-specific tactics
96
97
---------------------------------

98
99
100
- `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:
101
102

  + `%` : repeatedly frame hypotheses from the Coq context.
103
  + `#` : repeatedly frame hypotheses from the intuitionistic context.
104
105
  + `∗` : frame as much of the spatial context as possible. (N.B: this
          is the unicode symbol `∗`, not the regular asterisk `*`.)
106
107

  Notice that framing spatial hypotheses makes them disappear, but framing Coq
108
  or intuitionistic hypotheses does not make them disappear.
109

110
  This tactic solves the goal if everything in the conclusion has been
111
  framed.
112
113
- `iCombine "H1" "H2" as "pat"` : combines `H1 : P1` and `H2 : P2` into
  `H: P1 ∗ P2`, then calls `iDestruct H as pat` on the combined hypothesis.
Robbert Krebbers's avatar
Robbert Krebbers committed
114
115
116
- `iAccu` : solves a goal that is an evar by instantiating it with a all
  hypotheses from the spatial context joined together with a separating
  conjunction (or `emp` in case the spatial context is empty).
117

118
119
120
Modalities
----------

121
122
123
- `iModIntro mod` : introduction of a modality. The type class `FromModal` is
  used to specify which modalities this tactic should introduce. Instances of
  that type class include: later, except 0, basic update and fancy update,
124
125
126
  intuitionistically, persistently, affinely, plainly, absorbingly, objectively,
  and subjectively. The optional argument `mod` can be used to specify what
  modality to introduce in case of ambiguity, e.g. `⎡|==> P⎤`.
127
- `iAlways` : a deprecated alias of `iModIntro`.
128
129
- `iNext n` : an alias of `iModIntro (▷^n P)`.
- `iNext` : an alias of `iModIntro (▷^1 P)`.
130
131
132
133
- `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.

134
135
Induction
---------
136

137
138
139
140
- `iLöb as "IH" forall (x1 ... xn) "selpat"` : 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.
141
142
- `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
143
144
145
146
  variables. The induction hypotheses are inserted into the intuitionistic
  context and given fresh names prefixed `IH`. The tactic generalizes over the
  Coq level variables `x1 ... xn`, the hypotheses given by the selection pattern
  `selpat`, and the spatial context.
Robbert Krebbers's avatar
Robbert Krebbers committed
147

Robbert Krebbers's avatar
Robbert Krebbers committed
148
149
150
151
152
Rewriting / simplification
--------------------------

- `iRewrite pm_trm` / `iRewrite pm_trm in "H"` : rewrite using an internal
  equality in the proof mode goal / hypothesis `H`.
153
154
- `iRewrite -pm_trm` / `iRewrite -pm_trm in "H"` : rewrite in reverse direction
  using an internal equality in the proof mode goal / hypothesis `H`.
Robbert Krebbers's avatar
Robbert Krebbers committed
155
156
157
158
159
160
161
162
163
164
- `iEval (tac)` / `iEval (tac) in H` : performs a tactic `tac` on the proof mode
  goal / hypothesis `H`. The tactic `tac` should be a reduction or rewriting
  tactic like `simpl`, `cbv`, `lazy`, `rewrite` or `setoid_rewrite`. The `iEval`
  tactic is implemented by running `tac` on `?evar ⊢ P` / `P ⊢ ?evar` where `P`
  is the proof goal / hypothesis `H`. After running `tac`, `?evar` is unified
  with the resulting `P`, which in turn becomes the new proof mode goal /
  hypothesis `H`.
  Note that parentheses around `tac` are needed.
- `iSimpl` / `iSimpl in H` : performs `simpl` on the proof mode goal /
  hypothesis `H`. This is a shorthand for `iEval (simpl)`.
165
166
167
168
169


Iris
----

170
171
172
173
174
- `iInv S with "selpat" as (x1 ... xn) "ipat" "Hclose"` : where `S` is either
   a namespace N or an identifier "H". Open the invariant indicated by S.  The
   selection pattern `selpat` is used for any auxiliary assertions needed to
   open the invariant (e.g. for cancelable or non-atomic invariants). The update
   for closing the invariant is put in a hypothesis named `Hclose`.
175
176
177
178
179
180
181
182

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
183
184
  existential quantifiers, implications and wand, plainness, persistence, later
  and update modalities, and pure connectives.
185

186
187
188
189
190
191
192
193
194
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.
195
- `#` : select the entire intuitionistic context.
196
197
- `∗` : select the entire spatial context. (N.B: this
        is the unicode symbol `∗`, not the regular asterisk `*`.)
198

199
200
201
202
203
Introduction patterns
=====================

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

206
- `H` : create a hypothesis named `H`.
207
208
209
- `?` : create an anonymous hypothesis.
- `_` : remove the hypothesis.
- `$` : frame the hypothesis in the goal.
210
211
212
213
214
215
216
- `[ipat1 ipat2]` : (separating) conjunction elimination. In order to eliminate
  conjunctions `P ∧ Q` in the spatial context, one of the following conditions
  should hold:
  + Either the proposition `P` or `Q` should be persistent.
  + Either `ipat1` or `ipat2` should be `_`, which results in one of the
    conjuncts to be thrown away.
- `[ipat1|ipat2]` : disjunction elimination.
217
- `[]` : false elimination.
Robbert Krebbers's avatar
Robbert Krebbers committed
218
- `%` : move the hypothesis to the pure Coq context (anonymously).
219
- `->` and `<-` : rewrite using a pure Coq equality
220
- `# ipat` : move the hypothesis into the intuitionistic context.
221
- `> ipat` : eliminate a modality (if the goal permits).
222
223
224
225

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

226
227
228
- `{selpat}` : clear the hypotheses given by the selection pattern `selpat`.
  Items of the selection pattern can be prefixed with `$`, which cause them to
  be framed instead of cleared.
Robbert Krebbers's avatar
Robbert Krebbers committed
229
- `!%` : introduce a pure goal (and leave the proof mode).
230
231
- `!>` : introduce a modality by calling `iModIntro`.
- `!#` : introduce a modality by calling `iModIntro` (deprecated).
232
- `/=` : perform `simpl`.
233
234
- `//` : perform `try done` on all goals.
- `//=` : syntactic sugar for `/= //`
235
236
237
238
- `*` : 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
239

240
241
242
        ∀ x, <affine> ⌜ x = 0 ⌝ ⊢
          □ (P → False ∨ □ (Q ∧ ▷ R) -∗
          P ∗ ▷ (R ∗ Q ∧ ⌜ x = pred 2 ⌝)).
Ralf Jung's avatar
Ralf Jung committed
243

244
You can write
Ralf Jung's avatar
Ralf Jung committed
245

246
        iIntros (x Hx) "!# $ [[] | #[HQ HR]] /= !>".
247
248

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

250
251
252
        x : nat
        H : x = 0
        ______________________________________(1/1)
Robbert Krebbers's avatar
Robbert Krebbers committed
253
        "HQ" : Q
254
255
        "HR" : R
        --------------------------------------□
256
        R ∗ Q ∧ x = 1
Ralf Jung's avatar
Ralf Jung committed
257
258


259
260
Specialization patterns
=======================
Ralf Jung's avatar
Ralf Jung committed
261

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

267
268
- `H` : use the hypothesis `H` (it should match the premise exactly). If `H` is
  spatial, it will be consumed.
Robbert Krebbers's avatar
Robbert Krebbers committed
269

270
271
272
273
274
- `(H spat1 .. spatn)` : first recursively specialize the hypothesis `H` using
  the specialization patterns `spat1 .. spatn`, and finally use the result of
  the specialization of `H` (it should match the premise exactly). If `H` is
  spatial, it will be consumed.

Robbert Krebbers's avatar
Robbert Krebbers committed
275
- `[H1 .. Hn]` and `[H1 .. Hn //]` : generate a goal for the premise with the
276
277
278
279
280
  (spatial) hypotheses `H1 ... Hn` and all intuitionistic hypotheses. The
  spatial hypotheses among `H1 ... Hn` will be consumed, and will not be
  available for subsequent goals. Hypotheses prefixed with a `$` will be framed
  in the goal for the premise. The pattern can be terminated with a `//`, which
  causes `done` to be called to close the goal (after framing).
Robbert Krebbers's avatar
Robbert Krebbers committed
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
- `[-H1 ... Hn]` and `[-H1 ... Hn //]` : the negated forms of the above
  patterns, where the goal for the premise will have all spatial premises except
  `H1 .. Hn`.

- `[> H1 ... Hn]` and `[> H1 ... Hn //]` : like the above patterns, but these
  patterns can only be used if the goal is a modality `M`, in which case
  the goal for the premise will be wrapped in the modality `M`.
- `[> -H1 ... Hn]` and `[> -H1 ... Hn //]` : the negated forms of the above
  patterns.

- `[# $H1 .. $Hn]` and `[# $H1 .. $Hn //]` : generate a goal for a persistent
  premise in which all hypotheses are available. This pattern does not consume
  any hypotheses; all hypotheses are available in the goal for the premise, as
  well in the subsequent goal. The hypotheses `$H1 ... $Hn` will be framed in
  the goal for the premise. These patterns can be terminated with a `//`, which
  causes `done` to be called to close the goal (after framing).
- `[%]` and `[% //]` : generate a Coq goal for a pure premise. This pattern
  does not consume any hypotheses. The pattern can be terminated with a `//`,
  which causes `done` to be called to close the goal.

- `[$]` : solve the premise by framing. It will first repeatedly frame the
302
  spatial hypotheses, and then repeatedly frame the intuitionistic hypotheses.
Robbert Krebbers's avatar
Robbert Krebbers committed
303
304
305
306
307
308
  Spatial hypothesis that are not framed are carried over to the subsequent
  goal.
- `[> $]` : like the above pattern, but this pattern can only be used if the
  goal is a modality `M`, in which case the goal for the premise will be wrapped
  in the modality `M` before framing.
- `[# $]` : solve the persistent premise by framing. It will first repeatedly
309
  frame the spatial hypotheses, and then repeatedly frame the intuitionistic
Robbert Krebbers's avatar
Robbert Krebbers committed
310
  hypotheses. This pattern does not consume any hypotheses.
Ralf Jung's avatar
Ralf Jung committed
311

312
For example, given:
Ralf Jung's avatar
Ralf Jung committed
313

314
315
316
        H : □ P -∗ P 2 -∗ R -∗ x = 0 -∗ Q1 ∗ Q2

One can write:
Ralf Jung's avatar
Ralf Jung committed
317

318
        iDestruct ("H" with "[#] [H1 $H2] [$] [% //]") as "[H4 H5]".
Ralf Jung's avatar
Ralf Jung committed
319
320


321
322
323
324
325
326
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
327

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

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

332
Here, `H` can be either a hypothesis or a Coq lemma whose conclusion is
333
334
335
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
336

337
Proof mode terms can be written down using the following shorthand syntaxes, too:
Ralf Jung's avatar
Ralf Jung committed
338

339
340
341
        (H with "spat1 .. spatn")
        (H $! t1 ... tn)
        H
Ralf Jung's avatar
Ralf Jung committed
342

343
344
345
346
347
HeapLang tactics
================

If you came here looking for the `wp_` tactics, those are described in the
[HeapLang documentation](HeapLang.md).