-
Notifications
You must be signed in to change notification settings - Fork 10
/
abstractTypeExample.v
70 lines (49 loc) · 1.57 KB
/
abstractTypeExample.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Require Import Coq.Lists.List.
Definition insert (n:nat) (lst: list nat) :list nat := n::lst.
Definition remove (lst: list nat) : ((option nat) * list nat) :=
match rev(lst) with
| nil => (None, nil)
| l::lst' => (Some l,lst')
end.
Definition listProd: Set := (list nat * list nat) %type.
Definition insert' (n:nat) (lst: listProd) :listProd :=
match lst with
| (bs,fs) => (n::bs,fs)
end.
Definition remove' (lst:listProd): ((option nat) * listProd) :=
match lst with
| (bs , nil) => match rev(bs) with
| nil => (None,lst)
| i::bs' => (Some i, (nil,bs'))
end
| (bs, f::fs') => (Some f, (bs,fs'))
end.
Definition R (lst: list nat) (lstProd:listProd) : Prop :=
let (bs,fs):=lstProd in
lst = app (bs) (rev(fs)).
Lemma emptyR:
R nil (nil,nil).
Proof. simpl. auto. Qed.
Lemma insertR:
forall lst lstProd d, R lst lstProd -> R (insert d lst) (insert' d lstProd).
Proof.
intros. unfold R.
unfold insert. destruct lstProd.
simpl. inversion H. auto.
Qed.
Lemma removeR:
forall lst lstProd,
R lst lstProd ->
(lst = nil /\ lstProd = (nil,nil)
\/ (exists d d' lst' lstProd', remove lst = (Some d,lst') -> remove' lstProd =(Some d', lstProd') -> R lst' lstProd')).
Proof.
intros. destruct lstProd.
destruct l0. destruct l. inversion H. left. split; simpl; auto.
inversion H. simpl in H0. right.
exists n. exists n. exists l. exists ((nil,rev l)).
intros. unfold R. simpl. rewrite rev_involutive. auto.
inversion H. right.
exists n. exists n. exists (l++ rev l0).
exists ((l,l0)).
intros. unfold R. auto.
Qed.