Repository navigation
Expand file tree
/
Copy pathProgram_Semantics_3.thy
More file actions
2290 lines (2062 loc) · 103 KB
/
Copy pathProgram_Semantics_3.thy
File metadata and controls
2290 lines (2062 loc) · 103 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
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
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
theory Program_Semantics_3
imports Main HOL.Real "~~/src/HOL/Library/Countable_Set"
begin
\<comment> \<open>理解を確認するため組み込みの定義は使いません。\<close>
hide_const less less_eq sup inf top bot Sup Inf refl_on trans antisym partial_order_on range mono antimono range lfp
\<comment> \<open>これから先の定義では、台集合 D や D' を UNIV と同一視します。これによって台集合が有限であった場合の帰納法が封印されますが、これによって解けなくなる問題はありませんでした。\<close>
chapter "第3章 領域理論の基礎"
section "3.1 データの近似と極限"
subsection "定義3.1.1"
text "集合 D 上の二項関係 \<sqsubseteq> で次の性質を満たすものを D 上の半順序(partial order)と呼ぶ。"
text "(1) a \<sqsubseteq> a(反射律)"
text "(2) a \<sqsubseteq> b かつ b \<sqsubseteq> a ならば a = b(反対称律)"
text "(3) a \<sqsubseteq> b かつ b \<sqsubseteq> c ならば a \<sqsubseteq> c(推移律)"
class po =
fixes le :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<sqsubseteq>" 53)
assumes refl: "\<And>a. a \<sqsubseteq> a"
and antisym: "\<And>a b. \<lbrakk> a \<sqsubseteq> b; b \<sqsubseteq> a \<rbrakk> \<Longrightarrow> a = b"
and trans: "\<And>a b c. \<lbrakk> a \<sqsubseteq> b; b \<sqsubseteq> c \<rbrakk> \<Longrightarrow> a \<sqsubseteq> c"
subsection "定義 3.1.2"
text "半順序集合 D 上の最小元(least element あるいは bottom)とは、次の条件を満たす元 \<bottom> \<in> D のことである。"
text "\<forall>a \<in> D (\<bottom> \<sqsubseteq> a)"
class bot =
fixes bot :: 'a ("\<bottom>")
class po_bot = po + bot +
assumes bot_le: "\<And>a. \<bottom> \<sqsubseteq> a"
text "最小元と対になる概念として、半順序集合 D の最大元(greatest element あるいは top)とは、次の条件を満たす元 \<top> \<in> D である。"
text "\<forall>a \<in> D (a \<sqsubseteq> \<top>)"
class top =
fixes top :: 'a ("\<top>")
class po_top = po + top +
assumes le_top: "\<And>a. a \<sqsubseteq> \<top>"
subsection "定義 3.1.3"
text "D を半順序集合、X を D の部分集合とする。元 d \<in> D について、"
text "\<forall>x \<in> X (x \<sqsubseteq> d)"
text "のとき d は X の上界(upper bound)であるといい、X \<sqsubseteq> d と書く。"
definition (in po) upper :: "'a set \<Rightarrow> 'a \<Rightarrow> bool" (infix "\<^sub>s\<sqsubseteq>" 51) \<comment> \<open>同じ文字の演算子があるので重複定義になることを避けた\<close>
where "X \<^sub>s\<sqsubseteq> d \<equiv> \<forall>x \<in> X. x \<sqsubseteq> d"
lemma (in po) upperE:
assumes "X \<^sub>s\<sqsubseteq> d"
and "x \<in> X"
shows "x \<sqsubseteq> d"
using assms unfolding upper_def by blast
lemma (in po) upperI:
assumes "\<And>x. x \<in> X \<Longrightarrow> x \<sqsubseteq> d"
shows "X \<^sub>s\<sqsubseteq> d"
unfolding upper_def using assms by blast
text "また、d が X の上界のうち最小の元であるとき、d を X の上限(supremum)あるいは"
text "最小上界(least upper bound)と呼ぶ。すなわち、X の上限は次の2つの条件を満たす元 d \<in> D のことである。"
text "X \<sqsubseteq> d, \<forall>a \<in> D (X \<sqsubseteq> a ならば d \<sqsubseteq> a)"
definition (in po) supremum :: "'a set \<Rightarrow> 'a \<Rightarrow> bool"
where "supremum X d \<equiv> X \<^sub>s\<sqsubseteq> d \<and> (\<forall>a. X \<^sub>s\<sqsubseteq> a \<longrightarrow> d \<sqsubseteq> a)"
lemma (in po) supremumI:
assumes "X \<^sub>s\<sqsubseteq> d"
and "\<And>a. X \<^sub>s\<sqsubseteq> a \<Longrightarrow> d \<sqsubseteq> a"
shows "supremum X d"
unfolding supremum_def using assms by blast
lemma (in po)
assumes "supremum X d"
shows supremum_upperE: "X \<^sub>s\<sqsubseteq> d"
and supremum_leastE: "\<And>a. X \<^sub>s\<sqsubseteq> a \<Longrightarrow> d \<sqsubseteq> a"
using assms unfolding supremum_def by blast+
lemma (in po) supremum_leE:
assumes sup_d: "supremum X d"
and x_mem: "x \<in> X"
shows "x \<sqsubseteq> d"
using supremum_upperE[OF sup_d] x_mem by (rule upperE)
text "同様に上界および上限と対になる概念として、下界および下限が定義できる。元 d \<in> D について、"
text "\<forall>x \<in> X (d \<sqsubseteq> x)"
text "のとき、d は X の下界(lower bound)であるといい、d \<sqsubseteq> X と書く。"
text "また、d が X の下界のうち最大の元のとき、d を Xの下限(infimum)あるいは最大下界(greatest lower bound)と呼ぶ。"
definition (in po) lower :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" (infix "\<sqsubseteq>\<^sub>s" 51) \<comment> \<open>同じ文字の演算子があるので重複定義になることを避けた\<close>
where "lower d X \<equiv> \<forall>x \<in> X. d \<sqsubseteq> x"
lemma (in po) lowerI:
assumes "\<And>x. x \<in> X \<Longrightarrow> d \<sqsubseteq> x"
shows "d \<sqsubseteq>\<^sub>s X"
unfolding lower_def using assms by blast
lemma (in po) lowerE:
assumes "d \<sqsubseteq>\<^sub>s X"
and "x \<in> X"
shows "d \<sqsubseteq> x"
using assms unfolding lower_def by blast
definition (in po) infimum :: "'a set \<Rightarrow> 'a \<Rightarrow> bool"
where "infimum X d \<equiv> d \<sqsubseteq>\<^sub>s X \<and> (\<forall>x. x \<sqsubseteq>\<^sub>s X \<longrightarrow> x \<sqsubseteq> d)"
lemma (in po) infimumI:
assumes "d \<sqsubseteq>\<^sub>s X"
and "\<And>a. a \<sqsubseteq>\<^sub>s X \<Longrightarrow> a \<sqsubseteq> d"
shows "infimum X d"
unfolding infimum_def using assms by blast
lemma (in po)
assumes "infimum X d"
shows infimum_lowerE: "d \<sqsubseteq>\<^sub>s X"
and infimum_greatestE: "\<And>a. a \<sqsubseteq>\<^sub>s X \<Longrightarrow> a \<sqsubseteq> d"
using assms unfolding infimum_def by blast+
lemma (in po) infimum_leE:
assumes inf_d: "infimum X d"
and x_mem: "x \<in> X"
shows "d \<sqsubseteq> x"
using infimum_lowerE[OF inf_d] x_mem by (rule lowerE)
text "半順序集合 D の部分集合 X について、常に X の上限が存在するとは限らないが、存在するとすれば唯一である。その元を \<squnion>X で表す。"
lemma (in po) supremum_uniq:
fixes a b :: 'a
assumes sup_a: "supremum X a"
and sup_b: "supremum X b"
shows "b = a"
proof -
show ?thesis proof (rule antisym)
show "a \<sqsubseteq> b" using sup_a proof (rule supremum_leastE)
show "X \<^sub>s\<sqsubseteq> b" using sup_b by (rule supremum_upperE)
qed
next
show "b \<sqsubseteq> a" using sup_b proof (rule supremum_leastE)
show "X \<^sub>s\<sqsubseteq> a" using sup_a by (rule supremum_upperE)
qed
qed
qed
definition (in po) Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion> _" [54] 54)
where "\<Squnion>X \<equiv> (THE x. supremum X x)"
lemma (in po) Sup_eq:
assumes "supremum X a"
shows "\<Squnion>X = a"
unfolding Sup_def using assms proof (rule the_equality)
show "\<And>d. supremum X d \<Longrightarrow> d = a" by (rule supremum_uniq[OF assms])
qed
lemma (in po) le_SupI:
assumes sup_x: "supremum X x"
and a_mem: "a \<in> X"
shows "a \<sqsubseteq> \<Squnion>X"
unfolding Sup_eq[OF sup_x] using sup_x a_mem by (rule supremum_leE)
lemma (in po) Sup_leI:
assumes sup_x: "supremum X x"
and upper_a: "X \<^sub>s\<sqsubseteq> a"
shows "\<Squnion>X \<sqsubseteq> a"
unfolding Sup_eq[OF sup_x] using sup_x upper_a by (rule supremum_leastE)
lemma (in po) supremum_SupI:
assumes sup_x: "supremum X x"
shows "supremum X (\<Squnion>X)"
unfolding Sup_eq[OF sup_x] by (rule sup_x)
text "同様に、X の下限が存在すれば唯一なので、その元を \<sqinter>X で表す。"
lemma (in po) infimum_uniq:
fixes a b :: 'a
assumes inf_a: "infimum X a"
and inf_b: "infimum X b"
shows "b = a"
proof (rule antisym)
show "b \<sqsubseteq> a" using inf_a proof (rule infimum_greatestE)
show "b \<sqsubseteq>\<^sub>s X" using inf_b by (rule infimum_lowerE)
qed
next
show "a \<sqsubseteq> b" using inf_b proof (rule infimum_greatestE)
show "a \<sqsubseteq>\<^sub>s X" using inf_a by (rule infimum_lowerE)
qed
qed
definition (in po) Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter> _" [54] 54)
where "\<Sqinter>X \<equiv> (THE x. infimum X x)"
lemma (in po) Inf_eq:
assumes "infimum X a"
shows "\<Sqinter>X = a"
unfolding Inf_def using assms proof (rule the_equality)
show "\<And>d. infimum X d \<Longrightarrow> d = a" using assms by (rule infimum_uniq)
qed
definition (in po) sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infix "\<squnion>" 54)
where "sup a b \<equiv> \<Squnion> {a, b}"
definition (in po) inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infix "\<sqinter>" 54)
where "inf a b \<equiv> \<Sqinter> {a, b}"
subsection "定義 3.1.4"
text "半順序集合 D において、すべての部分集合 X \<subseteq> D について上限 \<squnion>X \<in> D が存在するとき、D を完備束(complete_lattice)と呼ぶ。"
text "完備束の定義で X = \<emptyset> とすると、\<squnion>X は D の最小元になり、X = D とすると \<squnion>X は D の最大限になる。"
text "すなわち、完備束は常に最小元と最大元を持つことがわかる。"
class complete_lattice = po + bot + top +
assumes ex_supremum: "\<And>X. \<exists>d. supremum X d"
and bot_def: "\<bottom> = \<Squnion> {}"
and top_def: "\<top> = \<Squnion> UNIV"
begin
lemma le_Sup:
assumes "x \<in> X"
shows "x \<sqsubseteq> \<Squnion>X"
using Sup_eq assms ex_supremum supremum_upperE upperE by metis
lemma least_Sup:
assumes "X \<^sub>s\<sqsubseteq> b"
shows "\<Squnion>X \<sqsubseteq> b"
using Sup_eq assms ex_supremum supremum_leastE by metis
subclass po_bot
proof standard
show "\<And>a. \<bottom> \<sqsubseteq> a" unfolding bot_def proof -
fix a
show "\<Squnion> {} \<sqsubseteq> a" proof (rule least_Sup)
show "{} \<^sub>s\<sqsubseteq> a " unfolding upper_def by simp
qed
qed
qed
subclass po_top
proof standard
fix a
show "a \<sqsubseteq> \<top>" unfolding top_def using UNIV_I by (rule le_Sup)
qed
end
subsection "定義 3.1.5"
text "半順序集合 D の元の列 a0 \<sqsubseteq> a1 \<sqsubseteq> a2 \<sqsubseteq> \<dots> を \<omega> 鎖(\<omega>-chain)と呼ぶ。"
text "すなわち、列 (a0, a1, a2, \<dots>) は自然数の集合と1対1に対応し、i \<le> j ならば ai \<sqsubseteq> aj である。"
definition (in po) omega_chain :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool"
where "omega_chain f \<equiv> \<forall>i j. i \<le> j \<longrightarrow> f i \<sqsubseteq> f j"
lemma (in po) omega_chainI:
assumes "\<And>i j. i \<le> j \<Longrightarrow> f i \<sqsubseteq> f j"
shows "omega_chain f"
unfolding omega_chain_def using assms by blast
lemma (in po) omega_chainE:
assumes "omega_chain f"
shows omega_chain_leE: "\<And>i j. i \<le> j \<Longrightarrow> f i \<sqsubseteq> f j"
using assms unfolding omega_chain_def by blast+
subsection "定義 3.1.6"
text "半順序集合 D の空でない部分集合 X で、"
text "\<forall>a \<in> X \<forall>b \<in> X \<exists>c \<in> X (a \<sqsubseteq> c かつ b \<sqsubseteq> c)"
text "が成り立つとき、X は有向集合(directed set)であるという。"
definition (in po) directed :: "'a set \<Rightarrow> bool"
where "directed X \<equiv> X \<noteq> {} \<and> (\<forall>a \<in> X. \<forall>b \<in> X. \<exists>c \<in> X. a \<sqsubseteq> c \<and> b \<sqsubseteq> c)"
lemma (in po) directedI:
assumes "X \<noteq> {}"
and "\<And>a b. \<lbrakk> a \<in> X; b \<in> X \<rbrakk> \<Longrightarrow> \<exists>c \<in> X. a \<sqsubseteq> c \<and> b \<sqsubseteq> c"
shows "directed X"
unfolding directed_def using assms by blast
lemma (in po)
assumes "directed X"
shows directed_nemptyE: "X \<noteq> {}"
and directed_exE: "\<And>a b. \<lbrakk> a \<in> X; b \<in> X \<rbrakk> \<Longrightarrow> \<exists>c \<in> X. a \<sqsubseteq> c \<and> b \<sqsubseteq> c"
using assms unfolding directed_def by blast+
subsection "定義 3.1.7"
text "次の2つの条件を満たす半順序集合 D を完備半順序集合(complete partially ordered set)と呼ぶ。"
text "(1) D は最小元をもつ。"
text "(2) D は任意の有向部分集合 X について、X の上限 \<squnion> X \<in> D が存在する。"
class cpo = po_bot +
assumes ex_supremum: "\<And>X. directed X \<Longrightarrow> \<exists>d. supremum X d"
subsection "例 3.1.8"
subsection "例 3.1.9"
text "集合 S から T への部分関数の全体を [S \<rightharpoonup> T] と表す。"
typedef ('a, 'b) graph = "{R :: ('a \<times> 'b) set. single_valued R}"
proof (rule exI)
show "{} \<in> {R. single_valued R}" unfolding single_valued_def by blast
qed
text "前に説明したように部分関数間の半順序を"
text "f \<sqsubseteq> g \<Leftrightarrow> \<forall>x \<in> S (f(x) が定義されていれば g(x) も定義され f(x) = g(x))"
text "のように定義すると、[S \<rightharpoonup> T] は cpo となる。"
\<comment>\<open>後で証明\<close>
text "部分関数の半順序はもっと違った観点からも定義できる。f を S から T への部分関数として、直積"
text "S \<times> T = {(a, b)|a \<in> S かつ b \<in> T}"
text "の部分集合 {(x, f(x))|x \<in> S かつ f(x) が定義されている } を f のグラフと呼ぶ。"
instantiation graph :: (type, type) po
begin
text "部分関数 f とそのグラフを同一視すれば、f \<subseteq> g と f \<sqsubseteq> g は同じことになる。"
definition le_graph :: "('a, 'b) graph \<Rightarrow> ('a, 'b) graph \<Rightarrow> bool"
where "R1 \<sqsubseteq> R2 \<equiv> Rep_graph R1 \<subseteq> Rep_graph R2"
instance proof
fix a :: "('a, 'b) graph"
show "a \<sqsubseteq> a" unfolding le_graph_def by (rule order.refl)
next
fix a b :: "('a, 'b) graph"
assume "a \<sqsubseteq> b" "b \<sqsubseteq> a"
hence "Rep_graph a = Rep_graph b" unfolding le_graph_def by (rule order.antisym)
thus "a = b" by (simp add: Rep_graph_inject)
next
fix a b c :: "('a, 'b) graph"
assume "a \<sqsubseteq> b" "b \<sqsubseteq> c"
hence subset: "Rep_graph a \<subseteq> Rep_graph c" unfolding le_graph_def by (rule order.trans)
show "a \<sqsubseteq> c" unfolding le_graph_def by (rule subset)
qed
end
text "この半順序における [S \<rightharpoonup> T] の最小元は空集合を \<emptyset> \<in> S \<times> T、すなわち、いたるところ未定義の部分関数である。"
instantiation graph :: (type, type) po_bot
begin
definition bot_graph :: "('a, 'b) graph"
where "bot_graph \<equiv> Abs_graph {}"
instance proof
fix a :: "('a, 'b) graph"
have eq: "Rep_graph \<bottom> = {}" unfolding bot_graph_def proof (rule Abs_graph_inverse)
show "{} \<in> {R. single_valued R}" by auto
qed
show "\<bottom> \<sqsubseteq> a" unfolding le_graph_def eq by blast
qed
end
text "また F を [S \<rightharpoonup> T] の有向部分集合とすると、F の上限は \<Union>F である。"
lemma Rep_graph_Abs_graph_Un:
fixes F :: "('s, 't) graph set"
assumes directed: "directed F"
shows "Rep_graph (Abs_graph (\<Union> (Rep_graph ` F))) = \<Union>(Rep_graph ` F)"
proof (rule Abs_graph_inverse, rule CollectI)
show "single_valued (\<Union> (Rep_graph ` F))" using assms proof (rule contrapos_pp)
assume "\<not> single_valued (\<Union> (Rep_graph ` F))"
then obtain a b c
where mem1_Un: "(a, b) \<in> \<Union> (Rep_graph ` F)"
and mem2_Un: "(a, c) \<in> \<Union> (Rep_graph ` F)"
and neq: "b \<noteq> c"
unfolding single_valued_def by blast
obtain R1 R2
where mem1_R1: "(a, b) \<in> Rep_graph R1"
and R1_mem: "R1 \<in> F"
and mem2_R2: "(a, c) \<in> Rep_graph R2"
and R2_mem: "R2 \<in> F"
using mem1_Un mem2_Un by blast
show "\<not>directed F" unfolding directed_def ball_simps bex_simps proof auto
assume "\<forall>a\<in>F. \<forall>b\<in>F. \<exists>c\<in>F. a \<sqsubseteq> c \<and> b \<sqsubseteq> c"
then obtain R3 where R1_le_R3: "R1 \<sqsubseteq> R3" and R2_le_R3: "R2 \<sqsubseteq> R3" using R1_mem R2_mem by blast
show "False" using R1_le_R3 R2_le_R3 unfolding le_graph_def proof -
assume "Rep_graph R1 \<subseteq> Rep_graph R3"
hence mem1: "(a, b) \<in> Rep_graph R3" using mem1_R1 by blast
assume "Rep_graph R2 \<subseteq> Rep_graph R3"
hence mem2: "(a, c) \<in> Rep_graph R3" using mem2_R2 by blast
have "single_valued (Rep_graph R3)" using Rep_graph by blast
thus False unfolding single_valued_def using mem1 mem2 neq by blast
qed
qed
qed
qed
lemma supremum_graph:
fixes F :: "('a, 'b) graph set"
assumes directed: "directed F"
shows "supremum F (Abs_graph (\<Union> (Rep_graph ` F)))"
proof (rule supremumI)
show " F \<^sub>s\<sqsubseteq> Abs_graph (\<Union> (Rep_graph ` F))" proof (rule upperI)
fix x
assume x_mem: "x \<in> F"
show "x \<sqsubseteq> Abs_graph (\<Union> (Rep_graph ` F)) " unfolding le_graph_def Rep_graph_Abs_graph_Un[OF directed] using x_mem by blast
qed
next
fix a
assume upper_a: "F \<^sub>s\<sqsubseteq> a"
show "Abs_graph (\<Union> (Rep_graph ` F)) \<sqsubseteq> a" unfolding le_graph_def Rep_graph_Abs_graph_Un[OF directed] proof (rule Complete_Lattices.Sup_least)
fix x
assume x_mem: "x \<in> Rep_graph ` F"
then obtain y where x_eq: "x = Rep_graph y" and y_mem: "y \<in> F" by blast
show "x \<subseteq> Rep_graph a" using upperE[OF upper_a y_mem] unfolding le_graph_def x_eq .
qed
qed
instantiation graph :: (type, type) cpo
begin
instance proof
fix X :: "('a, 'b) graph set"
assume directed: "directed X"
show "\<exists>d. supremum X d" by (rule exI, rule supremum_graph[OF directed])
qed
end
subsection "例 3.1.10"
text "上の例で扱った部分関数は、未定義を表す特別な要素を導入して全関数とみなすこともできる。"
text "一般に、集合 S に新しく要素 \<bottom> を付け加えた集合 S_\<bottom> は、"
text "a \<sqsubseteq> b \<Leftrightarrow> a = \<bottom> あるいは a = b"
instantiation option :: (type) po
begin
definition le_option :: "('a option) \<Rightarrow> ('a option) \<Rightarrow> bool"
where "a \<sqsubseteq> b \<equiv> a = None \<or> a = b"
instance proof
fix a :: "'a option"
show "a \<sqsubseteq> a" unfolding le_option_def by blast
next
fix a b :: "'a option"
assume "a \<sqsubseteq> b" "b \<sqsubseteq> a"
thus "a = b" unfolding le_option_def by blast
next
fix a b c :: "'a option"
assume "a \<sqsubseteq> b" "b \<sqsubseteq> c"
thus "a \<sqsubseteq> c" unfolding le_option_def by blast
qed
end
instantiation option :: (type) po_bot
begin
definition bot_option :: "'a option"
where "\<bottom> \<equiv> None"
instance proof
fix a :: "'a option"
show "\<bottom> \<sqsubseteq> a" unfolding le_option_def bot_option_def by blast
qed
end
text "と定義した半順序 \<sqsubseteq> に関して cpo をなす。このような cpo を特に平坦 cpo(flat cpo)と呼ぶ。"
instantiation option :: (type) cpo
begin
instance proof
fix X :: "'a option set"
assume directed: "directed X"
have "(\<exists>x. X = {x}) \<or> (\<exists>x. X = {None, Some x})" proof -
obtain x1 where x1_mem: "x1 \<in> X" using directed_nemptyE[OF directed] by blast
show "(\<exists>x. X = {x}) \<or> (\<exists>x. X = {None, Some x})" proof (cases "X = {x1}")
case True
show ?thesis by (rule disjI1; simp add: True)
next
case False
have "X \<noteq> {}" using directed by (rule directed_nemptyE)
then obtain x2 where x2_mem: "x2 \<in> X" and x1_neq_x2: "x1 \<noteq> x2" using x1_mem False by blast
show ?thesis proof (rule disjI2)
show "\<exists>x. X = {None, Some x}" proof (cases "x1 = None")
case x1_eq: True
then obtain y2 where x2_eq: "x2 = Some y2" using x1_neq_x2 option.exhaust_sel by blast
have Some_uniq: "\<And>y. Some y \<in> X \<Longrightarrow> Some y = x2" by (metis x1_eq directed directed_exE le_option_def option.distinct(1) x1_neq_x2 x2_mem)
obtain Y where X_eq: "X = insert None (Some ` Y)" by (metis Set.set_insert x1_eq notin_range_Some subsetI subset_imageE x1_mem)
hence Y_eq: "Y = {y2}" using Some_uniq by (smt (verit, ccfv_threshold) Diff_eq_empty_iff Diff_insert_absorb x1_eq X_eq \<open>\<And>thesis. (\<And>x2. \<lbrakk>x2 \<in> X; x1 \<noteq> x2\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis\<close> x2_eq image_iff image_subset_iff insertE mk_disjoint_insert singletonI subset_insertI these_empty these_image_Some_eq these_insert_Some)
show ?thesis proof
show "X = {None, Some y2}" unfolding X_eq Y_eq by blast
qed
next
case False
then obtain y1 where x1_eq: "x1 = Some y1" by blast
have Some_uniq: "\<And>y. Some y \<in> X \<Longrightarrow> Some y = x1" by (metis False directed directed_exE le_option_def option.discI x1_mem)
have x2_eq: "x2 = None" by (metis False directed directed_exE le_option_def x1_mem x1_neq_x2 x2_mem)
obtain Y where X_eq: "X = insert None (Some ` Y)" by (metis Set.set_insert notin_range_Some subsetI subset_imageE x2_eq x2_mem)
hence Y_eq: "Y = {y1}" using Some_uniq using x1_eq x1_mem by blast
show ?thesis proof
show "X = {None, Some y1}" unfolding X_eq Y_eq by blast
qed
qed
qed
qed
qed
thus "\<exists>x. supremum X x" proof auto
fix x :: "'a option"
show "\<exists>y. supremum {x} y" proof
show "supremum {x} x" unfolding supremum_def upper_def le_option_def by blast
qed
next
fix x :: 'a
show "\<exists>y. supremum {None, Some x} y" proof
show "supremum {None, Some x} (Some x)" unfolding supremum_def upper_def le_option_def by blast
qed
qed
qed
end
text "\<bottom> と未定義要素と考えると、S から T への部分関数は S から T_\<bottom> への全関数として表せる。"
typedef ('a, 'b) pfun = "UNIV :: ('a \<Rightarrow> 'b option) set"
by (rule exI, rule UNIV_I)
lemma Rep_pfun_Abs_pfun[simp]: "Rep_pfun (Abs_pfun x) = x"
by (rule Abs_pfun_inverse, rule UNIV_I)
text "すなわち、f \<in> [S \<rightharpoonup> T] は次の全関数 f^: S \<rightarrow> T_\<bottom> で表せる。"
text "f^(x) = { f(x) (f(x) が定義)"
text " { \<bottom> (f(x) が未定義)"
instantiation pfun :: (type, type) po
begin
definition le_pfun :: "('a, 'b) pfun \<Rightarrow> ('a, 'b) pfun \<Rightarrow> bool"
where "f \<sqsubseteq> g \<equiv> \<forall>x y. (Rep_pfun f) x = Some y \<longrightarrow> (Rep_pfun g) x = Some y"
lemma pfun_leI:
fixes f g :: "('a, 'b) pfun"
assumes "\<And>a b. Rep_pfun f a = Some b \<Longrightarrow> Rep_pfun g a = Some b"
shows "f \<sqsubseteq> g"
unfolding le_pfun_def using assms by blast
lemma pfun_le_SomeE:
assumes "f \<sqsubseteq> g"
and "Rep_pfun f a = Some b"
shows "Rep_pfun g a = Some b"
using assms unfolding le_pfun_def by blast
lemma pfun_le_NoneE:
assumes "f \<sqsubseteq> g"
and "Rep_pfun g a = None"
shows "Rep_pfun f a = None"
using assms unfolding le_pfun_def proof -
assume imp[rule_format]: "\<forall>x y. Rep_pfun f x = Some y \<longrightarrow> Rep_pfun g x = Some y"
and g_a_eq: "Rep_pfun g a = None"
show "Rep_pfun f a = None" using g_a_eq proof (rule contrapos_pp)
assume "Rep_pfun f a \<noteq> None"
then obtain b where "Rep_pfun f a = Some b" by blast
hence "Rep_pfun g a = Some b" using imp by simp
thus "Rep_pfun g a \<noteq> None" by simp
qed
qed
instance proof
fix a :: "('a, 'b) pfun"
show "a \<sqsubseteq> a" unfolding le_pfun_def by blast
next
fix f g :: "('a, 'b) pfun"
assume f_le_g: "f \<sqsubseteq> g" and g_le_f: "g \<sqsubseteq> f"
have "Rep_pfun f = Rep_pfun g" proof
fix x
show "(Rep_pfun f) x = (Rep_pfun g) x" proof (cases "(Rep_pfun f) x")
case f_x_eq: None
show ?thesis proof (cases "(Rep_pfun g) x")
case g_x_eq: None
show ?thesis by (simp add: f_x_eq g_x_eq)
next
case g_x_eq: (Some a)
hence "(Rep_pfun f) x = Some a" using g_le_f unfolding le_pfun_def by blast
hence False using f_x_eq by simp
thus ?thesis by simp
qed
next
case f_x_eq: (Some a)
hence g_x_eq: "(Rep_pfun g) x = Some a" using f_le_g unfolding le_pfun_def by blast
show ?thesis unfolding f_x_eq g_x_eq by (rule HOL.refl)
qed
qed
thus "f = g" using Rep_pfun_inject by blast
next
fix a b c :: "('a, 'b) pfun"
assume a_le_b: "a \<sqsubseteq> b" and b_le_c: "b \<sqsubseteq> c"
thus "a \<sqsubseteq> c" unfolding le_pfun_def by auto
qed
lemma pfun_upperI:
fixes u :: "('a, 'b) pfun"
assumes "\<And>f a b. \<lbrakk> f \<in> F; Rep_pfun f a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun u a = Some b"
shows "F \<^sub>s\<sqsubseteq> u"
unfolding upper_def le_pfun_def using assms by blast
lemma pfun_upperE:
fixes u :: "('a, 'b) pfun"
assumes "F \<^sub>s\<sqsubseteq> u"
and "f \<in> F"
and "Rep_pfun f a = Some b"
shows "Rep_pfun u a = Some b"
using assms unfolding upper_def le_pfun_def by blast
lemma pfun_supremumI:
fixes s :: "('a, 'b) pfun"
assumes "\<And>f a b. \<lbrakk> f \<in> F; Rep_pfun f a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun s a = Some b"
and "\<And>u a b. \<lbrakk> \<And>f a b. \<lbrakk> f \<in> F; Rep_pfun f a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun u a = Some b; Rep_pfun s a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun u a = Some b"
shows "supremum F s"
unfolding supremum_def upper_def le_pfun_def using assms by blast
lemma pfun_supremum_leE:
fixes s :: "'a \<Rightarrow> 'b option"
assumes "supremum F (Abs_pfun s)"
and "f \<in> Rep_pfun ` F"
and "f a = Some b"
shows "s a = Some b"
using assms unfolding supremum_def upper_def le_pfun_def Rep_pfun_Abs_pfun by blast
lemma pfun_supremum_leastE:
fixes s :: "('a, 'b) pfun"
assumes "supremum F s"
and "\<And>f a b. \<lbrakk> f \<in> F; Rep_pfun f a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun u a = Some b"
and "Rep_pfun s a = Some b"
shows "Rep_pfun u a = Some b"
using assms unfolding supremum_def upper_def le_pfun_def by blast
lemma pfun_directedE:
fixes X :: "('a, 'b) pfun set"
assumes directed: "directed X"
and f_mem: "Abs_f \<in> X"
and g_mem: "Abs_g \<in> X"
and f_a_eq: "Rep_pfun Abs_f a = Some b1"
and g_a_eq: "Rep_pfun Abs_g a = Some b2"
shows "b1 = b2"
proof -
obtain Abs_h where "Rep_pfun Abs_h a = Some b1" and "Rep_pfun Abs_h a = Some b2"
using directed_exE[OF directed f_mem g_mem] f_a_eq g_a_eq unfolding le_pfun_def by blast
thus "b1 = b2" by simp
qed
definition sup_pfun :: "('a, 'b) pfun set \<Rightarrow> 'a \<Rightarrow> 'b option"
where "sup_pfun X \<equiv> (\<lambda>x.
if (\<exists>f \<in> Rep_pfun ` X. \<exists>y. f x = Some y)
then Some (THE y. \<exists>f \<in> Rep_pfun ` X. f x = Some y)
else None
)"
lemma sup_pfun_eq_NoneI:
fixes X :: "('a, 'b) pfun set"
assumes f_a_eq: "\<And>Abs_f. Abs_f \<in> X \<Longrightarrow> Rep_pfun Abs_f a = None"
shows "sup_pfun X a = None"
unfolding sup_pfun_def proof -
have "\<not>(\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y)" using f_a_eq by fastforce
thus "(if \<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y then Some (THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y) else None) = None" by simp
qed
lemma sup_pfun_eq_NoneE:
fixes X :: "('a, 'b) pfun set"
assumes sup_pfun_eq: "sup_pfun X a = None"
and f_mem: "Abs_f \<in> X"
shows "Rep_pfun Abs_f a = None"
proof -
have "\<not>(\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y)" using sup_pfun_eq unfolding sup_pfun_def proof (rule contrapos_pn)
assume "\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y"
then obtain Abs_f b where f_mem: "Abs_f \<in> X" and f_a_eq: "Rep_pfun Abs_f a = Some b" by blast
hence "\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y" using f_mem by blast
show "(if \<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y then Some (THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y) else None) \<noteq> None" proof simp
show "\<exists>f\<in>X. \<exists>b. Rep_pfun f a = Some b" using f_mem f_a_eq by blast
qed
qed
hence "\<And>Abs_f. Abs_f \<in> X \<Longrightarrow> \<nexists>y. Rep_pfun Abs_f a = Some y" by blast
thus "Rep_pfun Abs_f a = None" using f_mem by fastforce
qed
lemma sup_pfun_eq_SomeE:
fixes X :: "('a, 'b) pfun set"
assumes directed: "directed X"
and sup_pfun_eq: "sup_pfun X a = Some b"
obtains Abs_pfun where "Abs_pfun \<in> X" and "Rep_pfun Abs_pfun a = Some b"
proof -
have ex: "\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y" using sup_pfun_eq unfolding sup_pfun_def proof (rule contrapos_pp)
assume "\<not> (\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y)"
hence "\<And>Abs_f. Abs_f \<in> X \<Longrightarrow> \<nexists>b. Rep_pfun Abs_f a = Some b" by blast
thus "(if \<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y then Some (THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y) else None) \<noteq> Some b" by simp
qed
obtain Abs_f b' where f_mem: "Abs_f \<in> X" and f_a_eq: "Rep_pfun Abs_f a = Some b'" using ex by blast
have b_eq: "b = b'" proof (rule HOL.trans)
show "b = (THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y)" using sup_pfun_eq ex unfolding sup_pfun_def by simp
next
show "(THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y) = b'" proof (rule the_equality)
show "\<exists>f\<in>Rep_pfun ` X. f a = Some b'" using f_mem f_a_eq by blast
next
fix b''
assume "\<exists>f\<in>Rep_pfun ` X. f a = Some b''"
then obtain Abs_h where h_mem: "Abs_h \<in> X" and h_a_eq: "Rep_pfun Abs_h a = Some b''" by blast
show "b'' = b'" using directed h_mem f_mem h_a_eq f_a_eq by (rule pfun_directedE)
qed
qed
show ?thesis proof
show "Abs_f \<in> X" by (rule f_mem)
next
show "Rep_pfun Abs_f a = Some b" unfolding b_eq by (rule f_a_eq)
qed
qed
lemma sup_pfun_eq_SomeI:
fixes X :: "('a, 'b) pfun set"
assumes directed: "directed X"
and f_mem: "Abs_f \<in> X"
and f_a_eq: "Rep_pfun Abs_f a = Some b"
shows "sup_pfun X a = Some b"
unfolding sup_pfun_def proof -
have ex: "\<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y" using f_mem f_a_eq by blast
thus "(if \<exists>f\<in>Rep_pfun ` X. \<exists>y. f a = Some y then Some (THE y. \<exists>f\<in>Rep_pfun ` X. f a = Some y) else None) = Some b" proof simp
show "(THE y. \<exists>f\<in>X. Rep_pfun f a = Some y) = b" proof (rule the_equality)
show "\<exists>f\<in>X. Rep_pfun f a = Some b" using f_mem f_a_eq by blast
next
fix y
assume "\<exists>f\<in>X. Rep_pfun f a = Some y"
then obtain Abs_g where g_mem: "Abs_g \<in> X" and g_a_eq: "Rep_pfun Abs_g a = Some y" by blast
show "y = b" using directed g_mem f_mem g_a_eq f_a_eq by (rule pfun_directedE)
qed
qed
qed
lemma supremum_pfunI:
fixes X :: "('a, 'b) pfun set"
assumes directed: "directed X"
shows "supremum X (Abs_pfun (sup_pfun X))"
proof (rule pfun_supremumI)
fix f a b
assume f_mem: "f \<in> X"
and f_a_eq: "Rep_pfun f a = Some b"
show "Rep_pfun (Abs_pfun (sup_pfun X)) a = Some b" unfolding Rep_pfun_Abs_pfun using directed f_mem f_a_eq by (rule sup_pfun_eq_SomeI)
next
fix u a b
assume 1: "\<And>Abs_f a b. \<lbrakk> Abs_f \<in> X; Rep_pfun Abs_f a = Some b \<rbrakk> \<Longrightarrow> Rep_pfun u a = Some b"
and "Rep_pfun (Abs_pfun (sup_pfun X)) a = Some b"
hence sup_pfun_eq: "sup_pfun X a = Some b" by simp
obtain Abs_f where f_mem: "Abs_f \<in> X" and f_a_eq: "Rep_pfun Abs_f a = Some b" using directed sup_pfun_eq by (rule sup_pfun_eq_SomeE)
show "Rep_pfun u a = Some b" using f_mem f_a_eq by (rule 1)
qed
lemma eq_sup_pfun:
fixes x :: "('a, 'b) pfun"
assumes directed: "directed X"
and sup: "supremum X x"
shows "Rep_pfun x = sup_pfun X"
proof -
have "x = Abs_pfun (sup_pfun X)" proof (rule supremum_uniq)
show "supremum X (Abs_pfun (sup_pfun X))" using directed by (rule supremum_pfunI)
next
show "supremum X x" by (rule sup)
qed
thus "Rep_pfun x = sup_pfun X" using Rep_pfun_Abs_pfun by fastforce
qed
lemma sup_pfun_directedE:
fixes X :: "('a, 'b) pfun set"
assumes directed: "directed X"
and f_mem: "Abs_f \<in> X"
and f_a_eq: "Rep_pfun Abs_f a = Some b1"
and sup_pfun_a_eq: "sup_pfun X a = Some b2"
shows "b1 = b2"
proof -
obtain Abs_g where g_mem: "Abs_g \<in> X" and g_a_eq: "Rep_pfun Abs_g a = Some b2" using directed sup_pfun_a_eq by (rule sup_pfun_eq_SomeE)
show "b1 = b2" using directed f_mem g_mem f_a_eq g_a_eq by (rule pfun_directedE)
qed
end
instantiation pfun :: (type, type) po_bot
begin
definition bot_pfun :: "('a, 'b) pfun"
where "\<bottom> \<equiv> Abs_pfun Map.empty"
instance proof
fix a :: "('a, 'b) pfun"
have eq: "Rep_pfun (Abs_pfun Map.empty) = Map.empty" by (rule Abs_pfun_inverse, rule UNIV_I)
show "\<bottom> \<sqsubseteq> a" unfolding le_pfun_def bot_pfun_def eq by blast
qed
end
instantiation pfun :: (type, type) cpo
begin
instance proof
fix X :: "('a, 'b) pfun set"
assume directed: "directed X"
show "\<exists>d. supremum X d" using supremum_pfunI[OF directed] by blast
qed
end
subsection "例 3.1.11"
text "実数 a, b \<in> \<real> について、"
text "[a, b] = {x \<in> \<real> | a \<le> x \<le> b}"
text "のように閉区間を定義する。"
definition range :: "real \<Rightarrow> real \<Rightarrow> real set"
where "range a b \<equiv> {c | c. a \<le> c \<and> c \<le> b}"
text "閉区間の全部と \<real> 自身を合わせた集合"
text "I_\<real> = {[a, b] | a \<le> b} \<union> {\<real>}"
typedef range = "{range a b |a b. True} \<union> {UNIV}"
by blast
text "は、"
text "X \<sqsubseteq> Y \<Leftrightarrow> Y \<subseteq> X (X, Y \<in> I_\<real>)"
instantiation range :: po
begin
definition le_range :: "range \<Rightarrow> range \<Rightarrow> bool"
where "X \<sqsubseteq> Y \<equiv> Rep_range Y \<subseteq> Rep_range X"
instance proof
fix a :: range
show "a \<sqsubseteq> a" unfolding le_range_def by (rule order.refl)
next
fix a b :: range
assume a_le_b: "a \<sqsubseteq> b"
and b_le_a: "b \<sqsubseteq> a"
have "Rep_range a = Rep_range b" using b_le_a a_le_b unfolding le_range_def by (rule equalityI)
thus "a = b" using Rep_range_inject by blast
next
fix a b c :: range
assume a_le_b: "a \<sqsubseteq> b"
and b_le_c: "b \<sqsubseteq> c"
show "a \<sqsubseteq> c" using b_le_c a_le_b unfolding le_range_def by (rule order.trans)
qed
end
instantiation range :: po_bot
begin
definition bot_range :: range
where "\<bottom> \<equiv> Abs_range UNIV"
lemma Rep_range_bot: "Rep_range \<bottom> = UNIV" unfolding bot_range_def
by (rule Abs_range_inverse, blast)
instance proof
fix a :: range
show "\<bottom> \<sqsubseteq> a" unfolding le_range_def Rep_range_bot by (rule subset_UNIV)
qed
end
text "と定義した半順序に関して cpo をなす。"
lemma (in po_bot) directed_minusI:
assumes directed: "directed X"
and neq: "X \<noteq> {\<bottom>}"
shows "directed (X - {\<bottom>})"
proof (rule directedI)
fix x y
assume "x \<in> X - {\<bottom>}"
and "y \<in> X - {\<bottom>}"
hence x_mem: "x \<in> X" and x_neq: "x \<noteq> \<bottom>" and y_mem: "y \<in> X" and y_neq: "y \<noteq> \<bottom>" by blast+
obtain z where x_le_z: "x \<sqsubseteq> z" and y_le_z: "y \<sqsubseteq> z" and z_mem: "z \<in> X" using directed_exE[OF directed x_mem y_mem] by blast
show "\<exists>c \<in> X - {\<bottom>}. x \<sqsubseteq> c \<and> y \<sqsubseteq> c" proof
show "x \<sqsubseteq> z \<and> y \<sqsubseteq> z" using x_le_z y_le_z by (rule conjI)
next
have "z \<noteq> \<bottom>" using x_neq y_neq bot_le by (metis antisym y_le_z)
thus "z \<in> X - {\<bottom>}" using z_mem by blast
qed
next
show "X - {\<bottom>} \<noteq> {}" using neq directed_nemptyE[OF directed] by blast
qed
instantiation range :: cpo
begin
instance proof
fix X :: "range set"
assume directed: "directed X"
have eq: "Rep_range (Abs_range (\<Inter> (Rep_range ` X))) = \<Inter> (Rep_range ` X)" proof (rule Abs_range_inverse)
have 1: "\<Inter> (Rep_range ` X) = Rep_range \<bottom> \<or> (\<exists>a b. \<Inter> (Rep_range ` X) = range a b \<and> a \<le> b)" proof (cases "X = {\<bottom>}")
case X_eq: True
show ?thesis unfolding X_eq proof (rule disjI1)
show "\<Inter> (Rep_range ` {\<bottom>}) = Rep_range \<bottom>" by simp
qed
next
case X_neq: False
have ex_range: "\<And>X. \<lbrakk> directed X; X \<noteq> {\<bottom>} \<rbrakk> \<Longrightarrow> \<exists>a b. \<Inter> (Rep_range ` X) = range a b \<and> a \<le> b"
sorry \<comment> \<open>次を仮定してもなお解けなかった: UNIV の singleton でなければ最大元と最小元が存在する\<close>
show ?thesis proof (rule disjI2; cases "\<bottom> \<in> X")
case UNIV_mem: True
let ?X = "X - {\<bottom>}"
have Int_X_eq: "\<Inter> (Rep_range ` X) = \<Inter> (Rep_range ` ?X)" using X_neq using Rep_range_bot insert_Diff subsetI by auto
have "\<exists>a b. \<Inter> (Rep_range ` ?X) = range a b \<and> a \<le> b" proof (rule ex_range)
show "directed (X - {\<bottom>})" using directed X_neq by (rule directed_minusI)
next
show "X - {\<bottom>} \<noteq> {\<bottom>}" by blast
qed
then obtain a b where Int_X'_eq: "\<Inter> (Rep_range ` ?X) = range a b" and a_le_b: "a \<le> b" by blast
show "\<exists>a b. \<Inter> (Rep_range ` X) = range a b \<and> a \<le> b" unfolding Int_X_eq proof (intro exI)
show " \<Inter> (Rep_range ` ?X) = range a b \<and> a \<le> b" using Int_X'_eq a_le_b by (rule conjI)
qed
next
case UNIV_nmem: False
hence UNIV_neq: "X \<noteq> {\<bottom>}" by blast
have "\<exists>a b. \<Inter> (Rep_range ` X) = range a b \<and> a \<le> b" using directed UNIV_neq by (rule ex_range)
then obtain a b where Int_X_eq: "\<Inter> (Rep_range ` X) = range a b" and a_le_b: "a \<le> b" by blast
show "\<exists>a b. \<Inter> (Rep_range ` X) = range a b \<and> a \<le> b" proof (intro exI)
show "\<Inter> (Rep_range ` X) = range a b \<and> a \<le> b" using Int_X_eq a_le_b by (rule conjI)
qed
qed
qed
thus "\<Inter> (Rep_range ` X) \<in> {range a b |a b. True} \<union> {UNIV}" proof auto
fix x y
assume eq: "\<Inter> (Rep_range ` X) = Rep_range \<bottom>"
and x_mem: "x \<in> X"
have "X = {\<bottom>}" using eq unfolding Rep_range_bot
by (metis Diff_eq_empty_iff INT_E Rep_range_inverse UNIV_I UNIV_eq_I bot_range_def directed directed_nemptyE insertI1 po_bot_class.directed_minusI subsetI)
hence x_eq: "x = \<bottom>" using x_mem by blast
show "y \<in> Rep_range x" unfolding x_eq Rep_range_bot by (rule UNIV_I)
qed
qed
show "\<exists>d. supremum X d" proof
let ?x = "\<Inter> (Rep_range ` X)"
have eq: "Rep_range (Abs_range ?x) = ?x" unfolding eq by (rule HOL.refl)
show "supremum X (Abs_range ?x)" proof (rule supremumI)
show " X \<^sub>s\<sqsubseteq> Abs_range ?x" proof (rule upperI)
fix x
assume x_mem: "x \<in> X"
show "x \<sqsubseteq> Abs_range ?x" unfolding le_range_def eq using x_mem by blast
qed
next
fix a
assume upper_a: "X \<^sub>s\<sqsubseteq> a"
show "Abs_range ?x \<sqsubseteq> a" unfolding le_range_def eq
by (meson INT_greatest le_range_def upperE upper_a)
qed
qed
qed
end
text "また、I_\<real> の部分集合 I*_\<real> を"
text "I*_\<real> = {[a, b] | a \<le> b で a と b は有理数 }"
text "と定義すると、"
definition I\<^sub>R\<^sub>s :: "range set"
where "I\<^sub>R\<^sub>s \<equiv> {Abs_range (range (real_of_rat a) (real_of_rat b)) | a b :: rat. a \<le> b}"
text "任意の [a, b] \<in> I_\<real> について、"
text "[a, b] = \<squnion>{[c, d] \<in> I*_\<real> | [c, d] \<sqsubseteq> [a, b]}"
text "が成り立つ。"
\<comment> \<open>練習問題3.1 6 で証明。\<close>
text "すなわち、I_\<real> の各要素は I*_\<real> のある集合の上限で表せる。特に、a = b とおくと"
text "[a, a] = \<squnion>{[c, d] \<in> I*_\<real> | c \<le> a \<le> d}"
text "となる。すなわち、各実数は有理数で区切られた区間のある集合の上限で表せる。"
subsection "命題 3.1.12"
text "半順序集合 D について次の2つの条件は同値である。"
text "(1) 任意の可算な有向集合 X \<subseteq> D について、X は上限を持つ。"
text "(2) 任意の\<omega>鎖は上限を持つ。"
fun a_3_1_12 :: "(nat \<Rightarrow> 'a) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a"
where "a_3_1_12 x s 0 = x 0"
| "a_3_1_12 x s (Suc n) = s (a_3_1_12 x s n) (x (Suc n))"
lemma (in po)
shows "(\<forall>X. countable X \<longrightarrow> directed X \<longrightarrow> (\<exists>x. supremum X x)) \<longleftrightarrow> (\<forall>f. omega_chain f \<longrightarrow> (\<exists>x. supremum {f n|n. True} x))"
proof (intro iffI allI impI)
fix f :: "nat \<Rightarrow> 'a"
assume 1[rule_format]: "\<forall>X. countable X \<longrightarrow> directed X \<longrightarrow> (\<exists>x. supremum X x)"
and omega_chain: "omega_chain f"
have "\<And>i j. i \<le> j \<Longrightarrow> le (f i) (f j)" using omega_chain by (rule omega_chain_leE)
show "\<exists>x. supremum {f n|n. True} x" proof (rule 1)
show "countable {f n |n. True}" proof (rule countableI)
show "inj_on (inv f) {f n |n. True}" proof (rule inj_onI)
fix x y
assume "x \<in> {f n |n. True}"
and "y \<in> {f n |n. True}"
and inv_eq: "inv f x = inv f y"
then obtain xn yn where x_eq: "x = f xn" and y_eq: "y = f yn" by blast
show "x = y" using inv_eq by (metis inv_into_injective rangeI x_eq y_eq)
qed
qed
next
show "directed {f n |n. True}" proof (rule directedI)
show "{f n |n. True} \<noteq> {}" by blast
next
fix x y
assume "x \<in> {f n |n. True}"