src/HOL/Library/Mapping.thy
author kuncar
Fri Mar 08 13:21:58 2013 +0100 (2013-03-08)
changeset 51379 6dd83e007f56
parent 51375 d9e62d9c98de
child 53013 3fbcfa911863
permissions -rw-r--r--
convert mappings to parametric lifting
kuncar@49929
     1
(*  Title:      HOL/Library/Mapping.thy
kuncar@49929
     2
    Author:     Florian Haftmann and Ondrej Kuncar
kuncar@49929
     3
*)
haftmann@29708
     4
haftmann@29708
     5
header {* An abstract view on maps for code generation. *}
haftmann@29708
     6
haftmann@29708
     7
theory Mapping
kuncar@51375
     8
imports Main Quotient_Option Quotient_List
haftmann@29708
     9
begin
haftmann@29708
    10
kuncar@51379
    11
subsection {* Parametricity transfer rules *}
kuncar@51379
    12
kuncar@51379
    13
lemma empty_transfer: "(A ===> option_rel B) Map.empty Map.empty" by transfer_prover
kuncar@51379
    14
kuncar@51379
    15
lemma lookup_transfer: "((A ===> B) ===> A ===> B) (\<lambda>m k. m k) (\<lambda>m k. m k)" by transfer_prover
kuncar@51379
    16
kuncar@51379
    17
lemma update_transfer:
kuncar@51379
    18
  assumes [transfer_rule]: "bi_unique A"
kuncar@51379
    19
  shows "(A ===> B ===> (A ===> option_rel B) ===> A ===> option_rel B) 
kuncar@51379
    20
          (\<lambda>k v m. m(k \<mapsto> v)) (\<lambda>k v m. m(k \<mapsto> v))"
kuncar@51379
    21
by transfer_prover
kuncar@51379
    22
kuncar@51379
    23
lemma delete_transfer:
kuncar@51379
    24
  assumes [transfer_rule]: "bi_unique A"
kuncar@51379
    25
  shows "(A ===> (A ===> option_rel B) ===> A ===> option_rel B) 
kuncar@51379
    26
          (\<lambda>k m. m(k := None)) (\<lambda>k m. m(k := None))"
kuncar@51379
    27
by transfer_prover
kuncar@51379
    28
kuncar@51379
    29
definition equal_None :: "'a option \<Rightarrow> bool" where "equal_None x \<equiv> x = None"
kuncar@51379
    30
kuncar@51379
    31
lemma [transfer_rule]: "(option_rel A ===> op=) equal_None equal_None" 
kuncar@51379
    32
unfolding fun_rel_def option_rel_unfold equal_None_def by (auto split: option.split)
kuncar@51379
    33
kuncar@51379
    34
lemma dom_transfer:
kuncar@51379
    35
  assumes [transfer_rule]: "bi_total A"
kuncar@51379
    36
  shows "((A ===> option_rel B) ===> set_rel A) dom dom" 
kuncar@51379
    37
unfolding dom_def[abs_def] equal_None_def[symmetric] 
kuncar@51379
    38
by transfer_prover
kuncar@51379
    39
kuncar@51379
    40
lemma map_of_transfer [transfer_rule]:
kuncar@51379
    41
  assumes [transfer_rule]: "bi_unique R1"
kuncar@51379
    42
  shows "(list_all2 (prod_rel R1 R2) ===> R1 ===> option_rel R2) map_of map_of"
kuncar@51379
    43
unfolding map_of_def by transfer_prover
kuncar@51379
    44
kuncar@51379
    45
lemma tabulate_transfer: 
kuncar@51379
    46
  assumes [transfer_rule]: "bi_unique A"
kuncar@51379
    47
  shows "(list_all2 A ===> (A ===> B) ===> A ===> option_rel B) 
kuncar@51379
    48
    (\<lambda>ks f. (map_of (List.map (\<lambda>k. (k, f k)) ks))) (\<lambda>ks f. (map_of (List.map (\<lambda>k. (k, f k)) ks)))"
kuncar@51379
    49
by transfer_prover
kuncar@51379
    50
kuncar@51379
    51
lemma bulkload_transfer: 
kuncar@51379
    52
  "(list_all2 A ===> op= ===> option_rel A) 
kuncar@51379
    53
    (\<lambda>xs k. if k < length xs then Some (xs ! k) else None) (\<lambda>xs k. if k < length xs then Some (xs ! k) else None)"
kuncar@51379
    54
unfolding fun_rel_def 
kuncar@51379
    55
apply clarsimp 
kuncar@51379
    56
apply (erule list_all2_induct) 
kuncar@51379
    57
  apply simp 
kuncar@51379
    58
apply (case_tac xa) 
kuncar@51379
    59
  apply simp 
kuncar@51379
    60
by (auto dest: list_all2_lengthD list_all2_nthD)
kuncar@51379
    61
kuncar@51379
    62
lemma map_transfer: 
kuncar@51379
    63
  "((A ===> B) ===> (C ===> D) ===> (B ===> option_rel C) ===> A ===> option_rel D) 
kuncar@51379
    64
    (\<lambda>f g m. (Option.map g \<circ> m \<circ> f)) (\<lambda>f g m. (Option.map g \<circ> m \<circ> f))"
kuncar@51379
    65
by transfer_prover
kuncar@51379
    66
kuncar@51379
    67
lemma map_entry_transfer:
kuncar@51379
    68
  assumes [transfer_rule]: "bi_unique A"
kuncar@51379
    69
  shows "(A ===> (B ===> B) ===> (A ===> option_rel B) ===> A ===> option_rel B) 
kuncar@51379
    70
    (\<lambda>k f m. (case m k of None \<Rightarrow> m
kuncar@51379
    71
      | Some v \<Rightarrow> m (k \<mapsto> (f v)))) (\<lambda>k f m. (case m k of None \<Rightarrow> m
kuncar@51379
    72
      | Some v \<Rightarrow> m (k \<mapsto> (f v))))"
kuncar@51379
    73
by transfer_prover
kuncar@51379
    74
haftmann@29708
    75
subsection {* Type definition and primitive operations *}
haftmann@29708
    76
wenzelm@49834
    77
typedef ('a, 'b) mapping = "UNIV :: ('a \<rightharpoonup> 'b) set"
kuncar@49929
    78
  morphisms rep Mapping ..
haftmann@37700
    79
kuncar@49929
    80
setup_lifting(no_code) type_definition_mapping
haftmann@37700
    81
kuncar@51379
    82
lift_definition empty :: "('a, 'b) mapping" is Map.empty parametric empty_transfer .
haftmann@37700
    83
kuncar@51379
    84
lift_definition lookup :: "('a, 'b) mapping \<Rightarrow> 'a \<Rightarrow> 'b option" is "\<lambda>m k. m k" 
kuncar@51379
    85
  parametric lookup_transfer .
kuncar@49929
    86
kuncar@51379
    87
lift_definition update :: "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" is "\<lambda>k v m. m(k \<mapsto> v)" 
kuncar@51379
    88
  parametric update_transfer .
haftmann@37700
    89
kuncar@51379
    90
lift_definition delete :: "'a \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" is "\<lambda>k m. m(k := None)" 
kuncar@51379
    91
  parametric delete_transfer .
haftmann@39380
    92
kuncar@51379
    93
lift_definition keys :: "('a, 'b) mapping \<Rightarrow> 'a set" is dom parametric dom_transfer .
haftmann@29708
    94
kuncar@49929
    95
lift_definition tabulate :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) mapping" is
kuncar@51379
    96
  "\<lambda>ks f. (map_of (List.map (\<lambda>k. (k, f k)) ks))" parametric tabulate_transfer .
haftmann@29708
    97
kuncar@49929
    98
lift_definition bulkload :: "'a list \<Rightarrow> (nat, 'a) mapping" is
kuncar@51379
    99
  "\<lambda>xs k. if k < length xs then Some (xs ! k) else None" parametric bulkload_transfer .
haftmann@29708
   100
kuncar@49929
   101
lift_definition map :: "('c \<Rightarrow> 'a) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('c, 'd) mapping" is
kuncar@51379
   102
  "\<lambda>f g m. (Option.map g \<circ> m \<circ> f)" parametric map_transfer .
haftmann@29708
   103
haftmann@51161
   104
haftmann@40605
   105
subsection {* Functorial structure *}
haftmann@40605
   106
haftmann@41505
   107
enriched_type map: map
kuncar@49929
   108
  by (transfer, auto simp add: fun_eq_iff Option.map.compositionality Option.map.id)+
haftmann@40605
   109
haftmann@51161
   110
haftmann@29708
   111
subsection {* Derived operations *}
haftmann@29708
   112
haftmann@35194
   113
definition ordered_keys :: "('a\<Colon>linorder, 'b) mapping \<Rightarrow> 'a list" where
haftmann@37052
   114
  "ordered_keys m = (if finite (keys m) then sorted_list_of_set (keys m) else [])"
haftmann@35194
   115
haftmann@35157
   116
definition is_empty :: "('a, 'b) mapping \<Rightarrow> bool" where
haftmann@37052
   117
  "is_empty m \<longleftrightarrow> keys m = {}"
haftmann@35157
   118
haftmann@35157
   119
definition size :: "('a, 'b) mapping \<Rightarrow> nat" where
haftmann@37052
   120
  "size m = (if finite (keys m) then card (keys m) else 0)"
haftmann@35157
   121
haftmann@35157
   122
definition replace :: "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" where
haftmann@37052
   123
  "replace k v m = (if k \<in> keys m then update k v m else m)"
haftmann@29814
   124
haftmann@37026
   125
definition default :: "'a \<Rightarrow> 'b \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" where
haftmann@37052
   126
  "default k v m = (if k \<in> keys m then m else update k v m)"
haftmann@37026
   127
kuncar@49929
   128
lift_definition map_entry :: "'a \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" is
kuncar@49929
   129
  "\<lambda>k f m. (case m k of None \<Rightarrow> m
kuncar@51379
   130
    | Some v \<Rightarrow> m (k \<mapsto> (f v)))" parametric map_entry_transfer .
kuncar@49929
   131
kuncar@49929
   132
lemma map_entry_code [code]: "map_entry k f m = (case lookup m k of None \<Rightarrow> m
huffman@49975
   133
    | Some v \<Rightarrow> update k (f v) m)"
huffman@49975
   134
  by transfer rule
haftmann@37026
   135
haftmann@37026
   136
definition map_default :: "'a \<Rightarrow> 'b \<Rightarrow> ('b \<Rightarrow> 'b) \<Rightarrow> ('a, 'b) mapping \<Rightarrow> ('a, 'b) mapping" where
haftmann@37026
   137
  "map_default k v f m = map_entry k f (default k v m)" 
haftmann@37026
   138
kuncar@51379
   139
lift_definition assoc_list_to_mapping :: "('k \<times> 'v) list \<Rightarrow> ('k, 'v) mapping"
kuncar@51379
   140
is map_of parametric map_of_transfer .
kuncar@51379
   141
kuncar@51379
   142
lemma assoc_list_to_mapping_code [code]:
kuncar@51379
   143
  "assoc_list_to_mapping xs = foldr (\<lambda>(k, v) m. update k v m) xs empty"
kuncar@51379
   144
by transfer(simp add: map_add_map_of_foldr[symmetric])
kuncar@51379
   145
haftmann@51161
   146
instantiation mapping :: (type, type) equal
haftmann@51161
   147
begin
haftmann@51161
   148
haftmann@51161
   149
definition
haftmann@51161
   150
  "HOL.equal m1 m2 \<longleftrightarrow> (\<forall>k. lookup m1 k = lookup m2 k)"
haftmann@51161
   151
haftmann@51161
   152
instance proof
haftmann@51161
   153
qed (unfold equal_mapping_def, transfer, auto)
haftmann@51161
   154
haftmann@51161
   155
end
haftmann@51161
   156
haftmann@51161
   157
lemma [transfer_rule]:
kuncar@51379
   158
  assumes [transfer_rule]: "bi_total A"
kuncar@51379
   159
  assumes [transfer_rule]: "bi_unique B"
kuncar@51379
   160
  shows  "fun_rel (pcr_mapping A B) (fun_rel (pcr_mapping A B) HOL.iff) HOL.eq HOL.equal"
kuncar@51379
   161
by (unfold equal) transfer_prover
haftmann@51161
   162
haftmann@51161
   163
haftmann@29708
   164
subsection {* Properties *}
haftmann@29708
   165
kuncar@49973
   166
lemma lookup_update: "lookup (update k v m) k = Some v" 
kuncar@49973
   167
  by transfer simp
kuncar@49973
   168
kuncar@49973
   169
lemma lookup_update_neq: "k \<noteq> k' \<Longrightarrow> lookup (update k v m) k' = lookup m k'" 
kuncar@49973
   170
  by transfer simp
kuncar@49973
   171
kuncar@49973
   172
lemma lookup_empty: "lookup empty k = None" 
kuncar@49973
   173
  by transfer simp
kuncar@49973
   174
kuncar@49929
   175
lemma keys_is_none_rep [code_unfold]:
haftmann@37052
   176
  "k \<in> keys m \<longleftrightarrow> \<not> (Option.is_none (lookup m k))"
kuncar@49929
   177
  by transfer (auto simp add: is_none_def)
haftmann@29708
   178
kuncar@49929
   179
lemma tabulate_alt_def:
kuncar@49929
   180
  "map_of (List.map (\<lambda>k. (k, f k)) ks) = (Some o f) |` set ks"
kuncar@49929
   181
  by (induct ks) (auto simp add: tabulate_def restrict_map_def)
haftmann@29826
   182
haftmann@29708
   183
lemma update_update:
haftmann@29708
   184
  "update k v (update k w m) = update k v m"
haftmann@29708
   185
  "k \<noteq> l \<Longrightarrow> update k v (update l w m) = update l w (update k v m)"
kuncar@49929
   186
  by (transfer, simp add: fun_upd_twist)+
haftmann@29708
   187
haftmann@35157
   188
lemma update_delete [simp]:
haftmann@35157
   189
  "update k v (delete k m) = update k v m"
kuncar@49929
   190
  by transfer simp
haftmann@29708
   191
haftmann@29708
   192
lemma delete_update:
haftmann@29708
   193
  "delete k (update k v m) = delete k m"
haftmann@29708
   194
  "k \<noteq> l \<Longrightarrow> delete k (update l v m) = update l v (delete k m)"
kuncar@49929
   195
  by (transfer, simp add: fun_upd_twist)+
haftmann@29708
   196
haftmann@35157
   197
lemma delete_empty [simp]:
haftmann@35157
   198
  "delete k empty = empty"
kuncar@49929
   199
  by transfer simp
haftmann@29708
   200
haftmann@35157
   201
lemma replace_update:
haftmann@37052
   202
  "k \<notin> keys m \<Longrightarrow> replace k v m = m"
haftmann@37052
   203
  "k \<in> keys m \<Longrightarrow> replace k v m = update k v m"
kuncar@49929
   204
  by (transfer, auto simp add: replace_def fun_upd_twist)+
haftmann@29708
   205
haftmann@29708
   206
lemma size_empty [simp]:
haftmann@29708
   207
  "size empty = 0"
kuncar@49929
   208
  unfolding size_def by transfer simp
haftmann@29708
   209
haftmann@29708
   210
lemma size_update:
haftmann@37052
   211
  "finite (keys m) \<Longrightarrow> size (update k v m) =
haftmann@37052
   212
    (if k \<in> keys m then size m else Suc (size m))"
kuncar@49929
   213
  unfolding size_def by transfer (auto simp add: insert_dom)
haftmann@29708
   214
haftmann@29708
   215
lemma size_delete:
haftmann@37052
   216
  "size (delete k m) = (if k \<in> keys m then size m - 1 else size m)"
kuncar@49929
   217
  unfolding size_def by transfer simp
haftmann@29708
   218
haftmann@37052
   219
lemma size_tabulate [simp]:
haftmann@29708
   220
  "size (tabulate ks f) = length (remdups ks)"
kuncar@49929
   221
  unfolding size_def by transfer (auto simp add: tabulate_alt_def card_set comp_def)
haftmann@29708
   222
haftmann@29831
   223
lemma bulkload_tabulate:
haftmann@29826
   224
  "bulkload xs = tabulate [0..<length xs] (nth xs)"
kuncar@49929
   225
  by transfer (auto simp add: tabulate_alt_def)
haftmann@29826
   226
kuncar@49929
   227
lemma is_empty_empty [simp]:
haftmann@37052
   228
  "is_empty empty"
kuncar@49929
   229
  unfolding is_empty_def by transfer simp 
haftmann@37052
   230
haftmann@37052
   231
lemma is_empty_update [simp]:
haftmann@37052
   232
  "\<not> is_empty (update k v m)"
kuncar@49929
   233
  unfolding is_empty_def by transfer simp
haftmann@37052
   234
haftmann@37052
   235
lemma is_empty_delete:
haftmann@37052
   236
  "is_empty (delete k m) \<longleftrightarrow> is_empty m \<or> keys m = {k}"
kuncar@49929
   237
  unfolding is_empty_def by transfer (auto simp del: dom_eq_empty_conv)
haftmann@37052
   238
haftmann@37052
   239
lemma is_empty_replace [simp]:
haftmann@37052
   240
  "is_empty (replace k v m) \<longleftrightarrow> is_empty m"
kuncar@49929
   241
  unfolding is_empty_def replace_def by transfer auto
haftmann@37052
   242
haftmann@37052
   243
lemma is_empty_default [simp]:
haftmann@37052
   244
  "\<not> is_empty (default k v m)"
kuncar@49929
   245
  unfolding is_empty_def default_def by transfer auto
haftmann@37052
   246
haftmann@37052
   247
lemma is_empty_map_entry [simp]:
haftmann@37052
   248
  "is_empty (map_entry k f m) \<longleftrightarrow> is_empty m"
kuncar@49929
   249
  unfolding is_empty_def 
kuncar@49929
   250
  apply transfer by (case_tac "m k") auto
haftmann@37052
   251
haftmann@37052
   252
lemma is_empty_map_default [simp]:
haftmann@37052
   253
  "\<not> is_empty (map_default k v f m)"
haftmann@37052
   254
  by (simp add: map_default_def)
haftmann@37052
   255
haftmann@37052
   256
lemma keys_empty [simp]:
haftmann@37052
   257
  "keys empty = {}"
kuncar@49929
   258
  by transfer simp
haftmann@37052
   259
haftmann@37052
   260
lemma keys_update [simp]:
haftmann@37052
   261
  "keys (update k v m) = insert k (keys m)"
kuncar@49929
   262
  by transfer simp
haftmann@37052
   263
haftmann@37052
   264
lemma keys_delete [simp]:
haftmann@37052
   265
  "keys (delete k m) = keys m - {k}"
kuncar@49929
   266
  by transfer simp
haftmann@37052
   267
haftmann@37052
   268
lemma keys_replace [simp]:
haftmann@37052
   269
  "keys (replace k v m) = keys m"
kuncar@49929
   270
  unfolding replace_def by transfer (simp add: insert_absorb)
haftmann@37052
   271
haftmann@37052
   272
lemma keys_default [simp]:
haftmann@37052
   273
  "keys (default k v m) = insert k (keys m)"
kuncar@49929
   274
  unfolding default_def by transfer (simp add: insert_absorb)
haftmann@37052
   275
haftmann@37052
   276
lemma keys_map_entry [simp]:
haftmann@37052
   277
  "keys (map_entry k f m) = keys m"
kuncar@49929
   278
  apply transfer by (case_tac "m k") auto
haftmann@37052
   279
haftmann@37052
   280
lemma keys_map_default [simp]:
haftmann@37052
   281
  "keys (map_default k v f m) = insert k (keys m)"
haftmann@37052
   282
  by (simp add: map_default_def)
haftmann@37052
   283
haftmann@37052
   284
lemma keys_tabulate [simp]:
haftmann@37026
   285
  "keys (tabulate ks f) = set ks"
kuncar@49929
   286
  by transfer (simp add: map_of_map_restrict o_def)
haftmann@37026
   287
haftmann@37052
   288
lemma keys_bulkload [simp]:
haftmann@37026
   289
  "keys (bulkload xs) = {0..<length xs}"
haftmann@37026
   290
  by (simp add: keys_tabulate bulkload_tabulate)
haftmann@37026
   291
haftmann@37052
   292
lemma distinct_ordered_keys [simp]:
haftmann@37052
   293
  "distinct (ordered_keys m)"
haftmann@37052
   294
  by (simp add: ordered_keys_def)
haftmann@37052
   295
haftmann@37052
   296
lemma ordered_keys_infinite [simp]:
haftmann@37052
   297
  "\<not> finite (keys m) \<Longrightarrow> ordered_keys m = []"
haftmann@37052
   298
  by (simp add: ordered_keys_def)
haftmann@37052
   299
haftmann@37052
   300
lemma ordered_keys_empty [simp]:
haftmann@37052
   301
  "ordered_keys empty = []"
haftmann@37052
   302
  by (simp add: ordered_keys_def)
haftmann@37052
   303
haftmann@37052
   304
lemma ordered_keys_update [simp]:
haftmann@37052
   305
  "k \<in> keys m \<Longrightarrow> ordered_keys (update k v m) = ordered_keys m"
haftmann@37052
   306
  "finite (keys m) \<Longrightarrow> k \<notin> keys m \<Longrightarrow> ordered_keys (update k v m) = insort k (ordered_keys m)"
haftmann@37052
   307
  by (simp_all add: ordered_keys_def) (auto simp only: sorted_list_of_set_insert [symmetric] insert_absorb)
haftmann@37052
   308
haftmann@37052
   309
lemma ordered_keys_delete [simp]:
haftmann@37052
   310
  "ordered_keys (delete k m) = remove1 k (ordered_keys m)"
haftmann@37052
   311
proof (cases "finite (keys m)")
haftmann@37052
   312
  case False then show ?thesis by simp
haftmann@37052
   313
next
haftmann@37052
   314
  case True note fin = True
haftmann@37052
   315
  show ?thesis
haftmann@37052
   316
  proof (cases "k \<in> keys m")
haftmann@37052
   317
    case False with fin have "k \<notin> set (sorted_list_of_set (keys m))" by simp
haftmann@37052
   318
    with False show ?thesis by (simp add: ordered_keys_def remove1_idem)
haftmann@37052
   319
  next
haftmann@37052
   320
    case True with fin show ?thesis by (simp add: ordered_keys_def sorted_list_of_set_remove)
haftmann@37052
   321
  qed
haftmann@37052
   322
qed
haftmann@37052
   323
haftmann@37052
   324
lemma ordered_keys_replace [simp]:
haftmann@37052
   325
  "ordered_keys (replace k v m) = ordered_keys m"
haftmann@37052
   326
  by (simp add: replace_def)
haftmann@37052
   327
haftmann@37052
   328
lemma ordered_keys_default [simp]:
haftmann@37052
   329
  "k \<in> keys m \<Longrightarrow> ordered_keys (default k v m) = ordered_keys m"
haftmann@37052
   330
  "finite (keys m) \<Longrightarrow> k \<notin> keys m \<Longrightarrow> ordered_keys (default k v m) = insort k (ordered_keys m)"
haftmann@37052
   331
  by (simp_all add: default_def)
haftmann@37052
   332
haftmann@37052
   333
lemma ordered_keys_map_entry [simp]:
haftmann@37052
   334
  "ordered_keys (map_entry k f m) = ordered_keys m"
haftmann@37052
   335
  by (simp add: ordered_keys_def)
haftmann@37052
   336
haftmann@37052
   337
lemma ordered_keys_map_default [simp]:
haftmann@37052
   338
  "k \<in> keys m \<Longrightarrow> ordered_keys (map_default k v f m) = ordered_keys m"
haftmann@37052
   339
  "finite (keys m) \<Longrightarrow> k \<notin> keys m \<Longrightarrow> ordered_keys (map_default k v f m) = insort k (ordered_keys m)"
haftmann@37052
   340
  by (simp_all add: map_default_def)
haftmann@37052
   341
haftmann@37052
   342
lemma ordered_keys_tabulate [simp]:
haftmann@37052
   343
  "ordered_keys (tabulate ks f) = sort (remdups ks)"
haftmann@37052
   344
  by (simp add: ordered_keys_def sorted_list_of_set_sort_remdups)
haftmann@37052
   345
haftmann@37052
   346
lemma ordered_keys_bulkload [simp]:
haftmann@37052
   347
  "ordered_keys (bulkload ks) = [0..<length ks]"
haftmann@37052
   348
  by (simp add: ordered_keys_def)
haftmann@36110
   349
haftmann@31459
   350
haftmann@37700
   351
subsection {* Code generator setup *}
haftmann@31459
   352
haftmann@37701
   353
code_datatype empty update
haftmann@37701
   354
kuncar@49929
   355
hide_const (open) empty is_empty rep lookup update delete ordered_keys keys size
haftmann@40605
   356
  replace default map_entry map_default tabulate bulkload map
haftmann@35157
   357
huffman@49975
   358
end
haftmann@51161
   359
kuncar@51379
   360