(* 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                                                     *)
(** Sets as pointed graphs ~~~~~~~~~~~~~~~~~~~~~~ In the following, we will interpret sets as pointed graphs, that is, as triples of the form (X, A, a) where :  - X : Typ1     is the carrier (i.e. the small type of vertices); - A : (Rel X)  is the edge (or local membership) relation; - a : X        is the root.  Naming conventions ~~~~~~~~~~~~~~~~~~ Since the PTS Fw.2 does not provide any pairing mechanism, we will introduce the three components of each pointed graph separately. Of course, this separation is error-prone, and to avoid confusions we will name components according to the following scheme:  Pointed graph   Vertices -------------   -------- (X, A, a)       x, x', x0, x1, etc. (Y, B, b)       y, y', y0, y1, etc. (Z, C, c)       z, z', z0, z1, etc. etc.  Moreover, a letter affected with a prime (such as x') will usually indicate that the vertex (or carrier, or relation) it denotes is in some sense an element of the corresponding unaffected letter. *)
(********************************)
(** * Equality as bisimilarity  *)
(********************************)
(** Two pointed graphs (X, A, a) and (Y, B, b) are bisimilar if there exists a relation R:X->Y->Prop satisfying the following conditions:  (BIS1) (x,x':X; y:Y) (A x' x)/\(R x y) -> (Ex y':Y | (B y' y)/\(R x' y'))  (BIS2) (x,x':X; y:Y) (A x' x)/\(R x y) -> (Ex y':Y | (B y' y)/\(R x' y'))  (BIS3) (R a b)  Instead of defining this relation by the mean of standard logical connectives, we give an equivalent impredicative encoding for it in order to make the forthcoming proofs a little bit shorter. *)
Definition EQV (X : Typ1) (A : Rel X) (a : X) (Y : Typ1)
(B : Rel Y) (b : Y) : Prop :=
forall E : Prop,
(forall R : X -> Y -> Prop,
(forall (x x' : X) (y : Y),
A x' x -> R x y -> ex2 Y (fun y' => B y' y) (fun y' => R x' y')) ->
(forall (y y' : Y) (x : X),
B y' y -> R x y -> ex2 X (fun x' => A x' x) (fun x' => R x' y')) ->
R a b -> E) -> E.
(** Here is the corresponding introduction rule: *)
Proof fun X A a Y B b R H1 H2 H3 E e => e R H1 H2 H3.
(** It would be useless to define the corresponding elimination rule whose behaviour is obtained by using [Apply H] instead of [Elim H] in the following proof scripts.  We first check that bisimilarity is an equivalence relation: *)
(** The following lemma states that the bisimilarity relation can be shifted one vertex down by following the edges of both local membership relations. *)

Lemma EQV_shift :
forall (X : Typ1) (A : Rel X) (a : X) (Y : Typ1) (B : Rel Y) (b : Y),
EQV X A a Y B b ->
forall a' : X,
A a' a -> ex2 Y (fun b' => B b' b) (fun b' => EQV X A a' Y B b').