include "turing/multi_universal/unistep_aux.ma".
+include "turing/multi_universal/match.ma".
+definition exec_move ≝
+ cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
+
+definition R_exec_move ≝ λt1,t2:Vector (tape FSUnialpha) 3.
+∀c,m,ls1,ls2,rs2.
+ nth cfg ? t1 (niltape ?) = mk_tape FSUnialpha (c::ls1@[bar]) (None ?) [ ] →
+ nth prg ? t1 (niltape ?) = midtape FSUnialpha (ls2@[bar]) m rs2 →
+ only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
+ c ≠ bar → m ≠ bar →
+ let new_obj ≝
+ tape_move_mono ? (nth obj ? t1 (niltape ?))
+ 〈char_to_bit_option c, char_to_move m〉 in
+ let next_c ≝ low_char' (current ? new_obj) in
+ let new_cfg ≝ midtape ? [ ] bar ((reverse ? ls1)@[next_c]) in
+ let new_prg ≝ midtape FSUnialpha [ ] bar ((reverse ? ls2)@m::rs2) in
+ t2 = Vector_of_list ? [new_obj;new_cfg;new_prg].
+
+
+lemma sem_exec_move: exec_move ⊨ R_exec_move.
+@(sem_seq_app ??????? sem_cfg_to_obj1
+ (sem_seq ?????? sem_tape_move_obj
+ (sem_seq ?????? (sem_restart_tape ???) sem_obj_to_cfg1))) //
+#ta #tout * #t1 * #semM1 * #t2 * #semM2 * #t3 * #semM3 #semM4
+#c #m #ls1 #ls2 #rs2 #Hcfg #Hprg #Honlybits #Hc #Hm
+(* M1 = cfg_to_obj *)
+lapply (semM1 … Hcfg Hc) #Ht1
+(* M2 = tape_move *)
+whd in semM2; >Ht1 in semM2; -Ht1
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>Hprg #Ht2 lapply (Ht2 … (refl ??)) -Ht2
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec // >change_vec_commute [2:@eqb_false_to_not_eq %]
+>change_vec_change_vec #Ht2
+(* M3 = restart prg *)
+whd in semM3; >Ht2 in semM3; #semM3 lapply (semM3 … (refl ??)); -semM3
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %] #Ht3
+(* M4 = obj_to_cfg *)
+whd in semM4; >Ht3 in semM4;
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec [2:@leb_true_to_le %] #semM4 lapply (semM4 … (refl ??)) -semM4
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec [2:@leb_true_to_le %] #semM4 >(semM4 ?)
+ [(* tape by tape *)
+ @(eq_vec … (niltape ?)) #i #lei2
+ cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
+ [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
+ [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec [2:@leb_true_to_le %] %
+ |#Hi >Hi (* obj tape *)
+ >nth_change_vec [2:@leb_true_to_le %] whd in ⊢ (???%);
+ >reverse_cons >reverse_append >reverse_single
+ whd in match (option_hd ??); whd in match (tail ??);
+ whd in ⊢ (??%?); %
+ ]
+ |#Hi >Hi (* prg tape *)
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec [2:@leb_true_to_le %] whd in ⊢ (???%);
+ >Hprg whd in match (list_of_tape ??); >reverse_append
+ >reverse_single %
+ ]
+ |#b #Hcurrent @(list_of_tape_write ? is_bit … (char_to_bit_option c) ? Honlybits)
+ [#b0 cases c
+ [#b1 whd in ⊢ (??%?→?); #Hbit destruct (Hbit) %
+ |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
+ |whd in ⊢ (??%?→?); #Hbit destruct (Hbit)
+ ]
+ |>(list_of_tape_move … (char_to_move m)) @current_in_list @Hcurrent
+ ]
+ ]
+qed.
+
definition unistep ≝
match_m cfg prg FSUnialpha 2 ·
restart_tape cfg 2 · mmove cfg ? 2 R · copy prg cfg FSUnialpha 2 ·
- cfg_to_obj · tape_move_obj · restart_tape prg 2 · obj_to_cfg.
+ exec_move.
(*
definition legal_tape ≝ λn,l,h,t.
is_config n (bar::state@[char]) →
nth prg ? t1 (niltape ?) = midtape ? [ ] bar table →
bar::table = table_TM n l h → *)
-
-definition low_char' ≝ λc.
- match c with
- [ None ⇒ null
- | Some b ⇒ if (is_bit b) then b else null
- ].
-lemma low_char_option : ∀s.
- low_char' (option_map FinBool FSUnialpha bit s) = low_char s.
-* //
-qed.
+definition deterministic_tuples ≝ λn,h,l.
+ ∀t1,t2,conf,out1,out2.
+ is_config n conf →
+ mem ? t1 l → mem ? t2 l →
+ tuple_encoding n h t1 = conf@out1 →
+ tuple_encoding n h t2 = conf@out2 → out1 = out2.
definition R_unistep ≝ λn,l,h.λt1,t2: Vector ? 3.
∀state,char,table.
bar::table = table_TM n l h →
(* obj *)
only_bits (list_of_tape ? (nth obj ? t1 (niltape ?))) →
+ (* deterministic tuples *)
+ deterministic_tuples n h l →
let conf ≝ (bar::state@[char]) in
(∃ll,lr.bar::table = ll@conf@lr) →
(*
(tail sig rs2)) src)
(mk_tape sig (reverse sig rs1@x::ls0) (None sig) []) dst)).
-axiom sem_copy_strict : ∀src,dst,sig,n. src ≠ dst → src < S n → dst < S n →
+lemma sem_copy_strict : ∀src,dst,sig,n. src ≠ dst → src < S n → dst < S n →
copy src dst sig n ⊨ R_copy_strict src dst sig n.
+#src #dst #sig #n #Hneq #Hsrc #Hdst @(Realize_to_Realize … (sem_copy …)) //
+#ta #tb * #Htb1 #Htb2 % [ @Htb1 ]
+#ls #x #x0 #rs #ls0 #rs0 #Htamid_src #Htamid_dst #Hlen
+cases (Htb2 … Htamid_src Htamid_dst) -Htb1 -Htb2
+[ * #rs1 * #rs2 * * #Hrs0 #Heq #Htb <Heq in Hlen; >Hrs0 >length_append
+ >(plus_n_O (|rs1|)) #Hlen cut (|rs2| ≤ 0) [ /2 by le_plus_to_le/ ]
+ #Hlenrs2 cut (rs2 = [ ])
+ [ cases rs2 in Hlenrs2; // #r3 #rs3 normalize #H @False_ind cases (not_le_Sn_O (|rs3|)) /2/ ]
+ #Hrs2 destruct (Hrs2) >append_nil in Hrs0; #Hrs0 destruct (Hrs0) -Hlenrs2 -Hlen
+ <plus_n_O <plus_n_O %{rs} %{[ ]} >append_nil % [ % // ] @Htb
+| * #rs1 * #rs2 #H %{rs1} %{rs2} @H ]
+qed.
+
+lemma config_to_len : ∀n,b,q,c.is_config n (b::q@[c]) → |q| = S n.
+#n #b #q #c * #q0 * #cin * * * #_ #_ #Hq0 #H >(?:q = q0) //
+lapply (cons_injective_r ????? H) #H1 @(append_l1_injective … H1)
+lapply (eq_f … (length ?) … H) normalize >length_append >length_append
+<plus_n_Sm <plus_n_Sm <plus_n_O <plus_n_O #Hlen destruct (Hlen) //
+qed.
-lemma sem_unistep : ∀n,l,h.unistep ⊨ R_unistep n l h.
+lemma sem_unistep_low : ∀n,l,h.unistep ⊨ R_unistep n l h.
#n #l #h
@(sem_seq_app ??????? (sem_match_m cfg prg FSUnialpha 2 ???)
(sem_seq ?????? (sem_restart_tape ???)
(sem_seq ?????? (sem_move_multi ? 2 cfg R ?)
(sem_seq ?????? (sem_copy_strict prg cfg FSUnialpha 2 ???)
- (sem_seq ?????? sem_cfg_to_obj
- (sem_seq ?????? sem_tape_move_obj
- (sem_seq ?????? (sem_restart_tape ???) sem_obj_to_cfg)))))))
+ (sem_exec_move …)))))
/2 by le_n,sym_not_eq/
#ta #tb #HR #state #char #table #Hta_cfg #Hcfg #Hta_prg #Htable
-#Hbits_obj #Htotaltable
+#Hbits_obj #Hdeterm #Hmatching
#nstate #nchar #m #t #Htuple #Hmatch
cases HR -HR #tc * whd in ⊢ (%→?);
>Hta_cfg #H cases (H ?? (refl ??)) -H
(* prg starts with a bar, so it's not empty *) #_
>Hta_prg #H lapply (H ??? (refl ??)) -H *
-[| cases Htotaltable #ll * #lr #H >H
+[| cases Hmatching #ll * #lr #H >H
#Hfalse @False_ind cases (Hfalse ll lr) #H1 @H1 //]
-* #ll * #lr * #Hintable -Htotaltable #Htc
+* #ll * #lr * #Hintable #Htc
* #td * whd in ⊢ (%→?); >Htc
>nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
#Htd lapply (Htd ? (refl ??)) -Htd
>(?: list_of_tape ? (mk_tape ? (reverse ? (state@[char])@[bar]) (None ?) [ ]) =
bar::state@[char])
[|whd in ⊢ (??%?); >left_mk_tape >reverse_append >reverse_reverse
- >current_mk_tape >right_mk_tape normalize >append_nil % ]
+ >current_mk_tape >right_mk_tape [| #_ %2 % ] normalize >append_nil % ]
whd in ⊢ (???(???(????%?)??)→?); whd in match (tail ??); #Htd
(* move cfg to R *)
* #te * whd in ⊢ (%→?); >Htd
>change_vec_commute [|@sym_not_eq //] >change_vec_change_vec
->nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec //
+>nth_change_vec_neq [|@sym_not_eq //] >nth_change_vec [2:@leb_true_to_le %]
+cut (∃ll1.ll@[bar] = bar::ll1)
+[ cases ll in Hintable; [ #_ %{[ ]} % ]
+ #llhd #lltl normalize #H destruct (H) %{(lltl@[bar])} % ] * #ll1 #Hll1
>Htable in Hintable; #Hintable #Hte
(* copy *)
-cases (cfg_in_table_to_tuple ???? Hcfg ?? Hintable)
-#newstate * #m0 * #lr0 * * #Hlr destruct (Hlr) #Hnewcfg #Hm0
-cut (∃fo,so,co.state = fo::so@[co] ∧ |so| = n)
-[ @daemon ] * #fo * #so * #co * #Hstate_exp #Hsolen
-cut (∃fn,sn,cn.newstate = fn::sn@[cn] ∧ |sn| = n)
-[ @daemon ] * #fn * #sn * #cn * #Hnewstate_exp #Hsnlen
+lapply (table_to_list ???? Hcfg ?? Hintable) * #out * #lr0 * #t0
+* * #Hlr #Htuple_t0 #mem_t0
+cut (out = nstate@[nchar;m])
+ [@(Hdeterm … Hcfg mem_t0 Hmatch Htuple_t0 Htuple)] #Hout
+>(append_cons ? nchar) in Htuple; #Htuple
+lapply (tuple_to_config ?????? Hcfg … Htuple) #newconfig
+cut (∃fo,so.state = fo::so ∧ |so| = n)
+[ lapply (config_to_len … Hcfg) cases state [ normalize #H destruct (H) ]
+ #fo #so normalize #H destruct (H) %{fo} %{so} % // ]
+* #fo * #so * #Hstate_exp #Hsolen
+cut (∃fn,sn.nstate = fn::sn ∧ |sn| = n)
+[ lapply (config_to_len … newconfig) cases nstate [ normalize #H destruct (H) ]
+ #fn #sn normalize #H destruct (H) %{fn} %{sn} % // ]
+* #fn * #sn * #Hnewstate_exp #Hsnlen
+>Hstate_exp >Hout in Hlr; >Hnewstate_exp whd in ⊢ (???%→?); #Hlr
* #tf * * #_ >Hte >(nth_change_vec ?????? lt_prg)
>nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
->Hstate_exp >Hnewstate_exp
+>Hstate_exp >Hnewstate_exp >Hlr
whd in match (mk_tape ????); whd in match (tape_move ???);
#Htf cases (Htf ?????? (refl ??) (refl ??) ?) -Htf
[| whd in match (tail ??); >length_append >length_append
- >Hsolen >length_append >length_append >Hsnlen
- <plus_n_Sm <plus_n_Sm <plus_n_Sm <plus_n_O <plus_n_O normalize // ]
+ >Hsolen >length_append >Hsnlen normalize //]
#rs1 * #rs2 whd in match (tail ??); * *
->append_cons #Hrs1rs2 #Hrs1len
+#Hrs1rs2 #Hrs1len
>change_vec_change_vec >change_vec_commute [|@sym_not_eq //]
->change_vec_change_vec #Htf
-(* cfg to obj *)
-* #tg * whd in ⊢ (%→?); >Htf
->nth_change_vec_neq [|@sym_not_eq //] >(nth_change_vec ?????? lt_cfg)
->(change_vec_commute ????? cfg prg) [2:@eqb_false_to_not_eq %]
+>change_vec_change_vec >append_nil #Htf
+(* exec_move *)
+>append_cons in Hrs1rs2; >associative_append #Hrs1rs2
+cut ((sn@[nchar])=rs1)
+ [@(append_l1_injective ?????? Hrs1rs2) >Hrs1len
+ >length_append >length_append normalize >Hsolen >Hsnlen % ] #Hrs1
+cut (m::lr0=rs2) [@(append_l2_injective ?????? Hrs1rs2) >Hrs1 % ] #Hrs2
+whd in ⊢ (%→?); >Htf >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+>nth_change_vec [2:@leb_true_to_le %]
+>nth_change_vec [2:@leb_true_to_le %]
>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
>nth_change_vec_neq [2:@eqb_false_to_not_eq %]
-lapply (append_l1_injective ?????? Hrs1rs2)
-[ >Hsnlen >Hrs1len >length_append >length_append >length_append >length_append
- normalize >Hsolen >Hsnlen % ]
-#Hrs1 <Hrs1 >reverse_append #Htg cases (Htg ?? (refl ??)) -Htg
-cases m0
- [#mv #_ #Htg #_
-
-
-
-
-
-[ *
-
- match_m cfg prg FSUnialpha 2 ·
- restart_tape cfg · copy prg cfg FSUnialpha 2 ·
- cfg_to_obj · tape_move_obj · restart_tape prg · obj_to_cfg.
+>append_cons <Hrs1 >reverse_append >reverse_single
+<Hrs2 >(append_cons … bar ll) >Hll1 >reverse_cons
+#sem_exec_move
+lapply
+ (sem_exec_move ? m ?
+ (([nchar]@reverse FSUnialpha sn)
+ @fn::reverse FSUnialpha (ll1@(fo::so)@[char])) lr0 … (refl ??) ????)
+ [ cut (tuple_TM (S n) (tuple_encoding n h t)) // >Htuple
+ * #qin * #cin * #qout * #cout * #mv * * * * #_ #Hmv #_ #_
+ normalize >(?: bar::qin@cin::qout@[cout;mv] = (bar::qin@cin::qout@[cout])@[mv])
+ [| normalize >associative_append normalize >associative_append % ]
+ >(?: bar::(state@[char])@(nstate@[nchar])@[m] = (bar::(state@[char])@(nstate@[nchar]))@[m])
+ [|normalize >associative_append >associative_append >associative_append >associative_append >associative_append % ]
+ #Heq lapply (append_l2_injective_r ?????? Heq) // #H destruct (H) //
+ | cases newconfig #qout * #cout * * * #_ #Hcout #_ #H destruct (H) -H
+ lapply (append_l2_injective_r ?????? e0) // #H destruct (H) @Hcout
+ |@Hbits_obj
+ |whd in ⊢ (??%?); >associative_append >associative_append
+ >associative_append %
+ |#Htb >Htb @(eq_vec … (niltape ?)) (* tape by tape *) #i #lei2
+ cases (le_to_or_lt_eq … (le_S_S_to_le …lei2))
+ [#lei1 cases (le_to_or_lt_eq … (le_S_S_to_le …lei1))
+ [#lei0 lapply(le_n_O_to_eq … (le_S_S_to_le …lei0)) #eqi <eqi
+ (* obj tape *)
+ >nth_change_vec [2:@leb_true_to_le %] %
+ |(* cfg tape *) #eqi >eqi
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec [2:@leb_true_to_le %]
+ whd in ⊢ (??%?); cut (∀A.∀l:list A.[]@l = l) [//] #Hnil >Hnil
+ >reverse_append >reverse_single >reverse_reverse %
+ (* idem *)
+ ]
+ |(* prg tape *) #eqi >eqi
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >nth_change_vec_neq [2:@eqb_false_to_not_eq %]
+ >Hta_prg whd in ⊢ (??%?); @eq_f @(cons_injective_r ? bar bar)
+ >Htable >Hintable >reverse_append >reverse_cons
+ >reverse_reverse >reverse_cons >reverse_reverse
+ >associative_append >associative_append >associative_append
+ >(append_cons ? bar ll) >Hll1 @eq_f @eq_f <Hstate_exp @eq_f
+ >Hnewstate_exp >Hlr normalize >associative_append >associative_append %
+ ]
+ ]
+qed.
definition tape_map ≝ λA,B:FinSet.λf:A→B.λt.
mk_tape B (map ?? f (left ? t))
(option_map ?? f (current ? t))
(map ?? f (right ? t)).
-
+
+(* da spostare *)
+lemma map_reverse: ∀A,B,f,l.
+ map ?? f (reverse A l) = reverse B (map ?? f l).
+#A #B #f #l elim l //
+#a #l1 #Hind >reverse_cons >reverse_cons <map_append @eq_f2 //
+qed.
+
lemma map_list_of_tape: ∀A,B,f,t.
list_of_tape B (tape_map ?? f t) = map ?? f (list_of_tape A t).
-#A #B #f * // normalize // #ls #c #rs <map_append %
+#A #B #f * //
+ [#a #l normalize >rev_append_def >rev_append_def >append_nil
+ >append_nil <map_append <map_reverse @eq_f2 //
+ |#rs #a #ls normalize >rev_append_def >rev_append_def
+ >append_nil >append_nil <map_append normalize
+ @eq_f2 //
+ ]
qed.
lemma low_char_current : ∀t.
lapply(H (bits_of_state ? (nhalt M) (cstate ?? c))
(low_char (current ? (ctape ?? c)))
(tail ? (table_TM ? (graph_enum ?? (ntrans M)) (nhalt M)))
- ??????)
+ ???????)
[<Htable
lapply(list_to_table … (nhalt M) …Hingraph) * #ll * #lr #Htable1 %{ll}
%{(((bits_of_state ? (nhalt M) qout)@[low_char cout;low_mv m])@lr)}
>Htable1 @eq_f <associative_append @eq_f2 // >Htup
whd in ⊢ (??%?); @eq_f >associative_append %
+|#tx #ty #conf #outx #outy #isconf #memx #memy #tuplex #tupley
+ @(deterministic M … (refl ??) memx memy isconf tuplex tupley)
|>Ht1 >obj_low_tapes >map_list_of_tape elim (list_of_tape ??)
[#b @False_ind | #b #tl #Hind #a * [#Ha >Ha //| @Hind]]
|@sym_eq @Htable
>nth_change_vec_neq [|% whd in ⊢ (??%?→?); #H destruct (H)]
>Ht1 >prg_low_tapes //
]
-qed.
+qed.
+
+lemma sem_unistep : ∀M.unistep ⊨ R_unistep_high M.
+#M @(Realize_to_Realize … (R_unistep_equiv …)) //
+qed.