]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/library/algebra/groups.ma
Some more progress in the proof of the (ad-hoc ?) pigeonhole principle.
[helm.git] / helm / matita / library / algebra / groups.ma
index a9164a927bde9cf2f937d77a2b8f0dabadd64428..6deb73bd5cee4e285e4f7d87ae6e7a42b96f60d0 100644 (file)
 set "baseuri" "cic:/matita/algebra/groups/".
 
 include "algebra/monoids.ma".
+include "nat/le_arith.ma".
+include "datatypes/bool.ma".
+include "nat/compare.ma".
 
-record isGroup (M:Monoid) (opp: M -> M) : Prop ≝
- { opp_is_left_inverse: is_left_inverse M opp;
-   opp_is_right_inverse: is_right_inverse M opp
+record PreGroup : Type ≝
+ { premonoid:> PreMonoid;
+   opp: premonoid -> premonoid
+ }.
+
+record isGroup (G:PreGroup) : Prop ≝
+ { is_monoid: isMonoid G;
+   opp_is_left_inverse: is_left_inverse (mk_Monoid ? is_monoid) (opp G);
+   opp_is_right_inverse: is_right_inverse (mk_Monoid ? is_monoid) (opp G)
  }.
  
 record Group : Type ≝
- { monoid: Monoid;
-   opp: monoid -> monoid;
-   group_properties: isGroup ? opp
+ { pregroup:> PreGroup;
+   group_properties:> isGroup pregroup
  }.
-coercion cic:/matita/algebra/groups/monoid.con.
+
+(*notation < "G"
+for @{ 'monoid $G }.
+
+interpretation "Monoid coercion" 'monoid G =
+ (cic:/matita/algebra/groups/monoid.con G).*)
+
+notation < "G"
+for @{ 'type_of_group $G }.
+
+interpretation "Type_of_group coercion" 'type_of_group G =
+ (cic:/matita/algebra/groups/Type_of_Group.con G).
+
+notation < "G"
+for @{ 'magma_of_group $G }.
+
+interpretation "magma_of_group coercion" 'magma_of_group G =
+ (cic:/matita/algebra/groups/Magma_of_Group.con G).
 
 notation "hvbox(x \sup (-1))" with precedence 89
 for @{ 'gopp $x }.
@@ -35,43 +59,378 @@ for @{ 'gopp $x }.
 interpretation "Group inverse" 'gopp x =
  (cic:/matita/algebra/groups/opp.con _ x).
 
-definition left_cancellable :=
\lambda T:Type. \lambda op: T -> T -> T.
-  \forall x,y,z. op x y = op x z -> y = z.
+definition left_cancellable 
λT:Type. λop: T -> T -> T.
+  ∀x. injective ? ? (op x).
   
-definition right_cancellable :=
\lambda T:Type. \lambda op: T -> T -> T.
-  \forall x,y,z. op y x = op z x -> y = z.
+definition right_cancellable 
λT:Type. λop: T -> T -> T.
+  ∀x. injective ? ? (λz.op z x).
   
 theorem eq_op_x_y_op_x_z_to_eq:
\forall G:Group. left_cancellable G (op G).
G:Group. left_cancellable G (op G).
 intros;
 unfold left_cancellable;
-intros;
-rewrite < (e_is_left_unit ? ? (monoid_properties G));
-fold simplify (e G);
-rewrite < (e_is_left_unit ? ? (monoid_properties G) z);
-fold simplify (e G);
-rewrite < (opp_is_left_inverse ? ? (group_properties G) x);
-fold simplify (opp G);
-rewrite > (semigroup_properties G);
-fold simplify (op G);
-rewrite > (semigroup_properties G);
-fold simplify (op G);
+unfold injective;
+intros (x y z);
+rewrite < (e_is_left_unit ? (is_monoid ? (group_properties G)));
+rewrite < (e_is_left_unit ? (is_monoid ? (group_properties G)) z);
+rewrite < (opp_is_left_inverse ? (group_properties G) x);
+rewrite > (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
+rewrite > (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
 apply eq_f;
 assumption.
 qed.
 
-(*
+
 theorem eq_op_x_y_op_z_y_to_eq:
- \forall G:Group. right_cancellable G (op G).
+ ∀G:Group. right_cancellable G (op G).
+intros;
+unfold right_cancellable;
+unfold injective;
+simplify;fold simplify (op G); 
+intros (x y z);
+rewrite < (e_is_right_unit ? (is_monoid ? (group_properties G)));
+rewrite < (e_is_right_unit ? (is_monoid ? (group_properties G)) z);
+rewrite < (opp_is_right_inverse ? (group_properties G) x);
+rewrite < (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
+rewrite < (associative ? (is_semi_group ? (is_monoid ? (group_properties G))));
+rewrite > H;
+reflexivity.
 qed.
 
-definition has_cardinality :=
- \lambda T:Type. \lambda n:nat.
-  \exists f. injective T nat f.
 
-definition finite :=
- \lambda T:Type.
-  \exists f: T -> {n|n<
-*)
+record finite_enumerable (T:Type) : Type ≝
+ { order: nat;
+   repr: nat → T;
+   index_of: T → nat;
+   index_of_sur: ∀x.index_of x ≤ order;
+   index_of_repr: ∀n. n≤order → index_of (repr n) = n;
+   repr_index_of: ∀x. repr (index_of x) = x
+ }.
+notation "hvbox(C \sub i)" with precedence 89
+for @{ 'repr $C $i }.
+
+(* CSC: multiple interpretations in the same file are not considered in the
+ right order
+interpretation "Finite_enumerable representation" 'repr C i =
+ (cic:/matita/algebra/groups/repr.con C _ i).*)
+notation < "hvbox(|C|)" with precedence 89
+for @{ 'card $C }.
+
+interpretation "Finite_enumerable order" 'card C =
+ (cic:/matita/algebra/groups/order.con C _).
+
+record finite_enumerable_SemiGroup : Type ≝
+ { semigroup:> SemiGroup;
+   is_finite_enumerable:> finite_enumerable semigroup
+ }.
+
+notation < "S"
+for @{ 'semigroup_of_finite_enumerable_semigroup $S }.
+
+interpretation "Semigroup_of_finite_enumerable_semigroup"
+ 'semigroup_of_finite_enumerable_semigroup S
+=
+ (cic:/matita/algebra/groups/semigroup.con S).
+
+notation < "S"
+for @{ 'magma_of_finite_enumerable_semigroup $S }.
+
+interpretation "Magma_of_finite_enumerable_semigroup"
+ 'magma_of_finite_enumerable_semigroup S
+=
+ (cic:/matita/algebra/groups/Magma_of_finite_enumerable_SemiGroup.con S).
+notation < "S"
+for @{ 'type_of_finite_enumerable_semigroup $S }.
+
+interpretation "Type_of_finite_enumerable_semigroup"
+ 'type_of_finite_enumerable_semigroup S
+=
+ (cic:/matita/algebra/groups/Type_of_finite_enumerable_SemiGroup.con S).
+
+interpretation "Finite_enumerable representation" 'repr S i =
+ (cic:/matita/algebra/groups/repr.con S
+  (cic:/matita/algebra/groups/is_finite_enumerable.con S) i).
+
+notation "hvbox(ι e)" with precedence 60
+for @{ 'index_of_finite_enumerable_semigroup $e }.
+
+interpretation "Index_of_finite_enumerable representation"
+ 'index_of_finite_enumerable_semigroup e
+=
+ (cic:/matita/algebra/groups/index_of.con _
+  (cic:/matita/algebra/groups/is_finite_enumerable.con _) e).
+
+
+(* several definitions/theorems to be moved somewhere else *)
+
+definition ltb ≝ λn,m. leb n m ∧ notb (eqb n m).
+
+theorem not_eq_to_le_to_lt: ∀n,m. n≠m → n≤m → n<m.
+intros;
+elim (le_to_or_lt_eq ? ? H1);
+[ assumption
+| elim (H H2)
+].
+qed.
+
+theorem ltb_to_Prop :
+ ∀n,m.
+  match ltb n m with
+  [ true ⇒ n < m
+  | false ⇒ n ≮ m
+  ].
+intros;
+unfold ltb;
+apply leb_elim;
+apply eqb_elim;
+intros;
+simplify;
+[ rewrite < H;
+  apply le_to_not_lt;
+  constructor 1
+| apply (not_eq_to_le_to_lt ? ? H H1)
+| rewrite < H;
+  apply le_to_not_lt;
+  constructor 1
+| apply le_to_not_lt;
+  generalize in match (not_le_to_lt ? ? H1);
+  clear H1;
+  intro;
+  apply lt_to_le;
+  assumption
+].
+qed.
+
+theorem ltb_elim: \forall n,m:nat. \forall P:bool \to Prop.
+(n < m \to (P true)) \to (n ≮ m \to (P false)) \to
+P (ltb n m).
+intros.
+cut
+(match (ltb n m) with
+[ true  \Rightarrow n < m
+| false \Rightarrow n ≮ m] \to (P (ltb n m))).
+apply Hcut.apply ltb_to_Prop.
+elim (ltb n m).
+apply ((H H2)).
+apply ((H1 H2)).
+qed.
+
+theorem Not_lt_n_n: ∀n. n ≮ n.
+intro;
+unfold Not;
+intro;
+unfold lt in H;
+apply (not_le_Sn_n ? H).
+qed.
+
+theorem eq_pred_to_eq:
+ ∀n,m. O < n → O < m → pred n = pred m → n = m.
+intros 2;
+elim n;
+[ elim (Not_lt_n_n ? H)
+| generalize in match H3;
+  clear H3;
+  generalize in match H2;
+  clear H2;
+  elim m;
+  [ elim (Not_lt_n_n ? H2)
+  | simplify in H4;
+    apply (eq_f ? ? S);
+    assumption
+  ]
+].
+qed.
+
+theorem le_pred_to_le:
+ ∀n,m. O < m → pred n ≤ pred m \to n ≤ m.
+intros 2;
+elim n;
+[ apply le_O_n
+| simplify in H2;
+  rewrite > (S_pred m);
+  [ apply le_S_S;
+    assumption
+  | assumption
+  ]
+].
+qed.
+
+theorem le_to_le_pred:
+ ∀n,m. n ≤ m → pred n ≤ pred m.
+intros 2;
+elim n;
+[ simplify;
+  apply le_O_n
+| simplify;
+  generalize in match H1;
+  clear H1;
+  elim m;
+  [ elim (not_le_Sn_O ? H1)
+  | simplify;
+    apply le_S_S_to_le;
+    assumption
+  ]
+].
+qed.
+
+
+theorem pigeonhole:
+ ∀n:nat.∀f:nat→nat.
+  (∀x,y.x≤n → y≤n → f x = f y → x=y) →
+  (∀m. f m ≤ n) →
+   ∀x. x≤n \to ∃y.f y = x ∧ y ≤ n.
+intro;
+elim n;
+[ apply (ex_intro ? ? O);
+  split;
+  rewrite < (le_n_O_to_eq ? H2);
+  rewrite < (le_n_O_to_eq ? (H1 O));
+  reflexivity
+| clear n;
+  apply (nat_compare_elim (f (S n1)) x);
+  [ (* TODO: caso complicato, ma simile al terzo *) 
+  | intros;
+    apply (ex_intro ? ? (S n1));
+    split;
+    [ assumption
+    | constructor 1
+    ] 
+  | intro;
+    letin f' ≝
+     (λx.
+       let fSn1 ≝ f (S n1) in
+       let fx ≝ f x in
+        match ltb fSn1 fx with
+        [ true ⇒ pred fx
+        | false ⇒ fx
+        ]);
+    elim (H f' ? ? x);
+    [ simplify in H5;
+      clear f';
+      elim H5;
+      clear H5;
+      apply (ex_intro ? ? a);
+      split;
+      [ generalize in match H4;
+        clear H4;
+        rewrite < H6;
+        clear H6;
+        apply (ltb_elim (f (S n1)) (f a));
+        [ (* TODO: caso impossibile (uso l'iniettivita') *)
+          simplify;
+        | simplify;
+          intros;
+          reflexivity
+        ]        
+      | apply le_S;
+        assumption
+      ]
+    | (* This branch proves injectivity of f' *)    
+      simplify;
+      intros 4;
+      apply (ltb_elim (f (S n1)) (f x1));
+      simplify;
+      apply (ltb_elim (f (S n1)) (f y));
+      simplify;
+      intros;
+      [ cut (f x1 = f y);
+        [ apply (H1 ? ? ? ? Hcut);
+          apply le_S;
+          assumption
+        | apply eq_pred_to_eq;
+          [ apply (ltn_to_ltO ? ? H8)
+          | apply (ltn_to_ltO ? ? H7)
+          | assumption
+          ]
+        ]         
+      | (* TODO: pred (f x1) = f y assurdo per iniettivita'
+           poiche' y ≠ S n1 da cui f y ≠ f (S n1) da cui f y < f (S n1) < f x1
+           da cui assurdo pred (f x1) = f y *)
+      | (* TODO: f x1 = pred (f y) assurdo per iniettivita' *)
+      | apply (H1 ? ? ? ? H9);
+        apply le_S;
+        assumption
+      ]
+    | simplify;
+      intro;
+      apply (ltb_elim (f (S n1)) (f m));
+      simplify;
+      intro;
+      [ generalize in match (H2 m);
+        intro;
+        change in match n1 with (pred (S n1));
+        apply le_to_le_pred;
+        assumption
+      | generalize in match (H2 (S n1));
+        intro;
+        generalize in match (not_lt_to_le ? ? H5);
+        intro;
+        generalize in match (transitive_le ? ? ? H7 H6);
+        intro;
+        (* TODO: qui mi serve dimostrare che f m ≠ f (S n1) (per iniettivita'?) *) 
+      ]
+    | rewrite > (pred_Sn n1);
+      simplify;
+      generalize in match (H2 (S n1));
+      intro;
+      generalize in match (lt_to_le_to_lt ? ? ? H4 H5);
+      intro;
+      unfold lt in H6;
+      apply le_S_S_to_le;
+      assumption
+    ]
+  ]
+].
+qed.
+
+theorem foo:
+ ∀G:finite_enumerable_SemiGroup.
+  left_cancellable ? (op G) →
+  right_cancellable ? (op G) →
+   ∃e:G. isMonoid (mk_PreMonoid G e).
+intros;
+letin f ≝ (λn.ι(G \sub O · G \sub n));
+cut (∀n.n ≤ order ? (is_finite_enumerable G) → ∃m.f m = n);
+[ letin EX ≝ (Hcut O ?);
+  [ apply le_O_n
+  | clearbody EX;
+    clear Hcut;
+    unfold f in EX;
+    elim EX;
+    clear EX;
+    letin HH ≝ (eq_f ? ? (repr ? (is_finite_enumerable G)) ? ? H2);
+    clearbody HH;
+    rewrite > (repr_index_of ? (is_finite_enumerable G)) in HH;
+    apply (ex_intro ? ? (G \sub a));
+    letin GOGO ≝ (refl_eq ? (repr ? (is_finite_enumerable G) O));
+    clearbody GOGO;
+    rewrite < HH in GOGO;
+    rewrite < HH in GOGO:(? ? % ?);
+    rewrite > (associative ? G) in GOGO;
+    letin GaGa ≝ (H ? ? ? GOGO);
+    clearbody GaGa;
+    clear GOGO;
+    constructor 1;
+    [ simplify;
+      apply (semigroup_properties G)
+    | unfold is_left_unit; intro;
+      letin GaxGax ≝ (refl_eq ? (G \sub a ·x));
+      clearbody GaxGax;
+      rewrite < GaGa in GaxGax:(? ? % ?);
+      rewrite > (associative ? (semigroup_properties G)) in GaxGax;
+      apply (H ? ? ? GaxGax)
+    | unfold is_right_unit; intro;
+      letin GaxGax ≝ (refl_eq ? (x·G \sub a));
+      clearbody GaxGax;
+      rewrite < GaGa in GaxGax:(? ? % ?);
+      rewrite < (associative ? (semigroup_properties G)) in GaxGax;
+      apply (H1 ? ? ? GaxGax)
+    ]
+  ]
+| apply pigeonhole
+].