-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLattice.v
161 lines (138 loc) · 4.13 KB
/
Lattice.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
(** This file's definitions taken from [1].
Only standard lattice definitions are found in this file.
[1] -- John Wiegley, A Reflection-based Proof Tactic for Lattices in Coq, 2022.
https://github.com/jwiegley/coq-lattice
*)
Require Import Coq.Program.Program.
Require Import Coq.Bool.Bool.
Require Import Coq.Arith.Bool_nat.
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Lists.List.
Require Import Coq.Relations.Relations.
Require Import Coq.Classes.RelationClasses.
Require Import Coq.Wellfounded.Lexicographic_Product.
Generalizable All Variables.
Reserved Infix "⊓" (at level 40, left associativity).
Reserved Infix "⊔" (at level 36, left associativity).
Class Lattice (A : Type) := {
meet : A -> A -> A where "x ⊓ y" := (meet x y);
join : A -> A -> A where "x ⊔ y" := (join x y);
top : A;
bot : A;
meet_commutative : forall a b, a ⊓ b = b ⊓ a;
meet_associative : forall a b c, (a ⊓ b) ⊓ c = a ⊓ (b ⊓ c);
meet_absorptive : forall a b, a ⊓ (a ⊔ b) = a;
meet_idempotent : forall a, a ⊓ a = a;
join_commutative : forall a b, a ⊔ b = b ⊔ a;
join_associative : forall a b c, (a ⊔ b) ⊔ c = a ⊔ (b ⊔ c);
join_absorptive : forall a b, a ⊔ (a ⊓ b) = a;
join_idempotent : forall a, a ⊔ a = a;
meet_top : forall a, a ⊓ top = a;
meet_bot : forall a, a ⊓ bot = bot;
join_top : forall a, a ⊔ top = top;
join_bot : forall a, a ⊔ bot = a;
nontrivial : top <> bot
}.
Infix "⊓" := meet (at level 40, left associativity).
Infix "⊔" := join (at level 36, left associativity).
Class Order (A : Set) := {
ord : relation A;
reflexive :> Reflexive ord;
antisymmetric : forall {x y}, ord x y -> ord y x -> x = y;
transitive :> Transitive ord
}.
Infix "≤" := ord (at level 50).
Class LOSet {A : Set} `(@Order A) `(@Lattice A) := {
meet_consistent : forall a b, a ≤ b <-> a = a ⊓ b;
join_consistent : forall a b, a ≤ b <-> b = a ⊔ b
}.
Section Lattice.
Context `{O : Order A}.
Context `{L : Lattice A}.
Context `{@LOSet A O L}.
Theorem meet_is_glb : forall a b : A,
forall x, x ≤ a /\ x ≤ b <-> x ≤ a ⊓ b.
Proof.
split; intros.
intuition.
apply meet_consistent in H1.
apply meet_consistent in H2.
apply meet_consistent.
rewrite <- meet_associative, <- H1.
assumption.
apply meet_consistent in H0.
rewrite H0; clear H0.
split; apply meet_consistent.
rewrite meet_associative.
rewrite (meet_commutative (a ⊓ b) a).
rewrite <- (meet_associative a).
rewrite meet_idempotent.
reflexivity.
rewrite meet_associative.
rewrite meet_associative.
rewrite meet_idempotent.
reflexivity.
Qed.
Theorem meet_prime : forall a b : A,
forall x, a ≤ x \/ b ≤ x -> a ⊓ b ≤ x.
Proof.
intros.
destruct H0;
apply meet_consistent in H0;
apply meet_consistent; [rewrite meet_commutative|];
rewrite meet_associative;
rewrite <- H0; reflexivity.
Qed.
Theorem join_is_lub : forall a b : A,
forall x, a ≤ x /\ b ≤ x <-> a ⊔ b ≤ x.
Proof.
split; intros.
intuition.
apply join_consistent in H1.
apply join_consistent in H2.
apply join_consistent.
rewrite join_associative, <- H2.
assumption.
apply join_consistent in H0.
rewrite H0; clear H0.
split; apply join_consistent.
rewrite <- join_associative.
rewrite <- join_associative.
rewrite join_idempotent.
reflexivity.
rewrite (join_commutative a b).
rewrite <- join_associative.
rewrite <- join_associative.
rewrite join_idempotent.
reflexivity.
Qed.
Theorem join_prime : forall a b : A,
forall x, x ≤ a \/ x ≤ b -> x ≤ a ⊔ b.
Proof.
intros.
destruct H0;
apply join_consistent in H0;
apply join_consistent; [|rewrite join_commutative];
rewrite <- join_associative;
rewrite <- H0; reflexivity.
Qed.
Lemma lattice_gt_top : forall b : A,
ord top b ->
top = b.
Proof with eauto.
intros * Ord.
apply join_consistent in Ord.
rewrite Ord;
rewrite join_commutative;
rewrite join_top...
Qed.
Lemma lattice_lt_bot : forall b : A,
ord b bot ->
bot = b.
Proof with eauto.
intros * Ord.
apply meet_consistent in Ord.
rewrite Ord;
rewrite meet_bot...
Qed.
End Lattice.