thys/Turing_Hoare.thy
author Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
Mon, 07 Jan 2019 13:44:19 +0100
changeset 292 293e9c6f22e1
parent 288 a9003e6d0463
permissions -rwxr-xr-x
Added myself to the comments at the start of all files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     1
(* Title: thys/Turing_Hoare.thy
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     2
   Author: Jian Xu, Xingyuan Zhang, and Christian Urban
292
293e9c6f22e1 Added myself to the comments at the start of all files
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 288
diff changeset
     3
   Modifications: Sebastiaan Joosten
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     4
*)
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     5
288
a9003e6d0463 Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 168
diff changeset
     6
chapter {* Hoare Rules for TMs *}
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     7
163
67063c5365e1 changed theory names to uppercase
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 99
diff changeset
     8
theory Turing_Hoare
67063c5365e1 changed theory names to uppercase
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 99
diff changeset
     9
imports Turing
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
begin
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
59
30950dadd09f polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 56
diff changeset
    12
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
type_synonym assert = "tape \<Rightarrow> bool"
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
definition 
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  assert_imp :: "assert \<Rightarrow> assert \<Rightarrow> bool" ("_ \<mapsto> _" [0, 0] 100)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
where
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  "P \<mapsto> Q \<equiv> \<forall>l r. P (l, r) \<longrightarrow> Q (l, r)"
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    20
lemma [intro, simp]:
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    21
  "P \<mapsto> P"
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    22
unfolding assert_imp_def by simp
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    23
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
fun 
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  holds_for :: "(tape \<Rightarrow> bool) \<Rightarrow> config \<Rightarrow> bool" ("_ holds'_for _" [100, 99] 100)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
where
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  "P holds_for (s, l, r) = P (l, r)"  
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
lemma is_final_holds[simp]:
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  assumes "is_final c"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    31
  shows "Q holds_for (steps c p n) = Q holds_for c"
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
using assms 
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
apply(induct n)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
apply(auto)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
apply(case_tac [!] c)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
apply(auto)
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
done
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    39
(* Hoare Rules *)
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    40
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    41
(* halting case *)
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    42
definition
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
    43
  Hoare_halt :: "assert \<Rightarrow> tprog0 \<Rightarrow> assert \<Rightarrow> bool" ("({(1_)}/ (_)/ {(1_)})" 50)
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    44
where
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    45
  "{P} p {Q} \<equiv> \<forall>tp. P tp \<longrightarrow> (\<exists>n. is_final (steps0 (1, tp) p n) \<and> Q holds_for (steps0 (1, tp) p n))"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    46
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    47
(* not halting case *)
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    48
definition
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    49
  Hoare_unhalt :: "assert \<Rightarrow> tprog0 \<Rightarrow> bool" ("({(1_)}/ (_)) \<up>" 50)
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    50
where
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    51
  "{P} p \<up> \<equiv> \<forall>tp. P tp \<longrightarrow> (\<forall> n . \<not> (is_final (steps0 (1, tp) p n)))"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    52
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    53
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    54
lemma Hoare_haltI:
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    55
  assumes "\<And>l r. P (l, r) \<Longrightarrow> \<exists>n. is_final (steps0 (1, (l, r)) p n) \<and> Q holds_for (steps0 (1, (l, r)) p n)"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    56
  shows "{P} p {Q}"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    57
unfolding Hoare_halt_def 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    58
using assms by auto
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    59
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    60
lemma Hoare_unhaltI:
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    61
  assumes "\<And>l r n. P (l, r) \<Longrightarrow> \<not> is_final (steps0 (1, (l, r)) p n)"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    62
  shows "{P} p \<up>"
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    63
unfolding Hoare_unhalt_def 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    64
using assms by auto
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    65
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    66
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    67
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
text {*
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    70
  {P} A {Q}   {Q} B {S}  A well-formed
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    71
  -----------------------------------------
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    72
  {P} A |+| B {S}
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
*}
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    76
lemma Hoare_plus_halt [case_names A_halt B_halt A_wf]: 
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    77
  assumes A_halt : "{P} A {Q}"
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    78
  and B_halt : "{Q} B {S}"
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  and A_wf : "tm_wf (A, 0)"
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    80
  shows "{P} A |+| B {S}"
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    81
proof(rule Hoare_haltI)
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  fix l r
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    83
  assume h: "P (l, r)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    84
  then obtain n1 l' r' 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    85
    where "is_final (steps0 (1, l, r) A n1)"  
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    86
      and a1: "Q holds_for (steps0 (1, l, r) A n1)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    87
      and a2: "steps0 (1, l, r) A n1 = (0, l', r')"
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    88
    using A_halt unfolding Hoare_halt_def
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    89
    by (metis is_final_eq surj_pair) 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    90
  then obtain n2 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    91
    where "steps0 (1, l, r) (A |+| B) n2 = (Suc (length A div 2), l', r')"
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    92
    using A_wf by (rule_tac tm_comp_next) 
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  moreover
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    94
  from a1 a2 have "Q (l', r')" by (simp)
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    95
  then obtain n3 l'' r''
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    96
    where "is_final (steps0 (1, l', r') B n3)" 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
    97
    and b1: "S holds_for (steps0 (1, l', r') B n3)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
    98
    and b2: "steps0 (1, l', r') B n3 = (0, l'', r'')"
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
    99
    using B_halt unfolding Hoare_halt_def 
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   100
    by (metis is_final_eq surj_pair) 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   101
  then have "steps0 (Suc (length A div 2), l', r')  (A |+| B) n3 = (0, l'', r'')"
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
   102
    using A_wf by (rule_tac tm_comp_final) 
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
  ultimately show 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   104
    "\<exists>n. is_final (steps0 (1, l, r) (A |+| B) n) \<and> S holds_for (steps0 (1, l, r) (A |+| B) n)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   105
    using b1 b2 by (rule_tac x = "n2 + n3" in exI) (simp)
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
qed
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   108
text {*
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   109
  {P} A {Q}   {Q} B loops   A well-formed
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   110
  ------------------------------------------
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   111
          {P} A |+| B  loops
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   112
*}
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   114
lemma Hoare_plus_unhalt [case_names A_halt B_unhalt A_wf]:
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   115
  assumes A_halt: "{P} A {Q}"
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   116
  and B_uhalt: "{Q} B \<up>"
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  and A_wf : "tm_wf (A, 0)"
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   118
  shows "{P} (A |+| B) \<up>"
64
5c74f6b38a63 updated h_uh proof in uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   119
proof(rule_tac Hoare_unhaltI)
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   120
  fix n l r 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   121
  assume h: "P (l, r)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   122
  then obtain n1 l' r'
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   123
    where a: "is_final (steps0 (1, l, r) A n1)" 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   124
    and b: "Q holds_for (steps0 (1, l, r) A n1)"
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   125
    and c: "steps0 (1, l, r) A n1 = (0, l', r')"
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
   126
    using A_halt unfolding Hoare_halt_def 
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   127
    by (metis is_final_eq surj_pair) 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   128
  then obtain n2 where eq: "steps0 (1, l, r) (A |+| B) n2 = (Suc (length A div 2), l', r')"
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
   129
    using A_wf by (rule_tac tm_comp_next)
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   130
  then show "\<not> is_final (steps0 (1, l, r) (A |+| B) n)"
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   131
  proof(cases "n2 \<le> n")
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   132
    case True
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   133
    from b c have "Q (l', r')" by simp
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   134
    then have "\<forall> n. \<not> is_final (steps0 (1, l', r') B n)  "
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   135
      using B_uhalt unfolding Hoare_unhalt_def by simp
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   136
    then have "\<not> is_final (steps0 (1, l', r') B (n - n2))" by auto
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   137
    then obtain s'' l'' r'' 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   138
      where "steps0 (1, l', r') B (n - n2) = (s'', l'', r'')" 
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   139
      and "\<not> is_final (s'', l'', r'')" by (metis surj_pair)
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   140
    then have "steps0 (Suc (length A div 2), l', r') (A |+| B) (n - n2) = (s''+ length A div 2, l'', r'')"
168
d7570dbf9f06 small changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
   141
      using A_wf by (auto dest: tm_comp_second simp del: tm_wf.simps)
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   142
    then have "\<not> is_final (steps0 (1, l, r) (A |+| B) (n2 + (n  - n2)))"
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   143
      using A_wf by (simp only: steps_add eq) (simp add: tm_wf.simps)
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   144
    then show "\<not> is_final (steps0 (1, l, r) (A |+| B) n)" 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   145
      using `n2 \<le> n` by simp
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   146
  next 
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   147
    case False
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   148
    then obtain n3 where "n = n2 - n3"
288
a9003e6d0463 Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 168
diff changeset
   149
      using diff_le_self le_imp_diff_is_add nat_le_linear
a9003e6d0463 Up to date for Isabelle 2018. Gave names to simp rules in UF and UTM
Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
parents: 168
diff changeset
   150
      add.commute by metis
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   151
    moreover
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   152
    with eq show "\<not> is_final (steps0 (1, l, r) (A |+| B) n)"
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   153
      by (simp add: not_is_final[where ?n1.0="n2"])
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
  qed
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
qed
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   157
lemma Hoare_consequence:
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   158
  assumes "P' \<mapsto> P" "{P} p {Q}" "Q \<mapsto> Q'"
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  shows "{P'} p {Q'}"
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
using assms
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 64
diff changeset
   161
unfolding Hoare_halt_def assert_imp_def
61
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   162
by (metis holds_for.simps surj_pair)
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   163
7edbd5657702 updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 59
diff changeset
   164
55
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
cd4ef33c8fb1 added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
end