]> matita.cs.unibo.it Git - helm.git/blob - matita/library/logic/equality.ma
0561fb993cb90045a502a12dcf28a14680f46fdb
[helm.git] / 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_ind':
31  \forall A. \forall x:A. \forall P: \forall y:A. x=y \to Prop.
32   P ? (refl_eq ? x) \to \forall y:A. \forall p:x=y. P y p.
33  intros.
34  exact
35   (match p return \lambda y. \lambda p.P y p with
36     [refl_eq \Rightarrow H]).
37 qed.
38  
39 theorem reflexive_eq : \forall A:Type. reflexive A (eq A).
40 simplify.intros.apply refl_eq.
41 qed.
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 theorem 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 theorem 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 coercion cic:/matita/logic/equality/sym_eq.con.
69 coercion cic:/matita/logic/equality/eq_f.con.
70
71 default "equality"
72  cic:/matita/logic/equality/eq.ind
73  cic:/matita/logic/equality/sym_eq.con
74  cic:/matita/logic/equality/trans_eq.con
75  cic:/matita/logic/equality/eq_ind.con
76  cic:/matita/logic/equality/eq_elim_r.con
77  cic:/matita/logic/equality/eq_f.con
78  cic:/matita/logic/equality/eq_OF_eq.con. (* \x.sym (eq_f x) *)
79  
80 theorem eq_f2: \forall  A,B,C:Type.\forall f:A\to B \to C.
81 \forall x1,x2:A. \forall y1,y2:B.
82 x1=x2 \to y1=y2 \to f x1 y1 = f x2 y2.
83 intros.elim H1.elim H.reflexivity.
84 qed.
85
86 definition comp \def
87  \lambda A.
88   \lambda x,y,y':A.
89    \lambda eq1:x=y.
90     \lambda eq2:x=y'.
91      eq_ind ? ? (\lambda a.a=y') eq2 ? eq1.
92      
93 lemma trans_sym_eq:
94  \forall A.
95   \forall x,y:A.
96    \forall u:x=y.
97     comp ? ? ? ? u u = refl_eq ? y.
98  intros.
99  apply (eq_ind' ? ? ? ? ? u).
100  reflexivity.
101 qed.
102
103 definition nu \def
104  \lambda A.
105   \lambda H: \forall x,y:A. decidable (x=y).
106    \lambda x,y. \lambda p:x=y.
107      match H x y with
108       [ (or_introl p') \Rightarrow p'
109       | (or_intror K) \Rightarrow False_ind ? (K p) ].
110
111 theorem nu_constant:
112  \forall A.
113   \forall H: \forall x,y:A. decidable (x=y).
114    \forall x,y:A.
115     \forall u,v:x=y.
116      nu ? H ? ? u = nu ? H ? ? v.
117  intros.
118  unfold nu.
119  unfold decidable in H.
120  apply (Or_ind' ? ? ? ? ? (H x y)); simplify.
121   intro; reflexivity.
122   intro; elim (q u).
123 qed.
124
125 definition nu_inv \def
126  \lambda A.
127   \lambda H: \forall x,y:A. decidable (x=y).
128    \lambda x,y:A.
129     \lambda v:x=y.
130      comp ? ? ? ? (nu ? H ? ? (refl_eq ? x)) v.
131
132 theorem nu_left_inv:
133  \forall A.
134   \forall H: \forall x,y:A. decidable (x=y).
135    \forall x,y:A.
136     \forall u:x=y.
137      nu_inv ? H ? ? (nu ? H ? ? u) = u.
138  intros.
139  apply (eq_ind' ? ? ? ? ? u).
140  unfold nu_inv.
141  apply trans_sym_eq.
142 qed.
143
144 theorem eq_to_eq_to_eq_p_q:
145  \forall A. \forall x,y:A.
146   (\forall x,y:A. decidable (x=y)) \to
147    \forall p,q:x=y. p=q.
148  intros.
149  rewrite < (nu_left_inv ? H ? ? p).
150  rewrite < (nu_left_inv ? H ? ? q).
151  elim (nu_constant ? H ? ? q).
152  reflexivity.
153 qed.
154
155 (*CSC: alternative proof that does not pollute the environment with
156   technical lemmata. Unfortunately, it is a pain to do without proper
157   support for let-ins.
158 theorem eq_to_eq_to_eq_p_q:
159  \forall A. \forall x,y:A.
160   (\forall x,y:A. decidable (x=y)) \to
161    \forall p,q:x=y. p=q.
162 intros.
163 letin nu \def
164  (\lambda x,y. \lambda p:x=y.
165    match H x y with
166     [ (or_introl p') \Rightarrow p'
167     | (or_intror K) \Rightarrow False_ind ? (K p) ]).
168 cut
169  (\forall q:x=y.
170    eq_ind ? ? (\lambda z. z=y) (nu ? ? q) ? (nu ? ? (refl_eq ? x))
171    = q).
172 focus 8.
173  clear q; clear p.
174  intro.
175  apply (eq_ind' ? ? ? ? ? q);
176  fold simplify (nu ? ? (refl_eq ? x)).
177  generalize in match (nu ? ? (refl_eq ? x)); intro.
178  apply
179   (eq_ind' A x
180    (\lambda y. \lambda u.
181     eq_ind A x (\lambda a.a=y) u y u = refl_eq ? y)
182    ? x H1).
183  reflexivity.
184 unfocus.
185 rewrite < (Hcut p); fold simplify (nu ? ? p).
186 rewrite < (Hcut q); fold simplify (nu ? ? q).
187 apply (Or_ind' (x=x) (x \neq x)
188  (\lambda p:decidable (x=x). eq_ind A x (\lambda z.z=y) (nu x y p) x
189    ([\lambda H1.eq A x x]
190     match p with
191     [(or_introl p') \Rightarrow p'
192     |(or_intror K) \Rightarrow False_ind (x=x) (K (refl_eq A x))]) =
193    eq_ind A x (\lambda z.z=y) (nu x y q) x
194     ([\lambda H1.eq A x x]
195      match p with
196     [(or_introl p') \Rightarrow p'
197     |(or_intror K) \Rightarrow False_ind (x=x) (K (refl_eq A x))]))
198  ? ? (H x x)).
199 intro; simplify; reflexivity.
200 intro q; elim (q (refl_eq ? x)).
201 qed.
202 *)
203
204 (*
205 theorem a:\forall x.x=x\land True.
206
207 2:intros;
208   split;
209   [
210     exact (refl_eq Prop x);
211   |
212     exact I;
213   ]
214 1:
215   skip
216 ]
217 qed.
218 *)
219