Logic & Propositions
- Coq is a typed language → logical claims also have type
- All syntactically well-formed propositions have type
Prop(propositions) - Propositions can be used in many ways: in Theorem, Lemma, Example; can also be Definition
- Proposition can be parameterized → functions that return propositions are said to define properties of their arguments
- Use
Checkto print type of expression/what theorem identifier refers to
Logical-AND
Operator: /\
Prove with split tactic → replaces the goal with two subgoals A and B.
We can apply and_intro to achieve the same effect as split.
1 2 3 4 5 6 | |
Use destruct tactic to use a conjunctive hypothesis to help prove something else.
Can destruct H right when it is introduced.
1 2 3 4 5 6 7 8 | |
If only A or B is needed, use an underscore pattern _ to indicate that the unneeded conjunct should just be thrown away.
1 2 3 4 5 6 | |
Logical-OR
Operator: \/
To show that disjunction holds, only need to prove one side → use left and/or right tactic.
1 2 3 4 | |
Sometimes need both
1 2 3 4 5 6 | |
To use a disjunctive hypothesis, use case analysis i.e. destruct tactic.
1 2 3 4 5 6 7 | |
Negation & False
Operator: not
Use destruct to prove negations
1 2 3 4 | |
Use notation to set alternative operator
1 | |
To define notation for "not equals", use:
1 | |
If you are trying to prove a goal that is nonsensical,
apply ex_falso_quodlibet to change the goal to False.
Coq provides a built-in tactic exfalso for applying it.
1 2 3 4 5 6 7 8 | |
If and only if
Define as a conjunction of two implications:
1 | |
Notation
1 2 | |
rewrite and reflexivity can be used with iff statements after
importing this support library: From Coq Require Import Setoids.Setoid.
A "setoid" is a set equipped with an equivalence relation, that is, a relation that is reflexive, symmetric, and transitive. When two elements of a set are equivalent according to the relation, rewrite can be used to replace one element with the other.
iff is reflexive, symmetric, and transitive → in P <-> Q can replace P with Q or Q with P.
Existential Quantifiers
- \(\forall\):
forall - \(\exists\):
exists
1 2 3 4 5 6 | |
Propositions & Proofs
Example: "x occurs in a list"
- cannot occur in an empty list
- otherwise: may or may not occur
1 2 3 4 5 | |
1 2 3 4 | |
1 2 3 4 5 6 | |
Inductive Propositions
Example:
- Rule ev_0: The number 0 is even.
- Rule ev_SS: If n is even, then S (S n) is even.
Proof tree showing application of these rules to say 4 is even:
1 2 3 4 5 6 | |
Inductively definition in Coq:
1 2 3 | |
Note:
- Inductive definition from
nattoProp - Explicit type in each constructor
- In an inductive definition:
- argument to the type constructor on the left of the colon is a "parameter"
- argument on the right is an "index" or "annotation
- For example:
- in inductive list
(X : Type) := ...→Xis a parameter - in inductive
ev : nat -> Prop := ...→natis an index
- in inductive list
1 2 3 4 5 6 7 | |
Proof using the inversion:
1 2 3 4 5 6 7 8 | |
Inductive Relations
- Two argument propositions can be thought of as a relation → define a set of pairs for which the proposition is provable
- Relations can be defined inductively
example: less than or equal
1 2 3 4 5 | |
- apply constructors to prove
<=goals - use tactics like
inversionto extract information from<=hypotheses