Proof with eauto; try omega.
intros HP (k & l & [ u | u j ] & r & v & ? & ? & ?); inversion H; subst; clear H.
- inversion H0; inversion H1; subst; clear H0 H1.
eapply skip_steps...
econstructor. cbn. ring_simplify.
replace (1 + (k + length l)) with (k + length l + 1) by omega. unfold encode_state, fst, snd.
rewrite vec_prod_mult.
rewrite Nat.add_0_r; ring.
- inversion H0; inversion H1; subst; clear H0 H1.
all:eapply skip_steps...
+ cbn. econstructor 2.
intros [] % divides_mult_inv_l...
eapply divides_mult_inv in H0 as [ | ]...
* now eapply qs_ps_div in H0.
* eapply qs_encode_state in H0. omega.
* unfold encode_dec2. econstructor. unfold encode_state, fst, snd. ring.
+ econstructor. cbn. unfold encode_state, fst, snd. ring_simplify.
replace (1 + (k + length l)) with (k + length l + 1) by omega.
erewrite <- (vec_prod_div _ _ _ H4).
rewrite Nat.add_0_r; ring.
Qed.

Lemma steps_forward m i P i1 v1 i2 v2 k :
@mm_no_self_loops m (i, P)
-> (i, P) /MM/ (i1, v1) -[k]-> (i2,v2)
-> encode_mm_instr i P /F/ encode_state (i1,v1) -[k]-> encode_state (i2,v2).