-
Notifications
You must be signed in to change notification settings - Fork 108
/
Deterministic_AI.thy
5283 lines (4853 loc) · 190 KB
/
Deterministic_AI.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
(*
* Copyright 2014, General Dynamics C4 Systems
*
* SPDX-License-Identifier: GPL-2.0-only
*)
theory Deterministic_AI
imports AInvs
begin
arch_requalify_facts
update_work_units_empty_fail
reset_work_units_empty_fail
set_domain_empty_fail
thread_set_domain_empty_fail
arch_post_cap_deletion_valid_list
lemmas [wp] =
update_work_units_empty_fail
reset_work_units_empty_fail
set_domain_empty_fail
thread_set_domain_empty_fail
declare dxo_wp_weak[wp del]
(** This theory shows that the cdt_list operations
correctly correspond to the existing cdt operations
and demonstrates their effect on the traversal order
of the tree. *)
(* An unspecified invariant is given from the state
extension's type class, which is assumed to hold over
all the capability operations. We show here that it
therefore holds over the whole kernel. This will
later be instantiated to valid_list. *)
(* a valid cdt_list for a node is a list that contains all of its children
(from the mdb) exactly once *)
(*Some nasty hackery to get around lack of polymorphic type class operations*)
lemma and_assoc: "(A and (B and C)) = (A and B and C)" (* FIXME: eliminate *)
by (simp add: pred_conj_aci)
lemma no_children_empty_desc:
"(\<forall>c. m c \<noteq> Some slot) = (descendants_of slot m = {})"
apply(rule iffI)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(intro allI notI)
apply(drule tranclD)
apply(simp)
apply(fastforce simp: descendants_of_def cdt_parent_defs)
done
lemma next_childD:
"\<lbrakk>next_child slot t = Some child; valid_list_2 t m\<rbrakk>
\<Longrightarrow> (\<exists>xs. t slot = child # xs) \<and> m child = Some slot"
apply(simp only: valid_list_2_def)
apply(erule conjE)
apply(erule_tac x=slot in allE)
apply(clarsimp simp: next_child_def valid_list_2_def)
apply(case_tac "t slot")
apply(simp)
apply(fastforce)
done
lemma next_child_NoneD:
notes split_paired_All[simp del]
shows "next_child slot t = None \<Longrightarrow> t slot = []"
apply(simp add: next_child_def)
apply(case_tac "t slot")
apply(simp)
apply(simp)
done
lemma next_child_None_empty_desc:
notes split_paired_All[simp del]
shows "valid_list_2 t m
\<Longrightarrow> (next_child slot t = None) = (descendants_of slot m = {})"
apply(simp add: valid_list_2_def)
apply(erule conjE)
apply(erule_tac x=slot in allE)
apply(clarsimp simp: next_child_def)
apply(case_tac "t slot")
apply(simp add: no_children_empty_desc)
apply(fastforce simp: descendants_of_def cdt_parent_defs)
done
lemma next_sibD:
"next_sib slot t m = Some child
\<Longrightarrow> (\<exists>p. m slot = Some p \<and> after_in_list (t p) slot = Some child)"
apply(clarsimp simp: next_sib_def)
apply(case_tac "m slot")
apply(simp)
apply(clarsimp)
done
lemma next_sib_NoneD:
"next_sib slot t m = None
\<Longrightarrow> m slot = None \<or> (\<exists>p. m slot = Some p \<and> after_in_list (t p) slot = None)"
apply(clarsimp simp: next_sib_def)
apply(case_tac "m slot")
apply(fastforce)+
done
lemma desc_not_parent:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"valid_mdb s \<Longrightarrow> slot \<notin> descendants_of slot (cdt s)"
apply(fastforce simp: valid_mdb_def no_mloop_def descendants_of_def cdt_parent_defs)
done
lemma next_childI:
"t slot = child # xs
\<Longrightarrow> next_child slot t = Some child"
by (simp add: next_child_def)
lemma next_childI':
"\<lbrakk>t slot = child # xs; x = Some child\<rbrakk>
\<Longrightarrow> next_child slot t = x"
by (simp add: next_child_def)
lemma next_sibI:
"\<lbrakk>m slot = Some p; after_in_list (t p) slot = Some sib\<rbrakk>
\<Longrightarrow> next_sib slot t m = Some sib"
by (simp add: next_sib_def)
lemma next_sibI':
"\<lbrakk>m slot = Some p; after_in_list (t p) slot = Some sib; x = Some sib\<rbrakk>
\<Longrightarrow> next_sib slot t m = x"
by (simp add: next_sib_def)
lemma next_child_NoneI:
"t slot = [] \<Longrightarrow> next_child slot t = None"
by (simp add: next_child_def)
lemma next_sib_NoneI:
"m slot = None \<or> (m slot = Some p \<and> after_in_list (t p) slot = None) \<Longrightarrow> next_sib slot t m = None"
by (fastforce simp: next_sib_def)
lemma not_child_not_sib:
"\<lbrakk>m slot = None; valid_list_2 t m\<rbrakk> \<Longrightarrow> next_sib p t m \<noteq> Some slot"
apply(simp add: next_sib_def)
apply(case_tac "m p")
apply(simp)
apply(simp)
apply(rule notI)
apply(simp only: valid_list_2_def)
apply(erule conjE)
apply(erule_tac x=a in allE)
apply(fastforce dest: after_in_list_in_list)
done
lemma not_child_no_sibs:
"m slot = None \<Longrightarrow> next_sib slot t m = None"
by (simp add: next_sib_def)
lemma descendants_linear:
"\<lbrakk>a \<in> descendants_of b m; a \<in> descendants_of c m; b \<noteq> c\<rbrakk>
\<Longrightarrow> b \<in> descendants_of c m \<or> c \<in> descendants_of b m"
apply(clarsimp)
apply(simp add: descendants_of_def cdt_parent_rel_def is_cdt_parent_def)
apply(induct b a rule: trancl.induct)
apply(simp)
apply(erule tranclE)
apply(simp)
apply(simp)
apply(simp)
apply(subgoal_tac "(c, b) \<in> {(p, c). m c = Some p}\<^sup>+")
apply(simp)
apply(subgoal_tac "b \<noteq> c")
apply(erule_tac a=c and b=ca in tranclE)
apply(simp)
apply(simp)
apply(fastforce)
done
lemma descendants_trans:
"\<lbrakk>a \<in> descendants_of b m; b \<in> descendants_of c m\<rbrakk> \<Longrightarrow> a \<in> descendants_of c m"
by (simp add: descendants_of_def)
definition finite_depth :: "cdt \<Rightarrow> bool" where
"finite_depth m \<equiv>
\<forall>slot. \<exists>p. (slot \<in> descendants_of p m \<or> p = slot) \<and> m p = None"
lemma sib_not_desc:
"\<lbrakk>no_mloop m; m x = Some p; m y = Some p\<rbrakk>
\<Longrightarrow> x \<notin> descendants_of y m"
apply(rule notI)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(drule tranclD2)
apply(elim conjE exE)
apply(simp)
apply(drule rtranclD)
apply(erule disjE)
apply(fastforce simp: no_mloop_def cdt_parent_defs)
apply(erule conjE)
apply(subgoal_tac "(z, z) \<in> {(p, c). m c = Some p}\<^sup>+")
prefer 2
apply(rule_tac b=y in trancl_into_trancl2)
apply(simp)
apply(simp)
apply(fastforce simp: no_mloop_def cdt_parent_defs)
done
lemma finite_depth:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows "valid_mdb s \<Longrightarrow> finite_depth (cdt s)"
apply(simp add: finite_depth_def)
apply(intro allI)
apply(subgoal_tac "{x. slot \<in> descendants_of x (cdt s)} \<subseteq> {x. cte_wp_at (\<lambda>_. True) x s}")
prefer 2
apply(fastforce simp: descendants_of_cte_at2)
apply(drule finite_subset)
apply(simp add: cte_wp_at_set_finite)
apply(case_tac "cdt s slot")
apply(fastforce)
apply(rule ccontr)
apply(simp)
apply(frule_tac f="\<lambda>x. THE y. cdt s x = Some y" in inj_on_iff_eq_card)
apply(subgoal_tac "inj_on (\<lambda>x. THE y. cdt s x = Some y) {x. slot \<in> descendants_of x (cdt s)}")
prefer 2
apply(simp(no_asm) add: inj_on_def)
apply(intro allI impI)
apply(rule ccontr)
apply(frule_tac b=x and c=y in descendants_linear)
apply(simp)
apply(simp)
apply(case_tac "cdt s x")
apply(fastforce)
apply(case_tac "cdt s y")
apply(fastforce)
apply(fastforce simp: valid_mdb_def sib_not_desc)
apply(simp)
apply(subgoal_tac "((\<lambda>x. THE y. cdt s x = Some y) ` {x. slot \<in> descendants_of x (cdt s)})
\<subset> {x. slot \<in> descendants_of x (cdt s)}")
prefer 2
apply(rule psubsetI)
apply(rule subsetI)
apply(simp)
apply(erule imageE)
apply(case_tac "cdt s xa")
apply(fastforce)
apply(rule_tac b=xa in descendants_trans)
apply(simp)
apply(fastforce simp: descendants_of_def cdt_parent_defs)
apply(rule_tac x=a in set_neqI[symmetric])
apply(fastforce simp: descendants_of_def cdt_parent_defs)
apply(rule notI)
apply(erule imageE)
apply(case_tac "cdt s x")
apply(fastforce)
apply(fastforce simp: sib_not_desc valid_mdb_def)
apply(drule psubset_card_mono)
apply(assumption)
apply(simp)
done
lemma cdt_power:
"\<lbrakk>\<forall>i. m (f i) = Some (f (Suc i)); (p, f 0) \<in> {(p, c). m c = Some p} ^^ n\<rbrakk>
\<Longrightarrow> p = f n"
apply(induct n arbitrary: p)
apply(simp)
apply (metis (lifting, full_types) mem_Collect_eq option.inject prod.simps(2) relpow_Suc_D2)
done
lemma wf_cdt_parent_rel:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"finite_depth m \<Longrightarrow> wf (cdt_parent_rel m)"
apply(subst wf_iff_no_infinite_down_chain)
apply(rule notI)
apply(clarsimp simp: finite_depth_def descendants_of_def cdt_parent_defs)
apply(erule_tac x="f 0" in allE)
apply(elim exE conjE)
apply(erule disjE)
apply(simp add: trancl_power)
apply(elim exE conjE)
apply(frule cdt_power)
apply(assumption)
apply(clarsimp)
apply(simp)
done
lemma cdt_induct:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>\<And>x. m x = None \<Longrightarrow> P x; \<And>x y. \<lbrakk>m x = Some y; P y\<rbrakk> \<Longrightarrow> P x; finite_depth m\<rbrakk>
\<Longrightarrow> P slot"
apply(induct_tac rule: wf_induct[where r="cdt_parent_rel m"])
apply(simp add: wf_cdt_parent_rel)
apply(simp add: cdt_parent_defs)
apply(case_tac "m x")
apply(simp)
apply(erule_tac x=a in allE)
apply(simp)
done
lemma next_not_child_domintros:
"(\<And>x. \<lbrakk>next_sib slot t m = None; m slot = Some x\<rbrakk>
\<Longrightarrow> next_not_child_dom (x, t, m))
\<Longrightarrow> next_not_child_dom (slot, t, m)"
apply(rule accpI)
apply(erule next_not_child_rel.cases)
apply(simp)
done
lemma next_not_child_termination:
"finite_depth m \<Longrightarrow> next_not_child_dom (slot, t, m)"
apply(induct_tac rule: cdt_induct[where m=m])
apply(rule next_not_child_domintros)
apply(simp)
apply(rule next_not_child_domintros)
apply(simp)
apply(simp)
done
lemma next_not_child_pinduct':
"\<lbrakk>next_not_child_dom (slot, t, m);
\<And>slot.
\<lbrakk>next_not_child_dom (slot, t, m);
\<And>a. \<lbrakk>next_sib slot t m = None; m slot = Some a\<rbrakk> \<Longrightarrow> P a t m\<rbrakk>
\<Longrightarrow> P slot t m\<rbrakk>
\<Longrightarrow> P slot t m"
apply(induct rule: next_not_child.pinduct)
apply(simp)
done
lemma next_not_child_pinduct:
"\<lbrakk>\<And>slot. \<lbrakk>\<And>a. \<lbrakk>next_sib slot t m = None; m slot = Some a\<rbrakk> \<Longrightarrow> P a\<rbrakk>
\<Longrightarrow> P slot; finite_depth m\<rbrakk>
\<Longrightarrow> P slot"
apply(rule_tac t=t and m=m in next_not_child_pinduct')
apply(rule next_not_child_termination)
apply(assumption)
apply(fastforce)
done
declare next_not_child.psimps[simp]
lemma next_not_child_pinduct2':
"\<lbrakk>next_not_child_dom (p, t, m);
\<And>a slot. \<lbrakk>next_sib a t m = None; m a = Some slot; P a\<rbrakk> \<Longrightarrow> P slot;
next_not_child p t m = Some n; P p;
\<forall>a slot. next_sib a t m = Some slot \<longrightarrow> P slot\<rbrakk>
\<Longrightarrow> P n"
apply(induct rule: next_not_child.pinduct)
apply(simp split: if_split_asm del: split_paired_All)
apply(case_tac "m slot")
apply simp
apply simp
done
lemma next_not_child_pinduct2:
"\<lbrakk>\<And>a slot. \<lbrakk>next_sib a t m = None; m a = Some slot; P a\<rbrakk> \<Longrightarrow> P slot;
next_not_child p t m = Some n; P p;
\<forall>a slot. next_sib a t m = Some slot \<longrightarrow> P slot; finite_depth m\<rbrakk>
\<Longrightarrow> P n"
by (rule next_not_child_pinduct2', simp_all add: next_not_child_termination)
lemma next_not_child_linearI:
notes split_paired_All[simp del] split_paired_Ex[simp del] if_weak_cong[cong]
assumes f_d: "finite_depth m" shows
"\<lbrakk>m p = m' p; next_sib p t m = next_sib p t' m';
\<forall>q. p \<in> descendants_of q m \<longrightarrow> m q = m' q
\<and> next_sib q t m = next_sib q t' m'; finite_depth m; finite_depth m'\<rbrakk>
\<Longrightarrow> next_not_child p t' m' = next_not_child p t m"
supply subst_all [simp del]
apply(induct rule: next_not_child_pinduct[where t=t and m=m])
apply(simp)
apply(case_tac "m slot")
apply(simp add: next_not_child_termination)
apply(case_tac "next_sib slot t m")
apply(simp add: next_not_child_termination)
apply(case_tac "m' slot")
apply(simp)
apply(simp)
apply(atomize)
apply(erule_tac x=aa in allE)
apply(simp split: if_split_asm)
apply(case_tac "m' aa")
apply(simp)
apply(simp add: next_not_child_termination)
apply(intro conjI impI)
apply(case_tac "m aa")
apply(simp)
apply(erule_tac x=aa in allE)
apply(erule impE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(simp)
apply(erule exE)
apply(erule_tac x=aa in allE)(* condense *)
apply(erule impE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(simp)
apply(simp)
apply(erule impE)
apply(erule_tac x=aa in allE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(erule impE)
apply(erule_tac x=aa in allE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(erule impE)
apply(intro allI impI)
apply(erule_tac x=q in allE)
apply(erule impE)
apply(simp add: cdt_parent_defs descendants_of_def)
apply(rule_tac b=aa in trancl_into_trancl)
apply(simp, simp)
apply(simp)
apply(erule_tac x= aa in allE)
apply(erule impE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(simp add: next_not_child_termination) (* condense *)
apply(erule_tac x=aa in allE)
apply(erule impE)
apply(fastforce simp: cdt_parent_defs descendants_of_def)
apply(simp add: next_not_child_termination)
apply(simp)
apply(fastforce simp: next_not_child_termination)
using f_d
apply(assumption)
done
lemma next_not_child_linearI':
notes split_paired_All[simp del] split_paired_Ex[simp del]
assumes f_d: "finite_depth m" shows
"\<lbrakk>finite_depth m'; m p = m' p; next_sib p t m = next_sib p t' m';
\<forall>q. p \<in> descendants_of q m \<longrightarrow> m q = m' q
\<and> (m q = m' q \<longrightarrow> next_sib q t m = next_sib q t' m')\<rbrakk>
\<Longrightarrow> next_not_child p t' m' = next_not_child p t m"
using f_d
apply (rule next_not_child_linearI,simp+)
done
lemma next_not_childI':
notes split_paired_All[simp del] split_paired_Ex[simp del]
assumes f_d: "finite_depth m" shows
"\<lbrakk>next_sib p t m = Some n \<or>
(next_sib p t m = None \<and>
(\<exists>q. next_sib q t m = Some n \<and> p \<in> descendants_of q m
\<and> (\<forall>q'. q' \<in> descendants_of q m \<and> p \<in> descendants_of q' m
\<longrightarrow> next_sib q' t m = None))); finite_depth m\<rbrakk>
\<Longrightarrow> next_not_child p t m = Some n"
apply(induct p rule: next_not_child_pinduct[where t=t and m=m])
apply(simp)
apply(erule disjE)
apply(simp add: next_not_child_termination)
apply(simp)
apply(elim conjE exE)
apply(subst next_not_child.psimps, simp add: next_not_child_termination)
apply(simp)
apply(case_tac "m slot")
apply(simp)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(drule tranclD2)
apply(fastforce)
apply(atomize)
apply(erule_tac x=a in allE)
apply(simp)
apply(case_tac "next_sib a t m")
apply(simp)
apply(case_tac "a=q")
apply(simp)
apply(erule impE)
apply(rule_tac x=q in exI)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(drule tranclD2)
apply(elim exE conjE, simp)
apply(drule rtranclD, simp)
apply(intro allI impI)
apply(erule_tac x=q' in allE)
apply(simp)
apply(elim impE conjE)
apply(drule_tac x=q' and y=z in tranclD2)
apply(elim exE conjE)
apply(simp)
apply(rule_tac b=z in trancl_into_trancl)
apply(rule_tac b=za in rtrancl_into_trancl1)
apply(simp)
apply(simp)
apply(simp)
apply(simp)
apply(simp)
apply(simp)
apply(case_tac "a=q")
apply(simp)
apply(erule_tac x=a in allE)
apply(erule_tac Q="next_sib a t m = None" in impE)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(rule conjI)
apply(drule tranclD2)
apply(elim conjE exE)
apply(simp)
apply(drule rtranclD)
apply(simp)
apply(fastforce)
apply(simp)
using f_d apply(simp)
done
lemma next_not_childI:
"\<lbrakk>next_sib p t m = Some n \<or>
(next_sib p t m = None \<and>
(\<exists>q. next_sib q t m = Some n \<and> p \<in> descendants_of q m
\<and> (\<forall>q'. q' \<in> descendants_of q m \<and> p \<in> descendants_of q' m
\<longrightarrow> next_sib q' t m = None))); finite_depth m\<rbrakk>
\<Longrightarrow> next_not_child p t m = Some n"
by(simp add: next_not_childI')
lemma next_not_child_NoneI':
notes split_paired_All[simp del] split_paired_Ex[simp del]
assumes f_d: "finite_depth m"
shows
"\<lbrakk>\<forall>q. p \<in> descendants_of q m \<longrightarrow> next_sib q t m = None;
next_sib p t m = None; finite_depth m\<rbrakk>
\<Longrightarrow> next_not_child p t m = None"
apply(induct p rule: next_not_child_pinduct[where t=t and m=m])
apply(simp)
apply(case_tac "m slot")
apply(simp add: next_not_child_termination)
apply(atomize)
apply(erule_tac x=a in allE)
apply(simp)
apply(erule impE)
apply(intro allI impI)
apply(erule_tac x=q in allE)
apply(erule impE)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(rule_tac b=a in trancl_into_trancl)
apply(simp)
apply(simp)
apply(simp)
apply(erule impE)
apply(erule_tac x=a in allE)
apply(erule impE)
apply(fastforce simp: descendants_of_def cdt_parent_defs)
apply(simp)
apply(subst next_not_child.psimps)
apply(simp add: next_not_child_termination)
apply(simp)
using f_d apply(simp)
done
lemma next_not_child_NoneI:
"\<lbrakk>\<forall>q. p \<in> descendants_of q m \<longrightarrow> next_sib q t m = None;
next_sib p t m = None; finite_depth m\<rbrakk>
\<Longrightarrow> next_not_child p t m = None"
by(simp add: next_not_child_NoneI')
lemma next_not_childD':
notes split_paired_All[simp del] split_paired_Ex[simp del]
assumes f_d: "finite_depth m" shows
"\<lbrakk>next_not_child p t m = Some n; finite_depth m; no_mloop m\<rbrakk>
\<Longrightarrow> next_sib p t m = Some n \<or>
(next_sib p t m = None \<and>
(\<exists>q. next_sib q t m = Some n \<and> p \<in> descendants_of q m
\<and> (\<forall>q'. q' \<in> descendants_of q m \<and> p \<in> descendants_of q' m
\<longrightarrow> next_sib q' t m = None)))"
apply(induct p rule: next_not_child_pinduct[where t=t and m=m])
apply(simp)
apply(case_tac "m slot")
apply(simp)
apply(rule disjCI)
apply(simp)
apply(erule disjE)
apply(erule exE, drule next_sibD)
apply(simp add: next_sib_def)
apply(simp add: next_not_child_termination split: if_split_asm)
apply(atomize)
apply(erule_tac x=a in allE)
apply(simp)
apply(case_tac "next_sib slot t m")
apply(simp)
apply(case_tac "next_not_child a t m = Some n")
apply(simp)
apply(erule disjE)
apply(rule_tac x=a in exI)
apply(simp)
apply(rule conjI)
apply(fastforce simp: descendants_of_def cdt_parent_defs)
apply(intro impI allI)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(erule conjE)
apply(drule_tac x=q' in tranclD2)
apply(elim exE conjE)
apply(simp)
apply(drule_tac b=q' and c=z in trancl_rtrancl_trancl)
apply(simp)
apply(simp add: no_mloop_def cdt_parent_defs)
apply(elim conjE exE)
apply(rule_tac x=q in exI)
apply(simp)
apply(rule conjI)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(rule_tac b=a in trancl_into_trancl)
apply(simp)
apply(simp)
apply(intro allI impI)
apply(case_tac "a=q'")
apply(simp)
apply(erule_tac x=q' in allE)
apply(erule impE)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(erule conjE)
apply(drule_tac y=slot in tranclD2)
apply(elim conjE exE)
apply(simp)
apply(drule rtranclD)
apply(simp)
apply(simp)
apply(simp add: next_not_child_termination)
apply(simp add: next_not_child_termination)
using f_d apply(simp)
done
lemma next_not_childD:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>next_not_child p t m = Some n; finite_depth m; no_mloop m\<rbrakk>
\<Longrightarrow> next_sib p t m = Some n \<or>
(next_sib p t m = None \<and>
(\<exists>q. next_sib q t m = Some n \<and> p \<in> descendants_of q m
\<and> (\<forall>q'. q' \<in> descendants_of q m \<and> p \<in> descendants_of q' m
\<longrightarrow> next_sib q' t m = None)))"
by (simp add: next_not_childD')
lemma next_not_child_NoneD':
notes split_paired_All[simp del] split_paired_Ex[simp del]
assumes f_d: "finite_depth m" shows
"\<lbrakk>next_not_child p t m = None; finite_depth m\<rbrakk>
\<Longrightarrow> (\<forall>q. p \<in> descendants_of q m \<longrightarrow> next_sib q t m = None) \<and>
next_sib p t m = None"
apply(induct p rule: next_not_child_pinduct[where t=t and m=m])
apply(subgoal_tac "next_sib slot t m = None")
prefer 2
apply(subst(asm)(2) next_not_child.psimps)
apply(simp add: next_not_child_termination)
apply(case_tac "next_sib slot t m")
apply(simp)
apply(simp)
apply(simp)
apply(intro allI impI)
apply(case_tac "m slot")
apply(subst(asm)(2) next_not_child.psimps)
apply(simp add: next_not_child_termination)
apply(case_tac "next_sib slot t m")
apply(simp add: descendants_of_def cdt_parent_defs)
apply(drule tranclD2)
apply(fastforce)
apply(simp)
apply(atomize)
apply(erule_tac x=a in allE)
apply(simp)
apply(erule impE)
apply(simp add: next_not_child_termination)
apply(case_tac "q=a")
apply(simp add: next_not_child_termination split: if_split_asm)
apply(erule conjE)
apply(erule_tac x=q in allE)
apply(erule impE)
apply(simp add: descendants_of_def cdt_parent_defs)
apply(drule tranclD2)
apply(elim conjE exE)
apply(simp)
apply(drule rtranclD)
apply(simp)
apply(simp)
using f_d apply(simp)
done
lemma next_not_child_NoneD:
"\<lbrakk>next_not_child p t m = None; finite_depth m\<rbrakk>
\<Longrightarrow> (\<forall>q. p \<in> descendants_of q m \<longrightarrow> next_sib q t m = None) \<and>
next_sib p t m = None"
by (simp add: next_not_child_NoneD')
lemma slot_in_one_list:
"\<lbrakk>c \<in> set (t p); c \<in> set (t p'); valid_list_2 t m\<rbrakk> \<Longrightarrow> p = p'"
by (simp only: valid_list_2_def, simp)
lemma next_sib_inj:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>next_sib a t m = Some y; next_sib b t m = Some y; valid_list_2 t m\<rbrakk>
\<Longrightarrow> a = b"
apply(drule next_sibD)+
apply(simp add: valid_list_2_def)
apply(elim exE conjE)
apply(frule_tac a=a in after_in_list_in_list)
apply(frule_tac a=b in after_in_list_in_list)
apply(rule_tac list="t pa" and x=y in after_in_list_inj)
apply(simp)
apply(simp)
apply(simp)
done
lemma no_mloop_descendants:
"no_mloop m = (\<forall>x. x \<notin> descendants_of x m)"
by (clarsimp simp: no_mloop_def descendants_of_def)
lemma no_mloop_descendants':
"no_mloop m \<Longrightarrow> x \<notin> descendants_of x m"
by (simp add: no_mloop_descendants del: split_paired_All)
lemma valid_list_2D:
notes split_paired_All[simp del]
shows
"valid_list_2 t m \<Longrightarrow> src \<in> set (t p) \<Longrightarrow> m src = Some p"
apply (simp add: valid_list_2_def)
done
lemma replace_parent_ignore:
notes split_paired_All[simp del]
shows
"valid_list_2 t m \<Longrightarrow> m src \<noteq> Some src_p \<Longrightarrow> (list_replace (t src_p) src dest) = (t src_p)"
apply (rule list_replace_ignore)
apply (clarsimp simp add: valid_list_2_def)
done
lemma after_in_list_not_parent:
notes split_paired_All[simp del]
shows
"valid_list_2 t m \<Longrightarrow> no_mloop m \<Longrightarrow> after_in_list (t x) z \<noteq> Some x"
apply (rule notI)
apply (frule(1) valid_list_2D[OF _ after_in_list_in_list])
apply (frule(1) no_mloop_neq,simp)
done
lemma ancestor_not_descendant:
notes split_paired_All[simp del]
shows
"no_mloop m \<Longrightarrow> src \<in> descendants_of src_p m \<Longrightarrow> src_p \<notin> descendants_of src m"
apply (rule notI)
apply (frule(1) descendants_trans)
apply (simp add: no_mloop_def descendants_of_def)
done
lemma child_descendant:
"m src = Some src_p \<Longrightarrow> src \<in> descendants_of src_p m"
apply (simp add: descendants_of_def cdt_parent_rel_def is_cdt_parent_def)
apply (rule r_into_trancl')
apply simp
done
lemmas parent_not_descendant = ancestor_not_descendant[OF _ child_descendant]
lemma next_sib_not_self:
notes split_paired_All[simp del]
shows
"valid_list_2 t m \<Longrightarrow> next_sib src t m \<noteq> Some src"
apply (rule notI)
apply (simp add: next_sib_def split: option.splits)
apply (subgoal_tac "distinct (t (the (m src)))")
apply (frule distinct_after_in_list_not_self[where src=src])
apply simp
apply (simp add: valid_list_2_def)
done
lemma next_sib_same_parent:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"valid_list_2 t m \<Longrightarrow> next_sib sib t m = Some me \<Longrightarrow> \<exists>p. m sib = Some p \<and> m me = Some p"
apply (simp add: next_sib_def split: option.splits)
apply (drule after_in_list_in_list)
apply (simp add: valid_list_2_def)
done
lemma next_not_child_not_self:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"valid_list_2 t m \<Longrightarrow> finite_depth m \<Longrightarrow> no_mloop m \<Longrightarrow> next_not_child src t m \<noteq> Some src"
apply (rule notI)
apply (drule next_not_childD,simp+)
apply (elim disjE)
apply (frule next_sib_not_self[where src=src],simp)
apply (elim conjE exE)
apply (frule_tac me=src and sib=q in next_sib_same_parent,assumption)
apply (elim exE conjE)
apply (subgoal_tac "src \<notin> descendants_of q m")
apply simp
apply (rule sib_not_desc,simp+)
done
lemma empty_list_empty_desc:
"valid_list_2 t m \<Longrightarrow> (t p = []) = (descendants_of p m = {})"
apply(drule_tac slot=p in next_child_None_empty_desc)
apply(simp add: next_child_def)
apply(case_tac "t p", simp+)
done
lemma after_in_list_not_self_helper:
"\<lbrakk>distinct list;
after_in_list list c = Some c;
(list, c) = (x # y # xs, a)\<rbrakk>
\<Longrightarrow> False"
apply (induct list arbitrary: x y xs a,simp)
apply atomize
apply (case_tac xs)
apply (case_tac "aa =x")
apply (case_tac "x = y",simp,simp)
apply (simp split: if_split_asm)+
done
lemma after_in_list_not_self:
"\<lbrakk>m c = Some p; valid_list_2 t m\<rbrakk> \<Longrightarrow> after_in_list (t p) c \<noteq> Some c"
apply (simp only: valid_list_2_def)
apply (erule conjE)
apply (drule_tac x = p in spec)+
apply (thin_tac "set (t p) = {c. m c = Some p}")
apply (rule notI)
apply (rule_tac x = "(t p, c)" in after_in_list.cases, simp, simp)
apply (blast intro: after_in_list_not_self_helper)
done
lemma not_sib_self:
"valid_list_2 t m \<Longrightarrow> next_sib slot t m \<noteq> Some slot"
by (case_tac "m slot", auto simp: next_sib_def after_in_list_not_self)
lemma next_not_child_eq_next_sib_None:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows "\<lbrakk>next_not_child p t m = next_not_child q t m; p \<in> descendants_of a m \<or> p = a;
a \<in> descendants_of q m; valid_list_2 t m; finite_depth m; no_mloop m\<rbrakk>
\<Longrightarrow> next_sib a t m = None"
apply(case_tac "next_not_child p t m")
apply(drule(1) next_not_child_NoneD)
apply(fastforce)
apply(case_tac "next_not_child q t m")
apply(simp)
apply(subgoal_tac "aa=aaa")
prefer 2
apply(simp)
apply(drule(2) next_not_childD)+
apply(erule_tac P="next_sib p t m = Some aa" in disjE)
apply(erule_tac P="next_sib q t m = Some aaa" in disjE)
apply(simp)
apply(drule(2) next_sib_inj)
apply(simp)
apply(erule disjE)
apply(drule_tac a=q and c=q in descendants_trans)
apply(simp)
apply(simp add: no_mloop_descendants)
apply(simp add: no_mloop_descendants)
apply(elim exE conjE)
apply(drule_tac a=p and b=qa in next_sib_inj)
apply(simp)
apply(simp)
apply(simp)
apply(erule disjE)
apply(drule_tac a=qa and c=q in descendants_trans, simp)
apply(drule_tac a=qa and c=qa in descendants_trans, simp)
apply(simp add: no_mloop_descendants)
apply(simp)
apply(drule_tac a=a and c=a in descendants_trans, simp)
apply(simp add: no_mloop_descendants)
apply(erule_tac P="next_sib q t m = Some aaa" in disjE)
apply(elim exE conjE, simp)
apply(drule(2) next_sib_inj, fastforce)
apply(elim exE conjE, simp)
apply(drule(2) next_sib_inj, simp)
apply(erule_tac x=a in allE)+
apply(erule disjE)
apply(simp)
apply(erule impE)
apply(rule_tac b=q in descendants_trans, simp+)
done
lemma remove_collect: "{y. P y} - {x} = {y. P y \<and> y \<noteq> x}"
apply blast
done
locale mdb_insert_abs_simple =
fixes m :: cdt
fixes t :: cdt_list
fixes dest :: cslot_ptr
assumes valid_list : "valid_list_2 t m"
locale mdb_insert_abs_simple_parent = mdb_insert_abs_simple +
fixes dest_p :: cslot_ptr
fixes t' :: cdt_list
defines "t' \<equiv> t(dest_p := list_remove (t dest_p) dest)"
assumes dest: "m dest = Some dest_p"
begin
lemma valid_list_post:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"
valid_list_2 (t'(src := dest # (t' src)))
(m(dest \<mapsto> src))"
apply (insert valid_list dest)
apply (simp add: valid_list_2_def t'_def)
apply (simp add: list_remove_removed insert_Collect remove_collect)
apply (intro impI conjI allI)
apply (fastforce simp: list_remove_distinct cong: Collect_cong)+
done
lemma valid_list_post':
"\<lbrakk> t' src = []\<rbrakk> \<Longrightarrow>
valid_list_2 (t'(src := [dest]))
(m(dest \<mapsto> src))"
by (insert valid_list_post[where src=src],simp)
end
locale mdb_insert_abs_simple_no_parent = mdb_insert_abs_simple +
assumes dest: "m dest = None"
context mdb_insert_abs_simple_no_parent
begin
lemma valid_list_post:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"valid_list_2 (t(src := dest # (t src)))
(m(dest \<mapsto> src))"
apply (insert valid_list dest)
apply (fastforce simp: valid_list_2_def)
done
lemma valid_list_post':
"\<lbrakk> t src = []\<rbrakk> \<Longrightarrow>
valid_list_2 (t(src := [dest]))
(m(dest \<mapsto> src))"
by (insert valid_list_post[where src=src],simp)
end
locale mdb_insert_abs_sib_simple_no_parent = mdb_insert_abs_simple_no_parent +
fixes src :: cslot_ptr
fixes n
defines "n \<equiv> m(dest := m src)"
assumes neq: "dest \<noteq> src"
begin
lemma valid_list_post_no_parent:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>m src = None\<rbrakk> \<Longrightarrow> valid_list_2 t n"
apply (insert valid_list dest)
apply (simp add: valid_list_2_def n_def)
done
lemma valid_list_post:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>m src = Some p\<rbrakk>
\<Longrightarrow> valid_list_2 (t(p := list_insert_after (t p) src dest)) n"
apply (insert valid_list dest neq)
apply (simp add: valid_list_2_def n_def)
apply (fastforce simp: distinct_list_insert_after set_list_insert_after)
done
end
locale mdb_insert_abs_sib_simple_parent = mdb_insert_abs_simple_parent +
fixes src :: cslot_ptr
fixes n
defines "n \<equiv> m(dest := m src)"
assumes neq: "dest \<noteq> src"
context mdb_insert_abs_sib_simple_parent
begin
lemma valid_list_post_no_parent:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>m src = None\<rbrakk> \<Longrightarrow> valid_list_2 t' n"
apply (insert valid_list dest)
apply (simp add: valid_list_2_def t'_def n_def)
apply (simp add: list_remove_removed insert_Collect remove_collect)
apply (fastforce simp: list_remove_distinct cong: Collect_cong)
done
lemma valid_list_post:
notes split_paired_All[simp del] split_paired_Ex[simp del]
shows
"\<lbrakk>m src = Some p\<rbrakk>
\<Longrightarrow> valid_list_2 (t'(p := list_insert_after (t' p) src dest)) n"
apply (insert valid_list dest neq)
apply (simp add: valid_list_2_def t'_def n_def)
apply (fastforce simp: distinct_list_insert_after list_remove_distinct set_list_insert_after list_remove_removed)
done
end