-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGExp_Lexorder.thy
253 lines (236 loc) · 6.61 KB
/
GExp_Lexorder.thy
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
subsection\<open>GExp Lexorder\<close>
text\<open>This theory defines a lexicographical ordering on guard expressions such that we can build
orderings for transitions. We make use of the previously established orderings on arithmetic
expressions.\<close>
theory
GExp_Lexorder
imports
"GExp"
"AExp_Lexorder"
"HOL-Library.List_Lexorder"
begin
fun height :: "'a gexp \<Rightarrow> nat" where
"height (Bc _) = 1" |
"height (Eq a1 a2) = 1 + max (AExp_Lexorder.height a1) (AExp_Lexorder.height a2)" |
"height (Gt a1 a2) = 1 + max (AExp_Lexorder.height a1) (AExp_Lexorder.height a2)" |
"height (In v l) = 2 + size l" |
"height (Nor g1 g2) = 1 + max (height g1) (height g2)"
instantiation gexp :: (linorder) linorder begin
fun less_gexp_aux :: "'a gexp \<Rightarrow> 'a gexp \<Rightarrow> bool" where
"less_gexp_aux (Bc b1) (Bc b2) = (b1 < b2)" |
"less_gexp_aux (Bc b1) _ = True" |
"less_gexp_aux (Eq e1 e2) (Bc b2) = False" |
"less_gexp_aux (Eq e1 e2) (Eq e1' e2') = ((e1 < e1') \<or> ((e1 = e1') \<and> (e2 < e2')))" |
"less_gexp_aux (Eq e1 e2) _ = True" |
"less_gexp_aux (Gt e1 e2) (Bc b2) = False" |
"less_gexp_aux (Gt e1 e2) (Eq e1' e2') = False" |
"less_gexp_aux (Gt e1 e2) (Gt e1' e2') = ((e1 < e1') \<or> ((e1 = e1') \<and> (e2 < e2')))" |
"less_gexp_aux (Gt e1 e2) _ = True" |
"less_gexp_aux (In vb vc) (Nor v va) = True" |
"less_gexp_aux (In vb vc) (In v va) = (vb < v \<or> (vb = v \<and> vc < va))" |
"less_gexp_aux (In vb vc) _ = False" |
"less_gexp_aux (Nor g1 g2) (Nor g1' g2') = ((less_gexp_aux g1 g1') \<or> ((g1 = g1') \<and> (less_gexp_aux g2 g2')))" |
"less_gexp_aux (Nor g1 g2) _ = False"
definition less_gexp :: "'a gexp \<Rightarrow> 'a gexp \<Rightarrow> bool" where
"less_gexp a1 a2 = (
let
h1 = height a1;
h2 = height a2
in
if h1 = h2 then
less_gexp_aux a1 a2
else
h1 < h2
)"
declare less_gexp_def [simp]
definition less_eq_gexp :: "'a gexp \<Rightarrow> 'a gexp \<Rightarrow> bool" where
"less_eq_gexp e1 e2 \<equiv> (e1 < e2) \<or> (e1 = e2)"
lemma less_gexp_aux_antisym: "less_gexp_aux x y = (\<not>(less_gexp_aux y x) \<and> (x \<noteq> y))"
proof (induct x y rule: less_gexp_aux.induct)
case (1 b1 b2)
then show ?case by auto
next
case ("2_1" b1 v va)
then show ?case by auto
next
case ("2_2" b1 v va)
then show ?case by auto
next
case ("2_3" b1 v va)
then show ?case by auto
next
case ("2_4" b1 v va)
then show ?case by auto
next
case (3 e1 e2 b2)
then show ?case by auto
next
case (4 e1 e2 e1' e2')
then show ?case
by (metis less_gexp_aux.simps(7) less_imp_not_less less_linear)
next
case ("5_1" e1 e2 v va)
then show ?case by auto
next
case ("5_2" e1 e2 v va)
then show ?case by auto
next
case ("5_3" e1 e2 v va)
then show ?case by auto
next
case (6 e1 e2 b2)
then show ?case by auto
next
case (7 e1 e2 e1' e2')
then show ?case by auto
next
case (8 e1 e2 e1' e2')
then show ?case
by (metis less_gexp_aux.simps(13) less_imp_not_less less_linear)
next
case ("9_1" e1 e2 v va)
then show ?case by auto
next
case ("9_2" e1 e2 v va)
then show ?case by auto
next
case (10 vb vc v va)
then show ?case by auto
next
case (11 vb vc v va)
then show ?case by auto
next
case ("12_1" vb vc v)
then show ?case by auto
next
case ("12_2" vb vc v va)
then show ?case by auto
next
case ("12_3" vb vc v va)
then show ?case by auto
next
case (13 g1 g2 g1' g2')
then show ?case by auto
next
case ("14_1" g1 g2 v)
then show ?case by auto
next
case ("14_2" g1 g2 v va)
then show ?case by auto
next
case ("14_3" g1 g2 v va)
then show ?case by auto
next
case ("14_4" g1 g2 v va)
then show ?case by auto
qed
lemma less_gexp_antisym: "(x::'a gexp) < y = (\<not>(y < x) \<and> (x \<noteq> y))"
apply (simp add: Let_def)
apply standard
using less_gexp_aux_antisym apply blast
apply clarsimp
by (induct x, auto)
lemma less_gexp_aux_trans: "less_gexp_aux x y \<Longrightarrow> less_gexp_aux y z \<Longrightarrow> less_gexp_aux x z"
proof(induct x y arbitrary: z rule: less_gexp_aux.induct)
case (1 b1 b2)
then show ?case by (cases z, auto)
next
case ("2_1" b1 v va)
then show ?case by (cases z, auto)
next
case ("2_2" b1 v va)
then show ?case by (cases z, auto)
next
case ("2_3" b1 v va)
then show ?case by (cases z, auto)
next
case ("2_4" b1 v va)
then show ?case by (cases z, auto)
next
case (3 e1 e2 b2)
then show ?case by (cases z, auto)
next
case (4 e1 e2 e1' e2')
then show ?case
apply (cases z)
apply simp
apply (metis dual_order.strict_trans less_gexp_aux.simps(7))
by auto
next
case ("5_1" e1 e2 v va)
then show ?case by (cases z, auto)
next
case ("5_2" e1 e2 v va)
then show ?case by (cases z, auto)
next
case ("5_3" e1 e2 v va)
then show ?case by (cases z, auto)
next
case (6 e1 e2 b2)
then show ?case by (cases z, auto)
next
case (7 e1 e2 e1' e2')
then show ?case by (cases z, auto)
next
case (8 e1 e2 e1' e2')
then show ?case
apply (cases z)
apply simp
apply simp
apply (metis dual_order.strict_trans less_gexp_aux.simps(13))
by auto
next
case ("9_1" e1 e2 v va)
then show ?case by (cases z, auto)
next
case ("9_2" e1 e2 v va)
then show ?case by (cases z, auto)
next
case (10 vb vc v va)
then show ?case by (cases z, auto)
next
case (11 vb vc v va)
then show ?case by (cases z, auto)
next
case ("12_1" vb vc v)
then show ?case by (cases z, auto)
next
case ("12_2" vb vc v va)
then show ?case by (cases z, auto)
next
case ("12_3" vb vc v va)
then show ?case by (cases z, auto)
next
case (13 g1 g2 g1' g2')
then show ?case by (cases z, auto)
next
case ("14_1" g1 g2 v)
then show ?case by (cases z, auto)
next
case ("14_2" g1 g2 v va)
then show ?case by (cases z, auto)
next
case ("14_3" g1 g2 v va)
then show ?case by (cases z, auto)
next
case ("14_4" g1 g2 v va)
then show ?case by (cases z, auto)
qed
lemma less_gexp_trans: "(x::'a gexp) < y \<Longrightarrow> y < z \<Longrightarrow> x < z"
apply (simp add: Let_def)
by (metis (no_types, lifting) dual_order.strict_trans less_gexp_aux_trans less_imp_not_less)
instance proof
fix x y z :: "'a gexp"
show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
by (metis less_gexp_antisym less_eq_gexp_def)
show "(x \<le> x)"
by (simp add: less_eq_gexp_def)
show "x \<le> y \<Longrightarrow> y \<le> z \<Longrightarrow> x \<le> z"
by (metis less_eq_gexp_def less_gexp_trans)
show "x \<le> y \<Longrightarrow> y \<le> x \<Longrightarrow> x = y"
unfolding less_eq_gexp_def using less_gexp_antisym by blast
show "x \<le> y \<or> y \<le> x"
unfolding less_eq_gexp_def using less_gexp_antisym by blast
qed
end
end