(** 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.

Lemma EQV_refl : forall (X : Typ1) (A : Rel X) (a : X), EQV X A a X A a.