src/HOL/Hoare/Heap.thy
changeset 38353 d98baa2cf589
parent 35416 d8d7d1b785af
child 44890 22f665a2e91c
equal deleted inserted replaced
38352:4c8bcb826e83 38353:d98baa2cf589
    55 by simp
    55 by simp
    56 
    56 
    57 
    57 
    58 subsection "Non-repeating paths"
    58 subsection "Non-repeating paths"
    59 
    59 
    60 definition distPath :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool" where
    60 definition distPath :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool"
    61   "distPath h x as y   \<equiv>   Path h x as y  \<and>  distinct as"
    61   where "distPath h x as y \<longleftrightarrow> Path h x as y \<and> distinct as"
    62 
    62 
    63 text{* The term @{term"distPath h x as y"} expresses the fact that a
    63 text{* The term @{term"distPath h x as y"} expresses the fact that a
    64 non-repeating path @{term as} connects location @{term x} to location
    64 non-repeating path @{term as} connects location @{term x} to location
    65 @{term y} by means of the @{term h} field. In the case where @{text "x
    65 @{term y} by means of the @{term h} field. In the case where @{text "x
    66 = y"}, and there is a cycle from @{term x} to itself, @{term as} can
    66 = y"}, and there is a cycle from @{term x} to itself, @{term as} can
    80 
    80 
    81 subsection "Lists on the heap"
    81 subsection "Lists on the heap"
    82 
    82 
    83 subsubsection "Relational abstraction"
    83 subsubsection "Relational abstraction"
    84 
    84 
    85 definition List :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> bool" where
    85 definition List :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> bool"
    86 "List h x as == Path h x as Null"
    86   where "List h x as = Path h x as Null"
    87 
    87 
    88 lemma [simp]: "List h x [] = (x = Null)"
    88 lemma [simp]: "List h x [] = (x = Null)"
    89 by(simp add:List_def)
    89 by(simp add:List_def)
    90 
    90 
    91 lemma [simp]: "List h x (a#as) = (x = Ref a \<and> List h (h a) as)"
    91 lemma [simp]: "List h x (a#as) = (x = Ref a \<and> List h (h a) as)"
   131 done
   131 done
   132 
   132 
   133 
   133 
   134 subsection "Functional abstraction"
   134 subsection "Functional abstraction"
   135 
   135 
   136 definition islist :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> bool" where
   136 definition islist :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> bool"
   137 "islist h p == \<exists>as. List h p as"
   137   where "islist h p \<longleftrightarrow> (\<exists>as. List h p as)"
   138 
   138 
   139 definition list :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list" where
   139 definition list :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list"
   140 "list h p == SOME as. List h p as"
   140   where "list h p = (SOME as. List h p as)"
   141 
   141 
   142 lemma List_conv_islist_list: "List h p as = (islist h p \<and> as = list h p)"
   142 lemma List_conv_islist_list: "List h p as = (islist h p \<and> as = list h p)"
   143 apply(simp add:islist_def list_def)
   143 apply(simp add:islist_def list_def)
   144 apply(rule iffI)
   144 apply(rule iffI)
   145 apply(rule conjI)
   145 apply(rule conjI)