changeset 70 | 2363eb91d9fd |
parent 69 | 32ec97f94a07 |
child 71 | 8c7f10b3da7b |
69:32ec97f94a07 | 70:2363eb91d9fd |
---|---|
23 and "3 = Suc 2" |
23 and "3 = Suc 2" |
24 and "4 = Suc 3" |
24 and "4 = Suc 3" |
25 and "5 = Suc 4" |
25 and "5 = Suc 4" |
26 and "6 = Suc 5" by arith+ |
26 and "6 = Suc 5" by arith+ |
27 |
27 |
28 |
|
29 |
|
30 text {* |
28 text {* |
31 The {\em Copying} TM, which duplicates its input. |
29 The {\em Copying} TM, which duplicates its input. |
32 *} |
30 *} |
33 |
31 |
34 definition |
32 definition |
59 |
57 |
60 (* tcopy_init *) |
58 (* tcopy_init *) |
61 |
59 |
62 fun inv_init1 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
60 fun inv_init1 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
63 where |
61 where |
64 "inv_init1 x (l, r) = (l = [] \<and> r = Oc \<up> x )" |
62 "inv_init1 x (l, r) = (l = [] \<and> r = Oc \<up> x)" |
65 |
63 |
66 fun inv_init2 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
64 fun inv_init2 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
67 where |
65 where |
68 "inv_init2 x (l, r) = (\<exists> i j. i > 0 \<and> i + j = x \<and> l = Oc \<up> i \<and> r = Oc\<up>j)" |
66 "inv_init2 x (l, r) = (\<exists> i j. i > 0 \<and> i + j = x \<and> l = Oc \<up> i \<and> r = Oc \<up> j)" |
69 |
67 |
70 fun inv_init3 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
68 fun inv_init3 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
71 where |
69 where |
72 "inv_init3 x (l, r) = (x > 0 \<and> l = Bk # Oc \<up> x \<and> tl r = [])" |
70 "inv_init3 x (l, r) = (x > 0 \<and> l = Bk # Oc \<up> x \<and> tl r = [])" |
73 |
71 |
75 where |
73 where |
76 "inv_init4 x (l, r) = (x > 0 \<and> ((l = Oc \<up> x \<and> r = [Bk, Oc]) \<or> (l = Oc \<up> (x - 1) \<and> r = [Oc, Bk, Oc])))" |
74 "inv_init4 x (l, r) = (x > 0 \<and> ((l = Oc \<up> x \<and> r = [Bk, Oc]) \<or> (l = Oc \<up> (x - 1) \<and> r = [Oc, Bk, Oc])))" |
77 |
75 |
78 fun inv_init0 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
76 fun inv_init0 :: "nat \<Rightarrow> tape \<Rightarrow> bool" |
79 where |
77 where |
80 "inv_init0 x (l, r) = ((x > Suc 0 \<and> l = Oc\<up>(x - 2) \<and> r = [Oc, Oc, Bk, Oc]) \<or> |
78 "inv_init0 x (l, r) = ((x > 1 \<and> l = Oc \<up> (x - 2) \<and> r = [Oc, Oc, Bk, Oc]) \<or> |
81 (x = 1 \<and> l = [] \<and> r = [Bk, Oc, Bk, Oc]))" |
79 (x = 1 \<and> l = [] \<and> r = [Bk, Oc, Bk, Oc]))" |
82 |
80 |
83 fun inv_init :: "nat \<Rightarrow> config \<Rightarrow> bool" |
81 fun inv_init :: "nat \<Rightarrow> config \<Rightarrow> bool" |
84 where |
82 where |
85 "inv_init x (s, l, r) = ( |
83 "inv_init x (s, l, r) = |
86 if s = 0 then inv_init0 x (l, r) |
84 (if s = 0 then inv_init0 x (l, r) |
87 else if s = Suc 0 then inv_init1 x (l, r) |
85 else if s = 1 then inv_init1 x (l, r) |
88 else if s = 2 then inv_init2 x (l, r) |
86 else if s = 2 then inv_init2 x (l, r) |
89 else if s = 3 then inv_init3 x (l, r) |
87 else if s = 3 then inv_init3 x (l, r) |
90 else if s = 4 then inv_init4 x (l, r) |
88 else if s = 4 then inv_init4 x (l, r) |
91 else False)" |
89 else False)" |
92 |
90 |
1075 |
1073 |
1076 definition dither :: "instr list" |
1074 definition dither :: "instr list" |
1077 where |
1075 where |
1078 "dither \<equiv> [(W0, 1), (R, 2), (L, 1), (L, 0)] " |
1076 "dither \<equiv> [(W0, 1), (R, 2), (L, 1), (L, 0)] " |
1079 |
1077 |
1078 (* invariants of dither *) |
|
1079 abbreviation |
|
1080 "dither_halt_inv \<equiv> \<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc, Oc]" |
|
1081 |
|
1082 abbreviation |
|
1083 "dither_unhalt_inv \<equiv> \<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc]" |
|
1084 |
|
1080 lemma dither_unhalt_state: |
1085 lemma dither_unhalt_state: |
1081 "(steps0 (1, Bk \<up> m, [Oc]) dither stp = (1, Bk \<up> m, [Oc])) \<or> |
1086 "(steps0 (1, Bk \<up> m, [Oc]) dither stp = (1, Bk \<up> m, [Oc])) \<or> |
1082 (steps0 (1, Bk \<up> m, [Oc]) dither stp = (2, Oc # Bk \<up> m, []))" |
1087 (steps0 (1, Bk \<up> m, [Oc]) dither stp = (2, Oc # Bk \<up> m, []))" |
1083 apply(induct stp) |
1088 apply(induct stp) |
1084 apply(simp add: steps.simps) |
1089 apply(simp add: steps.simps) |
1090 shows "\<not> is_final (steps0 (1, Bk \<up> m, [Oc]) dither stp)" |
1095 shows "\<not> is_final (steps0 (1, Bk \<up> m, [Oc]) dither stp)" |
1091 using dither_unhalt_state[of m stp] |
1096 using dither_unhalt_state[of m stp] |
1092 by auto |
1097 by auto |
1093 |
1098 |
1094 lemma dither_loops: |
1099 lemma dither_loops: |
1095 shows "{(\<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc])} dither \<up>" |
1100 shows "{dither_unhalt_inv} dither \<up>" |
1096 apply(rule Hoare_unhaltI) |
1101 apply(rule Hoare_unhaltI) |
1097 using dither_unhalt_rs |
1102 using dither_unhalt_rs |
1098 apply(auto) |
1103 apply(auto) |
1099 done |
1104 done |
1100 |
1105 |
1101 lemma dither_halt_rs: |
1106 lemma dither_halt_rs: |
1102 "\<exists>stp. steps0 (Suc 0, Bk \<up> m, [Oc, Oc]) dither stp = (0, Bk \<up> m, [Oc, Oc])" |
1107 "\<exists>stp. steps0 (1, Bk \<up> m, [Oc, Oc]) dither stp = (0, Bk \<up> m, [Oc, Oc])" |
1103 unfolding dither_def |
1108 unfolding dither_def |
1104 apply(rule_tac x = "3" in exI) |
1109 apply(rule_tac x = "3" in exI) |
1105 apply(simp add: steps.simps step.simps fetch.simps numeral) |
1110 apply(simp add: steps.simps step.simps fetch.simps numeral) |
1106 done |
1111 done |
1107 |
1112 |
1108 definition |
|
1109 "dither_halt_inv \<equiv> (\<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc, Oc])" |
|
1110 |
1113 |
1111 lemma dither_halts: |
1114 lemma dither_halts: |
1112 shows "{dither_halt_inv} dither {dither_halt_inv}" |
1115 shows "{dither_halt_inv} dither {dither_halt_inv}" |
1113 unfolding dither_halt_inv_def |
|
1114 apply(rule HoareI) |
1116 apply(rule HoareI) |
1115 using dither_halt_rs |
1117 using dither_halt_rs |
1116 apply(auto) |
1118 apply(auto) |
1117 by (metis (lifting, mono_tags) holds_for.simps is_final_eq prod.cases) |
1119 by (metis (lifting, mono_tags) holds_for.simps is_final_eq prod.cases) |
1118 |
1120 |
1216 fixes code :: "instr list \<Rightarrow> nat" |
1218 fixes code :: "instr list \<Rightarrow> nat" |
1217 -- {* |
1219 -- {* |
1218 The TM @{text "H"} is the one which is assummed being able to solve the Halting problem. |
1220 The TM @{text "H"} is the one which is assummed being able to solve the Halting problem. |
1219 *} |
1221 *} |
1220 and H :: "instr list" |
1222 and H :: "instr list" |
1221 assumes h_wf[intro]: "tm_wf (H, 0)" |
1223 assumes h_wf[intro]: "tm_wf0 H" |
1222 -- {* |
1224 -- {* |
1223 The following two assumptions specifies that @{text "H"} does solve the Halting problem. |
1225 The following two assumptions specifies that @{text "H"} does solve the Halting problem. |
1224 *} |
1226 *} |
1225 and h_case: |
1227 and h_case: |
1226 "\<And> M n. \<lbrakk>(haltP (M, 0) lm)\<rbrakk> \<Longrightarrow> |
1228 "\<And> M lm. (haltP0 M lm) \<Longrightarrow> \<exists> na nb. (steps0 (1, [], <code M # lm>) H na = (0, Bk \<up> nb, [Oc]))" |
1227 \<exists> na nb. (steps (Suc 0, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc]))" |
|
1228 and nh_case: |
1229 and nh_case: |
1229 "\<And> M n. \<lbrakk>(\<not> haltP (M, 0) lm)\<rbrakk> \<Longrightarrow> |
1230 "\<And> M lm. (\<not> haltP0 M lm) \<Longrightarrow> |
1230 \<exists> na nb. (steps (Suc 0, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1231 \<exists> na nb. (steps0 (1, [], <code M # lm>) H na = (0, Bk \<up> nb, [Oc, Oc]))" |
1231 begin |
1232 begin |
1232 |
1233 |
1233 lemma h_newcase: |
1234 lemma h_newcase: |
1234 "\<And> M n. haltP (M, 0) lm \<Longrightarrow> |
1235 "\<And> M lm. haltP0 M lm \<Longrightarrow> \<exists> na nb. (steps0 (1, Bk \<up> x , <code M # lm>) H na = (0, Bk \<up> nb, [Oc]))" |
1235 \<exists> na nb. (steps (Suc 0, Bk\<up>x , <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc]))" |
|
1236 proof - |
1236 proof - |
1237 fix M n |
1237 fix M lm |
1238 assume "haltP (M, 0) lm" |
1238 assume "haltP (M, 0) lm" |
1239 hence "\<exists> na nb. (steps (Suc 0, [], <code M # lm>) (H, 0) na |
1239 hence "\<exists> na nb. (steps (1, [], <code M # lm>) (H, 0) na |
1240 = (0, Bk\<up>nb, [Oc]))" |
1240 = (0, Bk\<up>nb, [Oc]))" |
1241 apply(erule_tac h_case) |
1241 by (rule h_case) |
1242 done |
|
1243 from this obtain na nb where |
1242 from this obtain na nb where |
1244 cond1:"(steps (Suc 0, [], <code M # lm>) (H, 0) na |
1243 cond1:"(steps (1, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc]))" by blast |
1245 = (0, Bk\<up>nb, [Oc]))" by blast |
1244 thus "\<exists> na nb. (steps (1, Bk\<up>x, <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc]))" |
1246 thus "\<exists> na nb. (steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc]))" |
1245 proof(rule_tac x = na in exI, case_tac "steps (1, Bk\<up>x, <code M # lm>) (H, 0) na", simp) |
1247 proof(rule_tac x = na in exI, case_tac "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na", simp) |
|
1248 fix a b c |
1246 fix a b c |
1249 assume cond2: "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1247 assume cond2: "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1250 have "tinres (Bk\<up>nb) b \<and> [Oc] = c \<and> 0 = a" |
1248 have "tinres (Bk\<up>nb) b \<and> [Oc] = c \<and> 0 = a" |
1251 proof(rule_tac tinres_steps) |
1249 proof(rule_tac tinres_steps) |
1252 show "tinres [] (Bk\<up>x)" |
1250 show "tinres [] (Bk\<up>x)" |
1253 apply(simp add: tinres_def) |
1251 apply(simp add: tinres_def) |
1254 apply(auto) |
1252 apply(auto) |
1255 done |
1253 done |
1256 next |
1254 next |
1257 show "(steps (Suc 0, [], <code M # lm>) (H, 0) na |
1255 show "(steps (1, [], <code M # lm>) (H, 0) na |
1258 = (0, Bk\<up>nb, [Oc]))" |
1256 = (0, Bk\<up>nb, [Oc]))" |
1259 by(simp add: cond1) |
1257 by(simp add: cond1[simplified]) |
1260 next |
1258 next |
1261 show "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1259 show "steps (1, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1262 by(simp add: cond2) |
1260 by(simp add: cond2[simplified]) |
1263 qed |
1261 qed |
1264 thus "a = 0 \<and> (\<exists>nb. b = (Bk\<up>nb)) \<and> c = [Oc]" |
1262 thus "a = 0 \<and> (\<exists>nb. b = (Bk\<up>nb)) \<and> c = [Oc]" |
1265 by(auto elim: tinres_ex1) |
1263 by(auto elim: tinres_ex1) |
1266 qed |
1264 qed |
1267 qed |
1265 qed |
1268 |
1266 |
1269 lemma nh_newcase: "\<And> M n. \<lbrakk>\<not> (haltP (M, 0) lm)\<rbrakk> \<Longrightarrow> |
1267 lemma nh_newcase: |
1270 \<exists> na nb. (steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1268 "\<And> M lm. \<not> (haltP (M, 0) lm) \<Longrightarrow> \<exists> na nb. (steps0 (1, Bk\<up>x, <code M # lm>) H na = (0, Bk\<up>nb, [Oc, Oc]))" |
1271 proof - |
1269 proof - |
1272 fix M n |
1270 fix M lm |
1273 assume "\<not> haltP (M, 0) lm" |
1271 assume "\<not> haltP (M, 0) lm" |
1274 hence "\<exists> na nb. (steps (Suc 0, [], <code M # lm>) (H, 0) na |
1272 hence "\<exists> na nb. (steps (1, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1275 = (0, Bk\<up>nb, [Oc, Oc]))" |
1273 by (rule nh_case) |
1276 apply(erule_tac nh_case) |
|
1277 done |
|
1278 from this obtain na nb where |
1274 from this obtain na nb where |
1279 cond1: "(steps (Suc 0, [], <code M # lm>) (H, 0) na |
1275 cond1: "(steps (1, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" by blast |
1280 = (0, Bk\<up>nb, [Oc, Oc]))" by blast |
1276 thus "\<exists> na nb. (steps (1, Bk\<up>x, <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1281 thus "\<exists> na nb. (steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1277 proof(rule_tac x = na in exI, case_tac "steps (1, Bk\<up>x, <code M # lm>) (H, 0) na", simp) |
1282 proof(rule_tac x = na in exI, case_tac "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na", simp) |
|
1283 fix a b c |
1278 fix a b c |
1284 assume cond2: "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1279 assume cond2: "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1285 have "tinres (Bk\<up>nb) b \<and> [Oc, Oc] = c \<and> 0 = a" |
1280 have "tinres (Bk\<up>nb) b \<and> [Oc, Oc] = c \<and> 0 = a" |
1286 proof(rule_tac tinres_steps) |
1281 proof(rule_tac tinres_steps) |
1287 show "tinres [] (Bk\<up>x)" |
1282 show "tinres [] (Bk\<up>x)" |
1288 apply(auto simp: tinres_def) |
1283 apply(auto simp: tinres_def) |
1289 done |
1284 done |
1290 next |
1285 next |
1291 show "(steps (Suc 0, [], <code M # lm>) (H, 0) na |
1286 show "(steps (Suc 0, [], <code M # lm>) (H, 0) na = (0, Bk\<up>nb, [Oc, Oc]))" |
1292 = (0, Bk\<up>nb, [Oc, Oc]))" |
1287 by(simp add: cond1[simplified]) |
1293 by(simp add: cond1) |
|
1294 next |
1288 next |
1295 show "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1289 show "steps (Suc 0, Bk\<up>x, <code M # lm>) (H, 0) na = (a, b, c)" |
1296 by(simp add: cond2) |
1290 by(simp add: cond2[simplified]) |
1297 qed |
1291 qed |
1298 thus "a = 0 \<and> (\<exists>nb. b = Bk\<up>nb) \<and> c = [Oc, Oc]" |
1292 thus "a = 0 \<and> (\<exists>nb. b = Bk\<up>nb) \<and> c = [Oc, Oc]" |
1299 by(auto elim: tinres_ex1) |
1293 by(auto elim: tinres_ex1) |
1300 qed |
1294 qed |
1301 qed |
1295 qed |
1296 |
|
1297 |
|
1298 (* invariants for H *) |
|
1299 abbreviation |
|
1300 "pre_H_inv M n \<equiv> \<lambda>(l::cell list, r::cell list). (l = [Bk] \<and> r = <[code M, n]>)" |
|
1301 |
|
1302 abbreviation |
|
1303 "post_H_halt_inv \<equiv> \<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc, Oc]" |
|
1304 |
|
1305 abbreviation |
|
1306 "post_H_unhalt_inv \<equiv> \<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc]" |
|
1307 |
|
1308 |
|
1309 lemma H_halt_inv: |
|
1310 assumes "\<not> haltP0 M [n]" |
|
1311 shows "{pre_H_inv M n} H {post_H_halt_inv}" |
|
1312 proof - |
|
1313 obtain stp i |
|
1314 where "steps0 (1, Bk \<up> 1, <[code M, n]>) H stp = (0, Bk \<up> i, [Oc, Oc])" |
|
1315 using nh_newcase[of "M" "[n]" "1", OF assms] by auto |
|
1316 then show "{pre_H_inv M n} H {post_H_halt_inv}" |
|
1317 unfolding Hoare_def |
|
1318 apply(auto) |
|
1319 apply(rule_tac x = stp in exI) |
|
1320 apply(auto) |
|
1321 done |
|
1322 qed |
|
1323 |
|
1324 lemma H_unhalt_inv: |
|
1325 assumes "haltP0 M [n]" |
|
1326 shows "{pre_H_inv M n} H {post_H_unhalt_inv}" |
|
1327 proof - |
|
1328 obtain stp i |
|
1329 where "steps0 (1, Bk \<up> 1, <[code M, n]>) H stp = (0, Bk \<up> i, [Oc])" |
|
1330 using h_newcase[of "M" "[n]" "1", OF assms] by auto |
|
1331 then show "{pre_H_inv M n} H {post_H_unhalt_inv}" |
|
1332 unfolding Hoare_def |
|
1333 apply(auto) |
|
1334 apply(rule_tac x = stp in exI) |
|
1335 apply(auto) |
|
1336 done |
|
1337 qed |
|
1338 |
|
1302 |
1339 |
1303 (* TM that produces the contradiction and its code *) |
1340 (* TM that produces the contradiction and its code *) |
1304 abbreviation |
1341 abbreviation |
1305 "tcontra \<equiv> (tcopy |+| H) |+| dither" |
1342 "tcontra \<equiv> (tcopy |+| H) |+| dither" |
1306 abbreviation |
1343 abbreviation |
1312 shows "False" |
1349 shows "False" |
1313 proof - |
1350 proof - |
1314 (* invariants *) |
1351 (* invariants *) |
1315 def P1 \<equiv> "\<lambda>(l::cell list, r::cell list). (l = [] \<and> r = <[code_tcontra]>)" |
1352 def P1 \<equiv> "\<lambda>(l::cell list, r::cell list). (l = [] \<and> r = <[code_tcontra]>)" |
1316 def P2 \<equiv> "\<lambda>(l::cell list, r::cell list). (l = [Bk] \<and> r = <[code_tcontra, code_tcontra]>)" |
1353 def P2 \<equiv> "\<lambda>(l::cell list, r::cell list). (l = [Bk] \<and> r = <[code_tcontra, code_tcontra]>)" |
1317 def P3 \<equiv> dither_halt_inv |
1354 def P3 \<equiv> "\<lambda>(l, r). (\<exists>nd. l = Bk \<up> nd) \<and> r = [Oc, Oc]" |
1318 |
1355 |
1319 (* |
1356 (* |
1320 {P1} tcopy {P2} {P2} H {P3} |
1357 {P1} tcopy {P2} {P2} H {P3} |
1321 ---------------------------- |
1358 ---------------------------- |
1322 {P1} (tcopy |+| H) {P3} {P3} dither {P3} |
1359 {P1} (tcopy |+| H) {P3} {P3} dither {P3} |
1331 proof (cases rule: Hoare_plus_halt_simple) |
1368 proof (cases rule: Hoare_plus_halt_simple) |
1332 case A_halt (* of tcopy *) |
1369 case A_halt (* of tcopy *) |
1333 show "{P1} tcopy {P2}" unfolding P1_def P2_def |
1370 show "{P1} tcopy {P2}" unfolding P1_def P2_def |
1334 by (rule tcopy_correct2) |
1371 by (rule tcopy_correct2) |
1335 next |
1372 next |
1336 case B_halt |
1373 case B_halt (* of H *) |
1337 obtain n i |
1374 show "{P2} H {P3}" |
1338 where "steps0 (1, Bk \<up> 1, <[code_tcontra, code_tcontra]>) H n = (0, Bk \<up> i, [Oc, Oc])" |
1375 unfolding P2_def P3_def |
1339 using nh_newcase[of "tcontra" "[code_tcontra]" 1, OF assms] |
1376 using assms by (rule H_halt_inv) |
1340 by (auto) |
|
1341 then show "{P2} H {P3}" |
|
1342 unfolding P2_def P3_def dither_halt_inv_def |
|
1343 unfolding Hoare_def |
|
1344 apply(auto) |
|
1345 apply(rule_tac x = n in exI) |
|
1346 apply(simp) |
|
1347 done |
|
1348 qed (simp) |
1377 qed (simp) |
1349 |
1378 |
1350 (* {P3} dither {P3} *) |
1379 (* {P3} dither {P3} *) |
1351 have second: "{P3} dither {P3}" unfolding P3_def |
1380 have second: "{P3} dither {P3}" unfolding P3_def |
1352 by (rule dither_halts) |
1381 by (rule dither_halts) |
1354 (* {P1} tcontra {P3} *) |
1383 (* {P1} tcontra {P3} *) |
1355 have "{P1} tcontra {P3}" |
1384 have "{P1} tcontra {P3}" |
1356 by (rule Hoare_plus_halt_simple[OF first second H_wf]) |
1385 by (rule Hoare_plus_halt_simple[OF first second H_wf]) |
1357 |
1386 |
1358 with assms show "False" |
1387 with assms show "False" |
1359 unfolding P1_def P3_def dither_halt_inv_def |
1388 unfolding P1_def P3_def |
1360 unfolding haltP_def |
1389 unfolding haltP_def |
1361 unfolding Hoare_def |
1390 unfolding Hoare_def |
1362 apply(auto) |
1391 apply(auto) |
1363 apply(erule_tac x = n in allE) |
1392 apply(erule_tac x = n in allE) |
1364 apply(case_tac "steps0 (Suc 0, [], <[code tcontra]>) tcontra n") |
1393 apply(case_tac "steps0 (Suc 0, [], <[code tcontra]>) tcontra n") |
1365 apply(simp, auto) |
1394 apply(simp, auto) |
1366 apply(erule_tac x = 2 in allE, erule_tac x = 0 in allE) |
1395 apply(erule_tac x = 2 in allE, erule_tac x = 0 in allE) |
1367 apply(simp) |
1396 apply(simp add: numeral) |
1368 by (smt replicate_0 replicate_Suc) |
1397 done |
1369 qed |
1398 qed |
1370 |
1399 |
1371 (* asumme tcontra halts on its code *) |
1400 (* asumme tcontra halts on its code *) |
1372 lemma tcontra_halt: |
1401 lemma tcontra_halt: |
1373 assumes "haltP0 tcontra [code tcontra]" |
1402 assumes "haltP0 tcontra [code tcontra]" |
1393 proof (cases rule: Hoare_plus_halt_simple) |
1422 proof (cases rule: Hoare_plus_halt_simple) |
1394 case A_halt (* of tcopy *) |
1423 case A_halt (* of tcopy *) |
1395 show "{P1} tcopy {P2}" unfolding P1_def P2_def |
1424 show "{P1} tcopy {P2}" unfolding P1_def P2_def |
1396 by (rule tcopy_correct2) |
1425 by (rule tcopy_correct2) |
1397 next |
1426 next |
1398 case B_halt |
1427 case B_halt (* of H *) |
1399 obtain n i |
|
1400 where "steps0 (1, Bk \<up> 1, <[code_tcontra, code_tcontra]>) H n = (0, Bk \<up> i, [Oc])" |
|
1401 using h_newcase[of "tcontra" "[code_tcontra]" 1, OF assms] |
|
1402 by (auto) |
|
1403 then show "{P2} H {P3}" |
1428 then show "{P2} H {P3}" |
1404 unfolding P2_def P3_def |
1429 unfolding P2_def P3_def |
1405 unfolding Hoare_def |
1430 using assms by (rule H_unhalt_inv) |
1406 apply(auto) |
|
1407 apply(rule_tac x = n in exI) |
|
1408 apply(simp) |
|
1409 done |
|
1410 qed (simp) |
1431 qed (simp) |
1411 |
1432 |
1412 (* {P3} dither loops *) |
1433 (* {P3} dither loops *) |
1413 have second: "{P3} dither \<up>" unfolding P3_def |
1434 have second: "{P3} dither \<up>" unfolding P3_def |
1414 by (rule dither_loops) |
1435 by (rule dither_loops) |
1416 (* {P1} tcontra loops *) |
1437 (* {P1} tcontra loops *) |
1417 have "{P1} tcontra \<up>" |
1438 have "{P1} tcontra \<up>" |
1418 by (rule Hoare_plus_unhalt_simple[OF first second H_wf]) |
1439 by (rule Hoare_plus_unhalt_simple[OF first second H_wf]) |
1419 |
1440 |
1420 with assms show "False" |
1441 with assms show "False" |
1442 unfolding P1_def |
|
1421 unfolding haltP_def |
1443 unfolding haltP_def |
1422 unfolding P1_def |
|
1423 unfolding Hoare_unhalt_def |
1444 unfolding Hoare_unhalt_def |
1424 by (auto, metis is_final_eq) |
1445 by (auto, metis is_final_eq) |
1425 qed |
1446 qed |
1426 |
1447 |
1427 text {* |
1448 text {* |