Theory Module_ZF

(* 
    This file is a part of IsarMathLib - 
    a library of formalized mathematics written for Isabelle/Isar.

    Copyright (C) 2024  Slawomir Kolodynski

    This program is free software; Redistribution and use in source and binary forms, 
    with or without modification, are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, 
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation and/or 
   other materials provided with the distribution.
   3. The name of the author may not be used to endorse or promote products 
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*)

section  Modules

theory Module_ZF imports Ring_ZF_3 Field_ZF

begin

textA module is a generalization of the concept of a vector space in which scalars
  do not form a field but a ring. 

subsectionDefinition and basic properties of modules

textLet $R$ be a ring and $M$ be an abelian group. The most common definition
  of a left $R$-module posits the existence of a scalar multiplication operation
  $R\times M\rightarrow M$ satisfying certain four properties.
  Here we take a bit more concise and abstract approach defining a module as a ring action
  on an abelian group.  

textWe know that endomorphisms of an abelian group $\cal{M}$ form a ring with pointwise addition
  as the additive operation and composition as the ring multiplication. 
  This asssertion is a bit imprecise though as the domain of pointwise addition 
  is a binary operation on the space of functions $\cal{M}\rightarrow \cal{M}$ 
  (i.e. its domain is  $(\cal{M}\rightarrow \cal{M})\times \cal{M}\rightarrow \cal{M}$) 
  while we need the space of endomorphisms to be the
  domain of the ring addition and multiplication. Therefore, to get the actual additive operation
  we need to restrict the pointwise addition of functions $\cal{M}\rightarrow \cal{M}$ 
  to the set of endomorphisms of $\cal{M}$. 
  Recall from the Group_ZF_5› that the InEnd› operator restricts an operation to
  the set of endomorphisms and see the func_ZF› theory for definitions 
  of lifting an operation on a set to a function space over that set. 

definition "EndAdd(,A)  InEnd(A {lifted to function space over} ,,A)"

textSimilarly we define the multiplication in the ring of endomorphisms 
  as the restriction of compositions to the endomorphisms of $\cal{M}$.
  See the func_ZF› theory for the definition of the Composition› operator. 

definition "EndMult(,A)  InEnd(Composition(),,A)"

textWe can now reformulate the theorem end_is_ring› from the Group_ZF_5› theory
  in terms of the addition and multiplication of endomorphisms defined above. 

lemma (in abelian_group) end_is_ring1: 
  shows "IsAring(End(G,P),EndAdd(G,P),EndMult(G,P))"
  using end_is_ring unfolding EndAdd_def EndMult_def by simp

textWe define an action› as a homomorphism into a space of endomorphisms (typically of some
  abelian group). In the definition below $S$ is the set of scalars, $A$ is the addition operation
  on this set, $M$ is multiplication on the set, $V$ is the group, $A_V$ is the 
  group operation, and $H$ is the ring homomorphism that of the ring of scalars 
  to the ring of endomorphisms of the group.
  On the right hand side of the definition End(V,AV)› is the set of endomorphisms,  
  This definition is only ever used as part of the definition of a module and vector space, 
  it's just convenient to split it off to shorten the main definitions. 

definition 
  "IsAction(S,A,M,,AM,H)  ringHomomor(H,S,A,M,End(,AM),EndAdd(,AM),EndMult(,AM))"

textA module is a ring action on an abelian group.

definition "IsLeftModule(S,A,M,,AM,H) 
  IsAring(S,A,M)  IsAgroup(,AM)  (AM {is commutative on} )  IsAction(S,A,M,,AM,H)"


textThe next locale defines context (i.e. common assumptions and notation) when considering 
  modules. We reuse notation from the ring0› locale and add notation specific to
  modules. The addition and multiplication in the ring of scalars is denoted $+$ and $\cdot$,
  resp. The addition of module elements will be denoted $+_V$. 
  The multiplication (scaling) of scalars by module elemenst will be denoted $\cdot_S$. 
  $\Theta$ is the zero module element, i.e. the neutral element of the abelian group
  of the module elements. 

locale module0 = ring0 +
  
  fixes  AM H
  
  assumes mAbGr: "IsAgroup(,AM)  (AM {is commutative on} )"

  assumes mAction: "IsAction(R,A,M,,AM,H)"

  fixes zero_vec ("Θ")
  defines zero_vec_def [simp]: "Θ  TheNeutralElement(,AM)"

  fixes vAdd (infixl "+V" 80)
  defines vAdd_def [simp]: "v1 +V v2  AM`v1,v2"

  fixes scal (infix "S" 90)
  defines scal_def [simp]: "s S v  (H`(s))`(v)"

  fixes negV ("_")
  defines negV_def [simp]: "v  GroupInv(,AM)`(v)"

  fixes vSub (infix "-V" 80)
  defines vSub_def [simp]: "v1 -V v2  v1 +V (v2)"

textWe indeed talk about modules in the module0› context.

lemma (in module0) module_in_module0: shows "IsLeftModule(R,A,M,,AM,H)"
  using ringAssum mAbGr mAction unfolding IsLeftModule_def by simp

textTheorems proven in the abelian_group› context are valid as applied to the module0›
  context as applied to the abelian group of module elements. 

lemma (in module0) abelian_group_valid_module0: 
  shows "abelian_group(,AM)"
  using mAbGr group0_def abelian_group_def abelian_group_axioms_def 
  by simp

textAnother way to state that theorems proven in the abelian_group› context 
  can be used in the module0› context:  

sublocale module0 < mod_ab_gr: abelian_group "" "AM" "Θ" vAdd negV
  using abelian_group_valid_module0 by auto
  
textTheorems proven in the ring_homo› context are valid in the module0› context, as
  applied to ring $R$ and the ring of endomorphisms of the group of module elements. 
 
lemma (in module0) ring_homo_valid_module0: 
  shows "ring_homo(R,A,M,End(,AM),EndAdd(,AM),EndMult(,AM),H)"
  using ringAssum mAction abelian_group_valid_module0 abelian_group.end_is_ring1
  unfolding IsAction_def ring_homo_def by simp

textAnother way to make theorems proven in the ring_homo› context available in the 
  module0› context: 

sublocale module0 < vec_act_homo: ring_homo R A M 
  "End(,AM)" "EndAdd(,AM)" "EndMult(,AM)" H
  ringa
  ringminus
  ringsub
  ringm
  ringzero
  ringone
  ringtwo
  ringsq
  "λx y.  EndAdd(,AM) ` x, y"
  "λx. GroupInv(End(,AM), EndAdd(, AM))`(x)"
  "λx y. EndAdd(,AM)`x,GroupInv(End(, AM), EndAdd(, AM))`(y)"
  "λx y. EndMult(,AM)`x, y"
  "TheNeutralElement(End(, AM), EndAdd(, AM))"
  "TheNeutralElement(End(, AM), EndMult(, AM))"
  "EndAdd(,AM)`TheNeutralElement(End(, AM),EndMult(, AM)),TheNeutralElement(End(, AM), EndMult(,AM))"
  "λx.  EndMult(,AM)`x, x"
  using ring_homo_valid_module0 by auto

textIn the ring of endomorphisms of the module the neutral element of the additive operation 
  is the zero valued constant function. The neutral element of the multiplicative operation is
  the identity function.

lemma (in module0) add_mult_neut_elems: shows 
  "TheNeutralElement(End(, AM), EndMult(,AM)) = id()" and 
  "TheNeutralElement(End(,AM),EndAdd(,AM)) = ConstantFunction(,Θ)"
proof -
  show "TheNeutralElement(End(, AM), EndMult(, AM)) = id()"
    using mod_ab_gr.end_comp_monoid(2) unfolding EndMult_def
    by blast
  show "TheNeutralElement(End(, AM), EndAdd(, AM)) = ConstantFunction(,Θ)"
    using mod_ab_gr.end_add_neut_elem unfolding EndAdd_def by blast
qed

textThe value of the homomorphism defining the module is an endomorphism
  of the group of module elements and hence a function that maps the module into itself.

lemma (in module0) H_val_type: assumes "rR" shows 
  "H`(r)  End(,AM)" and "H`(r):"
  using mAction assms apply_funtype unfolding IsAction_def ringHomomor_def End_def
  by auto

text In the module0› context the neutral element of addition of module elements 
  is denoted $\Theta$. Of course $\Theta$ is an element of the module. 

lemma (in module0) zero_in_mod: shows "Θ  "
  using mod_ab_gr.group0_2_L2 by simp

text $\Theta$ is indeed the neutral element of addition of module elements.

lemma (in module0) zero_neutral: assumes "x" 
  shows "x +V Θ = x" and "Θ +V x = x"
  using assms  mod_ab_gr.group0_2_L2 by simp_all

subsectionModule axioms

textA more common definition of a module assumes that $R$ is a ring, $V$ 
  is an abelian group and lists a couple of properties that the multiplications of scalars 
  (elements of $R$) by the elements of the module $V$ should have. 
  In this section we show that the definition of a module as a ring action
  on an abelian group $V$ implies these properties.   

textThe scalar multiplication is distributive with respect to the module addition.

lemma (in module0) module_ax1: assumes "rR" "x" "y"
  shows "rS(x+Vy) = rSx +V rSy"
  using assms H_val_type(1) mod_ab_gr.endomor_eq by simp
  
textThe scalar addition is distributive with respect to scalar multiplication.

lemma (in module0) module_ax2: assumes "rR" "sR" "x"
  shows "(r\<ra>s)Sx = rSx +V sSx"
  using assms vec_act_homo.homomor_dest_add H_val_type(1) mod_ab_gr.end_pointwise_add_val
  unfolding EndAdd_def by simp

textMultiplication by scalars is associative with multiplication of scalars.

lemma (in module0) module_ax3: assumes "rR" "sR" "x"
  shows "(rs)Sx = rS(sSx)"
proof -
  let ?e = "EndMult(,AM)`H`(r),H`(s)"
  have "(rs)Sx = (H`(rs))`(x)" by simp
  also have "(H`(rs))`(x) = ?e`(x)"
  proof -
    from mAction assms(1,2) have "H`(rs) = ?e"
      using vec_act_homo.homomor_dest_mult unfolding IsAction_def
      by blast
    then show ?thesis by (rule same_constr)
  qed
  also have  "?e`(x) = rS(sSx)"
  proof - 
    from assms(1,2) have "?e`(x) = (Composition()`H`(r),H`(s))`(x)"
      using H_val_type(1) unfolding EndMult_def by simp
    also from assms have "... =  rS(sSx)" using H_val_type(2) func_ZF_5_L3
      by simp
    finally show "?e`(x) = rS(sSx)" by blast
  qed
  finally show ?thesis by simp
qed

textScaling a module element by one gives the same module element.

lemma (in module0) module_ax4: assumes "x" shows "𝟭Sx = x"
proof -
  let ?n = "TheNeutralElement(End(,AM),EndMult(,AM))"
  from mAction have "H`(TheNeutralElement(R,M)) = ?n"
    unfolding IsAction_def ringHomomor_def by blast
  moreover have "TheNeutralElement(R,M) = 𝟭" by simp
  ultimately have "H`(𝟭) = ?n" by blast
  also have "?n = id()" by (rule add_mult_neut_elems)
  finally have "H`(𝟭) = id()" by simp
  with assms show "𝟭Sx = x" by simp
qed

end