Chapter 5 - Truth Value Semantics and Elim Restriction

Require Import Base.

(* Definitions from earlier chapters: *)
Definition XM : Prop := ∀ X : Prop, X ∨ ¬X.
Definition surjective (X Y : Type) (f : X → Y) : Prop := ∀ y, ∃ x, f x = y.

5.1 Truth Value Semantics

Definition TVS : Prop := ∀ X : Prop, X=True ∨ X=False.

Goal TVS → XM.
Proof. intros A X. destruct (A X) as [B|B] ; rewrite B ; auto. Qed.

Definition PI : Prop := ∀ (X : Prop) (A B : X), A=B.

Goal TVS → PI.
Proof.
  intros A X B C. destruct (A X) ; subst X.
  - destruct B, C. reflexivity.
  - contradiction B.
Qed.

Definition PE : Prop := ∀ X Y : Prop, (X ↔ Y) → X=Y.

Goal TVS → PE.
Proof. intros A X Y B. destruct (A X), (A Y) ; subst X Y ; tauto. Qed.

Goal XM → PE → TVS.
Proof.
  intros xm pe X. destruct (xm X) as [A|A].
  - left. apply pe. tauto.
  - right. apply pe. tauto.
Qed.

(* Exercise 5.1.1 *)
Goal TVS ↔ XM ∧ PE.
Abort.

(* Exercise 5.1.2 *)
Goal TVS → PE.
Abort.

5.2 Elim Restriction


Goal ∀ X (f : X → bool), surjective f → ∃ x y : X, x ≠ y.
Proof.
  intros X f A. destruct (A true) as [x B]. destruct (A false) as [y C].
  ∃ x, y. congruence.
Qed.

Inductive bp : Prop := P1 : bp | P2 : bp.

(* This Check produced an "Incorrect elimination" error, because the function violates the elim restriction:
Check fun x : bp => match x with P1 => true | P2 => false end. *)


Lemma Prop_Skolem (X : Type) (Y : Prop) (p : X → Y → Prop) :
  (∀ x, ∃ y, p x y) → ∃ f, ∀ x, p x (f x).
Proof.
 intros A.
 ∃ (fun x ⇒ let (y,_) := A x in y).
 intros x.
 destruct (A x) as [y B].
 exact B.
Qed.

(* Exercise 5.2.1 *)
Goal (∀ X: Type, X = True ∨ X = False) → False.
Abort.

5.3 Propositional Extensionality Entails Proof Irrelevance


Lemma sur_fixpoint X Y (f : X → X → Y) (g : Y → Y) :
  surjective f → ∃ y, g y = y.
Proof.
  intros A.
  pose (h x := g (f x x)).
  destruct (A h) as [x B].
  ∃ (h x). unfold h at 2. rewrite <- B. reflexivity.
Qed.

Goal PE → PI.
Proof.
  intros pe.
  cut (P1=P2).
  { intros A X B C.
    change (B = match P1 with P1 ⇒ C | P2 ⇒ B end).
    rewrite A. reflexivity. }
  pose (neg x := match x with P1 ⇒ P2 | P2 ⇒ P1 end).
  cut (∃ P, neg P = P).
  { unfold neg. intros [[|] C].
    - symmetry. exact C.
    - exact C. }
  cut (∃ f : bp → bp → bp, surjective f).
  { intros [f A]. apply (sur_fixpoint (f:=f)). exact A. }
  cut (bp = (bp → bp)).
  { intros A. rewrite <- A. ∃ (fun x ⇒ x). intros x. ∃ x. reflexivity. }
  apply pe. split ; auto using P1.
Qed.

(* Exercise 5.3.1 *)
Lemma Cantor X :
  ¬ ∃ f : X → X → Prop, surjective f.
Abort.

(* Exercise 5.3.2 *)
Definition iso (X Y : Type) : Prop :=
  ∃ f : X → Y, ∃ g : Y → X, ∀ x y, g (f x) = x ∧ f (g y) = y.

Definition PU : Prop := ∀ X Y : Prop, iso X Y → X = Y.

Goal PE ↔ PU ∧ PI.
Abort.

5.4 A Simpler Proof


Goal PE → PI.
intros D X E F.
assert (C: X=True) by (apply D; tauto).
subst. destruct E, F. reflexivity.
Qed.

(* Exercise 5.4.1 *)
Goal PE → ∀ X:Prop, X → X = True.
Abort.

Goal (∀ X:Prop, X → X = True) → P1 = P2.
Abort.