Coq cheat sheet

advertisement
Coq cheat sheet
Notation
Propositions
>, ⊥
p∧q
p⇒q
p∨q
¬p
∀x ∈ A . p(x)
∀x, y ∈ A . ∀u, v ∈ B . q
∃x ∈ A . p(x)
Sets
1
A×B
A+B
A
B or A → B
{x ∈ A | p(x)}
P
B(x)
Q x∈A
B(x)
x∈A
Coq
True, False
p /\ q
p -> q
p \/ q
~ p
forall x:A, p x
forall (x y:A) (u v:B), q
exists x:A, p x
Coq
unit
prod A B or A * B
sum A B or A + B
A -> B
{x:A | p x}
{x:A & B x} or sig A B
forall x:A, B x
Elements
?∈1
x 7→ f (x) or λx ∈ A . f (x)
λx, y ∈ A . λu, v ∈ B . f (x)
(a, b) ∈ A × B
π1 (t) where t ∈ A × B
π2 (t) where t ∈ A × B
P
π1 (t) where t ∈ x∈A B(x)
P
π2 (t) where t ∈ x∈A B(x)
ι1 (t) ∈ A + B where t ∈ A
ι2 (t) ∈ A + B where t ∈ B
t ∈ {x ∈ A | p(x)} because ρ
ι(t) where ι : {x ∈ A | p(x)} ,→ A
Coq
tt : unit
fun (x : A) => f x
fun (x y : A) (u v : B) => f x
(a,b) : A * B
fst t
snd t
projT1 t
projT2 t
inl t
inr t
exist t ρ
projT1 t
Basic tactics
When the goal is . . .
very simple
p /\ q
p \/ q
p -> q
~p
p <-> q
an assumption
forall x, p
exists x, p
To use hypothesis H . . .
p \/ q
p /\ q
p -> q
p <-> q
~p
False
forall x, p
exists x, p
a = b
. . . use tactic
auto, tauto or firstorder
split
left or right
intro
intro
split
assumption
intro
exists t
. . . use tactic
destruct H as [H1 |H2 ]
destruct H as [H1 H2 ]
apply H
apply H
apply H or elim H
contradiction
apply H
destruct H as [x G]
rewrite H or rewrite <- H
If you want to . . .
prove by contradiction p ∧ ¬p
simplify expressions
prove via intermediate goal p
prove by induction on t
pretend you are done
import package P
compute t
print definition of p
check the type of t
search theorems about p
. . . then use
absurd p
simpl
cut p
induction t
admit
Require Import P
Eval compute in t
Print p
Check t
SearchAbout p
Inductive definitions
Inductive definition of X
Inductive X args
| constructor1
| constructor2
...
| constructorN
:=
: args1 -> X
: args2 -> X
: argsN -> X.
Coq generates induction and recursion principles X ind, X rec, X rect.
Construction of an object by cases
match t with
| case1: result1
| case2: result2
...
| caseN: resultN
end
Recursive definition of f
Fixpoint f args := ...
Download