Software Foundations
Michael Clarkson's Open Online Course (on Youtube) Michael Charkson's Course (on Bilibili)
Xiong Yingfei's Course Webpage (2023 Spring)
This note is used as a brief summary and supplementofr the textbook and courses.
Induction
Compile .v File and Inport It
We need to import all of our definitions from the previous chapter.
1
From LF Require Export Basics.
In Linux terminal, we can generate Makefile with command
1
$ coq_makefile -f _CoqProject *.v -o Makefile
1
$ make
1
$ make Basics.vo
It is slightly different in Windows, where you need to input
1
> coqc -Q . LF Basics.v
LF
is the alias of the directory when compiling.
induction
Here is an example of the usage of induction proof.
1 | Theorem add_0_r : forall n:nat, n + 0 = n. |
To understand this phenomena, we first look back at the definiton of plus in Basics.v.
1 | Fixpoint plus (n : nat) (m : nat) : nat := |
The definition of plus operation doesn't tell us how to conclude that
n'+ 0 = n'
, so the destruct way of proof failed.
But we can use induction to realize the proof:
1 | Theorem minus_n_n: forall n, minus n n = 0. |
(as [| n' IHn']
divide n into two circumstances,
O
and S n'
, and give name IHn'
to
the induction hypothesis)
The first subgoal proves that for n = 0, the theorem is correct. And the second subgoal proves that if for n = n', the theorem holds water, then it also does to n = S n'.
Structural induction is applicable to any type that is reductively defined. The first methametical induction is a special case of it on natural number.
assert
Proofs within proofs
1 | Theorem mult_0_plus'' : forall n m : nat, |
And print Set Printing Parentheses.
to see the
parentheses omitted and better understand rewrite
tactic
result.
Rewrite tactic also serve to specify the elements we want to apply
hypothesis to. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16Theorem plus_rearrange : forall n m p q : nat,
(n + m) + (p + q) = (m + n) + (p + q).
(* Wrong proof *)
Proof.
intros n m p q.
rewrite add_comm.
(* ==> p + q + (n + m) = m + n + (p + q)
Obviously that is not what we want.*)
Abort.
(* Corrent proof *)
Proof.
intros n m p q.
assert (H: n + m = m + n).
{ rewrite add_comm. reflexivity. }
rewrite H. reflexivity.
Qed.