Theory Order_ZF

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

    Copyright (C) 2005 - 2022  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 Order relations - introduction

theory Order_ZF imports Fol1

begin

textThis theory file considers various notion related to order. We redefine
  the notions of a preorder, directed set, total order, linear order and partial order to have the 
  same terminology as Wikipedia (I found it very consistent across different 
  areas of math). We also define and study the notions of intervals and bounded
  sets. We show the inclusion relations between the intervals with endpoints
  being in certain order. We also show that union of bounded sets are bounded. 
  This allows to show in Finite_ZF.thy› that finite sets are bounded.

subsectionDefinitions

textIn this section we formulate the definitions related to order 
  relations.

textA relation $r$ is ''total'' on a set $X$ if for all elements 
  $a,b$ of $X$ we have $a$ is in relation with $b$ or $b$ is in relation
  with $a$. An example is the $\leq $ relation on numbers.


definition
  IsTotal (infixl "{is total on}" 65) where
  "r {is total on} X  (aX.bX.  a,b  r   b,a  r)"

textA relation $r$ is a partial order on $X$ if it is reflexive on $X$
  (i.e. $\langle x,x \rangle$ for every $x\in X$), antisymmetric 
  (if $\langle x, y\rangle \in r $ and $\langle y, x\rangle \in r $, then
  $x=y$) and transitive $\langle x, y\rangle \in r $ and 
  $\langle y, z\rangle \in r $ implies $\langle x, z\rangle \in r $). 


definition
  "IsPartOrder(X,r)  refl(X,r)  antisym(r)  trans(r)"

textA relation that is reflexive and transitive is called a preorder›.

definition
  "IsPreorder(X,r)  refl(X,r)  trans(r)"

textWe say that a relation $r$ up-directs a set
  if every two-element subset of $X$ has an upper bound. 

definition
  UpDirects ("_ {up-directs} _" 90)
  where "r {up-directs} X  X0  (xX.yX.zX. x,z  r  y,z  r)"

textAnalogously we say that a relation $r$ down-directs a set
  if every two-element subset of $X$ has a lower bound. 

definition
  DownDirects ("_ {down-directs} _" 90)
  where "r {down-directs} X  X0  (xX.yX.zX. z,x  r  z,y  r)"

textTypically the notion that is actually defined is the notion of a directed set›. 
  or an upward directed set›, rather than $r$ down-directs $X$ (or $r$ up-directs $X$). 
  This is a nonempty set $X$ together which a preorder $r$ 
  such that $r$ up-directs $X$. We set that up in separate definitions as we sometimes want to
  use an upward or downward directed set with a partial order rather than a preorder. 

definition
  "IsUpDirectedSet(X,r)   IsPreorder(X,r)  (r {up-directs} X)"

textWe define the notion of a downward directed set› analogously.

definition
  "IsDownDirectedSet(X,r)  IsPreorder(X,r)  (r {down-directs} X)"

textWe define a linear order as a binary relation that is antisymmetric, 
  transitive and total. Note that this terminology is different than the
  one used the standard Order.thy file.

definition
  "IsLinOrder(X,r)  antisym(r)  trans(r)  (r {is total on} X)"

textA set is bounded above if there is that is an upper
  bound for it,  i.e. there are some $u$ such that 
  $\langle x, u\rangle \in r$ for all $x\in A$. 
  In addition, the empty set is defined as bounded.

definition
  "IsBoundedAbove(A,r)  ( A=0  (u. xA.  x,u  r))"

textWe define sets bounded below analogously.

definition
  "IsBoundedBelow(A,r)  (A=0  (l. xA.  l,x  r))"

textA set is bounded if it is bounded below and above.

definition
  "IsBounded(A,r)  (IsBoundedAbove(A,r)  IsBoundedBelow(A,r))"

textThe notation for the definition of an interval may be mysterious for some
  readers, see lemma Order_ZF_2_L1› for more intuitive notation.

definition
  "Interval(r,a,b)  r``{a}  r-``{b}"

textWe also define the maximum (the greater of) two elemnts 
  in the obvious way.

definition
  "GreaterOf(r,a,b)  (if  a,b  r then b else a)"

textThe definition a a minimum (the smaller of) two elements.

definition
  "SmallerOf(r,a,b)  (if  a,b  r then a else b)"

textWe say that a set has a maximum if it has an element that is 
  not smaller that any other one. We show that
  under some conditions this element of the set is unique (if exists).

definition
  "HasAmaximum(r,A)  MA.xA. x,M  r"

textA similar definition what it means that a set has a minimum.

definition
  "HasAminimum(r,A)  mA.xA. m,x  r"

textDefinition of the maximum of a set.

definition
  "Maximum(r,A)  THE M. MA  (xA. x,M  r)"

textDefinition of a minimum of a set.

definition
  "Minimum(r,A)  THE m. mA  (xA. m,x  r)"

textThe supremum of a set $A$ is defined as the minimum of the set of
  upper bounds, i.e. the set 
  $\{u.\forall_{a\in A} \langle a,u\rangle \in r\}=\bigcap_{a\in A} r\{a\}$. 
   Recall that in Isabelle/ZF
  r-``(A)› denotes the inverse image of the set $A$ by relation $r$
  (i.e. r-``(A)›=$\{ x: \langle x,y\rangle\in r$ for some $y\in A\}$).

definition
  "Supremum(r,A)  Minimum(r,aA. r``{a})"

text The notion of "having a supremum" is the same as the set of upper bounds having a
  minimum, but having it a a separate notion does simplify notation in some cases.
  The definition is written in terms of 
  images of singletons $\{ x\}$ under relation. To understand this formulation note
  that the set of upper bounds of a set $A\subseteq X$ is 
  $\bigcap_{x\in A}\{ y\in X | \langle x,y\rangle \in r \}$, which is the same
  as $\bigcap_{x\in A} r(\{ x \})$, where $r(\{ x \})$ is the image of the singleton $\{ x\}$ under
  relation $r$. 

definition
  "HasAsupremum(r,A)  HasAminimum(r,aA. r``{a})"

text The notion of "having an infimum" is the same as the set of lower bounds having a
  maximum. 

definition
  "HasAnInfimum(r,A)  HasAmaximum(r,aA. r-``{a})"


textInfimum is defined analogously.

definition
  "Infimum(r,A)  Maximum(r,aA. r-``{a})"

textWe define a relation to be complete if every nonempty bounded
  above set has a supremum.

definition
  IsComplete ("_ {is complete}") where
  "r {is complete}  
  A. IsBoundedAbove(A,r)  A0  HasAminimum(r,aA. r``{a})"

textIf a relation down-directs a set, then a larger one does as well.

lemma down_dir_mono: assumes "r {down-directs} X" "rR"
  shows "R {down-directs} X" using assms unfolding DownDirects_def
  by blast

textIf a relation up-directs a set, then a larger one does as well.

lemma up_dir_mono: assumes "r {up-directs} X" "rR"
  shows "R {up-directs} X" using assms unfolding UpDirects_def
  by blast

textThe essential condition to show that a total relation is reflexive.

lemma Order_ZF_1_L1: assumes "r {is total on} X" and "aX"
  shows "a,a  r" using assms IsTotal_def by auto

textA total relation is reflexive.

lemma total_is_refl:
  assumes "r {is total on} X"
  shows "refl(X,r)" using assms Order_ZF_1_L1 refl_def by simp

textA linear order is partial order.

lemma Order_ZF_1_L2: assumes "IsLinOrder(X,r)" 
  shows "IsPartOrder(X,r)" 
  using assms IsLinOrder_def IsPartOrder_def refl_def Order_ZF_1_L1
  by auto

textPartial order that is total is linear.

lemma Order_ZF_1_L3: 
  assumes "IsPartOrder(X,r)" and "r {is total on} X"
  shows "IsLinOrder(X,r)"
  using assms IsPartOrder_def IsLinOrder_def
  by simp

textRelation that is total on a set is total on any subset.

lemma Order_ZF_1_L4: assumes "r {is total on} X" and "AX"
  shows "r {is total on} A"
  using assms IsTotal_def by auto

textWe can restrict a partial order relation to the domain. 

lemma part_ord_restr: assumes "IsPartOrder(X,r)"
  shows "IsPartOrder(X,r  X×X)"
  using assms unfolding IsPartOrder_def refl_def antisym_def trans_def by auto

text We can restrict a total order relation to the domain. 

lemma total_ord_restr: assumes "r {is total on} X"
  shows "(r  X×X) {is total on} X"
  using assms unfolding IsTotal_def by auto

textA linear relation is linear on any subset and we can restrict it to any subset.

lemma ord_linear_subset: assumes  "IsLinOrder(X,r)" and "AX"
  shows  "IsLinOrder(A,r)" and  "IsLinOrder(A,r  A×A)"
proof -
  from assms show "IsLinOrder(A,r)" using IsLinOrder_def Order_ZF_1_L4 by blast
  then have "IsPartOrder(A,r  A×A)" and "(r  A×A) {is total on} A"
    using Order_ZF_1_L2 part_ord_restr total_ord_restr unfolding IsLinOrder_def 
    by auto
  then show "IsLinOrder(A,r  A×A)" using Order_ZF_1_L3 by simp
qed

textIf the relation is total, then every set is a union of those elements
  that are nongreater than a given one and nonsmaller than a given one.

lemma Order_ZF_1_L5: 
  assumes "r {is total on} X" and "AX" and "aX"
  shows "A = {xA. x,a  r}  {xA. a,x  r}"
  using assms IsTotal_def by auto

textA technical fact about reflexive relations.

lemma refl_add_point: 
  assumes "refl(X,r)" and "A  B  {x}" and "B  X" and
  "x  X" and "yB. y,x  r"
  shows "aA. a,x  r"
  using assms refl_def by auto
  
subsectionIntervals

textIn this section we discuss intervals.

textThe next lemma explains the notation of the definition of an interval.

lemma Order_ZF_2_L1: 
  shows "x  Interval(r,a,b)   a,x  r   x,b  r"
  using Interval_def by auto

textSince there are some problems with applying the above lemma 
  (seems that simp and auto don't handle equivalence very well), we
  split Order_ZF_2_L1› into two lemmas.

lemma Order_ZF_2_L1A: assumes "x  Interval(r,a,b)"
  shows " a,x  r"  " x,b  r"
  using assms  Order_ZF_2_L1 by auto

text Order_ZF_2_L1›, implication from right to left.

lemma Order_ZF_2_L1B: assumes " a,x  r"  " x,b  r"
  shows "x  Interval(r,a,b)"
  using assms Order_ZF_2_L1 by simp

textIf the relation is reflexive, the endpoints belong to the interval.

lemma Order_ZF_2_L2: assumes "refl(X,r)" 
  and "aX"  "bX" and " a,b  r"
  shows 
  "a  Interval(r,a,b)"  
  "b  Interval(r,a,b)"  
  using assms refl_def Order_ZF_2_L1 by auto

textUnder the assumptions of Order_ZF_2_L2›, the interval is 
  nonempty.

lemma Order_ZF_2_L2A: assumes "refl(X,r)" 
  and "aX"  "bX" and " a,b  r"
  shows "Interval(r,a,b)  0"
proof -
  from assms have "a  Interval(r,a,b)"
    using Order_ZF_2_L2 by simp
  then show "Interval(r,a,b)  0" by auto
qed

textIf $a,b,c,d$ are in this order, then $[b,c]\subseteq [a,d]$. We
  only need trasitivity for this to be true.

lemma Order_ZF_2_L3: 
  assumes A1: "trans(r)" and A2:" a,br"  " b,cr"  " c,dr"
shows "Interval(r,b,c)  Interval(r,a,d)"
proof
  fix x assume A3: "x  Interval(r, b, c)"
  note A1
  moreover from A2 A3 have " a,b  r   b,x  r" using Order_ZF_2_L1A
    by simp
  ultimately have T1: " a,x  r" by (rule Fol1_L3)
  note A1
  moreover from A2 A3 have " x,c  r   c,d  r" using Order_ZF_2_L1A
    by simp
  ultimately have " x,d  r" by (rule Fol1_L3)
  with T1 show "x  Interval(r,a,d)" using Order_ZF_2_L1B
    by simp
qed

textFor reflexive and antisymmetric relations the interval with equal 
  endpoints consists only of that endpoint.

lemma Order_ZF_2_L4: 
  assumes A1: "refl(X,r)" and A2: "antisym(r)" and A3: "aX"
  shows "Interval(r,a,a) = {a}"
proof
  from A1 A3 have " a,a  r" using refl_def by simp
  with A1 A3 show "{a}  Interval(r,a,a)" using Order_ZF_2_L2 by simp
  from A2 show "Interval(r,a,a)  {a}" using Order_ZF_2_L1A Fol1_L4
    by fast
qed

textFor transitive relations the endpoints have to be in the relation for
  the interval to be nonempty.

lemma Order_ZF_2_L5: assumes A1: "trans(r)" and A2: " a,b  r"
  shows "Interval(r,a,b) = 0"
proof -
  { assume "Interval(r,a,b)0" then obtain x where "x  Interval(r,a,b)"
    by auto
  with A1 A2 have False using Order_ZF_2_L1A Fol1_L3 by fast
  } thus ?thesis by auto
qed

textIf a relation is defined on a set, then intervals are subsets of that
  set.

lemma Order_ZF_2_L6: assumes A1: "r  X×X"
  shows "Interval(r,a,b)  X"
  using assms Interval_def by auto

subsectionBounded sets

textIn this section we consider properties of bounded sets.

textFor reflexive relations singletons are bounded.

lemma Order_ZF_3_L1: assumes "refl(X,r)" and "aX"
  shows "IsBounded({a},r)"
  using assms refl_def IsBoundedAbove_def IsBoundedBelow_def
    IsBounded_def by auto

textSets that are bounded above are contained in the domain of 
  the relation.

lemma Order_ZF_3_L1A: assumes "r  X×X" 
  and "IsBoundedAbove(A,r)"
  shows "AX" using assms IsBoundedAbove_def by auto

textSets that are bounded below are contained in the domain of 
  the relation.

lemma Order_ZF_3_L1B: assumes "r  X×X" 
  and "IsBoundedBelow(A,r)"
  shows "AX" using assms IsBoundedBelow_def by auto

textFor a total relation, the greater of two elements, 
  as defined above, is indeed greater of any of the two.

lemma Order_ZF_3_L2: assumes "r {is total on} X"
  and "xX" "yX"
  shows 
  "x,GreaterOf(r,x,y)  r" 
  "y,GreaterOf(r,x,y)  r"
  "SmallerOf(r,x,y),x  r" 
  "SmallerOf(r,x,y),y  r"
  using assms IsTotal_def Order_ZF_1_L1 GreaterOf_def SmallerOf_def
  by auto

textIf $A$ is bounded above by $u$, $B$ is bounded above by $w$,
  then $A\cup B$ is bounded above by the greater of $u,w$.

lemma Order_ZF_3_L2B:  
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "uX" "wX" 
  and A4: "xA.  x,u  r" "xB.  x,w  r"
  shows "xAB. x,GreaterOf(r,u,w)  r"
proof
  let ?v = "GreaterOf(r,u,w)"
  from A1 A3 have T1: " u,?v  r" and T2: " w,?v  r"
    using Order_ZF_3_L2 by auto
  fix x assume A5: "xAB" show "x,?v  r"
  proof -
    { assume "xA"
    with A4 T1 have " x,u  r   u,?v  r" by simp
    with A2 have "x,?v  r" by (rule Fol1_L3) }
  moreover
  { assume "xA" 
    with A5 A4 T2 have " x,w  r   w,?v  r" by simp
    with A2 have "x,?v  r" by (rule Fol1_L3) }
  ultimately show ?thesis by auto
  qed
qed

textFor total and transitive relation the union of two sets bounded 
  above is bounded above.

lemma Order_ZF_3_L3: 
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "IsBoundedAbove(A,r)" "IsBoundedAbove(B,r)"
  and A4: "r  X×X"
  shows "IsBoundedAbove(AB,r)"
proof -
  { assume "A=0  B=0" 
    with A3 have "IsBoundedAbove(AB,r)" by auto }
  moreover
  { assume "¬ (A = 0  B = 0)"
    then have T1: "A0" "B0" by auto
    with A3 obtain u w where D1: "xA.  x,u  r" "xB.  x,w  r"
      using IsBoundedAbove_def by auto
    let ?U = "GreaterOf(r,u,w)"
    from T1 A4 D1 have "uX" "wX" by auto
    with A1 A2 D1 have "xAB. x,?U  r"
      using Order_ZF_3_L2B by blast
    then have "IsBoundedAbove(AB,r)"
      using IsBoundedAbove_def by auto }
  ultimately show ?thesis by auto
qed
  
textFor total and transitive relations if a set $A$ is bounded above then 
  $A\cup \{a\}$ is bounded above.

lemma Order_ZF_3_L4: 
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "IsBoundedAbove(A,r)" and A4: "aX" and A5: "r  X×X"
  shows "IsBoundedAbove(A{a},r)"
proof -
  from A1 have "refl(X,r)"
    using total_is_refl by simp
  with assms show ?thesis using
    Order_ZF_3_L1 IsBounded_def Order_ZF_3_L3 by simp
qed

textIf $A$ is bounded below by $l$, $B$ is bounded below by $m$,
  then $A\cup B$ is bounded below by the smaller of $u,w$.

lemma Order_ZF_3_L5B:  
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "lX" "mX" 
  and A4: "xA.  l,x  r" "xB.  m,x  r"
  shows "xAB. SmallerOf(r,l,m),x  r"
proof
  let ?k = "SmallerOf(r,l,m)"
  from A1 A3 have T1: " ?k,l  r" and T2: " ?k,m  r"
    using Order_ZF_3_L2 by auto
  fix x assume A5: "xAB" show "?k,x  r"
  proof -
    { assume "xA"
      with A4 T1 have " ?k,l  r   l,x  r" by simp
      with A2 have "?k,x  r" by (rule Fol1_L3) }
    moreover
    { assume "xA" 
      with A5 A4 T2 have " ?k,m  r   m,x  r" by simp
      with A2 have "?k,x  r" by (rule Fol1_L3) }
    ultimately show ?thesis by auto
  qed
qed

textFor total and transitive relation the union of two sets bounded 
  below is bounded below.

lemma Order_ZF_3_L6: 
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "IsBoundedBelow(A,r)" "IsBoundedBelow(B,r)"
  and A4: "r  X×X"
  shows "IsBoundedBelow(AB,r)"
proof -
  { assume "A=0  B=0" 
    with A3 have ?thesis by auto }
  moreover
  { assume "¬ (A = 0  B = 0)"
    then have T1: "A0" "B0" by auto
    with A3 obtain l m where D1: "xA.  l,x  r" "xB.  m,x  r"
      using IsBoundedBelow_def by auto
    let ?L = "SmallerOf(r,l,m)"
    from T1 A4 D1 have T1: "lX" "mX" by auto
    with A1 A2 D1 have "xAB. ?L,x  r"
      using Order_ZF_3_L5B by blast
    then have "IsBoundedBelow(AB,r)"
      using IsBoundedBelow_def by auto }
  ultimately show ?thesis by auto
qed

textFor total and transitive relations if a set $A$ is bounded below then 
  $A\cup \{a\}$ is bounded below.

lemma Order_ZF_3_L7:
  assumes A1: "r {is total on} X" and A2: "trans(r)"
  and A3: "IsBoundedBelow(A,r)" and A4: "aX" and A5: "r  X×X"
  shows "IsBoundedBelow(A{a},r)"
proof -
  from A1 have "refl(X,r)"
    using total_is_refl by simp
  with assms show ?thesis using
    Order_ZF_3_L1 IsBounded_def Order_ZF_3_L6 by simp
qed

textFor total and transitive relations unions of two bounded sets are 
  bounded.

theorem Order_ZF_3_T1: 
  assumes "r {is total on} X" and "trans(r)" 
  and "IsBounded(A,r)" "IsBounded(B,r)"
  and "r  X×X"
  shows "IsBounded(AB,r)"
  using assms Order_ZF_3_L3 Order_ZF_3_L6 Order_ZF_3_L7 IsBounded_def
  by simp

textFor total and transitive relations if a set $A$ is bounded then 
  $A\cup \{a\}$ is bounded.

lemma Order_ZF_3_L8: 
  assumes "r {is total on} X" and "trans(r)"
  and "IsBounded(A,r)" and "aX" and "r  X×X"
  shows "IsBounded(A{a},r)"
  using assms total_is_refl Order_ZF_3_L1 Order_ZF_3_T1 by blast

textA sufficient condition for a set to be bounded below.

lemma Order_ZF_3_L9: assumes A1: "aA. l,a  r"
  shows "IsBoundedBelow(A,r)"
proof -
  from A1 have "l. xA. l,x  r"
    by auto
  then show "IsBoundedBelow(A,r)"
    using IsBoundedBelow_def by simp
qed

textA sufficient condition for a set to be bounded above.

lemma Order_ZF_3_L10: assumes A1: "aA. a,u  r"
  shows "IsBoundedAbove(A,r)"
proof -
  from A1 have "u. xA. x,u  r"
    by auto
  then show "IsBoundedAbove(A,r)"
    using IsBoundedAbove_def by simp
qed

textIntervals are bounded.
(*proof that uses Order_ZF_3_L9 and Order_ZF_3_L10 and is not shorter *)
lemma Order_ZF_3_L11: shows 
  "IsBoundedAbove(Interval(r,a,b),r)"
  "IsBoundedBelow(Interval(r,a,b),r)"
  "IsBounded(Interval(r,a,b),r)"
proof -
  { fix x assume "x  Interval(r,a,b)" 
    then have " x,b  r"  " a,x  r" 
      using Order_ZF_2_L1A by auto
  } then have 
      "u. xInterval(r,a,b).  x,u  r" 
      "l. xInterval(r,a,b).  l,x  r"
    by auto
  then show 
    "IsBoundedAbove(Interval(r,a,b),r)"
    "IsBoundedBelow(Interval(r,a,b),r)"
    "IsBounded(Interval(r,a,b),r)"
    using IsBoundedAbove_def IsBoundedBelow_def IsBounded_def
    by auto
qed

textA subset of a set that is bounded below is bounded below.

lemma Order_ZF_3_L12: assumes A1: "IsBoundedBelow(A,r)" and A2: "BA"
  shows "IsBoundedBelow(B,r)"
proof -
  { assume "A = 0"
    with assms have "IsBoundedBelow(B,r)" 
      using IsBoundedBelow_def by auto }
  moreover
  { assume "A  0"
    with A1 have "l. xA. l,x  r"
      using IsBoundedBelow_def by simp
    with A2 have "l.xB. l,x  r" by auto
    then have "IsBoundedBelow(B,r)" using IsBoundedBelow_def
      by auto }
  ultimately show "IsBoundedBelow(B,r)" by auto
qed

textA subset of a set that is bounded above is bounded above.

lemma Order_ZF_3_L13: assumes A1: "IsBoundedAbove(A,r)" and A2: "BA"
  shows "IsBoundedAbove(B,r)"
proof -
  { assume "A = 0"
    with assms have "IsBoundedAbove(B,r)" 
      using IsBoundedAbove_def by auto }
  moreover
  { assume "A  0"
    with A1 have "u. xA. x,u  r"
      using IsBoundedAbove_def by simp
    with A2 have "u.xB. x,u  r" by auto
    then have "IsBoundedAbove(B,r)" using IsBoundedAbove_def
      by auto }
  ultimately show "IsBoundedAbove(B,r)" by auto
qed

textIf for every element of $X$ we can find one in $A$ 
  that is greater, then the $A$ can not be bounded above.
  Works for relations that are total, transitive and antisymmetric,
  (i.e. for linear order relations).

lemma Order_ZF_3_L14:  
  assumes A1: "r {is total on} X" 
  and A2: "trans(r)" and A3: "antisym(r)"
  and A4: "r  X×X" and A5: "X0" 
  and A6: "xX. aA. xa  x,a  r"
  shows "¬IsBoundedAbove(A,r)"
proof -
  { from A5 A6 have I: "A0" by auto
    moreover assume "IsBoundedAbove(A,r)"
    ultimately obtain u where II: "xA.  x,u  r"
      using IsBounded_def IsBoundedAbove_def by auto
    with A4 I have "uX" by auto
    with A6 obtain b where "bA" and III: "ub" and "u,b  r"
      by auto
    with II have "b,u  r"  "u,b  r" by auto
    with A3 have "b=u" by (rule Fol1_L4)
    with III have False by simp
  } thus "¬IsBoundedAbove(A,r)" by auto
qed

textThe set of elements in a set $A$ that are nongreater than 
  a given element is bounded above.

lemma Order_ZF_3_L15: shows "IsBoundedAbove({xA. x,a  r},r)"
  using IsBoundedAbove_def by auto

textIf $A$ is bounded below, then the set of elements in a set $A$ 
  that are nongreater than a given element is bounded.

lemma Order_ZF_3_L16: assumes A1: "IsBoundedBelow(A,r)"
  shows "IsBounded({xA. x,a  r},r)"
proof -
  { assume "A=0" 
    then have "IsBounded({xA. x,a  r},r)"
      using IsBoundedBelow_def IsBoundedAbove_def IsBounded_def
      by auto }
  moreover
  { assume "A0"
    with A1 obtain l where I: "xA. l,x  r"
      using IsBoundedBelow_def by auto
    then have "y{xA. x,a  r}. l,y  r" by simp
    then have "IsBoundedBelow({xA. x,a  r},r)"
      by (rule Order_ZF_3_L9)
    then have "IsBounded({xA. x,a  r},r)" 
      using Order_ZF_3_L15 IsBounded_def by simp }
  ultimately show ?thesis by blast
qed

end