-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorted.v
129 lines (102 loc) · 3.14 KB
/
sorted.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
From sortalgs Require Export order.
Require Export Sorting.Permutation.
Import List.ListNotations.
Open Scope list_scope.
Inductive Sorted {A} `{DecTotalOrder A} : list A -> Prop :=
| Sorted_0 : Sorted []
| Sorted_1 : forall x, Sorted [x]
| Sorted_2 : forall x y l, Sorted (y :: l) -> leb x y ->
Sorted (x :: y :: l).
Lemma lem_sorted_tail `{DecTotalOrder} :
forall l x, Sorted (x :: l) -> Sorted l.
Proof.
sauto.
Qed.
(*********************************************************************)
Fixpoint sortedb {A} `{DecTotalOrder A} (l : list A) : bool :=
match l with
| [] => true
| [x] => true
| x :: (y :: l') as t => leb x y && sortedb t
end.
Lemma lem_sortedb_iff_sorted `{DecTotalOrder} :
forall l : list A, sortedb l <-> Sorted l.
Proof.
induction l; sauto brefl: on inv: Sorted.
Qed.
(*********************************************************************)
Definition LeLst `{DecTotalOrder} x :=
List.Forall (leb x).
Lemma lem_lelst_nil `{DecTotalOrder} : forall x, LeLst x [].
Proof.
sauto.
Qed.
Lemma lem_lelst_cons `{DecTotalOrder} :
forall x y l, LeLst x l -> leb x y -> LeLst x (y :: l).
Proof.
sauto.
Qed.
Global Hint Resolve lem_lelst_nil lem_lelst_cons : lelst.
Lemma lem_lelst_trans `{DecTotalOrder} :
forall l x y, LeLst y l -> leb x y -> LeLst x l.
Proof.
induction 1; sauto.
Qed.
Lemma lem_lelst_perm `{DecTotalOrder} :
forall l1 l2 x, Permutation l1 l2 -> LeLst x l1 -> LeLst x l2.
Proof.
induction 1; sauto lq: on.
Qed.
Lemma lem_lelst_perm_rev `{DecTotalOrder} :
forall l1 l2 x, Permutation l1 l2 -> LeLst x l2 -> LeLst x l1.
Proof.
induction 1; sauto lq: on.
Qed.
Lemma lem_lelst_app `{DecTotalOrder} :
forall l1 l2 x, LeLst x l1 -> LeLst x l2 -> LeLst x (l1 ++ l2).
Proof.
induction 1; sauto lq: on.
Qed.
Global Hint Resolve lem_lelst_trans lem_lelst_perm lem_lelst_perm_rev
lem_lelst_app : lelst.
Lemma lem_lelst_sorted `{DecTotalOrder} :
forall l x, Sorted (x :: l) <-> LeLst x l /\ Sorted l.
Proof.
induction l; sauto l: on use: lem_lelst_trans
inv: Sorted, List.Forall ctrs: Sorted.
Qed.
(*********************************************************************)
Definition GeLst `{DecTotalOrder} x l :=
List.Forall (fun y => leb y x) l.
Lemma lem_gelst_nil `{DecTotalOrder} : forall x, GeLst x [].
Proof.
sauto.
Qed.
Lemma lem_gelst_cons `{DecTotalOrder} :
forall x y l, GeLst x l -> leb y x -> GeLst x (y :: l).
Proof.
sauto.
Qed.
Global Hint Resolve lem_gelst_nil lem_gelst_cons : gelst.
Lemma lem_gelst_trans `{DecTotalOrder} :
forall l x y, GeLst y l -> leb y x -> GeLst x l.
Proof.
induction 1; sauto.
Qed.
Lemma lem_gelst_perm `{DecTotalOrder} :
forall x l1 l2, Permutation l1 l2 -> GeLst x l1 -> GeLst x l2.
Proof.
induction 1; sauto lq: on.
Qed.
Lemma lem_gelst_perm_rev `{DecTotalOrder} :
forall l1 l2 x, Permutation l1 l2 -> GeLst x l2 -> GeLst x l1.
Proof.
induction 1; sauto lq: on.
Qed.
Lemma lem_gelst_app `{DecTotalOrder} :
forall l1 l2 x, GeLst x l1 -> GeLst x l2 -> GeLst x (l1 ++ l2).
Proof.
induction 1; sauto lq: on.
Qed.
Global Hint Resolve lem_gelst_trans lem_gelst_perm lem_gelst_perm_rev
lem_gelst_app : gelst.