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