We start by showing how to run Coq, introduce its three main sub-languages (Gallina, Vernacular, and LTac), and use it on simple examples.
At first glance, Coq can be viewed as a typed programming language, similar to OCaml or Haskell. For example, we can define the booleans in the usual way as a data type using the Inductive
keyword. Terms like true
and false
are in a sub-language called "Gallina."
Inductive bool : Type :=
| true
| false.
Coq also provides commands like Check
and Print
, which are in a sub-language called "Vernacular", for checking the types of different terms, and for printing out their definition.
We can also define simple functions using pattern matching. Note that every match
must also have an end
.
Definition negb (b:bool) : bool := match b with | true => false | false => true end. Definition andb (b1 b2:bool) : bool := match b1 with | true => b2 | false => false end. Definition orb (b1 b2:bool) : bool := match b1 with | true => true | false => b2 end.
In addition to simple programs, Coq also supports doing proofs. For example, we can prove a simple lemma about orb
's behavior. Coq proofs are written using tactics such as reflexivity
, which is in a sub-language called "LTac", that manipulate the proof state. A proof is completed when all goals have been shown.
orb true false = truereflexivity. Qed.orb true false = true
Most of the terms we have seen so far are computational objects which inhabit a universe called Set
. Coq also has propositions which inhabit a universe called Prop
. Hence, we can prove simple propositions. Below we show that A
implies A
. Note that implication is written as ->
. We use the intros
tactic to introduce the implication and the assumption
tactic to discharge the proof goal of A
.
forall A : Prop, A -> Aforall A : Prop, A -> Aassumption. Qed.A: Prop
H: AA
The type of an equality is a proposition, which may or may not be provable.
Of course, there are many propositions that we cannot prove, such as the following one, which is clearly bogus.
Definition bogus : Prop := true = false.bogusbogusAbort.true = false