src/HOL/Hoare/Separation.thy
author nipkow
Tue, 11 Mar 2003 15:04:24 +0100
changeset 13857 11d7c5a8dbb7
child 13867 1fdecd15437f
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13857
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     1
theory Separation = HoareAbort:
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     2
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     3
types heap = "(nat \<Rightarrow> nat option)"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     4
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     5
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     6
text{* The semantic definition of a few connectives: *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     7
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     8
constdefs
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
     9
 R:: "heap \<Rightarrow> heap \<Rightarrow> heap \<Rightarrow> bool"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    10
"R h h1 h2 == dom h1 \<inter> dom h2 = {} \<and> h = h1 ++ h2"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    11
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    12
 star:: "(heap \<Rightarrow> bool) \<Rightarrow> (heap \<Rightarrow> bool) \<Rightarrow> (heap \<Rightarrow> bool)"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    13
"star P Q == \<lambda>h. \<exists>h1 h2. R h h1 h2 \<and> P h1 \<and> Q h2"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    14
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    15
 singl:: "heap \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    16
"singl h x y == dom h = {x} & h x = Some y"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    17
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    18
lemma "VARS x y z w h
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    19
 {star (%h. singl h x y) (%h. singl h z w) h}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    20
 SKIP
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    21
 {x \<noteq> z}"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    22
apply vcg
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    23
apply(auto simp:star_def R_def singl_def)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    24
done
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    25
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    26
text{* To suppress the heap parameter of the connectives, we assume it
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    27
is always called H and add/remove it upon parsing/printing. Thus
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    28
every pointer program needs to have a program variable H, and
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    29
assertions should not contain any locally bound Hs - otherwise they
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    30
may bind the implicit H. *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    31
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    32
text{* Nice input syntax: *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    33
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    34
syntax
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    35
 "@singl" :: "nat \<Rightarrow> nat \<Rightarrow> bool" ("[_ \<mapsto> _]")
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    36
 "@star" :: "bool \<Rightarrow> bool \<Rightarrow> bool" (infixl "**" 60)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    37
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    38
ML{*
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    39
fun singl_tr [p,q] = Syntax.const "singl" $ Syntax.free "H" $ p $ q
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    40
  | singl_tr ts = raise TERM ("singl_tr", ts);
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    41
fun star_tr [P,Q] = Syntax.const "star" $
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    42
      absfree("H",dummyT,P) $ absfree("H",dummyT,Q) $ Syntax.free "H"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    43
  | star_tr ts = raise TERM ("star_tr", ts);
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    44
*}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    45
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    46
parse_translation {* [("@singl", singl_tr),("@star", star_tr)] *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    47
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    48
lemma "VARS H x y z w
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    49
 {[x\<mapsto>y] ** [z\<mapsto>w]}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    50
 SKIP
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    51
 {x \<noteq> z}"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    52
apply vcg
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    53
apply(auto simp:star_def R_def singl_def)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    54
done
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    55
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    56
text{* Nice output syntax: *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    57
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    58
ML{*
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    59
fun singl_tr' [_,p,q] = Syntax.const "@singl" $ p $ q
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    60
fun star_tr' [Abs(_,_,P),Abs(_,_,Q),_] = Syntax.const "@star" $ P $ Q
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    61
*}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    62
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    63
print_translation {* [("singl", singl_tr'),("star", star_tr')] *}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    64
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    65
lemma "VARS H x y z w
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    66
 {[x\<mapsto>y] ** [z\<mapsto>w]}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    67
 SKIP
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    68
 {x \<noteq> z}"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    69
apply vcg
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    70
apply(auto simp:star_def R_def singl_def)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    71
done
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    72
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    73
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    74
consts llist :: "(heap * nat)set"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    75
inductive llist
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    76
intros
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    77
empty: "(%n. None, 0) : llist"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    78
cons: "\<lbrakk> R h h1 h2; pto h1 p q; (h2,q):llist \<rbrakk> \<Longrightarrow> (h,p):llist"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    79
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    80
lemma "VARS p q h
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    81
 {(h,p) : llist}
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    82
 h := h(q \<mapsto> p)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    83
 {(h,q) : llist}"
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    84
apply vcg
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    85
apply(rule_tac "h1.0" = "%n. if n=q then Some p else None" in llist.cons)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    86
prefer 3 apply assumption
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    87
prefer 2 apply(simp add:singl_def dom_def)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    88
apply(simp add:R_def dom_def)
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    89
11d7c5a8dbb7 *** empty log message ***
nipkow
parents:
diff changeset
    90