diff -r eb589fa73fc1 -r 2e9881578cb2 thys/uncomputable.thy --- a/thys/uncomputable.thy Fri Jan 25 15:57:58 2013 +0100 +++ b/thys/uncomputable.thy Fri Jan 25 21:15:09 2013 +0000 @@ -64,24 +64,23 @@ inv_init3 :: "nat \ tape \ bool" and inv_init4 :: "nat \ tape \ bool" where - "inv_init0 x (l, r) = ((x > 1 \ l = Oc \ (x - 2) \ r = [Oc, Oc, Bk, Oc]) \ - (x = 1 \ l = [] \ r = [Bk, Oc, Bk, Oc]))" -| "inv_init1 x (l, r) = (l = [] \ r = Oc \ x)" -| "inv_init2 x (l, r) = (\ i j. i > 0 \ i + j = x \ l = Oc \ i \ r = Oc \ j)" -| "inv_init3 x (l, r) = (x > 0 \ l = Bk # Oc \ x \ tl r = [])" -| "inv_init4 x (l, r) = (x > 0 \ ((l = Oc \ x \ r = [Bk, Oc]) \ (l = Oc \ (x - 1) \ r = [Oc, Bk, Oc])))" + "inv_init0 n (l, r) = ((n > 1 \ (l, r) = (Oc \ (n - 2), [Oc, Oc, Bk, Oc])) \ + (n = 1 \ (l, r) = ([], [Bk, Oc, Bk, Oc])))" +| "inv_init1 n (l, r) = ((l, r) = ([], Oc \ n))" +| "inv_init2 n (l, r) = (\ i j. i > 0 \ i + j = n \ (l, r) = (Oc \ i, Oc \ j))" +| "inv_init3 n (l, r) = (n > 0 \ (l, tl r) = (Bk # Oc \ n, []))" +| "inv_init4 n (l, r) = (n > 0 \ ((l, r) = (Oc \ n, [Bk, Oc]) \ (l, r) = (Oc \ (n - 1), [Oc, Bk, Oc])))" fun inv_init :: "nat \ config \ bool" where - "inv_init x (s, l, r) = - (if s = 0 then inv_init0 x (l, r) - else if s = 1 then inv_init1 x (l, r) - else if s = 2 then inv_init2 x (l, r) - else if s = 3 then inv_init3 x (l, r) - else if s = 4 then inv_init4 x (l, r) + "inv_init n (s, l, r) = + (if s = 0 then inv_init0 n (l, r) else + if s = 1 then inv_init1 n (l, r) else + if s = 2 then inv_init2 n (l, r) else + if s = 3 then inv_init3 n (l, r) else + if s = 4 then inv_init4 n (l, r) else False)" -declare inv_init.simps[simp del] lemma [elim]: "\0 < i; 0 < j\ \ @@ -109,20 +108,19 @@ fun init_state :: "config \ nat" where - "init_state (s, l, r) = (if s = 0 then 0 - else 5 - s)" + "init_state (s, l, r) = (if s = 0 then 0 else 5 - s)" fun init_step :: "config \ nat" where - "init_step (s, l, r) = (if s = 2 then length r - else if s = 3 then if r = [] \ r = [Bk] then Suc 0 else 0 - else if s = 4 then length l - else 0)" + "init_step (s, l, r) = + (if s = 2 then length r else + if s = 3 then (if r = [] \ r = [Bk] then 1 else 0) else + if s = 4 then length l + else 0)" fun init_measure :: "config \ nat \ nat" where - "init_measure c = - (init_state c, init_step c)" + "init_measure c = (init_state c, init_step c)" definition lex_pair :: "((nat \ nat) \ nat \ nat) set" @@ -131,11 +129,11 @@ definition init_LE :: "(config \ config) set" where - "init_LE \ (inv_image lex_pair init_measure)" + "init_LE \ (inv_image lex_pair init_measure)" lemma [simp]: "\tl r = []; r \ []; r \ [Bk]\ \ r = [Oc]" -apply(case_tac r, auto, case_tac a, auto) -done +by (case_tac r, auto, case_tac a, auto) + lemma wf_init_le: "wf init_LE" by(auto intro:wf_inv_image simp:init_LE_def lex_pair_def) @@ -164,11 +162,10 @@ ultimately show "(steps (Suc 0, [], Oc \ x) (tcopy_init, 0) (Suc n), steps (Suc 0, [], Oc \ x) (tcopy_init, 0) n) \ init_LE" using a - proof(simp) + proof(simp del: inv_init.simps) assume "inv_init x (s, l, r)" "0 < s" thus "(step (s, l, r) (tcopy_init, 0), s, l, r) \ init_LE" - apply(auto simp: inv_init.simps init_LE_def lex_pair_def step.simps tcopy_init_def numeral - split: if_splits) + apply(auto simp: init_LE_def lex_pair_def step.simps tcopy_init_def numeral split: if_splits) apply(case_tac r, auto, case_tac a, auto) done qed @@ -199,48 +196,31 @@ (* tcopy_loop *) -fun inv_loop1_loop :: "nat \ tape \ bool" - where - "inv_loop1_loop x (l, r) = - (\ i j. i + j + 1 = x \ l = Oc\i \ r = Oc # Oc # Bk\j @ Oc\j \ j > 0)" - -fun inv_loop1_exit :: "nat \ tape \ bool" - where - "inv_loop1_exit x (l, r) = - (l = [] \ r = Bk # Oc # Bk\x @ Oc\x \ x > 0 )" - -fun inv_loop1 :: "nat \ tape \ bool" - where - "inv_loop1 x (l, r) = (inv_loop1_loop x (l, r) \ inv_loop1_exit x (l, r))" - -fun inv_loop2 :: "nat \ tape \ bool" - where - "inv_loop2 x (l, r) = - (\ i j any. i + j = x \ x > 0 \ i > 0 \ j > 0 \ l = Oc\i \ r = any#Bk\j@Oc\j)" - -fun inv_loop3 :: "nat \ tape \ bool" - where - "inv_loop3 x (l, r) = - (\ i j k t. i + j = x \ i > 0 \ j > 0 \ k + t = Suc j \ l = Bk\k@Oc\i \ r = Bk\t@Oc\j)" - -fun inv_loop4 :: "nat \ tape \ bool" - where - "inv_loop4 x (l, r) = - (\ i j k t. i + j = x \ i > 0 \ j > 0 \ k + t = j \ l = Oc\k @ Bk\(Suc j)@Oc\i \ r = Oc\t)" - -fun inv_loop5_loop :: "nat \ tape \ bool" +fun + inv_loop0 :: "nat \ tape \ bool" and + inv_loop1_loop :: "nat \ tape \ bool" and + inv_loop1_exit :: "nat \ tape \ bool" and + inv_loop1 :: "nat \ tape \ bool" and + inv_loop2 :: "nat \ tape \ bool" and + inv_loop3 :: "nat \ tape \ bool" and + inv_loop4 :: "nat \ tape \ bool" and + inv_loop5_loop :: "nat \ tape \ bool" and + inv_loop5_exit :: "nat \ tape \ bool" and + inv_loop5 :: "nat \ tape \ bool" where - "inv_loop5_loop x (l, r) = - (\ i j k t. i + j = Suc x \ i > 0 \ j > 0 \ k + t = j \ t > 0 \ l = Oc\k@Bk\j@Oc\i \ r = Oc\t)" - -fun inv_loop5_exit :: "nat \ tape \ bool" - where - "inv_loop5_exit x (l, r) = (\ i j. i + j = Suc x \ i > 0 \ j > 0 \ l = Bk\(j - 1)@Oc\i \ r = Bk # Oc\j)" - -fun inv_loop5 :: "nat \ tape \ bool" - where - "inv_loop5 x (l, r) = (inv_loop5_loop x (l, r) \ - inv_loop5_exit x (l, r))" + "inv_loop0 x (l, r) = (l = [Bk] \ r = Oc # Bk\x @ Oc\x \ x > 0 )" +| "inv_loop1_loop x (l, r) = (\ i j. i + j + 1 = x \ l = Oc\i \ r = Oc # Oc # Bk\j @ Oc\j \ j > 0)" +| "inv_loop1_exit x (l, r) = (l = [] \ r = Bk # Oc # Bk\x @ Oc\x \ x > 0)" +| "inv_loop1 x (l, r) = (inv_loop1_loop x (l, r) \ inv_loop1_exit x (l, r))" +| "inv_loop2 x (l, r) = (\ i j any. i + j = x \ x > 0 \ i > 0 \ j > 0 \ l = Oc\i \ r = any#Bk\j@Oc\j)" +| "inv_loop3 x (l, r) = + (\ i j k t. i + j = x \ i > 0 \ j > 0 \ k + t = Suc j \ l = Bk\k@Oc\i \ r = Bk\t@Oc\j)" +| "inv_loop4 x (l, r) = + (\ i j k t. i + j = x \ i > 0 \ j > 0 \ k + t = j \ l = Oc\k @ Bk\(Suc j)@Oc\i \ r = Oc\t)" +| "inv_loop5_loop x (l, r) = + (\ i j k t. i + j = Suc x \ i > 0 \ j > 0 \ k + t = j \ t > 0 \ l = Oc\k@Bk\j@Oc\i \ r = Oc\t)" +| "inv_loop5_exit x (l, r) = (\ i j. i + j = Suc x \ i > 0 \ j > 0 \ l = Bk\(j - 1)@Oc\i \ r = Bk # Oc\j)" +| "inv_loop5 x (l, r) = (inv_loop5_loop x (l, r) \ inv_loop5_exit x (l, r))" fun inv_loop6_loop :: "nat \ tape \ bool" where @@ -256,11 +236,6 @@ where "inv_loop6 x (l, r) = (inv_loop6_loop x (l, r) \ inv_loop6_exit x (l, r))" -fun inv_loop0 :: "nat \ tape \ bool" - where - "inv_loop0 x (l, r) = - (l = [Bk] \ r = Oc # Bk\x @ Oc\x \ x > 0 )" - fun inv_loop :: "nat \ config \ bool" where "inv_loop x (s, l, r) = @@ -277,21 +252,20 @@ inv_loop2.simps[simp del] inv_loop3.simps[simp del] inv_loop4.simps[simp del] inv_loop5.simps[simp del] inv_loop6.simps[simp del] + lemma [elim]: "Bk # list = Oc \ t \ RR" -apply(case_tac t, auto) -done - +by (case_tac t, auto) lemma [simp]: "inv_loop1 x (b, []) = False" by(simp add: inv_loop1.simps) lemma [elim]: "\0 < x; inv_loop2 x (b, [])\ \ inv_loop3 x (Bk # b, [])" -apply(auto simp: inv_loop2.simps inv_loop3.simps) -done +by (auto simp: inv_loop2.simps inv_loop3.simps) + lemma [elim]: "\0 < x; inv_loop3 x (b, [])\ \ inv_loop3 x (Bk # b, [])" -apply(auto simp: inv_loop3.simps) -done +by (auto simp: inv_loop3.simps) + lemma [elim]: "\0 < x; inv_loop4 x (b, [])\ \ inv_loop5 x (b, [Oc])" apply(auto simp: inv_loop4.simps inv_loop5.simps) @@ -1070,10 +1044,10 @@ (* invariants of dither *) abbreviation - "dither_halt_inv \ \(l, r). (\n. l = Bk \ n) \ r = [Oc, Oc]" + "dither_halt_inv \ \(l, r). (\n. (l, r) = (Bk \ n, [Oc, Oc]))" abbreviation - "dither_unhalt_inv \ \(l, r). (\n. l = Bk \ n) \ r = [Oc]" + "dither_unhalt_inv \ \(l, r). (\n. (l, r) = (Bk \ n, [Oc]))" lemma dither_loops_aux: "(steps0 (1, Bk \ m, [Oc]) dither stp = (1, Bk \ m, [Oc])) \ @@ -1330,9 +1304,9 @@ shows "False" proof - (* invariants *) - def P1 \ "\(l::cell list, r::cell list). (l = [] \ r = <[code_tcontra]>)" - def P2 \ "\(l::cell list, r::cell list). (l = [Bk] \ r = <[code_tcontra, code_tcontra]>)" - def P3 \ "\(l, r). (\nd. l = Bk \ nd) \ r = [Oc, Oc]" + def P1 \ "\(l::cell list, r::cell list). (l, r) = ([], <[code_tcontra]>)" + def P2 \ "\(l::cell list, r::cell list). (l, r) = ([Bk], <[code_tcontra, code_tcontra]>)" + def P3 \ "\(l, r). (\n. (l, r) = (Bk \ n, [Oc, Oc]))" (* {P1} tcopy {P2} {P2} H {P3} @@ -1349,12 +1323,12 @@ proof (cases rule: Hoare_plus_halt_simple) case A_halt (* of tcopy *) show "{P1} tcopy {P2}" unfolding P1_def P2_def - by (rule tcopy_correct2) + by (simp) (rule tcopy_correct2) next case B_halt (* of H *) show "{P2} H {P3}" unfolding P2_def P3_def - using assms by (rule H_halt_inv) + using assms by (simp) (rule H_halt_inv) qed (simp) (* {P3} dither {P3} *) @@ -1384,9 +1358,9 @@ shows "False" proof - (* invariants *) - def P1 \ "\(l::cell list, r::cell list). (l = [] \ r = <[code_tcontra]>)" - def P2 \ "\(l::cell list, r::cell list). (l = [Bk] \ r = <[code_tcontra, code_tcontra]>)" - def P3 \ "\(l::cell list, r::cell list). (\nd. l = Bk \ nd) \ r = [Oc]" + def P1 \ "\(l::cell list, r::cell list). (l, r) = ([], <[code_tcontra]>)" + def P2 \ "\(l::cell list, r::cell list). (l, r) = ([Bk], <[code_tcontra, code_tcontra]>)" + def P3 \ "\(l::cell list, r::cell list). (\n. (l, r) = (Bk \ n, [Oc]))" (* {P1} tcopy {P2} {P2} H {P3} @@ -1403,12 +1377,12 @@ proof (cases rule: Hoare_plus_halt_simple) case A_halt (* of tcopy *) show "{P1} tcopy {P2}" unfolding P1_def P2_def - by (rule tcopy_correct2) + by (simp) (rule tcopy_correct2) next case B_halt (* of H *) then show "{P2} H {P3}" unfolding P2_def P3_def - using assms by (rule H_unhalt_inv) + using assms by (simp) (rule H_unhalt_inv) qed (simp) (* {P3} dither loops *)