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