+
+definition test_null_char ≝ test_char FSUnialpha (λc.c == null).
+
+definition R_test_null_char_true ≝ λt1,t2.
+ current FSUnialpha t1 = Some ? null ∧ t1 = t2.
+
+definition R_test_null_char_false ≝ λt1,t2.
+ current FSUnialpha t1 ≠ Some ? null ∧ t1 = t2.
+
+lemma sem_test_null_char :
+ test_null_char ⊨ [ tc_true : R_test_null_char_true, R_test_null_char_false].
+#t1 cases (sem_test_char FSUnialpha (λc.c == null) t1) #k * #outc * * #Hloop #Htrue
+#Hfalse %{k} %{outc} % [ %
+[ @Hloop
+| #Houtc cases (Htrue ?) [| @Houtc] * #c * #Hcurt1 #Hcnull lapply (\P Hcnull)
+ -Hcnull #H destruct (H) #Houtc1 %
+ [ @Hcurt1 | <Houtc1 % ] ]
+| #Houtc cases (Hfalse ?) [| @Houtc] #Hc #Houtc %
+ [ % #Hcurt1 >Hcurt1 in Hc; #Hc lapply (Hc ? (refl ??))
+ >(?:((null:FSUnialpha) == null) = true) [|@(\b (refl ??)) ]
+ #H destruct (H)
+ | <Houtc % ] ]
+qed.
+
+definition copy_char_states ≝ initN 3.
+
+definition cc0 : copy_states ≝ mk_Sig ?? 0 (leb_true_to_le 1 3 (refl …)).
+definition cc1 : copy_states ≝ mk_Sig ?? 1 (leb_true_to_le 2 3 (refl …)).
+
+definition trans_copy_char ≝
+ λsrc,dst.λsig:FinSet.λn.
+ λp:copy_char_states × (Vector (option sig) (S n)).
+ let 〈q,a〉 ≝ p in
+ match pi1 … q with
+ [ O ⇒ 〈cc1,change_vec ? (S n)
+ (change_vec ? (S n) (null_action ? n) (〈None ?,R〉) src)
+ (〈nth src ? a (None ?),R〉) dst〉
+ | S _ ⇒ 〈cc1,null_action ? n〉 ].
+
+definition copy_char ≝
+ λsrc,dst,sig,n.
+ mk_mTM sig n copy_char_states (trans_copy_char src dst sig n)
+ cc0 (λq.q == cc1).
+
+definition R_copy_char ≝
+ λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
+ outt = change_vec ??
+ (change_vec ?? int
+ (tape_move_mono ? (nth src ? int (niltape ?)) 〈None ?, R〉) src)
+ (tape_move_mono ? (nth dst ? int (niltape ?))
+ 〈current ? (nth src ? int (niltape ?)), R〉) dst.
+
+lemma copy_char_q0_q1 :
+ ∀src,dst,sig,n,v.src ≠ dst → src < S n → dst < S n →
+ step sig n (copy_char src dst sig n) (mk_mconfig ??? cc0 v) =
+ mk_mconfig ??? cc1
+ (change_vec ? (S n)
+ (change_vec ?? v
+ (tape_move_mono ? (nth src ? v (niltape ?)) 〈None ?, R〉) src)
+ (tape_move_mono ? (nth dst ? v (niltape ?)) 〈current ? (nth src ? v (niltape ?)), R〉) dst).
+#src #dst #sig #n #v #Heq #Hsrc #Hdst
+whd in ⊢ (??%?);
+<(change_vec_same … v dst (niltape ?)) in ⊢ (??%?);
+<(change_vec_same … v src (niltape ?)) in ⊢ (??%?);
+>tape_move_multi_def @eq_f2 //
+>pmap_change >pmap_change <tape_move_multi_def
+>tape_move_null_action @eq_f2 // @eq_f2
+[ >change_vec_same %
+| >change_vec_same >change_vec_same // ]
+qed.
+
+lemma sem_copy_char:
+ ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
+ copy_char src dst sig n ⊨ R_copy_char src dst sig n.
+#src #dst #sig #n #Hneq #Hsrc #Hdst #int
+%{2} % [| % [ % | whd >copy_char_q0_q1 // ]]
+qed.
+
+definition cfg_to_obj ≝
+ mmove cfg FSUnialpha 2 L ·
+ (ifTM ?? (inject_TM ? test_null_char 2 cfg)
+ (nop ? 2)
+ (copy_char cfg obj FSUnialpha 2 ·
+ mmove cfg FSUnialpha 2 L ·
+ mmove obj FSUnialpha 2 L)
+ tc_true) ·
+ inject_TM ? (move_to_end FSUnialpha L) 2 cfg ·
+ mmove cfg FSUnialpha 2 R.
+
+definition R_cfg_to_obj ≝ λt1,t2:Vector (tape FSUnialpha) 3.
+ ∀c,ls.
+ nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls) (None ?) [ ] →
+ (c = null →
+ t2 = change_vec ?? t1
+ (mk_tape ? [ ] (option_hd FSUnialpha (reverse ? (c::ls)))
+ (tail ? (reverse ? (c::ls)))) cfg) ∧
+ (c ≠ null →
+ t2 = change_vec ??
+ (change_vec ?? t1
+ (midtape ? (left ? (nth obj ? t1 (niltape ?))) c (right ? (nth obj ? t1 (niltape ?)))) obj)
+ (mk_tape ? [ ] (option_hd ? (reverse ? (c::ls))) (tail ? (reverse ? (c::ls)))) cfg).
+
+lemma tape_move_mk_tape_L :
+ ∀sig,ls,c,rs.
+ (c = None ? → ls = [ ] ∨ rs = [ ]) →
+ tape_move ? (mk_tape sig ls c rs) L =
+ mk_tape ? (tail ? ls) (option_hd ? ls) (option_cons ? c rs).
+#sig * [ * [ * | #c * ] | #l0 #ls0 * [ *
+[| #r0 #rs0 #H @False_ind cases (H (refl ??)) #H1 destruct (H1) ] | #c * ] ]
+normalize //
+qed.
+
+lemma sem_cfg_to_obj : cfg_to_obj ⊨ R_cfg_to_obj.
+@(sem_seq_app FSUnialpha 2 ????? (sem_move_multi ? 2 cfg L ?)
+ (sem_seq ??????
+ (sem_if ??????????
+ (acc_sem_inject ?????? cfg ? sem_test_null_char)
+ (sem_nop …)
+ (sem_seq ?????? (sem_copy_char …)
+ (sem_seq ?????? (sem_move_multi ? 2 cfg L ?) (sem_move_multi ? 2 obj L ?))))
+ (sem_seq ?????? (sem_inject ???? cfg ? (sem_move_to_end_l ?))
+ (sem_move_multi ? 2 cfg R ?)))) // [@sym_not_eq //]
+#ta #tb *
+#tc * whd in ⊢ (%→?); #Htc *
+#td * *
+[ * #te * * * #Hcurtc #Hte1 #Hte2 whd in ⊢ (%→?); #Htd destruct (Htd)
+ * #tf * * * #Htf1 #Htf2 #Htf3
+ whd in ⊢ (%→?); #Htb
+ #c #ls #Hta %
+ [ #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
+ cut (te = tc) [@daemon] -Hte1 -Hte2 #Hte
+ cut (tf = change_vec ? 3 te (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
+ [@daemon] -Htf1 -Htf2 -Htf3 #Htf
+ destruct (Htf Hte Htc Htb)
+ >change_vec_change_vec >change_vec_change_vec >change_vec_change_vec
+ >nth_change_vec // >tape_move_mk_tape_R [| #_ % % ]
+ >reverse_cons %
+ | #Hc >Hta in Htc; >eq_mk_tape_rightof whd in match (tape_move ???); #Htc
+ >Htc in Hcurtc; >nth_change_vec // normalize in ⊢ (%→?);
+ #H destruct (H) @False_ind cases Hc /2/ ]
+ * #tf * *
+| * #te * * * #Hcurtc #Hte1 #Hte2
+ * #tf * whd in ⊢ (%→?); #Htf
+ * #tg * whd in ⊢ (%→%→?); #Htg #Htd
+ * #th * * * #Hth1 #Hth2 #Hth3
+ whd in ⊢ (%→?); #Htb
+ #c #ls #Hta % #Hc
+ [ >Htc in Hcurtc; >Hta >nth_change_vec // >tape_move_mk_tape_L //
+ >Hc normalize in ⊢ (%→?); * #H @False_ind /2/
+ | cut (te = tc) [ @daemon ] -Hte1 -Hte2 #Hte
+ cut (th = change_vec ?? td (mk_tape ? [ ] (None ?) (reverse ? ls@[c])) cfg)
+ [@daemon] -Hth1 -Hth2 -Hth3 #Hth
+ destruct (Hth Hte Hta Htb Htd Htg Htc Htf)
+ >change_vec_change_vec >change_vec_change_vec
+ >change_vec_commute // >change_vec_change_vec
+ >change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
+ >change_vec_commute // >change_vec_change_vec
+ >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
+ >nth_change_vec // >nth_change_vec_neq [|@sym_not_eq //]
+ >change_vec_commute [|@sym_not_eq //]
+ @eq_f3 //
+ [ >Hta >tape_move_mk_tape_L // >nth_change_vec // whd in match (current ??);
+ @eq_f2 // cases (nth obj ? ta (niltape ?))
+ [| #r0 #rs0 | #l0 #ls0 | #ls0 #c0 #rs0 ] try %
+ cases rs0 //
+ | >reverse_cons >tape_move_mk_tape_R // #_ % % ]