(* 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 Monoid_kernel.
Require Export Free_monoid.
Section Generated_monoid_def.
Variable M : MONOID.
Variable A : part_set M.

Definition generated_monoid : submonoid M :=
  image_monoid_hom (FM_lift (inj_part A)).
End Generated_monoid_def.

Lemma generated_monoid_minimal :
 forall (M : MONOID) (A : part_set M) (H : submonoid M),
 included A H -> included (generated_monoid A) H.
(* Goal: forall (M : Ob MONOID) (A : Carrier (part_set (sgroup_set (monoid_sgroup M)))), @included (sgroup_set (monoid_sgroup M)) A (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M (@generated_monoid M A))) *)
unfold included in |- *.
(* Goal: @Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) (@Build_subtype (sgroup_set (monoid_sgroup M)) A x H'))) *)
simpl in |- *.
(* Goal: forall (M : monoid) (A : Predicate (sgroup_set (monoid_sgroup M))) (H : submonoid M) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : @in_part (sgroup_set (monoid_sgroup M)) x A), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x0)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
intros M A H H' x H'0; try assumption.
(* Goal: @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
elim H'0; intros x0; clear H'0.
(* Goal: forall _ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x0)), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
generalize x; clear x.
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x0))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
elim x0.
(* Goal: forall (c : Carrier (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) c)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (f : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (f0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f0))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Law (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) f f0)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (Unit (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
intros c; try assumption.
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) c)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (f : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (f0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f0))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Law (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) f f0)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (Unit (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
elim c.
(* Goal: @Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) (@Build_subtype (sgroup_set (monoid_sgroup M)) A x H'))) *)
simpl in |- *.
intros y subtype_prf x H'0; elim H'0; intros H'1 H'2; try exact H'2;
 clear H'0.
(* Goal: @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (f : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (f0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f0))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Law (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) f f0)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (Unit (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
apply in_part_comp_l with y; auto with algebra.
(* Goal: forall (f : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (f0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (_ : forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) f0))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Law (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) f f0)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (Unit (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
intros f H'0 f0 H'1 x H'2; elim H'2; intros H'3 H'4; try exact H'4; clear H'2.
(* Goal: @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (Unit (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
simpl in H'4.
apply
 in_part_comp_l
  with
    (sgroup_law M (FM_lift_fun (inj_part A) f) (FM_lift_fun (inj_part A) f0));
(* Goal: True *)
 auto with algebra.
(* Goal: @Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) (@Build_subtype (sgroup_set (monoid_sgroup M)) A x H'))) *)
simpl in |- *.
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : and True (@Equal (sgroup_set (monoid_sgroup M)) x (@monoid_unit (monoid_sgroup M) (monoid_on_def M)))), @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
intros x H'0; elim H'0; intros H'1 H'2; try exact H'2; clear H'0.
(* Goal: @in_part (sgroup_set (monoid_sgroup M)) x (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M H)) *)
apply in_part_comp_l with (monoid_unit M); auto with algebra.
Qed.

Lemma generated_monoid_prop_included :
 forall (M : MONOID) (A : part_set M), included A (generated_monoid A).
(* Goal: forall (M : Ob MONOID) (A : Carrier (part_set (sgroup_set (monoid_sgroup M)))), @included (sgroup_set (monoid_sgroup M)) A (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M (@generated_monoid M A))) *)
unfold included in |- *.
(* Goal: @Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) (@Build_subtype (sgroup_set (monoid_sgroup M)) A x H'))) *)
simpl in |- *.
(* Goal: forall (M : monoid) (A : Predicate (sgroup_set (monoid_sgroup M))) (x : Carrier (sgroup_set (monoid_sgroup M))) (_ : @in_part (sgroup_set (monoid_sgroup M)) x A), @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x0 : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => and True (@Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x0))) *)
intros M A x H'; try assumption.
exists (Var (V:=A) (Build_subtype (E:=M) (P:=A) (subtype_elt:=x) H')); split;
 [ idtac | try assumption ].
(* Goal: True *)
auto with algebra.
(* Goal: @Equal (sgroup_set (monoid_sgroup M)) x (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) (@Var (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) (@Build_subtype (sgroup_set (monoid_sgroup M)) A x H'))) *)
simpl in |- *.
(* Goal: True *)
auto with algebra.
Qed.

Lemma generated_monoid_prop :
 forall (M : MONOID) (A : part_set M) (y : M),
 in_part y (generated_monoid A) ->
 exists x : FM A, Equal y (FM_lift (inj_part A) x).
(* Goal: True *)
simpl in |- *; auto with algebra.
(* Goal: forall (M : Ob MONOID) (A : Carrier (part_set (sgroup_set (monoid_sgroup M)))) (y : Carrier (sgroup_set (monoid_sgroup M))) (_ : @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => @Equal (sgroup_set (monoid_sgroup M)) y (@Ap (sgroup_set (monoid_sgroup (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))))) (sgroup_set (monoid_sgroup M)) (@sgroup_map (monoid_sgroup (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))) (monoid_sgroup M) (@monoid_sgroup_hom (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) M (@FM_lift (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A)))) x))), @in_part (sgroup_set (monoid_sgroup M)) y (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M (@generated_monoid M A))) *)
intros M A y H'; try assumption.
(* Goal: @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => @Equal (sgroup_set (monoid_sgroup M)) y (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x)) *)
elim H'; intros x E; elim E; intros H'0 H'1; try exact H'1; clear E H'.
(* Goal: @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => @Equal (sgroup_set (monoid_sgroup M)) y (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x)) *)
exists x; try assumption.
Qed.

Lemma generated_monoid_prop_rev :
 forall (M : MONOID) (A : part_set M) (y : M),
 (exists x : FM A, Equal y (FM_lift (inj_part A) x)) ->
 in_part y (generated_monoid A).
(* Goal: forall (M : Ob MONOID) (A : Carrier (part_set (sgroup_set (monoid_sgroup M)))) (y : Carrier (sgroup_set (monoid_sgroup M))) (_ : @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => @Equal (sgroup_set (monoid_sgroup M)) y (@Ap (sgroup_set (monoid_sgroup (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))))) (sgroup_set (monoid_sgroup M)) (@sgroup_map (monoid_sgroup (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)))) (monoid_sgroup M) (@monoid_sgroup_hom (FreeMonoid (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) M (@FM_lift (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A)))) x))), @in_part (sgroup_set (monoid_sgroup M)) y (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M (@generated_monoid M A))) *)
intros M A y H'; try assumption.
(* Goal: @in_part (sgroup_set (monoid_sgroup M)) y (@subsgroup_part (monoid_sgroup M) (@submonoid_subsgroup M (@generated_monoid M A))) *)
elim H'; intros x E; try exact E; clear H'.
(* Goal: True *)
simpl in |- *; auto with algebra.
(* Goal: @ex (FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A))) (fun x : FM (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) => and True (@Equal (sgroup_set (monoid_sgroup M)) y (@FM_lift_fun (@set_of_subtype_image (sgroup_set (monoid_sgroup M)) (@part (sgroup_set (monoid_sgroup M)) A)) M (@inj_part (sgroup_set (monoid_sgroup M)) A) x))) *)
exists x; split; [ idtac | try assumption ].
(* Goal: True *)
auto with algebra.
Qed.
Hint Resolve generated_monoid_minimal generated_monoid_prop_included
  generated_monoid_prop_rev: algebra.
