Theory Quasigroup_ZF

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

    Copyright (C) 2021 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  Quasigroups 

theory Quasigroup_ZF imports func1

begin

text A quasigroup is an algebraic structure that that one gets after adding (sort of)
   divsibility to magma. Quasigroups differ from groups in that they are not necessarily 
   associative and they do not have to have the neutral element. 

subsection Definitions and notation 

text According to Wikipedia there are at least two approaches to defining a quasigroup. 
  One defines a quasigroup as a set with a binary operation, and the other, 
  from universal algebra, defines a quasigroup as having three primitive operations. We will use 
  the first approach.  

text A quasigroup operation does not  have to have the neutral element. The left division is defined 
  as the only solution to the equation $a\cdot x=b$ (using multiplicative notation). 
  The next definition specifies
  what does it mean that an operation $A$ has a left division on a set $G$. 

definition
  "HasLeftDiv(G,A)  aG.bG.∃!x. (xG  A`a,x = b)" 


text An operation $A$ has the right inverse if for all elements $a,b \in G$ the equation $x\cdot a=b$ 
  has a unique solution. 

definition
  "HasRightDiv(G,A)  aG.bG.∃!x. (xG  A`x,a = b)" 

textAn operation that has both left and right division is said to have the Latin square property. 

definition
  HasLatinSquareProp (infix "{has Latin square property on}" 65) where
    "A {has Latin square property on} G  HasLeftDiv(G,A)  HasRightDiv(G,A)"

text A quasigroup is a set with a binary operation that has the Latin square property. 

definition
  "IsAquasigroup(G,A)  A:G×GG  A {has Latin square property on} G"

text The uniqueness of the left inverse allows us to define the left division as a function.
  The union expression as the value of the function extracts the only element
  of the set of solutions of the equation $x\cdot z = y$ for given 
  $\langle x,y \rangle = p \in G\times G$ using the identity $\bigcup \{x\} =x$. 

definition
  "LeftDiv(G,A)  {p,{zG. A`fst(p),z = snd(p)}.pG×G}"

textSimilarly the right division is defined as a function on $G\times G$.  

definition
  "RightDiv(G,A)  {p,{zG. A`z,fst(p) = snd(p)}.pG×G}"

textLeft and right divisions are binary operations on $G$. 

lemma lrdiv_binop: assumes "IsAquasigroup(G,A)" shows 
  "LeftDiv(G,A):G×GG" and  "RightDiv(G,A):G×GG"
proof -
  { fix p assume "pG×G"
    with assms have 
      "{xG. A`fst(p),x = snd(p)}  G" and  "{xG. A`x,fst(p) = snd(p)}  G"
      unfolding IsAquasigroup_def HasLatinSquareProp_def HasLeftDiv_def HasRightDiv_def
      using ZF1_1_L9(2) by auto
  } then show  "LeftDiv(G,A):G×GG" and "RightDiv(G,A):G×GG" 
    unfolding LeftDiv_def RightDiv_def using ZF_fun_from_total by auto
qed

text We will use multiplicative notation for the quasigroup operation. The right and left division will
  be denoted $a/b$ and $a\backslash b$, resp.

locale quasigroup0 =
  fixes G A
  assumes qgroupassum: "IsAquasigroup(G,A)"

  fixes qgroper (infixl "" 70)
  defines qgroper_def[simp]: "xy  A`x,y"

  fixes leftdiv (infixl "\<ld>" 70)
  defines leftdiv_def[simp]: "x\<ld>y LeftDiv(G,A)`x,y"

  fixes rightdiv (infixl "\<rd>" 70)
  defines rightdiv_def[simp]:"x\<rd>y RightDiv(G,A)`y,x"

text The quasigroup operation is closed on $G$. 

lemma (in quasigroup0) qg_op_closed: assumes "xG" "yG"
  shows "xy  G"
  using qgroupassum assms IsAquasigroup_def apply_funtype by auto

text A couple of properties of right and left division: 

lemma (in quasigroup0) lrdiv_props: assumes "xG" "yG"
  shows 
  "∃!z. zG  zx = y" "y\<rd>x  G" "(y\<rd>x)x = y" and
  "∃!z. zG  xz = y" "x\<ld>y  G" "x(x\<ld>y) = y"
proof -
  let ?zr = "{zG. zx = y}"
  from qgroupassum have I: "RightDiv(G,A):G×GG" using lrdiv_binop(2) by simp
  with assms have "RightDiv(G,A)`x,y = ?zr"
    unfolding RightDiv_def using ZF_fun_from_tot_val by auto
  moreover
  from qgroupassum assms show "∃!z. zG  zx = y"
    unfolding IsAquasigroup_def HasLatinSquareProp_def HasRightDiv_def by simp
  then have "?zrx = y" by (rule ZF1_1_L9)
  ultimately show "(y\<rd>x)x = y" by simp
  let ?zl = "{zG. xz = y}"
  from qgroupassum have II: "LeftDiv(G,A):G×GG" using lrdiv_binop(1) by simp
  with assms have "LeftDiv(G,A)`x,y = ?zl"
    unfolding LeftDiv_def using ZF_fun_from_tot_val by auto
  moreover
  from qgroupassum assms show "∃!z. zG  xz = y"
    unfolding IsAquasigroup_def HasLatinSquareProp_def HasLeftDiv_def by simp
  then have "x?zl = y" by (rule ZF1_1_L9)
  ultimately show "x(x\<ld>y) = y" by simp
  from assms I II show "y\<rd>x  G" and "x\<ld>y  G" using apply_funtype by auto
qed

text We can cancel the left element on both sides of an equation. 

lemma (in quasigroup0) qg_cancel_left: 
  assumes "xG" "yG" "zG" and "xy = xz"
  shows "y=z"
  using qgroupassum assms qg_op_closed lrdiv_props(4) by blast

text We can cancel the right element on both sides of an equation. 

lemma (in quasigroup0) qg_cancel_right: 
  assumes "xG" "yG" "zG" and "yx = zx"
  shows "y=z"
  using qgroupassum assms qg_op_closed lrdiv_props(1) by blast

text Two additional identities for right and left division: 

lemma (in quasigroup0) lrdiv_ident: assumes "xG" "yG"
  shows "(yx)\<rd>x = y" and "x\<ld>(xy) = y"
proof -
  from assms have "(yx)\<rd>x  G" and "((yx)\<rd>x)x = yx"
    using qg_op_closed lrdiv_props(2,3) by auto
  with assms show "(yx)\<rd>x = y" using qg_cancel_right by simp
  from assms have "x\<ld>(xy)  G" and "x(x\<ld>(xy)) = xy"
    using qg_op_closed lrdiv_props(5,6) by auto
  with assms show "x\<ld>(xy) = y" using qg_cancel_left by simp
qed
  
end