-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRange.thy
More file actions
346 lines (318 loc) · 10.1 KB
/
Range.thy
File metadata and controls
346 lines (318 loc) · 10.1 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
theory Range imports Main begin
(* NLS-1 *)
definition R :: "(int \<times> int) set" where
"R == { (x, y) | x y. x \<le> y }"
lemma le_le_trans: "\<lbrakk> a \<le> b; b \<le> c \<rbrakk> \<Longrightarrow> a \<le> c" for type a::int
apply(rule leI)
apply(rule notI)
apply(drule_tac x=c and y=a and z=b in less_le_trans)
apply(assumption)
apply(drule_tac y=b in leD)
apply(erule notE)
apply(assumption)
done
(* NLS-5 *)
theorem "a > b \<Longrightarrow> (a, b) \<notin> R"
apply(unfold R_def)
apply(rule notI)
apply(erule CollectE)
apply(elim exE)
apply(erule conjE)
apply(erule Pair_inject)
apply(drule_tac eq_refl)
apply(drule sym)
apply(drule_tac a=x and b=y and c=b in ord_le_eq_trans)
apply(assumption)
apply(drule_tac a=a and b=x and c=b in le_le_trans)
apply(assumption)
apply(drule_tac y=a in leD)
apply(erule notE)
apply(assumption)
done
fun lower_endpoint :: "(int \<times> int) \<Rightarrow> int" where
"lower_endpoint (x, y) = x"
fun upper_endpoint :: "(int \<times> int) \<Rightarrow> int" where
"upper_endpoint (x, y) = y"
(* NLS-2 *)
theorem "r \<in> R \<Longrightarrow> \<exists>x. x = lower_endpoint r"
apply(unfold R_def)
apply(erule CollectE)
apply(elim exE)
apply(drule conjunct1)
apply(erule ssubst)
apply(subst lower_endpoint.simps)
apply(rule_tac x=x in exI)
apply(rule refl)
done
(* NLS-2 *)
theorem "r \<in> R \<Longrightarrow> \<exists>x. x = upper_endpoint r"
apply(unfold R_def)
apply(erule CollectE)
apply(elim exE)
apply(drule conjunct1)
apply(erule ssubst)
apply(subst upper_endpoint.simps)
apply(rule_tac x=y in exI)
apply(rule refl)
done
fun in_range :: "int \<Rightarrow> (int \<times> int) \<Rightarrow> bool" where
"in_range n (x, y) = (x \<le> n \<and> n \<le> y)"
(* NLS-6 *)
theorem "\<forall>n. \<forall>r \<in> R. \<exists>b. b = in_range n r"
apply(unfold R_def)
apply(intro allI)
apply(rule ballI)
apply(erule CollectE)
apply(elim exE)
apply(erule conjE)
apply(erule ssubst)
apply(subst in_range.simps)
apply(rule_tac x="x \<le> n \<and> n \<le> y" in exI)
apply(rule refl)
done
(* NLS-9 *)
lemma example_3_8_in_R: "(3, 8) \<in> R"
apply(unfold R_def)
apply(rule CollectI)
apply(rule_tac x=3 in exI)
apply(rule_tac x=8 in exI)
apply(rule conjI)
apply(rule refl)
apply(simp)
done
(* NLS-10 *)
theorem "lower_endpoint (3, 8) = 3"
apply(subst lower_endpoint.simps)
apply(rule refl)
done
(* NLS-10 *)
theorem "upper_endpoint (3, 8) = 8"
apply(subst upper_endpoint.simps)
apply(rule refl)
done
fun char_of_digit :: "nat \<Rightarrow> char" where
c0: "char_of_digit 0 = CHR ''0''" |
c1: "char_of_digit (Suc 0) = CHR ''1''" |
c2: "char_of_digit (Suc (Suc 0)) = CHR ''2''" |
c3: "char_of_digit (Suc (Suc (Suc 0))) = CHR ''3''" |
c4: "char_of_digit (Suc (Suc (Suc (Suc 0)))) = CHR ''4''" |
c5: "char_of_digit (Suc (Suc (Suc (Suc (Suc 0))))) = CHR ''5''" |
c6: "char_of_digit (Suc (Suc (Suc (Suc (Suc (Suc 0)))))) = CHR ''6''" |
c7: "char_of_digit (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0))))))) = CHR ''7''" |
c8: "char_of_digit (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0)))))))) = CHR ''8''" |
c9: "char_of_digit (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0))))))))) = CHR ''9''" |
"char_of_digit _ = CHR ''?''"
fun string_of_nat :: "nat \<Rightarrow> string" where
"string_of_nat i = (if i < 10
then [char_of_digit i]
else (string_of_nat (i div 10)) @ [char_of_digit (i mod 10)])"
fun string_of_int :: "int \<Rightarrow> string" where
"string_of_int i = (if i > 0
then string_of_nat (nat i)
else (CHR ''-'') # (string_of_nat (nat \<bar>i\<bar>)))"
fun range_string :: "(int \<times> int) \<Rightarrow> string" where
"range_string (a, b) = [CHR ''[''] @ (string_of_int a) @ [CHR '',''] @ (string_of_int b) @ [CHR '']'']"
(* NLS-3 *)
theorem stringify: "r \<in> R \<Longrightarrow> \<exists>s. s = range_string r"
apply(unfold R_def)
apply(erule CollectE)
apply(elim exE)
apply(erule conjE)
apply(erule ssubst)
apply(rule_tac x="range_string (x, y)" in exI)
apply(rule refl)
done
(* NLS-4 *)
theorem stringify_3_8: "range_string (3, 8) = ''[3,8]''"
apply(unfold range_string.simps)
apply(unfold string_of_int.simps)
apply(simp)
apply(rule conjI)
apply(subgoal_tac "3 = (Suc (Suc (Suc 0)))")
apply(erule ssubst)
apply(rule c3)
apply(simp)
apply(subgoal_tac "8 = (Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc 0))))))))")
apply(erule ssubst)
apply(rule c8)
apply(simp)
done
(* NLS-11, NLS-12 *)
theorem example_3_8: "\<lbrakk> r = (3, 8); E = { x | x. 3 \<le> x \<and> x \<le> 8 } \<rbrakk> \<Longrightarrow>
\<forall>n. n \<in> E \<longleftrightarrow> in_range n r"
apply(elim ssubst)
apply(subst in_range.simps)
apply(rule allI)
apply(rule iffI)
apply(erule CollectE)
apply(erule exE)
apply(erule conjE)
apply(erule ssubst)
apply(assumption)
apply(rule CollectI)
apply(rule_tac x=n in exI)
apply(rule conjI)
apply(rule refl)
apply(assumption)
done
fun range_eq :: "(int \<times> int) \<Rightarrow> (int \<times> int) \<Rightarrow> bool" where
"range_eq (a1, a2) (b1, b2) = (a1 = b1 \<and> a2 = b2)"
(* NLS-7 *)
theorem "range_eq (a1, a2) (b1, b2) \<Longrightarrow>
\<forall>n. in_range n (a1, a2) \<longleftrightarrow> in_range n (b1, b2)"
apply(erule range_eq.elims)
apply(rule allI)
apply(erule conjE)
apply(elim Pair_inject)
apply(drule_tac r=a1 and s=a1a and t=b1a in trans)
apply(assumption)
apply(drule_tac r=a1 and s=b1a and t=b1 in trans_sym)
apply(assumption)
apply(drule_tac r=a2 and s=a2a and t=b2a in trans)
apply(assumption)
apply(drule_tac r=a2 and s=b2a and t=b2 in trans_sym)
apply(assumption)
apply(erule_tac t=b1 and s=a1 in subst)
apply(erule_tac t=b2 and s=a2 in subst)
apply(rule refl)
done
theorem range_eq_sym: "range_eq (a1, a2) (b1, b2) \<longleftrightarrow> range_eq (b1, b2) (a1, a2)"
apply(subst range_eq.simps)
apply(subst range_eq.simps)
apply(rule iffI)
apply(erule conjE)
apply(erule subst)
apply(erule subst)
apply(rule conjI)
apply(rule refl)
apply(rule refl)
apply(erule conjE)
apply(erule subst)
apply(erule subst)
apply(rule conjI)
apply(rule refl)
apply(rule refl)
done
lemma all_iffD: "(\<forall>x. P x \<longleftrightarrow> Q x) \<Longrightarrow> (\<forall>x. P x \<longrightarrow> Q x) \<and> (\<forall>x. Q x \<longrightarrow> P x)"
apply(rule conjI)
apply(rule allI)
apply(erule_tac x=x in allE)
apply(erule iffE)
apply(assumption)
apply(rule allI)
apply(erule_tac x=x in allE)
apply(erule iffE)
apply(assumption)
done
lemma range_uniq: "\<lbrakk> a1 \<le> a2; b1 \<le> b2; \<forall>n. (a1 \<le> n \<and> n \<le> a2) \<longleftrightarrow> (b1 \<le> n \<and> n \<le> b2) \<rbrakk> \<Longrightarrow> a1 = b1 \<and> a2 = b2" for a1::int and a2::int and b1::int and b2::int
apply(drule all_iffD)
apply(erule conjE)
apply(rule conjI)
apply(erule_tac x=a1 in allE)
apply(erule impE)
apply(rule conjI)
apply(rule order_refl)
apply(assumption)
apply(erule conjE)
apply(erule_tac x=b1 in allE)
apply(erule impE)
apply(rule conjI)
apply(rule order_refl)
apply(assumption)
apply(erule conjE)
apply(erule antisym)
apply(assumption)
apply(erule_tac x=a2 in allE)
apply(erule impE)
apply(erule conjI)
apply(rule order_refl)
apply(erule_tac x=b2 in allE)
apply(erule impE)
apply(erule conjI)
apply(rule order_refl)
apply(elim conjE)
apply(erule antisym)
apply(assumption)
done
theorem in_range_uniq: "\<forall>r1 \<in> R. \<forall>r2 \<in> R.
r1 = (a1, a2) \<and> r2 = (b1, b2)
\<longrightarrow> (\<forall>n. in_range n (a1, a2) \<longleftrightarrow> in_range n (b1, b2))
\<longrightarrow> range_eq (a1, a2) (b1, b2)"
apply(unfold R_def)
apply(subst range_eq.simps)
apply(subst in_range.simps)
apply(subst in_range.simps)
apply(intro ballI)
apply(intro impI)
apply(elim conjE)
apply(drule_tac a=r1 and b="(a1, a2)" in back_subst)
apply(assumption)
apply(drule_tac a=r2 and b="(b1, b2)" in back_subst)
apply(assumption)
apply(elim CollectE)
apply(elim exE)
apply(elim conjE)
apply(elim Pair_inject)
apply(drule_tac a=a1 and b=x and c=y in ord_eq_le_trans)
apply(assumption)
apply(drule_tac a=a1 and b=y and c=a2 in ord_le_eq_trans)
apply(erule sym)
apply(drule_tac a=b1 and b=xa and c=ya in ord_eq_le_trans)
apply(assumption)
apply(drule_tac a=b1 and b=ya and c=b2 in ord_le_eq_trans)
apply(erule sym)
apply(erule range_uniq)
apply(assumption)
apply(assumption)
done
fun range_contains :: "(int \<times> int) \<Rightarrow> (int \<times> int) \<Rightarrow> bool" where
"range_contains (a1, a2) (b1, b2) = (a1 \<le> b1 \<and> b2 \<le> a2)"
(* NLS-8 *)
theorem "range_contains (a1, a2) (b1, b2) \<Longrightarrow>
\<forall>n. in_range n (b1, b2) \<longrightarrow> in_range n (a1, a2)"
apply(unfold in_range.simps)
apply(erule range_contains.elims)
apply(elim Pair_inject)
apply(rule allI)
apply(rule impI)
apply(elim conjE)
apply(rule conjI)
apply(erule ssubst)
apply(drule_tac s=b2 in sym)
apply(drule_tac s=b1 in sym)
apply(drule_tac x=b1a in eq_refl)
apply(erule_tac a=a1 and b=b1a and c=n in le_le_trans)
apply(erule_tac b=b1 and c=n in le_le_trans)
apply(assumption)
apply(drule_tac s=b2 in sym)
apply(drule_tac s=b2 and P="\<lambda>b2. n \<le> b2" in ssubst)
apply(assumption)
apply(drule_tac a=n and b=b2a and c=a2a in le_le_trans)
apply(assumption)
apply(erule_tac t=a2 in ssubst)
apply(assumption)
done
theorem range_contains_antisym: "range_contains (a1, a2) (b1, b2) \<and> range_contains (b1, b2) (a1, a2) \<longleftrightarrow> range_eq (a1, a2) (b1, b2)"
apply(subst range_contains.simps)
apply(subst range_contains.simps)
apply(subst range_eq.simps)
apply(rule iffI)
apply(elim conjE)
apply(rule conjI)
apply(erule antisym)
apply(assumption)
apply(erule_tac x=a2 in antisym)
apply(assumption)
apply(erule conjE)
apply(rule conjI)
apply(erule subst)
apply(erule subst)
apply(rule conjI)
apply(rule order_refl)
apply(rule order_refl)
apply(erule subst)
apply(erule subst)
apply(rule conjI)
apply(rule order_refl)
apply(rule order_refl)
done