-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.v
99 lines (86 loc) · 2.23 KB
/
order.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
From Hammer Require Export Tactics Reflect.
Require Import Recdef.
Require Export List.
Import List.ListNotations.
Open Scope list_scope.
Class DecTotalOrder (A : Type) := {
leb : A -> A -> bool;
leb_total : forall x y, leb x y \/ leb y x;
leb_antisym : forall x y, leb x y -> leb y x -> x = y;
leb_trans : forall x y z, leb x y -> leb y z -> leb x z }.
Lemma leb_refl `{DecTotalOrder} : forall x, leb x x.
Proof.
intro x; destruct (leb_total x x); auto.
Qed.
Lemma lem_neg_leb `{DecTotalOrder} :
forall x y, ~ (leb x y) -> leb y x.
Proof.
qauto use: leb_total.
Qed.
Definition leb_total_dec `{DecTotalOrder} : forall x y, {leb x y}+{leb y x}.
intros x y.
sdestruct (leb x y).
- left; constructor.
- right; destruct (leb_total x y); auto.
Defined.
Definition eq_dec {A} `{DecTotalOrder A} : forall x y : A, {x = y}+{x <> y}.
intros x y.
sdestruct (leb x y).
- sdestruct (leb y x).
+ auto using leb_antisym.
+ sauto.
- sdestruct (leb y x).
+ sauto.
+ destruct (leb_total_dec x y); auto.
Defined.
Definition eqb `{DecTotalOrder} x y : bool :=
if eq_dec x y then
true
else
false.
Definition ltb `{DecTotalOrder} x y : bool :=
leb x y && negb (eqb x y).
Definition leb_ltb_dec `{DecTotalOrder} x y : {leb x y}+{ltb y x}.
destruct (leb_total_dec x y).
- left; sauto.
- unfold ltb, negb, eqb.
destruct (eq_dec y x).
+ left; sauto.
+ right; sauto brefl: on.
Defined.
Lemma lem_ltb_leb_incl `{DecTotalOrder} :
forall x y : A, ltb x y -> leb x y.
Proof.
sauto brefl: on unfold: ltb.
Qed.
Function lexb `{DecTotalOrder} l1 l2 :=
match l1 with
| [] => true
| x :: l1' =>
match l2 with
| [] => false
| y :: l2' =>
if eq_dec x y then
lexb l1' l2'
else
leb x y
end
end.
Instance dto_list {A} `{DecTotalOrder A} : DecTotalOrder (list A).
Proof.
apply Build_DecTotalOrder with (leb := lexb).
- induction x; sauto.
- intros x y.
functional induction (lexb x y).
+ sauto inv: list.
+ sauto.
+ sauto.
+ sauto inv: - use: leb_antisym.
- intros x y.
functional induction (lexb x y); sauto.
Defined.
Instance dto_nat : DecTotalOrder nat.
Proof.
apply Build_DecTotalOrder with (leb := Nat.leb);
induction x; sauto.
Defined.