Section SoupPredicates.
(*****************************************************)
(* Message predicates  [Valid messages in soup]  The following generic definition "msg_in_souop" specifies which messages are considered valid in the specific state and the soup.  The derived definition come next.  *)
Definition msg_in_soup (from to : nid) (criterion : nat -> seq nat -> bool)
(d : soup) : Prop :=
(exists! i, exists t c,
find i d = Some (Msg (TMsg t c) from to true)) /\
forall i t c,
find i d = Some (Msg (TMsg t c) from to true) ->
criterion t c.
(* Fix specific tag and content *)
Definition msg_spec from to tg cnt :=
msg_in_soup from to (fun x y => (x == tg) && (y == cnt)).
Definition no_msg_from (from : nid) (d : soup) : Prop :=
forall i to tms b, find i d = Some (Msg tms from to b) -> b = false.
Definition no_msg_to (to : nid) (d : soup) : Prop :=
forall i from tms b, find i d = Some (Msg tms from to b) -> b = false.
Definition no_msg_from_to from to (d : soup) :=
forall i tms b,
find i d = Some (Msg tms from to b) -> b = false.

Lemma msg_specE_consume2 s pt from to to' tg cnt i m :
valid s ->
find i s =
Some {| content := m; from := from; to := to'; active := true |} ->
(to != to') ->
msg_spec pt to tg cnt s ->
msg_spec pt to tg cnt (consume_msg s i).