Definition TS2BSS {P: ProgrammingLanguage} {state: Type} {Ac: Action} {Res: Resource} (TS: TraceSemantics P (resources * state) Ac): BigStepSemantics P state :=
  Build_BigStepSemantics _ _ (fun s c ms => traces_access (cmd_denote c) (fun _ => False, s) (lift_function (pair ( fun _ => False)) ms)).Definition is_upper_bound {A: Type} {R: Relation A} (s: A -> Prop) (a: A): Prop :=
  forall a0, s a0 -> a0 <= a.Definition greatest {A: Type} {R: Relation A} (s: A -> Prop) (a: A): Prop :=
  s a /\ is_upper_bound s a.Inductive thread_local_state_enable {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac} (Inv: resource * (state -> Prop) -> Prop) : action -> resources * state -> MetaState (resources * state) -> Prop :=
| thread_local_state_enable_acq: forall r A1 A2 I m f n,
    join A1 (eq r) A2 ->
    Inv (r, I) -> I f ->
    join m f n ->
    thread_local_state_enable Inv (Aacquire_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_succ: forall r A1 A2 I m n,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    greatest (fun n => exists f, I f /\ join n f m) n ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_fail: forall r A1 A2 I m,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    (forall n, ~ exists f, I f /\ join n f m) ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) Error
| thread_local_state_enable_non_resource: forall a s s',
    ~ is_resources_action a ->
    state_enable a s s' ->
    thread_local_state_enable Inv a s s'.Inductive thread_local_state_enable {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac} (Inv: resource * (state -> Prop) -> Prop) : action -> resources * state -> MetaState (resources * state) -> Prop :=
| thread_local_state_enable_acq: forall r A1 A2 I m f n,
    join A1 (eq r) A2 ->
    Inv (r, I) -> I f ->
    join m f n ->
    thread_local_state_enable Inv (Aacquire_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_succ: forall r A1 A2 I m n,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    greatest (fun n => exists f, I f /\ join n f m) n ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_fail: forall r A1 A2 I m,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    (forall n, ~ exists f, I f /\ join n f m) ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) Error
| thread_local_state_enable_non_resource: forall a s s',
    ~ is_resources_action a ->
    state_enable a s s' ->
    thread_local_state_enable Inv a s s'.Inductive thread_local_state_enable {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac} (Inv: resource * (state -> Prop) -> Prop) : action -> resources * state -> MetaState (resources * state) -> Prop :=
| thread_local_state_enable_acq: forall r A1 A2 I m f n,
    join A1 (eq r) A2 ->
    Inv (r, I) -> I f ->
    join m f n ->
    thread_local_state_enable Inv (Aacquire_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_succ: forall r A1 A2 I m n,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    greatest (fun n => exists f, I f /\ join n f m) n ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_fail: forall r A1 A2 I m,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    (forall n, ~ exists f, I f /\ join n f m) ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) Error
| thread_local_state_enable_non_resource: forall a s s',
    ~ is_resources_action a ->
    state_enable a s s' ->
    thread_local_state_enable Inv a s s'.Inductive thread_local_state_enable {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac} (Inv: resource * (state -> Prop) -> Prop) : action -> resources * state -> MetaState (resources * state) -> Prop :=
| thread_local_state_enable_acq: forall r A1 A2 I m f n,
    join A1 (eq r) A2 ->
    Inv (r, I) -> I f ->
    join m f n ->
    thread_local_state_enable Inv (Aacquire_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_succ: forall r A1 A2 I m n,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    greatest (fun n => exists f, I f /\ join n f m) n ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_fail: forall r A1 A2 I m,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    (forall n, ~ exists f, I f /\ join n f m) ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) Error
| thread_local_state_enable_non_resource: forall a s s',
    ~ is_resources_action a ->
    state_enable a s s' ->
    thread_local_state_enable Inv a s s'.Inductive thread_local_state_enable {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac} (Inv: resource * (state -> Prop) -> Prop) : action -> resources * state -> MetaState (resources * state) -> Prop :=
| thread_local_state_enable_acq: forall r A1 A2 I m f n,
    join A1 (eq r) A2 ->
    Inv (r, I) -> I f ->
    join m f n ->
    thread_local_state_enable Inv (Aacquire_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_succ: forall r A1 A2 I m n,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    greatest (fun n => exists f, I f /\ join n f m) n ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) (Terminating (A2, n))
| thread_local_state_enable_rel_fail: forall r A1 A2 I m,
    join A2 (eq r) A1 ->
    Inv (r, I) ->
    (forall n, ~ exists f, I f /\ join n f m) ->
    thread_local_state_enable Inv (Arelease_res r) (A1, m) Error
| thread_local_state_enable_non_resource: forall a s s',
    ~ is_resources_action a ->
    state_enable a s s' ->
    thread_local_state_enable Inv a s s'.

Lemma thread_local_state_enable_non_resource_action {state: Type} {Ac: Action} {Res: Resource} {J: Join state} {state_R: Relation state} {Acr: Action_resource Ac Res} {ac_sem: ActionInterpret (resources * state) Ac}: forall Inv a s s', ~ is_resources_action a -> (state_enable a s s' <-> thread_local_state_enable Inv a s s').