src/HOL/Hoare/SepLogHeap.thy
author wenzelm
Sun, 31 Dec 2023 19:24:37 +0100
changeset 79409 e1895596e1b9
parent 72990 db8f94656024
permissions -rw-r--r--
minor performance tuning: proper Same.operation; clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 38353
diff changeset
     1
(*  Title:      HOL/Hoare/SepLogHeap.thy
14074
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
72990
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
     6
section \<open>Heap abstractions for Separation Logic\<close>
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
     7
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
     8
text \<open>(at the moment only Path and List)\<close>
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
     9
18576
8d98b7711e47 Reversed Larry's option/iff change.
nipkow
parents: 18447
diff changeset
    10
theory SepLogHeap
72990
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
    11
  imports Main
18576
8d98b7711e47 Reversed Larry's option/iff change.
nipkow
parents: 18447
diff changeset
    12
begin
18447
da548623916a removed or modified some instances of [iff]
paulson
parents: 16972
diff changeset
    13
42174
d0be2722ce9f modernized specifications;
wenzelm
parents: 41959
diff changeset
    14
type_synonym heap = "(nat \<Rightarrow> nat option)"
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    15
62042
6c6ccf573479 isabelle update_cartouches -c -t;
wenzelm
parents: 44890
diff changeset
    16
text\<open>\<open>Some\<close> means allocated, \<open>None\<close> means
6c6ccf573479 isabelle update_cartouches -c -t;
wenzelm
parents: 44890
diff changeset
    17
free. Address \<open>0\<close> serves as the null reference.\<close>
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    18
72990
db8f94656024 tuned document, notably authors and sections;
wenzelm
parents: 62042
diff changeset
    19
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    20
subsection "Paths in the heap"
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    21
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    22
primrec Path :: "heap \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat \<Rightarrow> bool"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    23
where
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    24
  "Path h x [] y = (x = y)"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    25
| "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
    26
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    27
lemma [iff]: "Path h 0 xs y = (xs = [] \<and> y = 0)"
16972
d3f9abe00712 no eq_sym_conv;
wenzelm
parents: 16417
diff changeset
    28
by (cases xs) simp_all
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    29
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    30
lemma [simp]: "x\<noteq>0 \<Longrightarrow> Path h x as z =
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    31
 (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
    32
by (cases as) auto
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    33
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    34
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
    35
by (induct as) auto
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    36
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    37
lemma Path_upd[simp]:
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    38
 "\<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
    39
by (induct as) simp_all
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    40
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    41
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    42
subsection "Lists on the heap"
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    43
38353
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    44
definition List :: "heap \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> bool"
d98baa2cf589 modernized specifications;
wenzelm
parents: 35416
diff changeset
    45
  where "List h x as = Path h x as 0"
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    46
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    47
lemma [simp]: "List h x [] = (x = 0)"
16972
d3f9abe00712 no eq_sym_conv;
wenzelm
parents: 16417
diff changeset
    48
by (simp add: List_def)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    49
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    50
lemma [simp]:
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    51
 "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
    52
by (simp add: List_def)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    53
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    54
lemma [simp]: "List h 0 as = (as = [])"
16972
d3f9abe00712 no eq_sym_conv;
wenzelm
parents: 16417
diff changeset
    55
by (cases as) simp_all
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    56
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    57
lemma List_non_null: "a\<noteq>0 \<Longrightarrow>
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    58
 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
    59
by (cases as) simp_all
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    60
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    61
theorem notin_List_update[simp]:
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    62
 "\<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
    63
by (induct as) simp_all
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    64
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    65
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
    66
by (induct as) (auto simp add:List_non_null)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    67
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    68
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
    69
by (blast intro: List_unique)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    70
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    71
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
    72
by (induct as) auto
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    73
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    74
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
    75
apply (clarsimp simp add:in_set_conv_decomp)
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    76
apply(frule List_app[THEN iffD1])
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 42174
diff changeset
    77
apply(fastforce dest: List_unique)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    78
done
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    79
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    80
lemma List_distinct[simp]: "\<And>x. List h x as \<Longrightarrow> distinct as"
16972
d3f9abe00712 no eq_sym_conv;
wenzelm
parents: 16417
diff changeset
    81
by (induct as) (auto dest:List_hd_not_in_tl)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    82
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    83
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
    84
by (induct ps) auto
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    85
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    86
lemma list_ortho_sum1[simp]:
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    87
 "\<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
    88
by (induct ps) (auto simp add:map_add_def split:option.split)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    89
18447
da548623916a removed or modified some instances of [iff]
paulson
parents: 16972
diff changeset
    90
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    91
lemma list_ortho_sum2[simp]:
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    92
 "\<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
    93
by (induct ps) (auto simp add:map_add_def split:option.split)
14074
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    94
93dfce3b6f86 *** empty log message ***
nipkow
parents:
diff changeset
    95
end