src/HOL/Data_Structures/Brother12_Map.thy
author nipkow
Wed, 31 Mar 2021 18:18:03 +0200
changeset 73526 a3cc9fa1295d
parent 68431 b294e095f64c
permissions -rw-r--r--
new automatic order prover: stateless, complete, verified
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     1
(* Author: Tobias Nipkow *)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     2
62130
90a3016a6c12 added AA_Map; tuned titles
nipkow
parents: 61809
diff changeset
     3
section \<open>1-2 Brother Tree Implementation of Maps\<close>
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     4
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     5
theory Brother12_Map
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     6
imports
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     7
  Brother12_Set
67965
aaa31cd0caef more name tuning
nipkow
parents: 67406
diff changeset
     8
  Map_Specs
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
     9
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    10
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    11
fun lookup :: "('a \<times> 'b) bro \<Rightarrow> 'a::linorder \<Rightarrow> 'b option" where
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    12
"lookup N0 x = None" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    13
"lookup (N1 t) x = lookup t x" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    14
"lookup (N2 l (a,b) r) x =
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    15
  (case cmp x a of
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    16
     LT \<Rightarrow> lookup l x |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    17
     EQ \<Rightarrow> Some b |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    18
     GT \<Rightarrow> lookup r x)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    19
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    20
locale update = insert
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    21
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    22
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    23
fun upd :: "'a::linorder \<Rightarrow> 'b \<Rightarrow> ('a\<times>'b) bro \<Rightarrow> ('a\<times>'b) bro" where
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    24
"upd x y N0 = L2 (x,y)" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    25
"upd x y (N1 t) = n1 (upd x y t)" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    26
"upd x y (N2 l (a,b) r) =
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    27
  (case cmp x a of
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    28
     LT \<Rightarrow> n2 (upd x y l) (a,b) r |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    29
     EQ \<Rightarrow> N2 l (a,y) r |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    30
     GT \<Rightarrow> n2 l (a,b) (upd x y r))"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    31
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    32
definition update :: "'a::linorder \<Rightarrow> 'b \<Rightarrow> ('a\<times>'b) bro \<Rightarrow> ('a\<times>'b) bro" where
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    33
"update x y t = tree(upd x y t)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    34
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    35
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    36
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    37
context delete
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    38
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    39
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    40
fun del :: "'a::linorder \<Rightarrow> ('a\<times>'b) bro \<Rightarrow> ('a\<times>'b) bro" where
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    41
"del _ N0         = N0" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    42
"del x (N1 t)     = N1 (del x t)" |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    43
"del x (N2 l (a,b) r) =
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    44
  (case cmp x a of
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    45
     LT \<Rightarrow> n2 (del x l) (a,b) r |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    46
     GT \<Rightarrow> n2 l (a,b) (del x r) |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
    47
     EQ \<Rightarrow> (case split_min r of
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    48
              None \<Rightarrow> N1 l |
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    49
              Some (ab, r') \<Rightarrow> n2 l ab r'))"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    50
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    51
definition delete :: "'a::linorder \<Rightarrow> ('a\<times>'b) bro \<Rightarrow> ('a\<times>'b) bro" where
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    52
"delete a t = tree (del a t)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    53
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    54
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    55
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    56
subsection "Functional Correctness Proofs"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    57
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    58
subsubsection "Proofs for lookup"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    59
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    60
lemma lookup_map_of: "t \<in> T h \<Longrightarrow>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    61
  sorted1(inorder t) \<Longrightarrow> lookup t x = map_of (inorder t) x"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    62
by(induction h arbitrary: t) (auto simp: map_of_simps split: option.splits)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    63
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    64
subsubsection "Proofs for update"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    65
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    66
context update
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    67
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    68
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    69
lemma inorder_upd: "t \<in> T h \<Longrightarrow>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    70
  sorted1(inorder t) \<Longrightarrow> inorder(upd x y t) = upd_list x y (inorder t)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    71
by(induction h arbitrary: t) (auto simp: upd_list_simps inorder_n1 inorder_n2)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    72
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    73
lemma inorder_update: "t \<in> T h \<Longrightarrow>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    74
  sorted1(inorder t) \<Longrightarrow> inorder(update x y t) = upd_list x y (inorder t)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    75
by(simp add: update_def inorder_upd inorder_tree)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    76
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    77
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    78
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    79
subsubsection \<open>Proofs for deletion\<close>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    80
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    81
context delete
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    82
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    83
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    84
lemma inorder_del:
61792
nipkow
parents: 61789
diff changeset
    85
  "t \<in> T h \<Longrightarrow> sorted1(inorder t) \<Longrightarrow> inorder(del x t) = del_list x (inorder t)"
73526
a3cc9fa1295d new automatic order prover: stateless, complete, verified
nipkow
parents: 68431
diff changeset
    86
  apply (induction h arbitrary: t)
a3cc9fa1295d new automatic order prover: stateless, complete, verified
nipkow
parents: 68431
diff changeset
    87
  apply (auto simp: del_list_simps inorder_n2)
a3cc9fa1295d new automatic order prover: stateless, complete, verified
nipkow
parents: 68431
diff changeset
    88
  apply (auto simp: del_list_simps inorder_n2
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
    89
     inorder_split_min[OF UnI1] inorder_split_min[OF UnI2] split: option.splits)
73526
a3cc9fa1295d new automatic order prover: stateless, complete, verified
nipkow
parents: 68431
diff changeset
    90
  done
61792
nipkow
parents: 61789
diff changeset
    91
nipkow
parents: 61789
diff changeset
    92
lemma inorder_delete:
nipkow
parents: 61789
diff changeset
    93
  "t \<in> T h \<Longrightarrow> sorted1(inorder t) \<Longrightarrow> inorder(delete x t) = del_list x (inorder t)"
nipkow
parents: 61789
diff changeset
    94
by(simp add: delete_def inorder_del inorder_tree)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    95
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    96
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    97
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    98
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
    99
subsection \<open>Invariant Proofs\<close>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   100
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   101
subsubsection \<open>Proofs for update\<close>
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   102
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   103
context update
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   104
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   105
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   106
lemma upd_type:
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   107
  "(t \<in> B h \<longrightarrow> upd x y t \<in> Bp h) \<and> (t \<in> U h \<longrightarrow> upd x y t \<in> T h)"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   108
apply(induction h arbitrary: t)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   109
 apply (simp)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   110
apply (fastforce simp: Bp_if_B n2_type dest: n1_type)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   111
done
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   112
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   113
lemma update_type:
61809
81d34cf268d8 tightened invariant
nipkow
parents: 61792
diff changeset
   114
  "t \<in> B h \<Longrightarrow> update x y t \<in> B h \<union> B (Suc h)"
81d34cf268d8 tightened invariant
nipkow
parents: 61792
diff changeset
   115
unfolding update_def by (metis upd_type tree_type)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   116
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   117
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   118
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   119
subsubsection "Proofs for deletion"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   120
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   121
context delete
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   122
begin
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   123
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   124
lemma del_type:
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   125
  "t \<in> B h \<Longrightarrow> del x t \<in> T h"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   126
  "t \<in> U h \<Longrightarrow> del x t \<in> Um h"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   127
proof (induction h arbitrary: x t)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   128
  case (Suc h)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   129
  { case 1
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   130
    then obtain l a b r where [simp]: "t = N2 l (a,b) r" and
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   131
      lr: "l \<in> T h" "r \<in> T h" "l \<in> B h \<or> r \<in> B h" by auto
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   132
    have ?case if "x < a"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   133
    proof cases
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   134
      assume "l \<in> B h"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   135
      from n2_type3[OF Suc.IH(1)[OF this] lr(2)]
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67040
diff changeset
   136
      show ?thesis using \<open>x<a\<close> by(simp)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   137
    next
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   138
      assume "l \<notin> B h"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   139
      hence "l \<in> U h" "r \<in> B h" using lr by auto
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   140
      from n2_type1[OF Suc.IH(2)[OF this(1)] this(2)]
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67040
diff changeset
   141
      show ?thesis using \<open>x<a\<close> by(simp)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   142
    qed
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   143
    moreover
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   144
    have ?case if "x > a"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   145
    proof cases
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   146
      assume "r \<in> B h"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   147
      from n2_type3[OF lr(1) Suc.IH(1)[OF this]]
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67040
diff changeset
   148
      show ?thesis using \<open>x>a\<close> by(simp)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   149
    next
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   150
      assume "r \<notin> B h"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   151
      hence "l \<in> B h" "r \<in> U h" using lr by auto
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   152
      from n2_type2[OF this(1) Suc.IH(2)[OF this(2)]]
67406
23307fd33906 isabelle update_cartouches -c;
wenzelm
parents: 67040
diff changeset
   153
      show ?thesis using \<open>x>a\<close> by(simp)
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   154
    qed
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   155
    moreover
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   156
    have ?case if [simp]: "x=a"
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   157
    proof (cases "split_min r")
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   158
      case None
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   159
      show ?thesis
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   160
      proof cases
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   161
        assume "r \<in> B h"
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   162
        with split_minNoneN0[OF this None] lr show ?thesis by(simp)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   163
      next
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   164
        assume "r \<notin> B h"
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   165
        hence "r \<in> U h" using lr by auto
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   166
        with split_minNoneN1[OF this None] lr(3) show ?thesis by (simp)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   167
      qed
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   168
    next
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   169
      case [simp]: (Some br')
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   170
      obtain b r' where [simp]: "br' = (b,r')" by fastforce
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   171
      show ?thesis
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   172
      proof cases
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   173
        assume "r \<in> B h"
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   174
        from split_min_type(1)[OF this] n2_type3[OF lr(1)]
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   175
        show ?thesis by simp
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   176
      next
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   177
        assume "r \<notin> B h"
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   178
        hence "l \<in> B h" and "r \<in> U h" using lr by auto
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   179
        from split_min_type(2)[OF this(2)] n2_type2[OF this(1)]
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   180
        show ?thesis by simp
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   181
      qed
67040
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   182
    qed
c1b87d15774a replaced raw proof blocks by local lemmas
nipkow
parents: 63411
diff changeset
   183
    ultimately show ?case by auto                         
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   184
  }
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   185
  { case 2 with Suc.IH(1) show ?case by auto }
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   186
qed auto
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   187
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   188
lemma delete_type:
61809
81d34cf268d8 tightened invariant
nipkow
parents: 61792
diff changeset
   189
  "t \<in> B h \<Longrightarrow> delete x t \<in> B h \<union> B(h-1)"
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   190
unfolding delete_def
61809
81d34cf268d8 tightened invariant
nipkow
parents: 61792
diff changeset
   191
by (cases h) (simp, metis del_type(1) tree_type Suc_eq_plus1 diff_Suc_1)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   192
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   193
end
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   194
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   195
subsection "Overall correctness"
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   196
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   197
interpretation Map_by_Ordered
68431
b294e095f64c more abstract naming
nipkow
parents: 68020
diff changeset
   198
where empty = empty and lookup = lookup and update = update.update
61809
81d34cf268d8 tightened invariant
nipkow
parents: 61792
diff changeset
   199
and delete = delete.delete and inorder = inorder and inv = "\<lambda>t. \<exists>h. t \<in> B h"
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   200
proof (standard, goal_cases)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   201
  case 2 thus ?case by(auto intro!: lookup_map_of)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   202
next
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   203
  case 3 thus ?case by(auto intro!: update.inorder_update)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   204
next
61792
nipkow
parents: 61789
diff changeset
   205
  case 4 thus ?case by(auto intro!: delete.inorder_delete)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   206
next
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   207
  case 6 thus ?case using update.update_type by (metis Un_iff)
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   208
next
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   209
  case 7 thus ?case using delete.delete_type by blast
68431
b294e095f64c more abstract naming
nipkow
parents: 68020
diff changeset
   210
qed (auto simp: empty_def)
61789
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   211
9ce1a397410a added Brother12_Map
nipkow
parents:
diff changeset
   212
end