[7860bc]: thys / Collections / AnnotatedListGAPrioUniqueImpl.thy  Maximize  Restore  History

Download this file

1083 lines (1001 with data), 40.6 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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
header {*\isaheader{Implementing Unique Priority Queues by Annotated Lists}*}
theory AnnotatedListGAPrioUniqueImpl
imports
AnnotatedListSpec
PrioUniqueSpec
begin
text {*
In this theory we use annotated lists to implement unique priority queues
with totally ordered elements.
This theory is written as a generic adapter from the AnnotatedList interface
to the unique priority queue interface.
The annotated list stores a sequence of elements annotated with
priorities\footnote{Technically, the annotated list elements are of unit-type,
and the annotations hold both, the priority queue elements and the priorities.
This is required as we defined annotated lists to only sum up the elements
annotations.}
The monoids operations forms the maximum over the elements and
the minimum over the priorities.
The sequence of pairs is ordered by ascending elements' order.
The insertion point for a new element, or the priority of an existing element
can be found by splitting the
sequence at the point where the maximum of the elements read so far gets
bigger than the element to be inserted.
The minimum priority can be read out as the sum over the whole sequence.
Finding the element with minimum priority is done by splitting the sequence
at the point where the minimum priority of the elements read so far becomes
equal to the minimum priority of the whole sequence.
*}
subsection "Definitions"
subsubsection "Monoid"
datatype ('e, 'a) LP = Infty | LP 'e 'a
fun p_unwrap :: "('e,'a) LP \<Rightarrow> ('e \<times> 'a)" where
"p_unwrap (LP e a) = (e , a)"
fun p_min :: "('e::linorder, 'a::linorder) LP \<Rightarrow> ('e, 'a) LP \<Rightarrow> ('e, 'a) LP" where
"p_min Infty Infty = Infty"|
"p_min Infty (LP e a) = LP e a"|
"p_min (LP e a) Infty = LP e a"|
"p_min (LP e1 a) (LP e2 b) = (LP (max e1 e2) (min a b))"
fun e_less_eq :: "'e \<Rightarrow> ('e::linorder, 'a::linorder) LP \<Rightarrow> bool" where
"e_less_eq e Infty = False"|
"e_less_eq e (LP e' _) = (e \<le> e')"
text_raw{*\paragraph{Instantiation of classes}\ \\*}
lemma p_min_re_neut[simp]: "p_min a Infty = a" by (induct a) auto
lemma p_min_le_neut[simp]: "p_min Infty a = a" by (induct a) auto
lemma p_min_asso: "p_min (p_min a b) c = p_min a (p_min b c)"
apply(induct a b rule: p_min.induct )
apply (auto)
apply (induct c)
apply (auto)
apply (metis min_max.sup_assoc)
apply (metis min_max.inf_assoc)
done
lemma lp_mono: "class.monoid_add p_min Infty" by unfold_locales (auto simp add: p_min_asso)
instantiation LP :: (linorder,linorder) monoid_add
begin
definition zero_def: "0 == Infty"
definition plus_def: "a+b == p_min a b"
instance by
intro_classes
(auto simp add: p_min_asso zero_def plus_def)
end
fun p_less_eq :: "('e, 'a::linorder) LP \<Rightarrow> ('e, 'a) LP \<Rightarrow> bool" where
"p_less_eq (LP e a) (LP f b) = (a \<le> b)"|
"p_less_eq _ Infty = True"|
"p_less_eq Infty (LP e a) = False"
fun p_less :: "('e, 'a::linorder) LP \<Rightarrow> ('e, 'a) LP \<Rightarrow> bool" where
"p_less (LP e a) (LP f b) = (a < b)"|
"p_less (LP e a) Infty = True"|
"p_less Infty _ = False"
lemma p_less_le_not_le : "p_less x y \<longleftrightarrow> p_less_eq x y \<and> \<not> (p_less_eq y x)"
by (induct x y rule: p_less.induct) auto
lemma p_order_refl : "p_less_eq x x"
by (induct x) auto
lemma p_le_inf : "p_less_eq Infty x \<Longrightarrow> x = Infty"
by (induct x) auto
lemma p_order_trans : "\<lbrakk>p_less_eq x y; p_less_eq y z\<rbrakk> \<Longrightarrow> p_less_eq x z"
apply (induct y z rule: p_less.induct)
apply auto
apply (induct x)
apply auto
apply (cases x)
apply auto
apply(induct x)
apply (auto simp add: p_le_inf)
apply (metis p_le_inf p_less_eq.simps(2))
apply (metis p_le_inf p_less_eq.simps(2))
done
lemma p_linear2 : "p_less_eq x y \<or> p_less_eq y x"
apply (induct x y rule: p_less_eq.induct)
apply auto
done
instantiation LP :: (type, linorder) preorder
begin
definition plesseq_def: "less_eq = p_less_eq"
definition pless_def: "less = p_less"
instance
apply (intro_classes)
apply (simp only: p_less_le_not_le pless_def plesseq_def)
apply (simp only: p_order_refl plesseq_def pless_def)
apply (simp only: plesseq_def)
apply (metis p_order_trans)
done
end
subsubsection "Operations"
definition aluprio_\<alpha> :: "('s \<Rightarrow> (unit \<times> ('e::linorder,'a::linorder) LP) list)
\<Rightarrow> 's \<Rightarrow> ('e::linorder \<rightharpoonup> 'a::linorder)"
where
"aluprio_\<alpha> \<alpha> ft == (map_of (map p_unwrap (map snd (\<alpha> ft))))"
definition aluprio_invar :: "('s \<Rightarrow> (unit \<times> ('c::linorder, 'd::linorder) LP) list)
\<Rightarrow> ('s \<Rightarrow> bool) \<Rightarrow> 's \<Rightarrow> bool"
where
"aluprio_invar \<alpha> invar ft ==
invar ft
\<and> (\<forall> x\<in>set (\<alpha> ft). snd x\<noteq>Infty)
\<and> sorted (map fst (map p_unwrap (map snd (\<alpha> ft))))
\<and> distinct (map fst (map p_unwrap (map snd (\<alpha> ft)))) "
definition aluprio_empty where
"aluprio_empty empt = empt"
definition aluprio_isEmpty where
"aluprio_isEmpty isEmpty = isEmpty"
definition aluprio_insert ::
"((('e::linorder,'a::linorder) LP \<Rightarrow> bool)
\<Rightarrow> ('e,'a) LP \<Rightarrow> 's \<Rightarrow> ('s \<times> (unit \<times> ('e,'a) LP) \<times> 's))
\<Rightarrow> ('s \<Rightarrow> ('e,'a) LP)
\<Rightarrow> ('s \<Rightarrow> bool)
\<Rightarrow> ('s \<Rightarrow> 's \<Rightarrow> 's)
\<Rightarrow> ('s \<Rightarrow> unit \<Rightarrow> ('e,'a) LP \<Rightarrow> 's)
\<Rightarrow> 's \<Rightarrow> 'e \<Rightarrow> 'a \<Rightarrow> 's"
where
"
aluprio_insert splits annot isEmpty app consr s e a =
(if e_less_eq e (annot s) \<and> \<not> isEmpty s
then
(let (l, (_,lp) , r) = splits (e_less_eq e) Infty s in
(if e < fst (p_unwrap lp)
then
app (consr (consr l () (LP e a)) () lp) r
else
app (consr l () (LP e a)) r ))
else
consr s () (LP e a))
"
definition aluprio_pop :: "((('e::linorder,'a::linorder) LP \<Rightarrow> bool) \<Rightarrow> ('e,'a) LP
\<Rightarrow> 's \<Rightarrow> ('s \<times> (unit \<times> ('e,'a) LP) \<times> 's))
\<Rightarrow> ('s \<Rightarrow> ('e,'a) LP)
\<Rightarrow> ('s \<Rightarrow> 's \<Rightarrow> 's)
\<Rightarrow> 's
\<Rightarrow> 'e \<times>'a \<times>'s"
where
"aluprio_pop splits annot app s =
(let (l, (_,lp) , r) = splits (\<lambda> x. x \<le> (annot s)) Infty s
in
(case lp of
(LP e a) \<Rightarrow>
(e, a, app l r) ))"
definition aluprio_prio ::
"((('e::linorder,'a::linorder) LP \<Rightarrow> bool) \<Rightarrow> ('e,'a) LP \<Rightarrow> 's
\<Rightarrow> ('s \<times> (unit \<times> ('e,'a) LP) \<times> 's))
\<Rightarrow> ('s \<Rightarrow> ('e,'a) LP)
\<Rightarrow> ('s \<Rightarrow> bool)
\<Rightarrow> 's \<Rightarrow> 'e \<Rightarrow> 'a option"
where
"
aluprio_prio splits annot isEmpty s e =
(if e_less_eq e (annot s) \<and> \<not> isEmpty s
then
(let (l, (_,lp) , r) = splits (e_less_eq e) Infty s in
(if e = fst (p_unwrap lp)
then
Some (snd (p_unwrap lp))
else
None))
else
None)
"
lemmas aluprio_defs =
aluprio_invar_def
aluprio_\<alpha>_def
aluprio_empty_def
aluprio_isEmpty_def
aluprio_insert_def
aluprio_pop_def
aluprio_prio_def
subsection "Correctness"
subsubsection "Auxiliary Lemmas"
lemma p_linear: "(x::('e, 'a::linorder) LP) \<le> y \<or> y \<le> x"
by (unfold plesseq_def) (simp only: p_linear2)
lemma e_less_eq_mon1: "e_less_eq e x \<Longrightarrow> e_less_eq e (x + y)"
apply (cases x)
apply (auto simp add: plus_def)
apply (cases y)
apply (auto simp add: min_max.le_supI1)
done
lemma e_less_eq_mon2: "e_less_eq e y \<Longrightarrow> e_less_eq e (x + y)"
apply (cases x)
apply (auto simp add: plus_def)
apply (cases y)
apply (auto simp add: min_max.le_supI2)
done
lemmas e_less_eq_mon =
e_less_eq_mon1
e_less_eq_mon2
lemma p_less_eq_mon:
"(x::('e::linorder,'a::linorder) LP) \<le> z \<Longrightarrow> (x + y) \<le> z"
apply(cases y)
apply(auto simp add: plus_def)
apply (cases x)
apply (cases z)
apply (auto simp add: plesseq_def)
apply (cases z)
apply (auto simp add: min_max.le_infI1)
done
lemma p_less_eq_lem1:
"\<lbrakk>\<not> (x::('e::linorder,'a::linorder) LP) \<le> z;
(x + y) \<le> z\<rbrakk>
\<Longrightarrow> y \<le> z "
apply (cases x,auto simp add: plus_def)
apply (cases y, auto)
apply (cases z, auto simp add: plesseq_def)
apply (metis min_le_iff_disj)
done
lemma infadd: "x \<noteq> Infty \<Longrightarrow>x + y \<noteq> Infty"
apply (unfold plus_def)
apply (induct x y rule: p_min.induct)
apply auto
done
lemma e_less_eq_listsum:
"\<lbrakk>\<not> e_less_eq e (listsum xs)\<rbrakk> \<Longrightarrow> \<forall>x \<in> set xs. \<not> e_less_eq e x"
proof (induct xs)
case Nil thus ?case by simp
next
case (Cons a xs)
hence "\<not> e_less_eq e (listsum xs)" by (auto simp add: e_less_eq_mon)
hence v1: "\<forall>x\<in>set xs. \<not> e_less_eq e x" using Cons.hyps by simp
from Cons.prems have "\<not> e_less_eq e a" by (auto simp add: e_less_eq_mon)
with v1 show "\<forall>x\<in>set (a#xs). \<not> e_less_eq e x" by simp
qed
lemma e_less_eq_p_unwrap:
"\<lbrakk>x \<noteq> Infty;\<not> e_less_eq e x\<rbrakk> \<Longrightarrow> fst (p_unwrap x) < e"
by (cases x) auto
lemma e_less_eq_refl :
"b \<noteq> Infty \<Longrightarrow> e_less_eq (fst (p_unwrap b)) b"
by (cases b) auto
lemma e_less_eq_listsum2:
assumes
"\<forall>x\<in>set (\<alpha>s). snd x \<noteq> Infty"
"((), b) \<in> set (\<alpha>s)"
shows "e_less_eq (fst (p_unwrap b)) (listsum (map snd (\<alpha>s)))"
apply(insert assms)
apply (induct "\<alpha>s")
apply (auto simp add: zero_def e_less_eq_mon e_less_eq_refl)
done
lemma e_less_eq_lem1:
"\<lbrakk>\<not> e_less_eq e a;e_less_eq e (a + b)\<rbrakk> \<Longrightarrow> e_less_eq e b"
apply (auto simp add: plus_def)
apply (cases a)
apply auto
apply (cases b)
apply auto
apply (metis le_max_iff_disj)
done
lemma p_unwrap_less_sum: "snd (p_unwrap ((LP e aa) + b)) \<le> aa"
apply (cases b)
apply (auto simp add: plus_def)
done
lemma listsum_less_elems: "\<forall>x\<in>set xs. snd x \<noteq> Infty \<Longrightarrow>
\<forall>y\<in>set (map snd (map p_unwrap (map snd xs))).
snd (p_unwrap (listsum (map snd xs))) \<le> y"
proof (induct xs)
case Nil thus ?case by simp
next
case (Cons a as) thus ?case
apply auto
apply (cases "(snd a)" rule: p_unwrap.cases)
apply auto
apply (cases "listsum (map snd as)")
apply auto
apply (metis linorder_linear p_min_re_neut p_unwrap.simps plus_def_raw snd_eqD)
apply (auto simp add: p_unwrap_less_sum)
apply (unfold plus_def)
apply (cases "(snd a, listsum (map snd as))" rule: p_min.cases)
apply auto
apply (cases "map snd as")
apply (auto simp add: infadd)
apply (metis min_max.le_infI2 snd_conv)
done
qed
lemma distinct_sortet_list_app:
"\<lbrakk>sorted xs; distinct xs; xs = as @ b # cs\<rbrakk>
\<Longrightarrow> \<forall> x\<in> set cs. b < x"
by (metis distinct.simps(2) distinct_append
linorder_antisym_conv2 mem_def sorted_Cons sorted_append)
lemma distinct_sorted_list_lem1:
assumes
"sorted xs"
"sorted ys"
"distinct xs"
"distinct ys"
" \<forall> x \<in> set xs. x < e"
" \<forall> y \<in> set ys. e < y"
shows
"sorted (xs @ e # ys)"
"distinct (xs @ e # ys)"
proof -
from assms (5,6)
have "\<forall>x\<in>set xs. \<forall>y\<in>set ys. x \<le> y" by force
thus "sorted (xs @ e # ys)"
using assms
by (auto simp add: sorted_append sorted_Cons)
have "set xs \<inter> set ys = {}" using assms (5,6) by force
thus "distinct (xs @ e # ys)"
using assms
by (auto simp add: distinct_append)
qed
lemma distinct_sorted_list_lem2:
assumes
"sorted xs"
"sorted ys"
"distinct xs"
"distinct ys"
"e < e'"
" \<forall> x \<in> set xs. x < e"
" \<forall> y \<in> set ys. e' < y"
shows
"sorted (xs @ e # e' # ys)"
"distinct (xs @ e # e' # ys)"
proof -
have "sorted (e' # ys)"
"distinct (e' # ys)"
"\<forall> y \<in> set (e' # ys). e < y"
using assms(2,4,5,7)
by (auto simp add: sorted_Cons)
thus "sorted (xs @ e # e' # ys)"
"distinct (xs @ e # e' # ys)"
using assms(1,3,6) distinct_sorted_list_lem1[of xs "e' # ys" e]
by auto
qed
lemma map_of_distinct_upd:
"x \<notin> set (map fst xs) \<Longrightarrow> [x \<mapsto> y] ++ map_of xs = (map_of xs) (x \<mapsto> y)"
by (induct xs) (auto simp add: fun_upd_twist)
lemma map_of_distinct_upd2:
assumes "x \<notin> set(map fst xs)"
"x \<notin> set (map fst ys)"
shows "map_of (xs @ (x,y) # ys) = (map_of (xs @ ys))(x \<mapsto> y)"
apply(insert assms)
apply(induct xs)
apply (auto intro: ext)
done
lemma map_of_distinct_upd3:
assumes "x \<notin> set(map fst xs)"
"x \<notin> set (map fst ys)"
shows "map_of (xs @ (x,y) # ys) = (map_of (xs @ (x,y') # ys))(x \<mapsto> y)"
apply(insert assms)
apply(induct xs)
apply (auto intro: ext)
done
lemma map_of_distinct_upd4:
assumes "x \<notin> set(map fst xs)"
"x \<notin> set (map fst ys)"
shows "map_of (xs @ ys) = (map_of (xs @ (x,y) # ys))(x := None)"
apply(insert assms)
apply(induct xs)
apply (auto simp add: map_of_eq_None_iff intro: ext)
done
lemma map_of_distinct_lookup:
assumes "x \<notin> set(map fst xs)"
"x \<notin> set (map fst ys)"
shows "map_of (xs @ (x,y) # ys) x = Some y"
proof -
have "map_of (xs @ (x,y) # ys) = (map_of (xs @ ys)) (x \<mapsto> y)"
using assms map_of_distinct_upd2 by simp
thus ?thesis
by simp
qed
lemma ran_distinct:
assumes dist: "distinct (map fst al)"
shows "ran (map_of al) = snd ` set al"
using assms proof (induct al)
case Nil then show ?case by simp
next
case (Cons kv al)
then have "ran (map_of al) = snd ` set al" by simp
moreover from Cons.prems have "map_of al (fst kv) = None"
by (simp add: map_of_eq_None_iff)
ultimately show ?case by (simp only: map_of.simps ran_map_upd) simp
qed
subsubsection "Finite"
lemma aluprio_finite_correct: "uprio_finite (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar)"
by(unfold_locales) (simp add: aluprio_defs finite_dom_map_of)
subsubsection "Empty"
lemma aluprio_empty_correct:
assumes "al_empty \<alpha> invar empt"
shows "uprio_empty (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar) (aluprio_empty empt)"
proof -
interpret al_empty \<alpha> invar empt by fact
show ?thesis
apply (unfold_locales)
apply (auto simp add: empty_correct aluprio_defs)
done
qed
subsubsection "Is Empty"
lemma aluprio_isEmpty_correct:
assumes "al_isEmpty \<alpha> invar isEmpty"
shows "uprio_isEmpty (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar) (aluprio_isEmpty isEmpty)"
proof -
interpret al_isEmpty \<alpha> invar isEmpty by fact
show ?thesis
apply (unfold_locales)
apply (auto simp add: aluprio_defs isEmpty_correct)
apply (metis Nil_is_map_conv hd_in_set length_map length_remove1
length_sort map_eq_imp_length_eq map_fst_zip map_map map_of.simps(1)
map_of_eq_None_iff remove1.simps(1) set_map)
done
qed
subsubsection "Insert"
lemma annot_inf:
assumes A: "invar s" "\<forall>x\<in>set (\<alpha> s). snd x \<noteq> Infty" "al_annot \<alpha> invar annot"
shows "annot s = Infty \<longleftrightarrow> \<alpha> s = [] "
proof -
from A have invs: "invar s" by (simp add: aluprio_defs)
interpret al_annot \<alpha> invar annot by fact
show "annot s = Infty \<longleftrightarrow> \<alpha> s = []"
proof (cases "\<alpha> s = []")
case True
hence "map snd (\<alpha> s) = []" by simp
hence "listsum (map snd (\<alpha> s)) = Infty"
by (auto simp add: zero_def)
with invs have "annot s = Infty" by (auto simp add: annot_correct)
with True show ?thesis by simp
next
case False
hence " \<exists>x xs. (\<alpha> s) = x # xs" by (cases "\<alpha> s") auto
from this obtain x xs where [simp]: "(\<alpha> s) = x # xs" by blast
from this assms(2) have "snd x \<noteq> Infty" by (auto simp add: aluprio_defs)
hence "listsum (map snd (\<alpha> s)) \<noteq> Infty" by (auto simp add: infadd)
thus ?thesis using annot_correct invs False by simp
qed
qed
lemma e_less_eq_annot:
assumes "al_annot \<alpha> invar annot"
"invar s" "\<forall>x\<in>set (\<alpha> s). snd x \<noteq> Infty" "\<not> e_less_eq e (annot s)"
shows "\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> s)). x < e"
proof -
interpret al_annot \<alpha> invar annot by fact
from assms(2) have "annot s = listsum (map snd (\<alpha> s))"
by (auto simp add: annot_correct)
with assms(4) have
"\<forall>x \<in> set (map snd (\<alpha> s)). \<not> e_less_eq e x"
by (metis e_less_eq_listsum)
with assms(3)
show ?thesis
by (auto simp add: e_less_eq_p_unwrap)
qed
lemma aluprio_insert_correct:
assumes
"al_splits \<alpha> invar splits"
"al_annot \<alpha> invar annot"
"al_isEmpty \<alpha> invar isEmpty"
"al_app \<alpha> invar app"
"al_consr \<alpha> invar consr"
shows
"uprio_insert (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar)
(aluprio_insert splits annot isEmpty app consr)"
proof -
interpret al_splits \<alpha> invar splits by fact
interpret al_annot \<alpha> invar annot by fact
interpret al_isEmpty \<alpha> invar isEmpty by fact
interpret al_app \<alpha> invar app by fact
interpret al_consr \<alpha> invar consr by fact
show ?thesis
proof (unfold_locales,unfold aluprio_defs)
case goal1 note g1asms = this
thus ?case proof (cases "e_less_eq e (annot s) \<and> \<not> isEmpty s")
case False with g1asms show ?thesis
apply (auto simp add: consr_correct )
proof -
case goal1
with assms(2) have
"\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> s)). x < e"
by (simp add: e_less_eq_annot)
with goal1(3) show ?case
by(auto simp add: sorted_append)
next
case goal2
hence "annot s = listsum (map snd (\<alpha> s))"
by (simp add: annot_correct)
with goal2
show ?case
by (auto simp add: e_less_eq_listsum2)
next
case goal3
hence "\<alpha> s = []" by (auto simp add: isEmpty_correct)
thus ?case by simp
next
case goal4
hence "\<alpha> s = []" by (auto simp add: isEmpty_correct)
with goal4(6) show ?case by simp
qed
next
case True note T1 = this
obtain l uu lp r where
l_lp_r: "(splits (e_less_eq e) Infty s) = (l, ((), lp), r) "
by (cases "splits (e_less_eq e) Infty s", auto)
note v2 = splits_correct[of s "e_less_eq e" Infty l "()" lp r]
have
v3: "invar s"
"\<not> e_less_eq e Infty"
"e_less_eq e (Infty + listsum (map snd (\<alpha> s)))"
using T1 g1asms annot_correct
by (auto simp add: plus_def)
have
v4: "\<alpha> s = \<alpha> l @ ((), lp) # \<alpha> r"
"\<not> e_less_eq e (Infty + listsum (map snd (\<alpha> l)))"
"e_less_eq e (Infty + listsum (map snd (\<alpha> l)) + lp)"
"invar l"
"invar r"
using v2[OF v3(1) _ v3(2) v3(3) l_lp_r] e_less_eq_mon(1) by auto
hence v5: "e_less_eq e lp"
by (metis e_less_eq_lem1)
hence v6: "e \<le> (fst (p_unwrap lp))"
by (cases lp) auto
have "(Infty + listsum (map snd (\<alpha> l))) = (annot l)"
by (metis add_0_left annot_correct v4(4) zero_def)
hence v7:"\<not> e_less_eq e (annot l)"
using v4(2) by simp
have "\<forall>x\<in>set (\<alpha> l). snd x \<noteq> Infty"
using g1asms v4(1) by simp
hence v7: "\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> l)). x < e"
using v4(4) v7 assms(2)
by(simp add: e_less_eq_annot)
have v8:"map fst (map p_unwrap (map snd (\<alpha> s))) =
map fst (map p_unwrap (map snd (\<alpha> l))) @ fst(p_unwrap lp) #
map fst (map p_unwrap (map snd (\<alpha> r)))"
using v4(1)
by simp
note distinct_sortet_list_app[of "map fst (map p_unwrap (map snd (\<alpha> s)))"
"map fst (map p_unwrap (map snd (\<alpha> l)))" "fst(p_unwrap lp)"
"map fst (map p_unwrap (map snd (\<alpha> r)))"]
hence v9:
"\<forall> x\<in>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> r)). fst(p_unwrap lp) < x"
using v4(1) g1asms v8
by auto
have v10:
"sorted (map fst (map p_unwrap (map snd (\<alpha> l))))"
"distinct (map fst (map p_unwrap (map snd (\<alpha> l))))"
"sorted (map fst (map p_unwrap (map snd (\<alpha> r))))"
"distinct (map fst (map p_unwrap (map snd (\<alpha> l))))"
using g1asms v8
by (auto simp add: sorted_append sorted_Cons)
from l_lp_r T1 g1asms show ?thesis
proof (fold aluprio_insert_def, cases "e < fst (p_unwrap lp)")
case True
hence v11:
"aluprio_insert splits annot isEmpty app consr s e a
= app (consr (consr l () (LP e a)) () lp) r"
using l_lp_r T1
by (auto simp add: aluprio_defs)
have v12: "invar (app (consr (consr l () (LP e a)) () lp) r)"
using v4(4,5)
by (auto simp add: app_correct consr_correct)
have v13:
"\<alpha> (app (consr (consr l () (LP e a)) () lp) r)
= \<alpha> l @ ((),(LP e a)) # ((), lp) # \<alpha> r"
using v4(4,5) by (auto simp add: app_correct consr_correct)
hence v14:
"(\<forall>x\<in>set (\<alpha> (app (consr (consr l () (LP e a)) () lp) r)).
snd x \<noteq> Infty)"
using g1asms v4(1)
by auto
have v15: "e = fst(p_unwrap (LP e a))" by simp
hence v16:
"sorted (map fst (map p_unwrap
(map snd (\<alpha> l @ ((),(LP e a)) # ((), lp) # \<alpha> r))))"
"distinct (map fst (map p_unwrap
(map snd (\<alpha> l @ ((),(LP e a)) # ((), lp) # \<alpha> r))))"
using v10(1,3) v7 True v9 v4(1) g1asms distinct_sorted_list_lem2
by (auto simp add: sorted_append sorted_Cons)
thus "invar (aluprio_insert splits annot isEmpty app consr s e a) \<and>
(\<forall>x\<in>set (\<alpha> (aluprio_insert splits annot isEmpty app consr s e a)).
snd x \<noteq> Infty) \<and>
sorted (map fst (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a))))) \<and>
distinct (map fst (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a)))))"
using v11 v12 v13 v14
by simp
next
case False
hence v11:
"aluprio_insert splits annot isEmpty app consr s e a
= app (consr l () (LP e a)) r"
using l_lp_r T1
by (auto simp add: aluprio_defs)
have v12: "invar (app (consr l () (LP e a)) r)" using v4(4,5)
by (auto simp add: app_correct consr_correct)
have v13: "\<alpha> (app (consr l () (LP e a)) r) = \<alpha> l @ ((),(LP e a)) # \<alpha> r"
using v4(4,5) by (auto simp add: app_correct consr_correct)
hence v14: "(\<forall>x\<in>set (\<alpha> (app (consr l () (LP e a)) r)). snd x \<noteq> Infty)"
using g1asms v4(1)
by auto
have v15: "e = fst(p_unwrap (LP e a))" by simp
have v16: "e = fst(p_unwrap lp)"
using False v5 by (cases lp) auto
hence v17:
"sorted (map fst (map p_unwrap
(map snd (\<alpha> l @ ((),(LP e a)) # \<alpha> r))))"
"distinct (map fst (map p_unwrap
(map snd (\<alpha> l @ ((),(LP e a)) # \<alpha> r))))"
using v16 v15 v10(1,3) v7 True v9 v4(1)
g1asms distinct_sorted_list_lem1
by (auto simp add: sorted_append sorted_Cons)
thus "invar (aluprio_insert splits annot isEmpty app consr s e a) \<and>
(\<forall>x\<in>set (\<alpha> (aluprio_insert splits annot isEmpty app consr s e a)).
snd x \<noteq> Infty) \<and>
sorted (map fst (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a))))) \<and>
distinct (map fst (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a)))))"
using v11 v12 v13 v14
by simp
qed
qed
next
case goal2 note g1asms = this
thus ?case proof (cases "e_less_eq e (annot s) \<and> \<not> isEmpty s")
case False with g1asms show ?thesis
apply (auto simp add: consr_correct)
proof -
case goal1
with assms(2) have
"\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> s)). x < e"
by (simp add: e_less_eq_annot)
hence "e \<notin> set (map fst ((map (p_unwrap \<circ> snd)) (\<alpha> s)))"
by auto
thus ?case
by (auto simp add: map_of_distinct_upd)
next
case goal2
hence "\<alpha> s = []" by (auto simp add: isEmpty_correct)
thus ?case
by simp
qed
next
case True note T1 = this
obtain l uu lp r where
l_lp_r: "(splits (e_less_eq e) Infty s) = (l, ((), lp), r) "
by (cases "splits (e_less_eq e) Infty s", auto)
note v2 = splits_correct[of s "e_less_eq e" Infty l "()" lp r]
have
v3: "invar s"
"\<not> e_less_eq e Infty"
"e_less_eq e (Infty + listsum (map snd (\<alpha> s)))"
using T1 g1asms annot_correct
by (auto simp add: plus_def)
have
v4: "\<alpha> s = \<alpha> l @ ((), lp) # \<alpha> r"
"\<not> e_less_eq e (Infty + listsum (map snd (\<alpha> l)))"
"e_less_eq e (Infty + listsum (map snd (\<alpha> l)) + lp)"
"invar l"
"invar r"
using v2[OF v3(1) _ v3(2) v3(3) l_lp_r] e_less_eq_mon(1) by auto
hence v5: "e_less_eq e lp"
by (metis e_less_eq_lem1)
hence v6: "e \<le> (fst (p_unwrap lp))"
by (cases lp) auto
have "(Infty + listsum (map snd (\<alpha> l))) = (annot l)"
by (metis add_0_left annot_correct v4(4) zero_def)
hence v7:"\<not> e_less_eq e (annot l)"
using v4(2) by simp
have "\<forall>x\<in>set (\<alpha> l). snd x \<noteq> Infty"
using g1asms v4(1) by simp
hence v7: "\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> l)). x < e"
using v4(4) v7 assms(2)
by(simp add: e_less_eq_annot)
have v8:"map fst (map p_unwrap (map snd (\<alpha> s))) =
map fst (map p_unwrap (map snd (\<alpha> l))) @ fst(p_unwrap lp) #
map fst (map p_unwrap (map snd (\<alpha> r)))"
using v4(1)
by simp
note distinct_sortet_list_app[of "map fst (map p_unwrap (map snd (\<alpha> s)))"
"map fst (map p_unwrap (map snd (\<alpha> l)))" "fst(p_unwrap lp)"
"map fst (map p_unwrap (map snd (\<alpha> r)))"]
hence v9: "
\<forall> x\<in>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> r)). fst(p_unwrap lp) < x"
using v4(1) g1asms v8
by auto
hence v10: " \<forall> x\<in>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> r)). e < x"
using v6 by auto
have v11:
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> l))))"
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> r))))"
using v7 v10 v8 g1asms
by auto
from l_lp_r T1 g1asms show ?thesis
proof (fold aluprio_insert_def, cases "e < fst (p_unwrap lp)")
case True
hence v12:
"aluprio_insert splits annot isEmpty app consr s e a
= app (consr (consr l () (LP e a)) () lp) r"
using l_lp_r T1
by (auto simp add: aluprio_defs)
have v13:
"\<alpha> (app (consr (consr l () (LP e a)) () lp) r)
= \<alpha> l @ ((),(LP e a)) # ((), lp) # \<alpha> r"
using v4(4,5) by (auto simp add: app_correct consr_correct)
have v14: "e = fst(p_unwrap (LP e a))" by simp
have v15: "e \<notin> set (map fst (map p_unwrap (map snd(((),lp)#\<alpha> r))))"
using v11(2) True by auto
note map_of_distinct_upd2[OF v11(1) v15]
thus
"map_of (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a))))
= map_of (map p_unwrap (map snd (\<alpha> s)))(e \<mapsto> a)"
using v12 v13 v4(1)
by simp
next
case False
hence v12:
"aluprio_insert splits annot isEmpty app consr s e a
= app (consr l () (LP e a)) r"
using l_lp_r T1
by (auto simp add: aluprio_defs)
have v13:
"\<alpha> (app (consr l () (LP e a)) r) = \<alpha> l @ ((),(LP e a)) # \<alpha> r"
using v4(4,5) by (auto simp add: app_correct consr_correct)
have v14: "e = fst(p_unwrap lp)"
using False v5 by (cases lp) auto
note v15 = map_of_distinct_upd3[OF v11(1) v11(2)]
have v16:"(map p_unwrap (map snd (\<alpha> s))) =
(map p_unwrap (map snd (\<alpha> l))) @ (e,snd(p_unwrap lp)) #
(map p_unwrap (map snd (\<alpha> r)))"
using v4(1) v14
by simp
note v15[of a "snd(p_unwrap lp)"]
thus
"map_of (map p_unwrap (map snd (\<alpha>
(aluprio_insert splits annot isEmpty app consr s e a))))
= map_of (map p_unwrap (map snd (\<alpha> s)))(e \<mapsto> a)"
using v12 v13 v16
by simp
qed
qed
qed
qed
subsubsection "Prio"
lemma aluprio_prio_correct:
assumes
"al_splits \<alpha> invar splits"
"al_annot \<alpha> invar annot"
"al_isEmpty \<alpha> invar isEmpty"
shows
"uprio_prio (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar) (aluprio_prio splits annot isEmpty)"
proof -
interpret al_splits \<alpha> invar splits by fact
interpret al_annot \<alpha> invar annot by fact
interpret al_isEmpty \<alpha> invar isEmpty by fact
show ?thesis
proof (unfold_locales)
fix s e
assume inv1: "aluprio_invar \<alpha> invar s"
hence sinv: "invar s"
"(\<forall> x\<in>set (\<alpha> s). snd x\<noteq>Infty)"
"sorted (map fst (map p_unwrap (map snd (\<alpha> s))))"
"distinct (map fst (map p_unwrap (map snd (\<alpha> s))))"
by (auto simp add: aluprio_defs)
show "aluprio_prio splits annot isEmpty s e = aluprio_\<alpha> \<alpha> s e"
proof(cases "e_less_eq e (annot s) \<and> \<not> isEmpty s")
case False note F1 = this
thus ?thesis
proof(cases "isEmpty s")
case True
hence "\<alpha> s = []"
using sinv isEmpty_correct by simp
hence "aluprio_\<alpha> \<alpha> s = empty" by (simp add:aluprio_defs)
hence "aluprio_\<alpha> \<alpha> s e = None" by simp
thus "aluprio_prio splits annot isEmpty s e = aluprio_\<alpha> \<alpha> s e"
using F1
by (auto simp add: aluprio_defs)
next
case False
hence v3:"\<not> e_less_eq e (annot s)" using F1 by simp
note v4=e_less_eq_annot[OF assms(2)]
note v4[OF sinv(1) sinv(2) v3]
hence v5:"e\<notin>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> s))"
by auto
hence "map_of (map (p_unwrap \<circ> snd) (\<alpha> s)) e = None"
using map_of_eq_None_iff
by (metis map_map map_of_eq_None_iff set_map v5)
thus "aluprio_prio splits annot isEmpty s e = aluprio_\<alpha> \<alpha> s e"
using F1
by (auto simp add: aluprio_defs)
qed
next
case True note T1 = this
obtain l uu lp r where
l_lp_r: "(splits (e_less_eq e) Infty s) = (l, ((), lp), r) "
by (cases "splits (e_less_eq e) Infty s", auto)
note v2 = splits_correct[of s "e_less_eq e" Infty l "()" lp r]
have
v3: "invar s"
"\<not> e_less_eq e Infty"
"e_less_eq e (Infty + listsum (map snd (\<alpha> s)))"
using T1 sinv annot_correct
by (auto simp add: plus_def)
have
v4: "\<alpha> s = \<alpha> l @ ((), lp) # \<alpha> r"
"\<not> e_less_eq e (Infty + listsum (map snd (\<alpha> l)))"
"e_less_eq e (Infty + listsum (map snd (\<alpha> l)) + lp)"
"invar l"
"invar r"
using v2[OF v3(1) _ v3(2) v3(3) l_lp_r] e_less_eq_mon(1) by auto
hence v5: "e_less_eq e lp"
by (metis e_less_eq_lem1)
hence v6: "e \<le> (fst (p_unwrap lp))"
by (cases lp) auto
have "(Infty + listsum (map snd (\<alpha> l))) = (annot l)"
by (metis add_0_left annot_correct v4(4) zero_def)
hence v7:"\<not> e_less_eq e (annot l)"
using v4(2) by simp
have "\<forall>x\<in>set (\<alpha> l). snd x \<noteq> Infty"
using sinv v4(1) by simp
hence v7: "\<forall>x \<in> set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> l)). x < e"
using v4(4) v7 assms(2)
by(simp add: e_less_eq_annot)
have v8:"map fst (map p_unwrap (map snd (\<alpha> s))) =
map fst (map p_unwrap (map snd (\<alpha> l))) @ fst(p_unwrap lp) #
map fst (map p_unwrap (map snd (\<alpha> r)))"
using v4(1)
by simp
note distinct_sortet_list_app[of "map fst (map p_unwrap (map snd (\<alpha> s)))"
"map fst (map p_unwrap (map snd (\<alpha> l)))" "fst(p_unwrap lp)"
"map fst (map p_unwrap (map snd (\<alpha> r)))"]
hence v9:
"\<forall> x\<in>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> r)). fst(p_unwrap lp) < x"
using v4(1) sinv v8
by auto
hence v10: " \<forall> x\<in>set (map (fst \<circ> (p_unwrap \<circ> snd)) (\<alpha> r)). e < x"
using v6 by auto
have v11:
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> l))))"
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> r))))"
using v7 v10 v8 sinv
by auto
from l_lp_r T1 sinv show ?thesis
proof (cases "e = fst (p_unwrap lp)")
case False
have v12: "e \<notin> set (map fst (map p_unwrap (map snd(\<alpha> s))))"
using v11 False v4(1) by auto
hence "map_of (map (p_unwrap \<circ> snd) (\<alpha> s)) e = None"
using map_of_eq_None_iff
by (metis map_map map_of_eq_None_iff set_map v12)
thus ?thesis
using T1 False l_lp_r
by (auto simp add: aluprio_defs)
next
case True
have v12: "map (p_unwrap \<circ> snd) (\<alpha> s) =
map p_unwrap (map snd (\<alpha> l)) @ (e,snd (p_unwrap lp)) #
map p_unwrap (map snd (\<alpha> r))"
using v4(1) True by simp
note map_of_distinct_lookup[OF v11]
hence
"map_of (map (p_unwrap \<circ> snd) (\<alpha> s)) e = Some (snd (p_unwrap lp))"
using v12 by simp
thus ?thesis
using T1 True l_lp_r
by (auto simp add: aluprio_defs)
qed
qed
qed
qed
subsubsection "Pop"
lemma aluprio_pop_correct:
assumes "al_splits \<alpha> invar splits"
"al_annot \<alpha> invar annot"
"al_app \<alpha> invar app"
shows
"uprio_pop (aluprio_\<alpha> \<alpha>) (aluprio_invar \<alpha> invar) (aluprio_pop splits annot app)"
proof -
interpret al_splits \<alpha> invar splits by fact
interpret al_annot \<alpha> invar annot by fact
interpret al_app \<alpha> invar app by fact
show ?thesis
proof (unfold_locales)
fix s e a s'
assume A: "aluprio_invar \<alpha> invar s"
"aluprio_\<alpha> \<alpha> s \<noteq> empty"
"aluprio_pop splits annot app s = (e, a, s')"
hence v1: "\<alpha> s \<noteq> []"
by (auto simp add: aluprio_defs)
obtain l lp r where
l_lp_r: "splits (\<lambda> x. x\<le>annot s) Infty s = (l,((),lp),r)"
by (cases "splits (\<lambda> x. x\<le>annot s) Infty s", auto)
have invs:
"invar s"
"(\<forall>x\<in>set (\<alpha> s). snd x \<noteq> Infty)"
"sorted (map fst (map p_unwrap (map snd (\<alpha> s))))"
"distinct (map fst (map p_unwrap (map snd (\<alpha> s))))"
using A by (auto simp add:aluprio_defs)
note a1 = annot_inf[of invar s \<alpha> annot]
note a1[OF invs(1) invs(2) assms(2)]
hence v2: "annot s \<noteq> Infty"
using v1 by simp
hence v3:
"\<not> Infty \<le> annot s"
by(cases "annot s") (auto simp add: plesseq_def)
have v4: "annot s = listsum (map snd (\<alpha> s))"
by (auto simp add: annot_correct invs(1))
hence
v5:
"(Infty + listsum (map snd (\<alpha> s))) \<le> annot s"
by (auto simp add: plus_def)
note p_mon = p_less_eq_mon[of _ "annot s"]
note v6 = splits_correct[OF invs(1)]
note v7 = v6[of "\<lambda> x. x \<le> annot s"]
note v7[OF _ v3 v5 l_lp_r] p_mon
hence v8:
" \<alpha> s = \<alpha> l @ ((), lp) # \<alpha> r"
"\<not> Infty + listsum (map snd (\<alpha> l)) \<le> annot s"
"Infty + listsum (map snd (\<alpha> l)) + lp \<le> annot s"
"invar l"
"invar r"
by auto
hence v9: "lp \<noteq> Infty"
using invs(2) by auto
hence v10:
"s' = app l r"
"(e,a) = p_unwrap lp"
using l_lp_r A(3)
apply (auto simp add: aluprio_defs)
apply (cases lp)
apply auto
apply (cases lp)
apply auto
done
have "lp \<le> annot s"
using v8(2,3) p_less_eq_lem1
by auto
hence v11: "a \<le> snd (p_unwrap (annot s))"
using v10(2) v2 v9
apply (cases "annot s")
apply auto
apply (cases lp)
apply (auto simp add: plesseq_def)
done
note listsum_less_elems[OF invs(2)]
hence v12: "\<forall>y\<in>set (map snd (map p_unwrap (map snd (\<alpha> s)))). a \<le> y"
using v4 v11 by auto
have "ran (aluprio_\<alpha> \<alpha> s) = set (map snd (map p_unwrap (map snd (\<alpha> s))))"
using ran_distinct[OF invs(4)]
apply (unfold aluprio_defs)
apply (simp only: set_map)
done
hence ziel1: "\<forall>y\<in>ran (aluprio_\<alpha> \<alpha> s). a \<le> y"
using v12 by simp
have v13:
"map p_unwrap (map snd (\<alpha> s))
= map p_unwrap (map snd (\<alpha> l)) @ (e,a) # map p_unwrap (map snd (\<alpha> r))"
using v8(1) v10 by auto
hence v14:
"map fst (map p_unwrap (map snd (\<alpha> s)))
= map fst (map p_unwrap (map snd (\<alpha> l))) @ e
# map fst (map p_unwrap (map snd (\<alpha> r)))"
by auto
hence v15:
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> l))))"
"e \<notin> set (map fst (map p_unwrap (map snd (\<alpha> r))))"
using invs(4) by auto
note map_of_distinct_lookup[OF v15]
note this[of a]
hence ziel2: "aluprio_\<alpha> \<alpha> s e = Some a"
using v13
by (unfold aluprio_defs, auto)
have v16:
"\<alpha> s' = \<alpha> l @ \<alpha> r"
"invar s'"
using v8(4,5) app_correct v10 by auto
note map_of_distinct_upd4[OF v15]
note this[of a]
hence
ziel3: "aluprio_\<alpha> \<alpha> s' = (aluprio_\<alpha> \<alpha> s)(e := None)"
unfolding aluprio_defs
using v16(1) v13 by auto
have ziel4: "aluprio_invar \<alpha> invar s'"
using v16 v8(1) invs(2,3,4)
unfolding aluprio_defs
by (auto simp add: sorted_Cons sorted_append)
show "aluprio_invar \<alpha> invar s' \<and>
aluprio_\<alpha> \<alpha> s' = (aluprio_\<alpha> \<alpha> s)(e := None) \<and>
aluprio_\<alpha> \<alpha> s e = Some a \<and> (\<forall>y\<in>ran (aluprio_\<alpha> \<alpha> s). a \<le> y)"
using ziel1 ziel2 ziel3 ziel4 by simp
qed
qed
lemmas aluprio_correct =
aluprio_finite_correct
aluprio_empty_correct
aluprio_isEmpty_correct
aluprio_insert_correct
aluprio_pop_correct
aluprio_prio_correct
end

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks