-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsorted.v
More file actions
166 lines (142 loc) · 4.76 KB
/
Copy pathsorted.v
File metadata and controls
166 lines (142 loc) · 4.76 KB
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
(***********************************************************************
Copyright (c) 2014 Jonathan Leivent
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***********************************************************************)
(* Useful lemmas about sorted lists. *)
Require Export List.
Import ListNotations.
Require Export ordered.
Require Export Sorted.
Notation sorted := (LocallySorted lt).
Hint Constructors LocallySorted.
Section defs.
Context {A : Set}.
Context {A_ordered : Ordered A}.
Lemma sortedl : forall {l1 l2 : list A}, sorted (l1++l2) -> sorted l1.
Proof.
induction l1; eauto. intros l2 H.
destruct l1; eauto.
inversion H. subst. eauto.
Qed.
Lemma sortedr : forall {l1 l2 : list A}, sorted (l1++l2) -> sorted l2.
Proof.
induction l1; eauto. intros l2 H.
destruct l1.
- destruct l2; eauto.
inversion H. subst. eauto.
- inversion H. subst. eauto.
Qed.
Lemma sortedtail : forall {l : list A}{a : A}, sorted (a::l) -> sorted l.
Proof.
intros l a H.
destruct l.
- eauto.
- inversion H. eauto.
Qed.
Lemma sortins : forall {l1 l2 l3 : list A}{a b : A},
sorted(l1++a::l2) ->
sorted(l2++b::l3) -> lt a b ->
sorted(l1++a::l2++b::l3).
Proof.
induction l1.
- intros l2 l3 a b H H0 H1.
destruct l2; simpl in *.
+ inversion H0; subst; eauto.
+ inversion H; subst; eauto.
- intros l2 l3 a0 b H H0 H1.
destruct l1; simpl in *.
+ inversion H; subst; eauto using sortedtail.
+ inversion H; subst; eauto using sortedtail.
Qed.
Lemma desort : forall {l1 l2 : list A}{a b : A},
sorted (a::l1++b::l2) -> lt a b.
Proof.
induction l1.
- intros l2 a b H.
inversion H; subst; eauto.
- intros l2 a0 b H.
inversion H; subst; transitivity a; eauto.
Qed.
Lemma sortedm : forall {l1 l2 l3 : list A},
sorted (l1++l2++l3) -> sorted (l1++l3).
Proof.
induction l1.
- intros l2 l3 H.
eauto using sortedr.
- intros l2 l3 H.
destruct l1.
+ destruct l3; simpl in *; eauto using sortedtail, desort.
+ simpl in *.
inversion H; subst; eauto.
Qed.
Definition NotIn(x : A)(l : list A) := ~In x l.
Lemma NotInNil: forall (x : A), NotIn x [].
Proof.
intro x.
apply in_nil.
Qed.
Lemma NotInCons: forall {l : list A}{x d : A},
lt x d -> sorted (d::l) -> NotIn x (d::l).
Proof.
induction l as [|y l IHl].
- intros x d H H0.
destruct 1; subst; eauto.
contradict H.
apply irreflexivity.
- intros x d H H0.
inversion H0; subst.
destruct 1; subst.
+ contradict H. apply irreflexivity.
+ eapply (IHl x y); eauto.
transitivity d; eauto.
Qed.
Lemma NotInl: forall {x d : A}{l1 l2:list A},
NotIn x l1 -> lt x d -> sorted(l1++d::l2) ->
NotIn x (l1++d::l2).
Proof.
induction l1 as [|y l1 IHl1].
- intros l2 H H0 H1.
simpl in *.
auto using NotInCons.
- intros l2 H H0 H1.
destruct 1 as [|H2]; subst.
+ elim H.
apply in_eq.
+ eapply IHl1 in H2; eauto.
* intro. elim H. simpl. auto.
* eauto using sortedtail.
Qed.
Lemma NotInr: forall {x d : A}{l1 l2 : list A},
NotIn x l2 -> lt d x -> sorted(l1++d::l2) ->
NotIn x (l1++d::l2).
Proof.
induction l1 as [|y l1 IHl1].
- intros l2 H H0 H1.
destruct 1; subst.
+ contradict H0.
apply irreflexivity.
+ contradiction.
- intros l2 H H0 H1.
destruct 1 as [|H2]; subst.
+ apply desort in H1.
contradict (irreflexivity (transitivity H1 H0)).
+ contradict H2.
eapply IHl1; eauto using sortedtail.
Qed.
End defs.
Hint Resolve NotInNil NotInl NotInr.