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