- λsrc,dst,sig,n,is_sep.λint,outt: Vector (tape sig) (S n).
- (∀ls,x,xs,rs,sep.
- nth src ? int (niltape ?) = midtape sig ls x (xs@sep::rs) →
- (∀c.memb ? c (x::xs) = true → is_sep c = false) → is_sep sep = true →
- ∀ls0,x0,target,c,rs0.|xs| = |target| →
- nth dst ? int (niltape ?) = midtape sig ls0 x0 (target@c::rs0) →
- outt = change_vec ??
- (change_vec ?? int (midtape sig (reverse ? xs@x::ls) sep rs) src)
- (midtape sig (reverse ? xs@x::ls0) c rs0) dst) ∧
- (∀c.current ? (nth src ? int (niltape ?)) = Some ? c → is_sep c = true →
- outt = int) ∧
- (current ? (nth src ? int (niltape ?)) = None ? → outt = int).
-
-lemma wsem_copy : ∀src,dst,sig,n,is_sep.src ≠ dst → src < S n → dst < S n →
- copy src dst sig n is_sep ⊫ R_copy src dst sig n is_sep.
-#src #dst #sig #n #is_sep #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
-lapply (sem_while … (sem_copy_step src dst sig n is_sep Hneq Hsrc Hdst) … Hloop) //
--Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar -ta
-[ whd in ⊢ (%→?); *
- [ * #x * * #Hx #Hsep #Houtc % [ %
- [ #ls #x0 #xs #rs #sep #Hsrctc #Hnosep >Hsrctc in Hx; normalize in ⊢ (%→?);
- #Hx0 destruct (Hx0) lapply (Hnosep ? (memb_hd …)) >Hsep
- #Hfalse destruct (Hfalse)
- | #c #Hc #Hsepc @Houtc ]
- | #_ @Houtc ]
- | * #Hcur #Houtc % [ %
- [ #ls #x0 #xs #rs #sep #Hsrctc >Hsrctc in Hcur; normalize in ⊢ (%→?);
- #Hcur destruct (Hcur)
- | #c #Hc #Hsepc @Houtc ]
- | #_ @Houtc ]
+ λsrc,dst,sig,n.λint,outt: Vector (tape sig) (S n).
+ ((current ? (nth src ? int (niltape ?)) = None ? ∨
+ current ? (nth dst ? int (niltape ?)) = None ?) → outt = int) ∧
+ (∀ls,x,x0,rs,ls0,rs0.
+ nth src ? int (niltape ?) = midtape sig ls x rs →
+ nth dst ? int (niltape ?) = midtape sig ls0 x0 rs0 →
+ (∃rs01,rs02.rs0 = rs01@rs02 ∧ |rs01| = |rs| ∧
+ outt = change_vec ??
+ (change_vec ?? int
+ (mk_tape sig (reverse sig rs@x::ls) (None sig) []) src)
+ (mk_tape sig (reverse sig rs@x::ls0) (option_hd sig rs02)
+ (tail sig rs02)) dst) ∨
+ (∃rs1,rs2.rs = rs1@rs2 ∧ |rs1| = |rs0| ∧
+ outt = change_vec ??
+ (change_vec ?? int
+ (mk_tape sig (reverse sig rs1@x::ls) (option_hd sig rs2)
+ (tail sig rs2)) src)
+ (mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
+
+lemma wsem_copy : ∀src,dst,sig,n.src ≠ dst → src < S n → dst < S n →
+ copy src dst sig n ⊫ R_copy src dst sig n.
+#src #dst #sig #n #Hneq #Hsrc #Hdst #ta #k #outc #Hloop
+lapply (sem_while … (sem_copy_step src dst sig n Hneq Hsrc Hdst) … Hloop) //
+-Hloop * #tb * #Hstar @(star_ind_l ??????? Hstar) -Hstar
+[ whd in ⊢ (%→?); * #Hnone #Hout %
+ [#_ @Hout
+ |#ls #x #x0 #rs #ls0 #rs0 #Hsrc1 #Hdst1 @False_ind cases Hnone
+ [>Hsrc1 normalize #H destruct (H) | >Hdst1 normalize #H destruct (H)]
+ ]
+|#tc #td * #x * #y * * #Hcx #Hcy #Htd #Hstar #IH #He lapply (IH He) -IH *
+ #IH1 #IH2 %
+ [* [>Hcx #H destruct (H) | >Hcy #H destruct (H)]
+ |#ls #x' #y' #rs #ls0 #rs0 #Hnth_src #Hnth_dst
+ >Hnth_src in Hcx; whd in ⊢ (??%?→?); #H destruct (H)
+ >Hnth_dst in Hcy; whd in ⊢ (??%?→?); #H destruct (H)
+ >Hnth_src in Htd; >Hnth_dst -Hnth_src -Hnth_dst
+ cases rs
+ [(* the source tape is empty after the move *)
+ #Htd lapply (IH1 ?)
+ [%1 >Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] >nth_change_vec //]
+ #Hout (* whd in match (tape_move ???); *) %1 %{([])} %{rs0} %
+ [% [// | // ]
+ |whd in match (reverse ??); whd in match (reverse ??);
+ >Hout >Htd @eq_f2 // cases rs0 //
+ ]
+ |#c1 #tl1 cases rs0
+ [(* the dst tape is empty after the move *)
+ #Htd lapply (IH1 ?) [%2 >Htd >nth_change_vec //]
+ #Hout (* whd in match (tape_move ???); *) %2 %{[ ]} %{(c1::tl1)} %
+ [% [// | // ]
+ |whd in match (reverse ??); whd in match (reverse ??);
+ >Hout >Htd @eq_f2 //
+ ]
+ |#c2 #tl2 whd in match (tape_move_mono ???); whd in match (tape_move_mono ???);
+ #Htd
+ cut (nth src (tape sig) td (niltape sig)=midtape sig (x::ls) c1 tl1)
+ [>Htd >nth_change_vec_neq [2:@(not_to_not … Hneq) //] @nth_change_vec //]
+ #Hsrc_td
+ cut (nth dst (tape sig) td (niltape sig)=midtape sig (x::ls0) c2 tl2)
+ [>Htd @nth_change_vec //]
+ #Hdst_td cases (IH2 … Hsrc_td Hdst_td) -Hsrc_td -Hdst_td
+ [* #rs01 * #rs02 * * #H1 #H2 #H3 %1
+ %{(c2::rs01)} %{rs02} % [% [@eq_f //|normalize @eq_f @H2]]
+ >Htd in H3; >change_vec_commute // >change_vec_change_vec
+ >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
+ #H >reverse_cons >associative_append >associative_append @H
+ |* #rs11 * #rs12 * * #H1 #H2 #H3 %2
+ %{(c1::rs11)} %{rs12} % [% [@eq_f //|normalize @eq_f @H2]]
+ >Htd in H3; >change_vec_commute // >change_vec_change_vec
+ >change_vec_commute [2:@(not_to_not … Hneq) //] >change_vec_change_vec
+ #H >reverse_cons >associative_append >associative_append @H
+ ]
+ ]
+ ]