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