(* 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                                                     *)
(** Let (X, A, a) be a pointed graph.  The powerset of the set represented by this pointed graph is itself represented by the pointed graph  ((sum X X->Prop), (POWER X A a), (out X X->Prop))  whose edge relation (POWER X A a) : (Rel (sum X X->Prop)) is defined by the following 3 clauses:  1. Delocating A into the powerset:  if (A x' x), then (POWER X A a (inl X X->Prop x') (inl X X->Prop x))  2. Connecting each vertex x':X such that (A x' a) to all the predicates p : X->Prop such that (p x'):  if (A x' a) and (p x'), then (POWER X A a (inl X X->Prop x') (inr X X->Prop p))  3. Connecting all the predicates p : X->Prop to the new root:  (POWER X A a (inr X X->Prop p) (out X X->Prop)).  This relation is impredicatively encoded as follows: *)
Definition POWER (X : Typ1) (A : Rel X) (a : X) (z' z : sum X (X -> Prop)) :=
forall E : Prop,
(forall x x' : X,
eq (sum X (X -> Prop)) z' (inl X (X -> Prop) x') ->
eq (sum X (X -> Prop)) z (inl X (X -> Prop) x) -> A x' x -> E) ->
(forall (x' : X) (p : X -> Prop),
eq (sum X (X -> Prop)) z' (inl X (X -> Prop) x') ->
eq (sum X (X -> Prop)) z (inr X (X -> Prop) p) -> A x' a -> p x' -> E) ->
(forall p : X -> Prop,
eq (sum X (X -> Prop)) z' (inr X (X -> Prop) p) ->
eq (sum X (X -> Prop)) z (out X (X -> Prop)) -> E) -> E.
(** Introduction rules corresponding to the clauses: *)
Proof
fun X A a x x' H E e _ _ =>
e x x' (eq_refl (sum X (X -> Prop)) (inl X (X -> Prop) x'))
(eq_refl (sum X (X -> Prop)) (inl X (X -> Prop) x)) H.
Proof
fun X A a x' p H1 H2 E _ e _ =>
e x' p (eq_refl (sum X (X -> Prop)) (inl X (X -> Prop) x'))
(eq_refl (sum X (X -> Prop)) (inr X (X -> Prop) p)) H1 H2.
Proof
fun X A a p E _ _ e =>
e p (eq_refl (sum X (X -> Prop)) (inr X (X -> Prop) p))
(eq_refl (sum X (X -> Prop)) (out X (X -> Prop))).
(** We now prove that the left injection (inl X X->Prop) is a delocation from (X, A) to ((sum X X->Prop), (POWER X A a)), and deduce the expected property of bisimilarity. *)
(** Moreover, any subset of (X, A, a) is bisimilar to a pointed graph of the form ((sum X X->Prop), (POWER X A a), (inr X X->Prop) p) for a suitable predicate p : X->Prop. *)
(** From this, we deduce the introduction rule of the powerset: *)
(** And the elimination rule comes easily: *)

Lemma powerset_elim :
forall (X : Typ1) (A : Rel X) (a : X) (Y : Typ1) (B : Rel Y) (b : Y),
ELT Y B b (sum X (X -> Prop)) (POWER X A a) (out X (X -> Prop)) ->
SUB Y B b X A a.