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.
Lists
Pairs
We define the pair of natural numbers. (Cartesian product)
1
2
3
4
5
6
7
8
9
10
11
12
13
14Inductive natprod : Type :=
| pair (n1 n2 : nat).
Definition fst (p : natprod) : nat :=
match p with
| pair x y => x
end.
Definition snd (p : natprod) : nat :=
match p with
| pair x y => y
end.
Notation "( x , y )" := (pair x y).
Then comes a new usage of destruct
:
1 | Theorem surjective_pairing : forall (p : natprod), |
Lists of Natural Numbers
1 | Inductive natlist : Type := |
The concatenation operation of natlist
is then defined
as follows. 1
2
3
4
5
6
7Fixpoint app (l1 l2 : natlist) : natlist :=
match l1 with
| nil => l2
| h :: t => h :: (app t l2)
end.
Notation "x ++ y" := (app x y)
(right associativity, at level 60).
Then comes the usage of destruct
: 1
2
3
4
5
6
7
8
9Theorem tl_length_pred : forall l:natlist,
pred (length l) = length (tl l).
Proof.
intros l. destruct l as [| n l'].
- (* l = nil *)
reflexivity.
- (* l = cons n l' *)
reflexivity.
Qed.
And of instruction
1
2
3
4
5
6
7
8
9Theorem app_assoc : forall l1 l2 l3 : natlist,
(l1 ++ l2) ++ l3 = l1 ++ (l2 ++ l3).
Proof.
intros l1 l2 l3. induction l1 as [| n l1' IHl1'].
- (* l1 = nil *)
reflexivity.
- (* l1 = cons n l1' *)
simpl. rewrite -> IHl1'. reflexivity.
Qed.
Search
Command
1 |
|
Options
1 | Inductive natoption : Type := |
Recall Haskell's Maybe
, Nothing
and
Just
.
Partial Maps
1 | Inductive id : Type := |