Theory OrderedGroup_ZF

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

    Copyright (C) 2005, 2006  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 Ordered groups - introduction

theory OrderedGroup_ZF imports Group_ZF_1 AbelianGroup_ZF Finite_ZF_1 OrderedLoop_ZF

begin

textThis theory file defines and shows the basic properties of (partially
  or linearly) ordered groups. 
  We show that in linearly ordered groups finite sets are bounded 
  and provide a sufficient condition for bounded sets to be finite. This 
  allows to show in Int_ZF_IML.thy› that subsets of integers are 
  bounded iff they are finite.
  Some theorems proven here are properties of ordered loops rather that groups.
  However, for now the development is independent from the material in the OrderedLoop_ZF› theory,
  we just import the definitions of NonnegativeSet› and PositiveSet› from there.

subsectionOrdered groups

textThis section defines ordered groups and various related notions.

textAn ordered group is a group equipped with a partial order that is
  "translation invariant", that is if $a\leq b$ then $a\cdot g \leq b\cdot g$
  and $g\cdot a \leq g\cdot b$.

definition
  "IsAnOrdGroup(G,P,r)  
  (IsAgroup(G,P)  rG×G  IsPartOrder(G,r)  (gG. a b. 
  a,b  r  P` a,g,P` b,g   r   P` g,a,P` g,b   r ) )"


textWe also define 
  the absolute value as a ZF-function that is the 
  identity on $G^+$ and the group inverse on the rest of the group.

definition
  "AbsoluteValue(G,P,r)  id(Nonnegative(G,P,r))  
  restrict(GroupInv(G,P),G - Nonnegative(G,P,r))"

textThe odd functions are defined as those having property 
  $f(a^{-1})=(f(a))^{-1}$. This looks a bit strange in the 
  multiplicative notation, I have to admit.
  For linearly ordered groups a function $f$ defined on the set of positive
  elements iniquely defines an odd function of the whole group. This function
  is called an odd extension of $f$

definition
  "OddExtension(G,P,r,f)  
  (f  {a, GroupInv(G,P)`(f`(GroupInv(G,P)`(a))). 
  a  GroupInv(G,P)``(PositiveSet(G,P,r))}  
  {TheNeutralElement(G,P),TheNeutralElement(G,P)})"

textWe will use a similar notation for ordered groups as for the generic 
  groups. G+ denotes the set of nonnegative elements 
  (that satisfy $1\leq a$) and G+ is the set of (strictly) positive
  elements. \<sm>A› is the set inverses of elements from $A$. I hope 
  that using additive notation for this notion is not too shocking here. 
  The symbol f°› denotes the odd extension of $f$. For a function
  defined on $G_+$ this is the unique odd function on $G$ that is 
  equal to $f$ on $G_+$.

locale group3 =

  fixes G and P and r

  assumes ordGroupAssum: "IsAnOrdGroup(G,P,r)"

  fixes unit ("𝟭")
  defines unit_def [simp]: "𝟭  TheNeutralElement(G,P)"

  fixes groper (infixl "" 70)
  defines groper_def [simp]: "a  b  P` a,b"

  fixes inv ("_¯ " [90] 91)
  defines inv_def [simp]: "x¯  GroupInv(G,P)`(x)"

  fixes lesseq (infix "\<lsq>" 68)
  defines lesseq_def [simp]: "a \<lsq> b   a,b  r"

  fixes sless (infix "\<ls>" 68)
  defines sless_def [simp]: "a \<ls> b  a\<lsq>b  ab"

  fixes nonnegative ("G+")
  defines nonnegative_def [simp]: "G+  Nonnegative(G,P,r)"

  fixes positive ("G+")
  defines positive_def [simp]: "G+  PositiveSet(G,P,r)"
  
  fixes setinv ("\<sm> _" 72)
  defines setninv_def [simp]: "\<sm>A  GroupInv(G,P)``(A)"

  fixes abs ("¦ _ ¦")
  defines abs_def [simp]: "¦a¦  AbsoluteValue(G,P,r)`(a)"

  fixes oddext ("_ °")
  defines oddext_def [simp]: "f°  OddExtension(G,P,r,f)"


textIn group3› context we can use the theorems proven in the 
  group0› context.

lemma (in group3) OrderedGroup_ZF_1_L1: shows "group0(G,P)"
  using ordGroupAssum IsAnOrdGroup_def group0_def by simp

textOrdered group (carrier) is not empty. This is a property of
  monoids, but it is good to have it handy in the group3› context.

lemma (in group3) OrderedGroup_ZF_1_L1A: shows "G0"
  using OrderedGroup_ZF_1_L1 group0.group0_2_L1 monoid0.group0_1_L3A
  by blast
  
textThe next lemma is just to see the definition of the nonnegative set
  in our notation.

lemma (in group3) OrderedGroup_ZF_1_L2: 
  shows "gG+  𝟭\<lsq>g"
  using ordGroupAssum IsAnOrdGroup_def Nonnegative_def 
  by auto

textThe next lemma is just to see the definition of the positive set
  in our notation.

lemma (in group3) OrderedGroup_ZF_1_L2A: 
  shows "gG+  (𝟭\<lsq>g  g𝟭)"
  using ordGroupAssum IsAnOrdGroup_def PositiveSet_def 
  by auto

textFor total order if $g$ is not in $G^{+}$, then it has to be 
  less or equal the unit.

lemma (in group3) OrderedGroup_ZF_1_L2B: 
  assumes A1: "r {is total on} G" and A2: "aG-G+"
  shows "a\<lsq>𝟭"
proof -
  from A2 have "aG"   "𝟭  G"  "¬(𝟭\<lsq>a)" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2 OrderedGroup_ZF_1_L2 
    by auto
  with A1 show ?thesis using IsTotal_def by auto
qed

textThe group order is reflexive.

lemma (in group3) OrderedGroup_ZF_1_L3: assumes "gG"
  shows "g\<lsq>g"
  using ordGroupAssum assms IsAnOrdGroup_def IsPartOrder_def refl_def
  by simp

text$1$ is nonnegative.

lemma (in group3) OrderedGroup_ZF_1_L3A: shows "𝟭G+"
  using OrderedGroup_ZF_1_L2 OrderedGroup_ZF_1_L3
    OrderedGroup_ZF_1_L1 group0.group0_2_L2 by simp
  
textIn this context $a \leq b$ implies that both $a$ and $b$ belong 
  to $G$.

lemma (in group3) OrderedGroup_ZF_1_L4: 
  assumes "a\<lsq>b" shows "aG" "bG"
  using ordGroupAssum assms IsAnOrdGroup_def by auto

textSimilarly in this context $a \le b$ implies that both $a$ and $b$ belong 
  to $G$.

lemma (in group3) less_are_members: 
  assumes "a\<ls>b" shows "aG" "bG"
  using ordGroupAssum assms IsAnOrdGroup_def by auto

textIt is good to have transitivity handy.

lemma (in group3) Group_order_transitive:
  assumes A1: "a\<lsq>b"  "b\<lsq>c" shows "a\<lsq>c"
proof -
  from ordGroupAssum have "trans(r)"
    using IsAnOrdGroup_def IsPartOrder_def
    by simp
  moreover from A1 have " a,b  r   b,c  r" by simp
  ultimately have " a,c  r" by (rule Fol1_L3)
  thus ?thesis by simp
qed

textThe order in an ordered group is antisymmetric.

lemma (in group3) group_order_antisym:
  assumes A1: "a\<lsq>b"  "b\<lsq>a" shows "a=b"
proof -
  from ordGroupAssum A1 have 
    "antisym(r)"  " a,b  r"  " b,a  r"
    using IsAnOrdGroup_def IsPartOrder_def by auto
  then show "a=b" by (rule Fol1_L4) 
qed

textTransitivity for the strict order: if $a < b$ and $b\leq c$, then $a < c$.

lemma (in group3) OrderedGroup_ZF_1_L4A:
  assumes A1: "a\<ls>b"  and A2: "b\<lsq>c"
  shows "a\<ls>c"
proof -
  from A1 A2 have "a\<lsq>b"  "b\<lsq>c" by auto
  then have "a\<lsq>c" by (rule Group_order_transitive)
  moreover from A1 A2 have "ac" using group_order_antisym by auto
  ultimately show "a\<ls>c" by simp
qed

textAnother version of transitivity for the strict order: 
  if $a\leq b$ and $b < c$, then $a < c$.

lemma (in group3) group_strict_ord_transit:
  assumes A1: "a\<lsq>b" and A2: "b\<ls>c"
  shows "a\<ls>c"
proof -
  from A1 A2 have "a\<lsq>b"  "b\<lsq>c" by auto
  then have  "a\<lsq>c" by (rule Group_order_transitive)
  moreover from A1 A2 have "ac" using group_order_antisym by auto
  ultimately show "a\<ls>c" by simp
qed

textThe order is translation invariant. 

lemma (in group3) ord_transl_inv: assumes "a\<lsq>b" "cG"
  shows "ac \<lsq> bc" and "ca \<lsq> cb"
  using ordGroupAssum assms unfolding IsAnOrdGroup_def by auto

textStrict order is preserved by translations.

lemma (in group3) group_strict_ord_transl_inv: 
  assumes "a\<ls>b" and "cG"
  shows "ac \<ls> bc" and "ca \<ls> cb"
  using assms ord_transl_inv OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 group0.group0_2_L19 
  by auto

textIf the group order is total, then the group is ordered linearly.

lemma (in group3) group_ord_total_is_lin:
  assumes "r {is total on} G"
  shows "IsLinOrder(G,r)"
  using assms ordGroupAssum IsAnOrdGroup_def Order_ZF_1_L3
  by simp

textFor linearly ordered groups elements in the nonnegative set are
  greater than those in the complement.

lemma (in group3) OrderedGroup_ZF_1_L4B:
  assumes "r {is total on} G" 
  and "aG+" and "b  G-G+"
  shows "b\<lsq>a"
proof -
  from assms have "b\<lsq>𝟭" "𝟭\<lsq>a"
    using OrderedGroup_ZF_1_L2 OrderedGroup_ZF_1_L2B by auto
  then show ?thesis by (rule Group_order_transitive)
qed

textIf $a\leq 1$ and $a\neq 1$, then $a \in G\setminus G^{+}$.

lemma (in group3) OrderedGroup_ZF_1_L4C:
  assumes A1: "a\<lsq>𝟭" and A2: "a𝟭"
  shows "a  G-G+"
proof - 
  { assume "a  G-G+" 
    with ordGroupAssum A1 A2 have False 
      using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L2
	OrderedGroup_ZF_1_L4 IsAnOrdGroup_def IsPartOrder_def antisym_def
      by auto
  } thus ?thesis by auto
qed

textAn element smaller than an element in $G\setminus G^+$ is in 
  $G\setminus G^+$.

lemma (in group3) OrderedGroup_ZF_1_L4D:
  assumes A1: "aG-G+" and A2: "b\<lsq>a"
  shows "bG-G+"
proof - 
  { assume "b  G - G+"
    with A2 have "𝟭\<lsq>b" "b\<lsq>a"
      using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L2 by auto
    then have "𝟭\<lsq>a" by (rule Group_order_transitive)
    with A1 have False using OrderedGroup_ZF_1_L2 by simp
  } thus ?thesis by auto
qed

textThe nonnegative set is contained in the group.

lemma (in group3) OrderedGroup_ZF_1_L4E: shows "G+  G"
  using OrderedGroup_ZF_1_L2 OrderedGroup_ZF_1_L4 by auto

textThe positive set is contained in the nonnegative set, hence in the group.

lemma (in group3) pos_set_in_gr: shows "G+  G+" and "G+  G"
  using OrderedGroup_ZF_1_L2A OrderedGroup_ZF_1_L2 OrderedGroup_ZF_1_L4E
  by auto  

textTaking the inverse on both sides reverses the inequality.

lemma (in group3) OrderedGroup_ZF_1_L5:
  assumes A1: "a\<lsq>b" shows "b¯\<lsq>a¯"
proof -
  from A1 have T1: "aG" "bG" "a¯G" "b¯G" 
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 
      group0.inverse_in_group by auto
  with A1 ordGroupAssum have "aa¯\<lsq>ba¯" using IsAnOrdGroup_def
    by simp
  with T1 ordGroupAssum have "b¯𝟭\<lsq>b¯(ba¯)"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L6 IsAnOrdGroup_def
    by simp
  with T1 show ?thesis using
    OrderedGroup_ZF_1_L1 group0.group0_2_L2 group0.group_oper_assoc
    group0.group0_2_L6 by simp
qed

textIf an element is smaller that the unit, then its inverse is greater.

lemma (in group3) OrderedGroup_ZF_1_L5A: 
  assumes A1: "a\<lsq>𝟭" shows "𝟭\<lsq>a¯"
proof -
  from A1 have "𝟭¯\<lsq>a¯" using OrderedGroup_ZF_1_L5
    by simp
  then show ?thesis using OrderedGroup_ZF_1_L1 group0.group_inv_of_one 
    by simp
qed

textIf an the inverse of an element is greater that the unit, 
  then the element is smaller.

lemma (in group3) OrderedGroup_ZF_1_L5AA: 
  assumes A1: "aG" and A2: "𝟭\<lsq>a¯"  
  shows "a\<lsq>𝟭"
proof -
  from A2 have "(a¯)¯\<lsq>𝟭¯" using OrderedGroup_ZF_1_L5
    by simp
  with A1 show "a\<lsq>𝟭"
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv group0.group_inv_of_one
    by simp
qed

textIf an element is nonnegative, then the inverse is 
  not greater that the unit.
  Also shows that nonnegative elements cannot be negative

lemma (in group3) OrderedGroup_ZF_1_L5AB:
  assumes A1: "𝟭\<lsq>a" shows "a¯\<lsq>𝟭" and "¬(a\<lsq>𝟭  a𝟭)"
proof -
  from A1 have "a¯\<lsq>𝟭¯"
    using OrderedGroup_ZF_1_L5 by simp
  then show "a¯\<lsq>𝟭" using OrderedGroup_ZF_1_L1 group0.group_inv_of_one
    by simp
  { assume "a\<lsq>𝟭" and "a𝟭"
    with A1 have False using group_order_antisym
      by blast
  } then show "¬(a\<lsq>𝟭  a𝟭)" by auto
qed

textIf two elements are greater or equal than the unit, then the inverse
  of one is not greater than the other.

lemma (in group3) OrderedGroup_ZF_1_L5AC:
  assumes A1: "𝟭\<lsq>a"  "𝟭\<lsq>b"
  shows "a¯ \<lsq> b"
proof -
  from A1 have "a¯\<lsq>𝟭"  "𝟭\<lsq>b"
    using OrderedGroup_ZF_1_L5AB by auto
  then show "a¯ \<lsq> b" by (rule Group_order_transitive)
qed

subsectionInequalities

textThis section developes some simple tools to deal with inequalities.


textTaking negative on both sides reverses the inequality, case with
  an inverse on one side.

lemma (in group3) OrderedGroup_ZF_1_L5AD:
  assumes A1: "b  G" and A2: "a\<lsq>b¯"
  shows "b \<lsq> a¯"
proof -
  from A2 have "(b¯)¯ \<lsq> a¯"
    using OrderedGroup_ZF_1_L5 by simp
  with A1 show "b \<lsq> a¯"
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
    by simp
qed

textWe can cancel the same element on both sides of an inequality.

lemma (in group3) OrderedGroup_ZF_1_L5AE:
  assumes A1: "aG"  "bG"  "cG" and A2: "ab \<lsq> ac"
  shows "b\<lsq>c"
proof -
  from ordGroupAssum A1 A2 have "a¯(ab) \<lsq> a¯(ac)"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group IsAnOrdGroup_def 
    by simp
  with A1 show "b\<lsq>c" 
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
qed

textWe can cancel the same element on both sides of an inequality, right side.

lemma (in group3) ineq_cancel_right:
  assumes "aG"  "bG"  "cG" and "ab \<lsq> cb"
  shows "a\<lsq>c"
proof -
  from assms(2,4) have "(ab)b¯ \<lsq> (cb)b¯"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group ord_transl_inv(1) by simp
  with assms(1,2,3) show "a\<lsq>c" using OrderedGroup_ZF_1_L1 group0.inv_cancel_two(2) 
    by auto
qed

textWe can cancel the same element on both sides of an inequality,
  a version with an inverse on both sides.

lemma (in group3) OrderedGroup_ZF_1_L5AF:
  assumes A1: "aG"  "bG"  "cG" and A2: "ab¯ \<lsq> ac¯"
  shows "c\<lsq>b"
proof -
  from A1 A2 have "(c¯)¯ \<lsq> (b¯)¯"
     using OrderedGroup_ZF_1_L1 group0.inverse_in_group 
      OrderedGroup_ZF_1_L5AE OrderedGroup_ZF_1_L5 by simp
  with A1 show "c\<lsq>b" 
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv by simp
qed

textTaking negative on both sides reverses the inequality, another case with
  an inverse on one side.

lemma (in group3) OrderedGroup_ZF_1_L5AG:
  assumes A1: "a  G" and A2: "a¯\<lsq>b"
  shows "b¯ \<lsq> a"
proof -
  from A2 have "b¯ \<lsq> (a¯)¯"
    using OrderedGroup_ZF_1_L5 by simp
  with A1 show "b¯ \<lsq> a"
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
    by simp
qed
  
textWe can multiply the sides of two inequalities.

lemma (in group3) OrderedGroup_ZF_1_L5B:
  assumes A1: "a\<lsq>b" and A2: "c\<lsq>d"
  shows "ac \<lsq> bd"
proof -
  from A1 A2 have "cG" "bG" using OrderedGroup_ZF_1_L4 by auto
  with A1 A2 ordGroupAssum have "ac\<lsq> bc" "bc\<lsq>bd"
    using IsAnOrdGroup_def by auto
  then show "ac \<lsq> bd" by (rule Group_order_transitive)
qed

textWe can replace first of the factors on one side of an inequality 
  with a greater one.

lemma (in group3) OrderedGroup_ZF_1_L5C: 
  assumes A1: "cG" and A2: "a\<lsq>bc" and A3: "b\<lsq>b1" 
  shows "a\<lsq>b1c"
proof -
  from A1 A3 have "bc \<lsq> b1c"
    using OrderedGroup_ZF_1_L3 OrderedGroup_ZF_1_L5B by simp
  with A2 show "a\<lsq>b1c" by (rule Group_order_transitive)
qed

textWe can replace second of the factors on one side of an inequality 
  with a greater one.

lemma (in group3) OrderedGroup_ZF_1_L5D: 
  assumes A1: "bG" and A2: "a \<lsq> bc" and A3: "c\<lsq>b1" 
  shows "a \<lsq> bb1"
proof -
  from A1 A3 have "bc \<lsq> bb1"
    using OrderedGroup_ZF_1_L3 OrderedGroup_ZF_1_L5B by auto
  with A2 show "a\<lsq>bb1" by (rule Group_order_transitive)
qed

textWe can replace factors on one side of an inequality 
  with greater ones.

lemma (in group3) OrderedGroup_ZF_1_L5E: 
  assumes A1: "a \<lsq> bc" and A2: "b\<lsq>b1"  "c\<lsq>c1"  
  shows "a \<lsq> b1c1"
proof -
  from A2 have "bc \<lsq> b1c1" using OrderedGroup_ZF_1_L5B 
    by simp
  with A1 show "a\<lsq>b1c1" by (rule Group_order_transitive)
qed

textWe don't decrease an element of the group by multiplying by one that is
  nonnegative.

lemma (in group3) OrderedGroup_ZF_1_L5F:
  assumes A1: "𝟭\<lsq>a" and A2: "bG"
  shows "b\<lsq>ab"  "b\<lsq>ba" 
proof -
  from ordGroupAssum A1 A2 have  
    "𝟭b\<lsq>ab"  "b𝟭\<lsq>ba"
    using IsAnOrdGroup_def by auto
  with A2 show "b\<lsq>ab"  "b\<lsq>ba"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by auto
qed

textWe can multiply the right hand side of an inequality by a nonnegative
  element.

lemma (in group3) OrderedGroup_ZF_1_L5G: assumes A1: "a\<lsq>b"
  and A2: "𝟭\<lsq>c" shows "a\<lsq>bc"  "a\<lsq>cb" 
proof -
  from A1 A2 have I: "b\<lsq>bc"  and II: "b\<lsq>cb"
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L5F by auto
  from A1 I show "a\<lsq>bc" by (rule Group_order_transitive)
  from A1 II show "a\<lsq>cb" by (rule Group_order_transitive)
qed

textWe can put two elements on the other side of inequality, 
  changing their sign.

lemma (in group3) OrderedGroup_ZF_1_L5H: 
  assumes A1: "aG"  "bG" and A2: "ab¯ \<lsq> c"
  shows 
  "a \<lsq> cb"
  "c¯a \<lsq> b"
proof -
  from A2 have T: "cG"  "c¯  G"
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 
      group0.inverse_in_group by auto
  from ordGroupAssum A1 A2 have "ab¯b \<lsq> cb"
    using IsAnOrdGroup_def by simp
  with A1 show "a \<lsq> cb" 
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
  with ordGroupAssum A2 T have "c¯a \<lsq> c¯(cb)"
    using IsAnOrdGroup_def by simp
  with A1 T show "c¯a \<lsq> b"  
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
qed

textWe can multiply the sides of one inequality by inverse of another.

lemma (in group3) OrderedGroup_ZF_1_L5I: 
  assumes "a\<lsq>b" and "c\<lsq>d"
  shows "ad¯ \<lsq> bc¯"
  using assms OrderedGroup_ZF_1_L5 OrderedGroup_ZF_1_L5B
  by simp

textWe can put an element on the other side of an inequality
  changing its sign, version with the inverse.

lemma (in group3) OrderedGroup_ZF_1_L5J:
  assumes A1: "aG"  "bG" and A2: "c \<lsq> ab¯"
  shows "cb \<lsq> a"
proof -
  from ordGroupAssum A1 A2 have "cb \<lsq> ab¯b"
    using IsAnOrdGroup_def by simp
  with A1 show "cb \<lsq> a" 
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
qed

textWe can put an element on the other side of an inequality
  changing its sign, version with the inverse.

lemma (in group3) OrderedGroup_ZF_1_L5JA:
  assumes A1: "aG"  "bG" and A2: "c \<lsq> a¯b"
  shows "ac\<lsq> b"
proof -
  from ordGroupAssum A1 A2 have "ac \<lsq> a(a¯b)"
    using IsAnOrdGroup_def by simp
  with A1 show "ac\<lsq> b" 
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
qed
    

textA special case of OrderedGroup_ZF_1_L5J› where $c=1$.

corollary (in group3) OrderedGroup_ZF_1_L5K: 
  assumes A1: "aG"  "bG" and A2: "𝟭 \<lsq> ab¯"
  shows "b \<lsq> a"
proof -
  from A1 A2 have "𝟭b \<lsq> a"
    using OrderedGroup_ZF_1_L5J by simp
  with A1 show "b \<lsq> a"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
qed

textA special case of OrderedGroup_ZF_1_L5JA› where $c=1$.

corollary (in group3) OrderedGroup_ZF_1_L5KA: 
  assumes A1: "aG"  "bG" and A2: "𝟭 \<lsq> a¯b"
  shows "a \<lsq> b"
proof -
  from A1 A2 have "a𝟭 \<lsq> b"
    using OrderedGroup_ZF_1_L5JA by simp
  with A1 show "a \<lsq> b"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
qed

textIf the order is total, the elements that do not belong
  to the positive set are negative. We also show here that the group inverse
  of an element that does not belong to the nonnegative set does belong to the
  nonnegative set.

lemma (in group3) OrderedGroup_ZF_1_L6: 
  assumes A1: "r {is total on} G" and A2: "aG-G+"
  shows "a\<lsq>𝟭"  "a¯  G+"  "restrict(GroupInv(G,P),G-G+)`(a)  G+" 
proof - 
  from A2 have T1: "aG" "aG+" "𝟭G" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2 by auto
  with A1 show "a\<lsq>𝟭" using OrderedGroup_ZF_1_L2 IsTotal_def
    by auto
  then show "a¯  G+" using OrderedGroup_ZF_1_L5A OrderedGroup_ZF_1_L2
    by simp
  with A2 show "restrict(GroupInv(G,P),G-G+)`(a)  G+"
    using restrict by simp
qed

textIf a property is invariant with respect to taking the inverse
  and it is true on the nonnegative set, than it is true on the whole
  group.

lemma (in group3) OrderedGroup_ZF_1_L7:
  assumes A1: "r {is total on} G"
  and A2: "aG+.bG+. Q(a,b)"
  and A3: "aG.bG. Q(a,b)Q(a¯,b)"
  and A4: "aG.bG. Q(a,b)Q(a,b¯)"
  and A5: "aG" "bG"
  shows "Q(a,b)"
proof -
  { assume A6: "aG+" have "Q(a,b)"
    proof -
      { assume "bG+" 
	with A6 A2 have "Q(a,b)" by simp }
      moreover
      { assume "bG+"
	with A1 A2 A4 A5 A6 have "Q(a,(b¯)¯)"  
	  using OrderedGroup_ZF_1_L6 OrderedGroup_ZF_1_L1 group0.inverse_in_group
	  by simp
	with A5 have "Q(a,b)" using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
	  by simp }
      ultimately show "Q(a,b)" by auto
    qed }
  moreover
  { assume "aG+"
    with A1 A5 have T1: "a¯  G+" using OrderedGroup_ZF_1_L6 by simp
    have "Q(a,b)"
    proof -
      { assume "bG+"
	with A2 A3 A5 T1 have "Q((a¯)¯,b)" 
	  using OrderedGroup_ZF_1_L1 group0.inverse_in_group by simp
	with A5 have "Q(a,b)" using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
	  by simp }
      moreover
      { assume "bG+"
	with A1 A2 A3 A4 A5 T1 have "Q((a¯)¯,(b¯)¯)"
	  using OrderedGroup_ZF_1_L6 OrderedGroup_ZF_1_L1 group0.inverse_in_group
	  by simp
	with A5 have "Q(a,b)" using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
	  by simp }
      ultimately show "Q(a,b)" by auto
    qed }
  ultimately show "Q(a,b)" by auto
qed

textA lemma about splitting the ordered group "plane" into 6 subsets. Useful
  for proofs by cases.

lemma (in group3) OrdGroup_6cases: assumes A1: "r {is total on} G" 
  and A2:  "aG"  "bG"
  shows 
  "𝟭\<lsq>a  𝟭\<lsq>b    a\<lsq>𝟭  b\<lsq>𝟭    
  a\<lsq>𝟭  𝟭\<lsq>b  𝟭 \<lsq> ab   a\<lsq>𝟭  𝟭\<lsq>b  ab \<lsq> 𝟭    
  𝟭\<lsq>a  b\<lsq>𝟭  𝟭 \<lsq> ab    𝟭\<lsq>a  b\<lsq>𝟭  ab \<lsq> 𝟭"
proof -
  from A1 A2 have 
    "𝟭\<lsq>a  a\<lsq>𝟭"   
    "𝟭\<lsq>b  b\<lsq>𝟭"
    "𝟭 \<lsq> ab  ab \<lsq> 𝟭"
    using OrderedGroup_ZF_1_L1 group0.group_op_closed group0.group0_2_L2
      IsTotal_def by auto
  then show ?thesis by auto
qed

textThe next lemma shows what happens when one element of a totally 
  ordered group is not greater or equal than another.

lemma (in group3) OrderedGroup_ZF_1_L8:
  assumes A1: "r {is total on} G"
  and A2: "aG"  "bG"
  and A3: "¬(a\<lsq>b)"
  shows "b \<lsq> a"  "a¯ \<lsq> b¯"  "ab"  "b\<ls>a"
 
proof -
  from A1 A2 A3 show I: "b \<lsq> a" using IsTotal_def
    by auto
  then show "a¯ \<lsq> b¯" using OrderedGroup_ZF_1_L5 by simp
  from A2 have "a \<lsq> a" using OrderedGroup_ZF_1_L3 by simp
  with I A3 show "ab"  "b \<ls> a" by auto
qed

textIf one element is greater or equal and not equal to another,
  then it is not smaller or equal.

lemma (in group3) OrderedGroup_ZF_1_L8AA: 
  assumes A1: "a\<lsq>b" and A2: "ab"
  shows "¬(b\<lsq>a)"
proof -
  { note A1
    moreover assume "b\<lsq>a"
    ultimately have "a=b" by (rule group_order_antisym)
    with A2 have False by simp
  } thus "¬(b\<lsq>a)" by auto
qed

textA special case of OrderedGroup_ZF_1_L8› when one of 
  the elements is the unit.

corollary (in group3) OrderedGroup_ZF_1_L8A:
  assumes A1: "r {is total on} G"
  and A2: "aG" and A3: "¬(𝟭\<lsq>a)"
  shows "𝟭 \<lsq> a¯"  "𝟭a"  "a\<lsq>𝟭"
proof -
  from A1 A2 A3 have I:
    "r {is total on} G"
    "𝟭G"  "aG"
     "¬(𝟭\<lsq>a)"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by auto
  then have "𝟭¯ \<lsq> a¯"
    by (rule OrderedGroup_ZF_1_L8)
  then show "𝟭 \<lsq> a¯"
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_one by simp
  from I show "𝟭a" by (rule OrderedGroup_ZF_1_L8)
  from A1 I show "a\<lsq>𝟭" using IsTotal_def
    by auto
qed

textA negative element can not be nonnegative.

lemma (in group3) OrderedGroup_ZF_1_L8B:
  assumes A1: "a\<lsq>𝟭"  and A2: "a𝟭" shows "¬(𝟭\<lsq>a)"
proof -
  { assume  "𝟭\<lsq>a" 
    with A1 have "a=𝟭" using group_order_antisym
      by auto
    with A2 have False by simp
  } thus ?thesis by auto
qed

textAn element is greater or equal than another iff the difference is 
  nonpositive.

lemma (in group3) OrderedGroup_ZF_1_L9:
  assumes A1: "aG"  "bG"
  shows "a\<lsq>b  ab¯ \<lsq> 𝟭"
proof
  assume "a \<lsq> b"
  with ordGroupAssum A1 have "ab¯ \<lsq> bb¯"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group
    IsAnOrdGroup_def by simp
  with A1 show "ab¯ \<lsq> 𝟭" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L6
    by simp
next assume A2: "ab¯ \<lsq> 𝟭"
  with ordGroupAssum A1 have "ab¯b \<lsq> 𝟭b"
    using IsAnOrdGroup_def by simp
  with A1 show "a \<lsq> b"
    using OrderedGroup_ZF_1_L1 
      group0.inv_cancel_two group0.group0_2_L2 
    by simp
qed

textWe can move an element to the other side of an inequality.

lemma (in group3) OrderedGroup_ZF_1_L9A:
  assumes A1: "aG"  "bG"  "cG"
  shows "ab \<lsq> c   a \<lsq> cb¯"
proof
  assume "ab \<lsq> c"
  with ordGroupAssum A1 have "abb¯ \<lsq> cb¯"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group IsAnOrdGroup_def
    by simp
  with A1 show "a \<lsq> cb¯"
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two by simp
next assume "a \<lsq> cb¯"
  with ordGroupAssum A1 have "ab \<lsq> cb¯b"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group IsAnOrdGroup_def
    by simp
  with A1 show "ab \<lsq> c"
     using OrderedGroup_ZF_1_L1 group0.inv_cancel_two by simp
qed

textA one side version of the previous lemma with weaker assuptions.

lemma (in group3) OrderedGroup_ZF_1_L9B:
  assumes A1: "aG"  "bG" and A2: "ab¯ \<lsq> c"
  shows "a \<lsq> cb"
proof - 
  from A1 A2 have "aG"  "b¯G"  "cG"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group 
      OrderedGroup_ZF_1_L4 by auto
  with A1 A2 show "a \<lsq> cb"
    using OrderedGroup_ZF_1_L9A OrderedGroup_ZF_1_L1 
      group0.group_inv_of_inv by simp
qed

textWe can put en element on the other side of inequality, 
  changing its sign.

lemma (in group3) OrderedGroup_ZF_1_L9C:
  assumes A1: "aG"  "bG" and A2: "c\<lsq>ab"
  shows 
  "cb¯ \<lsq> a"
  "a¯c \<lsq> b"
proof -
  from ordGroupAssum A1 A2 have
    "cb¯ \<lsq> abb¯"
    "a¯c \<lsq> a¯(ab)"
    using OrderedGroup_ZF_1_L1 group0.inverse_in_group IsAnOrdGroup_def
    by auto
  with A1 show  
    "cb¯ \<lsq> a"
    "a¯c \<lsq> b"
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by auto
qed

textIf an element is greater or equal than another then the difference is 
  nonnegative.

lemma (in group3) OrderedGroup_ZF_1_L9D: assumes A1: "a\<lsq>b"
  shows "𝟭 \<lsq> ba¯"
proof -
  from A1 have T: "aG"  "bG"   "a¯  G" 
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 
      group0.inverse_in_group by auto
  with ordGroupAssum A1 have "aa¯ \<lsq> ba¯"
    using IsAnOrdGroup_def by simp
  with T show "𝟭 \<lsq> ba¯" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L6
    by simp
qed

textIf an element is greater than another then the difference is 
  positive.

lemma (in group3) OrderedGroup_ZF_1_L9E: 
  assumes A1: "a\<lsq>b"  "ab"
  shows "𝟭 \<lsq> ba¯"  "𝟭  ba¯"  "ba¯  G+"
proof -
  from A1 have T: "aG"  "bG" using OrderedGroup_ZF_1_L4
    by auto
  from A1 show I: "𝟭 \<lsq> ba¯" using OrderedGroup_ZF_1_L9D
    by simp
  { assume "ba¯ = 𝟭" 
    with T have "a=b"
      using OrderedGroup_ZF_1_L1 group0.group0_2_L11A
      by auto
    with A1 have False by simp 
  } then show "𝟭  ba¯" by auto
  then have "ba¯  𝟭" by auto
  with I show "ba¯  G+" using OrderedGroup_ZF_1_L2A
    by simp
qed

textIf the difference is nonnegative, then $a\leq b$.

lemma (in group3) OrderedGroup_ZF_1_L9F: 
  assumes A1: "aG"  "bG" and A2: "𝟭 \<lsq> ba¯"
  shows "a\<lsq>b"
proof -
  from A1 A2 have "𝟭a \<lsq> b"
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L9A
    by simp
  with A1 show "a\<lsq>b" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
qed


textIf we increase the middle term in a product, the whole product 
  increases.

lemma (in group3) OrderedGroup_ZF_1_L10: 
  assumes "aG"  "bG" and "c\<lsq>d"
  shows "acb \<lsq> adb"
  using ordGroupAssum assms IsAnOrdGroup_def by simp

textA product of (strictly) positive elements is not the unit.

lemma (in group3) OrderedGroup_ZF_1_L11: 
  assumes A1: "𝟭\<lsq>a"  "𝟭\<lsq>b"
  and A2: "𝟭  a"  "𝟭  b"
  shows "𝟭  ab"
proof -
  from A1 have T1: "aG"  "bG"
    using OrderedGroup_ZF_1_L4 by auto
  { assume "𝟭 = ab"
    with A1 T1 have "a\<lsq>𝟭"  "𝟭\<lsq>a"
      using OrderedGroup_ZF_1_L1 group0.group0_2_L9 OrderedGroup_ZF_1_L5AA 
      by auto
    then have "a = 𝟭" by (rule group_order_antisym)
    with A2 have False by simp
  } then show "𝟭  ab" by auto
qed

textA product of nonnegative elements is nonnegative.

lemma (in group3) OrderedGroup_ZF_1_L12:
  assumes A1: "𝟭 \<lsq> a"  "𝟭 \<lsq> b"
  shows "𝟭 \<lsq> ab"
proof -
  from A1 have "𝟭𝟭 \<lsq> ab"
    using  OrderedGroup_ZF_1_L5B by simp
  then show "𝟭 \<lsq> ab" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2 
    by simp
qed

textIf $a$ is not greater than $b$, then $1$ is not greater than
  $b\cdot a^{-1}$.

lemma (in group3) OrderedGroup_ZF_1_L12A:
  assumes A1: "a\<lsq>b" shows "𝟭 \<lsq> ba¯"
proof -
  from A1 have T: "𝟭  G"  "aG"  "bG" 
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by auto
  with A1 have "𝟭a \<lsq> b" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
  with T show "𝟭 \<lsq> ba¯" using OrderedGroup_ZF_1_L9A
    by simp
qed
  
textWe can move an element to the other side of a strict inequality.

lemma (in group3) OrderedGroup_ZF_1_L12B:  
  assumes A1: "aG"  "bG" and  A2: "ab¯ \<ls> c"
  shows "a \<ls> cb"
proof -
  from A1 A2 have "ab¯b \<ls> cb"
    using group_strict_ord_transl_inv by auto
  moreover from A1 have "ab¯b = a"
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
  ultimately show "a \<ls> cb"
    by auto
qed

(*lemma (in group3) OrderedGroup_ZF_1_L12B:  
  assumes A1: "a∈G"  "b∈G" and  A2: "a⋅b¯ \<lsq> c"  "a⋅b¯ ≠ c"
  shows "a \<lsq> c⋅b"  "a ≠ c⋅b"
proof -
  from A1 A2 have "a⋅b¯⋅b \<lsq> c⋅b"  "a⋅b¯⋅b ≠ c⋅b"
    using group_strict_ord_transl_inv by auto
  moreover from A1 have "a⋅b¯⋅b = a"
    using OrderedGroup_ZF_1_L1 group0.inv_cancel_two
    by simp
  ultimately show "a \<lsq> c⋅b"  "a ≠ c⋅b"
    by auto
qed;*)

textWe can multiply the sides of two inequalities,
  first of them strict and we get a strict inequality.

lemma (in group3) OrderedGroup_ZF_1_L12C:
  assumes A1: "a\<ls>b" and A2: "c\<lsq>d"
  shows "ac \<ls> bd"
proof -
  from A1 A2 have T: "aG"  "bG"  "cG"  "dG"
    using OrderedGroup_ZF_1_L4 by auto
  with ordGroupAssum A2 have "ac \<lsq> ad"
    using IsAnOrdGroup_def by simp
  moreover from A1 T have "ad \<ls> bd"
    using group_strict_ord_transl_inv by simp
  ultimately show "ac \<ls> bd"
    by (rule group_strict_ord_transit)
qed
  
textWe can multiply the sides of two inequalities,
  second of them strict and we get a strict inequality.

lemma (in group3) OrderedGroup_ZF_1_L12D:
  assumes A1: "a\<lsq>b" and A2: "c\<ls>d"
  shows "ac \<ls> bd"
proof -
  from A1 A2 have T: "aG"  "bG"  "cG"  "dG"
    using OrderedGroup_ZF_1_L4 by auto
  with A2 have "ac \<ls> ad" 
    using group_strict_ord_transl_inv by simp
  moreover from ordGroupAssum A1 T have "ad \<lsq> bd"
     using IsAnOrdGroup_def by simp
   ultimately show "ac \<ls> bd"
     by (rule OrderedGroup_ZF_1_L4A)
qed

subsectionThe set of positive elements

textIn this section we study G+ - the set of elements that are 
  (strictly) greater than the unit. The most important result is that every
  linearly ordered group can decomposed into $\{1\}$, G+ and the 
  set of those elements $a\in G$ such that $a^{-1}\in$G+. 
  Another property of linearly ordered groups that we prove here is that 
  if G+$\neq \emptyset$, then it is infinite. This allows to show 
  that nontrivial linearly ordered groups are infinite.

textThe positive set is closed under the group operation.

lemma (in group3) OrderedGroup_ZF_1_L13: shows "G+ {is closed under} P"
proof -
  { fix a b assume "aG+"  "bG+"
    then have T1: "𝟭 \<lsq> ab"   and "𝟭  ab"
      using PositiveSet_def OrderedGroup_ZF_1_L11 OrderedGroup_ZF_1_L12
      by auto
    moreover from T1 have "ab  G"
      using OrderedGroup_ZF_1_L4 by simp
    ultimately have "ab  G+" using PositiveSet_def by simp
  } then show "G+ {is closed under} P" using IsOpClosed_def
    by simp
qed

textFor totally ordered groups every nonunit element is positive or its 
  inverse is positive.

lemma (in group3) OrderedGroup_ZF_1_L14:
  assumes A1: "r {is total on} G" and A2: "aG" 
  shows "a=𝟭  aG+  a¯G+"
proof -
  { assume A3: "a𝟭"
    moreover from A1 A2 have "a\<lsq>𝟭  𝟭\<lsq>a"
      using IsTotal_def OrderedGroup_ZF_1_L1 group0.group0_2_L2
      by simp
    moreover from A3 A2 have T1: "a¯  𝟭"
      using OrderedGroup_ZF_1_L1 group0.group0_2_L8B
      by simp
    ultimately have "a¯G+  aG+"
      using OrderedGroup_ZF_1_L5A OrderedGroup_ZF_1_L2A
      by auto
  } thus "a=𝟭  aG+  a¯G+" by auto
qed

textIf an element belongs to the positive set, then it is not the unit
  and its inverse does not belong to the positive set.

lemma (in group3) OrderedGroup_ZF_1_L15:
   assumes A1: "aG+"  shows "a𝟭"  "a¯G+"
proof -
  from A1 show T1: "a𝟭" using PositiveSet_def by auto
  { assume "a¯  G+" 
    with A1 have "a\<lsq>𝟭"  "𝟭\<lsq>a"
      using OrderedGroup_ZF_1_L5AA PositiveSet_def by auto
    then have "a=𝟭" by (rule group_order_antisym)
    with T1 have False by simp
  } then show "a¯G+" by auto
qed

textIf $a^{-1}$ is positive, then $a$ can not be positive or the unit.

lemma (in group3) OrderedGroup_ZF_1_L16:
  assumes A1: "aG" and A2: "a¯G+" shows "a𝟭"  "aG+"
proof -
  from A2 have "a¯𝟭"  "(a¯)¯  G+"
    using OrderedGroup_ZF_1_L15 by auto
  with A1 show "a𝟭"  "aG+"
    using OrderedGroup_ZF_1_L1 group0.group0_2_L8C group0.group_inv_of_inv 
    by auto
qed

textFor linearly ordered groups each element is either the unit, 
  positive or its inverse is positive.

lemma (in group3) OrdGroup_decomp: 
  assumes A1: "r {is total on} G" and A2: "aG" 
  shows "Exactly_1_of_3_holds (a=𝟭,aG+,a¯G+)"
proof -
  from A1 A2 have "a=𝟭  aG+  a¯G+"
    using OrderedGroup_ZF_1_L14 by simp
  moreover from A2 have "a=𝟭  (aG+  a¯G+)"
    using OrderedGroup_ZF_1_L1 group0.group_inv_of_one
    PositiveSet_def by simp
  moreover from A2 have "aG+  (a𝟭  a¯G+)"
    using OrderedGroup_ZF_1_L15 by simp
  moreover from A2 have "a¯G+  (a𝟭  aG+)"
    using OrderedGroup_ZF_1_L16 by simp
  ultimately show "Exactly_1_of_3_holds (a=𝟭,aG+,a¯G+)"
    by (rule Fol1_L5)
qed

textA if $a$ is a nonunit element that is not positive, then $a^{-1}$ is 
  is positive. This is useful for some proofs by cases.

lemma (in group3) OrdGroup_cases:
  assumes A1: "r {is total on} G" and A2: "aG" 
  and A3: "a𝟭"  "aG+"
  shows "a¯  G+"
proof -
  from A1 A2 have "a=𝟭  aG+  a¯G+"
    using OrderedGroup_ZF_1_L14 by simp
  with A3 show "a¯  G+" by auto
qed
  
textElements from $G\setminus G_+$ are not greater that the unit.

lemma (in group3) OrderedGroup_ZF_1_L17:
  assumes A1: "r {is total on} G" and A2: "a  G-G+"
  shows "a\<lsq>𝟭"
proof -
  { assume "a=𝟭"
    with A2 have "a\<lsq>𝟭" using OrderedGroup_ZF_1_L3 by simp }
  moreover
  { assume "a𝟭"
    with A1 A2 have "a\<lsq>𝟭" 
      using PositiveSet_def OrderedGroup_ZF_1_L8A
      by auto }
  ultimately show "a\<lsq>𝟭" by auto
qed

textThe next lemma allows to split proofs that something holds 
  for all $a\in G$ into cases $a=1$, $a\in G_+$, $-a\in G_+$.

lemma (in group3) OrderedGroup_ZF_1_L18: 
  assumes A1: "r {is total on} G" and A2: "bG"
  and A3: "Q(𝟭)" and A4: "aG+. Q(a)" and A5: "aG+. Q(a¯)"
  shows "Q(b)"
proof -
  from A1 A2 A3 A4 A5 have "Q(b)  Q((b¯)¯)"
    using OrderedGroup_ZF_1_L14 by auto
  with A2 show "Q(b)" using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
    by simp
qed

textAll elements greater or equal than an element of G+
  belong to G+.

lemma (in group3) OrderedGroup_ZF_1_L19:
  assumes A1: "a  G+" and A2: "a\<lsq>b"
  shows "b  G+"
proof -
  from A1 have I: "𝟭\<lsq>a"  and II: "a𝟭"
    using OrderedGroup_ZF_1_L2A by auto
  from I A2 have "𝟭\<lsq>b" by (rule Group_order_transitive)
  moreover have "b𝟭"
  proof -
    { assume "b=𝟭"
      with I A2 have "𝟭\<lsq>a"  "a\<lsq>𝟭"
	by auto
      then have "𝟭=a" by (rule group_order_antisym)
      with II have False by simp
    } then show "b𝟭" by auto
  qed
  ultimately show "b  G+" 
    using OrderedGroup_ZF_1_L2A by simp
qed

textThe inverse of an element of G+ cannot be in G+.

lemma (in group3) OrderedGroup_ZF_1_L20:
  assumes A1: "r {is total on} G" and A2: "a  G+" 
  shows "a¯  G+"
proof -
  from A2 have "aG" using PositiveSet_def
    by simp
  with A1 have "Exactly_1_of_3_holds (a=𝟭,aG+,a¯G+)"
    using OrdGroup_decomp by simp
  with A2 show "a¯  G+" by (rule Fol1_L7)
qed

textThe set of positive elements of a 
  nontrivial linearly ordered group is not empty.

lemma (in group3) OrderedGroup_ZF_1_L21:
  assumes A1: "r {is total on} G" and A2: "G  {𝟭}"
  shows "G+  0"
proof -
  have "𝟭  G" using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
  with A2 obtain a where "aG"  "a𝟭" by auto
  with A1 have "aG+  a¯G+" 
    using OrderedGroup_ZF_1_L14 by auto
  then show "G+  0" by auto
qed

textIf $b\in$G+, then $a < a\cdot b$. 
  Multiplying $a$ by a positive elemnt increases $a$.

lemma (in group3) OrderedGroup_ZF_1_L22:
  assumes A1: "aG"  "bG+"
  shows "a\<lsq>ab"  "a  ab"  "ab  G"
proof -
  from ordGroupAssum A1 have "a𝟭 \<lsq> ab"
    using OrderedGroup_ZF_1_L2A IsAnOrdGroup_def
    by simp
  with A1 show "a\<lsq>ab" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by simp
  then show "ab  G"
    using OrderedGroup_ZF_1_L4 by simp
  { from A1 have "aG"  "bG"  
      using PositiveSet_def by auto
    moreover assume "a = ab"
    ultimately have "b = 𝟭"
      using OrderedGroup_ZF_1_L1 group0.group0_2_L7
      by simp
    with A1 have False using PositiveSet_def
      by simp
  } then show "a  ab" by auto
qed

textIf $G$ is a nontrivial linearly ordered hroup, 
  then for every element of $G$ we can find one in G+ that is
  greater or equal.

lemma (in group3) OrderedGroup_ZF_1_L23: 
  assumes A1: "r {is total on} G" and A2: "G  {𝟭}"
  and A3: "aG"
  shows "bG+. a\<lsq>b"
proof -
  { assume A4: "aG+" then have "a\<lsq>a"
      using PositiveSet_def OrderedGroup_ZF_1_L3
      by simp
    with A4 have "bG+. a\<lsq>b" by auto }
  moreover
  { assume "aG+"
    with A1 A3 have I: "a\<lsq>𝟭" using OrderedGroup_ZF_1_L17
      by simp
    from A1 A2 obtain b where II: "bG+" 
      using OrderedGroup_ZF_1_L21 by auto
    then have "𝟭\<lsq>b" using PositiveSet_def by simp
    with I have "a\<lsq>b" by (rule Group_order_transitive)
    with II have "bG+. a\<lsq>b" by auto }
  ultimately show ?thesis by auto
qed

textThe G+ is G+ plus the unit.
lemma (in group3) OrderedGroup_ZF_1_L24: shows "G+ = G+{𝟭}"
  using OrderedGroup_ZF_1_L2 OrderedGroup_ZF_1_L2A OrderedGroup_ZF_1_L3A
  by auto

textWhat is $-G_+$, really?

lemma (in group3) OrderedGroup_ZF_1_L25: shows 
  "(\<sm>G+) = {a¯. aG+}"
  "(\<sm>G+)  G"
proof -
  from ordGroupAssum have I: "GroupInv(G,P) : GG"
    using IsAnOrdGroup_def group0_2_T2 by simp
  moreover have "G+  G" using PositiveSet_def by auto
  ultimately show 
    "(\<sm>G+) = {a¯. aG+}"
    "(\<sm>G+)  G"
    using func_imagedef func1_1_L6 by auto
qed

textIf the inverse of $a$ is in G+, then $a$ is in the inverse
  of G+.

lemma (in group3) OrderedGroup_ZF_1_L26:
  assumes A1: "aG" and A2: "a¯  G+"
  shows "a  (\<sm>G+)"
proof -
  from A1 have "a¯  G"  "a = (a¯)¯" using OrderedGroup_ZF_1_L1 
    group0.inverse_in_group group0.group_inv_of_inv
    by auto
  with A2 show "a  (\<sm>G+)" using OrderedGroup_ZF_1_L25
    by auto
qed

textIf $a$ is in the inverse of  G+, 
  then its inverse is in $G_+$.

lemma (in group3) OrderedGroup_ZF_1_L27:
  assumes "a  (\<sm>G+)"
  shows "a¯  G+"
  using assms OrderedGroup_ZF_1_L25 PositiveSet_def 
    OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
  by auto

textA linearly ordered group can be decomposed into $G_+$, $\{1\}$ and
  $-G_+$

lemma (in group3) OrdGroup_decomp2: 
  assumes A1: "r {is total on} G"
  shows 
  "G = G+  (\<sm>G+) {𝟭}"
  "G+(\<sm>G+) = 0"
  "𝟭  G+(\<sm>G+)"
proof -
  { fix a assume A2: "aG"
    with A1 have "aG+  a¯G+  a=𝟭"
      using OrderedGroup_ZF_1_L14 by auto
    with A2 have "aG+  a(\<sm>G+)  a=𝟭"
      using OrderedGroup_ZF_1_L26 by auto
    then have "a  (G+  (\<sm>G+) {𝟭})"
      by auto
  } then have "G  G+  (\<sm>G+) {𝟭}"
    by auto
  moreover have "G+  (\<sm>G+) {𝟭}  G"
    using OrderedGroup_ZF_1_L25 PositiveSet_def
      OrderedGroup_ZF_1_L1 group0.group0_2_L2
    by auto
  ultimately show "G = G+  (\<sm>G+) {𝟭}" by auto
  { let ?A = "G+(\<sm>G+)"
    assume "G+(\<sm>G+)  0"
    then have "?A0" by simp
    then obtain a where "a?A" by blast
    then have False using OrderedGroup_ZF_1_L15 OrderedGroup_ZF_1_L27
      by auto
  } then show "G+(\<sm>G+) = 0" by auto
  show "𝟭  G+(\<sm>G+)"
    using OrderedGroup_ZF_1_L27
      OrderedGroup_ZF_1_L1 group0.group_inv_of_one
      OrderedGroup_ZF_1_L2A by auto
qed

textIf $a\cdot b^{-1}$ is nonnegative, then $b \leq a$. This maybe used to
  recover the order from the set of nonnegative elements and serve as a way
  to define order by prescibing that set (see the "Alternative definitions"
  section).

lemma (in group3) OrderedGroup_ZF_1_L28:
  assumes A1: "aG"  "bG" and A2: "ab¯  G+"
  shows "b\<lsq>a"
proof -
  from A2 have "𝟭 \<lsq> ab¯" using OrderedGroup_ZF_1_L2
    by simp
  with A1 show "b\<lsq>a" using OrderedGroup_ZF_1_L5K
    by simp
qed

textA special case of OrderedGroup_ZF_1_L28› when
  $a\cdot b^{-1}$ is positive.

corollary (in group3) OrderedGroup_ZF_1_L29:
  assumes A1: "aG"  "bG" and A2: "ab¯  G+"
  shows "b\<lsq>a"  "ba"
proof -
  from A2 have "𝟭 \<lsq> ab¯" and I: "ab¯  𝟭"
    using OrderedGroup_ZF_1_L2A by auto
  with A1 show "b\<lsq>a" using OrderedGroup_ZF_1_L5K
    by simp
  from A1 I show "ba" 
    using OrderedGroup_ZF_1_L1 group0.group0_2_L6
    by auto
qed

textA bit stronger that OrderedGroup_ZF_1_L29›, adds
   case when two elements are equal.

lemma (in group3) OrderedGroup_ZF_1_L30:
  assumes "aG"  "bG" and "a=b  ba¯  G+"
  shows "a\<lsq>b"
  using assms OrderedGroup_ZF_1_L3 OrderedGroup_ZF_1_L29
  by auto

textA different take on decomposition: we can have $a=b$ or $a<b$
  or $b<a$.

lemma (in group3) OrderedGroup_ZF_1_L31: 
  assumes A1: "r {is total on} G" and A2: "aG"  "bG"
  shows "a=b  (a\<lsq>b  ab)  (b\<lsq>a  ba)"
proof -
  from A2 have "ab¯  G" using OrderedGroup_ZF_1_L1
    group0.inverse_in_group group0.group_op_closed
    by simp
  with A1 have "ab¯ = 𝟭  ab¯  G+  (ab¯)¯  G+"
    using OrderedGroup_ZF_1_L14 by simp
  moreover
  { assume "ab¯ = 𝟭"
    then have "ab¯b = 𝟭b" by simp
    with A2 have "a=b  (a\<lsq>b  ab)  (b\<lsq>a  ba)"
      using OrderedGroup_ZF_1_L1
	group0.inv_cancel_two group0.group0_2_L2 by auto }
  moreover
  { assume "ab¯  G+"
    with A2 have "a=b  (a\<lsq>b  ab)  (b\<lsq>a  ba)"
      using OrderedGroup_ZF_1_L29 by auto }
  moreover
  { assume "(ab¯)¯  G+"
    with A2 have "ba¯  G+" using OrderedGroup_ZF_1_L1
      group0.group0_2_L12 by simp
    with A2 have "a=b  (a\<lsq>b  ab)  (b\<lsq>a  ba)"
      using OrderedGroup_ZF_1_L29 by auto }
  ultimately show "a=b  (a\<lsq>b  ab)  (b\<lsq>a  ba)"
    by auto
qed

subsectionIntervals and bounded sets

textIntervals here are the closed intervals of the form 
 $\{x\in G. a\leq x \leq b \}$.

textA bounded set can be translated to put it in  $G^+$ and then it is 
 still bounded above.

lemma (in group3) OrderedGroup_ZF_2_L1: 
  assumes A1: "gA. L\<lsq>g  g\<lsq>M"
  and A2: "S = RightTranslation(G,P,L¯)" 
  and A3: "a  S``(A)"
  shows "a \<lsq> ML¯"   "𝟭\<lsq>a"
proof -
  from A3 have "A0" using func1_1_L13A by fast
  then obtain g where "gA" by auto
  with A1 have T1: "LG" "MG" "L¯G" 
    using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 
    group0.inverse_in_group by auto
  with A2 have "S : GG" using OrderedGroup_ZF_1_L1 group0.group0_5_L1
    by simp
  moreover from A1 have T2: "AG" using OrderedGroup_ZF_1_L4 by auto
  ultimately have "S``(A) = {S`(b). bA}" using func_imagedef
    by simp
  with A3 obtain b where T3: "bA" "a = S`(b)" by auto
  with A1 ordGroupAssum T1 have "bL¯\<lsq>ML¯" "LL¯\<lsq>bL¯"
    using IsAnOrdGroup_def by auto
  with T3 A2 T1 T2 show "a\<lsq>ML¯" "𝟭\<lsq>a"
    using OrderedGroup_ZF_1_L1 group0.group0_5_L2 group0.group0_2_L6 
    by auto
qed

textEvery bounded set is an image of a subset of an interval that starts at 
  $1$.

lemma (in group3) OrderedGroup_ZF_2_L2:
  assumes A1: "IsBounded(A,r)" 
  shows "B.gG+.TGG. A = T``(B)  B  Interval(r,𝟭,g)"
proof - 
  { assume A2: "A=0" 
    let ?B = "0"
    let ?g = "𝟭"
    let ?T = "ConstantFunction(G,𝟭)"
    have "?gG+" using OrderedGroup_ZF_1_L3A by simp
    moreover have "?T : GG"
      using func1_3_L1 OrderedGroup_ZF_1_L1 group0.group0_2_L2 by simp
    moreover from A2 have "A = T``(?B)" by simp
    moreover have "?B  Interval(r,𝟭,?g)" by simp
    ultimately have
      "B.gG+.TGG. A = T``(B)  B  Interval(r,𝟭,g)"
      by auto }
  moreover
  { assume A3: "A0"
    with A1 have "L. xA. L\<lsq>x" and "U. xA. x\<lsq>U"
      using IsBounded_def IsBoundedBelow_def IsBoundedAbove_def 
      by auto
    then obtain L U where D1: "xA. L\<lsq>x  x\<lsq>U "
      by auto
    with A3 have T1: "AG" using OrderedGroup_ZF_1_L4 by auto
    from A3 obtain a where "aA" by auto
    with D1 have T2: "L\<lsq>a" "a\<lsq>U" by auto
    then have T3: "LG" "L¯ G" "UG" 
      using OrderedGroup_ZF_1_L4 OrderedGroup_ZF_1_L1 
	group0.inverse_in_group by auto
    let ?T = "RightTranslation(G,P,L)"
    let ?B = "RightTranslation(G,P,L¯)``(A)"
    let ?g = "UL¯"
    have "?gG+"
    proof -
      from T2 have "L\<lsq>U" using Group_order_transitive by fast
      with ordGroupAssum T3 have "LL¯\<lsq>?g" 
	using IsAnOrdGroup_def by simp
      with T3 show ?thesis using OrderedGroup_ZF_1_L1 group0.group0_2_L6
	OrderedGroup_ZF_1_L2 by simp
    qed
    moreover from T3 have "?T : GG"
      using OrderedGroup_ZF_1_L1 group0.group0_5_L1
      by simp
    moreover have "A = ?T``(?B)"
    proof -
      from T3 T1 have "?T``(?B) = {aL¯L. aA}"
	using OrderedGroup_ZF_1_L1 group0.group0_5_L6
	by simp
      moreover from T3 T1 have "aA. aL¯L = a(L¯L)"
	using OrderedGroup_ZF_1_L1 group0.group_oper_assoc by auto
      ultimately have "?T``(?B) = {a(L¯L). aA}" by simp
      with T3 have "?T``(?B) = {a𝟭. aA}"
	using OrderedGroup_ZF_1_L1 group0.group0_2_L6 by simp
      moreover from T1 have "aA. a𝟭=a"
	using OrderedGroup_ZF_1_L1 group0.group0_2_L2 by auto
      ultimately show ?thesis by simp
    qed
    moreover have "?B  Interval(r,𝟭,?g)"
    proof
      fix y assume A4: "y  ?B"
      let ?S = "RightTranslation(G,P,L¯)"
      from D1 have T4: "xA. L\<lsq>x  x\<lsq>U" by simp
      moreover have T5: "?S = RightTranslation(G,P,L¯)" 
	by simp 
      moreover from A4 have T6: "y  ?S``(A)" by simp
      ultimately have "y\<lsq>UL¯" using OrderedGroup_ZF_2_L1
	by blast
      moreover from T4 T5 T6 have "𝟭\<lsq>y" by (rule OrderedGroup_ZF_2_L1)
      ultimately show "y  Interval(r,𝟭,?g)" using Interval_def by auto
    qed
    ultimately have
      "B.gG+.TGG. A = T``(B)  B  Interval(r,𝟭,g)"
      by auto }
  ultimately show ?thesis by auto
qed
      
textIf every interval starting at $1$ is finite, then every bounded set is 
  finite. I find it interesting that this does not require the group to be 
  linearly ordered (the order to be total).

theorem (in group3) OrderedGroup_ZF_2_T1:
  assumes A1: "gG+. Interval(r,𝟭,g)  Fin(G)"
  and A2: "IsBounded(A,r)" 
  shows "A  Fin(G)"
proof -
  from A2 have
    "B.gG+.TGG. A = T``(B)  B  Interval(r,𝟭,g)"
    using OrderedGroup_ZF_2_L2 by simp
  then obtain B g T where D1: "gG+" "B  Interval(r,𝟭,g)" 
    and D2: "T : GG" "A = T``(B)" by auto
  from D1 A1 have "BFin(G)" using Fin_subset_lemma by blast
  with D2 show ?thesis using Finite1_L6A by simp
qed

textIn linearly ordered groups finite sets are bounded.

theorem (in group3) ord_group_fin_bounded:
  assumes "r {is total on} G" and "BFin(G)" 
  shows "IsBounded(B,r)"
  using ordGroupAssum assms IsAnOrdGroup_def IsPartOrder_def Finite_ZF_1_T1
  by simp

textFor nontrivial linearly ordered groups  if for every element $G$ 
  we can find one in $A$ 
  that is greater or equal (not necessarily strictly greater), then $A$
  can neither be finite nor bounded above.

lemma (in group3) OrderedGroup_ZF_2_L2A:
  assumes A1: "r {is total on} G" and A2: "G  {𝟭}"
  and A3: "aG. bA. a\<lsq>b"
  shows 
  "aG. bA. ab  a\<lsq>b"
  "¬IsBoundedAbove(A,r)"
  "A  Fin(G)"
proof -
  { fix a
    from A1 A2 obtain c where "c  G+"
      using OrderedGroup_ZF_1_L21 by auto
    moreover assume "aG"
    ultimately have 
      "ac  G"  and I: "a \<ls> ac"
      using OrderedGroup_ZF_1_L22 by auto
    with A3 obtain b where II: "bA"  and III: "ac \<lsq> b"
      by auto
    moreover from I III have "a\<ls>b" by (rule OrderedGroup_ZF_1_L4A)
    ultimately have "bA. ab  a\<lsq>b" by auto
  } thus "aG. bA. ab  a\<lsq>b" by simp
  with ordGroupAssum A1 show 
    "¬IsBoundedAbove(A,r)"
    "A  Fin(G)"
    using IsAnOrdGroup_def IsPartOrder_def 
    OrderedGroup_ZF_1_L1A Order_ZF_3_L14 Finite_ZF_1_1_L3
    by auto
qed


textNontrivial linearly ordered groups are infinite. Recall 
  that Fin(A)› is the collection of finite subsets of $A$. 
  In this lemma we show that $G\notin$ Fin(G)›, that is that
  $G$ is not a finite subset of itself. This is a way of saying that $G$ 
  is infinite. We also show that for nontrivial linearly ordered groups 
  G+ is infinite.

theorem (in group3) Linord_group_infinite:
  assumes A1: "r {is total on} G" and A2: "G  {𝟭}"
  shows 
  "G+  Fin(G)"
  "G  Fin(G)"
proof -
  from A1 A2 show I: "G+  Fin(G)"
    using OrderedGroup_ZF_1_L23 OrderedGroup_ZF_2_L2A
    by simp
  { assume "G  Fin(G)"
    moreover have "G+  G" using PositiveSet_def by auto
    ultimately have "G+  Fin(G)" using Fin_subset_lemma
      by blast
    with I have False by simp
  } then show "G  Fin(G)" by auto
qed
  
textA property of nonempty subsets of linearly ordered groups that don't
  have a maximum: for any element in such subset we can find one that
  is strictly greater.

lemma (in group3) OrderedGroup_ZF_2_L2B:
  assumes A1: "r {is total on} G" and A2: "AG" and 
  A3: "¬HasAmaximum(r,A)" and A4: "xA"
  shows "yA. x\<ls>y"
proof -
  from ordGroupAssum assms have
    "antisym(r)"
    "r {is total on} G"
    "AG"  "¬HasAmaximum(r,A)"  "xA"
    using IsAnOrdGroup_def IsPartOrder_def
    by auto
  then have "yA. x,y  r  yx"
    using Order_ZF_4_L16 by simp
  then show "yA. x\<ls>y" by auto
qed
    
textIn linearly ordered groups $G\setminus G_+$ is bounded above.

lemma (in group3) OrderedGroup_ZF_2_L3:
  assumes A1: "r {is total on} G" shows "IsBoundedAbove(G-G+,r)"
proof -
  from A1 have "aG-G+. a\<lsq>𝟭"
    using OrderedGroup_ZF_1_L17 by simp
  then show "IsBoundedAbove(G-G+,r)" 
    using IsBoundedAbove_def by auto
qed

textIn linearly ordered groups if $A\cap G_+$ is finite, 
  then $A$ is bounded above.

lemma (in group3) OrderedGroup_ZF_2_L4:
  assumes A1: "r {is total on} G" and A2: "AG" 
  and A3: "A  G+  Fin(G)"
  shows "IsBoundedAbove(A,r)"
proof -
  have "A  (G-G+)  G-G+" by auto
  with A1 have "IsBoundedAbove(A  (G-G+),r)"
    using OrderedGroup_ZF_2_L3 Order_ZF_3_L13
    by blast
  moreover from A1 A3 have "IsBoundedAbove(A  G+,r)"
    using ord_group_fin_bounded IsBounded_def 
    by simp
  moreover from A1 ordGroupAssum have
    "r {is total on} G"  "trans(r)"  "rG×G"
    using IsAnOrdGroup_def IsPartOrder_def by auto
  ultimately have "IsBoundedAbove(A  (G-G+)  A  G+,r)"
    using Order_ZF_3_L3 by simp
  moreover from A2 have "A = A  (G-G+)  A  G+"
    by auto
  ultimately show  "IsBoundedAbove(A,r)" by simp
qed

textIf a set $-A\subseteq G$ is bounded above, then $A$ is bounded below.

lemma (in group3) OrderedGroup_ZF_2_L5:
  assumes A1: "AG" and A2: "IsBoundedAbove(\<sm>A,r)"
  shows "IsBoundedBelow(A,r)"
proof -
  { assume "A = 0" then have "IsBoundedBelow(A,r)"
      using IsBoundedBelow_def by auto }
  moreover
  { assume A3: "A0"
    from ordGroupAssum have I: "GroupInv(G,P) : GG"
      using IsAnOrdGroup_def group0_2_T2 by simp
    with A1 A2 A3 obtain u where D: "a(\<sm>A). a\<lsq>u"
      using func1_1_L15A IsBoundedAbove_def by auto
    { fix b assume "bA"
      with A1 I D have "b¯ \<lsq> u" and T: "bG"
	using func_imagedef by auto
      then have "u¯\<lsq>(b¯)¯" using OrderedGroup_ZF_1_L5
	by simp
      with T have "u¯\<lsq>b"
	using OrderedGroup_ZF_1_L1 group0.group_inv_of_inv
	by simp
    } then have "bA. u¯,b  r" by simp
    then have "IsBoundedBelow(A,r)"
      using Order_ZF_3_L9 by blast }
  ultimately show ?thesis by auto
qed

textIf $a\leq b$, then the image of the interval $a..b$ by any function is
  nonempty.

lemma (in group3) OrderedGroup_ZF_2_L6: 
  assumes "a\<lsq>b" and "f:GG"
  shows "f``(Interval(r,a,b))  0"
  using ordGroupAssum assms OrderedGroup_ZF_1_L4 
    Order_ZF_2_L6 Order_ZF_2_L2A 
    IsAnOrdGroup_def IsPartOrder_def func1_1_L15A
  by auto
  
end