(***********************************************************************)
(** * Simulation                                                       *)
(***********************************************************************)
(** A scoped configuration is one where all free variables in terms are either bound in the heap or come from [D] *)
Inductive scoped_conf : atoms -> configuration -> Prop :=
scoped_conf_witness : forall D h e s,
scoped_heap D h ->
fv_exp (nom_to_exp e) [<=] dom h \u D ->
fv_stack s [<=] dom h \u D  ->
scoped_conf D (h,e,s).
(** *** Exercise [simulate_step]  After stepping through the simulation result below, finish the missing case.  *)

(* Could be zero or one steps! *)
Lemma simulate_step : forall D h e s h' e' s' ,
machine_step D (h,e,s) = TakeStep _ (h',e',s') ->
scoped_conf D (h,e,s) ->
decode (h,e,s) = decode (h',e',s') \/
step (decode (h,e,s)) (decode (h',e',s')).