+lemma merge_char_not_null :
+ ∀c1,c2.c1 ≠ null → merge_char c1 c2 ≠ null.
+#c1 #c2 @not_to_not cases c2
+[ #c1' normalize #Hfalse destruct (Hfalse)
+| normalize //
+| *: normalize #Hfalse destruct (Hfalse)
+]
+qed.
+
+lemma merge_char_null : ∀c.merge_char null c = c.
+* //
+qed.
+
+lemma merge_char_cases : ∀c1,c2.merge_char c1 c2 = c1 ∨ merge_char c1 c2 = c2.
+#c1 *
+[ #c1' %2 %
+| % %
+| *: %2 % ]
+qed.
+
+(* lemma merge_char_c_bit :
+ ∀c1,c2.is_bit c2 = true → merge_char c1 c2 = c2.
+#c1 *
+[ #c2' #_ %
+|*: normalize #Hfalse destruct (Hfalse) ]
+qed.
+
+lemma merge_char_c_bit :
+ ∀c1,c2.is_null c2 = true → merge_char c1 c2 = c1.
+#c1 *
+[ #c2' #_ %
+|*: normalize #Hfalse destruct (Hfalse) ]
+qed.
+
+*)
+
+lemma sem_exec_move : Realize ? exec_move R_exec_move.
+#intape
+cases (sem_seq … sem_init_copy
+ (sem_seq … sem_copy
+ (sem_seq … (sem_move_r …) sem_move_tape )) intape)
+#k * #outc * #Hloop #HR
+@(ex_intro ?? k) @(ex_intro ?? outc) % [ @Hloop ] -Hloop
+#n #curconfig #ls #rs #c0 #c1 #s0 #s1 #table1 #newconfig #mv #table2
+#Htable #Hcurconfig1 #Hcurconfig2 #Hnewconfig #Hc1 #Hlen #Htape #Hintape #t1' #Ht1'
+cases HR -HR #ta * whd in ⊢ (%→?); #Hta
+lapply (Hta (〈c0,false〉::curconfig) table1 s0 ls s1
+ (newconfig@〈c1,false〉::〈comma,false〉::〈mv,false〉::table2@〈grid,false〉::rs) … Hintape) -Hta
+[ (*Hcurconfig2*) @daemon
+| (*Htable*) @daemon
+| (*bit_or_null c0 = true *) @daemon
+| (*Hcurconfig1*) @daemon
+| #Hta * #tb * whd in ⊢ (%→?); #Htb
+ lapply (Htb (〈grid,false〉::ls) s0 s1 c0 c1 (〈mv,false〉::table2@〈grid,false〉::rs) newconfig (〈comma,false〉::reverse ? table1) curconfig Hta ????????) -Htb
+ [9:|*:(* bit_or_null c0,c1; |curconfig| = |newconfig|*) @daemon ]
+ #Htb * #tc * whd in ⊢ (%→?); #Htc lapply (Htc … Htb) -Htc whd in ⊢(???(??%%%)→?);#Htc
+ whd in ⊢ (%→?); #Houtc whd in Htc:(???%); whd in Htc:(???(??%%%));
+ lapply (Houtc rs n
+ (〈comma,false〉::〈c1,false〉::reverse ? newconfig@〈s1,false〉::〈comma,false〉::reverse ? table1)
+ mv table2 (merge_char c0 c1) (reverse ? newconfig@[〈s1,false〉]) ls ????????)
+ [3: cases Htape -Htape * * #Hnomarks #Hbits #Hc0 #Hlsrs % [ % [ %
+ [ #x #Hx cases (orb_true_l … Hx) #Hx'
+ [ >(\P Hx') %
+ | @Hnomarks @memb_cons // ]
+ | @Hbits ]
+ | cases (merge_char_cases c0 c1) #Hmerge >Hmerge // ]
+ | cases (true_or_false (c0 == null)) #Hc0'
+ [ cases Hlsrs -Hlsrs
+ [ *
+ [ >(\P Hc0') * #Hfalse @False_ind /2/
+ | #Hlsnil % %2 // ]
+ | #Hrsnil %2 // ]
+ | % % @merge_char_not_null @(\Pf Hc0') ] ]
+ |4:>Htc @(eq_f3 … (midtape ?))
+ [ @eq_f @eq_f >associative_append >associative_append %
+ | %
+ | % ]
+ | %
+ || >reverse_cons >reverse_cons >reverse_append >reverse_reverse
+ >reverse_cons >reverse_cons >reverse_reverse
+ >associative_append >associative_append >associative_append
+ >associative_append >associative_append
+ @Htable
+ | (* well formedness of table *) @daemon
+ | (* Hnewconfig *) @daemon
+ | (* bit_or_null mv = true (well formedness of table) *) @daemon
+ | -Houtc * #ls1 * #rs1 * #newc * #Hnewtapelegal * #Houtc *
+ [ *
+ [ * #Hmv #Htapemove
+ @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc)
+ %
+ [ %
+ [ >Houtc -Houtc >reverse_append
+ >reverse_reverse >reverse_single @eq_f
+ >reverse_cons >reverse_cons >reverse_append >reverse_cons
+ >reverse_cons >reverse_reverse >reverse_reverse
+ >associative_append >associative_append
+ >associative_append >associative_append
+ >associative_append >associative_append %
+ | >Hmv >Ht1' >Htapemove
+ (* mv = bit false -→ c1 = bit ? *)
+ cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
+ >Hc1 >tape_move_left_eq >(legal_tape_left … Htape)
+ >(legal_tape_right … Htape) %
+ ]
+ | //
+ ]
+ | * #Hmv #Htapemove
+ @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
+ [ %
+ [ >Houtc -Houtc >reverse_append
+ >reverse_reverse >reverse_single @eq_f
+ >reverse_cons >reverse_cons >reverse_append >reverse_cons
+ >reverse_cons >reverse_reverse >reverse_reverse
+ >associative_append >associative_append
+ >associative_append >associative_append
+ >associative_append >associative_append %
+ |>Hmv >Ht1' >Htapemove
+ cut (∃c1'.c1 = bit c1') [ @daemon ] * #c1' #Hc1
+ >Hc1 >tape_move_right_eq >(legal_tape_left … Htape)
+ >(legal_tape_right … Htape) %
+ ]
+ | //
+ ]
+ ]
+ | * * * #Hmv #Hlseq #Hrseq #Hnewc
+ @(ex_intro ?? ls1) @(ex_intro ?? rs1) @(ex_intro ?? newc) %
+ [ %
+ [ >Houtc -Houtc >reverse_append
+ >reverse_reverse >reverse_single @eq_f
+ >reverse_cons >reverse_cons >reverse_append >reverse_cons
+ >reverse_cons >reverse_reverse >reverse_reverse
+ >associative_append >associative_append
+ >associative_append >associative_append
+ >associative_append >associative_append %
+ |>Hmv >Ht1' cases c1 in Hnewc;
+ [ #c1' whd in ⊢ (??%?→?);#Hnewc <Hnewc
+ >Hlseq >Hrseq whd in ⊢ (??%%);
+ >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
+ | whd in ⊢ (??%?→?); #Hnewc >Hnewc >Hlseq >Hrseq %
+ |*: whd in ⊢ (??%?→?);#Hnewc <Hnewc
+ >Hlseq >Hrseq whd in ⊢ (??%%);
+ >(legal_tape_left … Htape) >(legal_tape_right … Htape) %
+ ]
+ ]
+ | //
+ ]
+ ]
+ ]
+]
+qed.
+
+(*
+if is_false(current) (* current state is not final *)
+ then init_match;
+ match_tuple;
+ if is_marked(current) = false (* match ok *)
+ then
+ exec_move
+ move_r;