text‹
a Turing machine $M_1$ computing $f_1$ in time $T_1$ and a TM $M_2$
$f_2$ in time $T_2$ there is a TM $M$ computing $f_2 \circ f_1$ in
$O(T_1(n) + \max_{m \le T_1(n)} T_2(m))$. If $T_1$ is monotone
time bound is $O(T_1 + T_2 \circ T_1)$; if $T_1$ and $T_2$ are
bounded the running-time of $M$ is polynomially bounded, too.
Turing machines $M_1$ and $M_2$ can have both a different alphabet and
of tapes, so generally they cannot be composed by the $;;$ operator. To
around this we enlarge the alphabet and prepend and append tapes, so $M$ has
many tapes as $M_1$ and $M_2$ combined. The following function returns the
Turing machine $M$.
lemma G1: "G1 ≤ G"and G2: "G2 ≤ G" using G_def by simp_all
lemma k_ge: "k1 ≥ 2""k2 ≥ 2" using tm_M1 tm_M2 turing_machine_def by simp_all
lemma tm1_tm: "turing_machine (k1 + k2) G tm1" unfolding tm1_def using turing_machine_enlarged append_tapes_tm tm_M1 G1 by simp
lemma tm2_tm: "turing_machine (k1 + k2) G tm2" unfolding tm2_def using tm1_tm tm_start_tm turing_machine_def by blast
lemma tm3_tm: "turing_machine (k1 + k2) G tm3" unfolding tm3_def using tm2_tm tm_cp_until_tm turing_machine_def k_ge turing_machine_sequential_turing_machine by (metis add_leD1 less_add_same_cancel1 less_le_trans less_numeral_extra(1) nat_1_add_1)
lemma tm4_tm: "turing_machine (k1 + k2) G tm4" unfolding tm4_def using tm3_tm tm_erase_cr_tm turing_machine_def turing_machine_sequential_turing_machine by (metis Suc_1 Suc_le_lessD tm_erase_cr_tm zero_less_one)
lemma tm5_tm: "turing_machine (k1 + k2) G tm5" unfolding tm5_def using tm4_tm tm_start_tm turing_machine_def turing_machine_sequential_turing_machine by auto
lemma tm6_tm: "turing_machine (k1 + k2) G tm6" unfolding tm6_def using tm5_tm tm56_def turing_machine_enlarged prepend_tapes_tm tm_M2 G2 by simp
lemma tm7_tm: "turing_machine (k1 + k2) G tm7" unfolding tm7_def using tm6_tm tm_cr_tm turing_machine_def by blast
lemma tm8_tm: "turing_machine (k1 + k2) G tm8" unfolding tm8_def using tm7_tm tm_cp_until_tm turing_machine_def turing_machine_sequential_turing_machine k_ge(2) by (metis add.commute add_less_cancel_right add_strict_increasing nat_1_add_1
verit_comp_simplify1(3) zero_less_one)
context fixes x :: string begin
definition"zs ≡ string_to_symbols x"
lemma bit_symbols_zs: "bit_symbols zs" using zs_def by simp
abbreviation"n ≡ length x"
lemma length_zs [simp]: "length zs = n" using zs_def by simp
lemma tps1_at_1: "tps1 ! 1 = tps1a ! 1" using tps1_def length_tps1a k_ge by (metis Suc_1 Suc_le_lessD nth_append)
lemma tps1_at_1': "tps1 ::: 1 = string_to_contents (f1 x)" using tps1_at_1 tps1a by simp
lemma tps1_pos_le: "tps1 :#: 1 ≤ T1 n" proof - have"execute M1 (start_config k1 zs) (T1 n) = (length M1, tps1a)" using transforms_def transits_def tps1a(2) by (metis (no_types, lifting) execute_after_halting_ge fst_conv start_config_def snd_conv) moreoverhave"execute M1 (start_config k1 zs) (T1 n) <#> 1 ≤ T1 n" using head_pos_le_time[OF tm_M1, of 1] k_ge by fastforce ultimatelyshow ?thesis using tps1_at_1 by simp qed
lemma length_f1_x: "length (f1 x) ≤ T1 n" proof - have"execute M1 (start_config k1 zs) (T1 n) = (length M1, tps1a)" using transforms_def transits_def tps1a(2) by (metis (no_types, lifting) execute_after_halting_ge fst_conv start_config_def snd_conv) moreoverhave"(execute M1 (start_config k1 zs) (T1 n) <:> 1) i = ◻"if"i > T1 n"fori using blank_after_time[OF that _ _ tm_M1] k_ge(1) by simp ultimatelyhave"(tps1a ::: 1) i = ◻"if"i > T1 n"for i using that by simp thenhave"(string_to_contents (f1 x)) i = ◻"if"i > T1 n"for i using that tps1a(1) by simp thenhave"length (string_to_symbols (f1 x)) ≤ T1 n" by (metis length_map order_refl verit_comp_simplify1(3) zero_neq_numeral zero_neq_one) thenshow ?thesis by simp qed
lemma start_config_append: "start_config (k1 + k2) zs = (0, snd (start_config k1 zs) @ tps1b)" proof have"k1 > 0" using tm_M1 turing_machine_def by simp show"fst (start_config (k1 + k2) zs) = fst (0, snd (start_config k1 zs) @ tps1b)" using start_config_def by simp show"snd (start_config (k1 + k2) zs) = snd (0, snd (start_config k1 zs) @ tps1b)"
(is"?l = ?r") proof (rule nth_equalityI) have len: "||start_config k1 zs|| = k1" using start_config_length by (simp add: ‹0 < k1›) show"length ?l = length ?r" using start_config_length tps1b_def tm_M1 turing_machine_def by simp show"?l ! j = ?r ! j"if"j < length ?l"for j proof (cases "j < k1") case True show ?thesis proof (cases "j = 0") case True thenshow ?thesis using start_config_def `k1 > 0` by simp next case False thenhave1: "?l ! j = (λi. if i = 0 then ▹ else ◻, 0)" using start_config_def `k1 > 0` True by auto have"?r ! j = snd (start_config k1 zs) ! j" using True len by (simp add: nth_append) thenhave"?r ! j = (λi. if i = 0 then ▹ else ◻, 0)" using start_config4 `k1 > 0` False True by simp thenshow ?thesis using1by simp qed next case False thenhave j: "j < k1 + k2""k1 ≤ j" using that ‹0 < k1› add_gr_0 start_config_length by simp_all thenhave"?r ! j = (⌊[]⌋, 0)" using tps1b_def by (simp add: False len nth_append) moreoverhave"?l ! j = (λi. if i = 0 then ▹ else ◻, 0)" using start_config4 `k1 > 0` j by simp ultimatelyshow ?thesis by auto qed qed qed
lemma tm1 [transforms_intros]: "transforms tm1 tps0 (T1 n) tps1" proof - let ?M = "append_tapes k1 (k1 + length tps1b) M1" have len: "||start_config k1 zs|| = k1" using start_config_length[of k1 zs] tm_M1 turing_machine_def by simp have"transforms ?M (snd (start_config k1 zs) @ tps1b) (T1 n) (tps1a @ tps1b)" using transforms_append_tapes[OF tm_M1 len tps1a(2), of tps1b] . moreoverhave"tps0 = snd (start_config k1 zs) @ tps1b" unfolding tps0_def using start_config_append by simp ultimatelyhave *: "transforms ?M tps0 (T1 n) tps1" using tps1_def by simp
have"symbols_lt G1 zs" using bit_symbols_zs tm_M1 turing_machine_def by auto moreoverhave"turing_machine (k1 + k2) G1 ?M" using append_tapes_tm[OF tm_M1, of "k1 + k2"] by (simp add: tps1b_def) ultimatelyhave"transforms (enlarged G1 ?M) tps0 (T1 n) tps1" using transforms_enlarged * tps0_def by simp thenshow ?thesis using tm1_def tps1b_def by simp qed
lemma clean_string_to_contents: "clean_tape (string_to_contents xs, i)" using clean_tape_def by simp
lemma tm8: assumes"t = 15 + 7 * T1 n + 2 * T2 m + length (f2 (f1 x))" shows"transforms tm8 tps0 t tps8" unfolding tm8_def proof (tform tps: assms) show"k1 + 1 < length tps7" using tps7_def length_tps1a length_tps6b k_ge(2) by simp show"1 < length tps7" using tps7_def length_tps6b k_ge(2) by simp let ?n = "length (f2 (f1 x))" show"rneigh (tps7 ! (k1 + 1)) {◻} ?n" proof (rule rneighI) show"(tps7 ::: (k1 + 1)) (tps7 :#: (k1 + 1) + ?n) ∈ {◻}" using tps7_at_Suc_k1 by simp show"∧n'. n' < ?n ==> (tps7 ::: (k1 + 1)) (tps7 :#: (k1 + 1) + n') ∉ {◻}" using tps7_at_Suc_k1 by simp qed show"tps8 = tps7 [k1 + 1 := tps7 ! (k1 + 1) |+| ?n, 1 := implant (tps7 ! (k1 + 1)) (tps7 ! 1) ?n]"
(is"tps8 = ?tps") proof (rule nth_equalityI) show"length tps8 = length ?tps" using tps8_def tps7_def by simp have len: "length tps8 = k1 + k2" using tps8_def length_tps6b by simp show"tps8 ! j = ?tps ! j"if"j < length tps8"for j proof (cases "j < k1") case j_less: True thenhave lhs: "tps8 ! j = tps1a[1 := (string_to_contents (f2 (f1 x)), Suc (length (f2 (f1 x))))] ! j" using tps8_def length_tps1a length_tps6b k_ge by (simp add: nth_append) show ?thesis proof (cases "j = 1") case True thenhave1: "?tps ! j = implant (tps7 ! (k1 + 1)) (tps7 ! 1) ?n" using‹1 < length tps7›by simp have2: "tps8 ! j = (string_to_contents (f2 (f1 x)), Suc (length (f2 (f1 x))))" using lhs True j_less by simp have3: "tps7 ! 1 = (⌊[]⌋, 1)" using tps7_def length_tps1a by (metis (no_types, lifting) True j_less length_list_update nth_append nth_list_update_eq) have"implant (string_to_contents (f2 (f1 x)), 1) (⌊[]⌋, 1) ?n = (string_to_contents (f2 (f1 x)), Suc ?n)" using implant contents_def by auto thenshow ?thesis using123 tps7_at_Suc_k1 by simp next case False thenhave"?tps ! j = tps7 ! j" by (metis One_nat_def Suc_eq_plus1 add.commute j_less not_add_less2 nth_list_update_neq) thenhave"?tps ! j = tps1a ! j" using False j_less tps7_def length_tps1a by (metis (no_types, lifting) length_list_update nth_append nth_list_update_neq) moreoverhave"tps8 ! j = tps1a ! j" using False j_less tps8_def lhs by simp ultimatelyshow ?thesis by simp qed next case j_ge: False thenhave lhs: "tps8 ! j = tps6b[1 := (string_to_contents (f2 (f1 x)), Suc (length (f2 (f1 x))))] ! (j - k1)" using tps8_def length_tps1a length_tps6b k_ge by (simp add: nth_append) show ?thesis proof (cases "j = Suc k1") case True thenhave"tps8 ! j = (string_to_contents (f2 (f1 x)), Suc (length (f2 (f1 x))))" using lhs len that length_tps6b by simp moreoverhave"?tps ! j = tps7 ! Suc k1 |+| ?n" using True ‹k1 + 1 < length tps7› k_ge(1) by simp ultimatelyshow ?thesis using tps7_at_Suc_k1 True by simp next case False thenhave"tps8 ! j = tps6b ! (j - k1)" using lhs by simp moreoverhave"?tps ! j = tps7 ! j" using False j_ge that k_ge(1) by simp ultimatelyshow ?thesis using tps7_def j_ge False length_tps1a by (metis (no_types, lifting) add.commute add_diff_inverse_nat length_list_update
nth_append nth_list_update_neq plus_1_eq_Suc) qed qed qed qed
lemma tm8': assumes"t = 15 + 7 * T1 n + 3 * T2 m" shows"transforms tm8 tps0 t tps8" proof (rule transforms_monotone[OF tm8], simp) show"15 + 7 * T1 n + 2 * T2 m + length (f2 (f1 x)) ≤ t" using length_f2_f1_x assms by simp qed
lemma tm8'_mono: assumes"mono T2" and"t = 15 + 7 * T1 n + 3 * T2 (T1 n)" shows"transforms tm8 tps0 t tps8" proof (rule transforms_monotone[OF tm8'], simp) have"T2 (T1 n) ≥ T2 m" using assms(1) length_f1_x monoE by auto thenshow"15 + 7 * T1 n + 3 * T2 m ≤ t" using assms(2) by simp qed
end(* context x *)
lemma computes_composed_mono: assumes"mono T2"and"T = (λn. 15 + 7 * T1 n + 3 * T2 (T1 n))" shows"computes_in_time (k1 + k2) tm8 (f2 ∘ f1) T" proof fix x have"tps8 x ::: 1 = string_to_contents (f2 (f1 x))" using tps8_at_1 by simp moreoverhave"transforms tm8 (snd (start_config (k1 + k2) (string_to_symbols x))) (T (length x)) (tps8 x)" using tm8'_mono assms tps0_def zs_def by simp ultimatelyshow"∃tps. tps ::: 1 = string_to_contents ((f2 ∘ f1) x) ∧ transforms tm8 (snd (start_config (k1 + k2) (string_to_symbols x))) (T (length x)) tps" by force qed
end(* locale compose *)
lemma computes_composed_poly: assumes tm_M1: "turing_machine k1 G1 M1" and tm_M2: "turing_machine k2 G2 M2" and computes1: "computes_in_time k1 M1 f1 T1" and computes2: "computes_in_time k2 M2 f2 T2" assumes"big_oh_poly T1"and"big_oh_poly T2" shows"∃T k G M. big_oh_poly T ∧ turing_machine k G M ∧ computes_in_time k M (f2 ∘ f1) T" proof - obtain d1 :: nat where"big_oh T1 (λn. n ^ d1)" using assms(5) big_oh_poly_def by auto obtain b c d2 :: nat where cm: "d2 > 0""∀n. T2 n ≤ b + c * n ^ d2" using big_oh_poly_offset[OF assms(6)] by auto let ?U = "λn. b + c * n ^ d2" have U: "T2 n ≤ ?U n"for n using cm by simp have"mono ?U" by standard (simp add: cm(1)) have computesU: "computes_in_time k2 M2 f2 ?U" using computes_in_time_mono[OF computes2 U] . interpret compo: compose k1 k2 G1 G2 M1 M2 T1 ?U f1 f2 using assms computesU compose.intro by simp let ?M = "compo.tm8" let ?T = "(λn. 15 + 7 * T1 n + 3 * (b + c * T1 n ^ d2))" have"computes_in_time (k1 + k2) ?M (f2 ∘ f1) ?T" using compo.computes_composed_mono[OF `mono ?U`, of ?T] by simp moreoverhave"big_oh_poly ?T" proof - have"big_oh_poly (λn. n ^ d2)" using big_oh_poly_poly by simp moreoverhave"(λn. T1 n ^ d2) = (λn. n ^ d2) ∘ T1" by auto ultimatelyhave"big_oh_poly (λn. T1 n ^ d2)" using big_oh_poly_composition[OF assms(5)] by auto thenhave"big_oh_poly (λn. 3 * (b + c * T1 n ^ d2))" using big_oh_poly_const big_oh_poly_prod big_oh_poly_sum by simp thenshow ?thesis using assms(5) big_oh_poly_const big_oh_poly_prod big_oh_poly_sum by simp qed moreoverhave"turing_machine (k1 + k2) compo.G ?M" using compo.tm8_tm . ultimatelyshow ?thesis by auto qed
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.