Section Minsky_Machine_env_based.
Variable (X : Set) (X_eq_dec : eqdec X).
Definition mm_state := (nat*env X nat)%type.
Local Notation " e ⇢ x " := (@get_env _ _ e x).
Local Notation " e ⦃  x ⇠ v ⦄ " := (@set_env _ _ X_eq_dec e x v).
(* Minsky machine small step semantics *)
Inductive mm_sss_env : mm_instr X -> mm_state -> mm_state -> Prop :=
| in_mm_sss_env_inc   : forall i x v,                   INC x  // (i,v) -1> (1+i,v⦃x⇠S(v⇢x)⦄)
| in_mm_sss_env_dec_0 : forall i x k v,   v⇢x = O   -> DEC x k // (i,v) -1> (k,v)
| in_mm_sss_env_dec_1 : forall i x k v u, v⇢x = S u -> DEC x k // (i,v) -1> (1+i,v⦃x⇠u⦄)
where "i // s -1> t" := (mm_sss_env i s t).
Fact mm_sss_env_fun i s t1 t2 : i // s -1> t1 -> i // s -1> t2 -> t1 = t2.
Fact mm_sss_env_total ii s : { t | ii // s -1> t }.
Fact mm_sss_env_INC_inv x i v j w : INC x // (i,v) -1> (j,w) -> j=1+i /\ w = v⦃x⇠S(v⇢x)⦄.
Fact mm_sss_env_DEC1_inv x k u i v j w : v⇢x = S u -> DEC x k // (i,v) -1> (j,w) -> j=1+i /\ w = v⦃x⇠u⦄.
Notation "P // s -[ k ]-> t" := (sss_steps mm_sss_env P k s t).
Notation "P // s -+> t" := (sss_progress mm_sss_env P s t).
Notation "P // s ->> t" := (sss_compute mm_sss_env P s t).
Fact mm_env_progress_INC P i x v st :
(i,INC x::nil) <sc P
-> P // (1+i,v⦃x⇠S(v⇢x)⦄) ->> st
-> P // (i,v) -+> st.

Corollary mm_env_compute_DEC_S P i x k v u st :
(i,DEC x k::nil) <sc P
-> v⇢x = S u
-> P // (1+i,v⦃x⇠u⦄) ->> st
-> P // (i,v) ->> st.