]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/logic/equality.ma
510f0c5c6fe3144b395840770c1f8dbe15084163
[helm.git] / helm / software / matita / library / logic / equality.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 set "baseuri" "cic:/matita/logic/equality/".
16
17 include "higher_order_defs/relations.ma".
18
19 inductive eq (A:Type) (x:A) : A \to Prop \def
20     refl_eq : eq A x x.
21
22 (*CSC: the URI must disappear: there is a bug now *)
23 interpretation "leibnitz's equality"
24    'eq x y = (cic:/matita/logic/equality/eq.ind#xpointer(1/1) _ x y).
25 (*CSC: the URI must disappear: there is a bug now *)
26 interpretation "leibnitz's non-equality"
27   'neq x y = (cic:/matita/logic/connectives/Not.con
28     (cic:/matita/logic/equality/eq.ind#xpointer(1/1) _ x y)).
29
30 theorem eq_rect':
31  \forall A. \forall x:A. \forall P: \forall y:A. x=y \to Type.
32   P ? (refl_eq ? x) \to \forall y:A. \forall p:x=y. P y p.
33  intros.
34  exact
35   (match p1 return \lambda y. \lambda p.P y p with
36     [refl_eq \Rightarrow p]).
37 qed.
38  
39 variant reflexive_eq : \forall A:Type. reflexive A (eq A)
40 \def refl_eq.
41 (* simplify.intros.apply refl_eq. *)
42     
43 theorem symmetric_eq: \forall A:Type. symmetric A (eq A).
44 unfold symmetric.intros.elim H. apply refl_eq.
45 qed.
46
47 variant sym_eq : \forall A:Type.\forall x,y:A. x=y  \to y=x
48 \def symmetric_eq.
49
50 theorem transitive_eq : \forall A:Type. transitive A (eq A).
51 unfold transitive.intros.elim H1.assumption.
52 qed.
53
54 variant trans_eq : \forall A:Type.\forall x,y,z:A. x=y  \to y=z \to x=z
55 \def transitive_eq.
56
57 theorem eq_elim_r:
58  \forall A:Type.\forall x:A. \forall P: A \to Prop.
59    P x \to \forall y:A. y=x \to P y.
60 intros. elim (sym_eq ? ? ? H1).assumption.
61 qed.
62
63 theorem eq_f: \forall  A,B:Type.\forall f:A\to B.
64 \forall x,y:A. x=y \to f x = f y.
65 intros.elim H.apply refl_eq.
66 qed.
67
68 theorem eq_f': \forall  A,B:Type.\forall f:A\to B.
69 \forall x,y:A. x=y \to f y = f x.
70 intros.elim H.apply refl_eq.
71 qed.
72
73 (*  *)
74 coercion cic:/matita/logic/equality/sym_eq.con.
75 coercion cic:/matita/logic/equality/eq_f.con.
76 (* *)
77
78 default "equality"
79  cic:/matita/logic/equality/eq.ind
80  cic:/matita/logic/equality/sym_eq.con
81  cic:/matita/logic/equality/transitive_eq.con
82  cic:/matita/logic/equality/eq_ind.con
83  cic:/matita/logic/equality/eq_elim_r.con
84  cic:/matita/logic/equality/eq_f.con
85 (* *)
86  cic:/matita/logic/equality/eq_OF_eq.con.
87 (* *)
88 (*  
89  cic:/matita/logic/equality/eq_f'.con. (* \x.sym (eq_f x) *)
90  *)
91  
92 theorem eq_f2: \forall  A,B,C:Type.\forall f:A\to B \to C.
93 \forall x1,x2:A. \forall y1,y2:B.
94 x1=x2 \to y1=y2 \to f x1 y1 = f x2 y2.
95 intros.elim H1.elim H.reflexivity.
96 qed.
97
98 definition comp \def
99  \lambda A.
100   \lambda x,y,y':A.
101    \lambda eq1:x=y.
102     \lambda eq2:x=y'.
103      eq_ind ? ? (\lambda a.a=y') eq2 ? eq1.
104      
105 lemma trans_sym_eq:
106  \forall A.
107   \forall x,y:A.
108    \forall u:x=y.
109     comp ? ? ? ? u u = refl_eq ? y.
110  intros.
111  apply (eq_rect' ? ? ? ? ? u).
112  reflexivity.
113 qed.
114
115 definition nu \def
116  \lambda A.
117   \lambda H: \forall x,y:A. decidable (x=y).
118    \lambda x,y. \lambda p:x=y.
119      match H x y with
120       [ (or_introl p') \Rightarrow p'
121       | (or_intror K) \Rightarrow False_ind ? (K p) ].
122
123 theorem nu_constant:
124  \forall A.
125   \forall H: \forall x,y:A. decidable (x=y).
126    \forall x,y:A.
127     \forall u,v:x=y.
128      nu ? H ? ? u = nu ? H ? ? v.
129  intros.
130  unfold nu.
131  unfold decidable in H.
132  apply (Or_ind' ? ? ? ? ? (H x y)); simplify.
133   intro; reflexivity.
134   intro; elim (q u).
135 qed.
136
137 definition nu_inv \def
138  \lambda A.
139   \lambda H: \forall x,y:A. decidable (x=y).
140    \lambda x,y:A.
141     \lambda v:x=y.
142      comp ? ? ? ? (nu ? H ? ? (refl_eq ? x)) v.
143
144 theorem nu_left_inv:
145  \forall A.
146   \forall H: \forall x,y:A. decidable (x=y).
147    \forall x,y:A.
148     \forall u:x=y.
149      nu_inv ? H ? ? (nu ? H ? ? u) = u.
150  intros.
151  apply (eq_rect' ? ? ? ? ? u).
152  unfold nu_inv.
153  apply trans_sym_eq.
154 qed.
155
156 theorem eq_to_eq_to_eq_p_q:
157  \forall A. \forall x,y:A.
158   (\forall x,y:A. decidable (x=y)) \to
159    \forall p,q:x=y. p=q.
160  intros.
161  rewrite < (nu_left_inv ? H ? ? p).
162  rewrite < (nu_left_inv ? H ? ? q).
163  elim (nu_constant ? H ? ? q).
164  reflexivity.
165 qed.
166
167 (*CSC: alternative proof that does not pollute the environment with
168   technical lemmata. Unfortunately, it is a pain to do without proper
169   support for let-ins.
170 theorem eq_to_eq_to_eq_p_q:
171  \forall A. \forall x,y:A.
172   (\forall x,y:A. decidable (x=y)) \to
173    \forall p,q:x=y. p=q.
174 intros.
175 letin nu \def
176  (\lambda x,y. \lambda p:x=y.
177    match H x y with
178     [ (or_introl p') \Rightarrow p'
179     | (or_intror K) \Rightarrow False_ind ? (K p) ]).
180 cut
181  (\forall q:x=y.
182    eq_ind ? ? (\lambda z. z=y) (nu ? ? q) ? (nu ? ? (refl_eq ? x))
183    = q).
184 focus 8.
185  clear q; clear p.
186  intro.
187  apply (eq_rect' ? ? ? ? ? q);
188  fold simplify (nu ? ? (refl_eq ? x)).
189  generalize in match (nu ? ? (refl_eq ? x)); intro.
190  apply
191   (eq_rect' A x
192    (\lambda y. \lambda u.
193     eq_ind A x (\lambda a.a=y) u y u = refl_eq ? y)
194    ? x H1).
195  reflexivity.
196 unfocus.
197 rewrite < (Hcut p); fold simplify (nu ? ? p).
198 rewrite < (Hcut q); fold simplify (nu ? ? q).
199 apply (Or_ind' (x=x) (x \neq x)
200  (\lambda p:decidable (x=x). eq_ind A x (\lambda z.z=y) (nu x y p) x
201    ([\lambda H1.eq A x x]
202     match p with
203     [(or_introl p') \Rightarrow p'
204     |(or_intror K) \Rightarrow False_ind (x=x) (K (refl_eq A x))]) =
205    eq_ind A x (\lambda z.z=y) (nu x y q) x
206     ([\lambda H1.eq A x x]
207      match p with
208     [(or_introl p') \Rightarrow p'
209     |(or_intror K) \Rightarrow False_ind (x=x) (K (refl_eq A x))]))
210  ? ? (H x x)).
211 intro; simplify; reflexivity.
212 intro q; elim (q (refl_eq ? x)).
213 qed.
214 *)
215
216 (*
217 theorem a:\forall x.x=x\land True.
218
219 2:intros;
220   split;
221   [
222     exact (refl_eq Prop x);
223   |
224     exact I;
225   ]
226 1:
227   skip
228 ]
229 qed.
230 *)
231