(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)


Set Implicit Arguments.
Unset Strict Implicit.
Require Export Sgroup_facts.
Require Export Parts.
Section Def.
Variable G : SGROUP.
Section Sub_sgroup.
Variable H : part_set G.
Hypothesis
  Hprop :
    forall x y : G,
    in_part x H -> in_part y H -> in_part (sgroup_law _ x y) H.

Definition subsgroup_law : law_of_composition H.
(* Goal: Carrier (law_of_composition (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H))) *)
unfold law_of_composition in |- *.
apply
 (Build_Map
    (A:=cart (set_of_subtype_image (part H)) (set_of_subtype_image (part H)))
    (B:=H)
    (Ap:=fun
           x : cart (set_of_subtype_image (part H))
                 (set_of_subtype_image (part H)) =>
         Build_subtype
           (Hprop (subtype_prf (proj1 x)) (subtype_prf (proj2 x))))).
(* Goal: @injective (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) *)
red in |- *.
(* Goal: forall x y z : @subtype (sgroup_set G) H, @Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z)) (@Hprop (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z) (@Hprop (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H x) (@subtype_prf (sgroup_set G) H y)) (@subtype_prf (sgroup_set G) H z)))) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z))) (@Hprop (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z)) (@subtype_prf (sgroup_set G) H x) (@Hprop (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z) (@subtype_prf (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H z))))) *)
simpl in |- *.
(* Goal: forall (x y : cart_type (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H))) (_ : and (@subtype_image_equal (sgroup_set G) (@subtype (sgroup_set G) H) (@subtype_elt (sgroup_set G) H) (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x) (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)) (@subtype_image_equal (sgroup_set G) (@subtype (sgroup_set G) H) (@subtype_elt (sgroup_set G) H) (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x) (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))), @Equal (sgroup_set G) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x))) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))) *)
unfold cart_eq, subtype_image_equal in |- *.
(* Goal: forall x y z : @subtype (sgroup_set G) H, @Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z)) (@Hprop (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z) (@Hprop (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H x) (@subtype_prf (sgroup_set G) H y)) (@subtype_prf (sgroup_set G) H z)))) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z))) (@Hprop (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z)) (@subtype_prf (sgroup_set G) H x) (@Hprop (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z) (@subtype_prf (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H z))))) *)
simpl in |- *.
(* Goal: forall (x y : cart_type (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H))) (_ : and (@subtype_image_equal (sgroup_set G) (@subtype (sgroup_set G) H) (@subtype_elt (sgroup_set G) H) (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x) (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)) (@subtype_image_equal (sgroup_set G) (@subtype (sgroup_set G) H) (@subtype_elt (sgroup_set G) H) (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x) (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))), @Equal (sgroup_set G) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x))) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))) *)
unfold cart_eq, subtype_image_equal in |- *.
(* Goal: forall (x y : cart_type (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H))) (_ : and (@Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x)) (@subtype_elt (sgroup_set G) H (@cart_l (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))) (@Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x)) (@subtype_elt (sgroup_set G) H (@cart_r (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)))), @Equal (sgroup_set G) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) x))) (sgroup_law G (@subtype_elt (sgroup_set G) H (@proj1 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y)) (@subtype_elt (sgroup_set G) H (@proj2 (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) y))) *)
intuition.
Defined.

Definition subsgroup_sgroup : sgroup.
(* Goal: sgroup *)
apply (Build_sgroup (sgroup_set:=H)).
(* Goal: sgroup_on (@set_of_subtype_image (sgroup_set G) (@part (sgroup_set G) H)) *)
apply (Build_sgroup_on (E:=H) (sgroup_law_map:=subsgroup_law)).
(* Goal: @injective (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) *)
red in |- *.
(* Goal: forall x y z : @subtype (sgroup_set G) H, @Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z)) (@Hprop (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z) (@Hprop (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H x) (@subtype_prf (sgroup_set G) H y)) (@subtype_prf (sgroup_set G) H z)))) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z))) (@Hprop (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z)) (@subtype_prf (sgroup_set G) H x) (@Hprop (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z) (@subtype_prf (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H z))))) *)
simpl in |- *.
(* Goal: forall x y z : @subtype (sgroup_set G) H, @subtype_image_equal (sgroup_set G) (@subtype (sgroup_set G) H) (@subtype_elt (sgroup_set G) H) (@Build_subtype (sgroup_set G) H (sgroup_law G (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z)) (@Hprop (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z) (@Hprop (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H x) (@subtype_prf (sgroup_set G) H y)) (@subtype_prf (sgroup_set G) H z))) (@Build_subtype (sgroup_set G) H (sgroup_law G (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z))) (@Hprop (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z)) (@subtype_prf (sgroup_set G) H x) (@Hprop (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z) (@subtype_prf (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H z)))) *)
unfold subtype_image_equal in |- *.
(* Goal: forall x y z : @subtype (sgroup_set G) H, @Equal (sgroup_set G) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z)) (@Hprop (sgroup_law G (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y)) (@subtype_elt (sgroup_set G) H z) (@Hprop (@subtype_elt (sgroup_set G) H x) (@subtype_elt (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H x) (@subtype_prf (sgroup_set G) H y)) (@subtype_prf (sgroup_set G) H z)))) (@subtype_elt (sgroup_set G) H (@Build_subtype (sgroup_set G) H (sgroup_law G (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z))) (@Hprop (@subtype_elt (sgroup_set G) H x) (sgroup_law G (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z)) (@subtype_prf (sgroup_set G) H x) (@Hprop (@subtype_elt (sgroup_set G) H y) (@subtype_elt (sgroup_set G) H z) (@subtype_prf (sgroup_set G) H y) (@subtype_prf (sgroup_set G) H z))))) *)
simpl in |- *.
(* Goal: forall (x y : Carrier (sgroup_set (@sgroup_of_subsgroup G H))) (_ : @Equal (sgroup_set G) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) x) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) y)), @Equal (sgroup_set (@sgroup_of_subsgroup G H)) x y *)
auto with algebra.
Defined.
End Sub_sgroup.

Record subsgroup : Type := 
  {subsgroup_part : Predicate G;
   subsgroup_prop :
    forall x y : G,
    in_part x subsgroup_part ->
    in_part y subsgroup_part -> in_part (sgroup_law _ x y) subsgroup_part}.

Definition sgroup_of_subsgroup (H : subsgroup) :=
  subsgroup_sgroup (subsgroup_prop (s:=H)).
End Def.
Coercion sgroup_of_subsgroup : subsgroup >-> sgroup.
Coercion subsgroup_part : subsgroup >-> Predicate.
Section Injection.
Variable G : SGROUP.
Variable H : subsgroup G.

Lemma subsgroup_in_prop :
 forall x y : G, in_part x H -> in_part y H -> in_part (sgroup_law _ x y) H.
(* Goal: forall (x y : Carrier (sgroup_set G)) (_ : @in_part (sgroup_set G) x (@subsgroup_part G H)) (_ : @in_part (sgroup_set G) y (@subsgroup_part G H)), @in_part (sgroup_set G) (sgroup_law G x y) (@subsgroup_part G H) *)
intros x y H' H'0; try assumption.
(* Goal: forall (x y : Carrier (sgroup_set (@sgroup_of_subsgroup G H))) (_ : @Equal (sgroup_set G) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) x) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) y)), @Equal (sgroup_set (@sgroup_of_subsgroup G H)) x y *)
apply (subsgroup_prop (G:=G) (s:=H)); auto with algebra.
Qed.

Definition inj_subsgroup : Hom (H:SGROUP) G.
(* Goal: Carrier (@Hom SGROUP (@sgroup_of_subsgroup G H : Ob SGROUP) G) *)
apply (Build_sgroup_hom (E:=H) (F:=G) (sgroup_map:=inj_part H)).
(* Goal: @injective (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) *)
red in |- *.
(* Goal: forall (x y : Carrier (sgroup_set (@sgroup_of_subsgroup G H))) (_ : @Equal (sgroup_set G) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) x) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) y)), @Equal (sgroup_set (@sgroup_of_subsgroup G H)) x y *)
auto with algebra.
Defined.

Lemma inj_subgroup_injective : injective inj_subsgroup.
(* Goal: @injective (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) *)
red in |- *.
(* Goal: forall (x y : Carrier (sgroup_set (@sgroup_of_subsgroup G H))) (_ : @Equal (sgroup_set G) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) x) (@Ap (sgroup_set (@sgroup_of_subsgroup G H)) (sgroup_set G) (@sgroup_map (@sgroup_of_subsgroup G H) G inj_subsgroup) y)), @Equal (sgroup_set (@sgroup_of_subsgroup G H)) x y *)
auto with algebra.
Qed.
End Injection.
Hint Resolve subsgroup_in_prop inj_subgroup_injective: algebra.