-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathsetSpecScript.sml
557 lines (460 loc) · 12.6 KB
/
setSpecScript.sml
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
(*
Specification of (roughly) Zermelo's set theory.
Two main definitions:
is_set_theory (mem : 'U -> 'U -> bool), and
is_model (mem, indset, ch)
*)
open preamble cardinalTheory
val _ = new_theory"setSpec"
val _ = Parse.remove_type_abbrev "reln";
val _ = Parse.remove_type_abbrev "inf";
(* http://www.lemma-one.com/ProofPower/specs/spc002.pdf *)
val _ = Parse.hide "mem";
val mem = ``mem:'U->'U->bool``
val _ = Parse.add_infix("<:",425,Parse.NONASSOC)
Overload "<:" = ``mem:'U->'U->bool``
Definition extensional_def:
extensional ^mem ⇔ ∀x y. x = y ⇔ ∀a. mem a x ⇔ mem a y
End
Definition is_separation_def:
is_separation ^mem sub ⇔ ∀x P. ∀a. mem a (sub x P) ⇔ mem a x ∧ P a
End
Definition is_power_def:
is_power ^mem power ⇔ ∀x. ∀a. mem a (power x) ⇔ ∀b. mem b a ⇒ mem b x
End
Definition is_union_def:
is_union ^mem union ⇔ ∀x. ∀a. mem a (union x) ⇔ ∃b. mem a b ∧ mem b x
End
Definition is_upair_def:
is_upair ^mem upair ⇔ ∀x y. ∀a. mem a (upair x y) ⇔ a = x ∨ a = y
End
Definition is_set_theory_def:
is_set_theory ^mem ⇔
extensional mem ∧
(∃sub. is_separation mem sub) ∧
(∃power. is_power mem power) ∧
(∃union. is_union mem union) ∧
(∃upair. is_upair mem upair)
End
Theorem separation_unique:
extensional ^mem ⇒
∀sub1 sub2. is_separation mem sub1 ∧ is_separation mem sub2 ⇒ sub1 = sub2
Proof
rw[is_separation_def,extensional_def,FUN_EQ_THM]
QED
Theorem power_unique:
extensional ^mem ⇒
∀power1 power2. is_power mem power1 ∧ is_power mem power2 ⇒ power1 = power2
Proof
rw[is_power_def,extensional_def,FUN_EQ_THM]
QED
Theorem union_unique:
extensional ^mem ⇒
∀union1 union2. is_union mem union1 ∧ is_union mem union2 ⇒ union1 = union2
Proof
rw[is_union_def,extensional_def,FUN_EQ_THM]
QED
Theorem upair_unique:
extensional ^mem ⇒
∀upair1 upair2. is_upair mem upair1 ∧ is_upair mem upair2 ⇒ upair1 = upair2
Proof
rw[is_upair_def,extensional_def,FUN_EQ_THM]
QED
Definition sub_def:
sub ^mem = @sub. is_separation mem sub
End
Definition power_def:
power ^mem = @power. is_power mem power
End
Definition union_def:
union ^mem = @union. is_union mem union
End
Definition upair_def:
upair ^mem = @upair. is_upair mem upair
End
Theorem is_extensional:
is_set_theory ^mem ⇒ extensional mem
Proof
rw[is_set_theory_def]
QED
Theorem is_separation_sub:
is_set_theory ^mem ⇒ is_separation mem (sub mem)
Proof
rw[sub_def] >> SELECT_ELIM_TAC >> fsrw_tac[SATISFY_ss][is_set_theory_def]
QED
Theorem is_power_power:
is_set_theory ^mem ⇒ is_power mem (power mem)
Proof
rw[power_def] >> SELECT_ELIM_TAC >> fsrw_tac[SATISFY_ss][is_set_theory_def]
QED
Theorem is_union_union:
is_set_theory ^mem ⇒ is_union mem (union mem)
Proof
rw[union_def] >> SELECT_ELIM_TAC >> fsrw_tac[SATISFY_ss][is_set_theory_def]
QED
Theorem is_upair_upair:
is_set_theory ^mem ⇒ is_upair mem (upair mem)
Proof
rw[upair_def] >> SELECT_ELIM_TAC >> fsrw_tac[SATISFY_ss][is_set_theory_def]
QED
val _ = Parse.add_infix("suchthat",9,Parse.LEFT)
Overload suchthat = ``sub ^mem``
Overload Pow = ``power ^mem``
Overload "+" = ``upair ^mem``
Theorem mem_sub:
is_set_theory ^mem ⇒ ∀x s P. x <: (s suchthat P) ⇔ x <: s ∧ P x
Proof
strip_tac >> imp_res_tac is_separation_sub >> fs[is_separation_def]
QED
Theorem mem_power:
is_set_theory ^mem ⇒
∀x y. x <: (Pow y) ⇔ (∀b. b <: x ⇒ b <: y)
Proof
strip_tac >> imp_res_tac is_power_power >> fs[is_power_def]
QED
Theorem mem_union:
is_set_theory ^mem ⇒
∀x s. x <: (union mem s) ⇔ ∃a. x <: a ∧ a <: s
Proof
strip_tac >> imp_res_tac is_union_union >> fs[is_union_def]
QED
Theorem mem_upair:
is_set_theory ^mem ⇒ ∀a x y. a <: (x + y) ⇔ a = x ∨ a = y
Proof
strip_tac >> imp_res_tac is_upair_upair >> fs[is_upair_def]
QED
Definition empty_def:
empty ^mem = sub mem ARB (K F)
End
Overload "∅" = ``empty ^mem``
Theorem mem_empty:
is_set_theory ^mem ⇒ ∀x. ¬(x <: ∅)
Proof
strip_tac >> imp_res_tac is_separation_sub >>
fs[empty_def,is_separation_def]
QED
Definition unit_def:
unit ^mem x = x + x
End
Overload Unit = ``unit ^mem``
Theorem mem_unit:
is_set_theory ^mem ⇒
∀x y. x <: (Unit y) ⇔ x = y
Proof
strip_tac >> imp_res_tac is_upair_upair >>
fs[is_upair_def,unit_def]
QED
Theorem unit_inj:
is_set_theory ^mem ⇒
∀x y. Unit x = Unit y ⇔ x = y
Proof
strip_tac >>
imp_res_tac is_extensional >>
fs[extensional_def,mem_unit] >>
metis_tac[]
QED
Definition one_def:
one ^mem = Unit ∅
End
Overload One = ``one ^mem``
Theorem mem_one:
is_set_theory ^mem ⇒
∀x. x <: One ⇔ x = ∅
Proof
strip_tac >> simp[mem_unit,one_def]
QED
Definition two_def:
two ^mem = ∅ + One
End
Overload Two = ``two ^mem``
Theorem mem_two:
is_set_theory ^mem ⇒
∀x. x <: Two ⇔ x = ∅ ∨ x = One
Proof
strip_tac >> simp[mem_upair,mem_one,two_def]
QED
Definition pair_def:
pair ^mem x y = (Unit x) + (x + y)
End
Overload "," = ``pair ^mem``
Theorem upair_inj:
is_set_theory ^mem ⇒
∀a b c d. a + b = c + d ⇔ a = c ∧ b = d ∨ a = d ∧ b = c
Proof
strip_tac >>
imp_res_tac is_extensional >>
fs[extensional_def,mem_upair] >>
metis_tac[]
QED
Theorem unit_eq_upair:
is_set_theory ^mem ⇒
∀x y z. Unit x = y + z ⇔ x = y ∧ y = z
Proof
strip_tac >>
imp_res_tac is_extensional >>
fs[extensional_def,mem_unit,mem_upair] >>
metis_tac[]
QED
Theorem pair_inj:
is_set_theory ^mem ⇒
∀a b c d. (a,b) = (c,d) ⇔ a = c ∧ b = d
Proof
strip_tac >> fs[pair_def] >> rw[] >>
simp[upair_inj,unit_inj,unit_eq_upair] >>
metis_tac[]
QED
Definition binary_union_def:
binary_union ^mem x y = union mem (upair mem x y)
End
Overload UNION = ``binary_union ^mem``
Theorem mem_binary_union:
is_set_theory ^mem ⇒
∀a x y. a <: (x ∪ y) ⇔ a <: x ∨ a <: y
Proof
strip_tac >> fs[binary_union_def,mem_union,mem_upair] >>
metis_tac[]
QED
Definition product_def:
product ^mem x y =
(Pow (Pow (x ∪ y)) suchthat
λa. ∃b c. b <: x ∧ c <: y ∧ a = (b,c))
End
Overload CROSS = ``product ^mem``
Theorem mem_product:
is_set_theory ^mem ⇒
∀a x y. a <: (x × y) ⇔ ∃b c. a = (b,c) ∧ b <: x ∧ c <: y
Proof
strip_tac >> fs[product_def] >>
simp[mem_sub,mem_power,mem_binary_union] >>
rw[EQ_IMP_THM] >> TRY(metis_tac[]) >>
rfs[pair_def,mem_upair] >> rw[] >>
rfs[mem_unit,mem_upair]
QED
Definition relspace_def:
relspace ^mem x y = Pow (x × y)
End
Overload Relspace = ``relspace ^mem``
Definition funspace_def:
funspace ^mem x y =
(Relspace x y suchthat
λf. ∀a. a <: x ⇒ ∃!b. (a,b) <: f)
End
Overload Funspace = ``funspace ^mem``
Definition apply_def:
apply ^mem x y = @a. (y,a) <: x
End
Overload "'" = ``apply ^mem``
Overload boolset = ``Two``
Definition true_def:
true ^mem = ∅
End
Definition false_def:
false ^mem = One
End
Overload True = ``true ^mem``
Overload False = ``false ^mem``
Theorem true_neq_false:
is_set_theory ^mem ⇒ True ≠ False
Proof
strip_tac >>
imp_res_tac mem_one >>
imp_res_tac mem_empty >>
fs[true_def,false_def,is_set_theory_def,extensional_def,one_def] >>
metis_tac[]
QED
Theorem mem_boolset:
is_set_theory ^mem ⇒
∀x. x <: boolset ⇔ ((x = True) ∨ (x = False))
Proof
strip_tac >> fs[mem_two,true_def,false_def]
QED
Definition boolean_def:
boolean ^mem b = if b then True else False
End
Overload Boolean = ``boolean ^mem``
Theorem boolean_in_boolset:
is_set_theory ^mem ⇒
∀b. Boolean b <: boolset
Proof
strip_tac >> imp_res_tac mem_boolset >>
Cases >> simp[boolean_def]
QED
Theorem boolean_eq_true:
is_set_theory ^mem ⇒ ∀b. Boolean b = True ⇔ b
Proof
strip_tac >> rw[boolean_def,true_neq_false]
QED
Definition holds_def:
holds ^mem s x ⇔ s ' x = True
End
Overload Holds = ``holds ^mem``
Definition abstract_def:
abstract ^mem dom rng f = (dom × rng suchthat λx. ∃a. x = (a,f a))
End
Overload Abstract = ``abstract ^mem``
Theorem apply_abstract:
is_set_theory ^mem ⇒
∀f x s t. x <: s ∧ f x <: t ⇒ (Abstract s t f) ' x = f x
Proof
strip_tac >>
rw[apply_def,abstract_def] >>
SELECT_ELIM_TAC >>
simp[mem_sub,mem_product,pair_inj]
QED
Theorem apply_abstract_matchable:
∀f x s t u. x <: s ∧ f x <: t ∧ is_set_theory ^mem ∧ f x = u ⇒ Abstract s t f ' x = u
Proof
metis_tac[apply_abstract]
QED
Theorem apply_in_rng:
is_set_theory ^mem ⇒
∀f x s t. x <: s ∧ f <: Funspace s t ⇒
f ' x <: t
Proof
strip_tac >>
simp[funspace_def,mem_sub,relspace_def,
mem_power,apply_def,mem_product,EXISTS_UNIQUE_THM] >>
rw[] >> res_tac >> SELECT_ELIM_TAC >> res_tac >> rfs[pair_inj] >> metis_tac[]
QED
Theorem abstract_in_funspace:
is_set_theory ^mem ⇒
∀f s t. (∀x. x <: s ⇒ f x <: t) ⇒ Abstract s t f <: Funspace s t
Proof
strip_tac >>
simp[funspace_def,relspace_def,abstract_def,mem_power,mem_product,mem_sub] >>
simp[EXISTS_UNIQUE_THM,pair_inj]
QED
Theorem abstract_in_funspace_matchable:
is_set_theory ^mem ⇒
∀f s t fs. (∀x. x <: s ⇒ f x <: t) ∧ fs = Funspace s t ⇒ Abstract s t f <: fs
Proof
PROVE_TAC[abstract_in_funspace]
QED
Theorem abstract_eq:
is_set_theory ^mem ⇒
∀s t1 t2 f g.
(∀x. x <: s ⇒ f x <: t1 ∧ g x <: t2 ∧ f x = g x)
⇒ Abstract s t1 f = Abstract s t2 g
Proof
rw[] >>
imp_res_tac is_extensional >>
pop_assum mp_tac >>
simp[extensional_def] >>
disch_then kall_tac >>
simp[abstract_def,mem_sub,mem_product] >>
metis_tac[pair_inj]
QED
Theorem in_funspace_abstract:
is_set_theory ^mem ⇒
∀z s t. z <: Funspace s t ⇒
∃f. z = Abstract s t f ∧ (∀x. x <: s ⇒ f x <: t)
Proof
rw[funspace_def,mem_sub,relspace_def,mem_power] >>
qexists_tac`λx. @y. (x,y) <: z` >>
conj_tac >- (
imp_res_tac is_extensional >>
pop_assum(fn th => SIMP_TAC std_ss [SIMP_RULE std_ss [extensional_def] th]) >>
simp[abstract_def,EQ_IMP_THM] >> gen_tac >>
rfs[mem_sub,mem_product] >>
conj_tac >>
TRY strip_tac >>
rfs[pair_inj] >>
fs[EXISTS_UNIQUE_THM] >>
metis_tac[] ) >>
rfs[EXISTS_UNIQUE_THM,mem_product] >>
metis_tac[pair_inj]
QED
Theorem axiom_of_choice =
UNDISCH(prove(
``is_set_theory ^mem ⇒
∀x. (∀a. mem a x ⇒ ∃b. mem b a) ⇒
∃f. ∀a. mem a x ⇒ mem (f ' a) a``,
rw[] >>
qexists_tac`Abstract x (union mem x) (λa. @b. mem b a)` >>
rw[] >>
qmatch_abbrev_tac`z <: a` >>
qsuff_tac`z = @b. b <: a` >- (
SELECT_ELIM_TAC >> rw[] ) >>
unabbrev_all_tac >>
match_mp_tac apply_abstract_matchable >>
rw[mem_union] >>
SELECT_ELIM_TAC >> rw[] >>
metis_tac[]))
val indset = ``indset:'U``
val ch = ``ch:'U->'U``
val s = ``(^mem,^indset,^ch)``
Overload M = ``(^mem,^indset,^ch)``
Definition is_choice_def:
is_choice ^mem ch = ∀x. (∃a. a <: x) ⇒ ch x <: x
End
Definition is_infinite_def:
is_infinite ^mem s = INFINITE {a | a <: s}
End
Definition is_model_def:
is_model ^s ⇔
is_set_theory mem ∧
is_infinite mem indset ∧
is_choice mem ch
End
Theorem is_model_is_set_theory:
is_model M ⇒ is_set_theory ^mem
Proof
rw[is_model_def]
QED
Theorem indset_inhabited:
is_infinite ^mem indset ⇒ ∃i. i <: indset
Proof
rw[is_infinite_def] >> imp_res_tac INFINITE_INHAB >>
fs[] >> metis_tac[]
QED
Theorem funspace_inhabited:
is_set_theory ^mem ⇒ ∀s t. (∃x. x <: s) ∧ (∃x. x <: t) ⇒ ∃f. f <: Funspace s t
Proof
rw[] >> qexists_tac`Abstract s t (λx. @x. x <: t)` >>
match_mp_tac (MP_CANON abstract_in_funspace) >>
metis_tac[]
QED
Definition tuple_def:
(tuple0 ^mem [] = ∅) ∧
(tuple0 ^mem (a::as) = (a, tuple0 ^mem as))
End
Overload tuple = ``tuple0 ^mem``
Theorem pair_not_empty:
is_set_theory ^mem ⇒ (x,y) ≠ ∅
Proof
rw[] >>
imp_res_tac is_extensional >>
fs[extensional_def,mem_empty] >>
pop_assum kall_tac >>
simp[pair_def,mem_upair] >>
metis_tac[]
QED
Theorem tuple_empty:
is_set_theory ^mem ⇒ ∀ls. tuple ls = ∅ ⇔ ls = []
Proof
strip_tac >> Cases >> simp[tuple_def] >>
simp[pair_not_empty]
QED
Theorem tuple_inj:
is_set_theory ^mem ⇒
∀l1 l2. tuple l1 = tuple l2 ⇔ l1 = l2
Proof
strip_tac >>
Induct >> simp[tuple_def] >- metis_tac[tuple_empty] >>
gen_tac >> Cases >> simp[tuple_def,pair_not_empty] >>
simp[pair_inj]
QED
Definition bigcross_def:
(bigcross0 ^mem [] = One) ∧
(bigcross0 ^mem (a::as) = a × (bigcross0 ^mem as))
End
Overload bigcross = ``bigcross0 ^mem``
Theorem mem_bigcross:
is_set_theory ^mem ⇒
∀ls x. (mem x (bigcross ls) ⇔ ∃xs. x = tuple xs ∧ LIST_REL mem xs ls)
Proof
strip_tac >> Induct >>
simp[bigcross_def,tuple_def,mem_one] >>
simp[mem_product,PULL_EXISTS,tuple_def]
QED
val _ = export_theory()