author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 22 Jan 2013 14:38:56 +0000 | |
changeset 61 | 7edbd5657702 |
parent 59 | 30950dadd09f |
child 62 | e33306b4c62e |
permissions | -rw-r--r-- |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory turing_hoare |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports turing_basic |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
59
30950dadd09f
polished turing_basic
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
56
diff
changeset
|
5 |
|
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
type_synonym assert = "tape \<Rightarrow> bool" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
definition |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
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
|
10 |
where |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
"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
|
12 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
fun |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
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
|
15 |
where |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
"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
|
17 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
18 |
(* halting case *) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
19 |
definition |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
20 |
Hoare :: "assert \<Rightarrow> tprog0 \<Rightarrow> assert \<Rightarrow> bool" ("({(1_)}/ (_)/ {(1_)})" [50, 49] 50) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
21 |
where |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
22 |
"{P} p {Q} \<equiv> |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
23 |
(\<forall>tp. P tp \<longrightarrow> (\<exists>n. is_final (steps0 (1, tp) p n) \<and> Q holds_for (steps0 (1, tp) p n)))" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
24 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
25 |
(* not halting case *) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
26 |
definition |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
27 |
Hoare_unhalt :: "assert \<Rightarrow> tprog0 \<Rightarrow> bool" ("({(1_)}/ (_)) \<up>" [50, 49] 50) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
28 |
where |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
29 |
"{P} p \<up> \<equiv> (\<forall>tp. P tp \<longrightarrow> (\<forall> n . \<not> (is_final (steps0 (1, tp) p n))))" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
30 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
31 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
32 |
lemma HoareI: |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
33 |
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)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
34 |
shows "{P} p {Q}" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
35 |
unfolding Hoare_def |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
36 |
using assms by auto |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
37 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
38 |
lemma Hoare_unhalt_I: |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
39 |
assumes "\<And>l r n. P (l, r) \<Longrightarrow> \<not> is_final (steps0 (1, (l, r)) p n)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
40 |
shows "{P} p \<up>" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
41 |
unfolding Hoare_unhalt_def |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
42 |
using assms by auto |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
43 |
|
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
lemma is_final_holds[simp]: |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
assumes "is_final c" |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
46 |
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
|
47 |
using assms |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
apply(induct n) |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
apply(auto) |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
apply(case_tac [!] c) |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
apply(auto) |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
done |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
text {* |
56
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
56 |
{P1} A {Q1} {P2} B {Q2} Q1 \<mapsto> P2 A, B well-formed |
0838b0ac52ab
some small changes to turing and uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
55
diff
changeset
|
57 |
------------------------------------------------------ |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
{P1} A |+| B {Q2} |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
*} |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
lemma Hoare_plus_halt: |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
63 |
assumes a_imp: "Q1 \<mapsto> P2" |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
and A_wf : "tm_wf (A, 0)" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
and A_halt : "{P1} A {Q1}" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
and B_halt : "{P2} B {Q2}" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
shows "{P1} A |+| B {Q2}" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
proof(rule HoareI) |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
fix l r |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
assume h: "P1 (l, r)" |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
71 |
then obtain n1 l' r' |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
72 |
where "is_final (steps0 (1, l, r) A n1)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
73 |
and a1: "Q1 holds_for (steps0 (1, l, r) A n1)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
74 |
and a2: "steps0 (1, l, r) A n1 = (0, l', r')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
75 |
using A_halt unfolding Hoare_def |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
76 |
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
|
77 |
then obtain n2 |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
78 |
where "steps0 (1, l, r) (A |+| B) n2 = (Suc (length A div 2), l', r')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
79 |
using A_wf by (rule_tac tm_comp_pre_halt_same) |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
moreover |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
81 |
from a1 a2 a_imp have "P2 (l', r')" by (simp add: assert_imp_def) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
82 |
then obtain n3 l'' r'' |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
83 |
where "is_final (steps0 (1, l', r') B n3)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
84 |
and b1: "Q2 holds_for (steps0 (1, l', r') B n3)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
85 |
and b2: "steps0 (1, l', r') B n3 = (0, l'', r'')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
86 |
using B_halt unfolding Hoare_def |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
87 |
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
|
88 |
then have "steps0 (Suc (length A div 2), l', r') (A |+| B) n3 = (0, l'', r'')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
89 |
using A_wf by (rule_tac t_merge_second_halt_same) |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
ultimately show |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
"\<exists>n. is_final (steps0 (1, l, r) (A |+| B) n) \<and> Q2 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
|
92 |
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
|
93 |
qed |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
|
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
96 |
text {* |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
97 |
{P1} A {Q1} {P2} B loops Q1 \<mapsto> P2 A well-formed |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
98 |
------------------------------------------------------ |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
99 |
{P1} A |+| B loops |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
100 |
*} |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
lemma Hoare_plus_unhalt: |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
103 |
assumes a_imp: "Q1 \<mapsto> P2" |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
and A_wf : "tm_wf (A, 0)" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
and A_halt : "{P1} A {Q1}" |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
106 |
and B_uhalt : "{P2} B \<up>" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
107 |
shows "{P1} (A |+| B) \<up>" |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
proof(rule_tac Hoare_unhalt_I) |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
109 |
fix n l r |
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
assume h: "P1 (l, r)" |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
111 |
then obtain n1 l' r' |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
112 |
where a: "is_final (steps0 (1, l, r) A n1)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
113 |
and b: "Q1 holds_for (steps0 (1, l, r) A n1)" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
114 |
and c: "steps0 (1, l, r) A n1 = (0, l', r')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
115 |
using A_halt unfolding Hoare_def |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
116 |
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
|
117 |
then obtain n2 where eq: "steps0 (1, l, r) (A |+| B) n2 = (Suc (length A div 2), l', r')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
118 |
using A_wf by (rule_tac tm_comp_pre_halt_same) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
119 |
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
|
120 |
proof(cases "n2 \<le> n") |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
121 |
case True |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
122 |
from b c a_imp have "P2 (l', r')" by (simp add: assert_imp_def) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
123 |
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
|
124 |
using B_uhalt unfolding Hoare_unhalt_def by simp |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
125 |
then have "\<not> is_final (steps0 (Suc 0, l', r') B (n - n2))" by auto |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
126 |
then obtain s'' l'' r'' |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
127 |
where "steps0 (Suc 0, l', r') B (n - n2) = (s'', l'', r'')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
128 |
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
|
129 |
then have "steps0 (Suc (length A div 2), l', r') (A |+| B) (n - n2) = (s''+ length A div 2, l'', r'')" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
130 |
using A_wf by (auto dest: t_merge_second_same simp del: steps.simps) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
using `n2 \<le> n` by simp |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
135 |
next |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
136 |
case False |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
137 |
then obtain n3 where "n = n2 - n3" |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
138 |
by (metis diff_le_self le_imp_diff_is_add nat_add_commute nat_le_linear) |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
139 |
moreover |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
qed |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
qed |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
lemma Hoare_weak: |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
assumes a: "{P} p {Q}" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
and b: "P' \<mapsto> P" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
and c: "Q \<mapsto> Q'" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
shows "{P'} p {Q'}" |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
using assms |
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
unfolding Hoare_def assert_imp_def |
61
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
152 |
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
|
153 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
154 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
155 |
declare step.simps[simp del] |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
156 |
declare steps.simps[simp del] |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
157 |
declare tm_comp.simps [simp del] adjust.simps[simp del] shift.simps[simp del] |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
158 |
declare tm_wf.simps[simp del] |
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
159 |
|
7edbd5657702
updated files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
59
diff
changeset
|
160 |
|
55
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
|
cd4ef33c8fb1
added turing_hoare
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
end |