(* ajout et retrait d'un message dans une file d'attente *)

Definition Post_message (m0 : Message) (b0 : Bag_of_message)
  (s0 s1 : Site) :=
  change_queue (queue Message) b0 s0 s1 (input Message m0 (b0 s0 s1)).Definition Collect_message (b0 : Bag_of_message) (s0 s1 : Site) :=
  change_queue (queue Message) b0 s0 s1 (first_out Message (b0 s0 s1)).

(* Specifications: *)
Lemma post_here : forall (b0 : Bag_of_message) (m0 : Message) (s0 s1 : Site), Post_message m0 b0 s0 s1 s0 s1 = input Message m0 (b0 s0 s1).
Lemma post_elsewhere : forall (b0 : Bag_of_message) (m0 : Message) (s0 s1 s2 s3 : Site), s0 <> s2 \/ s1 <> s3 -> Post_message m0 b0 s0 s1 s2 s3 = b0 s2 s3.
Lemma collect_here : forall (b0 : Bag_of_message) (s0 s1 : Site), Collect_message b0 s0 s1 s0 s1 = first_out Message (b0 s0 s1).
Lemma collect_elsewhere : forall (b0 : Bag_of_message) (s0 s1 s2 s3 : Site), s0 <> s2 \/ s1 <> s3 -> Collect_message b0 s0 s1 s2 s3 = b0 s2 s3.
Lemma in_post : forall (m m' : Message) (bom : Bag_of_message) (s1 s2 s3 s4 : Site), m <> m' -> In_queue Message m (Post_message m' bom s1 s2 s3 s4) -> In_queue Message m (bom s3 s4).
Lemma in_collect : forall (m : Message) (bom : Bag_of_message) (s1 s2 s3 s4 : Site), In_queue Message m (Collect_message bom s1 s2 s3 s4) -> In_queue Message m (bom s3 s4).
Lemma post_card_mess : forall (m : Message) (s1 s2 : Site) (b : Bag_of_message), card_mess m (Post_message m b s1 s2 s1 s2) = (card_mess m (b s1 s2) + 1)%Z.
Lemma diff_post_card_mess : forall (m m' : Message) (s1 s2 s3 s4 : Site) (b : Bag_of_message), m <> m' \/ s1 <> s3 \/ s2 <> s4 -> card_mess m (Post_message m' b s3 s4 s1 s2) = card_mess m (b s1 s2).
Lemma collect_card_mess : forall (m : Message) (s1 s2 : Site) (b : Bag_of_message), first Message (b s1 s2) = value Message m -> card_mess m (Collect_message b s1 s2 s1 s2) = (card_mess m (b s1 s2) - 1)%Z.
Lemma diff_collect_card_mess : forall (m : Message) (s1 s2 s3 s4 : Site) (b : Bag_of_message), first Message (b s1 s2) <> value Message m \/ s1 <> s3 \/ s2 <> s4 -> card_mess m (Collect_message b s3 s4 s1 s2) = card_mess m (b s1 s2).
Lemma D_collect : forall s1 s2 : Site, D_queue (b0 s0 owner) -> D_queue (Collect_message b0 s1 s2 s0 owner).
Lemma D_post_elsewhere : forall (s1 s2 : Site) (m : Message), s1 <> s0 \/ s2 <> owner -> D_queue (b0 s0 owner) -> D_queue (Post_message m b0 s1 s2 s0 owner).
Lemma D_post_dec : D_queue (Post_message dec b0 s0 owner s0 owner).
Lemma alt_collect : forall s1 s2 : Site, alternate (b0 s0 owner) -> alternate (Collect_message b0 s1 s2 s0 owner).
Lemma alt_post_elsewhere : forall (s1 s2 : Site) (m : Message), s1 <> s0 \/ s2 <> owner -> alternate (b0 s0 owner) -> alternate (Post_message m b0 s1 s2 s0 owner).
Lemma alt_post_dec : alternate (b0 s0 owner) -> alternate (Post_message dec b0 s0 owner s0 owner).
Lemma alt_post_inc : forall s1 : Site, alternate (b0 s0 owner) -> b0 s0 owner = empty Message \/ last Message (b0 s0 owner) = value Message dec -> alternate (Post_message (inc_dec s1) b0 s0 owner s0 owner).