-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsublist.v
167 lines (127 loc) · 4.67 KB
/
sublist.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
(** * Internals *)
Require Import Coq.Arith.Arith.
Require Import Omega.
Require Import Coq.Lists.List.
Open Scope list_scope.
(* ####################################################### *)
(** ** Helpers *)
Theorem list_loop : forall {A : Set} {x : A} {l : list A}, (x::l) <> l.
intros; generalize dependent x.
induction l; intros x C.
inversion C.
set (f:= @tail A); pose proof (f_equal f C) as H; simpl in H.
apply (IHl _ H).
Qed.
(* ####################################################### *)
(** ** length measure for lists *)
Section length_measure.
Definition lt_length {A : Set} (l1 l2 : list A) :=
List.length l1 < List.length l2.
Theorem lt_length_wf {A : Set} : well_founded (@lt_length A).
Proof. intro. apply well_founded_ltof. Qed.
Set Implicit Arguments.
Section lt_length_order.
Variable A : Set.
Variables c d : A.
Variables l l' l'' : list A.
Theorem lt_length_irrefl : ~ lt_length l l.
Proof. apply lt_irrefl. Qed.
Theorem lt_length_asym : lt_length l l' -> ~ lt_length l' l.
Proof. apply lt_asym. Qed.
Theorem lt_length_trans :
lt_length l l' -> lt_length l' l'' -> lt_length l l''.
Proof. apply lt_trans. Qed.
Theorem lt_length_not_nil : lt_length l l' -> l' <> nil.
Proof. induction l'; [ inversion 1 | intros _ C; inversion C]. Qed.
Theorem lt_length_tail : lt_length l (c::l).
Proof. cbv; intros; apply le_n. Qed.
Theorem lt_length_tails : lt_length (c::l) (d::l') -> lt_length l l'.
Proof. cbv; auto with arith. Qed.
Theorem lt_length_cons : lt_length l l' -> lt_length l (c::l').
Proof. cbv; auto with arith. Qed.
Theorem lt_length_cons_cons : lt_length l l' -> lt_length (c::l) (d::l').
Proof. cbv; auto with arith. Qed.
Hint Unfold lt_length.
Hint Resolve lt_length_trans lt_length_tail lt_length_tails lt_length_cons
lt_length_cons_cons. (* : pdfparser. *)
End lt_length_order.
Unset Implicit Arguments.
End length_measure.
(* ####################################################### *)
(** ** truer sublist *)
Section true_sublist.
Set Implicit Arguments.
Variable (A : Set).
Inductive sublist : list A -> list A -> Prop :=
| sl_tail : forall (c : A) l, sublist l (c::l)
| sl_cons : forall (c : A) l' l, sublist l' l -> sublist l' (c::l).
Section sublist_order.
Theorem sublist__lt_length : forall l l', sublist l' l -> lt_length l' l.
Proof.
intros l l' H. induction H.
apply lt_length_tail.
apply lt_length_cons; assumption.
Qed.
Lemma sublist_longer :
forall l l', List.length l' > List.length l -> ~ sublist l' l.
Proof.
intros l l' H C.
apply sublist__lt_length in C.
unfold lt_length in *; omega.
Qed.
Theorem sublist_not_nil : forall l l', sublist l l' -> l' <> nil.
Proof. induction l'; [ inversion 1 | intros _ C; inversion C]. Qed.
Theorem sublist_nil : forall c l, sublist nil (c::l).
Proof.
intros c l; generalize dependent c.
induction l; intros.
constructor.
constructor; apply IHl.
Qed.
Theorem sublist_tails :
forall c d l l', sublist (c::l) (d::l') -> sublist l l'.
Proof.
intros c d l l'; generalize dependent l;
generalize dependent d; generalize dependent c.
induction l'; intros.
inversion H; inversion H2.
inversion H; subst.
constructor.
constructor; apply (IHl' _ _ _ H2).
Qed.
Theorem sublist_irrefl : forall l, ~ sublist l l.
Proof.
induction l; intro C; inversion C.
apply (list_loop H2).
subst. apply sublist__lt_length in H1.
cbv in H1; omega.
Qed.
Theorem sublist_asym : forall l l', sublist l l' -> ~ sublist l' l.
Proof.
intros l l' H; induction H.
intro C. apply sublist__lt_length in C. cbv in C; omega.
intro C. apply sublist__lt_length in C. apply sublist__lt_length in H.
cbv in H; cbv in C; omega.
Qed.
Theorem sublist_trans : forall l l' l'',
sublist l l' -> sublist l' l'' -> sublist l l''.
Proof.
intros l l' l'' H0 H; generalize dependent l.
induction H; intros.
constructor; assumption.
constructor; apply (IHsublist _ H0).
Qed.
End sublist_order.
(* additional pseudo-constructor *)
Theorem sl_minus :
forall (c : A) {l' l}, sublist (c::l') l -> sublist l' l.
Proof.
intros; destruct l.
inversion H.
apply sublist_tails in H. constructor; assumption.
Qed.
Unset Implicit Arguments.
End true_sublist.
Hint Constructors sublist.
Hint Resolve sublist__lt_length sublist_tails sublist_trans. (* : sublist pdfparser. *)
Hint Resolve sl_minus.