Tests/abacus.thy
author Christian Urban <urbanc@in.tum.de>
Fri, 11 Jan 2019 13:37:54 +0000
changeset 297 bee184c83071
parent 230 49dcc0b9b0b3
permissions -rw-r--r--
added some text at the beginning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
header {* 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
 {\em abacus} a kind of register machine
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
*}
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
theory abacus
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
     6
imports Main (*StateMonad*)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
begin
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
text {*
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  {\em Abacus} instructions:
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
*}
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
datatype abc_inst =
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
  -- {* @{text "Inc n"} increments the memory cell (or register) 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
         with address @{text "n"} by one.
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
     *}
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
     Inc nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  -- {*
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
     @{text "Dec n label"} decrements the memory cell with address @{text "n"} by one. 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
      If cell @{text "n"} is already zero, no decrements happens and the executio jumps to
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
      the instruction labeled by @{text "label"}.
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
     *}
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
   | Dec nat nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  -- {*
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  @{text "Goto label"} unconditionally jumps to the instruction labeled by @{text "label"}.
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  *}
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
   | Goto nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    29
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    30
fun splits :: "'a set \<Rightarrow> ('a set \<times> 'a set) \<Rightarrow> bool"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    31
where "splits s (u, v) = (u \<union> v = s \<and> u \<inter> v = {})"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    33
declare splits.simps [simp del]
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    35
definition "stimes p q = {s . \<exists> u v. u \<in> p \<and> v \<in> q \<and> splits s (u, v)}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    36
lemmas st_def = stimes_def[unfolded splits.simps]
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    38
notation stimes (infixr "*" 70)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    39
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    40
lemma stimes_comm: "(p::('a set set)) * q = q * p"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    41
  by (unfold st_def, auto)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    43
lemma splits_simp: "splits s (u, v) = (v = (s - u) \<and> v \<subseteq> s \<and> u \<subseteq> s)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    44
  by (unfold splits.simps, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    45
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    46
lemma stimes_assoc: "p * q * r = (p * q) * (r::'a set set)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    47
  by (unfold st_def, blast)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
definition
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  "emp = {{}}"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
lemma emp_unit_r [simp]: "p * emp = p"
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    53
  by (unfold st_def emp_def, auto)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
lemma emp_unit_l [simp]: "emp * p = p"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  by (metis emp_unit_r stimes_comm)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
lemma stimes_mono: "p \<subseteq> q \<Longrightarrow> p * r \<subseteq> q * r"
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    59
  by (unfold st_def, auto)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
lemma stimes_left_commute:
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    62
  "(q * (p * r)) = ((p::'a set set) * (q * r))"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
by (metis stimes_assoc stimes_comm)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
lemmas stimes_ac = stimes_comm stimes_assoc stimes_left_commute
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    67
lemma "x * y * z = z * y * (x::'a set set)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    68
by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    69
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    70
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
definition pasrt :: "bool \<Rightarrow> ('a set set)" ("<_>" [71] 71)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
where "pasrt b = {s . s = {} \<and> b}"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
datatype apg = 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
   Instr abc_inst
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
 | Label nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
 | Seq apg apg
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
 | Local "(nat \<Rightarrow> apg)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    80
notation Local (binder "LOCAL " 10)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    81
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    82
term "LOCAL a b. Seq (Label a) (Label b)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    83
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    84
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
    85
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
abbreviation prog_instr :: "abc_inst \<Rightarrow> apg" ("\<guillemotright>_" [61] 61)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
where "\<guillemotright>i \<equiv> Instr i"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
abbreviation prog_seq :: "apg \<Rightarrow> apg \<Rightarrow> apg" (infixl ";" 52)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
where "c1 ; c2 \<equiv> Seq c1 c2"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
type_synonym aconf = "((nat \<rightharpoonup> abc_inst) \<times> nat \<times> (nat \<rightharpoonup> nat) \<times> nat)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
fun astep :: "aconf \<Rightarrow> aconf"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  where "astep (prog, pc, m, faults) = 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
              (case (prog pc) of
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
                  Some (Inc i) \<Rightarrow> 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
                         case m(i) of
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
                           Some n \<Rightarrow> (prog, pc + 1, m(i:= Some (n + 1)), faults)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
                         | None \<Rightarrow> (prog, pc, m, faults + 1)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
                | Some (Dec i e) \<Rightarrow> 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
                         case m(i) of
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
                           Some n \<Rightarrow> if (n = 0) then (prog, e, m, faults)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
                                     else (prog, pc + 1, m(i:= Some (n - 1)), faults)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
                         | None \<Rightarrow> (prog, pc, m, faults + 1)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
                | Some (Goto pc') \<Rightarrow> (prog, pc', m, faults)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
                | None \<Rightarrow> (prog, pc, m, faults + 1))"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
definition "run n = astep ^^ n"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
datatype aresource = 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
    M nat nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
  | C nat abc_inst
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
  | At nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  | Faults nat
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   117
definition "prog_set prog = {C i inst | i inst. prog i = Some inst}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   118
definition "pc_set pc = {At pc}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   119
definition "mem_set m = {M i n | i n. m (i) = Some n} "
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   120
definition "faults_set faults = {Faults faults}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   121
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   122
lemmas cpn_set_def = prog_set_def pc_set_def mem_set_def faults_set_def
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   123
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
fun rset_of :: "aconf \<Rightarrow> aresource set"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  where "rset_of (prog, pc, m, faults) = 
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   126
               prog_set prog \<union> pc_set pc \<union> mem_set m \<union> faults_set faults"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   127
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   128
definition "pc l = {pc_set l}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   129
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   130
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   131
definition "m a v = {{M a v}}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   132
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   133
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   134
declare rset_of.simps[simp del]
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
type_synonym assert = "aresource set set"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
primrec assemble_to :: "apg \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> assert" 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  where 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  "assemble_to (Instr ai) i j = ({{C i ai}} * <(j = i + 1)>)" |
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  "assemble_to (Seq p1 p2) i j = (\<Union> j'. (assemble_to p1 i j') * (assemble_to p2 j' j))" |
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  "assemble_to (Local fp) i j  = (\<Union> l. (assemble_to (fp l) i j))" |
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  "assemble_to (Label l) i j = <(i = j \<and> j = l)>"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
abbreviation asmb_to :: "nat \<Rightarrow> apg \<Rightarrow> nat \<Rightarrow> assert" ("_ :[ _ ]: _" [60, 60, 60] 60)
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   146
  where "i :[ apg ]: j \<equiv> assemble_to apg i j"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   147
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   148
lemma stimes_sgD: "s \<in> {x} * q \<Longrightarrow> (s - x) \<in> q \<and> x \<subseteq> s"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   149
  apply (unfold st_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   150
by (smt Diff_disjoint Un_Diff_cancel2 Un_Int_distrib 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   151
     Un_commute Un_empty_right Un_left_absorb)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   152
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   153
lemma pcD: "rset_of (prog, i', mem, fault) \<in> pc i * r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   154
       \<Longrightarrow> i' = i"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   155
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   156
  assume "rset_of (prog, i', mem, fault) \<in> pc i * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   157
  from stimes_sgD [OF this[unfolded pc_def], unfolded rset_of.simps]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   158
  have "pc_set i \<subseteq> prog_set prog \<union> pc_set i' \<union> mem_set mem \<union> faults_set fault" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   159
  thus ?thesis 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   160
    by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   161
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   162
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   163
lemma codeD: "rset_of (prog, pos, mem, fault) \<in>  pc i * {{C i inst}} * r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   164
       \<Longrightarrow> prog pos = Some inst"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   165
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   166
  assume h: "rset_of (prog, pos, mem, fault) \<in>  pc i * {{C i inst}} * r" (is "?c \<in> ?X")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   167
  from pcD[OF this] have "i = pos" by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   168
  with h show ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   169
    by (unfold rset_of.simps st_def pc_def prog_set_def 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   170
      pc_set_def mem_set_def faults_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   171
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   172
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   173
lemma memD: "rset_of (prog, pos, mem, fault) \<in>  (m a v)  * r \<Longrightarrow> mem a = Some v"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   174
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   175
  assume "rset_of (prog, pos, mem, fault) \<in>  (m a v)  * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   176
  from stimes_sgD[OF this[unfolded rset_of.simps cpn_set_def m_def]]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   177
  have "{M a v} \<subseteq> {C i inst |i inst. prog i = Some inst} \<union> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   178
            {At pos} \<union> {M i n |i n. mem i = Some n} \<union> {Faults fault}" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   179
  thus ?thesis by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   180
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
definition
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
  Hoare_abc :: "assert \<Rightarrow> assert  \<Rightarrow> assert \<Rightarrow> bool" ("({(1_)}/ (_)/ {(1_)})" 50)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
where
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   185
  "{p} c {q} \<equiv> (\<forall> s r. (rset_of s) \<in> (p*c*r) \<longrightarrow>
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   186
    (\<exists> k. ((rset_of (run k s)) \<in> (q*c*r))))" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   187
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   188
definition "dec_fun v j e = (if (v = 0) then (e, v) else (j, v - 1))"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   189
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   190
lemma disj_Diff: "a \<inter> b = {} \<Longrightarrow> a \<union> b - b = a"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   191
by (metis (lifting) Diff_cancel Un_Diff Un_Diff_Int)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   193
lemma diff_pc_set: "prog_set aa \<union> pc_set i \<union> mem_set ab \<union> faults_set b - pc_set i = 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   194
         prog_set aa \<union> mem_set ab \<union> faults_set b"  (is "?L = ?R")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   195
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   196
  have "?L = (prog_set aa \<union> mem_set ab \<union> faults_set b \<union> pc_set i)  - pc_set i"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   197
    by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   198
  also have "\<dots> = ?R"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   199
  proof(rule disj_Diff)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   200
    show " (prog_set aa \<union> mem_set ab \<union> faults_set b) \<inter> pc_set i = {}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   201
      by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   202
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   203
  finally show ?thesis .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   204
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   205
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   206
lemma M_in_simp: "({M a v} \<subseteq> prog_set x \<union> pc_set y \<union> mem_set mem \<union> faults_set f) = 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   207
        ({M a v} \<subseteq> mem_set mem)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   208
  by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   209
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   210
lemma mem_set_upd: 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   211
  "{M a v} \<subseteq> mem_set mem \<Longrightarrow> mem_set (mem(a:=Some v')) = ((mem_set mem) - {M a v}) \<union> {M a v'}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   212
  by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   213
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   214
lemma mem_set_disj: "{M a v} \<subseteq> mem_set mem \<Longrightarrow> {M a v'} \<inter>  (mem_set mem - {M a v}) = {}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   215
  by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   216
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   217
lemma stimesE:
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   218
  assumes h: "s \<in> x * y"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   219
  obtains s1 s2 where "s = s1 \<union> s2" and "s1 \<inter> s2 = {}" and "s1 \<in> x" and "s2 \<in> y"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   220
  by (insert h, auto simp:st_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   221
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   222
lemma stimesI: 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   223
  "\<lbrakk>s = s1 \<union> s2; s1 \<inter> s2 = {}; s1 \<in> x; s2 \<in> y\<rbrakk> \<Longrightarrow> s \<in> x * y"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   224
  by (auto simp:st_def)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   226
lemma smem_upd: "(rset_of (x, y, mem, f)) \<in> (m a v)*r \<Longrightarrow> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   227
                    (rset_of (x, y, mem(a := Some v'), f) \<in> (m a v')*r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   228
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   229
  assume h: " rset_of (x, y, mem, f) \<in> m a v * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   230
  from h[unfolded rset_of.simps m_def]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   231
  have "prog_set x \<union> pc_set y \<union> mem_set mem \<union> faults_set f \<in> {{M a v}} * r" .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   232
  from stimes_sgD [OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   233
  have h1: "prog_set x \<union> pc_set y \<union> mem_set mem \<union> faults_set f - {M a v} \<in> r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   234
           "{M a v} \<subseteq> prog_set x \<union> pc_set y \<union> mem_set mem \<union> faults_set f" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   235
  moreover have "prog_set x \<union> pc_set y \<union> mem_set mem \<union> faults_set f - {M a v} = 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   236
                 prog_set x \<union> pc_set y \<union> (mem_set mem  - {M a v}) \<union> faults_set f"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   237
    by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   238
  ultimately have h0: "prog_set x \<union> pc_set y \<union> (mem_set mem - {M a v}) \<union> faults_set f \<in> r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   239
    by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   240
  from h1(2) and M_in_simp have "{M a v} \<subseteq> mem_set mem" by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   241
  from mem_set_upd [OF this] mem_set_disj[OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   242
  have h2: "mem_set (mem(a \<mapsto> v')) = {M a v'} \<union> (mem_set mem - {M a v})" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   243
           "{M a v'} \<inter> (mem_set mem - {M a v}) = {}" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   244
  show ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   245
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   246
    have "mem_set (mem(a \<mapsto> v')) \<union>  prog_set x \<union> pc_set y \<union> faults_set f \<in> m a v' * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   247
    proof(rule stimesI[OF _ _ _ h0])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   248
      show "{M a v'} \<in> m a v'" by (unfold m_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   249
    next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   250
      show "mem_set (mem(a \<mapsto> v')) \<union> prog_set x \<union> pc_set y \<union> faults_set f =
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   251
             {M a v'} \<union> (prog_set x \<union> pc_set y \<union> (mem_set mem - {M a v}) \<union> faults_set f)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   252
        apply (unfold h2(1))
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   253
        by (smt Un_commute Un_insert_left Un_insert_right 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   254
             Un_left_commute 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   255
                  `prog_set x \<union> pc_set y \<union> mem_set mem \<union> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   256
                  faults_set f - {M a v} =prog_set x \<union> pc_set y 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   257
                  \<union> (mem_set mem - {M a v}) \<union> faults_set f`)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   258
    next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   259
      from h2(2)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   260
      show "{M a v'} \<inter> (prog_set x \<union> pc_set y \<union> (mem_set mem - {M a v}) \<union> faults_set f) = {}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   261
        by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   262
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   263
    thus ?thesis 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   264
      apply (unfold rset_of.simps)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   265
      by (metis `mem_set (mem(a \<mapsto> v')) 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   266
            \<union> prog_set x \<union> pc_set y \<union> faults_set f \<in> m a v' * r` 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   267
         stimes_comm sup_commute sup_left_commute)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   268
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   269
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   271
lemma spc_upd: "rset_of (x, i, y, z) \<in> pc i' * r \<Longrightarrow> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   272
                rset_of (x, i'', y, z) \<in> pc i'' * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   273
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   274
  assume h: "rset_of (x, i, y, z) \<in> pc i' * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   275
  from stimes_sgD [OF h[unfolded rset_of.simps pc_set_def pc_def]]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   276
  have h1: "prog_set x \<union> {At i} \<union> mem_set y \<union> faults_set z - {At i'} \<in> r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   277
           "{At i'} \<subseteq> prog_set x \<union> {At i} \<union> mem_set y \<union> faults_set z" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   278
  from h1(2) have eq_i: "i' = i" by (unfold cpn_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   279
  have "prog_set x \<union> {At i} \<union> mem_set y \<union> faults_set z - {At i'} =
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   280
        prog_set x  \<union> mem_set y \<union> faults_set z "
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   281
    apply (unfold eq_i)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   282
    by (metis (full_types) Un_insert_left Un_insert_right 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   283
         diff_pc_set faults_set_def insert_commute insert_is_Un 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   284
          pc_set_def sup_assoc sup_bot_left sup_commute)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   285
  with h1(1) have in_r: "prog_set x \<union>  mem_set y \<union> faults_set z \<in> r" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   286
  show ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   287
  proof(unfold rset_of.simps, rule stimesI[OF _ _ _ in_r])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   288
    show "{At i''} \<in> pc i''" by (unfold pc_def pc_set_def, simp)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   289
  next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   290
    show "prog_set x \<union> pc_set i'' \<union> mem_set y \<union> faults_set z =
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   291
    {At i''} \<union> (prog_set x \<union> mem_set y \<union> faults_set z)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   292
      by (unfold pc_set_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   293
  next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   294
    show "{At i''} \<inter> (prog_set x \<union> mem_set y \<union> faults_set z) = {}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   295
      by (auto simp:cpn_set_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   296
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   297
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   298
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   299
lemma condD: "s \<in> <b>*r \<Longrightarrow> b"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   300
  by (unfold st_def pasrt_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   301
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   302
lemma condD1: "s \<in> <b>*r \<Longrightarrow> s \<in> r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   303
  by (unfold st_def pasrt_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   304
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   305
lemma hoare_dec_suc: "{(pc i * m a v) * <(v > 0)>} 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   306
                          i:[\<guillemotright>(Dec a e) ]:j  
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   307
                      {pc j * m a (v - 1)}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   308
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   309
  fix prog i' ab b r 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   310
  assume h: "rset_of (prog, i', ab, b) \<in> ((pc i * m a v) * <(0 < v)>) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   311
                           (is "?r \<in> ?S")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   312
  show "\<exists>k. rset_of (run k (prog, i', ab, b)) \<in> (pc j * m a (v - 1)) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   313
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   314
    from h [unfolded assemble_to.simps]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   315
    have h1: "?r \<in> pc i * {{C i (Dec a e)}} * m a v * <(0 < v)> *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   316
             "?r \<in>  m a v * pc i * {{C i (Dec a e)}} * <(0 < v)> *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   317
             "?r \<in>   <(0 < v)> *  <(j = i + 1)> * m a v * pc i * {{C i (Dec a e)}} * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   318
             "?r \<in>   <(j = i + 1)> * <(0 < v)> *   m a v * pc i * {{C i (Dec a e)}} * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   319
      by ((metis stimes_ac)+)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   320
    note h2 =  condD [OF h1(3)] condD[OF h1(4)] pcD[OF h1(1)] codeD[OF h1(1)] memD[OF h1(2)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   321
    hence stp: "run 1 (prog, i', ab, b) = (prog, Suc i, ab(a \<mapsto> v - Suc 0), b)" (is "?x = ?y")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   322
      by (unfold run_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   323
    have "rset_of ?x \<in> (pc j * m a (v - 1)) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   324
    proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   325
      have "rset_of ?y \<in> (pc j * m a (v - 1)) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   326
      proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   327
        from spc_upd[OF h1(1), of "Suc i"]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   328
        have "rset_of (prog, (Suc i), ab, b) \<in> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   329
                m a v * pc (Suc i) * {{C i (Dec a e)}} * <(0 < v)> * <(j = i + 1)> * r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   330
          by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   331
        from smem_upd[OF this, of "v - (Suc 0)"]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   332
        have "rset_of ?y \<in> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   333
           m a (v - Suc 0) * pc (Suc i) * {{C i (Dec a e)}} * <(0 < v)> * <(j = i + 1)> * r" .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   334
        hence "rset_of ?y \<in> <(0 < v)> *
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   335
                (pc (Suc i) * m a (v - Suc 0)) * ({{C i (Dec a e)}} * <(j = i + 1)>) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   336
          by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   337
        from condD1[OF this] 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   338
        have "rset_of ?y \<in> (pc (Suc i) * m a (v - Suc 0)) * ({{C i (Dec a e)}} * <(j = i + 1)>) * r" .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   339
        thus ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   340
          by (unfold h2(2) assemble_to.simps, simp)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   341
      qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   342
      with stp show ?thesis by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   343
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   344
    thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   345
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   346
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
lemma hoare_dec_fail: "{pc i * m a 0} 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
                          i:[ \<guillemotright>(Dec a e) ]:j   
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
                       {pc e * m a 0}"
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   351
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   352
  fix prog i' ab b r 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   353
  assume h: "rset_of (prog, i', ab, b) \<in> (pc i * m a 0) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   354
                           (is "?r \<in> ?S")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   355
  show "\<exists>k. rset_of (run k (prog, i', ab, b)) \<in> (pc e * m a 0) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   356
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   357
    from h [unfolded assemble_to.simps]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   358
    have h1: "?r \<in> pc i * {{C i (Dec a e)}} * m a 0  *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   359
             "?r \<in>  m a 0 * pc i * {{C i (Dec a e)}} *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   360
             "?r \<in> <(j = i + 1)> * m a 0 * pc i * {{C i (Dec a e)}} * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   361
      by ((metis stimes_ac)+)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   362
    note h2 =  condD [OF h1(3)]  pcD[OF h1(1)] codeD[OF h1(1)] memD[OF h1(2)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   363
    hence stp: "run 1 (prog, i', ab, b) = (prog, e, ab, b)" (is "?x = ?y")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   364
      by (unfold run_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   365
    have "rset_of ?x \<in> (pc e * m a 0) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   366
    proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   367
      have "rset_of ?y \<in> (pc e * m a 0) * (i :[ \<guillemotright>Dec a e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   368
      proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   369
        from spc_upd[OF h1(1), of "e"]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   370
        have "rset_of ?y \<in> pc e * {{C i (Dec a e)}} * m a 0 * <(j = i + 1)> * r" .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   371
        thus ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   372
          by (unfold assemble_to.simps, metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   373
      qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   374
      with stp show ?thesis by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   375
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   376
    thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   377
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   378
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   379
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   380
lemma pasrtD_p: "\<lbrakk>{p*<b>} c {q}\<rbrakk> \<Longrightarrow> (b \<longrightarrow> {p} c {q})"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   381
  apply (unfold Hoare_abc_def pasrt_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   382
  by (fold emp_def, simp add:emp_unit_r)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   383
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   384
lemma hoare_dec: "dec_fun v j e = (pc', v') \<Longrightarrow> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   385
                    {pc i * m a v} 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   386
                       i:[ \<guillemotright>(Dec a e) ]:j   
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   387
                    {pc pc' * m a v'}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   388
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   389
  assume "dec_fun v j e = (pc', v')"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   390
  thus  "{pc i * m a v} 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   391
                       i:[ \<guillemotright>(Dec a e) ]:j   
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   392
                    {pc pc' * m a v'}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   393
    apply (auto split:if_splits simp:dec_fun_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   394
    apply (insert hoare_dec_fail, auto)[1]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   395
    apply (insert hoare_dec_suc, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   396
    apply (atomize)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   397
    apply (erule_tac x = i in allE, erule_tac x = a in allE,
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   398
           erule_tac x = v in allE, erule_tac x = e in allE, erule_tac x = pc' in allE)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   399
    by (drule_tac pasrtD_p, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   400
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
lemma hoare_inc: "{pc i * m a v} 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
                      i:[ \<guillemotright>(Inc a) ]:j   
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   404
                  {pc j * m a (v + 1)}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   405
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   406
  fix prog i' ab b r 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   407
  assume h: "rset_of (prog, i', ab, b) \<in> (pc i * m a v) * (i :[ \<guillemotright>Inc a ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   408
                           (is "?r \<in> ?S")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   409
  show "\<exists>k. rset_of (run k (prog, i', ab, b)) \<in> (pc j * m a (v + 1)) * (i :[ \<guillemotright>Inc a ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   410
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   411
    from h [unfolded assemble_to.simps]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   412
    have h1: "?r \<in> pc i * {{C i (Inc a)}} * m a v *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   413
             "?r \<in>  m a v * pc i * {{C i (Inc a)}} * <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   414
             "?r \<in>   <(j = i + 1)> * m a v * pc i * {{C i (Inc a)}} * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   415
      by ((metis stimes_ac)+)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   416
    note h2 =  condD [OF h1(3)] pcD[OF h1(1)] codeD[OF h1(1)] memD[OF h1(2)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   417
    hence stp: "run 1 (prog, i', ab, b) = (prog, Suc i, ab(a \<mapsto> Suc v), b)" (is "?x = ?y")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   418
      by (unfold run_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   419
    have "rset_of ?x \<in> (pc j * m a (v + 1)) * (i :[ \<guillemotright>Inc a]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   420
    proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   421
      have "rset_of ?y \<in> (pc j * m a (v + 1)) * (i :[ \<guillemotright>Inc a ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   422
      proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   423
        from spc_upd[OF h1(1), of "Suc i"]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   424
        have "rset_of (prog, (Suc i), ab, b) \<in> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   425
                m a v * pc (Suc i) * {{C i (Inc a)}} * <(j = i + 1)> * r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   426
          by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   427
        from smem_upd[OF this, of "Suc v"]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   428
        have "rset_of ?y \<in> 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   429
           m a (v + 1) * pc (i + 1) * {{C i (Inc a)}} * <(j = i + 1)> * r" by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   430
        thus ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   431
          by (unfold h2(1) assemble_to.simps, metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   432
      qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   433
      with stp show ?thesis by simp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   434
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   435
    thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   436
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   437
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   439
lemma hoare_goto: "{pc i} 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   440
                      i:[ \<guillemotright>(Goto e) ]:j   
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   441
                   {pc e}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   442
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   443
  fix prog i' ab b r 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   444
  assume h: "rset_of (prog, i', ab, b) \<in> pc i * (i :[ \<guillemotright>Goto e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   445
                           (is "?r \<in> ?S")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   446
  show "\<exists>k. rset_of (run k (prog, i', ab, b)) \<in> pc e * (i :[ \<guillemotright>Goto e ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   447
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   448
    from h [unfolded assemble_to.simps]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   449
    have h1: "?r \<in> pc i * {{C i (Goto e)}} *  <(j = i + 1)> * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   450
      by ((metis stimes_ac)+)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   451
    note h2 = pcD[OF h1(1)] codeD[OF h1(1)] 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   452
    hence stp: "run 1 (prog, i', ab, b) = (prog, e, ab, b)" (is "?x = ?y")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   453
      by (unfold run_def, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   454
    have "rset_of ?x \<in> pc e * (i :[ \<guillemotright>Goto e]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   455
    proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   456
      from spc_upd[OF h1(1), of "e"] 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   457
      show ?thesis
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   458
        by (unfold stp assemble_to.simps, metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   459
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   460
    thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   461
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   462
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   464
no_notation stimes (infixr "*" 70)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   465
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   466
interpretation foo: comm_monoid_mult 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   467
  "stimes :: 'a set set => 'a set set => 'a set set" "emp::'a set set"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
apply(default)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
apply(simp add: stimes_assoc)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
apply(simp add: stimes_comm)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
apply(simp add: emp_def[symmetric])
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
done
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   475
notation stimes (infixr "*" 70)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   476
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
(*used by simplifier for numbers *)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
thm mult_cancel_left
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
(*
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
interpretation foo: comm_ring_1 "op * :: 'a set set => 'a set set => 'a set set" "{{}}::'a set set" 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
apply(default)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
*)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   485
lemma frame: "{p} c {q} \<Longrightarrow>  \<forall> r. {p * r} c {q * r}"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
apply (unfold Hoare_abc_def, clarify)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
apply (erule_tac x = "(a, aa, ab, b)" in allE)
224
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 223
diff changeset
   488
apply (erule_tac x = "r * ra" in allE) 
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   489
apply(metis stimes_ac)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
done
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
lemma code_extension: "\<lbrakk>{p} c {q}\<rbrakk> \<Longrightarrow> (\<forall> e. {p} c * e {q})"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
  apply (unfold Hoare_abc_def, clarify)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
  apply (erule_tac x = "(a, aa, ab, b)" in allE)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
  apply (erule_tac x = "e * r" in allE)
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   496
  apply(metis stimes_ac)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
  done
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
lemma run_add: "run (n1 + n2) s = run n1 (run n2 s)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
apply (unfold run_def)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
by (metis funpow_add o_apply)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
lemma composition: "\<lbrakk>{p} c1 {q}; {q} c2 {r}\<rbrakk> \<Longrightarrow> {p} c1 * c2 {r}"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   504
proof -
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   505
  assume h: "{p} c1 {q}" "{q} c2 {r}"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
  from code_extension [OF h(1), rule_format, of "c2"] 
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
  have "{p} c1 * c2 {q}" .
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
  moreover from code_extension [OF h(2), rule_format, of "c1"] and stimes_comm
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
  have "{q} c1 * c2 {r}" by metis
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
  ultimately show "{p} c1 * c2 {r}"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
    apply (unfold Hoare_abc_def, clarify)
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
    proof -
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
      fix a aa ab b ra
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
      assume h1: "\<forall>s r. rset_of s \<in> p * (c1 * c2) * r \<longrightarrow>
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
                       (\<exists>k. rset_of (run k s) \<in> q * (c1 * c2) * r)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
        and h2: "\<forall>s ra. rset_of s \<in> q * (c1 * c2) * ra \<longrightarrow>
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
                       (\<exists>k. rset_of (run k s) \<in> r * (c1 * c2) * ra)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
        and h3: "rset_of (a, aa, ab, b) \<in> p * (c1 * c2) * ra"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
      show "\<exists>k. rset_of (run k (a, aa, ab, b)) \<in> r * (c1 * c2) * ra"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
      proof -
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
        let ?s = "(a, aa, ab, b)"
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
        from h1 [rule_format, of ?s, OF h3]
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
        obtain n1 where "rset_of (run n1 ?s) \<in> q * (c1 * c2) * ra" by blast
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
        from h2 [rule_format, OF this]
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
        obtain n2 where "rset_of (run n2 (run n1 ?s)) \<in> r * (c1 * c2) * ra" by blast
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
        with run_add show ?thesis by metis
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
      qed
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
    qed
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
qed
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   531
lemma stimes_simp: "s \<in> x * y = (\<exists> s1 s2. (s = s1 \<union> s2 \<and> s1 \<inter> s2 = {} \<and> s1 \<in> x \<and> s2 \<in> y))"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   532
by (metis (lifting) stimesE stimesI)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   534
lemma hoare_seq: 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   535
  "\<lbrakk>\<forall> i j. {pc i * p} i:[c1]:j {pc j * q}; 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   536
    \<forall> j k. {pc j * q} j:[c2]:k {pc k * r}\<rbrakk> \<Longrightarrow>  {pc i * p} i:[(c1 ; c2)]:k {pc k *r}"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
proof -
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   538
  assume h: "\<forall>i j. {pc i * p} i :[ c1 ]: j {pc j * q}" "\<forall> j k. {pc j * q} j:[c2]:k {pc k * r}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   539
  show "{pc i * p} i:[(c1 ; c2)]:k {pc k *r}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   540
  proof(subst Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   541
    fix a aa ab b ra
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   542
    assume "rset_of (a, aa, ab, b) \<in> (pc i * p) * (i :[ (c1 ; c2) ]: k) * ra"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   543
    hence "rset_of (a, aa, ab, b) \<in> (i :[ (c1 ; c2) ]: k) * (pc i * p * ra)" (is "?s \<in> ?X * ?Y")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   544
      by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   545
    from stimesE[OF this] obtain s1 s2 where
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   546
      sp: "rset_of(a, aa, ab, b) = s1 \<union> s2" "s1 \<inter> s2 = {}" "s1 \<in> ?X" "s2 \<in> ?Y" by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   547
    from sp (3) obtain j' where 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   548
      "s1 \<in> (i:[c1]:j') * (j':[c2]:k)" (is "s1 \<in> ?Z")
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   549
      by (auto simp:assemble_to.simps)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   550
    from stimesI[OF sp(1, 2) this sp(4)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   551
    have "?s \<in>  (pc i * p) * (i :[ c1 ]: j') * (j' :[ c2 ]: k) * ra" by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   552
    from h(1)[unfolded Hoare_abc_def, rule_format, OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   553
    obtain ka where 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   554
      "rset_of (run ka (a, aa, ab, b)) \<in> (pc j' * q) * (j' :[ c2 ]: k) * ((i :[ c1 ]: j') * ra)" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   555
      sorry
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   556
    from h(2)[unfolded Hoare_abc_def, rule_format, OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   557
    obtain kb where 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   558
      "rset_of (run kb (run ka (a, aa, ab, b)))
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   559
      \<in>  (pc k * r) * (j' :[ c2 ]: k) * (i :[ c1 ]: j') * ra" by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   560
    hence h3: "rset_of (run (kb + ka) (a, aa, ab, b))
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   561
      \<in> pc k * r * (j' :[ c2 ]: k) * ((i :[ c1 ]: j') * ra)" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   562
      sorry
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   563
    hence "rset_of (run (kb + ka) (a, aa, ab, b)) \<in> pc k * r * (i :[ (c1 ; c2) ]: k) * ra"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   564
    proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   565
      have "rset_of (run (kb + ka) (a, aa, ab, b)) \<in> (i :[ (c1 ; c2) ]: k) * (pc k * r * ra)"
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
      proof -
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   567
        from h3 have "rset_of (run (kb + ka) (a, aa, ab, b))
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   568
          \<in> ((j' :[ c2 ]: k) * ((i :[ c1 ]: j'))) * (pc k * r *  ra)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   569
          by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   570
        then obtain 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   571
          s1 s2 where h4: "rset_of (run (kb + ka) (a, aa, ab, b)) = s1 \<union> s2"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   572
          " s1 \<inter> s2 = {}" "s1 \<in> (j' :[ c2 ]: k) * (i :[ c1 ]: j')"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   573
          "s2 \<in>  pc k * r * ra" by (rule stimesE, blast)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   574
        from h4(3) have "s1 \<in> (i :[ (c1 ; c2) ]: k)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   575
          sorry
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   576
        from stimesI [OF h4(1, 2) this h4(4)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   577
        show ?thesis .
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
      qed
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   579
      thus ?thesis by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   580
    qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   581
    thus "\<exists>ka. rset_of (run ka (a, aa, ab, b)) \<in> (pc k * r) * (i :[ (c1 ; c2) ]: k) * ra"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   582
      by (metis stimes_ac)
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
  qed
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
qed
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
  
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   586
lemma hoare_local: 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   587
  "\<forall> l i j. {pc i*p} i:[c(l)]:j {pc j * q} 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   588
  \<Longrightarrow> {pc i * p} i:[Local c]:j {pc j * q}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   589
proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   590
  assume h: "\<forall> l i j. {pc i*p} i:[c(l)]:j {pc j * q} "
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   591
  show "{pc i * p} i:[Local c]:j {pc j * q}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   592
  proof(unfold assemble_to.simps Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   593
    fix a aa ab b r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   594
    assume h1: "rset_of (a, aa, ab, b) \<in> (pc i * p) * (\<Union>l. i :[ c l ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   595
    hence "rset_of (a, aa, ab, b) \<in> (\<Union>l. i :[ c l ]: j) * (pc i * p * r)" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   596
      by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   597
    then obtain s1 s2 l 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   598
      where "rset_of (a, aa, ab, b) = s1 \<union> s2"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   599
                "s1 \<inter> s2 = {}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   600
                "s1 \<in> (i :[ c l ]: j)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   601
                "s2 \<in> pc i * p * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   602
      by (rule stimesE, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   603
    from stimesI[OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   604
    have "rset_of (a, aa, ab, b) \<in> (pc i * p) * (i :[ c l ]: j) * r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   605
      by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   606
    from h[unfolded Hoare_abc_def, rule_format, OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   607
    obtain k where "rset_of (run k (a, aa, ab, b)) \<in> (i :[ c l ]: j) * (pc j * q * r)" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   608
      sorry
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   609
    then obtain s1 s2
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   610
      where h3: "rset_of (run k (a, aa, ab, b)) = s1 \<union> s2"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   611
                " s1 \<inter> s2 = {}" "s1 \<in> (\<Union> l. (i :[ c l ]: j))" "s2 \<in> pc j * q * r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   612
      by(rule stimesE, auto)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   613
    from stimesI[OF this]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   614
    show "\<exists>k. rset_of (run k (a, aa, ab, b)) \<in> (pc j * q) * (\<Union>l. i :[ c l ]: j) * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   615
      by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   616
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   617
qed
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   619
lemma move_pure: "{p*<b>} c {q} = (b \<longrightarrow> {p} c {q})"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   620
proof(unfold Hoare_abc_def, default, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   621
  fix prog i' mem ft r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   622
  assume h: "\<forall>s r. rset_of s \<in> (p * <b>) * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   623
            "b" "rset_of (prog, i', mem, ft) \<in> p * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   624
  show "\<exists>k. rset_of (run k (prog, i', mem, ft)) \<in> q * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   625
  proof(rule h(1)[rule_format])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   626
    have "(p * <b>) * c * r = <b> * p * c * r" by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   627
    moreover have "rset_of (prog, i', mem, ft) \<in> \<dots>"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   628
    proof(rule stimesI[OF _ _ _ h(3)])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   629
      from h(2) show "{} \<in> <b>" by (auto simp:pasrt_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   630
    qed auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   631
    ultimately show "rset_of (prog, i', mem, ft) \<in> (p * <b>) * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   632
      by (simp)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   633
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   634
next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   635
  assume h: "b \<longrightarrow> (\<forall>s r. rset_of s \<in> p * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r))"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   636
  show "\<forall>s r. rset_of s \<in> (p * <b>) * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   637
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   638
    { fix s r 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   639
      assume "rset_of s \<in> (p * <b>) * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   640
      hence h1: "rset_of s \<in> <b> * p * c * r" by (metis stimes_ac)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   641
      have "(\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   642
      proof(rule h[rule_format])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   643
        from condD[OF h1] show b .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   644
      next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   645
        from condD1[OF h1] show "rset_of s \<in> p * c * r" .
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   646
      qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   647
    } thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   648
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   649
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   650
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   651
lemma precond_ex: "{\<Union> x. p x} c {q} = (\<forall> x. {p x} c {q})"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   652
proof(unfold Hoare_abc_def, default, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   653
  fix x prog i' mem ft r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   654
  assume h: "\<forall>s r. rset_of s \<in> UNION UNIV p * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   655
            "rset_of (prog, i', mem, ft) \<in> p x * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   656
  show "\<exists>k. rset_of (run k (prog, i', mem, ft)) \<in> q * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   657
  proof(rule h[rule_format])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   658
    from h(2) show "rset_of (prog, i', mem, ft) \<in> UNION UNIV p * c * r" by (auto simp:stimes_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   659
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   660
next
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   661
  assume h: "\<forall>x s r. rset_of s \<in> p x * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   662
  show "\<forall>s r. rset_of s \<in> UNION UNIV p * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   663
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   664
    { fix s r
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   665
      assume "rset_of s \<in> UNION UNIV p * c * r"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   666
      then obtain x where "rset_of s \<in> p x * c * r" 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   667
        by (unfold st_def, auto, metis)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   668
      hence "(\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   669
        by(rule h[rule_format])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   670
    } thus ?thesis by blast
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   671
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   672
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   673
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   674
lemma pre_stren: "\<lbrakk>{p} c {q}; r \<subseteq> p\<rbrakk> \<Longrightarrow> {r} c {q}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   675
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   676
  fix prog i' mem ft r'
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   677
  assume h: "\<forall>s r. rset_of s \<in> p * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   678
            " r \<subseteq> p" " rset_of (prog, i', mem, ft) \<in> r * c * r'"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   679
  show "\<exists>k. rset_of (run k (prog, i', mem, ft)) \<in> q * c * r'"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   680
  proof(rule h(1)[rule_format])
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   681
    from stimes_mono[OF h(2), of "c * r'"] h(3)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   682
    show "rset_of (prog, i', mem, ft) \<in> p * c * r'" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   683
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   684
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   685
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   686
lemma post_weaken: "\<lbrakk>{p} c {q}; q \<subseteq> r\<rbrakk> \<Longrightarrow> {p} c {r}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   687
proof(unfold Hoare_abc_def, clarify)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   688
  fix prog i' mem ft r'
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   689
  assume h: "\<forall>s r. rset_of s \<in> p * c * r \<longrightarrow> (\<exists>k. rset_of (run k s) \<in> q * c * r)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   690
            " q \<subseteq> r" "rset_of (prog, i', mem, ft) \<in> p * c * r'"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   691
  show "\<exists>k. rset_of (run k (prog, i', mem, ft)) \<in> r * c * r'"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   692
  proof -
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   693
    from h(1)[rule_format, OF h(3)]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   694
    obtain k where "rset_of (run k (prog, i', mem, ft)) \<in> q * c * r'" by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   695
    moreover from h(2) have "\<dots> \<subseteq> r * c * r'" by (metis stimes_mono)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   696
    ultimately show ?thesis by auto
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   697
  qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   698
qed
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 224
diff changeset
   699
223
db6ba2232945 added a stimes_ac lemma for Xingyuan
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
end