src/HOL/Library/RBT.thy
author nipkow
Tue, 07 Sep 2010 10:05:19 +0200
changeset 39198 f967a16dfcdd
parent 38857 97775f3e8722
child 39302 d7728f65b353
permissions -rw-r--r--
expand_fun_eq -> ext_iff expand_set_eq -> set_ext_iff Naming in line now with multisets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
     1
(* Author: Florian Haftmann, TU Muenchen *)
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
     2
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
     3
header {* Abstract type of Red-Black Trees *}
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
     4
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
     5
(*<*)
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
     6
theory RBT
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
     7
imports Main RBT_Impl Mapping
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
     8
begin
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
     9
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    10
subsection {* Type definition *}
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    11
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    12
typedef (open) ('a, 'b) rbt = "{t :: ('a\<Colon>linorder, 'b) RBT_Impl.rbt. is_rbt t}"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    13
  morphisms impl_of RBT
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    14
proof -
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    15
  have "RBT_Impl.Empty \<in> ?rbt" by simp
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    16
  then show ?thesis ..
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    17
qed
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    18
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    19
lemma is_rbt_impl_of [simp, intro]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    20
  "is_rbt (impl_of t)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    21
  using impl_of [of t] by simp
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    22
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    23
lemma rbt_eq:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    24
  "t1 = t2 \<longleftrightarrow> impl_of t1 = impl_of t2"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    25
  by (simp add: impl_of_inject)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    26
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
    27
lemma [code abstype]:
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    28
  "RBT (impl_of t) = t"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    29
  by (simp add: impl_of_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    30
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    31
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    32
subsection {* Primitive operations *}
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    33
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    34
definition lookup :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a \<rightharpoonup> 'b" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    35
  [code]: "lookup t = RBT_Impl.lookup (impl_of t)"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    36
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    37
definition empty :: "('a\<Colon>linorder, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    38
  "empty = RBT RBT_Impl.Empty"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    39
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    40
lemma impl_of_empty [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    41
  "impl_of empty = RBT_Impl.Empty"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    42
  by (simp add: empty_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    43
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    44
definition insert :: "'a\<Colon>linorder \<Rightarrow> 'b \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    45
  "insert k v t = RBT (RBT_Impl.insert k v (impl_of t))"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    46
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    47
lemma impl_of_insert [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    48
  "impl_of (insert k v t) = RBT_Impl.insert k v (impl_of t)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    49
  by (simp add: insert_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    50
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    51
definition delete :: "'a\<Colon>linorder \<Rightarrow> ('a, 'b) rbt \<Rightarrow> ('a, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    52
  "delete k t = RBT (RBT_Impl.delete k (impl_of t))"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    53
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    54
lemma impl_of_delete [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    55
  "impl_of (delete k t) = RBT_Impl.delete k (impl_of t)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    56
  by (simp add: delete_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    57
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    58
definition entries :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a \<times> 'b) list" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    59
  [code]: "entries t = RBT_Impl.entries (impl_of t)"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    60
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    61
definition keys :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'a list" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    62
  [code]: "keys t = RBT_Impl.keys (impl_of t)"
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
    63
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    64
definition bulkload :: "('a\<Colon>linorder \<times> 'b) list \<Rightarrow> ('a, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    65
  "bulkload xs = RBT (RBT_Impl.bulkload xs)"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    66
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    67
lemma impl_of_bulkload [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    68
  "impl_of (bulkload xs) = RBT_Impl.bulkload xs"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    69
  by (simp add: bulkload_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    70
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    71
definition map_entry :: "'a \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    72
  "map_entry k f t = RBT (RBT_Impl.map_entry k f (impl_of t))"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    73
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    74
lemma impl_of_map_entry [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    75
  "impl_of (map_entry k f t) = RBT_Impl.map_entry k f (impl_of t)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    76
  by (simp add: map_entry_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    77
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    78
definition map :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) rbt" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    79
  "map f t = RBT (RBT_Impl.map f (impl_of t))"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    80
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    81
lemma impl_of_map [code abstract]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    82
  "impl_of (map f t) = RBT_Impl.map f (impl_of t)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    83
  by (simp add: map_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    84
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    85
definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> 'c) \<Rightarrow> ('a\<Colon>linorder, 'b) rbt \<Rightarrow> 'c \<Rightarrow> 'c" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    86
  [code]: "fold f t = RBT_Impl.fold f (impl_of t)"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    87
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    88
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    89
subsection {* Derived operations *}
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    90
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    91
definition is_empty :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> bool" where
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    92
  [code]: "is_empty t = (case impl_of t of RBT_Impl.Empty \<Rightarrow> True | _ \<Rightarrow> False)"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    93
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    94
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    95
subsection {* Abstract lookup properties *}
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
    96
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    97
lemma lookup_RBT:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    98
  "is_rbt t \<Longrightarrow> lookup (RBT t) = RBT_Impl.lookup t"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
    99
  by (simp add: lookup_def RBT_inverse)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   100
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   101
lemma lookup_impl_of:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   102
  "RBT_Impl.lookup (impl_of t) = lookup t"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   103
  by (simp add: lookup_def)
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   104
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   105
lemma entries_impl_of:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   106
  "RBT_Impl.entries (impl_of t) = entries t"
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   107
  by (simp add: entries_def)
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   108
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   109
lemma keys_impl_of:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   110
  "RBT_Impl.keys (impl_of t) = keys t"
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   111
  by (simp add: keys_def)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   112
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   113
lemma lookup_empty [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   114
  "lookup empty = Map.empty"
39198
f967a16dfcdd expand_fun_eq -> ext_iff
nipkow
parents: 38857
diff changeset
   115
  by (simp add: empty_def lookup_RBT ext_iff)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   116
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   117
lemma lookup_insert [simp]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   118
  "lookup (insert k v t) = (lookup t)(k \<mapsto> v)"
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   119
  by (simp add: insert_def lookup_RBT lookup_insert lookup_impl_of)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   120
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   121
lemma lookup_delete [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   122
  "lookup (delete k t) = (lookup t)(k := None)"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   123
  by (simp add: delete_def lookup_RBT RBT_Impl.lookup_delete lookup_impl_of restrict_complement_singleton_eq)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   124
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   125
lemma map_of_entries [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   126
  "map_of (entries t) = lookup t"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   127
  by (simp add: entries_def map_of_entries lookup_impl_of)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   128
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   129
lemma entries_lookup:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   130
  "entries t1 = entries t2 \<longleftrightarrow> lookup t1 = lookup t2"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   131
  by (simp add: entries_def lookup_def entries_lookup)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   132
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   133
lemma lookup_bulkload [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   134
  "lookup (bulkload xs) = map_of xs"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   135
  by (simp add: bulkload_def lookup_RBT RBT_Impl.lookup_bulkload)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   136
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   137
lemma lookup_map_entry [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   138
  "lookup (map_entry k f t) = (lookup t)(k := Option.map f (lookup t k))"
37027
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   139
  by (simp add: map_entry_def lookup_RBT RBT_Impl.lookup_map_entry lookup_impl_of)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   140
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   141
lemma lookup_map [simp]:
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   142
  "lookup (map f t) k = Option.map (f k) (lookup t k)"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   143
  by (simp add: map_def lookup_RBT lookup_map lookup_impl_of)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   144
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   145
lemma fold_fold:
37462
802619d7576d prefer fold over foldl
haftmann
parents: 37053
diff changeset
   146
  "fold f t = More_List.fold (prod_case f) (entries t)"
39198
f967a16dfcdd expand_fun_eq -> ext_iff
nipkow
parents: 38857
diff changeset
   147
  by (simp add: fold_def ext_iff RBT_Impl.fold_def entries_impl_of)
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   148
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   149
lemma is_empty_empty [simp]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   150
  "is_empty t \<longleftrightarrow> t = empty"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   151
  by (simp add: rbt_eq is_empty_def impl_of_empty split: rbt.split)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   152
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   153
lemma RBT_lookup_empty [simp]: (*FIXME*)
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   154
  "RBT_Impl.lookup t = Map.empty \<longleftrightarrow> t = RBT_Impl.Empty"
39198
f967a16dfcdd expand_fun_eq -> ext_iff
nipkow
parents: 38857
diff changeset
   155
  by (cases t) (auto simp add: ext_iff)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   156
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   157
lemma lookup_empty_empty [simp]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   158
  "lookup t = Map.empty \<longleftrightarrow> t = empty"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   159
  by (cases t) (simp add: empty_def lookup_def RBT_inject RBT_inverse)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   160
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   161
lemma sorted_keys [iff]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   162
  "sorted (keys t)"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   163
  by (simp add: keys_def RBT_Impl.keys_def sorted_entries)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   164
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   165
lemma distinct_keys [iff]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   166
  "distinct (keys t)"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   167
  by (simp add: keys_def RBT_Impl.keys_def distinct_entries)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   168
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   169
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   170
subsection {* Implementation of mappings *}
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   171
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   172
definition Mapping :: "('a\<Colon>linorder, 'b) rbt \<Rightarrow> ('a, 'b) mapping" where
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   173
  "Mapping t = Mapping.Mapping (lookup t)"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   174
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   175
code_datatype Mapping
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   176
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   177
lemma lookup_Mapping [simp, code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   178
  "Mapping.lookup (Mapping t) = lookup t"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   179
  by (simp add: Mapping_def)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   180
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   181
lemma empty_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   182
  "Mapping.empty = Mapping empty"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   183
  by (rule mapping_eqI) simp
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   184
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   185
lemma is_empty_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   186
  "Mapping.is_empty (Mapping t) \<longleftrightarrow> is_empty t"
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   187
  by (simp add: rbt_eq Mapping.is_empty_empty Mapping_def)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   188
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   189
lemma insert_Mapping [code]:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   190
  "Mapping.update k v (Mapping t) = Mapping (insert k v t)"
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   191
  by (rule mapping_eqI) simp
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   192
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   193
lemma delete_Mapping [code]:
37027
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   194
  "Mapping.delete k (Mapping t) = Mapping (delete k t)"
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   195
  by (rule mapping_eqI) simp
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   196
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   197
lemma map_entry_Mapping [code]:
98bfff1d159d implement Mapping.map_entry
haftmann
parents: 36245
diff changeset
   198
  "Mapping.map_entry k f (Mapping t) = Mapping (map_entry k f t)"
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   199
  by (rule mapping_eqI) simp
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   200
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   201
lemma keys_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   202
  "Mapping.keys (Mapping t) = set (keys t)"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   203
  by (simp add: keys_def Mapping_def Mapping.keys_def lookup_def lookup_keys)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   204
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   205
lemma ordered_keys_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   206
  "Mapping.ordered_keys (Mapping t) = keys t"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   207
  by (rule sorted_distinct_set_unique) (simp_all add: ordered_keys_def keys_Mapping)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   208
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   209
lemma Mapping_size_card_keys: (*FIXME*)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   210
  "Mapping.size m = card (Mapping.keys m)"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   211
  by (simp add: Mapping.size_def Mapping.keys_def)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   212
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   213
lemma size_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   214
  "Mapping.size (Mapping t) = length (keys t)"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   215
  by (simp add: Mapping_size_card_keys keys_Mapping distinct_card)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   216
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   217
lemma tabulate_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   218
  "Mapping.tabulate ks f = Mapping (bulkload (List.map (\<lambda>k. (k, f k)) ks))"
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   219
  by (rule mapping_eqI) (simp add: map_of_map_restrict)
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   220
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   221
lemma bulkload_Mapping [code]:
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   222
  "Mapping.bulkload vs = Mapping (bulkload (List.map (\<lambda>n. (n, vs ! n)) [0..<length vs]))"
39198
f967a16dfcdd expand_fun_eq -> ext_iff
nipkow
parents: 38857
diff changeset
   223
  by (rule mapping_eqI) (simp add: map_of_map_restrict ext_iff)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   224
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   225
lemma equal_Mapping [code]:
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   226
  "HOL.equal (Mapping t1) (Mapping t2) \<longleftrightarrow> entries t1 = entries t2"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   227
  by (simp add: equal Mapping_def entries_lookup)
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   228
38857
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   229
lemma [code nbe]:
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   230
  "HOL.equal (x :: (_, _) mapping) x \<longleftrightarrow> True"
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   231
  by (fact equal_refl)
97775f3e8722 renamed class/constant eq to equal; tuned some instantiations
haftmann
parents: 37462
diff changeset
   232
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   233
36176
3fe7e97ccca8 replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents: 36147
diff changeset
   234
hide_const (open) impl_of lookup empty insert delete
36111
5844017e31f8 implementation of mappings by rbts
haftmann
parents: 35617
diff changeset
   235
  entries keys bulkload map_entry map fold
36147
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   236
(*>*)
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   237
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   238
text {* 
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   239
  This theory defines abstract red-black trees as an efficient
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   240
  representation of finite maps, backed by the implementation
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   241
  in @{theory RBT_Impl}.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   242
*}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   243
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   244
subsection {* Data type and invariant *}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   245
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   246
text {*
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   247
  The type @{typ "('k, 'v) RBT_Impl.rbt"} denotes red-black trees with
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   248
  keys of type @{typ "'k"} and values of type @{typ "'v"}. To function
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   249
  properly, the key type musorted belong to the @{text "linorder"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   250
  class.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   251
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   252
  A value @{term t} of this type is a valid red-black tree if it
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   253
  satisfies the invariant @{text "is_rbt t"}.  The abstract type @{typ
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   254
  "('k, 'v) rbt"} always obeys this invariant, and for this reason you
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   255
  should only use this in our application.  Going back to @{typ "('k,
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   256
  'v) RBT_Impl.rbt"} may be necessary in proofs if not yet proven
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   257
  properties about the operations must be established.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   258
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   259
  The interpretation function @{const "RBT.lookup"} returns the partial
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   260
  map represented by a red-black tree:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   261
  @{term_type[display] "RBT.lookup"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   262
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   263
  This function should be used for reasoning about the semantics of the RBT
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   264
  operations. Furthermore, it implements the lookup functionality for
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   265
  the data structure: It is executable and the lookup is performed in
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   266
  $O(\log n)$.  
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   267
*}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   268
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   269
subsection {* Operations *}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   270
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   271
text {*
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   272
  Currently, the following operations are supported:
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   273
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   274
  @{term_type [display] "RBT.empty"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   275
  Returns the empty tree. $O(1)$
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   276
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   277
  @{term_type [display] "RBT.insert"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   278
  Updates the map at a given position. $O(\log n)$
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   279
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   280
  @{term_type [display] "RBT.delete"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   281
  Deletes a map entry at a given position. $O(\log n)$
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   282
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   283
  @{term_type [display] "RBT.entries"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   284
  Return a corresponding key-value list for a tree.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   285
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   286
  @{term_type [display] "RBT.bulkload"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   287
  Builds a tree from a key-value list.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   288
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   289
  @{term_type [display] "RBT.map_entry"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   290
  Maps a single entry in a tree.
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   291
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   292
  @{term_type [display] "RBT.map"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   293
  Maps all values in a tree. $O(n)$
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   294
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   295
  @{term_type [display] "RBT.fold"}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   296
  Folds over all entries in a tree. $O(n)$
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   297
*}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   298
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   299
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   300
subsection {* Invariant preservation *}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   301
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   302
text {*
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   303
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   304
  @{thm Empty_is_rbt}\hfill(@{text "Empty_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   305
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   306
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   307
  @{thm insert_is_rbt}\hfill(@{text "insert_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   308
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   309
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   310
  @{thm delete_is_rbt}\hfill(@{text "delete_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   311
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   312
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   313
  @{thm bulkload_is_rbt}\hfill(@{text "bulkload_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   314
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   315
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   316
  @{thm map_entry_is_rbt}\hfill(@{text "map_entry_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   317
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   318
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   319
  @{thm map_is_rbt}\hfill(@{text "map_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   320
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   321
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   322
  @{thm union_is_rbt}\hfill(@{text "union_is_rbt"})
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   323
*}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   324
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   325
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   326
subsection {* Map Semantics *}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   327
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   328
text {*
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   329
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   330
  \underline{@{text "lookup_empty"}}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   331
  @{thm [display] lookup_empty}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   332
  \vspace{1ex}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   333
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   334
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   335
  \underline{@{text "lookup_insert"}}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   336
  @{thm [display] lookup_insert}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   337
  \vspace{1ex}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   338
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   339
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   340
  \underline{@{text "lookup_delete"}}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   341
  @{thm [display] lookup_delete}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   342
  \vspace{1ex}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   343
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   344
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   345
  \underline{@{text "lookup_bulkload"}}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   346
  @{thm [display] lookup_bulkload}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   347
  \vspace{1ex}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   348
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   349
  \noindent
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   350
  \underline{@{text "lookup_map"}}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   351
  @{thm [display] lookup_map}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   352
  \vspace{1ex}
b43b22f63665 theory RBT with abstract type of red-black trees backed by implementation RBT_Impl
haftmann
parents: 36111
diff changeset
   353
*}
35617
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   354
a6528fb99641 added Table.thy
haftmann
parents:
diff changeset
   355
end