Section INVARIANT4.
Definition new_inc_count (m : Message) :=
match m with
| inc_dec s => 1%Z
| _ => 0%Z
end.
(* Below five remarks aux1, aux2, aux3, aux4, aux5 ... followed by the real meat the invariant 4. *)
Remark aux1 :
forall c : Config,
legal c ->
st c owner =
(sigma_receive_table (rt c) + sigma_weight (bm c) -
sigma_table_but_owner Z (fun (_ : Site) (x : Z) => x) (st c))%Z.
Remark aux2 :
forall c : Config,
legal c ->
sigma_table_but_owner Z (fun (_ : Site) (x : Z) => x) (st c) =
sigma_but Site owner eq_site_dec LS (fun s : Site => sigma_rooted s (bm c)).
Remark aux3 :
forall (s1 s2 : Site) (q : queue Message),
(cardinal q -
sigma_but Site owner eq_site_dec LS (fun s : Site => rooted s s1 s2 q))%Z =
reduce Message
(fun a : Message =>
(cardinal_count a -
sigma_but Site owner eq_site_dec LS
(fun s : Site => rooted_fun s s1 s2 a))%Z) q.
Remark aux4 :
forall t : Site -> Site -> queue Message,
sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) =>
(cardinal q -
sigma_but Site owner eq_site_dec LS (fun s : Site => rooted s s1 s2 q))%Z)
t =
sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) =>
reduce Message
(fun a : Message =>
(cardinal_count a -
sigma_but Site owner eq_site_dec LS
(fun s : Site => rooted_fun s s1 s2 a))%Z) q) t.
Remark aux5 :
forall c : Config,
legal c ->
sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) =>
reduce Message
(fun a : Message =>
(cardinal_count a -
sigma_but Site owner eq_site_dec LS
(fun s : Site => rooted_fun s s1 s2 a))%Z) q)
(bm c) =
(sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) =>
if eq_site_dec s2 owner
then reduce Message dec_count q
else 0) (bm c) +
sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) =>
if eq_site_dec s1 owner
then reduce Message copy_count q
else 0) (bm c) -
sigma2_table Site LS LS (queue Message)
(fun (s1 s2 : Site) (q : queue Message) => reduce Message new_inc_count q)
(bm c))%Z.
Remark add_reduce :
forall x y a u w z : Z,
(y - a)%Z = (z + w - u)%Z -> (x + y - a)%Z = (x + z + w - u)%Z.

Lemma invariant4 :
forall c : Config,
legal c ->
st c owner =
(sigma_receive_table (rt c) +
sigma_table Site LS Z (Z_id Site)
(fun s1 : Site => reduce Message dec_count (bm c s1 owner)) +
sigma_table Site LS Z (Z_id Site)
(fun s2 : Site => reduce Message copy_count (bm c owner s2)) -
sigma_table Site LS Z (Z_id Site)
(fun s1 : Site => reduce Message new_inc_count (bm c s1 owner)))%Z.