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