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

4 5 6 7 8 9 10
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
classes in the file `proofmode/classes`. Most notable, many of the tactics can
be applied when the to be introduced or to be eliminated connective appears
under a later, a primitive view shift, or in the conclusion of a weakest
precondition connective.

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 17
- `iApply pm_trm` : match the conclusion of the current goal against the
   conclusion of `pm_trm` and generates goals for the premises of `pm_trm`. See
18 19 20 21 22
   proof mode terms below.

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

23
- `iIntros (x1 ... xn) "ipat1 ... ipatn"` : introduce universal quantifiers
24 25 26
  using Coq introduction patterns `x1 ... xn` and implications/wands using proof
  mode introduction patterns `ipat1 ... ipatn`.
- `iClear "H1 ... Hn"` : clear the hypothesis `H1 ... Hn`. The symbol `★` can
27 28
  be used to clear entire spatial context.
- `iRevert (x1 ... xn) "H1 ... Hn"` : revert the proof mode hypotheses
29 30 31 32
  `H1 ... Hn` into wands, as well as the Coq level hypotheses/variables
  `x1 ... xn` into universal quantifiers. The symbol `★` can be used to revert
  the entire spatial context.
- `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`.
41 42
- `iAssert P with "spat" as "ipat"` : create a new goal with conclusion `P` and
  put `P` in the context of the original goal. The specialization pattern
43
  `spat` specifies which hypotheses will be consumed by proving `P`. The
44
  introduction pattern `ipat` specifies how to eliminate `P`.
45 46
- `iAssert P with "spat" as %cpat` : assert `P` and eliminate it using the Coq
  introduction pattern `cpat`.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

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
  for the right conjunct.
- `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.
69 70 71 72 73 74 75
- `iDestruct pm_trm as (x1 ... xn) "ipat"` : elimination of existential
  quantifiers using Coq introduction patterns `x1 ... xn` and elimination of
  object level connectives using the proof mode introduction pattern `ipat`.
  In case all branches of `ipat` start with an `#` (moving the hypothesis to the
  persistent context) or `%` (moving the hypothesis to the pure Coq context),
  one can use all hypotheses for proving the premises of `pm_trm`, as well as
  for proving the resulting goal.
76
- `iDestruct pm_trm as %cpat` : elimination of a pure hypothesis using the Coq
77 78 79
  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.
80 81 82 83

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

84 85 86 87 88 89 90 91 92 93
- `iFrame (t1 .. tn) "H0 ... Hn"` : cancel the Coq terms (or Coq hypotheses)
  `t1 ... tn` and Iris hypotheses `H0 ... Hn` in the goal. Apart from
  hypotheses, the following symbols can be used:

  + `%` : 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.
94 95 96 97 98 99
- `iCombine "H1" "H2" as "H"` : turns `H1 : P1` and `H2 : P2` into
  `H : P1 ★ P2`.

The later modality
------------------
- `iNext` : introduce a later by stripping laters from all hypotheses.
100
- `iLöb (x1 ... xn) as "IH"` : perform Löb induction by generalizing over the
101 102 103 104 105
  Coq level variables `x1 ... xn` and the entire spatial context.

Rewriting
---------

106 107
- `iRewrite pm_trm` : rewrite an equality in the conclusion.
- `iRewrite pm_trm in "H"` : rewrite an equality in the hypothesis `H`.
108 109 110 111

Iris
----

Robbert Krebbers's avatar
Robbert Krebbers committed
112 113 114 115
- `iVsIntro` : introduction of a raw or primitive view shift.
- `iVs pm_trm as (x1 ... xn) "ipat"` : run a raw or primitive view shift
  `pm_trm` (if the goal permits, i.e. it is a raw or primitive view shift, or
   a weakest precondition).
116
- `iInv N as (x1 ... xn) "ipat"` : open the invariant `N`.
Robbert Krebbers's avatar
Robbert Krebbers committed
117 118 119
- `iTimeless "H"` : strip a later of a timeless hypothesis `H` (if the goal
   permits, i.e. it is a later, True now, raw or primitive view shift, or a
   weakest precondition).
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

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
  existential quantifiers, implications and wand, always and later modalities,
  primitive view shifts, and pure connectives.

Introduction patterns
=====================

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

- `H` : create a hypothesis named H.
- `?` : 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
143
- `[ipat|ipat]` : disjunction elimination.
144
- `[]` : false elimination.
Robbert Krebbers's avatar
Robbert Krebbers committed
145 146 147 148
- `%` : move the hypothesis to the pure Coq context (anonymously).
- `# ipat` : move the hypothesis to the persistent context.
- `> ipat` : remove a later of a timeless hypothesis (if the goal permits).
- `==> ipat` : run a view shift (if the goal permits).
149 150 151 152 153 154

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
155
  previous pattern, e.g., `{$H1 H2 $H3}`).
Robbert Krebbers's avatar
Robbert Krebbers committed
156 157 158 159
- `!%` : introduce a pure goal (and leave the proof mode).
- `!#` : introduce an always modality (given that the spatial context is empty).
- `!>` : introduce a later (which strips laters from all hypotheses).
- `!==>` : introduce a view shift.
160 161 162 163 164
- `/=` : 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
165

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

168
You can write
Ralf Jung's avatar
Ralf Jung committed
169

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

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

174 175 176
        x : nat
        H : x = 0
        ______________________________________(1/1)
Robbert Krebbers's avatar
Robbert Krebbers committed
177
        "HQ" : Q
178 179 180
        "HR" : R
        --------------------------------------□
        R ★ Q ∧ x = 1
Ralf Jung's avatar
Ralf Jung committed
181 182


183 184
Specialization patterns
=======================
Ralf Jung's avatar
Ralf Jung committed
185

186 187 188 189
Since we are reasoning in a spatial logic, when eliminating a lemma or
hypotheses of type ``P_0 -★ ... -★ P_n -★ R`` one has to specify how the
hypotheses are split between the premises. The proof mode supports the following
so called specification patterns to express this splitting:
Ralf Jung's avatar
Ralf Jung committed
190

191 192 193 194 195
- `H` : use the hypothesis `H` (it should match the premise exactly). If `H` is
  spatial, it will be consumed.
- `[H1 ... Hn]` : generate a goal with the spatial hypotheses `H1 ... Hn` and
  all persistent hypotheses. The hypotheses `H1 ... Hn` will be consumed.
- `[-H1 ... Hn]`  : negated form of the above pattern
Robbert Krebbers's avatar
Robbert Krebbers committed
196
- `==>[H1 ... Hn]` : same as the above pattern, but can only be used if the goal
197 198
  is a primitive view shift, in which case the view shift will be kept in the
  goal of the premise too.
199 200 201
- `[#]` : 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.
202 203 204
- `[%]` : 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
205

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

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

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

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

214 215 216 217 218 219
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
220

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

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

225 226 227 228
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
229

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

232 233 234
        (H with "spat1 .. spatn")
        (H $! t1 ... tn)
        H
Ralf Jung's avatar
Ralf Jung committed
235