Tactics guide
intros
Moves things from the goal to the context. It works on quantified variables:
- FORM:
intros x y z
- WHEN: goal looks like
forall a b c, H
- EFFECT: add
x
,y
, andz
to the context (bound toa
,b
, andc
, respectively); goal becomesH
- INFORMAL: "Let x, y, and z be given."
It also works on premises of implications:
- FORM:
intros H
- WHEN: goal looks like
H1 -> H2
- EFFECT: add
H1
to the context, goal becomesH2
- INFORMAL: "Suppose
H1
; we must showH2
."
The two forms can be combined, which leads to a canned phrase in informal proofs.
- FORM:
intros n H
- WHEN goal looks like
forall n, H -> H'
- EFFECT:
n
andH
added to the context; goal becomesH'
- INFORMAL: "Let
n
be given such thatH
; we must showH'
."
simpl
- WHEN: whenever
- EFFECT: does some reduction in the goal
- INFORMAL: No real correlate, but it can be nice to show the steps of computation.
You can also simplify in a hypothesis.
- FORM:
simpl in H
- WHEN:
H
is in the context - EFFECT: does some reduction in
H
- INFORMAL: As above.
reflexivity
- WHEN: goal looks like 'e = e'
- EFFECT: finishes the current case
- INFORMAL: No real correlate, but it can be nice to show the steps of computation. Conclude proofs with appropriate language, like, "and we are done" or "and we have ... immediately".
rewrite
Rewriting using equalities.
- FORM:
rewrite -> H
- WHEN:
H : e1 = e2
is in the context ande1
appears in the goal - EFFECT:
e1
is replaced withe2
in the goal - INFORMAL: "By
H
, we can replacee1
withe2
to find ...". Or do an algebraic proof, showing a series of equalities.
It's best to always give a direction when rewriting. The direction is in terms of the equation in your context: ->
means find an occurrence of the thing on the left of the equality and replace it with the thing on the right; <-
means the reverse.
- FORM:
rewrite <- H
- WHEN:
H : e1 = e2
is in the context ande2
appears in the goal - EFFECT:
e2
is replaced withe1
in the goal - INFORMAL: As above.
You can rewrite in the context, too.
- FORM:
rewrite -> H1 in H2
- WHEN
H : e1 = e2
ande1
appears inH2
- EFFECT:
e1
is replaced withe2
in H2 - INFORMAL: "Since we know
e1 = e2
, we can replacee1
withe2
inH
to find..."
There's also a right-to-left form. You can also rewrite if-and-only-ifs.
apply
Apply quantifications and implications---backward reasoning.
- FORM:
apply H
- WHEN:
H : P -> Q
is in the context and the goal isQ
- EFFECT: goal is replaced with
P
INFORMAL: "Since
P->Q
(byH
), it suffices to showP
."- FORM:
apply H
- WHEN:
H : forall x, Q
is in the context and the goal isQ
- EFFECT: goal is solved
INFORMAL: "Since
forall x, Q
(byH
), we are done."
You can use apply on things in the context, too---forward reasoning.
- FORM:
apply H1 in H2
- WHEN:
H1 : P -> Q
andH2 : P
are in the context - EFFECT:
H2
is replaced withP
- INFORMAL: "Since
P->Q
(byH1
) andP
(byH2
), we can conclude thatQ
."
When some quantified variables can't be inferred, you can explicitly specify values for variables.
- FORM:
apply H with x:=e
- WHEN:
H : forall x, P e -> Q
and the goal isQ
andQ
doesn't determine the value ofe
- EFFECT: the goal is replaced with
P e
- INFORMAL: "Since
P->Q
(byH
) it suffices to showP
fore
."
When there is just one ambiguous variable, you can leave off the x:=
part and just write apply H with e
.
destruct
Performs case analysis. Its precise use depends on the inductive type being analyzed. Be certain to use -
/+
/*
to nest your case analyses. Always write an as
pattern.
- FORM:
destruct n as [| n']
- WHEN:
n : nat
is in the context - EFFECT: proofs splits into two cases, where
n=0
andn=S n'
for somen'
- INFORMAL: "By cases on
n
. - Ifn=0
then... - Ifn=S n'
, then..." If you're at the beginning of a proof, don't forget to "letn
be given". It's often good to say what your goal is in each case.
Note that you can use destruct
on compound expressions, as in destruct (beq_nat n m)
, which will do a case analysis on the boolean value of testing n
and m
for equality. If you need to remember the result of the case analysis, you can ask for an equation to be saved.
- FORM:
destruct (foo bar) eqn:H
- WHEN:
foo bar
is of an inductive type - EFFECT: case analysis on the possible results of
foo bar
, where in each case of a possible valuev
, the hypothesisH : foo bar = v
is added to the contexr - INFORMAL: As above.
You can combine intros
and destruct
in one go by replacing the variable name with the pattern.
- FORM:
intros []
- WHEN: the goal is of the form
forall (b : bool), H
- EFFECT: the same as
intros b. destruct b as []
, i.e. the goal is split into two cases:H
withtrue
substituted forb
andH
withfalse
substituted forb
. - INFORMAL: "Let
b
be given---it could be eithertrue
orfalse
; we consider both cases." Or, more tersely, "We go by cases onb
."
You can also use destruct
to explode False
in the context.
- FORM:
destruct H
- WHEN:
H : False
- EFFECT: solves the current goal
- INFORMAL: "We have reached a contradiction!" Good paper proofs will explain the nature of the contradiction rather than talking about "False" explicitly.
inversion
Reason by injectivity and distinctness of constructors.
When the constructors are the same, inversion
generates equalities:
- FORM:
inversion H
- WHEN:
H : c e1 ... en = c e1' ... en'
wherec
is a constructor of an inductive type - EFFECT: adds hypothesis that
e1 = e1'
(or deeper, if they have obvious subparts), substituting appropriately in the goal and context - INFORMAL: "To have
c e1 ... en = c e1' ... en'
, it must be the case that eachei = ei'
, since constructors are injective."
When constructors are different, inversion
solves the goal:
- FORM:
inversion H
- WHEN:
H : c e1 ... en = d e1' ... en'
wherec
andd
are different constructors of an inductive type - EFFECT: solves the goal
- INFORMAL: "But it is a contradiction to have
c e1 ... en = d e1' ... en'
."
You can use inversion
on H : False
to solve the goal, as well.
induction
Performs induction. Its precise use depends on the inductive type. Be certain to use -
/+
/*
to nest your case analyses.
- FORM:
induction l as [|h t IHl']
- WHEN:
l : list X
is in the context and the goal is H - EFFECT: proof splits into two cases:
- The "base case", where
l = nil
. You must proveH
wherenil
is substituted forl
. - The "inductive case", where
l = cons h t
. You must proveH
wherecons h t
is substituted forl
. You are given an "inductive hypothesis"IHl'
, which isH
wherel'
is substituted forl
.
- The "base case", where
- INFORMAL: "By induction on
n
. - Ifn=0
then... - Ifn=S n'
, then our IH is ... and we must show ... ." It's very important that you state the IH and the new goal in each case.
assert
Sets a new, subsidiary goal. Typically used to control rewriting or perform forward reasoning. Be certain to use {
and }
to mark your subsidiary proofs.
- FORM:
assert (H: e)
orassert (e) as H
- WHEN: at any time; all variables in
e
must be in your context - EFFECT: introduce a "local lemma"
e
and call itH
- INFORMAL: "In order to ..., we first show that ... ."
generalize dependent
The opposite of intros
: requantifies variables. Typically used before induction to make sure the IH is sufficiently general.
- FORM:
generalize dependent x
- WHEN:
x : T
is in the context; the goal isQ
- EFFECT: the goal changes to
forall x:T, P1 -> ... -> Pn -> Q
, where each of thePi
are those hypotheses in the context that mentionedx
- INFORMAL: Just after you say you go by induction, add "leaving
x
general".
symmetry
Swaps the sides of an equality.
- FORM:
symmetry
- WHEN: goal is of the form
e1 = e2
- EFFECT: goal changes to
e2 = e1
- INFORMAL: General algebraic/equational reasoning.
You can also work in the context.
- FORM:
symmetry in H
- WHEN:
H : e1 = e2
is in the context - EFFECT:
H
changes toe2 = e1
- INFORMAL: General algebraic/equational reasoning.
unfold
Unfolds a definition.
- FORM:
unfold defn
- WHEN: the definition
defn
appears in the goal - EFFECT: unfolds the definition
defn
in the goal - INFORMAL: General algebraic/equational reasoning; recalling definitions.
You can also unfold
in the context.
- FORM:
unfold defn in H
- WHEN: the definition
defn
appears in hypothesisH
in the context - EFFECT: unfolds the definition
defn
inH
- INFORMAL: General algebraic/equational reasoning; recalling definitions.