-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSepLogic.thy
1495 lines (1088 loc) · 62.1 KB
/
SepLogic.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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 SepLogic
imports Util
begin
text \<open>
This file implements a hierarchy of typeclasses for resource algebras.
This is inspired by Klein et. al's [KKB2012] Isabelle/HOL separation algebra typeclasses
and Appel et. al.'s [VSTBook2014] typeclass hierarchy in Coq.
\<close>
section \<open> Common Notions \<close>
class disjoint =
fixes disjoint :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> (infix \<open>##\<close> 60)
section \<open> Permission Algebras \<close>
class perm_alg = disjoint + plus +
(* partial commutative monoid *)
assumes partial_add_assoc: \<open>a ## b \<Longrightarrow> b ## c \<Longrightarrow> a ## c \<Longrightarrow> (a + b) + c = a + (b + c)\<close>
assumes partial_add_commute: \<open>a ## b \<Longrightarrow> a + b = b + a\<close>
assumes disjoint_sym: \<open>a ## b \<Longrightarrow> b ## a\<close>
assumes disjoint_add_rightL: \<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> a ## b\<close>
assumes disjoint_add_right_commute: \<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> b ## a + c\<close>
(* separation laws *)
assumes positivity:
\<open>a ## c1 \<Longrightarrow> a + c1 = b \<Longrightarrow> b ## c2 \<Longrightarrow> b + c2 = a \<Longrightarrow> a = b\<close>
begin
lemma trans_helper:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> \<exists>d. a ## d \<and> a + b + c = a + d\<close>
by (metis disjoint_add_rightL disjoint_add_right_commute disjoint_sym partial_add_assoc
partial_add_commute)
lemma disjoint_sym_iff: \<open>a ## b \<longleftrightarrow> b ## a\<close>
using disjoint_sym by blast
lemma disjoint_add_rightR: \<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> a ## c\<close>
by (metis disjoint_add_rightL disjoint_sym partial_add_commute)
lemma disjoint_add_leftL: \<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> a ## c\<close>
using disjoint_add_rightL disjoint_sym by blast
lemma disjoint_add_leftR: \<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> b ## c\<close>
by (metis disjoint_add_leftL disjoint_sym partial_add_commute)
lemma disjoint_add_right_commute2:
\<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> c ## b + a\<close>
by (metis disjoint_add_rightR disjoint_add_right_commute disjoint_sym partial_add_commute)
lemma disjoint_add_left_commute:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> c + b ## a\<close>
by (simp add: disjoint_sym_iff disjoint_add_right_commute)
lemma disjoint_add_left_commute2:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> a + c ## b\<close>
by (metis disjoint_add_leftR disjoint_add_left_commute partial_add_commute)
lemma disjoint_add_swap_rl:
\<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> a + b ## c\<close>
by (simp add: disjoint_sym_iff disjoint_add_right_commute partial_add_commute)
lemma disjoint_add_swap_rl2:
\<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> a + c ## b\<close>
by (simp add: disjoint_sym_iff disjoint_add_right_commute partial_add_commute)
lemma disjoint_add_swap_lr:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> a ## b + c\<close>
by (simp add: disjoint_add_right_commute2 disjoint_sym_iff partial_add_commute)
lemma disjoint_add_swap_lr2:
\<open>a ## c \<Longrightarrow> a + c ## b \<Longrightarrow> a ## b + c\<close>
by (metis disjoint_add_left_commute disjoint_sym_iff)
lemma disjoint_middle_swap:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> a + b + c ## d \<Longrightarrow> a + c ## b + d\<close>
by (metis disjoint_add_leftR disjoint_add_right_commute2 disjoint_add_swap_lr disjoint_sym_iff
partial_add_assoc)
lemma disjoint_middle_swap2:
\<open>b ## c \<Longrightarrow> b + c ## d \<Longrightarrow> a ## b + c + d \<Longrightarrow> a + c ## b + d\<close>
by (metis disjoint_add_rightR disjoint_add_right_commute2 disjoint_add_rightL partial_add_assoc
partial_add_commute)
lemma partial_add_left_commute:
\<open>a ## b \<Longrightarrow> a ## c \<Longrightarrow> b ## c \<Longrightarrow> b + (a + c) = a + (b + c)\<close>
by (metis partial_add_assoc partial_add_commute disjoint_sym)
lemma partial_add_left_commute2:
\<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> b + (a + c) = a + (b + c)\<close>
by (metis partial_add_left_commute disjoint_add_rightL disjoint_add_rightR)
lemma partial_add_right_commute:
\<open>a ## b \<Longrightarrow> a ## c \<Longrightarrow> b ## c \<Longrightarrow> a + b + c = a + c + b\<close>
by (simp add: disjoint_sym partial_add_assoc partial_add_commute)
lemma partial_add_assoc_commute_left:
\<open>a ## b \<Longrightarrow> a ## c \<Longrightarrow> b ## c \<Longrightarrow> b + a + c = a + (b + c)\<close>
by (metis partial_add_assoc partial_add_commute)
lemma partial_add_assoc_commute_right:
\<open>a ## b \<Longrightarrow> a ## c \<Longrightarrow> b ## c \<Longrightarrow> a + c + b = a + (b + c)\<close>
by (metis partial_add_commute partial_add_assoc_commute_left partial_add_right_commute)
lemma partial_add_assoc2:
\<open>a ## b \<Longrightarrow> a + b ## c \<Longrightarrow> (a + b) + c = a + (b + c)\<close>
using disjoint_add_leftL disjoint_add_leftR partial_add_assoc by blast
lemma partial_add_assoc3:
\<open>b ## c \<Longrightarrow> a ## b + c \<Longrightarrow> (a + b) + c = a + (b + c)\<close>
by (meson disjoint_add_rightR disjoint_add_rightL partial_add_assoc)
lemma partial_add_double_assoc:
\<open>a ## c \<Longrightarrow> b ## d \<Longrightarrow> c ## d \<Longrightarrow> b ## c + d \<Longrightarrow> a ## b + (c + d) \<Longrightarrow> a + b + (c + d) = (a + c) + (b + d)\<close>
by (metis disjoint_add_rightR disjoint_add_rightL disjoint_add_right_commute partial_add_assoc
partial_add_left_commute)
subsection \<open> order \<close>
text \<open>
Resources give rise to a natural order, but it's not the same as standard
order implementations unless all elements have a unit.
\<close>
text \<open>
The 'part_of' relation is almost an order, except that it doesn't satisfy reflexivity.
\<close>
definition (in perm_alg) part_of :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> (infix \<open>\<lesssim>\<close> 50) where
\<open>a \<lesssim> b \<equiv> \<exists>c. a ## c \<and> a + c = b\<close>
lemma part_of_trans[trans]:
\<open>a \<lesssim> b \<Longrightarrow> b \<lesssim> c \<Longrightarrow> a \<lesssim> c\<close>
by (fastforce dest: trans_helper simp add: part_of_def)
text \<open> This lemma is just positivity stated another way. \<close>
lemma part_of_antisym:
\<open>a \<lesssim> b \<Longrightarrow> b \<lesssim> a \<Longrightarrow> a = b\<close>
using part_of_def positivity by auto
definition less_eq_sepadd :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> (infix \<open>\<preceq>\<close> 50) where
\<open>(\<preceq>) \<equiv> \<lambda>a b. a = b \<or> a \<lesssim> b\<close>
lemmas less_eq_sepadd_def' = less_eq_sepadd_def[simplified part_of_def]
definition less_sepadd :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> (infix \<open>\<prec>\<close> 50) where
\<open>(\<prec>) \<equiv> \<lambda>a b. a \<noteq> b \<and> a \<lesssim> b\<close>
lemmas less_sepadd_def' = less_sepadd_def[simplified part_of_def]
abbreviation (input) greater_eq_sepadd (infix \<open>\<succeq>\<close> 50)
where \<open>(\<succeq>) \<equiv> \<lambda>x y. (\<preceq>) y x\<close>
abbreviation (input) greater_sepadd (infix \<open>\<succ>\<close> 50)
where \<open>(\<succ>) \<equiv> \<lambda>x y. (\<prec>) y x\<close>
sublocale resource_ordering: ordering \<open>(\<preceq>)\<close> \<open>(\<prec>)\<close>
apply standard
apply (metis less_eq_sepadd_def)
apply (metis less_eq_sepadd_def part_of_trans)
apply (force dest: part_of_antisym simp add: less_sepadd_def less_eq_sepadd_def)
apply (metis less_eq_sepadd_def part_of_antisym)
done
sublocale resource_order: order \<open>(\<preceq>)\<close> \<open>(\<prec>)\<close>
apply standard
apply (force dest: part_of_antisym simp add: less_sepadd_def less_eq_sepadd_def)
apply (metis resource_ordering.refl)
apply (metis resource_ordering.trans)
apply (metis resource_ordering.antisym)
done
text \<open> Set up the isabelle machinery to treat this like an order. \<close>
local_setup \<open>
HOL_Order_Tac.declare_order {
ops = {eq = @{term \<open>(=) :: 'a \<Rightarrow> 'a \<Rightarrow> bool\<close>}, le = @{term \<open>(\<preceq>)\<close>}, lt = @{term \<open>(\<prec>)\<close>}},
thms = {trans = @{thm resource_ordering.trans},
refl = @{thm resource_ordering.refl},
eqD1 = @{thm eq_refl}, eqD2 = @{thm eq_refl[OF sym]},
antisym = @{thm resource_ordering.antisym}, contr = @{thm notE}},
conv_thms = {less_le = @{thm eq_reflection[OF resource_order.less_le]},
nless_le = @{thm eq_reflection[OF resource_order.nless_le]}}
}
\<close>
lemma le_res_less_le_not_le:
\<open>a \<prec> b \<longleftrightarrow> a \<lesssim> b \<and> \<not> b \<lesssim> a\<close>
by (metis part_of_def less_sepadd_def positivity)
lemma partial_le_plus: \<open>a ## b \<Longrightarrow> a \<preceq> a + b\<close>
by (meson less_eq_sepadd_def part_of_def)
lemma partial_le_plus2: \<open>a ## b \<Longrightarrow> b \<preceq> a + b\<close>
by (metis partial_le_plus disjoint_sym partial_add_commute)
lemma partial_le_part_left: \<open>a ## b \<Longrightarrow> a + b \<preceq> c \<Longrightarrow> a \<preceq> c\<close>
using resource_ordering.trans partial_le_plus by blast
lemma partial_le_part_right: \<open>a ## b \<Longrightarrow> a + b \<preceq> c \<Longrightarrow> b \<preceq> c\<close>
using resource_ordering.trans partial_le_plus2 by blast
lemma common_subresource_selfsep:
\<open>a ## b \<Longrightarrow> ab \<preceq> a \<Longrightarrow> ab \<preceq> b \<Longrightarrow> ab ## ab\<close>
by (metis disjoint_add_rightL disjoint_sym less_eq_sepadd_def part_of_def)
lemma selfdisjoint_over_selfdisjoint:
\<open>a ## a \<Longrightarrow> \<forall>x. x \<preceq> a \<longrightarrow> x ## x\<close>
using common_subresource_selfsep by blast
lemma disjoint_preservation:
\<open>a' \<preceq> a \<Longrightarrow> a ## b \<Longrightarrow> a' ## b\<close>
by (metis disjoint_add_rightL disjoint_sym less_eq_sepadd_def part_of_def)
lemma disjoint_preservation2:
\<open>b' \<preceq> b \<Longrightarrow> a ## b \<Longrightarrow> a ## b'\<close>
using disjoint_preservation disjoint_sym by blast
lemma sepadd_left_mono:
\<open>a ## b \<Longrightarrow> a ## c \<Longrightarrow> b \<preceq> c \<Longrightarrow> a + b \<preceq> a + c\<close>
by (metis disjoint_add_swap_rl less_eq_sepadd_def part_of_def partial_add_assoc3)
lemma sepadd_right_mono: \<open>a ## c \<Longrightarrow> b ## c \<Longrightarrow> a \<preceq> b \<Longrightarrow> a + c \<preceq> b + c\<close>
by (metis disjoint_sym_iff partial_add_commute sepadd_left_mono)
subsection \<open> sepadd_unit \<close>
definition \<open>sepadd_unit a \<equiv> a ## a \<and> (\<forall>b. a ## b \<longrightarrow> a + b = b)\<close>
lemma sepadd_unitI[intro]:
\<open>a ## a \<Longrightarrow> (\<And>b. a ## b \<Longrightarrow> a + b = b) \<Longrightarrow> sepadd_unit a\<close>
using sepadd_unit_def by blast
lemma sepadd_unitE[elim]:
\<open>sepadd_unit a \<Longrightarrow> (a ## a \<Longrightarrow> (\<And>b. a ## b \<Longrightarrow> a + b = b) \<Longrightarrow> P) \<Longrightarrow> P\<close>
using sepadd_unit_def by blast
lemma sepadd_unitD:
\<open>sepadd_unit a \<Longrightarrow> a ## a\<close>
\<open>sepadd_unit a \<Longrightarrow> a ## b \<Longrightarrow> a + b = b\<close>
by blast+
abbreviation \<open>sepadd_units \<equiv> Collect sepadd_unit\<close>
text \<open> sepadd_unit is antimono; positivity said a different way \<close>
lemma below_unit_impl_unit:
\<open>a \<preceq> b \<Longrightarrow> sepadd_unit b \<Longrightarrow> sepadd_unit a\<close>
unfolding sepadd_unit_def less_eq_sepadd_def part_of_def
by (metis disjoint_add_rightL positivity)
lemma units_separate_to_units:
\<open>x ## y \<Longrightarrow> sepadd_unit (x + y) \<Longrightarrow> sepadd_unit x\<close>
using below_unit_impl_unit partial_le_plus by blast
lemma le_unit_iff_eq:
\<open>sepadd_unit b \<Longrightarrow> a \<preceq> b \<longleftrightarrow> b = a\<close>
by (metis disjoint_preservation2 partial_le_plus resource_ordering.eq_iff sepadd_unit_def)
lemma units_least: \<open>sepadd_unit x \<Longrightarrow> x ## y \<Longrightarrow> x \<preceq> y\<close>
by (metis partial_le_plus sepadd_unit_def)
lemma almost_units_are_units:
\<open>(\<forall>b. a ## b \<longrightarrow> a + b = b) \<Longrightarrow> a ## b \<Longrightarrow> a ## a\<close>
by (metis disjoint_add_rightL)
lemma sepadd_unit_idem_add[simp]: \<open>sepadd_unit u \<Longrightarrow> u + u = u\<close>
using sepadd_unit_def by auto
lemma sepadd_unit_left: \<open>sepadd_unit u \<Longrightarrow> u ## a \<Longrightarrow> u + a = a\<close>
using sepadd_unit_def by auto
lemma sepadd_unit_right: \<open>sepadd_unit u \<Longrightarrow> a ## u \<Longrightarrow> a + u = a\<close>
by (metis disjoint_sym partial_add_commute sepadd_unit_left)
lemma sepadd_unit_selfsep[dest, simp]: \<open>sepadd_unit u \<Longrightarrow> u ## u\<close>
by (simp add: sepadd_unit_def)
lemma add_sepadd_unit_add_iff_parts_sepadd_unit[simp]:
\<open>x ## y \<Longrightarrow> sepadd_unit (x + y) \<longleftrightarrow> sepadd_unit x \<and> sepadd_unit y\<close>
by (metis sepadd_unit_def units_separate_to_units)
lemma disjoint_units_identical:
\<open>a ## b \<Longrightarrow> sepadd_unit a \<Longrightarrow> sepadd_unit b \<Longrightarrow> a = b\<close>
by (metis disjoint_sym partial_add_commute sepadd_unit_def)
lemma related_units_disjoint:
\<open>sepadd_unit u1 \<Longrightarrow> sepadd_unit u2 \<Longrightarrow> a ## u1 \<Longrightarrow> a ## u2 \<Longrightarrow> u1 ## u2\<close>
by (metis disjoint_add_leftL disjoint_sym sepadd_unit_def)
lemma related_units_identical:
\<open>sepadd_unit u1 \<Longrightarrow> sepadd_unit u2 \<Longrightarrow> a ## u1 \<Longrightarrow> a ## u2 \<Longrightarrow> u2 = u1\<close>
using related_units_disjoint disjoint_units_identical by blast
lemma trans_disjoint_units_identical:
\<open>a ## b \<Longrightarrow> b ## c \<Longrightarrow> sepadd_unit a \<Longrightarrow> sepadd_unit c \<Longrightarrow> a = c\<close>
by (metis disjoint_sym related_units_identical)
lemma sepadd_unit_disjoint_trans:
\<open>sepadd_unit a \<Longrightarrow> a ## b \<Longrightarrow> b ## c \<Longrightarrow> a ## c\<close>
using disjoint_preservation units_least by blast
lemma unit_sub_closure2:
\<open>a ## x \<Longrightarrow> a + x ## y \<Longrightarrow> a + (x + y) = a \<Longrightarrow> a + x = a\<close>
by (simp add: positivity partial_add_assoc2)
lemma unit_sub_closure2':
\<open>a ## x \<Longrightarrow> a + x ## y \<Longrightarrow> a + x + y = a \<Longrightarrow> a + x = a\<close>
by (simp add: positivity partial_add_assoc2)
subsection \<open> zero_sepadd \<close>
definition \<open>sepadd_zero a \<equiv> a ## a \<and> (\<forall>b. a ## b \<longrightarrow> a + b = a)\<close>
text \<open> sepadd_zero is antimono \<close>
lemma above_zero_impl_zero:
\<open>a \<preceq> b \<Longrightarrow> sepadd_zero a \<Longrightarrow> sepadd_zero b\<close>
by (metis less_eq_sepadd_def part_of_def sepadd_zero_def)
lemma zeros_add_to_zero: \<open>x ## y \<Longrightarrow> sepadd_zero x \<Longrightarrow> sepadd_zero (x + y)\<close>
by (simp add: sepadd_zero_def)
subsection \<open> duplicable \<close>
lemma add_to_selfsep_preserves_selfsep: \<open>a ## b \<Longrightarrow> a + b = c \<Longrightarrow> c ## c \<Longrightarrow> a ## a\<close>
by (meson disjoint_add_rightL disjoint_sym)
lemma add_to_selfsep_preserves_selfsepR: \<open>a ## b \<Longrightarrow> a + b = c \<Longrightarrow> c ## c \<Longrightarrow> b ## b\<close>
using disjoint_sym partial_add_commute add_to_selfsep_preserves_selfsep by blast
definition \<open>sepadd_dup a \<equiv> a ## a \<and> a + a = a\<close>
lemma units_are_dup: \<open>sepadd_unit a \<Longrightarrow> sepadd_dup a\<close>
by (simp add: sepadd_dup_def)
lemma zeros_are_dup: \<open>sepadd_zero a \<Longrightarrow> sepadd_dup a\<close>
by (simp add: sepadd_dup_def sepadd_zero_def)
subsection \<open>sepdomeq\<close>
definition \<open>sepdomeq a b \<equiv> \<forall>c. a ## c = b ## c\<close>
lemma sepdomeq_reflp:
\<open>reflp sepdomeq\<close>
by (simp add: reflpI sepdomeq_def)
lemma sepdomeq_symp:
\<open>symp sepdomeq\<close>
by (metis sepdomeq_def sympI)
lemma sepdomeq_transp:
\<open>transp sepdomeq\<close>
by (simp add: sepdomeq_def transp_def)
lemma same_sepdom_disjoint_leftD:
\<open>sepdomeq a b \<Longrightarrow> a ## c \<Longrightarrow> b ## c\<close>
by (simp add: sepdomeq_def)
lemma sepdomeq_disjoint_rightD:
\<open>sepdomeq a b \<Longrightarrow> b ## c \<Longrightarrow> a ## c\<close>
by (simp add: sepdomeq_def)
definition \<open>sepdomsubseteq a b \<equiv> \<forall>c. a ## c \<longrightarrow> b ## c\<close>
lemma sepdomsubseteq_reflp:
\<open>reflp sepdomsubseteq\<close>
by (simp add: reflpI sepdomsubseteq_def)
lemma sepdomsubseteq_transp:
\<open>transp sepdomsubseteq\<close>
by (simp add: sepdomsubseteq_def transp_def)
lemma sepdomsubseteq_disjointD:
\<open>sepdomsubseteq a b \<Longrightarrow> a ## c \<Longrightarrow> b ## c\<close>
by (simp add: sepdomsubseteq_def)
subsection \<open> Seplogic connectives \<close>
definition sepconj :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> (infixl \<open>\<^emph>\<close> 88) where
\<open>P \<^emph> Q \<equiv> \<lambda>h. \<exists>h1 h2. h1 ## h2 \<and> h = h1 + h2 \<and> P h1 \<and> Q h2\<close>
lemma sepconj_iff: \<open>(P \<^emph> Q) r = (\<exists>h1 h2. h1 ## h2 \<and> r = h1 + h2 \<and> P h1 \<and> Q h2)\<close>
by (simp add: sepconj_def)
lemma sepconjI[intro]: \<open>h1 ## h2 \<Longrightarrow> r = h1 + h2 \<Longrightarrow> P h1 \<Longrightarrow> Q h2 \<Longrightarrow> (P \<^emph> Q) r\<close>
using sepconj_iff by auto
lemma sepconjE[elim!]:
\<open>(P \<^emph> Q) r \<Longrightarrow> (\<And>h1 h2. h1 ## h2 \<Longrightarrow> r = h1 + h2 \<Longrightarrow> P h1 \<Longrightarrow> Q h2 \<Longrightarrow> Z) \<Longrightarrow> Z\<close>
using sepconj_iff by auto
definition sepimp :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> (infixr \<open>\<midarrow>\<^emph>\<close> 65) where
\<open>P \<midarrow>\<^emph> Q \<equiv> \<lambda>h. \<forall>h1. h ## h1 \<longrightarrow> P h1 \<longrightarrow> Q (h + h1)\<close>
text \<open> See Bannister et. al. [BHK2018] for more discussion of this connective. \<close>
definition sepcoimp :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> (infixr \<open>\<sim>\<^emph>\<close> 65) where
\<open>P \<sim>\<^emph> Q \<equiv> \<lambda>h. \<forall>h1 h2. h1 ## h2 \<longrightarrow> h = h1 + h2 \<longrightarrow> P h1 \<longrightarrow> Q h2\<close>
definition septract :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> (infixr \<open>\<midarrow>\<odot>\<close> 67) where
\<open>P \<midarrow>\<odot> Q \<equiv> \<lambda>h. \<exists>h1. h ## h1 \<and> P h1 \<and> Q (h + h1)\<close>
definition septract_rev :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> (infixr \<open>\<odot>\<midarrow>\<close> 67) where
\<open>P \<odot>\<midarrow> Q \<equiv> \<lambda>h. \<exists>h'. h ## h' \<and> P (h + h') \<and> Q h'\<close>
definition subheapexist :: \<open>('a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> bool)\<close> where
\<open>subheapexist P \<equiv> \<lambda>h. \<exists>h1. h1 \<preceq> h \<and> P h1\<close>
definition emp :: \<open>'a \<Rightarrow> bool\<close> where
\<open>emp \<equiv> \<lambda>x. sepadd_unit x\<close>
fun iter_sepconj :: \<open>('a \<Rightarrow> bool) list \<Rightarrow> ('a \<Rightarrow> bool)\<close> where
\<open>iter_sepconj (P # Ps) = P \<^emph> iter_sepconj Ps\<close>
| \<open>iter_sepconj [] = emp\<close>
subsection \<open> Seplogic connective properties \<close>
subsubsection \<open> Sepconj \<close>
lemma sepconj_assoc: \<open>(P \<^emph> Q) \<^emph> R = P \<^emph> (Q \<^emph> R)\<close>
apply (clarsimp simp add: sepconj_def ex_simps[symmetric] partial_add_assoc simp del: ex_simps)
apply (intro ext iffI)
apply (metis disjoint_add_leftR disjoint_add_right_commute disjoint_sym partial_add_assoc
partial_add_commute)+
done
lemma sepconj_comm: \<open>P \<^emph> Q = Q \<^emph> P\<close>
unfolding sepconj_def
by (metis disjoint_sym partial_add_commute)
lemma sepconj_left_comm: \<open>Q \<^emph> (P \<^emph> R) = P \<^emph> (Q \<^emph> R)\<close>
apply (clarsimp simp add: sepconj_def ex_simps[symmetric] partial_add_assoc simp del: ex_simps)
apply (rule ext)
apply (metis disjoint_add_rightR disjoint_add_rightL disjoint_add_right_commute
partial_add_left_commute)
done
lemmas sepconj_ac = sepconj_assoc sepconj_comm sepconj_left_comm
lemma sepconj_mono[intro]:
\<open>P \<le> P' \<Longrightarrow> Q \<le> Q' \<Longrightarrow> P \<^emph> Q \<le> P' \<^emph> Q'\<close>
using sepconj_def by auto
lemma sepconj_monoL[intro]:
\<open>P \<le> Q \<Longrightarrow> P \<^emph> R \<le> Q \<^emph> R\<close>
using sepconj_def by auto
lemma sepconj_monoR[intro]:
\<open>Q \<le> R \<Longrightarrow> P \<^emph> Q \<le> P \<^emph> R\<close>
using sepconj_def by auto
lemma sepconj_comm_imp:
\<open>P \<^emph> Q \<le> Q \<^emph> P\<close>
by (simp add: sepconj_comm)
lemma sepconj_middle_monotone_lhsR: \<open>A1 \<^emph> A2 \<le> B \<Longrightarrow> C \<le> D \<Longrightarrow> A1 \<^emph> C \<^emph> A2 \<le> B \<^emph> D\<close>
by (metis sepconj_assoc sepconj_comm sepconj_mono)
lemma sepconj_middle_monotone_lhsL: \<open>A1 \<^emph> A2 \<le> B \<Longrightarrow> C \<le> D \<Longrightarrow> A1 \<^emph> C \<^emph> A2 \<le> D \<^emph> B\<close>
by (metis sepconj_assoc sepconj_comm sepconj_mono)
lemma sepconj_middle_monotone_rhsR: \<open>A \<le> B1 \<^emph> B2 \<Longrightarrow> C \<le> D \<Longrightarrow> A \<^emph> C \<le> B1 \<^emph> D \<^emph> B2\<close>
by (metis sepconj_assoc sepconj_comm sepconj_mono)
lemma sepconj_middle_monotone_rhsL: \<open>A \<le> B1 \<^emph> B2 \<Longrightarrow> C \<le> D \<Longrightarrow> C \<^emph> A \<le> B1 \<^emph> D \<^emph> B2\<close>
using sepconj_comm sepconj_middle_monotone_rhsR by presburger
lemma sepconj_middle_monotone_lhsR2: \<open>A1 \<^emph> A2 \<le> B \<Longrightarrow> A1 \<^emph> C \<^emph> A2 \<le> B \<^emph> C\<close>
by (simp add: sepconj_middle_monotone_lhsR)
lemma sepconj_middle_monotone_lhsL2: \<open>A1 \<^emph> A2 \<le> B \<Longrightarrow> A1 \<^emph> C \<^emph> A2 \<le> C \<^emph> B\<close>
by (simp add: sepconj_middle_monotone_lhsL)
lemma sepconj_middle_monotone_rhsR2: \<open>A \<le> B1 \<^emph> B2 \<Longrightarrow> A \<^emph> C \<le> B1 \<^emph> C \<^emph> B2\<close>
by (simp add: sepconj_middle_monotone_rhsR)
lemma sepconj_middle_monotone_rhsL2: \<open>A \<le> B1 \<^emph> B2 \<Longrightarrow> C \<^emph> A \<le> B1 \<^emph> C \<^emph> B2\<close>
by (simp add: sepconj_middle_monotone_rhsL)
lemma sepconj_eq_eq:
\<open>((=) h1 \<^emph> (=) h2) = (\<lambda>x. h1 ## h2 \<and> x = h1 + h2)\<close>
by (simp add: sepconj_def fun_eq_iff)
lemma sepconj_eq_eq2:
\<open>h1 ## h2 \<Longrightarrow> ((=) h1 \<^emph> (=) h2) = ((=) (h1 + h2))\<close>
by (force simp add: sepconj_eq_eq)
subsubsection \<open> emp \<close>
lemma weak_emp_sepconj: \<open>\<top> \<le> emp \<midarrow>\<odot> p \<Longrightarrow> emp \<^emph> p = p\<close>
by (simp add: emp_def sepadd_unit_def septract_def sepconj_def le_fun_def fun_eq_iff)
(metis disjoint_sym_iff)
lemma weak_emp_sepconj2: \<open>emp \<midarrow>\<odot> p \<le> \<bottom> \<Longrightarrow> emp \<^emph> p = \<bottom>\<close>
by (simp add: emp_def sepadd_unit_def septract_def sepconj_def le_fun_def fun_eq_iff)
(metis disjoint_sym_iff partial_add_commute)
subsubsection \<open> Sepimp \<close>
lemma sepimp_sepconjL:
\<open>P \<^emph> Q \<midarrow>\<^emph> R = P \<midarrow>\<^emph> Q \<midarrow>\<^emph> R\<close>
apply (clarsimp simp add: sepconj_def sepimp_def fun_eq_iff)
apply (rule iffI)
apply (metis disjoint_add_rightR disjoint_add_right_commute disjoint_sym partial_add_assoc
partial_add_commute)+
done
lemma sepimp_conjR:
\<open>P \<midarrow>\<^emph> Q \<sqinter> R = (P \<midarrow>\<^emph> Q) \<sqinter> (P \<midarrow>\<^emph> R)\<close>
by (force simp add: sepimp_def fun_eq_iff)
lemma sepimp_top_eq[simp]:
\<open>P \<midarrow>\<^emph> \<top> = \<top>\<close>
by (simp add: sepimp_def fun_eq_iff)
subsubsection \<open> everything else \<close>
lemma septract_reverse: \<open>P \<midarrow>\<odot> Q = Q \<odot>\<midarrow> P\<close>
by (force simp add: septract_def septract_rev_def)
(*
\<^emph> < ~ > \<midarrow>\<^emph>
| X
\<sim>\<^emph> < ~ > \<midarrow>\<odot>
*)
lemma septract_sepimp_dual: \<open>P \<midarrow>\<odot> Q = -(P \<midarrow>\<^emph> (-Q))\<close>
unfolding septract_def sepimp_def
by force
lemma sepimp_sepcoimp_dual: \<open>P \<sim>\<^emph> Q = -(P \<^emph> (-Q))\<close>
unfolding sepconj_def sepcoimp_def
by force
lemma sepcoimp_sepimp_dual: \<open>P \<^emph> Q = -(P \<sim>\<^emph> -Q)\<close>
unfolding sepconj_def sepcoimp_def
by force
lemma sepconj_sepimp_galois: \<open>P \<^emph> Q \<le> R \<longleftrightarrow> P \<le> Q \<midarrow>\<^emph> R\<close>
using sepconj_def sepimp_def by fastforce
lemma sepcoimp_septract_galois: \<open>P \<odot>\<midarrow> Q \<le> R \<longleftrightarrow> P \<le> Q \<sim>\<^emph> R\<close>
unfolding sepcoimp_def septract_rev_def le_fun_def
using disjoint_sym partial_add_commute by fastforce
lemma sepcoimp_curry: \<open>P \<sim>\<^emph> Q \<sim>\<^emph> R = P \<^emph> Q \<sim>\<^emph> R\<close>
apply (clarsimp simp add: sepcoimp_def sepconj_def)
apply (intro ext iffI; clarsimp)
apply (metis disjoint_add_leftR disjoint_add_right_commute disjoint_sym partial_add_assoc
partial_add_commute)+
done
subsection \<open> Precision \<close>
definition precise :: \<open>('a \<Rightarrow> bool) \<Rightarrow> bool\<close> where
\<open>precise P \<equiv> \<forall>h h1 h2. h1 \<preceq> h \<longrightarrow> h2 \<preceq> h \<longrightarrow> P h1 \<longrightarrow> P h2 \<longrightarrow> h1 = h2\<close>
subsection \<open> sepconj/conj distributivity \<close>
text \<open> this direction is always true \<close>
lemma sepconj_conj_semidistrib:
\<open>f \<^emph> (q1 \<sqinter> q2) \<le> (f \<^emph> q1) \<sqinter> (f \<^emph> q2)\<close>
by (force simp add: le_fun_def)
text \<open>
The following predicates are equivalent to precision in a cancellative algebra,
but incomparable in a more generic setting.
\<close>
definition sepconj_conj_distrib :: \<open>('a \<Rightarrow> bool) \<Rightarrow> bool\<close> where
\<open>sepconj_conj_distrib P \<equiv> (\<forall>Q Q'. (P \<^emph> Q) \<sqinter> (P \<^emph> Q') \<le> P \<^emph> (Q \<sqinter> Q'))\<close>
lemma sepconj_conj_distribD:
\<open>sepconj_conj_distrib P \<Longrightarrow> P \<^emph> (Q \<sqinter> Q') = (P \<^emph> Q) \<sqinter> (P \<^emph> Q')\<close>
unfolding sepconj_conj_distrib_def
by (meson antisym sepconj_conj_semidistrib)
lemma sepconj_conj_distrib_then_sepconj_imp_sepcoimp:
\<open>sepconj_conj_distrib P \<Longrightarrow> P \<^emph> Q \<le> P \<sim>\<^emph> Q\<close>
unfolding sepconj_conj_distrib_def sepconj_def sepcoimp_def fun_eq_iff le_fun_def
apply clarsimp
apply (rename_tac h1 h1' h2 h2')
apply (drule_tac x=\<open>(=) h1'\<close> in spec, drule_tac x=\<open>(=) h2'\<close> in spec)
apply blast
done
lemma sepconj_imp_sepcoimp_then_sepconj_conj_distrib:
\<open>(\<forall>Q. P \<^emph> Q \<le> P \<sim>\<^emph> Q) \<Longrightarrow> sepconj_conj_distrib P\<close>
unfolding sepconj_conj_distrib_def sepconj_def sepcoimp_def fun_eq_iff le_fun_def
apply (clarsimp simp add: imp_ex_conjL imp_conjL)
apply (rename_tac h1 h1' h2 h2')
apply (drule_tac x=\<open>(=) h1'\<close> in spec)
apply blast
done
lemma sepconj_conj_distrib_iff_sepconj_imp_sepcoimp:
\<open>sepconj_conj_distrib P \<longleftrightarrow> (\<forall>Q. P \<^emph> Q \<le> P \<sim>\<^emph> Q)\<close>
using sepconj_conj_distrib_then_sepconj_imp_sepcoimp
sepconj_imp_sepcoimp_then_sepconj_conj_distrib
by blast
lemma sepconj_imp_sepcoimp_iff_sepconj_eq_strong_sepcoimp:
\<open>(\<forall>Q. P \<^emph> Q \<le> P \<sim>\<^emph> Q) \<longleftrightarrow> (\<forall>Q. P \<^emph> Q = (P \<^emph> \<top>) \<sqinter> (P \<sim>\<^emph> Q))\<close>
apply (clarsimp simp add: sepconj_def sepcoimp_def precise_def le_fun_def fun_eq_iff)
apply (intro iffI allI conjI impI)
apply blast
apply blast
apply blast
apply clarsimp
done
lemma sepconj_conj_distrib_iff_sepconj_eq_strong_sepcoimp:
\<open>sepconj_conj_distrib P \<longleftrightarrow> (\<forall>Q. P \<^emph> Q = (P \<^emph> \<top>) \<sqinter> (P \<sim>\<^emph> Q))\<close>
by (meson sepconj_conj_distrib_iff_sepconj_imp_sepcoimp
sepconj_imp_sepcoimp_iff_sepconj_eq_strong_sepcoimp)
lemmas sepconj_conj_distrib_then_sepconj_eq_strong_sepcoimp =
iffD1[OF sepconj_conj_distrib_iff_sepconj_eq_strong_sepcoimp]
lemmas sepconj_eq_strong_sepcoimp_then_sepconj_conj_distrib =
iffD2[OF sepconj_conj_distrib_iff_sepconj_eq_strong_sepcoimp]
lemma eqpred_sepconj_conj_distrib_impl_cancel:
\<open>sepconj_conj_distrib ((=) c) \<Longrightarrow>
a ## c \<Longrightarrow> b ## c \<Longrightarrow> a + c = b + c \<Longrightarrow> a = b\<close>
apply (clarsimp simp add: sepconj_conj_distrib_def sepconj_def le_fun_def)
apply (drule_tac x=\<open>(=) a\<close> and y=\<open>(=) b\<close> in spec2)
apply (simp add: disjoint_sym_iff partial_add_commute)
done
lemma sepconj_conj_distrib_impl_septract_sepconj_imp:
\<open>sepconj_conj_distrib P \<Longrightarrow> (P \<midarrow>\<odot> P \<^emph> Q) \<le> Q\<close>
by (simp add: sepcoimp_septract_galois sepconj_conj_distrib_then_sepconj_imp_sepcoimp septract_reverse)
lemma septract_sepconj_imp_impl_sepconj_conj_distrib:
\<open>\<forall>Q. (P \<midarrow>\<odot> P \<^emph> Q) \<le> Q \<Longrightarrow> sepconj_conj_distrib P\<close>
by (simp add: sepcoimp_septract_galois sepconj_conj_distrib_iff_sepconj_imp_sepcoimp
septract_reverse)
subsection \<open> Intuitionistic \<close>
(* TODO: rename intuitionistic to bring it in line with the seplogic jungle paper *)
definition intuitionistic :: \<open>('a \<Rightarrow> bool) \<Rightarrow> bool\<close> where
\<open>intuitionistic P \<equiv> \<forall>h h'. h \<preceq> h' \<longrightarrow> P h \<longrightarrow> P h'\<close>
lemma precise_to_intuitionistic:
\<open>precise P \<Longrightarrow> intuitionistic (P \<^emph> \<top>)\<close>
unfolding sepconj_def precise_def intuitionistic_def
by (metis less_eq_sepadd_def' partial_le_part_left resource_ordering.antisym top_conj(1))
lemma strong_sepcoimp_imp_sepconj:
\<open>(P \<^emph> \<top>) \<sqinter> (P \<sim>\<^emph> Q) \<le> P \<^emph> Q\<close>
by (force simp add: sepconj_def sepcoimp_def precise_def le_fun_def)
lemma sepconj_pdisj_distrib_left: \<open>P \<^emph> (Q1 \<squnion> Q2) = P \<^emph> Q1 \<squnion> P \<^emph> Q2\<close>
by (force simp add: sepconj_def)
lemma sepcoimp_pconj_distrib_left:
\<open>P \<sim>\<^emph> (Q \<sqinter> Q') = (P \<sim>\<^emph> Q) \<sqinter> (P \<sim>\<^emph> Q')\<close>
by (force simp add: sepcoimp_def)
subsection \<open> Supported \<close>
definition supported :: \<open>('a \<Rightarrow> bool) \<Rightarrow> bool\<close> where
\<open>supported P \<equiv> \<forall>s. P s \<longrightarrow> (\<exists>hp. P hp \<and> hp \<preceq> s \<and> (\<forall>s'. hp \<preceq> s' \<longrightarrow> s' \<preceq> s \<longrightarrow> P s'))\<close>
lemma precise_to_supported:
\<open>precise P \<Longrightarrow> supported (P \<^emph> \<top>)\<close>
using resource_ordering.eq_iff supported_def by auto
end
section \<open> Multi-unit Separation Algebra \<close>
class multiunit_sep_alg = perm_alg +
fixes unitof :: \<open>'a \<Rightarrow> 'a\<close>
assumes unitof_disjoint[simp]: \<open>unitof a ## a\<close>
assumes unitof_is_unit[simp]: \<open>\<And>a b. unitof a ## b \<Longrightarrow> unitof a + b = b\<close>
begin
lemma le_iff_sepadd: \<open>a \<preceq> b \<longleftrightarrow> (\<exists>c. a ## c \<and> b = a + c)\<close>
by (metis disjoint_sym less_eq_sepadd_def' partial_add_commute unitof_disjoint unitof_is_unit)
lemma le_iff_part_of: \<open>a \<preceq> b \<longleftrightarrow> a \<lesssim> b\<close>
unfolding part_of_def le_iff_sepadd
by blast
lemma unitof_disjoint2[simp,intro!]: \<open>a ## unitof a\<close>
by (simp add: disjoint_sym)
lemma unitof_inherits_disjointness: \<open>a ## b \<Longrightarrow> unitof a ## b\<close>
by (metis disjoint_add_leftL unitof_disjoint unitof_is_unit)
lemma unitof_is_unit2[simp]: \<open>b ## unitof a \<Longrightarrow> unitof a + b = b\<close>
by (simp add: disjoint_sym_iff)
lemma unitof_is_unitR[simp]: \<open>unitof a ## b \<Longrightarrow> b + unitof a = b\<close>
using partial_add_commute unitof_is_unit by presburger
lemma unitof_is_unitR2[simp]: \<open>b ## unitof a \<Longrightarrow> b + unitof a = b\<close>
by (simp add: disjoint_sym_iff)
lemma unitof_idem[simp]: \<open>unitof (unitof a) = unitof a\<close>
by (metis unitof_disjoint unitof_is_unit unitof_is_unitR2)
lemma unitof_is_sepadd_unit: \<open>sepadd_unit (unitof a)\<close>
by (simp add: sepadd_unit_def unitof_inherits_disjointness)
subsection \<open>partial canonically_ordered_monoid_add lemmas\<close>
lemma unitof_le[simp]: \<open>unitof x \<preceq> x\<close>
using partial_le_plus unitof_disjoint
by fastforce
lemma le_unitof_eq[simp]: \<open>x \<preceq> unitof x \<longleftrightarrow> x = unitof x\<close>
by (auto intro: resource_ordering.antisym)
lemma not_less_unitof[simp]: \<open>\<not> x \<prec> unitof x\<close>
by (simp add: resource_order.leD)
lemma unitof_less_iff_neq_unitof: \<open>unitof x \<prec> x \<longleftrightarrow> x \<noteq> unitof x\<close>
by (metis resource_order.antisym_conv2 unitof_le)
lemma gr_unitofI: "(x = unitof x \<Longrightarrow> False) \<Longrightarrow> unitof x \<prec> x"
using unitof_less_iff_neq_unitof by blast
lemma not_gr_unitof[simp]: "\<not> unitof x \<prec> x \<longleftrightarrow> x = unitof x"
by (simp add: unitof_less_iff_neq_unitof)
lemma gr_implies_not_unitof: "z \<prec> x \<Longrightarrow> x \<noteq> unitof x"
by (metis le_unit_iff_eq resource_order.dual_order.strict_iff_not unitof_is_sepadd_unit)
lemma unitof_sepadd_unit:
\<open>sepadd_unit x \<Longrightarrow> unitof x = x\<close>
by (metis sepadd_unit_def unitof_disjoint2 unitof_is_unitR2)
lemma sepadd_eq_unitof_iff_both_eq_unitof[simp]:
\<open>x ## y \<Longrightarrow> x + y = unitof (x + y) \<longleftrightarrow> x = unitof x \<and> y = unitof y\<close>
by (metis add_sepadd_unit_add_iff_parts_sepadd_unit unitof_is_sepadd_unit unitof_sepadd_unit)
lemma unitof_eq_sepadd_iff_both_eq_unitof[simp]:
\<open>x ## y \<Longrightarrow> unitof (x + y) = x + y \<longleftrightarrow> x = unitof x \<and> y = unitof y\<close>
by (metis sepadd_eq_unitof_iff_both_eq_unitof)
lemma disjoint_same_unit:
\<open>a ## b \<Longrightarrow> unitof a = unitof b\<close>
by (metis disjoint_sym_iff unitof_inherits_disjointness unitof_is_unit2 unitof_is_unitR2)
lemma common_disjoint_same_unit:
\<open>a ## c \<Longrightarrow> b ## c \<Longrightarrow> unitof a = unitof b\<close>
by (metis disjoint_sym_iff unitof_inherits_disjointness unitof_is_unit2 unitof_is_unitR2)
lemmas unitof_order = unitof_le le_unitof_eq not_less_unitof unitof_less_iff_neq_unitof not_gr_unitof
subsection \<open> emp \<close>
text \<open> emp is not really useful until now, where every element has a unit. \<close>
lemma emp_sepconj_unit[simp]: \<open>emp \<^emph> P = P\<close>
apply (simp add: emp_def sepconj_def fun_eq_iff)
apply (metis sepadd_unit_left unitof_disjoint unitof_is_sepadd_unit)
done
lemma emp_sepconj_unit_right[simp]: \<open>P \<^emph> emp = P\<close>
using emp_sepconj_unit sepconj_comm by force
lemma secoimp_imp_sepconj:
\<open>P \<sqinter> (P \<sim>\<^emph> Q) \<le> P \<^emph> (Q \<sqinter> emp)\<close>
apply (simp add: sepcoimp_def sepconj_def le_fun_def emp_def)
apply (metis unitof_disjoint2 unitof_is_unitR2 unitof_is_sepadd_unit)
done
lemma not_coimp_emp:
\<open>\<not> sepadd_unit h \<Longrightarrow> (- (\<top> \<sim>\<^emph> emp)) h\<close>
by (simp add: sepcoimp_def emp_def sepadd_unit_def,
metis unitof_disjoint unitof_is_unit)
lemma supported_intuitionistic_to_precise:
\<open>supported P \<Longrightarrow> intuitionistic P \<Longrightarrow> precise (P \<sqinter> - (P \<^emph> (-emp)))\<close>
nitpick[card=4]
oops
end
section \<open> (Single Unit) Separation Algebra\<close>
class sep_alg = multiunit_sep_alg + zero +
assumes zero_disjoint[simp]: \<open>0 ## a\<close>
assumes zero_unit[simp]: \<open>0 + a = a\<close>
begin
lemma zero_disjointR[simp]: \<open>a ## 0\<close>
by (simp add: disjoint_sym)
lemma zero_unitR[simp]: \<open>a + 0 = a\<close>
using partial_add_commute zero_disjoint zero_unit
by presburger
lemma zero_least[iff]: \<open>0 \<preceq> b\<close>
using less_eq_sepadd_def'
by simp
sublocale order_bot \<open>0\<close> \<open>(\<preceq>)\<close> \<open>(\<prec>)\<close>
by standard
(metis zero_least)
lemma unitof_eq_zero[simp]: \<open>unitof x = 0\<close>
by (metis common_disjoint_same_unit disjoint_preservation le_unitof_eq unitof_disjoint
unitof_is_sepadd_unit unitof_sepadd_unit zero_least)
lemma zero_only_unit[simp]:
\<open>sepadd_unit x \<longleftrightarrow> x = 0\<close>
by (metis unitof_is_sepadd_unit unitof_sepadd_unit unitof_eq_zero)
subsection \<open>partial canonically_ordered_monoid_add lemmas\<close>
lemma zero_less_iff_neq_zero: "0 \<prec> n \<longleftrightarrow> n \<noteq> 0"
using bot_less by auto
lemma gr_zeroI: "(n = 0 \<Longrightarrow> False) \<Longrightarrow> 0 \<prec> n"
using zero_less_iff_neq_zero by auto
lemma not_gr_zero[simp]: "\<not> 0 \<prec> n \<longleftrightarrow> n = 0"
by (simp add: zero_less_iff_neq_zero)
lemma gr_implies_not_zero: \<open>m \<prec> n \<Longrightarrow> n \<noteq> 0\<close>
using not_less_bot by auto
lemma sepadd_eq_0_iff_both_eq_0[simp]: \<open>x ## y \<Longrightarrow> x + y = 0 \<longleftrightarrow> x = 0 \<and> y = 0\<close>
using sepadd_eq_unitof_iff_both_eq_unitof by auto
lemma zero_eq_sepadd_iff_both_eq_0[simp]: \<open>x ## y \<Longrightarrow> 0 = x + y \<longleftrightarrow> x = 0 \<and> y = 0\<close>
using sepadd_eq_0_iff_both_eq_0 by fastforce
lemmas zero_order = zero_le le_zero_eq not_less_zero zero_less_iff_neq_zero not_gr_zero
paragraph \<open> Separation Logic \<close>
lemma emp_apply:
\<open>emp x \<longleftrightarrow> x = 0\<close>
by (simp add: emp_def)
lemma not_coimp_emp0:
\<open>h \<noteq> 0 \<Longrightarrow> (- (\<top> \<sim>\<^emph> emp)) h\<close>
apply (clarsimp simp add: sepcoimp_def emp_def)
apply (rule_tac x=0 in exI, force)
done
end
section \<open> Duplicable closure \<close>
class dupcl_perm_alg = perm_alg +
assumes dup_sub_closure:
\<open>a ## b \<Longrightarrow> a + b = c \<Longrightarrow> c ## c \<Longrightarrow> c + c = c \<Longrightarrow> a + a = a\<close>
begin
text \<open>
Duplicable sub-closure ensures that all elements less than a duplicable element
are also duplicable.
\<close>
lemma dupp_sub_closureR: \<open>a ## b \<Longrightarrow> a + b = c \<Longrightarrow> c ## c \<Longrightarrow> c + c = c \<Longrightarrow> b + b = b\<close>
using disjoint_sym partial_add_commute dup_sub_closure by blast
text \<open> another form of dup_sub_closure \<close>
lemma sepadd_dup_antimono:
\<open>a \<preceq> b \<Longrightarrow> sepadd_dup b \<Longrightarrow> sepadd_dup a\<close>
apply (clarsimp simp add: sepadd_dup_def)
apply (rule conjI)
apply (force dest: common_subresource_selfsep)
apply (metis less_eq_sepadd_def part_of_def dup_sub_closure)
done
lemma sepadd_dup_plus_dupL:
\<open>a ## b \<Longrightarrow> sepadd_dup (a + b) \<Longrightarrow> sepadd_dup a\<close>
using partial_le_plus sepadd_dup_antimono by auto
lemma sepadd_dup_plus_dupR:
\<open>a ## b \<Longrightarrow> sepadd_dup (a + b) \<Longrightarrow> sepadd_dup b\<close>
using partial_le_plus2 sepadd_dup_antimono by auto
end
section \<open> Compatibility \<close>
context perm_alg
begin
definition compatible :: \<open>'a \<Rightarrow> 'a \<Rightarrow> bool\<close> where
\<open>compatible \<equiv> ((\<preceq>) \<squnion> (\<succeq>))\<^sup>*\<^sup>*\<close>
lemmas compatible_induct[consumes 1] =
rtranclp_induct[of \<open>(\<preceq>) \<squnion> (\<succeq>)\<close>, simplified compatible_def[symmetric], simplified]
lemmas converse_compatible_induct[consumes 1] =
converse_rtranclp_induct[of \<open>(\<preceq>) \<squnion> (\<succeq>)\<close>, simplified compatible_def[symmetric], simplified]
lemmas compatibleE =
rtranclE[of \<open>(\<preceq>) \<squnion> (\<succeq>)\<close>, simplified compatible_def[symmetric], simplified]
lemmas converse_compatibleE =
converse_rtranclpE[of \<open>(\<preceq>) \<squnion> (\<succeq>)\<close>, simplified compatible_def[symmetric], simplified]
lemmas compatible_trans[trans] =
rtranclp_trans[of \<open>(\<preceq>) \<squnion> (\<succeq>)\<close>, simplified compatible_def[symmetric], simplified]
lemma compatible_refl[intro!, simp]:
\<open>compatible a a\<close>
by (simp add: compatible_def)
lemma compatible_sym:
assumes \<open>compatible a b\<close>
shows \<open>compatible b a\<close>
proof -
have \<open>((\<preceq>) \<squnion> (\<succeq>))\<^sup>*\<^sup>* = (((\<preceq>) \<squnion> (\<succeq>))\<inverse>\<inverse>)\<^sup>*\<^sup>*\<close>
by (force intro!: arg_cong[of _ _ rtranclp])
also have \<open>... = ((\<preceq>) \<squnion> (\<succeq>))\<^sup>*\<^sup>*\<inverse>\<inverse>\<close>
by (simp add: rtranclp_conversep)
finally show ?thesis
by (metis assms compatible_def conversep_iff)
qed
lemma le_is_compatible[intro]:
\<open>a \<preceq> b \<Longrightarrow> compatible a b\<close>
by (simp add: compatible_def r_into_rtranclp)
lemma ge_is_compatible[intro]:
\<open>a \<succeq> b \<Longrightarrow> compatible a b\<close>
by (simp add: compatible_def r_into_rtranclp)
lemma trans_le_le_is_compatible[intro]:
\<open>a \<preceq> b \<Longrightarrow> b \<preceq> c \<Longrightarrow> compatible a c\<close>
using le_is_compatible by force
lemma trans_ge_ge_is_compatible[intro]:
\<open>b \<preceq> a \<Longrightarrow> c \<preceq> b \<Longrightarrow> compatible a c\<close>
using ge_is_compatible by force
lemma trans_ge_le_is_compatible[intro]:
\<open>b \<preceq> a \<Longrightarrow> b \<preceq> c \<Longrightarrow> compatible a c\<close>
using compatible_trans by blast
lemma trans_le_ge_is_compatible[intro]:
\<open>a \<preceq> b \<Longrightarrow> c \<preceq> b \<Longrightarrow> compatible a c\<close>
using compatible_trans by blast
subsection \<open> Relation to other relations \<close>
lemma disjoint_rtrancl_implies_compatible:
\<open>(##)\<^sup>*\<^sup>* x y \<Longrightarrow> compatible x y\<close>
apply (induct rule: rtranclp_induct)
apply force
apply (metis compatible_trans partial_le_plus partial_le_plus2 trans_le_ge_is_compatible)
done
lemma compatible_eq_strict_compatible:
\<open>(compatible :: 'a \<Rightarrow> 'a \<Rightarrow> bool) = ((\<prec>) \<squnion> (\<succ>))\<^sup>*\<^sup>*\<close>
proof -
have \<open>compatible = ((=) \<squnion> (\<prec>) \<squnion> (\<succ>))\<^sup>*\<^sup>*\<close>
by (force intro: arg_cong[of _ _ rtranclp]
simp add: compatible_def less_sepadd_def less_eq_sepadd_def)
also have \<open>... = ((\<prec>) \<squnion> (\<succ>))\<^sup>*\<^sup>*\<close>
by (metis inf_sup_aci(5) rtranclp_reflclp rtranclp_sup_rtranclp)
finally show ?thesis .
qed
lemma implies_compatible_then_rtranscl_implies_compatible:
\<open>\<forall>x y. r x y \<longrightarrow> compatible x y \<Longrightarrow> r\<^sup>*\<^sup>* x y \<Longrightarrow> compatible x y\<close>
using implies_rel_then_rtranscl_implies_rel[of r _ _ compatible]
compatible_trans
by blast
lemma implies_compatible_then_rtranscl_implies_compatible2:
\<open>r \<le> compatible \<Longrightarrow> r\<^sup>*\<^sup>* \<le> compatible\<close>
using implies_compatible_then_rtranscl_implies_compatible
by (simp add: le_fun_def)
subsection \<open> Relation to units \<close>
lemma step_compatible_units_identical:
\<open>compatible b z \<Longrightarrow> a \<preceq> b \<or> b \<preceq> a \<Longrightarrow> sepadd_unit a \<Longrightarrow> sepadd_unit z \<Longrightarrow> a = z\<close>