]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/algebra/groups.ma
Closer to the proof of the pigeonhole principle... that is already in the
[helm.git] / helm / matita / library / algebra / groups.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 set "baseuri" "cic:/matita/algebra/groups/".
16
17 include "algebra/monoids.ma".
18 include "nat/le_arith.ma".
19 include "datatypes/bool.ma".
20 include "nat/compare.ma".
21
22 record PreGroup : Type ≝
23  { premonoid:> PreMonoid;
24    opp: premonoid -> premonoid
25  }.
26
27 record isGroup (G:PreGroup) : Prop ≝
28  { is_monoid: isMonoid G;
29    opp_is_left_inverse: is_left_inverse (mk_Monoid ? is_monoid) (opp G);
30    opp_is_right_inverse: is_right_inverse (mk_Monoid ? is_monoid) (opp G)
31  }.
32  
33 record Group : Type ≝
34  { pregroup:> PreGroup;
35    group_properties:> isGroup pregroup
36  }.
37
38 (*notation < "G"
39 for @{ 'monoid $G }.
40
41 interpretation "Monoid coercion" 'monoid G =
42  (cic:/matita/algebra/groups/monoid.con G).*)
43
44 notation < "G"
45 for @{ 'type_of_group $G }.
46
47 interpretation "Type_of_group coercion" 'type_of_group G =
48  (cic:/matita/algebra/groups/Type_of_Group.con G).
49
50 notation < "G"
51 for @{ 'magma_of_group $G }.
52
53 interpretation "magma_of_group coercion" 'magma_of_group G =
54  (cic:/matita/algebra/groups/Magma_of_Group.con G).
55
56 notation "hvbox(x \sup (-1))" with precedence 89
57 for @{ 'gopp $x }.
58
59 interpretation "Group inverse" 'gopp x =
60  (cic:/matita/algebra/groups/opp.con _ x).
61
62 definition left_cancellable ≝
63  λT:Type. λop: T -> T -> T.
64   ∀x. injective ? ? (op x).
65   
66 definition right_cancellable ≝
67  λT:Type. λop: T -> T -> T.
68   ∀x. injective ? ? (λz.op z x).
69   
70 theorem eq_op_x_y_op_x_z_to_eq:
71  ∀G:Group. left_cancellable G (op G).
72 intros;
73 unfold left_cancellable;
74 unfold injective;
75 intros (x y z);
76 rewrite < (e_is_left_unit ? (is_monoid ? (group_properties G)));
77 rewrite < (e_is_left_unit ? (is_monoid ? (group_properties G)) z);
78 rewrite < (opp_is_left_inverse ? (group_properties G) x);
79 rewrite > (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
80 rewrite > (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
81 apply eq_f;
82 assumption.
83 qed.
84
85
86 theorem eq_op_x_y_op_z_y_to_eq:
87  ∀G:Group. right_cancellable G (op G).
88 intros;
89 unfold right_cancellable;
90 unfold injective;
91 simplify;fold simplify (op G); 
92 intros (x y z);
93 rewrite < (e_is_right_unit ? (is_monoid ? (group_properties G)));
94 rewrite < (e_is_right_unit ? (is_monoid ? (group_properties G)) z);
95 rewrite < (opp_is_right_inverse ? (group_properties G) x);
96 rewrite < (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
97 rewrite < (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
98 rewrite > H;
99 reflexivity.
100 qed.
101
102
103 record finite_enumerable (T:Type) : Type ≝
104  { order: nat;
105    repr: nat → T;
106    index_of: T → nat;
107    index_of_sur: ∀x.index_of x ≤ order;
108    index_of_repr: ∀n. n≤order → index_of (repr n) = n;
109    repr_index_of: ∀x. repr (index_of x) = x
110  }.
111  
112 notation "hvbox(C \sub i)" with precedence 89
113 for @{ 'repr $C $i }.
114
115 (* CSC: multiple interpretations in the same file are not considered in the
116  right order
117 interpretation "Finite_enumerable representation" 'repr C i =
118  (cic:/matita/algebra/groups/repr.con C _ i).*)
119  
120 notation < "hvbox(|C|)" with precedence 89
121 for @{ 'card $C }.
122
123 interpretation "Finite_enumerable order" 'card C =
124  (cic:/matita/algebra/groups/order.con C _).
125
126 record finite_enumerable_SemiGroup : Type ≝
127  { semigroup:> SemiGroup;
128    is_finite_enumerable:> finite_enumerable semigroup
129  }.
130
131 notation < "S"
132 for @{ 'semigroup_of_finite_enumerable_semigroup $S }.
133
134 interpretation "Semigroup_of_finite_enumerable_semigroup"
135  'semigroup_of_finite_enumerable_semigroup S
136 =
137  (cic:/matita/algebra/groups/semigroup.con S).
138
139 notation < "S"
140 for @{ 'magma_of_finite_enumerable_semigroup $S }.
141
142 interpretation "Magma_of_finite_enumerable_semigroup"
143  'magma_of_finite_enumerable_semigroup S
144 =
145  (cic:/matita/algebra/groups/Magma_of_finite_enumerable_SemiGroup.con S).
146  
147 notation < "S"
148 for @{ 'type_of_finite_enumerable_semigroup $S }.
149
150 interpretation "Type_of_finite_enumerable_semigroup"
151  'type_of_finite_enumerable_semigroup S
152 =
153  (cic:/matita/algebra/groups/Type_of_finite_enumerable_SemiGroup.con S).
154
155 interpretation "Finite_enumerable representation" 'repr S i =
156  (cic:/matita/algebra/groups/repr.con S
157   (cic:/matita/algebra/groups/is_finite_enumerable.con S) i).
158
159 notation "hvbox(ι e)" with precedence 60
160 for @{ 'index_of_finite_enumerable_semigroup $e }.
161
162 interpretation "Index_of_finite_enumerable representation"
163  'index_of_finite_enumerable_semigroup e
164 =
165  (cic:/matita/algebra/groups/index_of.con _
166   (cic:/matita/algebra/groups/is_finite_enumerable.con _) e).
167
168
169 (* several definitions/theorems to be moved somewhere else *)
170
171 definition ltb ≝ λn,m. leb n m ∧ notb (eqb n m).
172
173 theorem not_eq_to_le_to_lt: ∀n,m. n≠m → n≤m → n<m.
174 intros;
175 elim (le_to_or_lt_eq ? ? H1);
176 [ assumption
177 | elim (H H2)
178 ].
179 qed.
180
181 theorem ltb_to_Prop :
182  ∀n,m.
183   match ltb n m with
184   [ true ⇒ n < m
185   | false ⇒ n ≮ m
186   ].
187 intros;
188 unfold ltb;
189 apply leb_elim;
190 apply eqb_elim;
191 intros;
192 simplify;
193 [ rewrite < H;
194   apply le_to_not_lt;
195   constructor 1
196 | apply (not_eq_to_le_to_lt ? ? H H1)
197 | rewrite < H;
198   apply le_to_not_lt;
199   constructor 1
200 | apply le_to_not_lt;
201   generalize in match (not_le_to_lt ? ? H1);
202   clear H1;
203   intro;
204   apply lt_to_le;
205   assumption
206 ].
207 qed.
208
209 theorem ltb_elim: \forall n,m:nat. \forall P:bool \to Prop.
210 (n < m \to (P true)) \to (n ≮ m \to (P false)) \to
211 P (ltb n m).
212 intros.
213 cut
214 (match (ltb n m) with
215 [ true  \Rightarrow n < m
216 | false \Rightarrow n ≮ m] \to (P (ltb n m))).
217 apply Hcut.apply ltb_to_Prop.
218 elim (ltb n m).
219 apply ((H H2)).
220 apply ((H1 H2)).
221 qed.
222
223 theorem Not_lt_n_n: ∀n. n ≮ n.
224 intro;
225 unfold Not;
226 intro;
227 unfold lt in H;
228 apply (not_le_Sn_n ? H).
229 qed.
230
231 theorem eq_pred_to_eq:
232  ∀n,m. O < n → O < m → pred n = pred m → n = m.
233 intros 2;
234 elim n;
235 [ elim (Not_lt_n_n ? H)
236 | generalize in match H3;
237   clear H3;
238   generalize in match H2;
239   clear H2;
240   elim m;
241   [ elim (Not_lt_n_n ? H2)
242   | simplify in H4;
243     apply (eq_f ? ? S);
244     assumption
245   ]
246 ].
247 qed.
248
249 theorem le_pred_to_le:
250  ∀n,m. O < m → pred n ≤ pred m \to n ≤ m.
251 intros 2;
252 elim n;
253 [ apply le_O_n
254 | simplify in H2;
255   rewrite > (S_pred m);
256   [ apply le_S_S;
257     assumption
258   | assumption
259   ]
260 ].
261 qed.
262
263 theorem le_to_le_pred:
264  ∀n,m. n ≤ m → pred n ≤ pred m.
265 intros 2;
266 elim n;
267 [ simplify;
268   apply le_O_n
269 | simplify;
270   generalize in match H1;
271   clear H1;
272   elim m;
273   [ elim (not_le_Sn_O ? H1)
274   | simplify;
275     apply le_S_S_to_le;
276     assumption
277   ]
278 ].
279 qed.
280
281
282 theorem pigeonhole:
283  ∀n:nat.∀f:nat→nat.
284   (∀x,y.x≤n → y≤n → f x = f y → x=y) →
285   (∀m. m ≤ n → f m ≤ n) →
286    ∀x. x≤n \to ∃y.f y = x ∧ y ≤ n.
287 intro;
288 elim n;
289 [ apply (ex_intro ? ? O);
290   split;
291   [ rewrite < (le_n_O_to_eq ? H2);
292     rewrite < (le_n_O_to_eq ? (H1 O ?));
293     [ reflexivity
294     | apply le_n
295     ]
296   | apply le_n
297   ]
298 | clear n;
299   apply (nat_compare_elim (f (S n1)) x);
300   [ (* TODO: caso complicato, ma simile al terzo *) 
301   | intros;
302     apply (ex_intro ? ? (S n1));
303     split;
304     [ assumption
305     | constructor 1
306     ] 
307   | intro;
308     letin f' ≝
309      (λx.
310        let fSn1 ≝ f (S n1) in
311        let fx ≝ f x in
312         match ltb fSn1 fx with
313         [ true ⇒ pred fx
314         | false ⇒ fx
315         ]);
316     cut (∀x,y. x ≤ n1 → y ≤ n1 → f' x = f' y → x=y);
317     [ cut (∀x. x ≤ n1 → f' x ≤ n1);
318       [ elim (H f' ? ? x);
319         [ simplify in H5;
320           clear Hcut;
321           clear Hcut1;
322           clear f';
323           elim H5;
324           clear H5;
325           apply (ex_intro ? ? a);
326           split;
327           [ generalize in match H4;
328             clear H4;
329             rewrite < H6;
330             clear H6;
331             apply (ltb_elim (f (S n1)) (f a));
332             [ (* TODO: caso impossibile (uso l'iniettivita') *)
333               simplify;
334             | simplify;
335               intros;
336               reflexivity
337             ]        
338           | apply le_S;
339             assumption
340           ]
341         | apply Hcut    
342         | apply Hcut1
343         | rewrite > (pred_Sn n1);
344           simplify;
345           generalize in match (H2 (S n1));
346           intro;
347           generalize in match (lt_to_le_to_lt ? ? ? H4 (H5 (le_n ?)));
348           intro;
349           unfold lt in H6;
350           apply le_S_S_to_le;
351           assumption
352         ]
353       | unfold f';
354         simplify;
355         intro;
356         apply (ltb_elim (f (S n1)) (f x1));
357         simplify;
358         intros;
359         [ generalize in match (H2 x1);
360           intro;
361           change in match n1 with (pred (S n1));
362           apply le_to_le_pred;
363           apply H7;
364           apply le_S;
365           assumption
366         | generalize in match (H2 (S n1) (le_n ?));
367           intro;
368           generalize in match (not_lt_to_le ? ? H5);
369           intro;
370           generalize in match (transitive_le ? ? ? H8 H7);
371           intro;
372           cut (f x1 ≠ f (S n1));
373           [ generalize in match (not_eq_to_le_to_lt ? ? Hcut1 H8);
374             intro;
375             unfold lt in H10;
376             generalize in match (transitive_le ? ? ? H10 H7);
377             intro;
378             apply le_S_S_to_le;
379             assumption
380           | unfold Not;
381             intro;
382             generalize in match (H1 ? ? ? ? H10);
383             [ intro;
384               rewrite > H11 in H6;
385               apply (not_le_Sn_n ? H6)
386             | apply le_S;
387               assumption
388             | apply le_n
389             ]
390           ] 
391         ]
392       ]
393     | intros 4;
394       unfold f';
395       simplify;
396       apply (ltb_elim (f (S n1)) (f x1));
397       simplify;
398       apply (ltb_elim (f (S n1)) (f y));
399       simplify;
400       intros;
401       [ cut (f x1 = f y);
402         [ apply (H1 ? ? ? ? Hcut);
403           apply le_S;
404           assumption
405         | apply eq_pred_to_eq;
406           [ apply (ltn_to_ltO ? ? H8)
407           | apply (ltn_to_ltO ? ? H7)
408           | assumption
409           ]
410         ]         
411       | (* pred (f x1) = f y absurd since y ≠ S n1 and thus f y ≠ f (S n1)
412            so that f y < f (S n1) < f x1; hence pred (f x1) = f y is absurd *)
413          cut (y < S n1);
414          [ generalize in match (lt_to_not_eq ? ? Hcut);
415            intro;
416            cut (f y ≠ f (S n1));
417            [ cut (f y < f (S n1));
418              [ rewrite < H9 in Hcut2;
419                unfold lt in Hcut2;
420                unfold lt in H8;
421                generalize in match (le_S_S ? ? Hcut2);
422                intro;
423                generalize in match (transitive_le ? ? ? H11 H8);
424                intros;
425                rewrite < (S_pred (f x1)) in H12;
426                 [ elim (not_le_Sn_n ? H12)
427                 | fold simplify ((f (S n1)) < (f x1)) in H8;
428                  apply (ltn_to_ltO ? ? H8)
429                 ]
430              | apply not_eq_to_le_to_lt;
431                [ assumption
432                | apply not_lt_to_le;
433                  assumption
434                ]
435              ]
436            | unfold Not;
437              intro;
438              apply H10;
439              apply (H1 ? ? ? ? H11);
440              [ apply lt_to_le;
441                assumption
442              | constructor 1
443              ]
444            ]
445          | unfold lt;
446            apply le_S_S;
447            assumption
448          ]
449       | (* f x1 = pred (f y) absurd since it implies S (f x1) = f y and
450            f x1 ≤ f (S n1) < f y = S (f x1) so that f x1 = f (S n1); by
451            injectivity x1 = S n1 that is absurd since x1 ≤ n1 *)
452          generalize in match (eq_f ? ? S ? ? H9);
453          intro;
454          rewrite < S_pred in H10;
455          [ rewrite < H10 in H7;
456            generalize in match (not_lt_to_le ? ? H8);
457            intro;
458            unfold lt in H7;
459            generalize in match (le_S_S ? ? H11);
460            intro;
461            generalize in match (antisym_le ? ? H12 H7);
462            intro;
463            generalize in match (inj_S ? ? H13);
464            intro;
465            generalize in match (H1 ? ? ? ? H14);
466            [ intro;
467              rewrite > H15 in H5;
468              elim (not_le_Sn_n ? H5)
469            | apply le_S;
470              assumption
471            | apply le_n
472            ]
473          | apply (ltn_to_ltO ?? H7) 
474          ]
475       | apply (H1 ? ? ? ? H9);
476         apply le_S;
477         assumption
478       ]
479     ]
480   ]
481 ].
482 qed.
483
484 theorem foo:
485  ∀G:finite_enumerable_SemiGroup.
486   left_cancellable ? (op G) →
487   right_cancellable ? (op G) →
488    ∃e:G. isMonoid (mk_PreMonoid G e).
489 intros;
490 letin f ≝ (λn.ι(G \sub O · G \sub n));
491 cut (∀n.n ≤ order ? (is_finite_enumerable G) → ∃m.f m = n);
492 [ letin EX ≝ (Hcut O ?);
493   [ apply le_O_n
494   | clearbody EX;
495     clear Hcut;
496     unfold f in EX;
497     elim EX;
498     clear EX;
499     letin HH ≝ (eq_f ? ? (repr ? (is_finite_enumerable G)) ? ? H2);
500     clearbody HH;
501     rewrite > (repr_index_of ? (is_finite_enumerable G)) in HH;
502     apply (ex_intro ? ? (G \sub a));
503     letin GOGO ≝ (refl_eq ? (repr ? (is_finite_enumerable G) O));
504     clearbody GOGO;
505     rewrite < HH in GOGO;
506     rewrite < HH in GOGO:(? ? % ?);
507     rewrite > (associative ? G) in GOGO;
508     letin GaGa ≝ (H ? ? ? GOGO);
509     clearbody GaGa;
510     clear GOGO;
511     constructor 1;
512     [ simplify;
513       apply (semigroup_properties G)
514     | unfold is_left_unit; intro;
515       letin GaxGax ≝ (refl_eq ? (G \sub a ·x));
516       clearbody GaxGax;
517       rewrite < GaGa in GaxGax:(? ? % ?);
518       rewrite > (associative ? (semigroup_properties G)) in GaxGax;
519       apply (H ? ? ? GaxGax)
520     | unfold is_right_unit; intro;
521       letin GaxGax ≝ (refl_eq ? (x·G \sub a));
522       clearbody GaxGax;
523       rewrite < GaGa in GaxGax:(? ? % ?);
524       rewrite < (associative ? (semigroup_properties G)) in GaxGax;
525       apply (H1 ? ? ? GaxGax)
526     ]
527   ]
528 | apply pigeonhole
529 ].