aboutsummaryrefslogtreecommitdiff
path: root/theories/Logic/ExtensionalityFacts.v
blob: 631177bebb9da28bfcdc9b55d74abf25aa4aad95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, *   INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010     *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(** Some facts and definitions about extensionality

We investigate the relations between the following extensionality principles

- Functional extensionality
- Equality of projections from diagonal
- Unicity of inverse bijections
- Bijectivity of bijective composition

Table of contents

1. Definitions

2. Functional extensionality <-> Equality of projections from diagonal

3. Functional extensionality <-> Unicity of inverse bijections

4. Functional extensionality <-> Bijectivity of bijective composition

*)

Set Implicit Arguments.

(**********************************************************************)
(** * Definitions *)

(** Being an inverse *)

Definition is_inverse A B f g := (forall a:A, g (f a) = a) /\ (forall b:B, f (g b) = b).

Definition iscontr (X:Type) := {x:X| forall y, x=y}.
Definition hfiber X Y (f:X -> Y) (y:Y) := {x:X| f x=y}.                                    
Definition isweq X Y (f:X -> Y) := forall y, iscontr (hfiber f y).                                                          

Goal forall X Y (f:X->Y), isweq f -> {g|is_inverse f g}.
Proof.
  intros * Hweq.
  set (g:=fun y => proj1_sig (proj1_sig (Hweq y))).
  exists g. split.
  - intro x. unfold g. destruct (Hweq (f x)) as ((x0,Hx0),Hxy). simpl.
    set (fiber0 := exist (fun x0 => f x0 = f x) x0 Hx0) in *. 
    set (fiber := exist (fun x0 => f x0 = f x) x eq_refl). 
    change (proj1_sig fiber0 = proj1_sig fiber).
    specialize Hxy with fiber.
    destruct Hxy.
    reflexivity.
  - intro y.
    unfold g.
    destruct (Hweq y) as ((x,Hxy),Hyuniq). simpl. assumption.
Qed.

Goal forall X Y (f:X->Y), {g|is_inverse f g} -> isweq f.
Proof.
  destruct 1 as (g,(Hgf,Hfg)).
  intro y.
  set (fiber := exist (fun x => f x = y) (g y) (Hfg y)).
  exists fiber.
  destruct y0 as (y0,Hfy0).
  unfold fiber.
  rewrite <- Hfy0 in *.
  assert (forall y, f_equal f (Hgf y) = Hfg (f y)). admit.
  rewrite <- H.
  rewrite Hgf.
  reflexivity.
Qed.

(** The diagonal over A and the one-one correspondence with A *)

Record Delta A := { pi1:A; pi2:A; eq:pi1=pi2 }.

Definition delta {A} (a:A) := {|pi1 := a; pi2 := a; eq := eq_refl a |}.

Implicit Arguments pi1 [[A]].
Implicit Arguments pi2 [[A]].

Lemma diagonal_projs_same_behavior : forall A (x:Delta A), pi1 x = pi2 x.
Proof.
  destruct x as (a1,a2,Heq); assumption.
Qed.

Lemma diagonal_inverse1 : forall A, is_inverse (A:=A) delta pi1.
Proof.
  split; [trivial|]; destruct b as (a1,a2,[]); reflexivity.
Qed.

Lemma diagonal_inverse2 : forall A, is_inverse (A:=A) delta pi2.
Proof.
  split; [trivial|]; destruct b as (a1,a2,[]); reflexivity.
Qed.

(** Functional extensionality *)

Local Notation FunctionalExtensionality := 
  (forall A B (f g : A -> B), (forall x, f x = g x) -> f = g).

(** Equality of projections from diagonal *)

Local Notation EqDeltaProjs := (forall A, pi1 = pi2 :> (Delta A -> A)).

(** Unicity of bijection inverse *)

Local Notation UniqueInverse := (forall A B (f:A->B) g1 g2, is_inverse f g1 -> is_inverse f g2 -> g1 = g2).

(** Bijectivity of bijective composition *)

Definition action A B C (f:A->B) := (fun h:B->C => fun x => h (f x)).

Local Notation BijectivityBijectiveComp := (forall A B C (f:A->B) g,
  is_inverse f g -> is_inverse (A:=B->C) (action f) (action g)).

(**********************************************************************)
(** * Functional extensionality <-> Equality of projections from diagonal *)

Theorem FunctExt_iff_EqDeltaProjs : FunctionalExtensionality <-> EqDeltaProjs.
Proof.
  split.
  - intros FunExt *; apply FunExt, diagonal_projs_same_behavior. 
  - intros EqProjs **; change f with (fun x => pi1 {|pi1:=f x; pi2:=g x; eq:=H x|}).
    rewrite EqProjs; reflexivity.
Qed.

(**********************************************************************)
(** * Functional extensionality <-> Unicity of bijection inverse *)

Lemma FunctExt_UniqInverse : FunctionalExtensionality -> UniqueInverse.
Proof.
  intros FunExt * (Hg1f,Hfg1) (Hg2f,Hfg2).
  apply FunExt. intros; congruence.
Qed.

Lemma UniqInverse_EqDeltaProjs : UniqueInverse -> EqDeltaProjs.
Proof.
  intros UniqInv *.
  apply UniqInv with delta; [apply diagonal_inverse1 | apply diagonal_inverse2].
Qed.

Theorem FunctExt_iff_UniqInverse : FunctionalExtensionality <-> UniqueInverse.
Proof.
  split. 
  - apply FunctExt_UniqInverse.
  - intro; apply FunctExt_iff_EqDeltaProjs, UniqInverse_EqDeltaProjs; trivial.
Qed.

(**********************************************************************)
(** * Functional extensionality <-> Bijectivity of bijective composition *)

Lemma FunctExt_BijComp : FunctionalExtensionality -> BijectivityBijectiveComp.
Proof.
  intros FunExt * (Hgf,Hfg). split; unfold action.
  - intros h; apply FunExt; intro b; rewrite Hfg; reflexivity.
  - intros h; apply FunExt; intro a; rewrite Hgf; reflexivity.
Qed.

Lemma BijComp_FunctExt : BijectivityBijectiveComp -> FunctionalExtensionality.
Proof.
  intros BijComp.
  apply FunctExt_iff_UniqInverse. intros * H1 H2.
  destruct BijComp with (C:=A) (1:=H2) as (Hg2f,_).
  destruct BijComp with (C:=A) (1:=H1) as (_,Hfg1).
  rewrite <- (Hg2f g1).
  change g1 with (action g1 (fun x => x)).
  rewrite -> (Hfg1 (fun x => x)).
  reflexivity.
Qed.