src/HOL/Library/AssocList.thy
author haftmann
Mon Jul 07 08:47:17 2008 +0200 (2008-07-07)
changeset 27487 c8a6ce181805
parent 27368 9f90ac19e32b
child 30235 58d147683393
permissions -rw-r--r--
absolute imports of HOL/*.thy theories
haftmann@22803
     1
(*  Title:      HOL/Library/AssocList.thy
schirmer@19234
     2
    ID:         $Id$
schirmer@19234
     3
    Author:     Norbert Schirmer, Tobias Nipkow, Martin Wildmoser
schirmer@19234
     4
*)
schirmer@19234
     5
schirmer@19234
     6
header {* Map operations implemented on association lists*}
schirmer@19234
     7
schirmer@19234
     8
theory AssocList 
haftmann@27487
     9
imports Plain "~~/src/HOL/Map"
schirmer@19234
    10
begin
schirmer@19234
    11
haftmann@22740
    12
text {*
haftmann@22740
    13
  The operations preserve distinctness of keys and 
haftmann@22740
    14
  function @{term "clearjunk"} distributes over them. Since 
haftmann@22740
    15
  @{term clearjunk} enforces distinctness of keys it can be used
haftmann@22740
    16
  to establish the invariant, e.g. for inductive proofs.
haftmann@22740
    17
*}
schirmer@19234
    18
haftmann@26152
    19
primrec
haftmann@22740
    20
  delete :: "'key \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    21
where
wenzelm@23373
    22
    "delete k [] = []"
haftmann@22740
    23
  | "delete k (p#ps) = (if fst p = k then delete k ps else p # delete k ps)"
nipkow@19323
    24
haftmann@26152
    25
primrec
haftmann@22740
    26
  update :: "'key \<Rightarrow> 'val \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    27
where
haftmann@22740
    28
    "update k v [] = [(k, v)]"
haftmann@22740
    29
  | "update k v (p#ps) = (if fst p = k then (k, v) # ps else p # update k v ps)"
schirmer@19234
    30
haftmann@26152
    31
primrec
haftmann@22740
    32
  updates :: "'key list \<Rightarrow> 'val list \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    33
where
haftmann@22740
    34
    "updates [] vs ps = ps"
haftmann@22740
    35
  | "updates (k#ks) vs ps = (case vs
haftmann@22740
    36
      of [] \<Rightarrow> ps
haftmann@22740
    37
       | (v#vs') \<Rightarrow> updates ks vs' (update k v ps))"
nipkow@19323
    38
haftmann@26152
    39
primrec
haftmann@22740
    40
  merge :: "('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    41
where
haftmann@22740
    42
    "merge qs [] = qs"
haftmann@22740
    43
  | "merge qs (p#ps) = update (fst p) (snd p) (merge qs ps)"
schirmer@19234
    44
schirmer@19234
    45
lemma length_delete_le: "length (delete k al) \<le> length al"
schirmer@19234
    46
proof (induct al)
haftmann@22740
    47
  case Nil thus ?case by simp
schirmer@19234
    48
next
schirmer@19234
    49
  case (Cons a al)
schirmer@19234
    50
  note length_filter_le [of "\<lambda>p. fst p \<noteq> fst a" al] 
schirmer@19234
    51
  also have "\<And>n. n \<le> Suc n"
schirmer@19234
    52
    by simp
nipkow@23281
    53
  finally have "length [p\<leftarrow>al . fst p \<noteq> fst a] \<le> Suc (length al)" .
schirmer@19234
    54
  with Cons show ?case
haftmann@22740
    55
    by auto
schirmer@19234
    56
qed
schirmer@19234
    57
haftmann@22740
    58
lemma compose_hint [simp]:
haftmann@22740
    59
  "length (delete k al) < Suc (length al)"
schirmer@19234
    60
proof -
schirmer@19234
    61
  note length_delete_le
schirmer@19234
    62
  also have "\<And>n. n < Suc n"
schirmer@19234
    63
    by simp
schirmer@19234
    64
  finally show ?thesis .
schirmer@19234
    65
qed
schirmer@19234
    66
haftmann@26152
    67
fun
haftmann@22740
    68
  compose :: "('key \<times> 'a) list \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('key \<times> 'b) list"
haftmann@22740
    69
where
haftmann@22740
    70
    "compose [] ys = []"
haftmann@22740
    71
  | "compose (x#xs) ys = (case map_of ys (snd x)
haftmann@22740
    72
       of None \<Rightarrow> compose (delete (fst x) xs) ys
haftmann@22740
    73
        | Some v \<Rightarrow> (fst x, v) # compose xs ys)"
schirmer@19234
    74
haftmann@26152
    75
primrec
haftmann@22740
    76
  restrict :: "'key set \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    77
where
wenzelm@23373
    78
    "restrict A [] = []"
haftmann@22740
    79
  | "restrict A (p#ps) = (if fst p \<in> A then p#restrict A ps else restrict A ps)"
schirmer@19234
    80
haftmann@26152
    81
primrec
haftmann@22740
    82
  map_ran :: "('key \<Rightarrow> 'val \<Rightarrow> 'val) \<Rightarrow> ('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    83
where
wenzelm@23373
    84
    "map_ran f [] = []"
haftmann@22740
    85
  | "map_ran f (p#ps) = (fst p, f (fst p) (snd p)) # map_ran f ps"
haftmann@22740
    86
haftmann@22740
    87
fun
haftmann@22740
    88
  clearjunk  :: "('key \<times> 'val) list \<Rightarrow> ('key \<times> 'val) list"
haftmann@22740
    89
where
wenzelm@23373
    90
    "clearjunk [] = []"  
haftmann@22740
    91
  | "clearjunk (p#ps) = p # clearjunk (delete (fst p) ps)"
haftmann@22740
    92
haftmann@22740
    93
lemmas [simp del] = compose_hint
schirmer@19234
    94
schirmer@19234
    95
schirmer@19234
    96
subsection {* @{const delete} *}
schirmer@19234
    97
wenzelm@26304
    98
lemma delete_eq:
haftmann@22740
    99
  "delete k xs = filter (\<lambda>p. fst p \<noteq> k) xs"
haftmann@22740
   100
  by (induct xs) auto
schirmer@19234
   101
haftmann@22740
   102
lemma delete_id [simp]: "k \<notin> fst ` set al \<Longrightarrow> delete k al = al"
wenzelm@21404
   103
  by (induct al) auto
schirmer@19234
   104
schirmer@19234
   105
lemma delete_conv: "map_of (delete k al) k' = ((map_of al)(k := None)) k'"
schirmer@19234
   106
  by (induct al) auto
schirmer@19234
   107
schirmer@19234
   108
lemma delete_conv': "map_of (delete k al) = ((map_of al)(k := None))"
schirmer@19234
   109
  by (rule ext) (rule delete_conv)
schirmer@19234
   110
schirmer@19234
   111
lemma delete_idem: "delete k (delete k al) = delete k al"
schirmer@19234
   112
  by (induct al) auto
schirmer@19234
   113
wenzelm@21404
   114
lemma map_of_delete [simp]:
wenzelm@21404
   115
    "k' \<noteq> k \<Longrightarrow> map_of (delete k al) k' = map_of al k'"
wenzelm@21404
   116
  by (induct al) auto
schirmer@19234
   117
schirmer@19234
   118
lemma delete_notin_dom: "k \<notin> fst ` set (delete k al)"
schirmer@19234
   119
  by (induct al) auto
schirmer@19234
   120
schirmer@19234
   121
lemma dom_delete_subset: "fst ` set (delete k al) \<subseteq> fst ` set al"
schirmer@19234
   122
  by (induct al) auto
schirmer@19234
   123
schirmer@19234
   124
lemma distinct_delete:
schirmer@19234
   125
  assumes "distinct (map fst al)" 
schirmer@19234
   126
  shows "distinct (map fst (delete k al))"
wenzelm@23373
   127
using assms
schirmer@19234
   128
proof (induct al)
schirmer@19234
   129
  case Nil thus ?case by simp
schirmer@19234
   130
next
schirmer@19234
   131
  case (Cons a al)
schirmer@19234
   132
  from Cons.prems obtain 
schirmer@19234
   133
    a_notin_al: "fst a \<notin> fst ` set al" and
schirmer@19234
   134
    dist_al: "distinct (map fst al)"
schirmer@19234
   135
    by auto
schirmer@19234
   136
  show ?case
schirmer@19234
   137
  proof (cases "fst a = k")
schirmer@19234
   138
    case True
wenzelm@23373
   139
    with Cons dist_al show ?thesis by simp
schirmer@19234
   140
  next
schirmer@19234
   141
    case False
schirmer@19234
   142
    from dist_al
schirmer@19234
   143
    have "distinct (map fst (delete k al))"
schirmer@19234
   144
      by (rule Cons.hyps)
schirmer@19234
   145
    moreover from a_notin_al dom_delete_subset [of k al] 
schirmer@19234
   146
    have "fst a \<notin> fst ` set (delete k al)"
schirmer@19234
   147
      by blast
schirmer@19234
   148
    ultimately show ?thesis using False by simp
schirmer@19234
   149
  qed
schirmer@19234
   150
qed
schirmer@19234
   151
schirmer@19234
   152
lemma delete_twist: "delete x (delete y al) = delete y (delete x al)"
schirmer@19234
   153
  by (induct al) auto
schirmer@19234
   154
schirmer@19234
   155
lemma clearjunk_delete: "clearjunk (delete x al) = delete x (clearjunk al)"
schirmer@19234
   156
  by (induct al rule: clearjunk.induct) (auto simp add: delete_idem delete_twist)
schirmer@19234
   157
wenzelm@23373
   158
schirmer@19234
   159
subsection {* @{const clearjunk} *}
schirmer@19234
   160
schirmer@19234
   161
lemma insert_fst_filter: 
schirmer@19234
   162
  "insert a(fst ` {x \<in> set ps. fst x \<noteq> a}) = insert a (fst ` set ps)"
schirmer@19234
   163
  by (induct ps) auto
schirmer@19234
   164
schirmer@19234
   165
lemma dom_clearjunk: "fst ` set (clearjunk al) = fst ` set al"
wenzelm@26304
   166
  by (induct al rule: clearjunk.induct) (simp_all add: insert_fst_filter delete_eq)
schirmer@19234
   167
schirmer@19234
   168
lemma notin_filter_fst: "a \<notin> fst ` {x \<in> set ps. fst x \<noteq> a}"
schirmer@19234
   169
  by (induct ps) auto
schirmer@19234
   170
schirmer@19234
   171
lemma distinct_clearjunk [simp]: "distinct (map fst (clearjunk al))"
schirmer@19234
   172
  by (induct al rule: clearjunk.induct) 
wenzelm@26304
   173
     (simp_all add: dom_clearjunk notin_filter_fst delete_eq)
schirmer@19234
   174
nipkow@23281
   175
lemma map_of_filter: "k \<noteq> a \<Longrightarrow> map_of [q\<leftarrow>ps . fst q \<noteq> a] k = map_of ps k"
schirmer@19234
   176
  by (induct ps) auto
schirmer@19234
   177
schirmer@19234
   178
lemma map_of_clearjunk: "map_of (clearjunk al) = map_of al"
schirmer@19234
   179
  apply (rule ext)
schirmer@19234
   180
  apply (induct al rule: clearjunk.induct)
schirmer@19234
   181
  apply  simp
schirmer@19234
   182
  apply (simp add: map_of_filter)
schirmer@19234
   183
  done
schirmer@19234
   184
schirmer@19234
   185
lemma length_clearjunk: "length (clearjunk al) \<le> length al"
schirmer@19234
   186
proof (induct al rule: clearjunk.induct [case_names Nil Cons])
schirmer@19234
   187
  case Nil thus ?case by simp
schirmer@19234
   188
next
haftmann@22740
   189
  case (Cons p ps)
nipkow@23281
   190
  from Cons have "length (clearjunk [q\<leftarrow>ps . fst q \<noteq> fst p]) \<le> length [q\<leftarrow>ps . fst q \<noteq> fst p]" 
wenzelm@26304
   191
    by (simp add: delete_eq)
schirmer@19234
   192
  also have "\<dots> \<le> length ps"
schirmer@19234
   193
    by simp
schirmer@19234
   194
  finally show ?case
wenzelm@26304
   195
    by (simp add: delete_eq)
schirmer@19234
   196
qed
schirmer@19234
   197
nipkow@23281
   198
lemma notin_fst_filter: "a \<notin> fst ` set ps \<Longrightarrow> [q\<leftarrow>ps . fst q \<noteq> a] = ps"
schirmer@19234
   199
  by (induct ps) auto
schirmer@19234
   200
            
schirmer@19234
   201
lemma distinct_clearjunk_id [simp]: "distinct (map fst al) \<Longrightarrow> clearjunk al = al"
schirmer@19234
   202
  by (induct al rule: clearjunk.induct) (auto simp add: notin_fst_filter)
schirmer@19234
   203
schirmer@19234
   204
lemma clearjunk_idem: "clearjunk (clearjunk al) = clearjunk al"
schirmer@19234
   205
  by simp
schirmer@19234
   206
wenzelm@23373
   207
schirmer@19234
   208
subsection {* @{const dom} and @{term "ran"} *}
schirmer@19234
   209
schirmer@19234
   210
lemma dom_map_of': "fst ` set al = dom (map_of al)"
schirmer@19234
   211
  by (induct al) auto
schirmer@19234
   212
schirmer@19234
   213
lemmas dom_map_of = dom_map_of' [symmetric]
schirmer@19234
   214
schirmer@19234
   215
lemma ran_clearjunk: "ran (map_of (clearjunk al)) = ran (map_of al)"
schirmer@19234
   216
  by (simp add: map_of_clearjunk)
schirmer@19234
   217
schirmer@19234
   218
lemma ran_distinct: 
schirmer@19234
   219
  assumes dist: "distinct (map fst al)" 
schirmer@19234
   220
  shows "ran (map_of al) = snd ` set al"
schirmer@19234
   221
using dist
schirmer@19234
   222
proof (induct al) 
schirmer@19234
   223
  case Nil
schirmer@19234
   224
  thus ?case by simp
schirmer@19234
   225
next
schirmer@19234
   226
  case (Cons a al)
schirmer@19234
   227
  hence hyp: "snd ` set al = ran (map_of al)"
schirmer@19234
   228
    by simp
schirmer@19234
   229
schirmer@19234
   230
  have "ran (map_of (a # al)) = {snd a} \<union> ran (map_of al)"
schirmer@19234
   231
  proof 
schirmer@19234
   232
    show "ran (map_of (a # al)) \<subseteq> {snd a} \<union> ran (map_of al)"
schirmer@19234
   233
    proof   
schirmer@19234
   234
      fix v
schirmer@19234
   235
      assume "v \<in> ran (map_of (a#al))"
schirmer@19234
   236
      then obtain x where "map_of (a#al) x = Some v"
schirmer@19234
   237
	by (auto simp add: ran_def)
schirmer@19234
   238
      then show "v \<in> {snd a} \<union> ran (map_of al)"
schirmer@19234
   239
	by (auto split: split_if_asm simp add: ran_def)
schirmer@19234
   240
    qed
schirmer@19234
   241
  next
schirmer@19234
   242
    show "{snd a} \<union> ran (map_of al) \<subseteq> ran (map_of (a # al))"
schirmer@19234
   243
    proof 
schirmer@19234
   244
      fix v
schirmer@19234
   245
      assume v_in: "v \<in> {snd a} \<union> ran (map_of al)"
schirmer@19234
   246
      show "v \<in> ran (map_of (a#al))"
schirmer@19234
   247
      proof (cases "v=snd a")
schirmer@19234
   248
	case True
schirmer@19234
   249
	with v_in show ?thesis
schirmer@19234
   250
	  by (auto simp add: ran_def)
schirmer@19234
   251
      next
schirmer@19234
   252
	case False
schirmer@19234
   253
	with v_in have "v \<in> ran (map_of al)" by auto
schirmer@19234
   254
	then obtain x where al_x: "map_of al x = Some v"
schirmer@19234
   255
	  by (auto simp add: ran_def)
schirmer@19234
   256
	from map_of_SomeD [OF this]
schirmer@19234
   257
	have "x \<in> fst ` set al"
schirmer@19234
   258
	  by (force simp add: image_def)
schirmer@19234
   259
	with Cons.prems have "x\<noteq>fst a"
schirmer@19234
   260
	  by - (rule ccontr,simp)
schirmer@19234
   261
	with al_x
schirmer@19234
   262
	show ?thesis
schirmer@19234
   263
	  by (auto simp add: ran_def)
schirmer@19234
   264
      qed
schirmer@19234
   265
    qed
schirmer@19234
   266
  qed
schirmer@19234
   267
  with hyp show ?case
schirmer@19234
   268
    by (simp only:) auto
schirmer@19234
   269
qed
schirmer@19234
   270
schirmer@19234
   271
lemma ran_map_of: "ran (map_of al) = snd ` set (clearjunk al)"
schirmer@19234
   272
proof -
schirmer@19234
   273
  have "ran (map_of al) = ran (map_of (clearjunk al))"
schirmer@19234
   274
    by (simp add: ran_clearjunk)
schirmer@19234
   275
  also have "\<dots> = snd ` set (clearjunk al)"
schirmer@19234
   276
    by (simp add: ran_distinct)
schirmer@19234
   277
  finally show ?thesis .
schirmer@19234
   278
qed
schirmer@19234
   279
   
wenzelm@23373
   280
schirmer@19234
   281
subsection {* @{const update} *}
schirmer@19234
   282
schirmer@19234
   283
lemma update_conv: "map_of (update k v al) k' = ((map_of al)(k\<mapsto>v)) k'"
schirmer@19234
   284
  by (induct al) auto
schirmer@19234
   285
schirmer@19234
   286
lemma update_conv': "map_of (update k v al)  = ((map_of al)(k\<mapsto>v))"
schirmer@19234
   287
  by (rule ext) (rule update_conv)
schirmer@19234
   288
schirmer@19234
   289
lemma dom_update: "fst ` set (update k v al) = {k} \<union> fst ` set al"
schirmer@19234
   290
  by (induct al) auto
schirmer@19234
   291
schirmer@19234
   292
lemma distinct_update:
schirmer@19234
   293
  assumes "distinct (map fst al)" 
schirmer@19234
   294
  shows "distinct (map fst (update k v al))"
wenzelm@23373
   295
using assms
schirmer@19234
   296
proof (induct al)
schirmer@19234
   297
  case Nil thus ?case by simp
schirmer@19234
   298
next
schirmer@19234
   299
  case (Cons a al)
schirmer@19234
   300
  from Cons.prems obtain 
schirmer@19234
   301
    a_notin_al: "fst a \<notin> fst ` set al" and
schirmer@19234
   302
    dist_al: "distinct (map fst al)"
schirmer@19234
   303
    by auto
schirmer@19234
   304
  show ?case
schirmer@19234
   305
  proof (cases "fst a = k")
schirmer@19234
   306
    case True
schirmer@19234
   307
    from True dist_al a_notin_al show ?thesis by simp
schirmer@19234
   308
  next
schirmer@19234
   309
    case False
schirmer@19234
   310
    from dist_al
schirmer@19234
   311
    have "distinct (map fst (update k v al))"
schirmer@19234
   312
      by (rule Cons.hyps)
schirmer@19234
   313
    with False a_notin_al show ?thesis by (simp add: dom_update)
schirmer@19234
   314
  qed
schirmer@19234
   315
qed
schirmer@19234
   316
schirmer@19234
   317
lemma update_filter: 
nipkow@23281
   318
  "a\<noteq>k \<Longrightarrow> update k v [q\<leftarrow>ps . fst q \<noteq> a] = [q\<leftarrow>update k v ps . fst q \<noteq> a]"
schirmer@19234
   319
  by (induct ps) auto
schirmer@19234
   320
schirmer@19234
   321
lemma clearjunk_update: "clearjunk (update k v al) = update k v (clearjunk al)"
wenzelm@26304
   322
  by (induct al rule: clearjunk.induct) (auto simp add: update_filter delete_eq)
schirmer@19234
   323
schirmer@19234
   324
lemma update_triv: "map_of al k = Some v \<Longrightarrow> update k v al = al"
schirmer@19234
   325
  by (induct al) auto
schirmer@19234
   326
schirmer@19234
   327
lemma update_nonempty [simp]: "update k v al \<noteq> []"
schirmer@19234
   328
  by (induct al) auto
schirmer@19234
   329
schirmer@19234
   330
lemma update_eqD: "update k v al = update k v' al' \<Longrightarrow> v=v'"
wenzelm@20503
   331
proof (induct al arbitrary: al') 
schirmer@19234
   332
  case Nil thus ?case 
schirmer@19234
   333
    by (cases al') (auto split: split_if_asm)
schirmer@19234
   334
next
schirmer@19234
   335
  case Cons thus ?case
schirmer@19234
   336
    by (cases al') (auto split: split_if_asm)
schirmer@19234
   337
qed
schirmer@19234
   338
schirmer@19234
   339
lemma update_last [simp]: "update k v (update k v' al) = update k v al"
schirmer@19234
   340
  by (induct al) auto
schirmer@19234
   341
schirmer@19234
   342
text {* Note that the lists are not necessarily the same:
schirmer@19234
   343
        @{term "update k v (update k' v' []) = [(k',v'),(k,v)]"} and 
schirmer@19234
   344
        @{term "update k' v' (update k v []) = [(k,v),(k',v')]"}.*}
schirmer@19234
   345
lemma update_swap: "k\<noteq>k' 
schirmer@19234
   346
  \<Longrightarrow> map_of (update k v (update k' v' al)) = map_of (update k' v' (update k v al))"
schirmer@19234
   347
  by (auto simp add: update_conv' intro: ext)
schirmer@19234
   348
schirmer@19234
   349
lemma update_Some_unfold: 
schirmer@19234
   350
  "(map_of (update k v al) x = Some y) = 
schirmer@19234
   351
     (x = k \<and> v = y \<or> x \<noteq> k \<and> map_of al x = Some y)"
schirmer@19234
   352
  by (simp add: update_conv' map_upd_Some_unfold)
schirmer@19234
   353
schirmer@19234
   354
lemma image_update[simp]: "x \<notin> A \<Longrightarrow> map_of (update x y al) ` A = map_of al ` A"
schirmer@19234
   355
  by (simp add: update_conv' image_map_upd)
schirmer@19234
   356
schirmer@19234
   357
schirmer@19234
   358
subsection {* @{const updates} *}
schirmer@19234
   359
schirmer@19234
   360
lemma updates_conv: "map_of (updates ks vs al) k = ((map_of al)(ks[\<mapsto>]vs)) k"
wenzelm@20503
   361
proof (induct ks arbitrary: vs al)
schirmer@19234
   362
  case Nil
schirmer@19234
   363
  thus ?case by simp
schirmer@19234
   364
next
schirmer@19234
   365
  case (Cons k ks)
schirmer@19234
   366
  show ?case
schirmer@19234
   367
  proof (cases vs)
schirmer@19234
   368
    case Nil
schirmer@19234
   369
    with Cons show ?thesis by simp
schirmer@19234
   370
  next
schirmer@19234
   371
    case (Cons k ks')
schirmer@19234
   372
    with Cons.hyps show ?thesis
schirmer@19234
   373
      by (simp add: update_conv fun_upd_def)
schirmer@19234
   374
  qed
schirmer@19234
   375
qed
schirmer@19234
   376
schirmer@19234
   377
lemma updates_conv': "map_of (updates ks vs al) = ((map_of al)(ks[\<mapsto>]vs))"
schirmer@19234
   378
  by (rule ext) (rule updates_conv)
schirmer@19234
   379
schirmer@19234
   380
lemma distinct_updates:
schirmer@19234
   381
  assumes "distinct (map fst al)"
schirmer@19234
   382
  shows "distinct (map fst (updates ks vs al))"
wenzelm@23373
   383
  using assms
haftmann@22740
   384
  by (induct ks arbitrary: vs al)
haftmann@22740
   385
   (auto simp add: distinct_update split: list.splits)
schirmer@19234
   386
schirmer@19234
   387
lemma clearjunk_updates:
schirmer@19234
   388
 "clearjunk (updates ks vs al) = updates ks vs (clearjunk al)"
wenzelm@20503
   389
  by (induct ks arbitrary: vs al) (auto simp add: clearjunk_update split: list.splits)
schirmer@19234
   390
schirmer@19234
   391
lemma updates_empty[simp]: "updates vs [] al = al"
schirmer@19234
   392
  by (induct vs) auto 
schirmer@19234
   393
schirmer@19234
   394
lemma updates_Cons: "updates (k#ks) (v#vs) al = updates ks vs (update k v al)"
schirmer@19234
   395
  by simp
schirmer@19234
   396
schirmer@19234
   397
lemma updates_append1[simp]: "size ks < size vs \<Longrightarrow>
schirmer@19234
   398
  updates (ks@[k]) vs al = update k (vs!size ks) (updates ks vs al)"
wenzelm@20503
   399
  by (induct ks arbitrary: vs al) (auto split: list.splits)
schirmer@19234
   400
schirmer@19234
   401
lemma updates_list_update_drop[simp]:
schirmer@19234
   402
 "\<lbrakk>size ks \<le> i; i < size vs\<rbrakk>
schirmer@19234
   403
   \<Longrightarrow> updates ks (vs[i:=v]) al = updates ks vs al"
wenzelm@20503
   404
  by (induct ks arbitrary: al vs i) (auto split:list.splits nat.splits)
schirmer@19234
   405
schirmer@19234
   406
lemma update_updates_conv_if: "
schirmer@19234
   407
 map_of (updates xs ys (update x y al)) =
schirmer@19234
   408
 map_of (if x \<in>  set(take (length ys) xs) then updates xs ys al
schirmer@19234
   409
                                  else (update x y (updates xs ys al)))"
schirmer@19234
   410
  by (simp add: updates_conv' update_conv' map_upd_upds_conv_if)
schirmer@19234
   411
schirmer@19234
   412
lemma updates_twist [simp]:
schirmer@19234
   413
 "k \<notin> set ks \<Longrightarrow> 
schirmer@19234
   414
  map_of (updates ks vs (update k v al)) = map_of (update k v (updates ks vs al))"
schirmer@19234
   415
  by (simp add: updates_conv' update_conv' map_upds_twist)
schirmer@19234
   416
schirmer@19234
   417
lemma updates_apply_notin[simp]:
schirmer@19234
   418
 "k \<notin> set ks ==> map_of (updates ks vs al) k = map_of al k"
schirmer@19234
   419
  by (simp add: updates_conv)
schirmer@19234
   420
schirmer@19234
   421
lemma updates_append_drop[simp]:
schirmer@19234
   422
  "size xs = size ys \<Longrightarrow> updates (xs@zs) ys al = updates xs ys al"
wenzelm@20503
   423
  by (induct xs arbitrary: ys al) (auto split: list.splits)
schirmer@19234
   424
schirmer@19234
   425
lemma updates_append2_drop[simp]:
schirmer@19234
   426
  "size xs = size ys \<Longrightarrow> updates xs (ys@zs) al = updates xs ys al"
wenzelm@20503
   427
  by (induct xs arbitrary: ys al) (auto split: list.splits)
schirmer@19234
   428
wenzelm@23373
   429
schirmer@19333
   430
subsection {* @{const map_ran} *}
schirmer@19234
   431
schirmer@19333
   432
lemma map_ran_conv: "map_of (map_ran f al) k = option_map (f k) (map_of al k)"
schirmer@19234
   433
  by (induct al) auto
schirmer@19234
   434
schirmer@19333
   435
lemma dom_map_ran: "fst ` set (map_ran f al) = fst ` set al"
schirmer@19234
   436
  by (induct al) auto
schirmer@19234
   437
schirmer@19333
   438
lemma distinct_map_ran: "distinct (map fst al) \<Longrightarrow> distinct (map fst (map_ran f al))"
schirmer@19333
   439
  by (induct al) (auto simp add: dom_map_ran)
schirmer@19234
   440
nipkow@23281
   441
lemma map_ran_filter: "map_ran f [p\<leftarrow>ps. fst p \<noteq> a] = [p\<leftarrow>map_ran f ps. fst p \<noteq> a]"
schirmer@19234
   442
  by (induct ps) auto
schirmer@19234
   443
schirmer@19333
   444
lemma clearjunk_map_ran: "clearjunk (map_ran f al) = map_ran f (clearjunk al)"
wenzelm@26304
   445
  by (induct al rule: clearjunk.induct) (auto simp add: delete_eq map_ran_filter)
schirmer@19234
   446
wenzelm@23373
   447
schirmer@19234
   448
subsection {* @{const merge} *}
schirmer@19234
   449
schirmer@19234
   450
lemma dom_merge: "fst ` set (merge xs ys) = fst ` set xs \<union> fst ` set ys"
wenzelm@20503
   451
  by (induct ys arbitrary: xs) (auto simp add: dom_update)
schirmer@19234
   452
schirmer@19234
   453
lemma distinct_merge:
schirmer@19234
   454
  assumes "distinct (map fst xs)"
schirmer@19234
   455
  shows "distinct (map fst (merge xs ys))"
wenzelm@23373
   456
  using assms
wenzelm@20503
   457
by (induct ys arbitrary: xs) (auto simp add: dom_merge distinct_update)
schirmer@19234
   458
schirmer@19234
   459
lemma clearjunk_merge:
schirmer@19234
   460
 "clearjunk (merge xs ys) = merge (clearjunk xs) ys"
schirmer@19234
   461
  by (induct ys) (auto simp add: clearjunk_update)
schirmer@19234
   462
schirmer@19234
   463
lemma merge_conv: "map_of (merge xs ys) k = (map_of xs ++ map_of ys) k"
schirmer@19234
   464
proof (induct ys)
schirmer@19234
   465
  case Nil thus ?case by simp 
schirmer@19234
   466
next
schirmer@19234
   467
  case (Cons y ys)
schirmer@19234
   468
  show ?case
schirmer@19234
   469
  proof (cases "k = fst y")
schirmer@19234
   470
    case True
schirmer@19234
   471
    from True show ?thesis
schirmer@19234
   472
      by (simp add: update_conv)
schirmer@19234
   473
  next
schirmer@19234
   474
    case False
schirmer@19234
   475
    from False show ?thesis
schirmer@19234
   476
      by (auto simp add: update_conv Cons.hyps map_add_def)
schirmer@19234
   477
  qed
schirmer@19234
   478
qed
schirmer@19234
   479
schirmer@19234
   480
lemma merge_conv': "map_of (merge xs ys) = (map_of xs ++ map_of ys)"
schirmer@19234
   481
  by (rule ext) (rule merge_conv)
schirmer@19234
   482
schirmer@19234
   483
lemma merge_emty: "map_of (merge [] ys) = map_of ys"
schirmer@19234
   484
  by (simp add: merge_conv')
schirmer@19234
   485
schirmer@19234
   486
lemma merge_assoc[simp]: "map_of (merge m1 (merge m2 m3)) = 
schirmer@19234
   487
                           map_of (merge (merge m1 m2) m3)"
schirmer@19234
   488
  by (simp add: merge_conv')
schirmer@19234
   489
schirmer@19234
   490
lemma merge_Some_iff: 
schirmer@19234
   491
 "(map_of (merge m n) k = Some x) = 
schirmer@19234
   492
  (map_of n k = Some x \<or> map_of n k = None \<and> map_of m k = Some x)"
schirmer@19234
   493
  by (simp add: merge_conv' map_add_Some_iff)
schirmer@19234
   494
schirmer@19234
   495
lemmas merge_SomeD = merge_Some_iff [THEN iffD1, standard]
schirmer@19234
   496
declare merge_SomeD [dest!]
schirmer@19234
   497
schirmer@19234
   498
lemma merge_find_right[simp]: "map_of n k = Some v \<Longrightarrow> map_of (merge m n) k = Some v"
schirmer@19234
   499
  by (simp add: merge_conv')
schirmer@19234
   500
schirmer@19234
   501
lemma merge_None [iff]: 
schirmer@19234
   502
  "(map_of (merge m n) k = None) = (map_of n k = None \<and> map_of m k = None)"
schirmer@19234
   503
  by (simp add: merge_conv')
schirmer@19234
   504
schirmer@19234
   505
lemma merge_upd[simp]: 
schirmer@19234
   506
  "map_of (merge m (update k v n)) = map_of (update k v (merge m n))"
schirmer@19234
   507
  by (simp add: update_conv' merge_conv')
schirmer@19234
   508
schirmer@19234
   509
lemma merge_updatess[simp]: 
schirmer@19234
   510
  "map_of (merge m (updates xs ys n)) = map_of (updates xs ys (merge m n))"
schirmer@19234
   511
  by (simp add: updates_conv' merge_conv')
schirmer@19234
   512
schirmer@19234
   513
lemma merge_append: "map_of (xs@ys) = map_of (merge ys xs)"
schirmer@19234
   514
  by (simp add: merge_conv')
schirmer@19234
   515
wenzelm@23373
   516
schirmer@19234
   517
subsection {* @{const compose} *}
schirmer@19234
   518
schirmer@19234
   519
lemma compose_first_None [simp]: 
schirmer@19234
   520
  assumes "map_of xs k = None" 
schirmer@19234
   521
  shows "map_of (compose xs ys) k = None"
wenzelm@23373
   522
using assms by (induct xs ys rule: compose.induct)
haftmann@22916
   523
  (auto split: option.splits split_if_asm)
schirmer@19234
   524
schirmer@19234
   525
lemma compose_conv: 
schirmer@19234
   526
  shows "map_of (compose xs ys) k = (map_of ys \<circ>\<^sub>m map_of xs) k"
haftmann@22916
   527
proof (induct xs ys rule: compose.induct)
haftmann@22916
   528
  case 1 then show ?case by simp
schirmer@19234
   529
next
haftmann@22916
   530
  case (2 x xs ys) show ?case
schirmer@19234
   531
  proof (cases "map_of ys (snd x)")
haftmann@22916
   532
    case None with 2
schirmer@19234
   533
    have hyp: "map_of (compose (delete (fst x) xs) ys) k =
schirmer@19234
   534
               (map_of ys \<circ>\<^sub>m map_of (delete (fst x) xs)) k"
schirmer@19234
   535
      by simp
schirmer@19234
   536
    show ?thesis
schirmer@19234
   537
    proof (cases "fst x = k")
schirmer@19234
   538
      case True
schirmer@19234
   539
      from True delete_notin_dom [of k xs]
schirmer@19234
   540
      have "map_of (delete (fst x) xs) k = None"
schirmer@19234
   541
	by (simp add: map_of_eq_None_iff)
schirmer@19234
   542
      with hyp show ?thesis
schirmer@19234
   543
	using True None
schirmer@19234
   544
	by simp
schirmer@19234
   545
    next
schirmer@19234
   546
      case False
schirmer@19234
   547
      from False have "map_of (delete (fst x) xs) k = map_of xs k"
schirmer@19234
   548
	by simp
schirmer@19234
   549
      with hyp show ?thesis
schirmer@19234
   550
	using False None
schirmer@19234
   551
	by (simp add: map_comp_def)
schirmer@19234
   552
    qed
schirmer@19234
   553
  next
schirmer@19234
   554
    case (Some v)
haftmann@22916
   555
    with 2
schirmer@19234
   556
    have "map_of (compose xs ys) k = (map_of ys \<circ>\<^sub>m map_of xs) k"
schirmer@19234
   557
      by simp
schirmer@19234
   558
    with Some show ?thesis
schirmer@19234
   559
      by (auto simp add: map_comp_def)
schirmer@19234
   560
  qed
schirmer@19234
   561
qed
schirmer@19234
   562
   
schirmer@19234
   563
lemma compose_conv': 
schirmer@19234
   564
  shows "map_of (compose xs ys) = (map_of ys \<circ>\<^sub>m map_of xs)"
schirmer@19234
   565
  by (rule ext) (rule compose_conv)
schirmer@19234
   566
schirmer@19234
   567
lemma compose_first_Some [simp]:
schirmer@19234
   568
  assumes "map_of xs k = Some v" 
schirmer@19234
   569
  shows "map_of (compose xs ys) k = map_of ys v"
wenzelm@23373
   570
using assms by (simp add: compose_conv)
schirmer@19234
   571
schirmer@19234
   572
lemma dom_compose: "fst ` set (compose xs ys) \<subseteq> fst ` set xs"
haftmann@22916
   573
proof (induct xs ys rule: compose.induct)
haftmann@22916
   574
  case 1 thus ?case by simp
schirmer@19234
   575
next
haftmann@22916
   576
  case (2 x xs ys)
schirmer@19234
   577
  show ?case
schirmer@19234
   578
  proof (cases "map_of ys (snd x)")
schirmer@19234
   579
    case None
haftmann@22916
   580
    with "2.hyps"
schirmer@19234
   581
    have "fst ` set (compose (delete (fst x) xs) ys) \<subseteq> fst ` set (delete (fst x) xs)"
schirmer@19234
   582
      by simp
schirmer@19234
   583
    also
schirmer@19234
   584
    have "\<dots> \<subseteq> fst ` set xs"
schirmer@19234
   585
      by (rule dom_delete_subset)
schirmer@19234
   586
    finally show ?thesis
schirmer@19234
   587
      using None
schirmer@19234
   588
      by auto
schirmer@19234
   589
  next
schirmer@19234
   590
    case (Some v)
haftmann@22916
   591
    with "2.hyps"
schirmer@19234
   592
    have "fst ` set (compose xs ys) \<subseteq> fst ` set xs"
schirmer@19234
   593
      by simp
schirmer@19234
   594
    with Some show ?thesis
schirmer@19234
   595
      by auto
schirmer@19234
   596
  qed
schirmer@19234
   597
qed
schirmer@19234
   598
schirmer@19234
   599
lemma distinct_compose:
schirmer@19234
   600
 assumes "distinct (map fst xs)"
schirmer@19234
   601
 shows "distinct (map fst (compose xs ys))"
wenzelm@23373
   602
using assms
haftmann@22916
   603
proof (induct xs ys rule: compose.induct)
haftmann@22916
   604
  case 1 thus ?case by simp
schirmer@19234
   605
next
haftmann@22916
   606
  case (2 x xs ys)
schirmer@19234
   607
  show ?case
schirmer@19234
   608
  proof (cases "map_of ys (snd x)")
schirmer@19234
   609
    case None
haftmann@22916
   610
    with 2 show ?thesis by simp
schirmer@19234
   611
  next
schirmer@19234
   612
    case (Some v)
haftmann@22916
   613
    with 2 dom_compose [of xs ys] show ?thesis 
schirmer@19234
   614
      by (auto)
schirmer@19234
   615
  qed
schirmer@19234
   616
qed
schirmer@19234
   617
schirmer@19234
   618
lemma compose_delete_twist: "(compose (delete k xs) ys) = delete k (compose xs ys)"
haftmann@22916
   619
proof (induct xs ys rule: compose.induct)
haftmann@22916
   620
  case 1 thus ?case by simp
schirmer@19234
   621
next
haftmann@22916
   622
  case (2 x xs ys)
schirmer@19234
   623
  show ?case
schirmer@19234
   624
  proof (cases "map_of ys (snd x)")
schirmer@19234
   625
    case None
haftmann@22916
   626
    with 2 have 
schirmer@19234
   627
      hyp: "compose (delete k (delete (fst x) xs)) ys =
schirmer@19234
   628
            delete k (compose (delete (fst x) xs) ys)"
schirmer@19234
   629
      by simp
schirmer@19234
   630
    show ?thesis
schirmer@19234
   631
    proof (cases "fst x = k")
schirmer@19234
   632
      case True
schirmer@19234
   633
      with None hyp
schirmer@19234
   634
      show ?thesis
schirmer@19234
   635
	by (simp add: delete_idem)
schirmer@19234
   636
    next
schirmer@19234
   637
      case False
schirmer@19234
   638
      from None False hyp
schirmer@19234
   639
      show ?thesis
schirmer@19234
   640
	by (simp add: delete_twist)
schirmer@19234
   641
    qed
schirmer@19234
   642
  next
schirmer@19234
   643
    case (Some v)
haftmann@22916
   644
    with 2 have hyp: "compose (delete k xs) ys = delete k (compose xs ys)" by simp
schirmer@19234
   645
    with Some show ?thesis
schirmer@19234
   646
      by simp
schirmer@19234
   647
  qed
schirmer@19234
   648
qed
schirmer@19234
   649
schirmer@19234
   650
lemma compose_clearjunk: "compose xs (clearjunk ys) = compose xs ys"
haftmann@22916
   651
  by (induct xs ys rule: compose.induct) 
schirmer@19234
   652
     (auto simp add: map_of_clearjunk split: option.splits)
schirmer@19234
   653
   
schirmer@19234
   654
lemma clearjunk_compose: "clearjunk (compose xs ys) = compose (clearjunk xs) ys"
schirmer@19234
   655
  by (induct xs rule: clearjunk.induct)
schirmer@19234
   656
     (auto split: option.splits simp add: clearjunk_delete delete_idem
schirmer@19234
   657
               compose_delete_twist)
schirmer@19234
   658
   
schirmer@19234
   659
lemma compose_empty [simp]:
schirmer@19234
   660
 "compose xs [] = []"
haftmann@22916
   661
  by (induct xs) (auto simp add: compose_delete_twist)
schirmer@19234
   662
schirmer@19234
   663
lemma compose_Some_iff:
schirmer@19234
   664
  "(map_of (compose xs ys) k = Some v) = 
schirmer@19234
   665
     (\<exists>k'. map_of xs k = Some k' \<and> map_of ys k' = Some v)" 
schirmer@19234
   666
  by (simp add: compose_conv map_comp_Some_iff)
schirmer@19234
   667
schirmer@19234
   668
lemma map_comp_None_iff:
schirmer@19234
   669
  "(map_of (compose xs ys) k = None) = 
schirmer@19234
   670
    (map_of xs k = None \<or> (\<exists>k'. map_of xs k = Some k' \<and> map_of ys k' = None)) " 
schirmer@19234
   671
  by (simp add: compose_conv map_comp_None_iff)
schirmer@19234
   672
schirmer@19234
   673
schirmer@19234
   674
subsection {* @{const restrict} *}
schirmer@19234
   675
wenzelm@26304
   676
lemma restrict_eq:
haftmann@22740
   677
  "restrict A = filter (\<lambda>p. fst p \<in> A)"
haftmann@22740
   678
proof
haftmann@22740
   679
  fix xs
haftmann@22740
   680
  show "restrict A xs = filter (\<lambda>p. fst p \<in> A) xs"
haftmann@22740
   681
  by (induct xs) auto
haftmann@22740
   682
qed
schirmer@19234
   683
schirmer@19234
   684
lemma distinct_restr: "distinct (map fst al) \<Longrightarrow> distinct (map fst (restrict A al))"
wenzelm@26304
   685
  by (induct al) (auto simp add: restrict_eq)
schirmer@19234
   686
schirmer@19234
   687
lemma restr_conv: "map_of (restrict A al) k = ((map_of al)|` A) k"
schirmer@19234
   688
  apply (induct al)
wenzelm@26304
   689
  apply  (simp add: restrict_eq)
schirmer@19234
   690
  apply (cases "k\<in>A")
wenzelm@26304
   691
  apply (auto simp add: restrict_eq)
schirmer@19234
   692
  done
schirmer@19234
   693
schirmer@19234
   694
lemma restr_conv': "map_of (restrict A al) = ((map_of al)|` A)"
schirmer@19234
   695
  by (rule ext) (rule restr_conv)
schirmer@19234
   696
schirmer@19234
   697
lemma restr_empty [simp]: 
schirmer@19234
   698
  "restrict {} al = []" 
schirmer@19234
   699
  "restrict A [] = []"
wenzelm@26304
   700
  by (induct al) (auto simp add: restrict_eq)
schirmer@19234
   701
schirmer@19234
   702
lemma restr_in [simp]: "x \<in> A \<Longrightarrow> map_of (restrict A al) x = map_of al x"
schirmer@19234
   703
  by (simp add: restr_conv')
schirmer@19234
   704
schirmer@19234
   705
lemma restr_out [simp]: "x \<notin> A \<Longrightarrow> map_of (restrict A al) x = None"
schirmer@19234
   706
  by (simp add: restr_conv')
schirmer@19234
   707
schirmer@19234
   708
lemma dom_restr [simp]: "fst ` set (restrict A al) = fst ` set al \<inter> A"
wenzelm@26304
   709
  by (induct al) (auto simp add: restrict_eq)
schirmer@19234
   710
schirmer@19234
   711
lemma restr_upd_same [simp]: "restrict (-{x}) (update x y al) = restrict (-{x}) al"
wenzelm@26304
   712
  by (induct al) (auto simp add: restrict_eq)
schirmer@19234
   713
schirmer@19234
   714
lemma restr_restr [simp]: "restrict A (restrict B al) = restrict (A\<inter>B) al"
wenzelm@26304
   715
  by (induct al) (auto simp add: restrict_eq)
schirmer@19234
   716
schirmer@19234
   717
lemma restr_update[simp]:
schirmer@19234
   718
 "map_of (restrict D (update x y al)) = 
schirmer@19234
   719
  map_of ((if x \<in> D then (update x y (restrict (D-{x}) al)) else restrict D al))"
schirmer@19234
   720
  by (simp add: restr_conv' update_conv')
schirmer@19234
   721
schirmer@19234
   722
lemma restr_delete [simp]:
schirmer@19234
   723
  "(delete x (restrict D al)) = 
schirmer@19234
   724
    (if x\<in> D then restrict (D - {x}) al else restrict D al)"
schirmer@19234
   725
proof (induct al)
schirmer@19234
   726
  case Nil thus ?case by simp
schirmer@19234
   727
next
schirmer@19234
   728
  case (Cons a al)
schirmer@19234
   729
  show ?case
schirmer@19234
   730
  proof (cases "x \<in> D")
schirmer@19234
   731
    case True
schirmer@19234
   732
    note x_D = this
schirmer@19234
   733
    with Cons have hyp: "delete x (restrict D al) = restrict (D - {x}) al"
schirmer@19234
   734
      by simp
schirmer@19234
   735
    show ?thesis
schirmer@19234
   736
    proof (cases "fst a = x")
schirmer@19234
   737
      case True
schirmer@19234
   738
      from Cons.hyps
schirmer@19234
   739
      show ?thesis
schirmer@19234
   740
	using x_D True
schirmer@19234
   741
	by simp
schirmer@19234
   742
    next
schirmer@19234
   743
      case False
schirmer@19234
   744
      note not_fst_a_x = this
schirmer@19234
   745
      show ?thesis
schirmer@19234
   746
      proof (cases "fst a \<in> D")
schirmer@19234
   747
	case True 
schirmer@19234
   748
	with not_fst_a_x 
schirmer@19234
   749
	have "delete x (restrict D (a#al)) = a#(delete x (restrict D al))"
wenzelm@26304
   750
	  by (cases a) (simp add: restrict_eq)
schirmer@19234
   751
	also from not_fst_a_x True hyp have "\<dots> = restrict (D - {x}) (a # al)"
wenzelm@26304
   752
	  by (cases a) (simp add: restrict_eq)
schirmer@19234
   753
	finally show ?thesis
schirmer@19234
   754
	  using x_D by simp
schirmer@19234
   755
      next
schirmer@19234
   756
	case False
schirmer@19234
   757
	hence "delete x (restrict D (a#al)) = delete x (restrict D al)"
wenzelm@26304
   758
	  by (cases a) (simp add: restrict_eq)
schirmer@19234
   759
	moreover from False not_fst_a_x
schirmer@19234
   760
	have "restrict (D - {x}) (a # al) = restrict (D - {x}) al"
wenzelm@26304
   761
	  by (cases a) (simp add: restrict_eq)
schirmer@19234
   762
	ultimately
schirmer@19234
   763
	show ?thesis using x_D hyp by simp
schirmer@19234
   764
      qed
schirmer@19234
   765
    qed
schirmer@19234
   766
  next
schirmer@19234
   767
    case False
schirmer@19234
   768
    from False Cons show ?thesis
schirmer@19234
   769
      by simp
schirmer@19234
   770
  qed
schirmer@19234
   771
qed
schirmer@19234
   772
schirmer@19234
   773
lemma update_restr:
schirmer@19234
   774
 "map_of (update x y (restrict D al)) = map_of (update x y (restrict (D-{x}) al))"
schirmer@19234
   775
  by (simp add: update_conv' restr_conv') (rule fun_upd_restrict)
schirmer@19234
   776
wenzelm@21404
   777
lemma upate_restr_conv [simp]:
schirmer@19234
   778
 "x \<in> D \<Longrightarrow> 
schirmer@19234
   779
 map_of (update x y (restrict D al)) = map_of (update x y (restrict (D-{x}) al))"
schirmer@19234
   780
  by (simp add: update_conv' restr_conv')
schirmer@19234
   781
wenzelm@21404
   782
lemma restr_updates [simp]: "
schirmer@19234
   783
 \<lbrakk> length xs = length ys; set xs \<subseteq> D \<rbrakk>
schirmer@19234
   784
 \<Longrightarrow> map_of (restrict D (updates xs ys al)) = 
schirmer@19234
   785
     map_of (updates xs ys (restrict (D - set xs) al))"
schirmer@19234
   786
  by (simp add: updates_conv' restr_conv')
schirmer@19234
   787
schirmer@19234
   788
lemma restr_delete_twist: "(restrict A (delete a ps)) = delete a (restrict A ps)"
schirmer@19234
   789
  by (induct ps) auto
schirmer@19234
   790
schirmer@19234
   791
lemma clearjunk_restrict:
schirmer@19234
   792
 "clearjunk (restrict A al) = restrict A (clearjunk al)"
schirmer@19234
   793
  by (induct al rule: clearjunk.induct) (auto simp add: restr_delete_twist)
schirmer@19234
   794
schirmer@19234
   795
end