-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.thy
More file actions
1670 lines (1241 loc) · 64.9 KB
/
Copy pathUtil.thy
File metadata and controls
1670 lines (1241 loc) · 64.9 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 Util
imports Main
begin
text \<open> A theory for helper lemmas and definitions. \<close>
text \<open> We extensively use lattice syntax for separation logic assertions. \<close>
unbundle lattice_syntax
section \<open> Boolean Algebras and Logical Lattices \<close>
definition top_embed :: \<open>'a::bounded_semilattice_inf_top \<Rightarrow> 'b::bounded_lattice\<close> (\<open>\<bbbT>\<close>) where
\<open>\<bbbT> b \<equiv> if b = \<top> then \<top> else \<bottom>\<close>
lemma top_embed_bool_eq[simp]:
\<open>\<bbbT> True = \<top>\<close>
\<open>\<bbbT> False = \<bottom>\<close>
by (simp add: top_embed_def)+
lemma top_embed_fun_apply[simp]:
\<open>(\<bbbT> f) x = \<bbbT> f\<close>
by (simp add: top_embed_def)
lemma top_embed_to_bool_eq[simp]:
\<open>\<bbbT> a \<longleftrightarrow> (a = \<top>)\<close>
by (simp add: top_embed_def)
context boolean_algebra
begin
definition impl :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "\<rightarrow>" 60) where
"a \<rightarrow> b \<equiv> -a \<squnion> b"
lemma not_impl_eq[simp]:
\<open>- (a \<rightarrow> b) = a \<sqinter> - b\<close>
by (simp add: impl_def)
lemma impl_shunt:
\<open>c \<sqinter> a \<le> b \<longleftrightarrow> c \<le> a \<rightarrow> b\<close>
by (simp add: impl_def shunt1)
lemma impl_simps[simp]:
\<open>\<top> \<rightarrow> b = b\<close>
\<open>\<bottom> \<rightarrow> b = \<top>\<close>
\<open>a \<rightarrow> \<bottom> = - a\<close>
\<open>a \<rightarrow> \<top> = \<top>\<close>
\<open>a \<rightarrow> a = \<top>\<close>
by (force simp add: impl_def)+
definition latiff :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixr "\<leftrightarrow>" 60) where
"a \<leftrightarrow> b \<equiv> (-a \<squnion> b) \<sqinter> (a \<squnion> -b)"
lemma latiff_simps[simp]:
\<open>a \<leftrightarrow> a = \<top>\<close>
\<open>\<bottom> \<leftrightarrow> a = -a\<close>
\<open>a \<leftrightarrow> \<bottom> = -a\<close>
\<open>\<top> \<leftrightarrow> a = a\<close>
\<open>a \<leftrightarrow> \<top> = a\<close>
by (clarsimp simp add: latiff_def)+
lemma latiff_on_not[simp]:
\<open>- a \<leftrightarrow> - b = a \<leftrightarrow> b\<close>
by (simp add: latiff_def local.inf.commute)
end
lemma impl_fun_apply[simp]:
\<open>(f \<rightarrow> g) x = (f x \<rightarrow> g x)\<close>
by (simp add: impl_def)
lemma impl_bool_eq[simp]:
\<open>(a \<rightarrow> b) = (a \<longrightarrow> b)\<close>
by (simp add: impl_def)
lemma impl_fun_iff:
\<open>(f \<rightarrow> g) = (\<lambda>x. f x \<rightarrow> g x)\<close>
by (force simp add: impl_def)
lemma latiff_fun_apply[simp]:
\<open>(f \<leftrightarrow> g) x = (f x \<leftrightarrow> g x)\<close>
by (simp add: latiff_def)
lemma latiff_bool_apply[simp]:
\<open>(a \<leftrightarrow> b) = (a \<longleftrightarrow> b)\<close>
by (force simp add: latiff_def)
lemma All_bot_iff[simp]:
\<open>All \<bottom> \<longleftrightarrow> \<bottom>\<close>
by simp
section \<open> Functional Programming \<close>
definition flip :: \<open>('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'a \<Rightarrow> 'c)\<close> where
\<open>flip f a b \<equiv> f b a\<close>
declare flip_def[simp]
lemma le_fun_eta[simp]: \<open>(\<lambda>x. a) \<le> (\<lambda>x. b) \<longleftrightarrow> a \<le> b\<close>
by (simp add: le_fun_def)
section \<open> Logic \<close>
lemmas conj_left_mp[simp] =
SMT.verit_bool_simplify(7)
arg_cong[where f=\<open>\<lambda>x. x \<and> R\<close> for R, OF SMT.verit_bool_simplify(7), simplified conj_assoc]
lemmas conj_right_mp[simp] =
SMT.verit_bool_simplify(8)
arg_cong[where f=\<open>\<lambda>x. x \<and> R\<close> for R, OF SMT.verit_bool_simplify(8), simplified conj_assoc]
lemma strong_imp_conj_iff: "(P \<Longrightarrow> R) \<Longrightarrow> ((Q \<longrightarrow> R) \<and> P) = P"
by blast
lemma conj_imp_distribR:
\<open>(p \<longrightarrow> q) \<and> r \<longleftrightarrow> (\<not> p \<and> r) \<or> (q \<and> r)\<close>
by force
lemma conj_imp_distribL:
\<open>p \<and> (q \<longrightarrow> r) \<longleftrightarrow> (p \<and> \<not> q) \<or> (p \<and> r)\<close>
by force
lemma if_eq_disj_cases: \<open>(A \<longrightarrow> B) \<and> (\<not> A \<longrightarrow> C) \<longleftrightarrow> (A \<and> B) \<or> (\<not> A \<and> C)\<close>
by blast
lemma imp_impL[simp]: \<open>(A \<longrightarrow> B) \<longrightarrow> C \<longleftrightarrow> (\<not> A \<longrightarrow> C) \<and> (B \<longrightarrow> C)\<close>
by blast
lemma all2_push[simp]:
\<open>(\<forall>x y. P y \<longrightarrow> Q x y) = (\<forall>y. P y \<longrightarrow> (\<forall>x. Q x y))\<close>
by force
lemma imp_ex_conjL:
\<open>\<And>P Q. ((\<exists>x. P x \<and> Q x) \<longrightarrow> R) \<longleftrightarrow> (\<forall>x. P x \<longrightarrow> Q x \<longrightarrow> R)\<close>
\<open>\<And>P Q. ((\<exists>x y. P x y \<and> Q x y) \<longrightarrow> R) \<longleftrightarrow> (\<forall>x y. P x y \<longrightarrow> Q x y \<longrightarrow> R)\<close>
\<open>\<And>P Q. ((\<exists>x y z. P x y z \<and> Q x y z) \<longrightarrow> R) \<longleftrightarrow> (\<forall>x y z. P x y z \<longrightarrow> Q x y z \<longrightarrow> R)\<close>
by blast+
lemma imp_conj_common:
\<open>(A1 \<longrightarrow> B \<longrightarrow> C1) \<and> (A2 \<longrightarrow> B \<longrightarrow> C2) \<longleftrightarrow> (B \<longrightarrow> (A1 \<longrightarrow> C1) \<and> (A2 \<longrightarrow> C2))\<close>
\<open>(A1 \<longrightarrow> B \<longrightarrow> C1) \<and> (A2 \<longrightarrow> B \<longrightarrow> C2) \<and> D \<longleftrightarrow> (B \<longrightarrow> (A1 \<longrightarrow> C1) \<and> (A2 \<longrightarrow> C2)) \<and> D\<close>
by blast+
lemma imp_all_conj_common:
\<open>(A1 \<longrightarrow> (\<forall>x. B x \<longrightarrow> C1 x)) \<and> (A2 \<longrightarrow> (\<forall>x. B x \<longrightarrow> C2 x)) \<longleftrightarrow> (\<forall>x. B x \<longrightarrow> (A1 \<longrightarrow> C1 x) \<and> (A2 \<longrightarrow> C2 x))\<close>
\<open>(A1 \<longrightarrow> (\<forall>x. B x \<longrightarrow> C1 x)) \<and> (A2 \<longrightarrow> (\<forall>x. B x \<longrightarrow> C2 x)) \<and> D \<longleftrightarrow>
(\<forall>x. B x \<longrightarrow> (A1 \<longrightarrow> C1 x) \<and> (A2 \<longrightarrow> C2 x)) \<and> D\<close>
by blast+
lemma all_conj_ex1:
\<open>(\<forall>x. P x \<longrightarrow> Q x) \<and> Ex P \<longleftrightarrow> (\<exists>x. P x \<and> Q x) \<and> (\<forall>x. P x \<longrightarrow> Q x)\<close>
by blast
lemma exsome_conj_some_imp:
\<open>(\<exists>x. y = Some x) \<and> (\<forall>x. y = Some x \<longrightarrow> P x) \<longleftrightarrow> (\<exists>x. y = Some x \<and> P x)\<close>
by blast
lemma ex_eq_pair_iff[simp]:
\<open>(\<exists>x y. a = (x, y) \<and> P x y) \<longleftrightarrow> P (fst a) (snd a)\<close>
by force
lemmas disjCI2 = disjCI[THEN Meson.disj_comm]
lemma pred_conjD: \<open>(A1 \<sqinter> A2) s \<Longrightarrow> A1 \<le> B1 \<Longrightarrow> A2 \<le> B2 \<Longrightarrow> (B1 \<sqinter> B2) s\<close>
by blast
lemma conj_disj_absorb2[simp]:
\<open>b \<and> (a \<or> b) \<longleftrightarrow> b\<close>
by blast
lemma disj_conj_absorb2[simp]:
\<open>b \<or> (a \<and> b) \<longleftrightarrow> b\<close>
by blast
lemma conj_disj_distribR_middle:
\<open>(P \<and> R \<or> S \<and> T) \<and> Q \<longleftrightarrow> P \<and> Q \<and> R \<or> S \<and> Q \<and> T\<close>
by blast
lemma eq_same_implies_iff_implies_eq:
\<open>(A \<longrightarrow> B) = (A \<longrightarrow> C) \<longleftrightarrow> (A \<longrightarrow> B = C)\<close>
by blast
lemma eq_same_conjR_iff_implies_eq:
\<open>(A \<and> C) = (B \<and> C) \<longleftrightarrow> (C \<longrightarrow> A = B)\<close>
by blast
lemma eq_same_conjL_iff_implies_eq:
\<open>(A \<and> B) = (A \<and> C) \<longleftrightarrow> (A \<longrightarrow> B = C)\<close>
by blast
lemma ex_middle_eq_iff:
\<open>(\<exists>c1'. (\<exists>c1. P c1 \<and> c1' = f c1) \<and> Q c1') \<longleftrightarrow> (\<exists>c1. P c1 \<and> Q (f c1))\<close>
by blast
section \<open> Tuples \<close>
lemma common_if_prod[simp]:
\<open>(if P then a1 else a2, if P then b1 else b2) = (if P then (a1,b1) else (a2,b2))\<close>
by simp
abbreviation plus_right_fst :: \<open>'a::plus \<times> 'b \<Rightarrow> 'a \<Rightarrow> 'a \<times> 'b\<close> (infixl \<open>+\<^sub>L\<close> 65) where
\<open>plus_right_fst xy a \<equiv> apfst (\<lambda>z. z + a) xy\<close>
abbreviation plus_right_snd :: \<open>'a \<times> 'b::plus \<Rightarrow> 'b \<Rightarrow> 'a \<times> 'b\<close> (infixl \<open>+\<^sub>R\<close> 65) where
\<open>plus_right_snd xy a \<equiv> apsnd (\<lambda>z. z + a) xy\<close>
lemma plus_right_fst_accum[simp]:
fixes x :: \<open>'a :: semigroup_add\<close>
shows \<open>(xy +\<^sub>L x) +\<^sub>L x' = xy +\<^sub>L (x + x')\<close>
by (cases xy, simp add: add.assoc)
lemma plus_right_snd_accum[simp]:
fixes y :: \<open>'a :: semigroup_add\<close>
shows \<open>(xy +\<^sub>R y) +\<^sub>R y' = xy +\<^sub>R (y + y')\<close>
by (cases xy, simp add: add.assoc)
section \<open> Lists \<close>
lemma upt_add_eq_append:
assumes \<open>i \<le> j\<close> \<open>j \<le> k\<close>
shows \<open>[i..<k] = [i..<j] @ [j..<k]\<close>
using assms
proof (induct k arbitrary: i j)
case 0 then show ?case by simp
next
case (Suc k)
show ?case
proof (cases \<open>j \<le> k\<close>)
case True
have \<open>[i..<Suc k] = [i..<k] @ [k]\<close>
using Suc.prems True
by simp
also have \<open>... = [i..<j] @ [j..<k] @ [k]\<close>
using Suc.prems True
by (subst Suc.hyps[where j=j]; simp)
also have \<open>... = [i..<j] @ [j..<Suc k]\<close>
using True
by simp
finally show ?thesis .
next
case False
then show ?thesis
using Suc.prems
by (clarsimp simp add: le_Suc_eq)
qed
qed
section \<open> Functions \<close>
lemma comp_constfn_eq[simp]:
\<open>(\<lambda>_. v) \<circ> f = (\<lambda>_. v)\<close>
by fastforce
lemma comp_inf_distrib:
\<open>a \<sqinter> b \<circ> f = (a \<circ> f) \<sqinter> (b \<circ> f)\<close>
by fastforce
lemma comp_sup_distrib:
\<open>a \<squnion> b \<circ> f = (a \<circ> f) \<squnion> (b \<circ> f)\<close>
by fastforce
lemma comp_neg_distrib:
\<open>- a \<circ> f = - (a \<circ> f)\<close>
by fastforce
lemma top_comp_eq[simp]:
\<open>\<top> \<circ> f = \<top>\<close>
by (simp add: fun_eq_iff)
lemma bot_comp_eq[simp]:
\<open>\<bottom> \<circ> f = \<bottom>\<close>
by (simp add: fun_eq_iff)
lemma minus_comp_distrib:
\<open>(a - b) \<circ> f = (a \<circ> f) - (b \<circ> f)\<close>
by (simp add: fun_eq_iff)
lemma impl_comp_distrib:
\<open>(a \<rightarrow> b) \<circ> f = (a \<circ> f) \<rightarrow> (b \<circ> f)\<close>
by (simp add: fun_eq_iff)
lemma comp_Inf_distrib:
\<open>\<Sqinter>A \<circ> f = \<Sqinter>((\<lambda>a. a \<circ> f) ` A)\<close>
by (clarsimp simp add: fun_eq_iff image_def Inf_fun_def)
metis
lemma top_comp_surj_eq[simp]:
\<open>surj f \<Longrightarrow> (\<top> \<circ> f) = \<top>\<close>
by (simp add: fun_eq_iff surj_def)
lemma All_comp_surj_iff[simp]:
\<open>surj f \<Longrightarrow> All (p \<circ> f) \<longleftrightarrow> All p\<close>
by (metis UNIV_I comp_apply f_inv_into_f)
lemma comp_fun_mono:
\<open>a \<le> b \<Longrightarrow> a \<circ> f \<le> b \<circ> f\<close>
by (simp add: le_fun_def)
section \<open> Predicates \<close>
definition
\<open>pred_image f p \<equiv> \<lambda>y. \<exists>x. f x = y \<and> p x\<close>
lemma pred_image_apply[simp]:
\<open>pred_image f p y = (\<exists>x. y = f x \<and> p x)\<close>
by (force simp add: pred_image_def)
lemma pred_image_empty_iff[simp]:
\<open>pred_image f r = \<bottom> \<longleftrightarrow> r = \<bottom>\<close>
by (metis (no_types, lifting) Collect_empty_eq_bot empty_Collect_eq pred_image_def)
section \<open> Relations \<close>
lemmas relpowp_simp_alt =
relpowp.simps(2)[simplified relpowp_commute[symmetric]]
subsection \<open> Relation definitions \<close>
definition \<open>predrel p q \<equiv> \<lambda>a b. p a \<and> q b\<close>
abbreviation \<open>invrel p \<equiv> predrel p p\<close>
abbreviation \<open>pretest p \<equiv> predrel p \<top>\<close>
abbreviation \<open>posttest \<equiv> predrel \<top>\<close>
lemmas invrel_def = predrel_def[of p p for p, simplified]
lemmas pretest_def = predrel_def[of _ \<top>, simplified]
lemmas posttest_def = predrel_def[of \<top>, simplified]
lemma predrel_apply[simp]:
\<open>predrel p q a b = (p a \<and> q b)\<close>
by (simp add: predrel_def)
lemma predrel_mono:
\<open>p \<le> p' \<Longrightarrow> q \<le> q' \<Longrightarrow> predrel p q \<le> predrel p' q'\<close>
by (simp add: predrel_def le_fun_def)
definition comp2 :: \<open>('b \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> 'c)\<close> (infixl \<open>\<circ>\<^sub>2\<close> 55) where
\<open>r \<circ>\<^sub>2 f \<equiv> \<lambda>x y. r (f x) (f y)\<close>
lemma comp2_apply[simp]: "(r \<circ>\<^sub>2 g) x y = r (g x) (g y)"
by (simp add: comp2_def)
lemma comp2_partial_apply: "(r \<circ>\<^sub>2 g) x = r (g x) \<circ> g"
by (simp add: comp2_def comp_def)
lemma comp2_fusion[simp]:
\<open>r \<circ>\<^sub>2 f \<circ>\<^sub>2 g = r \<circ>\<^sub>2 (f \<circ> g)\<close>
by (simp add: fun_eq_iff)
lemma comp2_id[simp]:
\<open>r \<circ>\<^sub>2 id = r\<close>
by (simp add: fun_eq_iff)
lemma comp2_exchange:
\<open>bij f \<Longrightarrow> ra \<circ>\<^sub>2 f = rb \<longleftrightarrow> ra = rb \<circ>\<^sub>2 inv f\<close>
by (simp add: fun_eq_iff, metis bij_inv_eq_iff)
lemma comp2_raw_id_eq[simp]:
\<open>r \<circ>\<^sub>2 (\<lambda>x. x) = r\<close>
by fastforce
definition rel_image :: \<open>('a \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool)\<close> where
\<open>rel_image f r \<equiv> \<lambda>x x'. \<exists>y y'. r y y' \<and> x = f y \<and> x' = f y'\<close>
lemma rel_image_apply[simp]:
\<open>rel_image f r x x' = (\<exists>y y'. r y y' \<and> x = f y \<and> x' = f y')\<close>
by (simp add: rel_image_def)
lemma rel_image_empty_iff[simp]:
\<open>rel_image f r = \<bottom> \<longleftrightarrow> r = \<bottom>\<close>
by (metis (mono_tags, opaque_lifting) bot2E order_bot_class.bot.extremum_unique predicate2I
rel_image_def)
definition \<open>pre_state_of B r \<equiv> \<lambda>a. \<exists>b\<in>B. r a b\<close>
definition \<open>post_state_of A r \<equiv> \<lambda>b. \<exists>a\<in>A. r a b\<close>
abbreviation \<open>pre_state \<equiv> pre_state_of UNIV\<close>
abbreviation \<open>post_state \<equiv> post_state_of UNIV\<close>
lemmas pre_state_def = pre_state_of_def[of UNIV, simplified]
lemmas post_state_def = post_state_of_def[of UNIV, simplified]
definition \<open>prepost_state \<equiv> pre_state \<squnion> post_state\<close>
lemmas prepost_state_def' =
prepost_state_def[simplified pre_state_def post_state_def sup_fun_def]
definition \<open>pre_change_state r \<equiv> \<lambda>a. \<exists>b. r a b \<and> a \<noteq> b\<close>
definition \<open>post_change_state r \<equiv> \<lambda>b. \<exists>a. r a b \<and> a \<noteq> b\<close>
definition \<open>change_state \<equiv> pre_change_state \<squnion> post_change_state\<close>
definition \<open>univ_states r s \<equiv> \<not> pre_state (- r) s\<close>
lemma pre_state_top_eq[simp]:
\<open>pre_state \<top> = \<top>\<close>
by (force simp add: pre_state_def fun_eq_iff)
lemma pre_state_bot_eq[simp]:
\<open>pre_state \<bottom> = \<bottom>\<close>
by (force simp add: pre_state_def fun_eq_iff)
lemma pre_state_eq_eq[simp]:
\<open>pre_state (=) = \<top>\<close>
by (force simp add: pre_state_def fun_eq_iff)
lemma univ_states_eq:
\<open>univ_states r = (\<lambda>a. All (r a))\<close>
by (simp add: univ_states_def pre_state_def fun_eq_iff)
lemma not_univ_states_eq[simp]:
\<open>- univ_states r = pre_state (- r)\<close>
by (force simp add: univ_states_def pre_state_def fun_eq_iff)
lemma univ_states_inf_distrib:
\<open>univ_states (a \<sqinter> b) = univ_states a \<sqinter> univ_states b\<close>
by (simp add: fun_eq_iff univ_states_eq) blast
subsubsection \<open> rel liftings / projs \<close>
paragraph \<open> binary relations \<close>
lemma predrel_mono_iff:
\<open>predrel pa qa \<le> predrel pb qb \<longleftrightarrow> pa \<sqinter> (\<lambda>_. Ex qa) \<le> pb \<and> qa \<sqinter> (\<lambda>_. Ex pa) \<le> qb\<close>
by (force simp add: predrel_def le_fun_def imp_conjR)
lemma predrel_inf_merge:
\<open>predrel pa qa \<sqinter> predrel pb qb = predrel (pa \<sqinter> pb) (qa \<sqinter> qb)\<close>
by (force simp add: predrel_def le_fun_def imp_conjR)
lemma predrel_top[simp]:
\<open>predrel \<top> \<top> = \<top>\<close>
by (force simp add: predrel_def)
lemma predrel_bot[simp]:
\<open>predrel \<bottom> = \<bottom>\<close>
\<open>predrel p \<bottom> = \<bottom>\<close>
by (force simp add: predrel_def)+
lemma predrel_pred_True[simp]:
\<open>predrel (\<lambda>x. True) (\<lambda>x. True) = \<top>\<close>
by (force simp add: predrel_def)
lemma predrel_pred_False[simp]:
\<open>predrel (\<lambda>x. False) = \<bottom>\<close>
\<open>predrel p (\<lambda>x. False) = \<bottom>\<close>
by (force simp add: predrel_def)+
lemma posttest_mono[simp]:
\<open>posttest p \<le> posttest q \<longleftrightarrow> p \<le> q\<close>
by (simp add: predrel_def)
lemma pretest_mono[simp]:
\<open>pretest p \<le> pretest q \<longleftrightarrow> p \<le> q\<close>
by (simp add: predrel_def le_fun_def)
lemma pretest_conj_distrib:
\<open>pretest (p1 \<sqinter> p2) = pretest p1 \<sqinter> pretest p2\<close>
by (force simp add: predrel_def)
lemma posttest_conj_distrib:
\<open>posttest (p1 \<sqinter> p2) = posttest p1 \<sqinter> posttest p2\<close>
by (force simp add: predrel_def)
lemma pretest_disj_distrib:
\<open>pretest (p1 \<squnion> p2) = pretest p1 \<squnion> pretest p2\<close>
by (force simp add: predrel_def)
lemma posttest_disj_distrib:
\<open>posttest (p1 \<squnion> p2) = posttest p1 \<squnion> posttest p2\<close>
by (force simp add: predrel_def)
lemma pretest_conj_eq:
\<open>pretest (p \<sqinter> q) = pretest p \<sqinter> pretest q\<close>
by (force simp add: predrel_def)
subsubsection \<open> rel_image \<close>
lemma rel_image_conj_semidistrib:
\<open>rel_image f (ra \<sqinter> rb) \<le> rel_image f ra \<sqinter> rel_image f rb\<close>
by (force simp add: rel_image_def le_fun_def)
lemma inj_rel_image_inf_distrib:
\<open>inj f \<Longrightarrow> rel_image f (ra \<sqinter> rb) = rel_image f ra \<sqinter> rel_image f rb\<close>
by (simp add: rel_image_def fun_eq_iff inj_def, blast)
lemma rel_image_disj_distrib:
\<open>rel_image f (ra \<squnion> rb) = rel_image f ra \<squnion> rel_image f rb\<close>
by (force simp add: rel_image_def le_fun_def)
lemma rel_image_mono:
\<open>ra \<le> rb \<Longrightarrow> rel_image f ra \<le> rel_image f rb\<close>
by (metis rel_image_disj_distrib sup.order_iff)
subsubsection \<open> pre- and post-state \<close>
lemma pre_state_Sup_eq[simp]:
\<open>pre_state (\<Squnion>A) = \<Squnion>(pre_state ` A)\<close>
by (force simp add: pre_state_def Sup_fun_def fun_eq_iff)
lemma post_state_Sup_eq[simp]:
\<open>post_state (\<Squnion>A) = \<Squnion>(post_state ` A)\<close>
by (force simp add: post_state_def Sup_fun_def fun_eq_iff)
lemma pre_state_trancl_eq[simp]:
\<open>pre_state (r\<^sup>+\<^sup>+) = pre_state r\<close>
unfolding pre_state_def
apply (intro ext iffI)
apply (clarify, rule tranclp_induct[of r]; blast)
apply blast
done
lemma post_state_trancl_eq[simp]:
\<open>post_state (r\<^sup>+\<^sup>+) = post_state r\<close>
unfolding post_state_def
apply (intro ext iffI)
apply (clarify, rule tranclp_induct[of r]; blast)
apply blast
done
lemma pre_state_relconj_le:
\<open>pre_state (r1 \<sqinter> r2) \<le> pre_state r1 \<sqinter> pre_state r2\<close>
by (force simp add: pre_state_def)
lemma pre_state_reldisj[simp]:
\<open>pre_state (r1 \<squnion> r2) = pre_state r1 \<squnion> pre_state r2\<close>
by (force simp add: pre_state_def)
lemma post_state_relconj_le:
\<open>post_state (r1 \<sqinter> r2) \<le> post_state r1 \<sqinter> post_state r2\<close>
by (force simp add: post_state_def)
lemma post_state_reldisj[simp]:
\<open>post_state (r1 \<squnion> r2) = post_state r1 \<squnion> post_state r2\<close>
by (force simp add: post_state_def)
subsubsection \<open> quasireflp \<close>
definition \<open>quasireflp r \<equiv> reflp_on (Collect (prepost_state r)) r\<close>
lemma quasireflp_iff:
\<open>quasireflp r = (\<forall>x. (\<exists>y. r x y) \<or> (\<exists>y. r y x) \<longrightarrow> r x x)\<close>
by (simp add: quasireflp_def reflp_on_def prepost_state_def')
lemma quasireflpD1[dest]:
\<open>quasireflp r \<Longrightarrow> r x y \<Longrightarrow> r x x\<close>
by (metis quasireflp_iff)
lemma quasireflpD2[dest]:
\<open>quasireflp r \<Longrightarrow> r x y \<Longrightarrow> r y y\<close>
by (metis quasireflp_iff)
lemma quasireflpD1'[dest]:
\<open>quasireflp r \<Longrightarrow> pre_state r x \<Longrightarrow> r x x\<close>
by (metis pre_state_def quasireflp_iff)
lemma quasireflpD2'[dest]:
\<open>quasireflp r \<Longrightarrow> post_state r y \<Longrightarrow> r y y\<close>
by (metis post_state_def quasireflp_iff)
subsubsection \<open> pre-change state\<close>
lemma pre_change_state_mono[dest]:
\<open>r1 \<le> r2 \<Longrightarrow> pre_change_state r1 x \<Longrightarrow> pre_change_state r2 x\<close>
by (force simp add: pre_change_state_def)
lemma post_change_state_mono[dest]:
\<open>r1 \<le> r2 \<Longrightarrow> post_change_state r1 x \<Longrightarrow> post_change_state r2 x\<close>
by (force simp add: post_change_state_def)
lemma change_state_mono[dest]:
\<open>r1 \<le> r2 \<Longrightarrow> change_state r1 x \<Longrightarrow> change_state r2 x\<close>
by (force simp add: change_state_def)
subsection \<open> Relational Trasitive and Reflexive-transitive Closure \<close>
lemma implies_rel_then_rtranscl_implies_rel:
assumes assms_induct:
\<open>r\<^sup>*\<^sup>* x y\<close>
\<open>\<forall>x y. r x y \<longrightarrow> s x y\<close>
and assms_misc:
\<open>(\<And>a. s a a)\<close>
\<open>(\<And>a b c. s a b \<Longrightarrow> s b c \<Longrightarrow> s a c)\<close>
shows \<open>s x y\<close>
using assms_induct
by (induct rule: rtranclp_induct)
(blast intro: assms_misc)+
lemma transp_subrel_compp_smaller:
\<open>transp S \<Longrightarrow> R \<le> S \<Longrightarrow> S OO R \<le> S\<close>
\<open>transp S \<Longrightarrow> R \<le> S \<Longrightarrow> R OO S \<le> S\<close>
by (meson order.refl order.trans relcompp_mono transp_relcompp_less_eq)+
lemma rel_le_rtranscp_relcompp_absorb:
\<open>R \<le> S \<Longrightarrow> S\<^sup>*\<^sup>* OO R\<^sup>*\<^sup>* = S\<^sup>*\<^sup>*\<close>
\<open>R \<le> S \<Longrightarrow> R\<^sup>*\<^sup>* OO S\<^sup>*\<^sup>* = S\<^sup>*\<^sup>*\<close>
apply -
apply (rule antisym)
apply (metis rtranclp_mono transp_rtranclp transp_subrel_compp_smaller(1))
apply force
apply (rule antisym)
apply (simp add: rtranclp_mono transp_subrel_compp_smaller(2))
apply force
done
lemma rtransp_rel_is_rtransclp:
\<open>reflp R \<Longrightarrow> transp R \<Longrightarrow> R\<^sup>*\<^sup>* = R\<close>
apply (intro ext iffI)
apply ((rule rtranclp_induct, assumption); force dest: reflpD transpD)
apply force
done
lemma rtranclp_absorb_id_right[simp]:
\<open>(\<lambda>x y. r x y \<or> x = y)\<^sup>*\<^sup>* = r\<^sup>*\<^sup>*\<close>
apply (rule HOL.trans[where s=\<open>r\<^sup>=\<^sup>=\<^sup>*\<^sup>*\<close>])
apply (simp del: rtranclp_reflclp add: sup_fun_def)
apply simp
done
lemma rtranclp_absorb_id_left[simp]:
\<open>(\<lambda>x y. x = y \<or> r x y)\<^sup>*\<^sup>* = r\<^sup>*\<^sup>*\<close>
by (subst disj_commute, simp)
lemma refl_le_trans_eq[simp]:
\<open>reflp r1 \<Longrightarrow> transp r2 \<Longrightarrow> r1 \<le> r2 \<Longrightarrow> r1 OO r2 = r2\<close>
by (metis (no_types, lifting) OO_eq eq_comp_r reflclp_ident_if_reflp relcompp_distrib2
sup.absorb_iff2 transp_subrel_compp_smaller(2))
lemma refl_le_trans_eq2[simp]:
\<open>reflp r1 \<Longrightarrow> transp r2 \<Longrightarrow> r1 \<le> r2 \<Longrightarrow> r2 OO r1 = r2\<close>
by (metis (no_types, lifting) OO_eq dual_order.eq_iff reflp_eq relcompp_mono
transp_subrel_compp_smaller(1))
lemma rtransp_relcompp_absorb_lr[simp]: \<open>(r1 \<squnion> r2)\<^sup>*\<^sup>* OO r1\<^sup>*\<^sup>* = (r1 \<squnion> r2)\<^sup>*\<^sup>*\<close>
by (simp add: rel_le_rtranscp_relcompp_absorb(1))
lemma rtransp_relcompp_absorb_rr[simp]: \<open>(r1 \<squnion> r2)\<^sup>*\<^sup>* OO r2\<^sup>*\<^sup>* = (r1 \<squnion> r2)\<^sup>*\<^sup>*\<close>
by (simp add: rel_le_rtranscp_relcompp_absorb(1))
lemma rtransp_relcompp_absorb_rl[simp]: \<open>r2\<^sup>*\<^sup>* OO (r1 \<squnion> r2)\<^sup>*\<^sup>* = (r1 \<squnion> r2)\<^sup>*\<^sup>*\<close>
by (simp add: rel_le_rtranscp_relcompp_absorb(2))
lemma rtransp_relcompp_absorb_ll[simp]: \<open>r1\<^sup>*\<^sup>* OO (r1 \<squnion> r2)\<^sup>*\<^sup>* = (r1 \<squnion> r2)\<^sup>*\<^sup>*\<close>
by (simp add: rel_le_rtranscp_relcompp_absorb(2))
declare eq_OO[simp] OO_eq[simp]
lemma rtranclp_tuple_rel_semidistrib:
\<open>(\<lambda>(a, c) (b, d). r1 a b \<and> r2 c d)\<^sup>*\<^sup>* ac bd
\<Longrightarrow> r1\<^sup>*\<^sup>* (fst ac) (fst bd) \<and> r2\<^sup>*\<^sup>* (snd ac) (snd bd)\<close>
by (induct rule: rtranclp_induct; force)
lemma rtranclp_tuple_lift_eq_left:
\<open>r\<^sup>*\<^sup>* c d \<Longrightarrow> (\<lambda>(a, c) (b, d). a = b \<and> r c d)\<^sup>*\<^sup>* (a,c) (a,d)\<close>
by (induct rule: rtranclp_induct, fast, simp add: rtranclp.rtrancl_into_rtrancl)
lemma rtranclp_tuple_lift_eq_right:
\<open>r\<^sup>*\<^sup>* a b \<Longrightarrow> (\<lambda>(a, c) (b, d). r a b \<and> c = d)\<^sup>*\<^sup>* (a,c) (b,c)\<close>
by (induct rule: rtranclp_induct, fast, simp add: rtranclp.rtrancl_into_rtrancl)
lemma rtranclp_eq_eq[simp]:
\<open>(=)\<^sup>*\<^sup>* = (=)\<close>
by (simp add: rtransp_rel_is_rtransclp)
lemma tranclp_mono:
\<open>r \<le> s \<Longrightarrow> r\<^sup>+\<^sup>+ \<le> s\<^sup>+\<^sup>+\<close>
by (simp add: relcompp_mono rtranclp_mono tranclp_unfold_left)
lemma univ_rel_refltranclp[simp]:
\<open>\<top>\<^sup>*\<^sup>* = \<top>\<close>
by auto
lemma empty_rel_tranclp[simp]:
\<open>\<bottom>\<^sup>+\<^sup>+ = \<bottom>\<close>
by (simp add: tranclp_unfold_left)
lemma inf_tranclp_subrel:
\<open>(A \<sqinter> B)\<^sup>+\<^sup>+ \<le> A\<^sup>+\<^sup>+\<close>
\<open>(A \<sqinter> B)\<^sup>+\<^sup>+ \<le> B\<^sup>+\<^sup>+\<close>
by (simp add: tranclp_mono)+
lemma inf_rtranclp_subrel:
\<open>(A \<sqinter> B)\<^sup>*\<^sup>* \<le> A\<^sup>*\<^sup>*\<close>
\<open>(A \<sqinter> B)\<^sup>*\<^sup>* \<le> B\<^sup>*\<^sup>*\<close>
by (simp add: rtranclp_mono)+
lemma subrel_sup_tranclp:
\<open>A\<^sup>+\<^sup>+ \<le> (A \<squnion> B)\<^sup>+\<^sup>+\<close>
\<open>B\<^sup>+\<^sup>+ \<le> (A \<squnion> B)\<^sup>+\<^sup>+\<close>
by (simp add: tranclp_mono)+
lemma subrel_sup_rtranclp:
\<open>A\<^sup>*\<^sup>* \<le> (A \<squnion> B)\<^sup>*\<^sup>*\<close>
\<open>B\<^sup>*\<^sup>* \<le> (A \<squnion> B)\<^sup>*\<^sup>*\<close>
by (simp add: rtranclp_mono)+
section \<open> Function Properties \<close>
lemmas bij_betw_disjoint_insert =
bij_betw_disjoint_Un[where A=\<open>{b}\<close> and C=\<open>{d}\<close> for b d, simplified]
lemma bij_betw_insert_ignore:
\<open>bij_betw f B D \<Longrightarrow> b \<in> B \<Longrightarrow> d \<in> D \<Longrightarrow> bij_betw f (insert b B) (insert d D)\<close>
by (simp add: insert_absorb)
lemma bij_betw_singleton:
\<open>f a = b \<Longrightarrow> bij_betw f {a} {b}\<close>
by (simp add: bij_betw_def)
lemmas bij_betw_combine_insert =
bij_betw_combine[where A=\<open>{b}\<close> and B=\<open>{d}\<close> for b d, simplified]
section \<open> Options \<close>
lemma not_eq_None[simp]: \<open>None \<noteq> x \<longleftrightarrow> (\<exists>z. x = Some z)\<close>
using option.exhaust_sel by auto
text \<open> We need to do this with cases to avoid infinite simp loops \<close>
lemma option_eq_iff:
\<open>x = y \<longleftrightarrow> (case x of
None \<Rightarrow> (case y of None \<Rightarrow> True | Some _ \<Rightarrow> False)
| Some x' \<Rightarrow> (case y of None \<Rightarrow> False | Some y' \<Rightarrow> x' = y'))\<close>
by (force split: option.splits)
text \<open> An alternative to \<open>option.split\<close>, which gives the conjunctive enumeration. \<close>
lemma case_option_disj_iff:
\<open>(case ma of None \<Rightarrow> p | Some a \<Rightarrow> q a) \<longleftrightarrow>
ma = None \<and> p \<or> (\<exists>a. ma = Some a \<and> q a)\<close>
by (metis case_optionE option.simps(4,5))
section \<open> Partial Maps \<close>
lemma map_le_restrict_eq: \<open>ma \<subseteq>\<^sub>m mb \<Longrightarrow> mb |` dom ma = ma\<close>
by (rule ext, metis domIff map_le_def restrict_map_def)
lemma map_restrict_un_eq:
\<open>m |` (A \<union> B) = m |` A ++ m |` B\<close>
by (force simp add: restrict_map_def map_add_def split: option.splits)
lemma map_le_split:
assumes \<open>ma \<subseteq>\<^sub>m mb\<close>
shows \<open>mb = ma ++ mb |` (- dom ma)\<close>
using assms
by (subst map_le_restrict_eq[OF assms, symmetric], force simp add: map_restrict_un_eq[symmetric])
lemma map_disjoint_dom_cancel_right:
assumes disjoint_ac: \<open>dom a \<inter> dom c = {}\<close>
and disjoint_ac: \<open>dom b \<inter> dom c = {}\<close>
shows \<open>(a ++ c = b ++ c) \<longleftrightarrow> a = b\<close>
using assms
by (metis (no_types, lifting) Int_Un_distrib Int_commute Un_Int_eq(3)
disjoint_ac dom_map_add map_add_comm map_le_iff_map_add_commute map_le_restrict_eq)
lemma map_disjoint_dom_cancel_left:
assumes disjoint_ac: \<open>dom a \<inter> dom b = {}\<close>
and disjoint_ac: \<open>dom a \<inter> dom c = {}\<close>
shows \<open>(a ++ b = a ++ c) \<longleftrightarrow> b = c\<close>
using assms
by (metis (no_types, lifting) Int_Un_distrib Int_commute Un_Int_eq(3)
disjoint_ac dom_map_add map_add_comm map_le_iff_map_add_commute map_le_restrict_eq)
lemma le_map_le_iff_sepadd:
\<open>(a \<subseteq>\<^sub>m b) = (\<exists>c. dom a \<inter> dom c = {} \<and> b = a ++ c)\<close>
by (metis dom_restrict inf_compl_bot_right map_add_comm map_le_map_add map_le_split)
lemma disjoint_dom_map_add_restrict_distrib:
\<open>dom a \<inter> dom b = {} \<Longrightarrow> (a ++ b) |` A = a |` A ++ b |` A\<close>
by (simp add: fun_eq_iff restrict_map_def map_add_def)
lemma antidom_restrict_eq[simp]:
\<open>a |` (- dom a) = Map.empty\<close>
by (force simp add: restrict_map_def subset_iff domIff)
lemma dom_subset_restrict_eq:
\<open>dom a \<subseteq> A \<Longrightarrow> a |` A = a\<close>
by (force simp add: restrict_map_def subset_iff domIff)
lemmas dom_disjoint_restrict_eq =
dom_subset_restrict_eq[OF iffD1[OF disjoint_eq_subset_Compl]]
section \<open> Sets \<close>
lemma disjoint_equiv_iff_eq:
\<open>(\<forall>C. A \<inter> C = {} \<longleftrightarrow> B \<inter> C = {}) \<longleftrightarrow> A = B\<close>
by blast
lemma surj_disjoint_equiv_iff_eq:
\<open>surj f \<Longrightarrow> (\<forall>x. A \<inter> f x = {} \<longleftrightarrow> B \<inter> f x = {}) \<longleftrightarrow> A = B\<close>
by (metis disjoint_equiv_iff_eq surjD)
lemma Collect_neg_eq:
\<open>Collect (- p) = - Collect p\<close>
by (simp add: set_eq_iff)
section \<open> Options \<close>
lemma not_Some_prod_eq[iff]: \<open>(\<forall>a b. x \<noteq> Some (a,b)) \<longleftrightarrow> x = None\<close>
by (metis not_eq_None prod.collapse)
lemma not_Some_prodprod_eq[iff]: \<open>(\<forall>a b c. x \<noteq> Some ((a,b),c)) \<longleftrightarrow> x = None\<close>
by (metis not_eq_None prod.collapse)
lemmas rev_finite_subset_Collect =
rev_finite_subset[of \<open>Collect P\<close> \<open>Collect Q\<close> for P Q, OF _ iffD2[OF Collect_mono_iff]]
(* We can prove the existence of a map satisfying a relation by showing
the relation is nice and that there exists a value for every input.
*)
lemma finite_map_choice_iff:
shows \<open>(\<exists>f. finite (dom f) \<and> (\<forall>x. P x (f x))) \<longleftrightarrow>
(finite {x. (\<exists>y. P x (Some y)) \<and> \<not> P x None} \<and> (\<forall>x. \<exists>y. P x y))\<close>
apply -
apply (rule iffI)
subgoal (* 1 \<Longrightarrow> 2 *)
apply (clarsimp simp add: dom_def)
apply (subgoal_tac \<open>(\<forall>x. f x = None \<longrightarrow> P x None) \<and> (\<forall>x y. f x = Some y \<longrightarrow> P x (Some y))\<close>)
prefer 2
apply metis
apply (rule conjI)
apply (rule rev_finite_subset, assumption)
apply blast
apply force
done
subgoal (* 2 \<Longrightarrow> 1 *)
apply (clarsimp simp add: dom_def)
apply (clarsimp simp add: choice_iff)
apply (rule_tac x=\<open>\<lambda>x. if \<exists>y. P x (Some y) \<and> \<not> P x None then f x else None\<close> in exI)
apply (rule conjI)
apply clarsimp
apply (simp add: rev_finite_subset_Collect)
apply (simp, metis option.exhaust_sel)
done
done
section \<open> Orders \<close>
lemma order_neq_less_conv:
\<open>x \<le> y \<Longrightarrow> (x :: ('a :: order)) \<noteq> y \<longleftrightarrow> x < y\<close>
\<open>y \<le> x \<Longrightarrow> (x :: ('a :: order)) \<noteq> y \<longleftrightarrow> y < x\<close>
by fastforce+
lemma order_sandwich:
fixes k x :: \<open>'a :: order\<close>
shows
\<open>k \<le> x \<and> x \<le> k \<and> P \<longleftrightarrow> x = k \<and> P\<close>
\<open>k \<le> x \<and> P \<and> x \<le> k \<and> Q \<longleftrightarrow> x = k \<and> P \<and> Q\<close>
by force+
lemma (in preorder) le_disj_eq_absorb[simp]: \<open>a \<le> b \<or> a = b \<longleftrightarrow> a \<le> b\<close>
by force
lemmas preordering_refl =
preordering.axioms(1)[THEN partial_preordering.refl]
lemmas preordering_trans =
preordering.axioms(1)[THEN partial_preordering.trans]
definition (in order) \<open>downset x \<equiv> {y. y\<le>x}\<close>
definition (in order) \<open>Downset X \<equiv> {y. \<exists>x\<in>X. y \<le> x}\<close>
section \<open> Lattices \<close>
subsection \<open> Bounded distributive lattices \<close>
class distrib_lattice_bot = distrib_lattice + bounded_lattice_bot
class distrib_lattice_top = distrib_lattice + bounded_lattice_top
class bounded_distrib_lattice = distrib_lattice_bot + distrib_lattice_top
context boolean_algebra
begin
subclass distrib_lattice_bot by standard
subclass distrib_lattice_top by standard
subclass bounded_distrib_lattice by standard
end
subsection \<open> Misc \<close>
lemma (in semilattice_inf) inf_antisym:
\<open>a \<sqinter> cx = b \<Longrightarrow> b \<sqinter> cy = a \<Longrightarrow> a = b\<close>
by (metis inf.left_idem inf.commute)
lemma (in semilattice_sup) sup_antisym:
\<open>a \<squnion> cx = b \<Longrightarrow> b \<squnion> cy = a \<Longrightarrow> a = b\<close>
by (metis sup.right_idem sup.commute)
context lattice
begin
lemma inf_twist_sup_idem: \<open>a \<sqinter> b \<squnion> b \<sqinter> a = a \<sqinter> b\<close>
by (simp add: inf.commute)
lemma inf_twist_sup_idem_assoc: \<open>a \<sqinter> b \<squnion> b \<sqinter> a \<squnion> c = a \<sqinter> b \<squnion> c\<close>
by (simp add: inf_twist_sup_idem)
lemma inf_abac_eq_abc:
shows \<open>(a \<sqinter> b) \<sqinter> a \<sqinter> c = a \<sqinter> b \<sqinter> c\<close>
by (simp add: inf.absorb1)
end
context distrib_lattice
begin
lemma inf_sup_absorb2[simp]:
\<open>b \<sqinter> (a \<squnion> b) = b\<close>
by (simp add: inf.absorb1)
lemma sup_inf_absorb2[simp]:
\<open>b \<squnion> (a \<sqinter> b) = b\<close>
by (simp add: sup.absorb1)
lemma inf_crosssplit:
\<open>a \<sqinter> b = c \<sqinter> d \<Longrightarrow>
\<exists>ac ad bc bd. ac \<sqinter> ad = a \<and> bc \<sqinter> bd = b \<and> ac \<sqinter> bc = c \<and> ad \<sqinter> bd = d\<close>
apply (rule_tac x=\<open>a \<squnion> c\<close> in exI)
apply (rule_tac x=\<open>a \<squnion> d\<close> in exI)
apply (rule_tac x=\<open>b \<squnion> c\<close> in exI)
apply (rule_tac x=\<open>b \<squnion> d\<close> in exI)
apply (metis inf.commute sup.commute sup_inf_absorb sup_inf_distrib1)
done
lemma sup_crosssplit:
\<open>a \<squnion> b = c \<squnion> d \<Longrightarrow>
\<exists>ac ad bc bd. ac \<squnion> ad = a \<and> bc \<squnion> bd = b \<and> ac \<squnion> bc = c \<and> ad \<squnion> bd = d\<close>
apply (rule_tac x=\<open>a \<sqinter> c\<close> in exI)
apply (rule_tac x=\<open>a \<sqinter> d\<close> in exI)
apply (rule_tac x=\<open>b \<sqinter> c\<close> in exI)
apply (rule_tac x=\<open>b \<sqinter> d\<close> in exI)
apply (metis inf.commute sup.commute inf_sup_absorb inf_sup_distrib1)
done
end
definition (in conditionally_complete_lattice) \<open>supcl (A::'a set) \<equiv> {\<Squnion>A'|A'. A' \<noteq> {} \<and> A'\<subseteq>A}\<close>
definition (in conditionally_complete_lattice) \<open>infcl (A::'a set) \<equiv> {\<Sqinter>A'|A'. A' \<noteq> {} \<and> A'\<subseteq>A}\<close>
section \<open> Groups \<close>
lemmas eq_diff_eq_comm =
HOL.trans[OF eq_diff_eq, OF arg_cong[where f=\<open>\<lambda>x. x = y\<close> for y], OF add.commute]
thm eq_diff_eq
section \<open> Arithmetic \<close>
(* It feels like Isabelle/HOL is missing a theory of non-abelian ordered monoids.
An example of an instance of such an algebra is traces.
*)
lemma prefixcl_weak_canonical_plusD:
fixes a1 a2 :: \<open>'a :: {order,monoid_add}\<close>
assumes zero_le: \<open>\<And>a::'a. 0 \<le> a\<close>
assumes add_left_cancel_le: \<open>\<And>a b c::'a. b \<le> c \<Longrightarrow> a + b \<le> a + c\<close>
shows \<open>a1 \<le> a1 + a2\<close>
using assms
by (metis add.right_neutral)
lemma ex_times_k_iff:
fixes a :: \<open>'a :: division_ring\<close>
assumes \<open>k \<noteq> 0\<close>
shows \<open>(\<exists>x. a = x * k \<and> P x) \<longleftrightarrow> P (a / k)\<close>
using assms
by (metis eq_divide_eq)
lemma max_eq_k_iff:
fixes a b :: \<open>'a :: linorder\<close>
shows \<open>(max a b = k) = (a = k \<and> b \<le> k \<or> a \<le> k \<and> b = k)\<close>
by (simp add: eq_iff le_max_iff_disj)
lemma min_eq_k_iff:
fixes a b :: \<open>'a :: linorder\<close>
shows \<open>(min a b = k) = (a = k \<and> k \<le> b \<or> k \<le> a \<and> b = k)\<close>
by (simp add: eq_iff min_le_iff_disj)
lemma field_All_mult_inverse_iff:
fixes x k :: \<open>'a :: field\<close>