Proof with eauto; try omega.
revert k. induction l; cbn - [subcode] in *; intros.
- revert H0. ring_simplify (k + 0). eauto.
- revert H0. ring_simplify (k + S (length l)). intros H1. destruct a.
+ econstructor 2. intros [[|] % divides_mult_inv | ] % divides_mult_inv; eauto.
* eapply primestream_divides in H0; omega.
* now eapply ps_qs_div in H0.
* eapply divides_encode_state in H0; omega.
* specialize IHl with (k := S k). revert IHl.
cbn - [subcode]. ring_simplify (S (k + length l)).
intros IHl. eapply IHl. 2:exact H1.
intros ? ? ?. eapply H. eapply subcode_cons. eassumption.
+ repeat econstructor 2. 2:unfold encode_dec2.
2,3: cbn- [subcode]. 1: intros [] % divides_mult_inv_l.
2: intros [ | ] % divides_mult_inv...
* eapply divides_mult_inv in H0 as [? | ?]...
eapply primestream_divides in H0...
eapply divides_encode_state in H0...
* eapply primestream_divides in H0... subst.
eapply (H n p). eauto.
* eapply divides_encode_state in H0...
* specialize (IHl (S k)). revert IHl.
cbn - [subcode]. ring_simplify (S (k + length l)).
intros IHl. eapply IHl. 2:exact H1.
intros ? ? ?. eapply H. eapply subcode_cons. eassumption.
Qed.

Lemma one_step_forward m i P i1 v1 i2 v2 :
@mm_no_self_loops m (i,P)
-> (i, P)              /MM/ (i1, v1)           → (i2,v2)
-> encode_mm_instr i P /F/  encode_state (i1,v1) → encode_state (i2,v2).