(* 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                                                     *)
(*****************)
(** * Universes  *)
(*****************)
(** In what follows, we will work with explicit universes rather than with Coq-style implicit universes.  For that, we define two universes Typ1 and Typ2 as shorthands for the generic universe Type by enforcing the constraint Typ1 : Typ2 so that Coq knows that the implicit index associated to Typ1 is smaller than the implicit index associated to Typ2. *)
Definition Typ2 := Type.
Definition Typ1 : Typ2 := Type. (* enforce Typ1 : Typ2 *)
(** Intuitively:  - Typ1 is the universe of small types, which contains the type Prop of propositions, and is closed under dependent product.  - Typ2 is the top-universe of large types, which contains the universe Typ1, and is closed under dependent product again.  In the following, small types (i.e. the inhabitants of Typ1) will be used as the carriers of pointed graphs (for representing sets). *)
(** The type of binary relations: *)
Definition Rel (X : Typ1) : Typ1 := X -> X -> Prop.
(***************************)
(** * Logical connectives  *)
(***************************)
(** To avoid the use of Coq-style inductive definitions, we redefine all the logical connectives from their second-order encoding and give their introduction rules.  Except in a few cases, it is not necessary to give the corresponding elimination rules whose behaviour is mimicked by using the tactic [Apply H] (instead of [Elim H]) in the subsequent proof-scripts. *)
(** ** Truth and falsity **)
Definition top : Prop := forall E : Prop, E -> E.
Proof fun E e => e.
Definition bot : Prop := forall E : Prop, E.
(** ** Conjunction **)
Definition and (A B : Prop) : Prop := forall E : Prop, (A -> B -> E) -> E.
Proof fun A B a b E f => f a b.
Proof fun A B p => p A (fun a _ => a).
Proof fun A B p => p B (fun _ b => b).
(** ** Disjunction **)
Definition or (A B : Prop) : Prop :=
forall E : Prop, (A -> E) -> (B -> E) -> E.
Proof fun A B a E f g => f a.
Proof fun A B b E f g => g b.
(** ** Logical equivalence **)
Definition iff (A B : Prop) : Prop := and (A -> B) (B -> A).
(****************************************************)
(** * Existential quantifiers and Leibniz equality  *)
(****************************************************)
(** ** Existential quantification in a given small type **)
Definition ex (X : Typ1) (P : X -> Prop) : Prop :=
forall E : Prop, (forall x : X, P x -> E) -> E.

Lemma ex_intro : forall (X : Typ1) (P : X -> Prop) (x : X), P x -> ex X P.