src/HOL/Hoare/SepLogHeap.thy
author wenzelm
Wed Aug 11 18:41:06 2010 +0200 (2010-08-11)
changeset 38353 d98baa2cf589
parent 35416 d8d7d1b785af
child 41959 b460124855b8
permissions -rw-r--r--
modernized specifications;
tuned headers;
nipkow@14074
     1
(*  Title:      HOL/Hoare/Heap.thy
nipkow@14074
     2
    Author:     Tobias Nipkow
nipkow@14074
     3
    Copyright   2002 TUM
nipkow@14074
     4
nipkow@14074
     5
Heap abstractions (at the moment only Path and List)
nipkow@14074
     6
for Separation Logic.
nipkow@14074
     7
*)
nipkow@14074
     8
nipkow@18576
     9
theory SepLogHeap
nipkow@18576
    10
imports Main
nipkow@18576
    11
begin
paulson@18447
    12
nipkow@14074
    13
types heap = "(nat \<Rightarrow> nat option)"
nipkow@14074
    14
wenzelm@16972
    15
text{* @{text "Some"} means allocated, @{text "None"} means
wenzelm@16972
    16
free. Address @{text "0"} serves as the null reference. *}
nipkow@14074
    17
nipkow@14074
    18
subsection "Paths in the heap"
nipkow@14074
    19
wenzelm@38353
    20
primrec Path :: "heap \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat \<Rightarrow> bool"
wenzelm@38353
    21
where
wenzelm@38353
    22
  "Path h x [] y = (x = y)"
wenzelm@38353
    23
| "Path h x (a#as) y = (x\<noteq>0 \<and> a=x \<and> (\<exists>b. h x = Some b \<and> Path h b as y))"
nipkow@14074
    24
nipkow@14074
    25
lemma [iff]: "Path h 0 xs y = (xs = [] \<and> y = 0)"
wenzelm@16972
    26
by (cases xs) simp_all
nipkow@14074
    27
nipkow@14074
    28
lemma [simp]: "x\<noteq>0 \<Longrightarrow> Path h x as z =
nipkow@14074
    29
 (as = [] \<and> z = x  \<or>  (\<exists>y bs. as = x#bs \<and> h x = Some y & Path h y bs z))"
wenzelm@16972
    30
by (cases as) auto
nipkow@14074
    31
nipkow@14074
    32
lemma [simp]: "\<And>x. Path f x (as@bs) z = (\<exists>y. Path f x as y \<and> Path f y bs z)"
wenzelm@16972
    33
by (induct as) auto
nipkow@14074
    34
nipkow@14074
    35
lemma Path_upd[simp]:
nipkow@14074
    36
 "\<And>x. u \<notin> set as \<Longrightarrow> Path (f(u := v)) x as y = Path f x as y"
wenzelm@16972
    37
by (induct as) simp_all
nipkow@14074
    38
nipkow@14074
    39
nipkow@14074
    40
subsection "Lists on the heap"
nipkow@14074
    41
wenzelm@38353
    42
definition List :: "heap \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> bool"
wenzelm@38353
    43
  where "List h x as = Path h x as 0"
nipkow@14074
    44
nipkow@14074
    45
lemma [simp]: "List h x [] = (x = 0)"
wenzelm@16972
    46
by (simp add: List_def)
nipkow@14074
    47
nipkow@14074
    48
lemma [simp]:
nipkow@14074
    49
 "List h x (a#as) = (x\<noteq>0 \<and> a=x \<and> (\<exists>y. h x = Some y \<and> List h y as))"
wenzelm@16972
    50
by (simp add: List_def)
nipkow@14074
    51
nipkow@14074
    52
lemma [simp]: "List h 0 as = (as = [])"
wenzelm@16972
    53
by (cases as) simp_all
nipkow@14074
    54
nipkow@14074
    55
lemma List_non_null: "a\<noteq>0 \<Longrightarrow>
nipkow@14074
    56
 List h a as = (\<exists>b bs. as = a#bs \<and> h a = Some b \<and> List h b bs)"
wenzelm@16972
    57
by (cases as) simp_all
nipkow@14074
    58
nipkow@14074
    59
theorem notin_List_update[simp]:
nipkow@14074
    60
 "\<And>x. a \<notin> set as \<Longrightarrow> List (h(a := y)) x as = List h x as"
wenzelm@16972
    61
by (induct as) simp_all
nipkow@14074
    62
nipkow@14074
    63
lemma List_unique: "\<And>x bs. List h x as \<Longrightarrow> List h x bs \<Longrightarrow> as = bs"
wenzelm@16972
    64
by (induct as) (auto simp add:List_non_null)
nipkow@14074
    65
nipkow@14074
    66
lemma List_unique1: "List h p as \<Longrightarrow> \<exists>!as. List h p as"
wenzelm@16972
    67
by (blast intro: List_unique)
nipkow@14074
    68
nipkow@14074
    69
lemma List_app: "\<And>x. List h x (as@bs) = (\<exists>y. Path h x as y \<and> List h y bs)"
wenzelm@16972
    70
by (induct as) auto
nipkow@14074
    71
nipkow@14074
    72
lemma List_hd_not_in_tl[simp]: "List h b as \<Longrightarrow> h a = Some b \<Longrightarrow> a \<notin> set as"
nipkow@14074
    73
apply (clarsimp simp add:in_set_conv_decomp)
nipkow@14074
    74
apply(frule List_app[THEN iffD1])
nipkow@14074
    75
apply(fastsimp dest: List_unique)
nipkow@14074
    76
done
nipkow@14074
    77
nipkow@14074
    78
lemma List_distinct[simp]: "\<And>x. List h x as \<Longrightarrow> distinct as"
wenzelm@16972
    79
by (induct as) (auto dest:List_hd_not_in_tl)
nipkow@14074
    80
nipkow@14074
    81
lemma list_in_heap: "\<And>p. List h p ps \<Longrightarrow> set ps \<subseteq> dom h"
wenzelm@16972
    82
by (induct ps) auto
nipkow@14074
    83
nipkow@14074
    84
lemma list_ortho_sum1[simp]:
nipkow@14074
    85
 "\<And>p. \<lbrakk> List h1 p ps; dom h1 \<inter> dom h2 = {}\<rbrakk> \<Longrightarrow> List (h1++h2) p ps"
wenzelm@16972
    86
by (induct ps) (auto simp add:map_add_def split:option.split)
nipkow@14074
    87
paulson@18447
    88
nipkow@14074
    89
lemma list_ortho_sum2[simp]:
nipkow@14074
    90
 "\<And>p. \<lbrakk> List h2 p ps; dom h1 \<inter> dom h2 = {}\<rbrakk> \<Longrightarrow> List (h1++h2) p ps"
wenzelm@16972
    91
by (induct ps) (auto simp add:map_add_def split:option.split)
nipkow@14074
    92
nipkow@14074
    93
end