Section HybridCoarseMachine.
Variable n: nat.
Context {resources: Resources}
{Sem: Semantics}
{ThreadPool : ThreadPool.ThreadPool}
{machineSig: MachineSig}.
Instance DilMem : DiluteMem :=
{| diluteMem := fun x => x |}.
intros.
split; auto.
Defined.
Instance scheduler : Scheduler :=
{| isCoarse := true;
yield := fun x => x |}.
Notation thread_pool := t.
Notation C:= (semC).
Notation G:= (semG).
Local Notation ctl := (@ctl C).
Notation machine_state := thread_pool.
Notation schedule := (seq nat).
Notation event_trace := (seq machine_event).
Definition HybridCoarseMachine : HybridMachine :=
@Build_HybridMachine resources Sem ThreadPool _ _ _
(MachineCoreSemantics)
(new_MachineSemantics)
(hybrid_initial_schedule).
(** Schedule safety of the coarse-grained machine*)
Inductive csafe (st : MachState) (m : mem) : nat -> Prop :=
| Safe_0: csafe st m 0
| HaltedSafe: forall n, halted_machine st -> csafe st m n
| CoreSafe : forall tp' m' n tr
(Hstep: MachStep st m (fst (fst st),(snd (fst st)) ++ tr,tp') m')
(Hsafe: csafe (fst (fst st),(snd (fst st)) ++ tr,tp') m' n),
csafe st m (S n)
| AngelSafe: forall tp' m' n (tr: event_trace)
(Hstep: MachStep st m (schedSkip (fst (fst st)),(snd (fst st)) ++ tr,tp') m')
(Hsafe: forall U'', csafe (U'',(snd (fst st)) ++ tr,tp') m' n),
csafe st m (S n).
(** Schedule safety of the coarse-grained machine*)
Inductive concur_safe U tp (m : mem) : nat -> Prop :=
| concur_Safe_0: concur_safe U tp m 0
| concur_HaltedSafe: forall n, halted_machine (U, nil, tp) -> concur_safe U tp m n
| concur_Internal : forall tp' m' n
(Hstep: internal_step U tp m tp' m')
(Hsafe: concur_safe U tp' m' n),
concur_safe U tp m (S n)
| concur_External: forall tp' m' n (tr tr': event_trace)
(Hstep: external_step U tr tp m U tr' tp' m')
(Hsafe: concur_safe U tp' m' n),
concur_safe U tp m (S n)
| concur_External_Angel: forall tp' m' n (tr tr': event_trace)
(Hstep: external_step U tr tp m (schedSkip U) tr' tp' m')
(Hsafe: forall U'', concur_safe U'' tp' m' n),
concur_safe U tp m (S n).

Lemma csafe_concur_safe: forall U tr tp m n, csafe (U, tr, tp) m n -> concur_safe U tp m n.