src/HOL/Library/RBT_Mapping.thy
author nipkow
Mon, 30 May 2022 20:58:45 +0200
changeset 75496 99b37c391433
parent 74157 8e2355ddce1b
permissions -rw-r--r--
Added lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
     1
(*  Title:      HOL/Library/RBT_Mapping.thy
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
     2
    Author:     Florian Haftmann and Ondrej Kuncar
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
     3
*)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
     4
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
     5
section \<open>Implementation of mappings with Red-Black Trees\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
     6
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
     7
(*<*)
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
     8
theory RBT_Mapping
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
     9
imports RBT Mapping
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    10
begin
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    11
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
    12
subsection \<open>Implementation of mappings\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    13
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    14
context includes rbt.lifting begin
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 60500
diff changeset
    15
lift_definition Mapping :: "('a::linorder, 'b) rbt \<Rightarrow> ('a, 'b) mapping" is RBT.lookup .
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    16
end
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    17
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    18
code_datatype Mapping
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    19
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    20
context includes rbt.lifting begin
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    21
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    22
lemma lookup_Mapping [simp, code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    23
  "Mapping.lookup (Mapping t) = RBT.lookup t"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    24
   by (transfer fixing: t) rule
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    25
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    26
lemma empty_Mapping [code]: "Mapping.empty = Mapping RBT.empty"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    27
proof -
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    28
  note RBT.empty.transfer[transfer_rule del]
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    29
  show ?thesis by transfer simp
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    30
qed
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    31
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    32
lemma is_empty_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    33
  "Mapping.is_empty (Mapping t) \<longleftrightarrow> RBT.is_empty t"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    34
  unfolding is_empty_def by (transfer fixing: t) simp
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    35
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    36
lemma insert_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    37
  "Mapping.update k v (Mapping t) = Mapping (RBT.insert k v t)"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    38
  by (transfer fixing: t) simp
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    39
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    40
lemma delete_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    41
  "Mapping.delete k (Mapping t) = Mapping (RBT.delete k t)"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    42
  by (transfer fixing: t) simp
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    43
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    44
lemma map_entry_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    45
  "Mapping.map_entry k f (Mapping t) = Mapping (RBT.map_entry k f t)"
63649
e690d6f2185b tuned proofs;
wenzelm
parents: 63194
diff changeset
    46
  apply (transfer fixing: t)
e690d6f2185b tuned proofs;
wenzelm
parents: 63194
diff changeset
    47
  apply (case_tac "RBT.lookup t k")
e690d6f2185b tuned proofs;
wenzelm
parents: 63194
diff changeset
    48
   apply auto
e690d6f2185b tuned proofs;
wenzelm
parents: 63194
diff changeset
    49
  done
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    50
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    51
lemma keys_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    52
  "Mapping.keys (Mapping t) = set (RBT.keys t)"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    53
by (transfer fixing: t) (simp add: lookup_keys)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    54
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    55
lemma ordered_keys_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    56
  "Mapping.ordered_keys (Mapping t) = RBT.keys t"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    57
unfolding ordered_keys_def 
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    58
by (transfer fixing: t) (auto simp add: lookup_keys intro: sorted_distinct_set_unique)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    59
73832
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    60
lemma Map_graph_lookup: "Map.graph (RBT.lookup t) = set (RBT.entries t)"
74157
8e2355ddce1b add/rename some theorems about Map(pings)
Lukas Stevens <mail@lukas-stevens.de>
parents: 73832
diff changeset
    61
  by (metis RBT.distinct_entries RBT.map_of_entries graph_map_of_if_distinct_dom)
73832
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    62
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    63
lemma entries_Mapping [code]: "Mapping.entries (Mapping t) = set (RBT.entries t)"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    64
  by (transfer fixing: t) (fact Map_graph_lookup)
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    65
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    66
lemma ordered_entries_Mapping [code]: "Mapping.ordered_entries (Mapping t) = RBT.entries t"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    67
proof -
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    68
  note folding_Map_graph.idem_if_sorted_distinct[
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    69
      where ?m="RBT.lookup t", OF _ _ folding_Map_graph.distinct_if_distinct_map]
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    70
  then show ?thesis
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    71
    unfolding ordered_entries_def
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    72
    by (transfer fixing: t) (auto simp: Map_graph_lookup distinct_entries sorted_entries)
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    73
qed
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    74
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    75
lemma fold_Mapping [code]: "Mapping.fold f (Mapping t) a = RBT.fold f t a"
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    76
  by (simp add: Mapping.fold_def fold_fold ordered_entries_Mapping)
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
    77
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    78
lemma Mapping_size_card_keys: (*FIXME*)
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    79
  "Mapping.size m = card (Mapping.keys m)"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    80
unfolding size_def by transfer simp
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    81
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    82
lemma size_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
    83
  "Mapping.size (Mapping t) = length (RBT.keys t)"
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    84
unfolding size_def
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    85
by (transfer fixing: t) (simp add: lookup_keys distinct_card)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
    86
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    87
context
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    88
  notes RBT.bulkload.transfer[transfer_rule del]
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    89
begin
60373
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    90
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    91
lemma tabulate_Mapping [code]:
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    92
  "Mapping.tabulate ks f = Mapping (RBT.bulkload (List.map (\<lambda>k. (k, f k)) ks))"
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    93
by transfer (simp add: map_of_map_restrict)
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    94
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    95
lemma bulkload_Mapping [code]:
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    96
  "Mapping.bulkload vs = Mapping (RBT.bulkload (List.map (\<lambda>n. (n, vs ! n)) [0..<length vs]))"
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    97
by transfer (simp add: map_of_map_restrict fun_eq_iff)
68eb60fd22a6 tuned whitespace;
wenzelm
parents: 58881
diff changeset
    98
49929
70300f1b6835 update RBT_Mapping, AList_Mapping and Mapping to use lifting/transfer
kuncar
parents: 47450
diff changeset
    99
end
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   100
63194
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   101
lemma map_values_Mapping [code]: 
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   102
  "Mapping.map_values f (Mapping t) = Mapping (RBT.map f t)"
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   103
  by (transfer fixing: t) (auto simp: fun_eq_iff)
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   104
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   105
lemma filter_Mapping [code]: 
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   106
  "Mapping.filter P (Mapping t) = Mapping (RBT.filter P t)"
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   107
  by (transfer' fixing: P t) (simp add: RBT.lookup_filter fun_eq_iff)
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   108
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   109
lemma combine_with_key_Mapping [code]:
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   110
  "Mapping.combine_with_key f (Mapping t1) (Mapping t2) =
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   111
     Mapping (RBT.combine_with_key f t1 t2)"
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   112
  by (transfer fixing: f t1 t2) (simp_all add: fun_eq_iff)
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   113
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   114
lemma combine_Mapping [code]:
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   115
  "Mapping.combine f (Mapping t1) (Mapping t2) =
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   116
     Mapping (RBT.combine f t1 t2)"
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   117
  by (transfer fixing: f t1 t2) (simp_all add: fun_eq_iff)
0b7bdb75f451 Added code generation for PMFs
eberlm
parents: 62390
diff changeset
   118
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   119
lemma equal_Mapping [code]:
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
   120
  "HOL.equal (Mapping t1) (Mapping t2) \<longleftrightarrow> RBT.entries t1 = RBT.entries t2"
73832
9db620f007fa More general fold function for maps
nipkow
parents: 69593
diff changeset
   121
  by (transfer fixing: t1 t2) (simp add: RBT.entries_lookup)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   122
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   123
lemma [code nbe]:
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   124
  "HOL.equal (x :: (_, _) mapping) x \<longleftrightarrow> True"
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   125
  by (fact equal_refl)
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   126
56019
682bba24e474 hide implementation details
kuncar
parents: 51438
diff changeset
   127
end
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   128
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   129
(*>*)
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   130
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   131
text \<open>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   132
  This theory defines abstract red-black trees as an efficient
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   133
  representation of finite maps, backed by the implementation
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   134
  in \<^theory>\<open>HOL-Library.RBT_Impl\<close>.
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   135
\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   136
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   137
subsection \<open>Data type and invariant\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   138
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   139
text \<open>
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   140
  The type \<^typ>\<open>('k, 'v) RBT_Impl.rbt\<close> denotes red-black trees with
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   141
  keys of type \<^typ>\<open>'k\<close> and values of type \<^typ>\<open>'v\<close>. To function
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   142
  properly, the key type musorted belong to the \<open>linorder\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   143
  class.
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   144
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   145
  A value \<^term>\<open>t\<close> of this type is a valid red-black tree if it
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   146
  satisfies the invariant \<open>is_rbt t\<close>.  The abstract type \<^typ>\<open>('k, 'v) rbt\<close> always obeys this invariant, and for this reason you
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   147
  should only use this in our application.  Going back to \<^typ>\<open>('k,
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   148
  'v) RBT_Impl.rbt\<close> may be necessary in proofs if not yet proven
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   149
  properties about the operations must be established.
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   150
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68484
diff changeset
   151
  The interpretation function \<^const>\<open>RBT.lookup\<close> returns the partial
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   152
  map represented by a red-black tree:
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   153
  @{term_type[display] "RBT.lookup"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   154
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   155
  This function should be used for reasoning about the semantics of the RBT
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   156
  operations. Furthermore, it implements the lookup functionality for
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   157
  the data structure: It is executable and the lookup is performed in
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   158
  $O(\log n)$.  
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   159
\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   160
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   161
subsection \<open>Operations\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   162
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   163
text \<open>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   164
  Currently, the following operations are supported:
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   165
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   166
  @{term_type [display] "RBT.empty"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   167
  Returns the empty tree. $O(1)$
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   168
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   169
  @{term_type [display] "RBT.insert"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   170
  Updates the map at a given position. $O(\log n)$
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   171
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   172
  @{term_type [display] "RBT.delete"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   173
  Deletes a map entry at a given position. $O(\log n)$
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   174
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   175
  @{term_type [display] "RBT.entries"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   176
  Return a corresponding key-value list for a tree.
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   177
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   178
  @{term_type [display] "RBT.bulkload"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   179
  Builds a tree from a key-value list.
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   180
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   181
  @{term_type [display] "RBT.map_entry"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   182
  Maps a single entry in a tree.
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   183
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   184
  @{term_type [display] "RBT.map"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   185
  Maps all values in a tree. $O(n)$
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   186
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   187
  @{term_type [display] "RBT.fold"}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   188
  Folds over all entries in a tree. $O(n)$
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   189
\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   190
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   191
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   192
subsection \<open>Invariant preservation\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   193
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   194
text \<open>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   195
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   196
  @{thm Empty_is_rbt}\hfill(\<open>Empty_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   197
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   198
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   199
  @{thm rbt_insert_is_rbt}\hfill(\<open>rbt_insert_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   200
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   201
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   202
  @{thm rbt_delete_is_rbt}\hfill(\<open>delete_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   203
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   204
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   205
  @{thm rbt_bulkload_is_rbt}\hfill(\<open>bulkload_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   206
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   207
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   208
  @{thm rbt_map_entry_is_rbt}\hfill(\<open>map_entry_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   209
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   210
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   211
  @{thm map_is_rbt}\hfill(\<open>map_is_rbt\<close>)
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   212
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   213
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   214
  @{thm rbt_union_is_rbt}\hfill(\<open>union_is_rbt\<close>)
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   215
\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   216
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   217
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   218
subsection \<open>Map Semantics\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   219
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   220
text \<open>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   221
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   222
  \underline{\<open>lookup_empty\<close>}
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   223
  @{thm [display] lookup_empty}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   224
  \vspace{1ex}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   225
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   226
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   227
  \underline{\<open>lookup_insert\<close>}
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   228
  @{thm [display] lookup_insert}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   229
  \vspace{1ex}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   230
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   231
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   232
  \underline{\<open>lookup_delete\<close>}
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   233
  @{thm [display] lookup_delete}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   234
  \vspace{1ex}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   235
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   236
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   237
  \underline{\<open>lookup_bulkload\<close>}
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   238
  @{thm [display] lookup_bulkload}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   239
  \vspace{1ex}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   240
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   241
  \noindent
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 61076
diff changeset
   242
  \underline{\<open>lookup_map\<close>}
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   243
  @{thm [display] lookup_map}
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   244
  \vspace{1ex}
60500
903bb1495239 isabelle update_cartouches;
wenzelm
parents: 60373
diff changeset
   245
\<close>
43124
fdb7e1d5f762 splitting RBT theory into RBT and RBT_Mapping
bulwahn
parents:
diff changeset
   246
62390
842917225d56 more canonical names
nipkow
parents: 61585
diff changeset
   247
end