src/HOL/Data_Structures/Tree234_Map.thy
author wenzelm
Fri, 05 Apr 2019 17:05:32 +0200
changeset 70067 9b34dbeb1103
parent 69040 e0d14f648d46
permissions -rw-r--r--
auxiliary operation for common uses of 'compile_generated_files';
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     1
(* Author: Tobias Nipkow *)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     2
62130
90a3016a6c12 added AA_Map; tuned titles
nipkow
parents: 61790
diff changeset
     3
section \<open>2-3-4 Tree Implementation of Maps\<close>
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     4
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     5
theory Tree234_Map
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     6
imports
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     7
  Tree234_Set
67965
aaa31cd0caef more name tuning
nipkow
parents: 63636
diff changeset
     8
  Map_Specs
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
     9
begin
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    10
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    11
subsection \<open>Map operations on 2-3-4 trees\<close>
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    12
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    13
fun lookup :: "('a::linorder * 'b) tree234 \<Rightarrow> 'a \<Rightarrow> 'b option" where
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    14
"lookup Leaf x = None" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    15
"lookup (Node2 l (a,b) r) x = (case cmp x a of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    16
  LT \<Rightarrow> lookup l x |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    17
  GT \<Rightarrow> lookup r x |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    18
  EQ \<Rightarrow> Some b)" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    19
"lookup (Node3 l (a1,b1) m (a2,b2) r) x = (case cmp x a1 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    20
  LT \<Rightarrow> lookup l x |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    21
  EQ \<Rightarrow> Some b1 |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    22
  GT \<Rightarrow> (case cmp x a2 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    23
          LT \<Rightarrow> lookup m x |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    24
          EQ \<Rightarrow> Some b2 |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    25
          GT \<Rightarrow> lookup r x))" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    26
"lookup (Node4 t1 (a1,b1) t2 (a2,b2) t3 (a3,b3) t4) x = (case cmp x a2 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    27
  LT \<Rightarrow> (case cmp x a1 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    28
           LT \<Rightarrow> lookup t1 x | EQ \<Rightarrow> Some b1 | GT \<Rightarrow> lookup t2 x) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    29
  EQ \<Rightarrow> Some b2 |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    30
  GT \<Rightarrow> (case cmp x a3 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    31
           LT \<Rightarrow> lookup t3 x | EQ \<Rightarrow> Some b3 | GT \<Rightarrow> lookup t4 x))"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    32
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    33
fun upd :: "'a::linorder \<Rightarrow> 'b \<Rightarrow> ('a*'b) tree234 \<Rightarrow> ('a*'b) up\<^sub>i" where
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    34
"upd x y Leaf = Up\<^sub>i Leaf (x,y) Leaf" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    35
"upd x y (Node2 l ab r) = (case cmp x (fst ab) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    36
   LT \<Rightarrow> (case upd x y l of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    37
           T\<^sub>i l' => T\<^sub>i (Node2 l' ab r)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    38
         | Up\<^sub>i l1 ab' l2 => T\<^sub>i (Node3 l1 ab' l2 ab r)) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    39
   EQ \<Rightarrow> T\<^sub>i (Node2 l (x,y) r) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    40
   GT \<Rightarrow> (case upd x y r of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    41
           T\<^sub>i r' => T\<^sub>i (Node2 l ab r')
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    42
         | Up\<^sub>i r1 ab' r2 => T\<^sub>i (Node3 l ab r1 ab' r2)))" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    43
"upd x y (Node3 l ab1 m ab2 r) = (case cmp x (fst ab1) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    44
   LT \<Rightarrow> (case upd x y l of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    45
           T\<^sub>i l' => T\<^sub>i (Node3 l' ab1 m ab2 r)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    46
         | Up\<^sub>i l1 ab' l2 => Up\<^sub>i (Node2 l1 ab' l2) ab1 (Node2 m ab2 r)) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    47
   EQ \<Rightarrow> T\<^sub>i (Node3 l (x,y) m ab2 r) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    48
   GT \<Rightarrow> (case cmp x (fst ab2) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    49
           LT \<Rightarrow> (case upd x y m of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    50
                   T\<^sub>i m' => T\<^sub>i (Node3 l ab1 m' ab2 r)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    51
                 | Up\<^sub>i m1 ab' m2 => Up\<^sub>i (Node2 l ab1 m1) ab' (Node2 m2 ab2 r)) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    52
           EQ \<Rightarrow> T\<^sub>i (Node3 l ab1 m (x,y) r) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    53
           GT \<Rightarrow> (case upd x y r of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    54
                   T\<^sub>i r' => T\<^sub>i (Node3 l ab1 m ab2 r')
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    55
                 | Up\<^sub>i r1 ab' r2 => Up\<^sub>i (Node2 l ab1 m) ab2 (Node2 r1 ab' r2))))" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    56
"upd x y (Node4 t1 ab1 t2 ab2 t3 ab3 t4) = (case cmp x (fst ab2) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    57
   LT \<Rightarrow> (case cmp x (fst ab1) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    58
            LT \<Rightarrow> (case upd x y t1 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    59
                     T\<^sub>i t1' => T\<^sub>i (Node4 t1' ab1 t2 ab2 t3 ab3 t4)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    60
                  | Up\<^sub>i t11 q t12 => Up\<^sub>i (Node2 t11 q t12) ab1 (Node3 t2 ab2 t3 ab3 t4)) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    61
            EQ \<Rightarrow> T\<^sub>i (Node4 t1 (x,y) t2 ab2 t3 ab3 t4) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    62
            GT \<Rightarrow> (case upd x y t2 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    63
                    T\<^sub>i t2' => T\<^sub>i (Node4 t1 ab1 t2' ab2 t3 ab3 t4)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    64
                  | Up\<^sub>i t21 q t22 => Up\<^sub>i (Node2 t1 ab1 t21) q (Node3 t22 ab2 t3 ab3 t4))) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    65
   EQ \<Rightarrow> T\<^sub>i (Node4 t1 ab1 t2 (x,y) t3 ab3 t4) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    66
   GT \<Rightarrow> (case cmp x (fst ab3) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    67
            LT \<Rightarrow> (case upd x y t3 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    68
                    T\<^sub>i t3' \<Rightarrow> T\<^sub>i (Node4 t1 ab1 t2 ab2 t3' ab3 t4)
69040
e0d14f648d46 eliminated old-style inner comments;
wenzelm
parents: 68440
diff changeset
    69
                  | Up\<^sub>i t31 q t32 => Up\<^sub>i (Node2 t1 ab1 t2) ab2\<^cancel>\<open>q\<close> (Node3 t31 q t32 ab3 t4)) |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    70
            EQ \<Rightarrow> T\<^sub>i (Node4 t1 ab1 t2 ab2 t3 (x,y) t4) |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    71
            GT \<Rightarrow> (case upd x y t4 of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    72
                    T\<^sub>i t4' => T\<^sub>i (Node4 t1 ab1 t2 ab2 t3 ab3 t4')
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    73
                  | Up\<^sub>i t41 q t42 => Up\<^sub>i (Node2 t1 ab1 t2) ab2 (Node3 t3 ab3 t41 q t42))))"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    74
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    75
definition update :: "'a::linorder \<Rightarrow> 'b \<Rightarrow> ('a*'b) tree234 \<Rightarrow> ('a*'b) tree234" where
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    76
"update x y t = tree\<^sub>i(upd x y t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    77
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
    78
fun del :: "'a::linorder \<Rightarrow> ('a*'b) tree234 \<Rightarrow> ('a*'b) up\<^sub>d" where
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    79
"del x Leaf = T\<^sub>d Leaf" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    80
"del x (Node2 Leaf ab1 Leaf) = (if x=fst ab1 then Up\<^sub>d Leaf else T\<^sub>d(Node2 Leaf ab1 Leaf))" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    81
"del x (Node3 Leaf ab1 Leaf ab2 Leaf) = T\<^sub>d(if x=fst ab1 then Node2 Leaf ab2 Leaf
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    82
  else if x=fst ab2 then Node2 Leaf ab1 Leaf else Node3 Leaf ab1 Leaf ab2 Leaf)" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    83
"del x (Node4 Leaf ab1 Leaf ab2 Leaf ab3 Leaf) =
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    84
  T\<^sub>d(if x = fst ab1 then Node3 Leaf ab2 Leaf ab3 Leaf else
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    85
     if x = fst ab2 then Node3 Leaf ab1 Leaf ab3 Leaf else
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    86
     if x = fst ab3 then Node3 Leaf ab1 Leaf ab2 Leaf
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    87
     else Node4 Leaf ab1 Leaf ab2 Leaf ab3 Leaf)" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    88
"del x (Node2 l ab1 r) = (case cmp x (fst ab1) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    89
  LT \<Rightarrow> node21 (del x l) ab1 r |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    90
  GT \<Rightarrow> node22 l ab1 (del x r) |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
    91
  EQ \<Rightarrow> let (ab1',t) = split_min r in node22 l ab1' t)" |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    92
"del x (Node3 l ab1 m ab2 r) = (case cmp x (fst ab1) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    93
  LT \<Rightarrow> node31 (del x l) ab1 m ab2 r |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
    94
  EQ \<Rightarrow> let (ab1',m') = split_min m in node32 l ab1' m' ab2 r |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    95
  GT \<Rightarrow> (case cmp x (fst ab2) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    96
           LT \<Rightarrow> node32 l ab1 (del x m) ab2 r |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
    97
           EQ \<Rightarrow> let (ab2',r') = split_min r in node33 l ab1 m ab2' r' |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    98
           GT \<Rightarrow> node33 l ab1 m ab2 (del x r)))" |
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
    99
"del x (Node4 t1 ab1 t2 ab2 t3 ab3 t4) = (case cmp x (fst ab2) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   100
  LT \<Rightarrow> (case cmp x (fst ab1) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   101
           LT \<Rightarrow> node41 (del x t1) ab1 t2 ab2 t3 ab3 t4 |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   102
           EQ \<Rightarrow> let (ab',t2') = split_min t2 in node42 t1 ab' t2' ab2 t3 ab3 t4 |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   103
           GT \<Rightarrow> node42 t1 ab1 (del x t2) ab2 t3 ab3 t4) |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   104
  EQ \<Rightarrow> let (ab',t3') = split_min t3 in node43 t1 ab1 t2 ab' t3' ab3 t4 |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   105
  GT \<Rightarrow> (case cmp x (fst ab3) of
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   106
          LT \<Rightarrow> node43 t1 ab1 t2 ab2 (del x t3) ab3 t4 |
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   107
          EQ \<Rightarrow> let (ab',t4') = split_min t4 in node44 t1 ab1 t2 ab2 t3 ab' t4' |
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   108
          GT \<Rightarrow> node44 t1 ab1 t2 ab2 t3 ab3 (del x t4)))"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   109
63411
e051eea34990 got rid of class cmp; added height-size proofs by Daniel Stuewe
nipkow
parents: 62130
diff changeset
   110
definition delete :: "'a::linorder \<Rightarrow> ('a*'b) tree234 \<Rightarrow> ('a*'b) tree234" where
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   111
"delete x t = tree\<^sub>d(del x t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   112
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   113
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   114
subsection "Functional correctness"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   115
61790
0494964bb226 avoid name clashes
nipkow
parents: 61686
diff changeset
   116
lemma lookup_map_of:
0494964bb226 avoid name clashes
nipkow
parents: 61686
diff changeset
   117
  "sorted1(inorder t) \<Longrightarrow> lookup t x = map_of (inorder t) x"
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   118
by (induction t) (auto simp: map_of_simps split: option.split)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   119
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   120
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   121
lemma inorder_upd:
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   122
  "sorted1(inorder t) \<Longrightarrow> inorder(tree\<^sub>i(upd a b t)) = upd_list a b (inorder t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   123
by(induction t)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   124
  (auto simp: upd_list_simps, auto simp: upd_list_simps split: up\<^sub>i.splits)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   125
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68431
diff changeset
   126
lemma inorder_update:
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   127
  "sorted1(inorder t) \<Longrightarrow> inorder(update a b t) = upd_list a b (inorder t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   128
by(simp add: update_def inorder_upd)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   129
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   130
lemma inorder_del: "\<lbrakk> bal t ; sorted1(inorder t) \<rbrakk> \<Longrightarrow>
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   131
  inorder(tree\<^sub>d (del x t)) = del_list x (inorder t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   132
by(induction t rule: del.induct)
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   133
  (auto simp: del_list_simps inorder_nodes split_minD split!: if_splits prod.splits)
63636
6f38b7abb648 introduced aggressive splitter "split!"
nipkow
parents: 63411
diff changeset
   134
(* 30 secs (2016) *)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   135
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68431
diff changeset
   136
lemma inorder_delete: "\<lbrakk> bal t ; sorted1(inorder t) \<rbrakk> \<Longrightarrow>
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   137
  inorder(delete x t) = del_list x (inorder t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   138
by(simp add: delete_def inorder_del)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   139
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   140
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   141
subsection \<open>Balancedness\<close>
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   142
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   143
lemma bal_upd: "bal t \<Longrightarrow> bal (tree\<^sub>i(upd x y t)) \<and> height(upd x y t) = height t"
63636
6f38b7abb648 introduced aggressive splitter "split!"
nipkow
parents: 63411
diff changeset
   144
by (induct t) (auto, auto split!: if_split up\<^sub>i.split) (* 20 secs (2015) *)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   145
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   146
lemma bal_update: "bal t \<Longrightarrow> bal (update x y t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   147
by (simp add: update_def bal_upd)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   148
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   149
lemma height_del: "bal t \<Longrightarrow> height(del x t) = height t"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   150
by(induction x t rule: del.induct)
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   151
  (auto simp add: heights height_split_min split!: if_split prod.split)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   152
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   153
lemma bal_tree\<^sub>d_del: "bal t \<Longrightarrow> bal(tree\<^sub>d(del x t))"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   154
by(induction x t rule: del.induct)
68020
6aade817bee5 del_min -> split_min
nipkow
parents: 67965
diff changeset
   155
  (auto simp: bals bal_split_min height_del height_split_min split!: if_split prod.split)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   156
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   157
corollary bal_delete: "bal t \<Longrightarrow> bal(delete x t)"
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   158
by(simp add: delete_def bal_tree\<^sub>d_del)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   159
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   160
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   161
subsection \<open>Overall Correctness\<close>
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   162
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68431
diff changeset
   163
interpretation M: Map_by_Ordered
68431
b294e095f64c more abstract naming
nipkow
parents: 68020
diff changeset
   164
where empty = empty and lookup = lookup and update = update and delete = delete
61686
e6784939d645 tuned names
nipkow
parents: 61640
diff changeset
   165
and inorder = inorder and inv = bal
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   166
proof (standard, goal_cases)
61790
0494964bb226 avoid name clashes
nipkow
parents: 61686
diff changeset
   167
  case 2 thus ?case by(simp add: lookup_map_of)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   168
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68431
diff changeset
   169
  case 3 thus ?case by(simp add: inorder_update)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   170
next
68440
6826718f732d qualify interpretations to avoid clashes
nipkow
parents: 68431
diff changeset
   171
  case 4 thus ?case by(simp add: inorder_delete)
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   172
next
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   173
  case 6 thus ?case by(simp add: bal_update)
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   174
next
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   175
  case 7 thus ?case by(simp add: bal_delete)
68431
b294e095f64c more abstract naming
nipkow
parents: 68020
diff changeset
   176
qed (simp add: empty_def)+
61640
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   177
44c9198f210c no CRLF
nipkow
parents: 61581
diff changeset
   178
end