equal
deleted
inserted
replaced
1 (* Title: HOL/Hoare/Heap.thy |
1 (* Title: HOL/Hoare/Heap.thy |
2 ID: $Id$ |
|
3 Author: Tobias Nipkow |
2 Author: Tobias Nipkow |
4 Copyright 2002 TUM |
3 Copyright 2002 TUM |
5 |
4 |
6 Pointers, heaps and heap abstractions. |
5 Pointers, heaps and heap abstractions. |
7 See the paper by Mehta and Nipkow. |
6 See the paper by Mehta and Nipkow. |
17 by (induct x) auto |
16 by (induct x) auto |
18 |
17 |
19 lemma not_Ref_eq [iff]: "(ALL y. x ~= Ref y) = (x = Null)" |
18 lemma not_Ref_eq [iff]: "(ALL y. x ~= Ref y) = (x = Null)" |
20 by (induct x) auto |
19 by (induct x) auto |
21 |
20 |
22 consts addr :: "'a ref \<Rightarrow> 'a" |
21 primrec addr :: "'a ref \<Rightarrow> 'a" where |
23 primrec "addr(Ref a) = a" |
22 "addr (Ref a) = a" |
24 |
23 |
25 |
24 |
26 section "The heap" |
25 section "The heap" |
27 |
26 |
28 subsection "Paths in the heap" |
27 subsection "Paths in the heap" |
29 |
28 |
30 consts |
29 primrec Path :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool" where |
31 Path :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool" |
30 "Path h x [] y \<longleftrightarrow> x = y" |
32 primrec |
31 | "Path h x (a#as) y \<longleftrightarrow> x = Ref a \<and> Path h (h a) as y" |
33 "Path h x [] y = (x = y)" |
|
34 "Path h x (a#as) y = (x = Ref a \<and> Path h (h a) as y)" |
|
35 |
32 |
36 lemma [iff]: "Path h Null xs y = (xs = [] \<and> y = Null)" |
33 lemma [iff]: "Path h Null xs y = (xs = [] \<and> y = Null)" |
37 apply(case_tac xs) |
34 apply(case_tac xs) |
38 apply fastsimp |
35 apply fastsimp |
39 apply fastsimp |
36 apply fastsimp |
58 by simp |
55 by simp |
59 |
56 |
60 |
57 |
61 subsection "Non-repeating paths" |
58 subsection "Non-repeating paths" |
62 |
59 |
63 constdefs |
60 definition distPath :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool" where |
64 distPath :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> 'a ref \<Rightarrow> bool" |
|
65 "distPath h x as y \<equiv> Path h x as y \<and> distinct as" |
61 "distPath h x as y \<equiv> Path h x as y \<and> distinct as" |
66 |
62 |
67 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 |
68 non-repeating path @{term as} connects location @{term x} to location |
64 non-repeating path @{term as} connects location @{term x} to location |
69 @{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 |
84 |
80 |
85 subsection "Lists on the heap" |
81 subsection "Lists on the heap" |
86 |
82 |
87 subsubsection "Relational abstraction" |
83 subsubsection "Relational abstraction" |
88 |
84 |
89 constdefs |
85 definition List :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> bool" where |
90 List :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list \<Rightarrow> bool" |
|
91 "List h x as == Path h x as Null" |
86 "List h x as == Path h x as Null" |
92 |
87 |
93 lemma [simp]: "List h x [] = (x = Null)" |
88 lemma [simp]: "List h x [] = (x = Null)" |
94 by(simp add:List_def) |
89 by(simp add:List_def) |
95 |
90 |
136 done |
131 done |
137 |
132 |
138 |
133 |
139 subsection "Functional abstraction" |
134 subsection "Functional abstraction" |
140 |
135 |
141 constdefs |
136 definition islist :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> bool" where |
142 islist :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> bool" |
|
143 "islist h p == \<exists>as. List h p as" |
137 "islist h p == \<exists>as. List h p as" |
144 list :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list" |
138 |
|
139 definition list :: "('a \<Rightarrow> 'a ref) \<Rightarrow> 'a ref \<Rightarrow> 'a list" where |
145 "list h p == SOME as. List h p as" |
140 "list h p == SOME as. List h p as" |
146 |
141 |
147 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)" |
148 apply(simp add:islist_def list_def) |
143 apply(simp add:islist_def list_def) |
149 apply(rule iffI) |
144 apply(rule iffI) |