(* 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 Module_util.
Require Export Sub_module.
Require Export Group_kernel.
(** Title "Kernel and image of a module homomorphism." *)
Section Def.
Variable R : RING.
Variable Mod Mod2 : MODULE R.
Variable f : Hom Mod Mod2.

Definition Ker : submodule Mod.
(* Goal: @submodule R Mod *)
apply (Build_submodule (R:=R) (M:=Mod) (submodule_subgroup:=Ker f)).
(* Goal: forall x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod2)) (@submodule_subgroup R Mod2 coKer)))) *)
simpl in |- *.
(* Goal: forall (a : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (ring_group R)))))) (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))))) (_ : @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) x (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0)))), @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@module_mult R Mod2 a x) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0))) *)
intros a x H'; try assumption.
(* Goal: @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) (@module_mult R Mod a x)) (@monoid_unit (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (monoid_on_def (group_monoid (abelian_group_group (@module_carrier R Mod2))))) *)
apply Trans with (module_mult a (f x)); auto with algebra.
apply Trans with (module_mult a (monoid_unit (module_carrier Mod2)));
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (_ : @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@monoid_unit (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (monoid_on_def (group_monoid (abelian_group_group (@module_carrier R Mod2)))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) x (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod)) (@submodule_subgroup R Mod Ker)))) *)
 auto with algebra.
Defined.

Definition coKer : submodule Mod2.
(* Goal: @submodule R Mod2 *)
apply (Build_submodule (R:=R) (M:=Mod2) (submodule_subgroup:=coKer f)).
(* Goal: forall x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod2)) (@submodule_subgroup R Mod2 coKer)))) *)
simpl in |- *.
(* Goal: forall (a : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (ring_group R)))))) (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))))) (_ : @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) x (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0)))), @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@module_mult R Mod2 a x) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0))) *)
intros a x H'; try assumption.
(* Goal: @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@module_mult R Mod2 a x) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0))) *)
elim H'; intros x0 E; elim E; intros H'0 H'1; try exact H'1; clear E H'.
(* Goal: @ex (Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (fun x0 : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) => and True (@Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@module_mult R Mod2 a x) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x0))) *)
exists (module_mult a x0); split; [ try assumption | idtac ].
(* Goal: @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@module_mult R Mod2 a x) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) (@module_mult R Mod a x0)) *)
apply Trans with (module_mult a (f x0)); auto with algebra.
Defined.

Lemma Ker_prop :
 forall x : Mod, in_part x Ker -> Equal (f x) (monoid_unit Mod2).
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (_ : @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@monoid_unit (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (monoid_on_def (group_monoid (abelian_group_group (@module_carrier R Mod2)))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) x (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod)) (@submodule_subgroup R Mod Ker)))) *)
auto with algebra.
Qed.

Lemma Ker_prop_rev :
 forall x : Mod, Equal (f x) (monoid_unit Mod2) -> in_part x Ker.
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (_ : @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@monoid_unit (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (monoid_on_def (group_monoid (abelian_group_group (@module_carrier R Mod2)))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) x (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod)) (@submodule_subgroup R Mod Ker)))) *)
auto with algebra.
Qed.

Lemma coKer_prop : forall x : Mod, in_part (f x) coKer.
(* Goal: forall x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod2)) (@submodule_subgroup R Mod2 coKer)))) *)
simpl in |- *.
(* Goal: forall (x : Carrier (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))))) (_ : @Equal (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@Ap (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2))))) (@sgroup_map (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (@monoid_sgroup_hom (group_monoid (abelian_group_group (@module_carrier R Mod))) (group_monoid (abelian_group_group (@module_carrier R Mod2))) (@module_monoid_hom R Mod Mod2 f))) x) (@monoid_unit (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod2)))) (monoid_on_def (group_monoid (abelian_group_group (@module_carrier R Mod2)))))), @in_part (sgroup_set (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod))))) x (@subsgroup_part (monoid_sgroup (group_monoid (abelian_group_group (@module_carrier R Mod)))) (@submonoid_subsgroup (group_monoid (abelian_group_group (@module_carrier R Mod))) (@subgroup_submonoid (abelian_group_group (@module_carrier R Mod)) (@submodule_subgroup R Mod Ker)))) *)
intros x; exists x; split; [ idtac | try assumption ]; auto with algebra.
Qed.
End Def.
Hint Resolve Ker_prop coKer_prop: algebra.
