src/HOL/Imperative_HOL/Heap.thy
author haftmann
Mon, 05 Jul 2010 15:36:37 +0200
changeset 37718 3046ebbb43c0
parent 37716 24bb91462892
child 37719 271ecd4fb9f9
permissions -rw-r--r--
only definite assignment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37714
haftmann
parents: 37678
diff changeset
     1
(*  Title:      HOL/Imperative_HOL/Heap.thy
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     2
    Author:     John Matthews, Galois Connections; Alexander Krauss, TU Muenchen
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     3
*)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     4
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     5
header {* A polymorphic heap based on cantor encodings *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     6
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     7
theory Heap
30738
0842e906300c normalized imports
haftmann
parents: 29399
diff changeset
     8
imports Main Countable
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     9
begin
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    10
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    11
subsection {* Representable types *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    12
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    13
text {* The type class of representable types *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    14
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
    15
class heap = typerep + countable
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    16
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    17
instance nat :: heap ..
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    18
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 36640
diff changeset
    19
instance prod :: (heap, heap) heap ..
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    20
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 36640
diff changeset
    21
instance sum :: (heap, heap) heap ..
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    22
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    23
instance list :: (heap) heap ..
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    24
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    25
instance option :: (heap) heap ..
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    26
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    27
instance int :: heap ..
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    28
31205
98370b26c2ce String.literal replaces message_string, code_numeral replaces (code_)index
haftmann
parents: 30738
diff changeset
    29
instance String.literal :: countable
98370b26c2ce String.literal replaces message_string, code_numeral replaces (code_)index
haftmann
parents: 30738
diff changeset
    30
  by (rule countable_classI [of "String.literal_case to_nat"])
98370b26c2ce String.literal replaces message_string, code_numeral replaces (code_)index
haftmann
parents: 30738
diff changeset
    31
   (auto split: String.literal.splits)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    32
31205
98370b26c2ce String.literal replaces message_string, code_numeral replaces (code_)index
haftmann
parents: 30738
diff changeset
    33
instance String.literal :: heap ..
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    34
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
    35
instance typerep :: heap ..
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    36
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    37
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    38
subsection {* A polymorphic heap with dynamic arrays and references *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    39
37714
haftmann
parents: 37678
diff changeset
    40
subsubsection {* Type definitions *}
haftmann
parents: 37678
diff changeset
    41
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    42
types addr = nat -- "untyped heap references"
37714
haftmann
parents: 37678
diff changeset
    43
types heap_rep = nat -- "representable values"
haftmann
parents: 37678
diff changeset
    44
haftmann
parents: 37678
diff changeset
    45
record heap =
haftmann
parents: 37678
diff changeset
    46
  arrays :: "typerep \<Rightarrow> addr \<Rightarrow> heap_rep list"
haftmann
parents: 37678
diff changeset
    47
  refs :: "typerep \<Rightarrow> addr \<Rightarrow> heap_rep"
haftmann
parents: 37678
diff changeset
    48
  lim  :: addr
haftmann
parents: 37678
diff changeset
    49
haftmann
parents: 37678
diff changeset
    50
definition empty :: heap where
haftmann
parents: 37678
diff changeset
    51
  "empty = \<lparr>arrays = (\<lambda>_ _. []), refs = (\<lambda>_ _. 0), lim = 0\<rparr>" -- "why undefined?"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    52
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    53
datatype 'a array = Array addr
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    54
datatype 'a ref = Ref addr -- "note the phantom type 'a "
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    55
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    56
primrec addr_of_array :: "'a array \<Rightarrow> addr" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    57
  "addr_of_array (Array x) = x"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    58
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    59
primrec addr_of_ref :: "'a ref \<Rightarrow> addr" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    60
  "addr_of_ref (Ref x) = x"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    61
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    62
lemma addr_of_array_inj [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    63
  "addr_of_array a = addr_of_array a' \<longleftrightarrow> a = a'"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    64
  by (cases a, cases a') simp_all
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    65
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    66
lemma addr_of_ref_inj [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    67
  "addr_of_ref r = addr_of_ref r' \<longleftrightarrow> r = r'"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    68
  by (cases r, cases r') simp_all
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    69
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    70
instance array :: (type) countable
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    71
  by (rule countable_classI [of addr_of_array]) simp
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    72
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    73
instance ref :: (type) countable
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    74
  by (rule countable_classI [of addr_of_ref]) simp
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    75
37714
haftmann
parents: 37678
diff changeset
    76
text {* Syntactic convenience *}
haftmann
parents: 37678
diff changeset
    77
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    78
setup {*
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    79
  Sign.add_const_constraint (@{const_name Array}, SOME @{typ "nat \<Rightarrow> 'a\<Colon>heap array"})
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    80
  #> Sign.add_const_constraint (@{const_name Ref}, SOME @{typ "nat \<Rightarrow> 'a\<Colon>heap ref"})
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    81
  #> Sign.add_const_constraint (@{const_name addr_of_array}, SOME @{typ "'a\<Colon>heap array \<Rightarrow> nat"})
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    82
  #> Sign.add_const_constraint (@{const_name addr_of_ref}, SOME @{typ "'a\<Colon>heap ref \<Rightarrow> nat"})
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    83
*}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    84
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    85
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    86
subsection {* Imperative references and arrays *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    87
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    88
text {*
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    89
  References and arrays are developed in parallel,
26586
a2255b130fd9 fix spelling
huffman
parents: 26300
diff changeset
    90
  but keeping them separate makes some later proofs simpler.
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    91
*}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    92
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    93
subsubsection {* Primitive operations *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    94
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    95
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    96
  ref_present :: "'a\<Colon>heap ref \<Rightarrow> heap \<Rightarrow> bool" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    97
  "ref_present r h \<longleftrightarrow> addr_of_ref r < lim h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    98
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    99
definition 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   100
  array_present :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> bool" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   101
  "array_present a h \<longleftrightarrow> addr_of_array a < lim h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   102
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   103
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   104
  get_ref :: "'a\<Colon>heap ref \<Rightarrow> heap \<Rightarrow> 'a" where
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   105
  "get_ref r h = from_nat (refs h (TYPEREP('a)) (addr_of_ref r))"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   106
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   107
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   108
  get_array :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> 'a list" where
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   109
  "get_array a h = map from_nat (arrays h (TYPEREP('a)) (addr_of_array a))"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   110
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   111
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   112
  set_ref :: "'a\<Colon>heap ref \<Rightarrow> 'a \<Rightarrow> heap \<Rightarrow> heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   113
  "set_ref r x = 
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   114
  refs_update (\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r:=to_nat x))))"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   115
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   116
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   117
  set_array :: "'a\<Colon>heap array \<Rightarrow> 'a list \<Rightarrow> heap \<Rightarrow> heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   118
  "set_array a x = 
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   119
  arrays_update (\<lambda>h. h(TYPEREP('a) := ((h(TYPEREP('a))) (addr_of_array a:=map to_nat x))))"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   120
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   121
definition ref :: "'a \<Rightarrow> heap \<Rightarrow> 'a\<Colon>heap ref \<times> heap" where
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   122
  "ref x h = (let
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   123
     l = lim h;
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   124
     r = Ref l;
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   125
     h'' = set_ref r x (h\<lparr>lim := l + 1\<rparr>)
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   126
   in (r, h''))"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   127
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   128
definition array :: "'a list \<Rightarrow> heap \<Rightarrow> 'a\<Colon>heap array \<times> heap" where
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   129
  "array xs h = (let
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   130
     l = lim h;
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   131
     r = Array l;
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   132
     h'' = set_array r xs (h\<lparr>lim := l + 1\<rparr>)
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   133
   in (r, h''))"
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   134
  
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   135
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   136
  upd :: "'a\<Colon>heap array \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> heap \<Rightarrow> heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   137
  "upd a i x h = set_array a ((get_array a h)[i:=x]) h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   138
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   139
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   140
  length :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> nat" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   141
  "length a h = size (get_array a h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   142
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   143
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   144
subsubsection {* Reference equality *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   145
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   146
text {* 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   147
  The following relations are useful for comparing arrays and references.
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   148
*}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   149
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   150
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   151
  noteq_refs :: "('a\<Colon>heap) ref \<Rightarrow> ('b\<Colon>heap) ref \<Rightarrow> bool" (infix "=!=" 70)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   152
where
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   153
  "r =!= s \<longleftrightarrow> TYPEREP('a) \<noteq> TYPEREP('b) \<or> addr_of_ref r \<noteq> addr_of_ref s"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   154
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   155
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   156
  noteq_arrs :: "('a\<Colon>heap) array \<Rightarrow> ('b\<Colon>heap) array \<Rightarrow> bool" (infix "=!!=" 70)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   157
where
28335
25326092cf9a renamed rtype to typerep
haftmann
parents: 28042
diff changeset
   158
  "r =!!= s \<longleftrightarrow> TYPEREP('a) \<noteq> TYPEREP('b) \<or> addr_of_array r \<noteq> addr_of_array s"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   159
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   160
lemma noteq_refs_sym: "r =!= s \<Longrightarrow> s =!= r"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   161
  and noteq_arrs_sym: "a =!!= b \<Longrightarrow> b =!!= a"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   162
  and unequal_refs [simp]: "r \<noteq> r' \<longleftrightarrow> r =!= r'" -- "same types!"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   163
  and unequal_arrs [simp]: "a \<noteq> a' \<longleftrightarrow> a =!!= a'"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   164
unfolding noteq_refs_def noteq_arrs_def by auto
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   165
36640
7eadf5acdaf4 added lemma about irreflexivity of pointer inequality in Imperative_HOL
bulwahn
parents: 36176
diff changeset
   166
lemma noteq_refs_irrefl: "r =!= r \<Longrightarrow> False"
7eadf5acdaf4 added lemma about irreflexivity of pointer inequality in Imperative_HOL
bulwahn
parents: 36176
diff changeset
   167
  unfolding noteq_refs_def by auto
7eadf5acdaf4 added lemma about irreflexivity of pointer inequality in Imperative_HOL
bulwahn
parents: 36176
diff changeset
   168
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   169
lemma present_new_ref: "ref_present r h \<Longrightarrow> r =!= fst (ref v h)"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   170
  by (simp add: ref_present_def ref_def Let_def noteq_refs_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   171
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   172
lemma present_new_arr: "array_present a h \<Longrightarrow> a =!!= fst (array xs h)"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   173
  by (simp add: array_present_def noteq_arrs_def array_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   174
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   175
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   176
subsubsection {* Properties of heap containers *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   177
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   178
text {* Properties of imperative arrays *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   179
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   180
text {* FIXME: Does there exist a "canonical" array axiomatisation in
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   181
the literature?  *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   182
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   183
lemma array_get_set_eq [simp]: "get_array r (set_array r x h) = x"
33639
603320b93668 New list theorems; added map_map to simpset, this is the prefered direction; allow sorting by a key
hoelzl
parents: 31205
diff changeset
   184
  by (simp add: get_array_def set_array_def o_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   185
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   186
lemma array_get_set_neq [simp]: "r =!!= s \<Longrightarrow> get_array r (set_array s x h) = get_array r h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   187
  by (simp add: noteq_arrs_def get_array_def set_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   188
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   189
lemma set_array_same [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   190
  "set_array r x (set_array r y h) = set_array r x h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   191
  by (simp add: set_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   192
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   193
lemma array_set_set_swap:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   194
  "r =!!= r' \<Longrightarrow> set_array r x (set_array r' x' h) = set_array r' x' (set_array r x h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   195
  by (simp add: Let_def expand_fun_eq noteq_arrs_def set_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   196
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   197
lemma array_ref_set_set_swap:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   198
  "set_array r x (set_ref r' x' h) = set_ref r' x' (set_array r x h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   199
  by (simp add: Let_def expand_fun_eq set_array_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   200
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   201
lemma get_array_upd_eq [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   202
  "get_array a (upd a i v h) = (get_array a h) [i := v]"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   203
  by (simp add: upd_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   204
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   205
lemma nth_upd_array_neq_array [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   206
  "a =!!= b \<Longrightarrow> get_array a (upd b j v h) ! i = get_array a h ! i"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   207
  by (simp add: upd_def noteq_arrs_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   208
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   209
lemma get_arry_array_upd_elem_neqIndex [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   210
  "i \<noteq> j \<Longrightarrow> get_array a (upd a j v h) ! i = get_array a h ! i"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   211
  by simp
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   212
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   213
lemma length_upd_eq [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   214
  "length a (upd a i v h) = length a h" 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   215
  by (simp add: length_def upd_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   216
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   217
lemma length_upd_neq [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   218
  "length a (upd b i v h) = length a h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   219
  by (simp add: upd_def length_def set_array_def get_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   220
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   221
lemma upd_swap_neqArray:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   222
  "a =!!= a' \<Longrightarrow> 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   223
  upd a i v (upd a' i' v' h) 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   224
  = upd a' i' v' (upd a i v h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   225
apply (unfold upd_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   226
apply simp
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   227
apply (subst array_set_set_swap, assumption)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   228
apply (subst array_get_set_neq)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   229
apply (erule noteq_arrs_sym)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   230
apply (simp)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   231
done
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   232
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   233
lemma upd_swap_neqIndex:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   234
  "\<lbrakk> i \<noteq> i' \<rbrakk> \<Longrightarrow> upd a i v (upd a i' v' h) = upd a i' v' (upd a i v h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   235
by (auto simp add: upd_def array_set_set_swap list_update_swap)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   236
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   237
lemma get_array_init_array_list:
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   238
  "get_array (fst (array ls h)) (snd (array ls' h)) = ls'"
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   239
  by (simp add: Let_def split_def array_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   240
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   241
lemma set_array:
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   242
  "set_array (fst (array ls h))
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   243
     new_ls (snd (array ls h))
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   244
       = snd (array new_ls h)"
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   245
  by (simp add: Let_def split_def array_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   246
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   247
lemma array_present_upd [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   248
  "array_present a (upd b i v h) = array_present a h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   249
  by (simp add: upd_def array_present_def set_array_def get_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   250
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   251
(*lemma array_of_list_replicate:
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   252
  "array_of_list (replicate n x) = array n x"
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   253
  by (simp add: expand_fun_eq array_of_list_def array_def)*)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   254
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   255
text {* Properties of imperative references *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   256
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   257
lemma next_ref_fresh [simp]:
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   258
  assumes "(r, h') = ref x h"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   259
  shows "\<not> ref_present r h"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   260
  using assms by (cases h) (auto simp add: ref_def ref_present_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   261
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   262
lemma next_ref_present [simp]:
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   263
  assumes "(r, h') = ref x h"
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   264
  shows "ref_present r h'"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   265
  using assms by (cases h) (auto simp add: ref_def set_ref_def ref_present_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   266
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   267
lemma ref_get_set_eq [simp]: "get_ref r (set_ref r x h) = x"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   268
  by (simp add: get_ref_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   269
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   270
lemma ref_get_set_neq [simp]: "r =!= s \<Longrightarrow> get_ref r (set_ref s x h) = get_ref r h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   271
  by (simp add: noteq_refs_def get_ref_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   272
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   273
(* FIXME: We need some infrastructure to infer that locally generated
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   274
  new refs (by new_ref(_no_init), new_array(')) are distinct
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   275
  from all existing refs.
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   276
*)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   277
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   278
lemma ref_set_get: "set_ref r (get_ref r h) h = h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   279
apply (simp add: set_ref_def get_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   280
oops
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   281
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   282
lemma set_ref_same[simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   283
  "set_ref r x (set_ref r y h) = set_ref r x h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   284
  by (simp add: set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   285
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   286
lemma ref_set_set_swap:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   287
  "r =!= r' \<Longrightarrow> set_ref r x (set_ref r' x' h) = set_ref r' x' (set_ref r x h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   288
  by (simp add: Let_def expand_fun_eq noteq_refs_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   289
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   290
lemma ref_new_set: "fst (ref v (set_ref r v' h)) = fst (ref v h)"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   291
  by (simp add: ref_def set_ref_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   292
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   293
lemma ref_get_new [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   294
  "get_ref (fst (ref v h)) (snd (ref v' h)) = v'"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   295
  by (simp add: ref_def Let_def split_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   296
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   297
lemma ref_set_new [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   298
  "set_ref (fst (ref v h)) new_v (snd (ref v h)) = snd (ref new_v h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   299
  by (simp add: ref_def Let_def split_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   300
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   301
lemma ref_get_new_neq: "r =!= (fst (ref v h)) \<Longrightarrow> 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   302
  get_ref r (snd (ref v h)) = get_ref r h"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   303
  by (simp add: get_ref_def set_ref_def ref_def Let_def noteq_refs_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   304
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   305
lemma lim_set_ref [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   306
  "lim (set_ref r v h) = lim h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   307
  by (simp add: set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   308
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   309
lemma ref_present_new_ref [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   310
  "ref_present r h \<Longrightarrow> ref_present r (snd (ref v h))"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   311
  by (simp add: ref_present_def ref_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   312
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   313
lemma ref_present_set_ref [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   314
  "ref_present r (set_ref r' v h) = ref_present r h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   315
  by (simp add: set_ref_def ref_present_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   316
34051
1a82e2e29d67 added Imperative_HOL examples; added tail-recursive combinator for monadic heap functions; adopted code generation of references; added lemmas
bulwahn
parents: 33639
diff changeset
   317
lemma noteq_refsI: "\<lbrakk> ref_present r h; \<not>ref_present r' h \<rbrakk>  \<Longrightarrow> r =!= r'"
1a82e2e29d67 added Imperative_HOL examples; added tail-recursive combinator for monadic heap functions; adopted code generation of references; added lemmas
bulwahn
parents: 33639
diff changeset
   318
  unfolding noteq_refs_def ref_present_def
1a82e2e29d67 added Imperative_HOL examples; added tail-recursive combinator for monadic heap functions; adopted code generation of references; added lemmas
bulwahn
parents: 33639
diff changeset
   319
  by auto
1a82e2e29d67 added Imperative_HOL examples; added tail-recursive combinator for monadic heap functions; adopted code generation of references; added lemmas
bulwahn
parents: 33639
diff changeset
   320
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   321
text {* Non-interaction between imperative array and imperative references *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   322
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   323
lemma get_array_set_ref [simp]: "get_array a (set_ref r v h) = get_array a h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   324
  by (simp add: get_array_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   325
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   326
lemma nth_set_ref [simp]: "get_array a (set_ref r v h) ! i = get_array a h ! i"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   327
  by simp
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   328
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   329
lemma get_ref_upd [simp]: "get_ref r (upd a i v h) = get_ref r h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   330
  by (simp add: get_ref_def set_array_def upd_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   331
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   332
lemma new_ref_upd: "fst (ref v (upd a i v' h)) = fst (ref v h)"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   333
  by (simp add: set_array_def get_array_def Let_def ref_new_set upd_def ref_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   334
26300
03def556e26e removed duplicate lemmas;
wenzelm
parents: 26170
diff changeset
   335
text {*not actually true ???*}
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   336
lemma upd_set_ref_swap: "upd a i v (set_ref r v' h) = set_ref r v' (upd a i v h)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   337
apply (case_tac a)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   338
apply (simp add: Let_def upd_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   339
apply auto
26300
03def556e26e removed duplicate lemmas;
wenzelm
parents: 26170
diff changeset
   340
oops
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   341
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   342
lemma length_new_ref[simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   343
  "length a (snd (ref v h)) = length a h"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   344
  by (simp add: get_array_def set_ref_def length_def  ref_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   345
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   346
lemma get_array_new_ref [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   347
  "get_array a (snd (ref v h)) = get_array a h"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   348
  by (simp add: ref_def set_ref_def get_array_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   349
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   350
lemma ref_present_upd [simp]: 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   351
  "ref_present r (upd a i v h) = ref_present r h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   352
  by (simp add: upd_def ref_present_def set_array_def get_array_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   353
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   354
lemma array_present_set_ref [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   355
  "array_present a (set_ref r v h) = array_present a h"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   356
  by (simp add: array_present_def set_ref_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   357
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   358
lemma array_present_new_ref [simp]:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   359
  "array_present a h \<Longrightarrow> array_present a (snd (ref v h))"
37718
3046ebbb43c0 only definite assignment
haftmann
parents: 37716
diff changeset
   360
  by (simp add: array_present_def ref_def Let_def)
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   361
37716
24bb91462892 remove primitive operation Heap.array in favour of Heap.array_of_list
haftmann
parents: 37714
diff changeset
   362
hide_const (open) empty upd length array ref
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   363
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   364
end