src/HOL/Bali/Table.thy
author berghofe
Sat Jan 30 17:03:46 2010 +0100 (2010-01-30)
changeset 34990 81e8fdfeb849
parent 34939 44294cfecb1d
child 35355 613e133966ea
child 35416 d8d7d1b785af
permissions -rw-r--r--
Adapted to changes in cases method.
wenzelm@12857
     1
(*  Title:      HOL/Bali/Table.thy
schirmer@12854
     2
    Author:     David von Oheimb
schirmer@12854
     3
*)
schirmer@12854
     4
header {* Abstract tables and their implementation as lists *}
schirmer@12854
     5
haftmann@16417
     6
theory Table imports Basis begin
schirmer@12854
     7
schirmer@12854
     8
text {*
schirmer@12854
     9
design issues:
schirmer@12854
    10
\begin{itemize}
schirmer@12854
    11
\item definition of table: infinite map vs. list vs. finite set
schirmer@12854
    12
      list chosen, because:
schirmer@12854
    13
  \begin{itemize} 
schirmer@12854
    14
  \item[+]  a priori finite
schirmer@12854
    15
  \item[+]  lookup is more operational than for finite set
schirmer@12854
    16
  \item[-]  not very abstract, but function table converts it to abstract 
schirmer@12854
    17
            mapping
schirmer@12854
    18
  \end{itemize}
schirmer@12854
    19
\item coding of lookup result: Some/None vs. value/arbitrary
schirmer@12854
    20
   Some/None chosen, because:
schirmer@12854
    21
  \begin{itemize}
schirmer@12854
    22
  \item[++] makes definedness check possible (applies also to finite set),
schirmer@12854
    23
     which is important for the type standard, hiding/overriding, etc.
schirmer@12854
    24
     (though it may perhaps be possible at least for the operational semantics
schirmer@12854
    25
      to treat programs as infinite, i.e. where classes, fields, methods etc.
schirmer@12854
    26
      of any name are considered to be defined)
schirmer@12854
    27
  \item[-]  sometimes awkward case distinctions, alleviated by operator 'the'
schirmer@12854
    28
  \end{itemize}
schirmer@12854
    29
\end{itemize}
schirmer@12854
    30
*}
schirmer@12854
    31
schirmer@13688
    32
types ('a, 'b) table    --{* table with key type 'a and contents type 'b *}
nipkow@14134
    33
      = "'a \<rightharpoonup> 'b"
schirmer@13688
    34
      ('a, 'b) tables   --{* non-unique table with key 'a and contents 'b *}
schirmer@12854
    35
      = "'a \<Rightarrow> 'b set"
schirmer@12854
    36
schirmer@12854
    37
schirmer@12854
    38
section "map of / table of"
schirmer@12854
    39
schirmer@12854
    40
syntax
schirmer@13688
    41
  table_of      :: "('a \<times> 'b) list \<Rightarrow> ('a, 'b) table"   --{* concrete table *}
schirmer@13337
    42
  
haftmann@34939
    43
abbreviation
haftmann@34939
    44
  "table_of \<equiv> map_of"
haftmann@34939
    45
schirmer@12854
    46
translations
haftmann@24194
    47
  (type)"'a \<rightharpoonup> 'b"       <= (type)"'a \<Rightarrow> 'b Datatype.option"
nipkow@14134
    48
  (type)"('a, 'b) table" <= (type)"'a \<rightharpoonup> 'b"
schirmer@12854
    49
schirmer@12854
    50
(* ### To map *)
nipkow@14025
    51
lemma map_add_find_left[simp]:
schirmer@12854
    52
"n k = None \<Longrightarrow> (m ++ n) k = m k"
nipkow@14025
    53
by (simp add: map_add_def)
schirmer@12854
    54
schirmer@12854
    55
section {* Conditional Override *}
schirmer@12854
    56
constdefs
schirmer@12854
    57
cond_override:: 
schirmer@12854
    58
  "('b \<Rightarrow>'b \<Rightarrow> bool) \<Rightarrow> ('a, 'b)table \<Rightarrow> ('a, 'b)table \<Rightarrow> ('a, 'b) table"
schirmer@12854
    59
schirmer@13688
    60
--{* when merging tables old and new, only override an entry of table old when  
schirmer@13688
    61
   the condition cond holds *}
schirmer@12854
    62
"cond_override cond old new \<equiv>
schirmer@12854
    63
 \<lambda> k.
schirmer@12854
    64
  (case new k of
schirmer@12854
    65
     None         \<Rightarrow> old k                       
schirmer@12854
    66
   | Some new_val \<Rightarrow> (case old k of
schirmer@12854
    67
                        None         \<Rightarrow> Some new_val          
schirmer@12854
    68
                      | Some old_val \<Rightarrow> (if cond new_val old_val
schirmer@12854
    69
                                         then Some new_val     
schirmer@12854
    70
                                         else Some old_val)))"
schirmer@12854
    71
schirmer@12854
    72
lemma cond_override_empty1[simp]: "cond_override c empty t = t"
schirmer@12854
    73
by (simp add: cond_override_def expand_fun_eq)
schirmer@12854
    74
schirmer@12854
    75
lemma cond_override_empty2[simp]: "cond_override c t empty = t"
schirmer@12854
    76
by (simp add: cond_override_def expand_fun_eq)
schirmer@12854
    77
schirmer@12854
    78
lemma cond_override_None[simp]:
schirmer@12854
    79
 "old k = None \<Longrightarrow> (cond_override c old new) k = new k"
schirmer@12854
    80
by (simp add: cond_override_def)
schirmer@12854
    81
schirmer@12854
    82
lemma cond_override_override:
schirmer@12854
    83
 "\<lbrakk>old k = Some ov;new k = Some nv; C nv ov\<rbrakk> 
schirmer@12854
    84
  \<Longrightarrow> (cond_override C old new) k = Some nv"
schirmer@12854
    85
by (auto simp add: cond_override_def)
schirmer@12854
    86
schirmer@12854
    87
lemma cond_override_noOverride:
schirmer@12854
    88
 "\<lbrakk>old k = Some ov;new k = Some nv; \<not> (C nv ov)\<rbrakk> 
schirmer@12854
    89
  \<Longrightarrow> (cond_override C old new) k = Some ov"
schirmer@12854
    90
by (auto simp add: cond_override_def)
schirmer@12854
    91
schirmer@12854
    92
lemma dom_cond_override: "dom (cond_override C s t) \<subseteq> dom s \<union> dom t"
schirmer@12854
    93
by (auto simp add: cond_override_def dom_def)
schirmer@12854
    94
schirmer@12854
    95
lemma finite_dom_cond_override:
schirmer@12854
    96
 "\<lbrakk> finite (dom s); finite (dom t) \<rbrakk> \<Longrightarrow> finite (dom (cond_override C s t))"
schirmer@12854
    97
apply (rule_tac B="dom s \<union> dom t" in finite_subset)
schirmer@12854
    98
apply (rule dom_cond_override)
schirmer@12854
    99
by (rule finite_UnI)
schirmer@12854
   100
schirmer@12854
   101
section {* Filter on Tables *}
schirmer@12854
   102
schirmer@12854
   103
constdefs
schirmer@12854
   104
filter_tab:: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('a, 'b) table \<Rightarrow> ('a, 'b) table"
schirmer@12854
   105
"filter_tab c t \<equiv> \<lambda> k. (case t k of 
schirmer@12854
   106
                           None   \<Rightarrow> None
schirmer@12854
   107
                         | Some x \<Rightarrow> if c k x then Some x else None)"
schirmer@12854
   108
schirmer@12854
   109
lemma filter_tab_empty[simp]: "filter_tab c empty = empty"
schirmer@12854
   110
by (simp add: filter_tab_def empty_def)
schirmer@12854
   111
schirmer@12854
   112
lemma filter_tab_True[simp]: "filter_tab (\<lambda>x y. True) t = t"
schirmer@12854
   113
by (simp add: expand_fun_eq filter_tab_def)
schirmer@12854
   114
schirmer@12854
   115
lemma filter_tab_False[simp]: "filter_tab (\<lambda>x y. False) t = empty"
schirmer@12854
   116
by (simp add: expand_fun_eq filter_tab_def empty_def)
schirmer@12854
   117
schirmer@12854
   118
lemma filter_tab_ran_subset: "ran (filter_tab c t) \<subseteq> ran t"
schirmer@12854
   119
by (auto simp add: filter_tab_def ran_def)
schirmer@12854
   120
schirmer@12854
   121
lemma filter_tab_range_subset: "range (filter_tab c t) \<subseteq> range t \<union> {None}"
schirmer@12854
   122
apply (auto simp add: filter_tab_def)
schirmer@12854
   123
apply (drule sym, blast)
schirmer@12854
   124
done
schirmer@12854
   125
schirmer@12854
   126
lemma finite_range_filter_tab:
schirmer@12854
   127
  "finite (range t) \<Longrightarrow> finite (range (filter_tab c t))"
schirmer@12854
   128
apply (rule_tac B="range t \<union> {None} " in finite_subset)
schirmer@12854
   129
apply (rule filter_tab_range_subset)
schirmer@12854
   130
apply (auto intro: finite_UnI)
schirmer@12854
   131
done
schirmer@12854
   132
schirmer@12854
   133
lemma filter_tab_SomeD[dest!]: 
schirmer@12854
   134
"filter_tab c t k = Some x \<Longrightarrow> (t k = Some x) \<and> c k x"
schirmer@12854
   135
by (auto simp add: filter_tab_def)
schirmer@12854
   136
schirmer@12854
   137
lemma filter_tab_SomeI: "\<lbrakk>t k = Some x;C k x\<rbrakk> \<Longrightarrow>filter_tab C t k = Some x"
schirmer@12854
   138
by (simp add: filter_tab_def)
schirmer@12854
   139
schirmer@12854
   140
lemma filter_tab_all_True: 
schirmer@12854
   141
 "\<forall> k y. t k = Some y \<longrightarrow> p k y \<Longrightarrow>filter_tab p t = t"
schirmer@12854
   142
apply (auto simp add: filter_tab_def expand_fun_eq)
schirmer@12854
   143
done
schirmer@12854
   144
schirmer@12854
   145
lemma filter_tab_all_True_Some:
schirmer@12854
   146
 "\<lbrakk>\<forall> k y. t k = Some y \<longrightarrow> p k y; t k = Some v\<rbrakk> \<Longrightarrow> filter_tab p t k = Some v"
schirmer@12854
   147
by (auto simp add: filter_tab_def expand_fun_eq)
schirmer@12854
   148
schirmer@12925
   149
lemma filter_tab_all_False: 
schirmer@12925
   150
 "\<forall> k y. t k = Some y \<longrightarrow> \<not> p k y \<Longrightarrow>filter_tab p t = empty"
schirmer@12925
   151
by (auto simp add: filter_tab_def expand_fun_eq)
schirmer@12925
   152
schirmer@12854
   153
lemma filter_tab_None: "t k = None \<Longrightarrow> filter_tab p t k = None"
schirmer@12854
   154
apply (simp add: filter_tab_def expand_fun_eq)
schirmer@12854
   155
done
schirmer@12854
   156
schirmer@12854
   157
lemma filter_tab_dom_subset: "dom (filter_tab C t) \<subseteq> dom t"
schirmer@12854
   158
by (auto simp add: filter_tab_def dom_def)
schirmer@12854
   159
schirmer@12854
   160
lemma filter_tab_eq: "\<lbrakk>a=b\<rbrakk> \<Longrightarrow> filter_tab C a = filter_tab C b"
schirmer@12854
   161
by (auto simp add: expand_fun_eq filter_tab_def)
schirmer@12854
   162
schirmer@12854
   163
lemma finite_dom_filter_tab:
schirmer@12854
   164
"finite (dom t) \<Longrightarrow> finite (dom (filter_tab C t))"
schirmer@12854
   165
apply (rule_tac B="dom t" in finite_subset)
schirmer@12854
   166
by (rule filter_tab_dom_subset)
schirmer@12854
   167
schirmer@12854
   168
schirmer@12854
   169
lemma filter_tab_weaken:
schirmer@12854
   170
"\<lbrakk>\<forall> a \<in> t k: \<exists> b \<in> s k: P a b; 
schirmer@12854
   171
  \<And> k x y. \<lbrakk>t k = Some x;s k = Some y\<rbrakk> \<Longrightarrow> cond k x \<longrightarrow> cond k y
schirmer@12854
   172
 \<rbrakk> \<Longrightarrow> \<forall> a \<in> filter_tab cond t k: \<exists> b \<in> filter_tab cond s k: P a b"
berghofe@13601
   173
apply (force simp add: filter_tab_def)
schirmer@12854
   174
done
schirmer@12854
   175
schirmer@12854
   176
lemma cond_override_filter: 
schirmer@12854
   177
  "\<lbrakk>\<And> k old new. \<lbrakk>s k = Some new; t k = Some old\<rbrakk> 
schirmer@12854
   178
    \<Longrightarrow> (\<not> overC new old \<longrightarrow>  \<not> filterC k new) \<and> 
schirmer@12854
   179
        (overC new old \<longrightarrow> filterC k old \<longrightarrow> filterC k new)
schirmer@12854
   180
   \<rbrakk> \<Longrightarrow>
schirmer@12854
   181
    cond_override overC (filter_tab filterC t) (filter_tab filterC s) 
schirmer@12854
   182
    = filter_tab filterC (cond_override overC t s)"
schirmer@12854
   183
by (auto simp add: expand_fun_eq cond_override_def filter_tab_def )
schirmer@12854
   184
schirmer@12925
   185
schirmer@12854
   186
section {* Misc. *}
schirmer@12854
   187
schirmer@12854
   188
lemma Ball_set_table: "(\<forall> (x,y)\<in> set l. P x y) \<Longrightarrow> \<forall> x. \<forall> y\<in> map_of l x: P x y"
wenzelm@24038
   189
apply (erule rev_mp)
schirmer@12854
   190
apply (induct l)
schirmer@12854
   191
apply simp
schirmer@12854
   192
apply (simp (no_asm))
schirmer@12854
   193
apply auto
schirmer@12854
   194
done
schirmer@12854
   195
schirmer@12854
   196
lemma Ball_set_tableD: 
nipkow@30235
   197
  "\<lbrakk>(\<forall> (x,y)\<in> set l. P x y); x \<in> Option.set (table_of l xa)\<rbrakk> \<Longrightarrow> P xa x"
schirmer@12854
   198
apply (frule Ball_set_table)
schirmer@12854
   199
by auto
schirmer@12854
   200
schirmer@12854
   201
declare map_of_SomeD [elim]
schirmer@12854
   202
schirmer@12854
   203
lemma table_of_Some_in_set:
schirmer@12854
   204
"table_of l k = Some x \<Longrightarrow> (k,x) \<in> set l"
schirmer@12854
   205
by auto
schirmer@12854
   206
schirmer@12854
   207
lemma set_get_eq: 
schirmer@12854
   208
  "unique l \<Longrightarrow> (k, the (table_of l k)) \<in> set l = (table_of l k \<noteq> None)"
paulson@18447
   209
by (auto dest!: weak_map_of_SomeI)
schirmer@12854
   210
schirmer@12854
   211
lemma inj_Pair_const2: "inj (\<lambda>k. (k, C))"
paulson@13585
   212
apply (rule inj_onI)
schirmer@12854
   213
apply auto
schirmer@12854
   214
done
schirmer@12854
   215
schirmer@12854
   216
lemma table_of_mapconst_SomeI:
schirmer@12854
   217
  "\<lbrakk>table_of t k = Some y'; snd y=y'; fst y=c\<rbrakk> \<Longrightarrow>
schirmer@12854
   218
   table_of (map (\<lambda>(k,x). (k,c,x)) t) k = Some y"
schirmer@12854
   219
apply (induct t)
schirmer@12854
   220
apply auto
schirmer@12854
   221
done
schirmer@12854
   222
schirmer@12854
   223
lemma table_of_mapconst_NoneI:
schirmer@12854
   224
  "\<lbrakk>table_of t k = None\<rbrakk> \<Longrightarrow>
schirmer@12854
   225
   table_of (map (\<lambda>(k,x). (k,c,x)) t) k = None"
schirmer@12854
   226
apply (induct t)
schirmer@12854
   227
apply auto
schirmer@12854
   228
done
schirmer@12854
   229
schirmer@12854
   230
lemmas table_of_map2_SomeI = inj_Pair_const2 [THEN map_of_mapk_SomeI, standard]
schirmer@12854
   231
schirmer@12854
   232
lemma table_of_map_SomeI [rule_format (no_asm)]: "table_of t k = Some x \<longrightarrow>
schirmer@12854
   233
   table_of (map (\<lambda>(k,x). (k, f x)) t) k = Some (f x)"
schirmer@12854
   234
apply (induct_tac "t")
schirmer@12854
   235
apply auto
schirmer@12854
   236
done
schirmer@12854
   237
schirmer@12854
   238
lemma table_of_remap_SomeD [rule_format (no_asm)]: 
schirmer@12854
   239
  "table_of (map (\<lambda>((k,k'),x). (k,(k',x))) t) k = Some (k',x) \<longrightarrow>
schirmer@12854
   240
  table_of t (k, k') = Some x"
schirmer@12854
   241
apply (induct_tac "t")
schirmer@12854
   242
apply  auto
schirmer@12854
   243
done
schirmer@12854
   244
schirmer@12854
   245
lemma table_of_mapf_Some [rule_format (no_asm)]: "\<forall>x y. f x = f y \<longrightarrow> x = y \<Longrightarrow> 
schirmer@12854
   246
  table_of (map (\<lambda>(k,x). (k,f x)) t) k = Some (f x) \<longrightarrow> table_of t k = Some x"
schirmer@12854
   247
apply (induct_tac "t")
schirmer@12854
   248
apply  auto
schirmer@12854
   249
done
schirmer@12854
   250
schirmer@12854
   251
lemma table_of_mapf_SomeD [rule_format (no_asm), dest!]: 
schirmer@12854
   252
"table_of (map (\<lambda>(k,x). (k, f x)) t) k = Some z \<longrightarrow> (\<exists>y\<in>table_of t k: z=f y)"
schirmer@12854
   253
apply (induct_tac "t")
schirmer@12854
   254
apply  auto
schirmer@12854
   255
done
schirmer@12854
   256
schirmer@12854
   257
lemma table_of_mapf_NoneD [rule_format (no_asm), dest!]: 
schirmer@12854
   258
"table_of (map (\<lambda>(k,x). (k, f x)) t) k = None \<longrightarrow> (table_of t k = None)"
schirmer@12854
   259
apply (induct_tac "t")
schirmer@12854
   260
apply auto
schirmer@12854
   261
done
schirmer@12854
   262
schirmer@12854
   263
lemma table_of_mapkey_SomeD [rule_format (no_asm), dest!]: 
schirmer@12854
   264
  "table_of (map (\<lambda>(k,x). ((k,C),x)) t) (k,D) = Some x \<longrightarrow> C = D \<and> table_of t k = Some x"
schirmer@12854
   265
apply (induct_tac "t")
schirmer@12854
   266
apply  auto
schirmer@12854
   267
done
schirmer@12854
   268
lemma table_of_mapkey_SomeD2 [rule_format (no_asm), dest!]: 
schirmer@12854
   269
  "table_of (map (\<lambda>(k,x). ((k,C),x)) t) ek = Some x 
schirmer@12854
   270
   \<longrightarrow> C = snd ek \<and> table_of t (fst ek) = Some x"
schirmer@12854
   271
apply (induct_tac "t")
schirmer@12854
   272
apply  auto
schirmer@12854
   273
done
schirmer@12854
   274
schirmer@12854
   275
lemma table_append_Some_iff: "table_of (xs@ys) k = Some z = 
schirmer@12854
   276
 (table_of xs k = Some z \<or> (table_of xs k = None \<and> table_of ys k = Some z))"
nipkow@14025
   277
apply (simp)
nipkow@14025
   278
apply (rule map_add_Some_iff)
schirmer@12854
   279
done
schirmer@12854
   280
schirmer@12854
   281
lemma table_of_filter_unique_SomeD [rule_format (no_asm)]:
schirmer@12854
   282
  "table_of (filter P xs) k = Some z \<Longrightarrow> unique xs \<longrightarrow> table_of xs k = Some z"
schirmer@12854
   283
apply (induct xs)
schirmer@12854
   284
apply (auto del: map_of_SomeD intro!: map_of_SomeD)
schirmer@12854
   285
done
schirmer@12854
   286
schirmer@12854
   287
schirmer@12854
   288
consts
schirmer@12854
   289
  Un_tables      :: "('a, 'b) tables set \<Rightarrow> ('a, 'b) tables"
schirmer@12854
   290
  overrides_t    :: "('a, 'b) tables     \<Rightarrow> ('a, 'b) tables \<Rightarrow>
schirmer@12854
   291
                     ('a, 'b) tables"             (infixl "\<oplus>\<oplus>" 100)
schirmer@12854
   292
  hidings_entails:: "('a, 'b) tables \<Rightarrow> ('a, 'c) tables \<Rightarrow> 
schirmer@12854
   293
                     ('b \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> bool"   ("_ hidings _ entails _" 20)
schirmer@13688
   294
  --{* variant for unique table: *}
schirmer@12854
   295
  hiding_entails :: "('a, 'b) table  \<Rightarrow> ('a, 'c) table  \<Rightarrow> 
schirmer@12854
   296
                     ('b \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> bool"   ("_ hiding _ entails _"  20)
schirmer@13688
   297
  --{* variant for a unique table and conditional overriding: *}
schirmer@12854
   298
  cond_hiding_entails :: "('a, 'b) table  \<Rightarrow> ('a, 'c) table  
schirmer@12854
   299
                          \<Rightarrow> ('b \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> bool"  
schirmer@12854
   300
                          ("_ hiding _ under _ entails _"  20)
schirmer@12854
   301
schirmer@12854
   302
defs
schirmer@12854
   303
  Un_tables_def:       "Un_tables ts\<spacespace>\<spacespace>\<equiv> \<lambda>k. \<Union>t\<in>ts. t k"
schirmer@12854
   304
  overrides_t_def:     "s \<oplus>\<oplus> t        \<equiv> \<lambda>k. if t k = {} then s k else t k"
schirmer@12854
   305
  hidings_entails_def: "t hidings s entails R \<equiv> \<forall>k. \<forall>x\<in>t k. \<forall>y\<in>s k. R x y"
schirmer@12854
   306
  hiding_entails_def:  "t hiding  s entails R \<equiv> \<forall>k. \<forall>x\<in>t k: \<forall>y\<in>s k: R x y"
schirmer@12854
   307
  cond_hiding_entails_def: "t hiding  s under C entails R
schirmer@12854
   308
                            \<equiv> \<forall>k. \<forall>x\<in>t k: \<forall>y\<in>s k: C x y \<longrightarrow> R x y"
schirmer@12854
   309
schirmer@12854
   310
section "Untables"
schirmer@12854
   311
schirmer@12854
   312
lemma Un_tablesI [intro]:  "\<And>x. \<lbrakk>t \<in> ts; x \<in> t k\<rbrakk> \<Longrightarrow> x \<in> Un_tables ts k"
schirmer@12854
   313
apply (simp add: Un_tables_def)
schirmer@12854
   314
apply auto
schirmer@12854
   315
done
schirmer@12854
   316
schirmer@12854
   317
lemma Un_tablesD [dest!]: "\<And>x. x \<in> Un_tables ts k \<Longrightarrow> \<exists>t. t \<in> ts \<and> x \<in> t k"
schirmer@12854
   318
apply (simp add: Un_tables_def)
schirmer@12854
   319
apply auto
schirmer@12854
   320
done
schirmer@12854
   321
schirmer@12854
   322
lemma Un_tables_empty [simp]: "Un_tables {} = (\<lambda>k. {})"
schirmer@12854
   323
apply (unfold Un_tables_def)
schirmer@12854
   324
apply (simp (no_asm))
schirmer@12854
   325
done
schirmer@12854
   326
schirmer@12854
   327
schirmer@12854
   328
section "overrides"
schirmer@12854
   329
schirmer@12854
   330
lemma empty_overrides_t [simp]: "(\<lambda>k. {}) \<oplus>\<oplus> m = m"
schirmer@12854
   331
apply (unfold overrides_t_def)
schirmer@12854
   332
apply (simp (no_asm))
schirmer@12854
   333
done
schirmer@12854
   334
lemma overrides_empty_t [simp]: "m \<oplus>\<oplus> (\<lambda>k. {}) = m"
schirmer@12854
   335
apply (unfold overrides_t_def)
schirmer@12854
   336
apply (simp (no_asm))
schirmer@12854
   337
done
schirmer@12854
   338
schirmer@12854
   339
lemma overrides_t_Some_iff: 
schirmer@12854
   340
 "(x \<in> (s \<oplus>\<oplus> t) k) = (x \<in> t k \<or> t k = {} \<and> x \<in> s k)"
schirmer@12854
   341
by (simp add: overrides_t_def)
schirmer@12854
   342
schirmer@12854
   343
lemmas overrides_t_SomeD = overrides_t_Some_iff [THEN iffD1, dest!]
schirmer@12854
   344
schirmer@12854
   345
lemma overrides_t_right_empty [simp]: "n k = {} \<Longrightarrow> (m \<oplus>\<oplus> n) k = m k"  
schirmer@12854
   346
by (simp add: overrides_t_def)
schirmer@12854
   347
schirmer@12854
   348
lemma overrides_t_find_right [simp]: "n k \<noteq> {} \<Longrightarrow> (m \<oplus>\<oplus> n) k = n k"  
schirmer@12854
   349
by (simp add: overrides_t_def)
schirmer@12854
   350
schirmer@12854
   351
section "hiding entails"
schirmer@12854
   352
schirmer@12854
   353
lemma hiding_entailsD: 
schirmer@12854
   354
  "\<lbrakk>t hiding s entails R; t k = Some x; s k = Some y\<rbrakk> \<Longrightarrow> R x y"
schirmer@12854
   355
by (simp add: hiding_entails_def)
schirmer@12854
   356
schirmer@12854
   357
lemma empty_hiding_entails: "empty hiding s entails R"
schirmer@12854
   358
by (simp add: hiding_entails_def)
schirmer@12854
   359
schirmer@12854
   360
lemma hiding_empty_entails: "t hiding empty entails R"
schirmer@12854
   361
by (simp add: hiding_entails_def)
schirmer@12854
   362
declare empty_hiding_entails [simp] hiding_empty_entails [simp]
schirmer@12854
   363
schirmer@12854
   364
section "cond hiding entails"
schirmer@12854
   365
schirmer@12854
   366
lemma cond_hiding_entailsD: 
schirmer@12854
   367
"\<lbrakk>t hiding s under C entails R; t k = Some x; s k = Some y; C x y\<rbrakk> \<Longrightarrow> R x y"
schirmer@12854
   368
by (simp add: cond_hiding_entails_def)
schirmer@12854
   369
schirmer@12854
   370
lemma empty_cond_hiding_entails[simp]: "empty hiding s under C entails R"
schirmer@12854
   371
by (simp add: cond_hiding_entails_def)
schirmer@12854
   372
schirmer@12854
   373
lemma cond_hiding_empty_entails[simp]: "t hiding empty under C entails R"
schirmer@12854
   374
by (simp add: cond_hiding_entails_def)
schirmer@12854
   375
schirmer@12854
   376
lemma hidings_entailsD: "\<lbrakk>t hidings s entails R; x \<in> t k; y \<in> s k\<rbrakk> \<Longrightarrow> R x y"
schirmer@12854
   377
by (simp add: hidings_entails_def)
schirmer@12854
   378
schirmer@12854
   379
lemma hidings_empty_entails: "t hidings (\<lambda>k. {}) entails R"
schirmer@12854
   380
apply (unfold hidings_entails_def)
schirmer@12854
   381
apply (simp (no_asm))
schirmer@12854
   382
done
schirmer@12854
   383
schirmer@12854
   384
lemma empty_hidings_entails: 
schirmer@12854
   385
  "(\<lambda>k. {}) hidings s entails R"apply (unfold hidings_entails_def)
schirmer@12854
   386
by (simp (no_asm))
schirmer@12854
   387
declare empty_hidings_entails [intro!] hidings_empty_entails [intro!]
schirmer@12854
   388
schirmer@12854
   389
schirmer@12854
   390
schirmer@12854
   391
(*###TO Map?*)
schirmer@12854
   392
consts
schirmer@12854
   393
  atleast_free :: "('a ~=> 'b) => nat => bool"
schirmer@12854
   394
primrec
schirmer@12854
   395
 "atleast_free m 0       = True"
schirmer@12854
   396
 atleast_free_Suc: 
schirmer@12854
   397
 "atleast_free m (Suc n) = (? a. m a = None & (!b. atleast_free (m(a|->b)) n))"
schirmer@12854
   398
schirmer@12854
   399
lemma atleast_free_weaken [rule_format (no_asm)]: 
schirmer@12854
   400
  "!m. atleast_free m (Suc n) \<longrightarrow> atleast_free m n"
schirmer@12854
   401
apply (induct_tac "n")
schirmer@12854
   402
apply (simp (no_asm))
schirmer@12854
   403
apply clarify
schirmer@12854
   404
apply (simp (no_asm))
schirmer@12854
   405
apply (drule atleast_free_Suc [THEN iffD1])
schirmer@12854
   406
apply fast
schirmer@12854
   407
done
schirmer@12854
   408
schirmer@12854
   409
lemma atleast_free_SucI: 
schirmer@12854
   410
"[| h a = None; !obj. atleast_free (h(a|->obj)) n |] ==> atleast_free h (Suc n)"
schirmer@12854
   411
by force
schirmer@12854
   412
schirmer@12854
   413
declare fun_upd_apply [simp del]
schirmer@12854
   414
lemma atleast_free_SucD_lemma [rule_format (no_asm)]: 
schirmer@12854
   415
" !m a. m a = None --> (!c. atleast_free (m(a|->c)) n) -->  
schirmer@12854
   416
  (!b d. a ~= b --> atleast_free (m(b|->d)) n)"
schirmer@12854
   417
apply (induct_tac "n")
schirmer@12854
   418
apply  auto
schirmer@12854
   419
apply (rule_tac x = "a" in exI)
schirmer@12854
   420
apply  (rule conjI)
schirmer@12854
   421
apply  (force simp add: fun_upd_apply)
schirmer@12854
   422
apply (erule_tac V = "m a = None" in thin_rl)
schirmer@12854
   423
apply clarify
schirmer@12854
   424
apply (subst fun_upd_twist)
schirmer@12854
   425
apply  (erule not_sym)
schirmer@12854
   426
apply (rename_tac "ba")
schirmer@12854
   427
apply (drule_tac x = "ba" in spec)
schirmer@12854
   428
apply clarify
schirmer@12854
   429
apply (tactic "smp_tac 2 1")
schirmer@12854
   430
apply (erule (1) notE impE)
schirmer@12854
   431
apply (case_tac "aa = b")
schirmer@12854
   432
apply fast+
schirmer@12854
   433
done
schirmer@12854
   434
declare fun_upd_apply [simp]
schirmer@12854
   435
schirmer@12854
   436
lemma atleast_free_SucD [rule_format (no_asm)]: "atleast_free h (Suc n) ==> atleast_free (h(a|->b)) n"
schirmer@12854
   437
apply auto
schirmer@12854
   438
apply (case_tac "aa = a")
schirmer@12854
   439
apply auto
schirmer@12854
   440
apply (erule atleast_free_SucD_lemma)
schirmer@12854
   441
apply auto
schirmer@12854
   442
done
schirmer@12854
   443
schirmer@12854
   444
declare atleast_free_Suc [simp del]
schirmer@12854
   445
end