(** * Backward simulations and program behaviors *)
Section BACKWARD_SIMULATIONS.
Context L1 L2 index order match_states (S: bsim_properties L1 L2 index order match_states).
Definition safe_along_behavior (s: state L1) (b: program_behavior) : Prop :=
forall t1 s' b2, Star L1 s t1 s' -> b = behavior_app t1 b2 ->
(exists r, final_state L1 s' r)
\/ (exists t2, exists s'', Step L1 s' t2 s'').
Remark safe_along_safe:
forall s b, safe_along_behavior s b -> safe L1 s.
Remark star_safe_along:
forall s b t1 s' b2,
safe_along_behavior s b ->
Star L1 s t1 s' -> b = behavior_app t1 b2 ->
safe_along_behavior s' b2.
Remark not_safe_along_behavior:
forall s b,
~ safe_along_behavior s b ->
exists t, exists s',
behavior_prefix t b
/\ Star L1 s t s'
/\ Nostep L1 s'
/\ (forall r, ~(final_state L1 s' r)).

(* Specifications: *)
Lemma backward_simulation_star:
forall s2 t s2', Star L2 s2 t s2' ->
forall i s1 b, match_states i s1 s2 -> safe_along_behavior s1 (behavior_app t b) ->
exists i', exists s1', Star L1 s1 t s1' /\ match_states i' s1' s2'.
Lemma backward_simulation_forever_silent:
forall i s1 s2,
Forever_silent L2 s2 -> match_states i s1 s2 -> safe L1 s1 ->
Forever_silent L1 s1.
Lemma backward_simulation_forever_reactive:
forall i s1 s2 T,
Forever_reactive L2 s2 T -> match_states i s1 s2 -> safe_along_behavior s1 (Reacts T) ->
Forever_reactive L1 s1 T.
Lemma backward_simulation_state_behaves:
forall i s1 s2 beh2,
match_states i s1 s2 -> state_behaves L2 s2 beh2 ->
exists beh1, state_behaves L1 s1 beh1 /\ behavior_improves beh1 beh2.
Lemma backward_simulation_star:
forall s2 t s2', Star L2 s2 t s2' ->
forall i s1 b, match_states i s1 s2 -> safe_along_behavior s1 (behavior_app t b) ->
exists i', exists s1', Star L1 s1 t s1' /\ match_states i' s1' s2'.
Lemma backward_simulation_forever_silent:
forall i s1 s2,
Forever_silent L2 s2 -> match_states i s1 s2 -> safe L1 s1 ->
Forever_silent L1 s1.
Lemma backward_simulation_forever_reactive:
forall i s1 s2 T,
Forever_reactive L2 s2 T -> match_states i s1 s2 -> safe_along_behavior s1 (Reacts T) ->
Forever_reactive L1 s1 T.
Lemma backward_simulation_state_behaves:
forall i s1 s2 beh2,
match_states i s1 s2 -> state_behaves L2 s2 beh2 ->
exists beh1, state_behaves L1 s1 beh1 /\ behavior_improves beh1 beh2.