(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Require Export DistributedReferenceCounting.machine1.machine.
Require Export DistributedReferenceCounting.machine1.cardinal.
Require Export DistributedReferenceCounting.machine1.comm.
Unset Standard Proposition Elimination Names.
Section ROOTED.
Variable s0 : Site.
Definition rooted_fun (s1 s2 : Site) (m : Message) :=
match m with
| copy => if eq_site_dec s1 s0 then 1%Z else 0%Z
| dec => if eq_site_dec s2 s0 then 1%Z else 0%Z
| inc_dec s3 =>
if eq_site_dec s3 s0
then
if eq_site_dec s2 owner then 1%Z else 0%Z
else 0%Z
end.
Definition rooted (s1 s2 : Site) (q : queue Message) :=
reduce Message (rooted_fun s1 s2) q.
Definition sigma_rooted (bm : Bag_of_message) :=
sigma2_table Site LS LS (queue Message) rooted bm.
End ROOTED.
Section ROOTED1.

Lemma rooted_first_out :
forall (s0 s1 s2 : Site) (q : queue Message) (m : Message),
first Message q = value Message m ->
rooted s0 s1 s2 (first_out Message q) =
(rooted s0 s1 s2 q - rooted_fun s0 s1 s2 m)%Z.