(*This file contains the proof of transitivity for the forward_simulations.coop_sim, ie the following theorem:  Theorem coop_sim_trans: forall (SIM12: coop_sim Sem1 Sem2 g1 g2 epts12) (SIM23: coop_sim Sem2 Sem3 g2 g3 epts23), coop_sim Sem1 Sem3 g1 g3 epts13.  The only holes in this file relate to the preservation and composition of meminj_preserves_globals, an issue that is largely orthogonal to our core focus of interest, and the definition of globalenvs may need to evolve a bit anyway once AST.program is restructured to support compilation units. *)
Declare Module MEMAX : MemoryInterpolationAxioms.
Definition entrypoints_compose
(ep12 ep23 ep13 : list (val * val * signature)): Prop :=
forall v1 v3 sig, In (v1,v3,sig) ep13 =
exists v2, In (v1,v2,sig) ep12 /\ In (v2,v3,sig) ep23.
Inductive sem_compose_ord_eq_eq {D12 D23:Type}
(ord12: D12 -> D12 -> Prop) (ord23: D23 -> D23 -> Prop) (C2:Type):
(D12 * option C2 * D23) ->  (D12 * option C2 * D23) ->  Prop :=
| sem_compose_ord1 :
forall (d12 d12':D12) (c2:C2) (d23:D23),
ord12 d12 d12' -> sem_compose_ord_eq_eq ord12 ord23 C2 (d12,Some c2,d23) (d12',Some c2,d23)
| sem_compose_ord2 :
forall (d12 d12':D12) (c2 c2':C2) (d23 d23':D23),
ord23 d23 d23' -> sem_compose_ord_eq_eq ord12 ord23 C2 (d12,Some c2,d23) (d12',Some c2',d23').

Lemma well_founded_sem_compose_ord_eq_eq: forall {D12 D23:Type}
(ord12: D12 -> D12 -> Prop) (ord23: D23 -> D23 -> Prop)  (C2:Type)
(WF12: well_founded ord12) (WF23: well_founded ord23),
well_founded (sem_compose_ord_eq_eq ord12 ord23 C2).