From BusyCoq Require Import Individual62.
Require Import ZArith Lia.
Require Import String.
Require Import List.
From BusyCoq Require Import ES_v3.
Definition tm := Eval compute in (TM_from_str "1RB1LD_0RC1RC_1LA1RE_---1LE_1RF0RC_0RB0LF").
Notation "c -->* c'" := (c -[ tm ]->* c') (at level 40).
Notation "c -->+ c'" := (c -[ tm ]->+ c') (at level 40).
Definition G : list sym :=
[0;0;1;1;0;1;1;1;1;0;1;1;0;1;1;1;1;1;1;0;1;1;0;1;1;1;1;1;0;0;1;1;0;1;1;1;1;1;0;1;1;0;0].
Definition Kr n a b c d :=
0inf <{{F}} G *> [1] *> [1;1]^^n *> [0] *> [1;1]^^a *> [0;1;1;0] *> [1;1]^^b
*> [0;0;0;0;0;0] *> [1] *> [1;1]^^c *> [0;1;1;0;1;1;1;1;0;0;0;0;0;0] *> [1;1]^^d
*> [0;1;1;0;0;1;1;0;1;1;1] *> 0inf.
Fixpoint cc_steps (n:nat) (x:cconfig) : option cconfig :=
match n with
| O => Some x
| S n0 =>
match cconfig_step tm x with
| Some x0 => cc_steps n0 x0
| None => None
end
end.
Lemma cc_steps_spec n x y:
cc_steps n x = Some y -> cconfig_to_config x -->* cconfig_to_config y.
Proof.
gen x.
induction n; cbn[cc_steps]; intros x H.
- inverts H. apply evstep_refl.
- pose proof (cconfig_step_spec tm x) as HE.
destruct (cconfig_step tm x) as [x0|]. 2: congruence.
eapply evstep_step; eauto.
Qed.
Fixpoint cc_steps' (n1 n2 n3:nat) (x:cconfig) : option cconfig :=
match n1 with
| O => cc_steps n3 x
| S n1 =>
match cc_steps n2 x with
| Some x0 => cc_steps' n1 n2 n3 x0
| None => None
end
end.
Lemma cc_steps'_spec n1 n2 n3 x y:
cc_steps' n1 n2 n3 x = Some y -> cconfig_to_config x -->* cconfig_to_config y.
Proof.
gen x.
induction n1; cbn[cc_steps']; intros x H.
- exact (cc_steps_spec _ _ _ H).
- destruct (cc_steps n2 x) as [x0|] eqn:E. 2: congruence.
eapply evstep_trans.
+ exact (cc_steps_spec _ _ _ E).
+ apply IHn1, H.
Qed.
Definition Kr_list n a b c d : list sym :=
G ++ [1] ++ [1;1]^^n ++ [0] ++ [1;1]^^a ++ [0;1;1;0] ++ [1;1]^^b
++ [0;0;0;0;0;0] ++ [1] ++ [1;1]^^c ++ [0;1;1;0;1;1;1;1;0;0;0;0;0;0] ++ [1;1]^^d
++ [0;1;1;0;0;1;1;0;1;1;1].
Lemma Kr_cc n a b c d:
Kr n a b c d = cconfig_to_config ([], Kr_list n a b c d, 0, F).
Proof.
unfold Kr, Kr_list, cconfig_to_config.
cbn [Str_app]. rewrite !Str_app_assoc. reflexivity.
Qed.
Lemma init:
c0 -->* Kr 979 17 34 22 9.
Proof.
rewrite Kr_cc.
change c0 with (cconfig_to_config ([], [], 0, A)).
apply (cc_steps'_spec 4097 1000 897).
vm_compute.
reflexivity.
Time Qed.