src/HOL/Algebra/Lattice.thy
author ballarin
Fri, 22 Dec 2006 14:03:30 +0100
changeset 21896 9a7949815a84
parent 21657 2a0c0fa4a3c4
child 22063 717425609192
permissions -rw-r--r--
Experimenting with interpretations of "definition".
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     1
(*
14706
71590b7733b7 tuned document;
wenzelm
parents: 14693
diff changeset
     2
  Title:     HOL/Algebra/Lattice.thy
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     3
  Id:        $Id$
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     4
  Author:    Clemens Ballarin, started 7 November 2003
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     5
  Copyright: Clemens Ballarin
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     6
*)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     7
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
     8
theory Lattice imports Main begin
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
     9
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
    10
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
    11
section {* Orders and Lattices *}
14751
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
    12
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
    13
text {* Object with a carrier set. *}
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
    14
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
    15
record 'a partial_object =
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
    16
  carrier :: "'a set"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    17
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
    18
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    19
subsection {* Partial Orders *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    20
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    21
text {* Locale @{text order_syntax} is required since we want to refer
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    22
  to definitions (and their derived theorems) outside of @{text partial_order}.
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    23
  *}
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    24
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    25
locale order_syntax =
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    26
  fixes L :: "'a set" and le :: "['a, 'a] => bool" (infix "\<sqsubseteq>" 50)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    27
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    28
text {* Note that the type constraints above are necessary, because the
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    29
  definition command cannot specialise the types. *}
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    30
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    31
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    32
  less (infixl "\<sqsubset>" 50) where "x \<sqsubset> y == x \<sqsubseteq> y & x ~= y"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    33
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    34
text {* Upper and lower bounds of a set. *}
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    35
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    36
definition (in order_syntax)
21896
9a7949815a84 Experimenting with interpretations of "definition".
ballarin
parents: 21657
diff changeset
    37
  Upper :: "'a set => 'a set" where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    38
  "Upper A == {u. (ALL x. x \<in> A \<inter> L --> x \<sqsubseteq> u)} \<inter> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    39
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    40
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    41
  Lower :: "'a set => 'a set" where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    42
  "Lower A == {l. (ALL x. x \<in> A \<inter> L --> l \<sqsubseteq> x)} \<inter> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    43
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    44
text {* Least and greatest, as predicate. *}
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    45
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    46
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    47
  least :: "['a, 'a set] => bool" where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    48
  "least l A == A \<subseteq> L & l \<in> A & (ALL x : A. l \<sqsubseteq> x)"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    49
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    50
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    51
  greatest :: "['a, 'a set] => bool" where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    52
  "greatest g A == A \<subseteq> L & g \<in> A & (ALL x : A. x \<sqsubseteq> g)"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    53
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    54
text {* Supremum and infimum *}
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    55
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    56
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    57
  sup :: "'a set => 'a" ("\<Squnion>_" [90] 90) where
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    58
  "\<Squnion>A == THE x. least x (Upper A)"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    59
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    60
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    61
  inf :: "'a set => 'a" ("\<Sqinter>_" [90] 90) where
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    62
  "\<Sqinter>A == THE x. greatest x (Lower A)"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    63
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    64
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    65
  join :: "['a, 'a] => 'a" (infixl "\<squnion>" 65) where
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    66
  "x \<squnion> y == sup {x, y}"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    67
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    68
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
    69
  meet :: "['a, 'a] => 'a" (infixl "\<sqinter>" 70) where
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    70
  "x \<sqinter> y == inf {x, y}"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    71
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    72
locale partial_order = order_syntax +
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    73
  assumes refl [intro, simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    74
                  "x \<in> L ==> x \<sqsubseteq> x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    75
    and anti_sym [intro]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    76
                  "[| x \<sqsubseteq> y; y \<sqsubseteq> x; x \<in> L; y \<in> L |] ==> x = y"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    77
    and trans [trans]:
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    78
                  "[| x \<sqsubseteq> y; y \<sqsubseteq> z;
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    79
                   x \<in> L; y \<in> L; z \<in> L |] ==> x \<sqsubseteq> z"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    80
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
    81
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
    82
subsubsection {* Upper *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    83
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    84
lemma (in order_syntax) Upper_closed [intro, simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    85
  "Upper A \<subseteq> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    86
  by (unfold Upper_def) clarify
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    87
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    88
lemma (in order_syntax) UpperD [dest]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    89
  "[| u \<in> Upper A; x \<in> A; A \<subseteq> L |] ==> x \<sqsubseteq> u"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
    90
  by (unfold Upper_def) blast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    91
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    92
lemma (in order_syntax) Upper_memI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
    93
  "[| !! y. y \<in> A ==> y \<sqsubseteq> x; x \<in> L |] ==> x \<in> Upper A"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
    94
  by (unfold Upper_def) blast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    95
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    96
lemma (in order_syntax) Upper_antimono:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
    97
  "A \<subseteq> B ==> Upper B \<subseteq> Upper A"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    98
  by (unfold Upper_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
    99
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   100
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   101
subsubsection {* Lower *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   102
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   103
lemma (in order_syntax) Lower_closed [intro, simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   104
  "Lower A \<subseteq> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   105
  by (unfold Lower_def) clarify
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   106
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   107
lemma (in order_syntax) LowerD [dest]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   108
  "[| l \<in> Lower A; x \<in> A; A \<subseteq> L |] ==> l \<sqsubseteq> x"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   109
  by (unfold Lower_def) blast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   110
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   111
lemma (in order_syntax) Lower_memI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   112
  "[| !! y. y \<in> A ==> x \<sqsubseteq> y; x \<in> L |] ==> x \<in> Lower A"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   113
  by (unfold Lower_def) blast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   114
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   115
lemma (in order_syntax) Lower_antimono:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   116
  "A \<subseteq> B ==> Lower B \<subseteq> Lower A"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   117
  by (unfold Lower_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   118
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   119
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   120
subsubsection {* least *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   121
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   122
lemma (in order_syntax) least_closed [intro, simp]:
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   123
  "least l A ==> l \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   124
  by (unfold least_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   125
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   126
lemma (in order_syntax) least_mem:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   127
  "least l A ==> l \<in> A"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   128
  by (unfold least_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   129
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   130
lemma (in partial_order) least_unique:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   131
  "[| least x A; least y A |] ==> x = y"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   132
  by (unfold least_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   133
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   134
lemma (in order_syntax) least_le:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   135
  "[| least x A; a \<in> A |] ==> x \<sqsubseteq> a"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   136
  by (unfold least_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   137
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   138
lemma (in order_syntax) least_UpperI:
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   139
  assumes above: "!! x. x \<in> A ==> x \<sqsubseteq> s"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   140
    and below: "!! y. y \<in> Upper A ==> s \<sqsubseteq> y"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   141
    and L: "A \<subseteq> L"  "s \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   142
  shows "least s (Upper A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   143
proof -
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   144
  have "Upper A \<subseteq> L" by simp
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   145
  moreover from above L have "s \<in> Upper A" by (simp add: Upper_def)
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   146
  moreover from below have "ALL x : Upper A. s \<sqsubseteq> x" by fast
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   147
  ultimately show ?thesis by (simp add: least_def)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   148
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   149
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   150
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   151
subsubsection {* greatest *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   152
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   153
lemma (in order_syntax) greatest_closed [intro, simp]:
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   154
  "greatest l A ==> l \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   155
  by (unfold greatest_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   156
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   157
lemma (in order_syntax) greatest_mem:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   158
  "greatest l A ==> l \<in> A"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   159
  by (unfold greatest_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   160
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   161
lemma (in partial_order) greatest_unique:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   162
  "[| greatest x A; greatest y A |] ==> x = y"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   163
  by (unfold greatest_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   164
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   165
lemma (in order_syntax) greatest_le:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   166
  "[| greatest x A; a \<in> A |] ==> a \<sqsubseteq> x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   167
  by (unfold greatest_def) fast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   168
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   169
lemma (in order_syntax) greatest_LowerI:
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   170
  assumes below: "!! x. x \<in> A ==> i \<sqsubseteq> x"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   171
    and above: "!! y. y \<in> Lower A ==> y \<sqsubseteq> i"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   172
    and L: "A \<subseteq> L"  "i \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   173
  shows "greatest i (Lower A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   174
proof -
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   175
  have "Lower A \<subseteq> L" by simp
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   176
  moreover from below L have "i \<in> Lower A" by (simp add: Lower_def)
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   177
  moreover from above have "ALL x : Lower A. x \<sqsubseteq> i" by fast
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   178
  ultimately show ?thesis by (simp add: greatest_def)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   179
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   180
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   181
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   182
subsection {* Lattices *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   183
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   184
locale lattice = partial_order +
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   185
  assumes sup_of_two_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   186
    "[| x \<in> L; y \<in> L |] ==> EX s. order_syntax.least L le s (order_syntax.Upper L le {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   187
    and inf_of_two_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   188
    "[| x \<in> L; y \<in> L |] ==> EX s. order_syntax.greatest L le s (order_syntax.Lower L le {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   189
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   190
lemma (in order_syntax) least_Upper_above:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   191
  "[| least s (Upper A); x \<in> A; A \<subseteq> L |] ==> x \<sqsubseteq> s"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   192
  by (unfold least_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   193
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   194
lemma (in order_syntax) greatest_Lower_above:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   195
  "[| greatest i (Lower A); x \<in> A; A \<subseteq> L |] ==> i \<sqsubseteq> x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   196
  by (unfold greatest_def) blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   197
14666
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   198
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   199
subsubsection {* Supremum *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   200
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   201
lemma (in lattice) joinI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   202
  "[| !!l. least l (Upper {x, y}) ==> P l; x \<in> L; y \<in> L |]
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   203
  ==> P (x \<squnion> y)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   204
proof (unfold join_def sup_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   205
  assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   206
    and P: "!!l. least l (Upper {x, y}) ==> P l"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   207
  with sup_of_two_exists obtain s where "least s (Upper {x, y})" by fast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   208
  with L show "P (THE l. least l (Upper {x, y}))"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   209
    by (fast intro: theI2 least_unique P)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   210
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   211
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   212
lemma (in lattice) join_closed [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   213
  "[| x \<in> L; y \<in> L |] ==> x \<squnion> y \<in> L"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   214
  by (rule joinI) (rule least_closed)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   215
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   216
lemma (in partial_order) sup_of_singletonI:     (* only reflexivity needed ? *)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   217
  "x \<in> L ==> least x (Upper {x})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   218
  by (rule least_UpperI) fast+
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   219
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   220
lemma (in partial_order) sup_of_singleton [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   221
  "x \<in> L ==> \<Squnion>{x} = x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   222
  by (unfold sup_def) (blast intro: least_unique least_UpperI sup_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   223
14666
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   224
65f8680c3f16 improved notation;
wenzelm
parents: 14651
diff changeset
   225
text {* Condition on @{text A}: supremum exists. *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   226
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   227
lemma (in lattice) sup_insertI:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   228
  "[| !!s. least s (Upper (insert x A)) ==> P s;
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   229
  least a (Upper A); x \<in> L; A \<subseteq> L |]
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   230
  ==> P (\<Squnion>(insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   231
proof (unfold sup_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   232
  assume L: "x \<in> L"  "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   233
    and P: "!!l. least l (Upper (insert x A)) ==> P l"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   234
    and least_a: "least a (Upper A)"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   235
  from least_a have La: "a \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   236
  from L sup_of_two_exists least_a
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   237
  obtain s where least_s: "least s (Upper {a, x})" by blast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   238
  show "P (THE l. least l (Upper (insert x A)))"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   239
  proof (rule theI2)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   240
    show "least s (Upper (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   241
    proof (rule least_UpperI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   242
      fix z
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   243
      assume "z \<in> insert x A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   244
      then show "z \<sqsubseteq> s"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   245
      proof
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   246
        assume "z = x" then show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   247
          by (simp add: least_Upper_above [OF least_s] L La)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   248
      next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   249
        assume "z \<in> A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   250
        with L least_s least_a show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   251
          by (rule_tac trans [where y = a]) (auto dest: least_Upper_above)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   252
      qed
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   253
    next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   254
      fix y
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   255
      assume y: "y \<in> Upper (insert x A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   256
      show "s \<sqsubseteq> y"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   257
      proof (rule least_le [OF least_s], rule Upper_memI)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   258
	fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   259
	assume z: "z \<in> {a, x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   260
	then show "z \<sqsubseteq> y"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   261
	proof
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   262
          have y': "y \<in> Upper A"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   263
            apply (rule subsetD [where A = "Upper (insert x A)"])
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   264
            apply (rule Upper_antimono) apply clarify apply assumption
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   265
            done
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   266
          assume "z = a"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   267
          with y' least_a show ?thesis by (fast dest: least_le)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   268
	next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   269
	  assume "z \<in> {x}"  (* FIXME "z = x"; declare specific elim rule for "insert x {}" (!?) *)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   270
          with y L show ?thesis by blast
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   271
	qed
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   272
      qed (rule Upper_closed [THEN subsetD])
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   273
    next
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   274
      from L show "insert x A \<subseteq> L" by simp
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   275
      from least_s show "s \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   276
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   277
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   278
    fix l
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   279
    assume least_l: "least l (Upper (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   280
    show "l = s"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   281
    proof (rule least_unique)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   282
      show "least s (Upper (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   283
      proof (rule least_UpperI)
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   284
        fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   285
        assume "z \<in> insert x A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   286
        then show "z \<sqsubseteq> s"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   287
	proof
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   288
          assume "z = x" then show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   289
            by (simp add: least_Upper_above [OF least_s] L La)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   290
	next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   291
          assume "z \<in> A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   292
          with L least_s least_a show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   293
            by (rule_tac trans [where y = a]) (auto dest: least_Upper_above)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   294
	qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   295
      next
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   296
        fix y
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   297
        assume y: "y \<in> Upper (insert x A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   298
        show "s \<sqsubseteq> y"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   299
        proof (rule least_le [OF least_s], rule Upper_memI)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   300
          fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   301
          assume z: "z \<in> {a, x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   302
          then show "z \<sqsubseteq> y"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   303
          proof
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   304
            have y': "y \<in> Upper A"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   305
	      apply (rule subsetD [where A = "Upper (insert x A)"])
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   306
	      apply (rule Upper_antimono) apply clarify apply assumption
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   307
	      done
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   308
            assume "z = a"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   309
            with y' least_a show ?thesis by (fast dest: least_le)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   310
	  next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   311
            assume "z \<in> {x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   312
            with y L show ?thesis by blast
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   313
          qed
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   314
        qed (rule Upper_closed [THEN subsetD])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   315
      next
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   316
        from L show "insert x A \<subseteq> L" by simp
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   317
        from least_s show "s \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   318
      qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   319
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   320
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   321
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   322
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   323
lemma (in lattice) finite_sup_least:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   324
  "[| finite A; A \<subseteq> L; A ~= {} |] ==> least (\<Squnion>A) (Upper A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   325
proof (induct set: Finites)
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   326
  case empty
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   327
  then show ?case by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   328
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 14751
diff changeset
   329
  case (insert x A)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   330
  show ?case
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   331
  proof (cases "A = {}")
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   332
    case True
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   333
    with insert show ?thesis by (simp add: sup_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   334
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   335
    case False
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   336
    with insert have "least (\<Squnion>A) (Upper A)" by simp
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   337
    with _ show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   338
      by (rule sup_insertI) (simp_all add: insert [simplified])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   339
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   340
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   341
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   342
lemma (in lattice) finite_sup_insertI:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   343
  assumes P: "!!l. least l (Upper (insert x A)) ==> P l"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   344
    and xA: "finite A"  "x \<in> L"  "A \<subseteq> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   345
  shows "P (\<Squnion> (insert x A))"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   346
proof (cases "A = {}")
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   347
  case True with P and xA show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   348
    by (simp add: sup_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   349
next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   350
  case False with P and xA show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   351
    by (simp add: sup_insertI finite_sup_least)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   352
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   353
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   354
lemma (in lattice) finite_sup_closed:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   355
  "[| finite A; A \<subseteq> L; A ~= {} |] ==> \<Squnion>A \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   356
proof (induct set: Finites)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   357
  case empty then show ?case by simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   358
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 14751
diff changeset
   359
  case insert then show ?case
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   360
    by - (rule finite_sup_insertI, simp_all)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   361
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   362
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   363
lemma (in lattice) join_left:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   364
  "[| x \<in> L; y \<in> L |] ==> x \<sqsubseteq> x \<squnion> y"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   365
  by (rule joinI [folded join_def]) (blast dest: least_mem)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   366
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   367
lemma (in lattice) join_right:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   368
  "[| x \<in> L; y \<in> L |] ==> y \<sqsubseteq> x \<squnion> y"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   369
  by (rule joinI [folded join_def]) (blast dest: least_mem)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   370
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   371
lemma (in lattice) sup_of_two_least:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   372
  "[| x \<in> L; y \<in> L |] ==> least (\<Squnion>{x, y}) (Upper {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   373
proof (unfold sup_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   374
  assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   375
  with sup_of_two_exists obtain s where "least s (Upper {x, y})" by fast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   376
  with L show "least (THE xa. least xa (Upper {x, y})) (Upper {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   377
  by (fast intro: theI2 least_unique)  (* blast fails *)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   378
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   379
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   380
lemma (in lattice) join_le:
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   381
  assumes sub: "x \<sqsubseteq> z"  "y \<sqsubseteq> z"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   382
    and L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   383
  shows "x \<squnion> y \<sqsubseteq> z"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   384
proof (rule joinI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   385
  fix s
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   386
  assume "least s (Upper {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   387
  with sub L show "s \<sqsubseteq> z" by (fast elim: least_le intro: Upper_memI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   388
qed
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   389
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   390
lemma (in lattice) join_assoc_lemma:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   391
  assumes L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   392
  shows "x \<squnion> (y \<squnion> z) = \<Squnion>{x, y, z}"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   393
proof (rule finite_sup_insertI)
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   394
  -- {* The textbook argument in Jacobson I, p 457 *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   395
  fix s
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   396
  assume sup: "least s (Upper {x, y, z})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   397
  show "x \<squnion> (y \<squnion> z) = s"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   398
  proof (rule anti_sym)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   399
    from sup L show "x \<squnion> (y \<squnion> z) \<sqsubseteq> s"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   400
      by (fastsimp intro!: join_le elim: least_Upper_above)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   401
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   402
    from sup L show "s \<sqsubseteq> x \<squnion> (y \<squnion> z)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   403
    by (erule_tac least_le)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   404
      (blast intro!: Upper_memI intro: trans join_left join_right join_closed)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   405
  qed (simp_all add: L least_closed [OF sup])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   406
qed (simp_all add: L)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   407
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   408
lemma (in order_syntax) join_comm:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   409
  "x \<squnion> y = y \<squnion> x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   410
  by (unfold join_def) (simp add: insert_commute)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   411
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   412
lemma (in lattice) join_assoc:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   413
  assumes L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   414
  shows "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   415
proof -
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   416
  have "(x \<squnion> y) \<squnion> z = z \<squnion> (x \<squnion> y)" by (simp only: join_comm)
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   417
  also from L have "... = \<Squnion>{z, x, y}" by (simp add: join_assoc_lemma)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   418
  also from L have "... = \<Squnion>{x, y, z}" by (simp add: insert_commute)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   419
  also from L have "... = x \<squnion> (y \<squnion> z)" by (simp add: join_assoc_lemma)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   420
  finally show ?thesis .
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   421
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   422
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   423
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   424
subsubsection {* Infimum *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   425
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   426
lemma (in lattice) meetI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   427
  "[| !!i. greatest i (Lower {x, y}) ==> P i; x \<in> L; y \<in> L |]
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   428
  ==> P (x \<sqinter> y)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   429
proof (unfold meet_def inf_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   430
  assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   431
    and P: "!!g. greatest g (Lower {x, y}) ==> P g"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   432
  with inf_of_two_exists obtain i where "greatest i (Lower {x, y})" by fast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   433
  with L show "P (THE g. greatest g (Lower {x, y}))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   434
  by (fast intro: theI2 greatest_unique P)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   435
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   436
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   437
lemma (in lattice) meet_closed [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   438
  "[| x \<in> L; y \<in> L |] ==> x \<sqinter> y \<in> L"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   439
  by (rule meetI) (rule greatest_closed)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   440
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   441
lemma (in partial_order) inf_of_singletonI:      (* only reflexivity needed ? *)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   442
  "x \<in> L ==> greatest x (Lower {x})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   443
  by (rule greatest_LowerI) fast+
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   444
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   445
lemma (in partial_order) inf_of_singleton [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   446
  "x \<in> L ==> \<Sqinter> {x} = x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   447
  by (unfold inf_def) (blast intro: greatest_unique greatest_LowerI inf_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   448
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   449
text {* Condition on A: infimum exists. *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   450
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   451
lemma (in lattice) inf_insertI:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   452
  "[| !!i. greatest i (Lower (insert x A)) ==> P i;
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   453
  greatest a (Lower A); x \<in> L; A \<subseteq> L |]
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   454
  ==> P (\<Sqinter>(insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   455
proof (unfold inf_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   456
  assume L: "x \<in> L"  "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   457
    and P: "!!g. greatest g (Lower (insert x A)) ==> P g"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   458
    and greatest_a: "greatest a (Lower A)"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   459
  from greatest_a have La: "a \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   460
  from L inf_of_two_exists greatest_a
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   461
  obtain i where greatest_i: "greatest i (Lower {a, x})" by blast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   462
  show "P (THE g. greatest g (Lower (insert x A)))"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   463
  proof (rule theI2)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   464
    show "greatest i (Lower (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   465
    proof (rule greatest_LowerI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   466
      fix z
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   467
      assume "z \<in> insert x A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   468
      then show "i \<sqsubseteq> z"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   469
      proof
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   470
        assume "z = x" then show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   471
          by (simp add: greatest_Lower_above [OF greatest_i] L La)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   472
      next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   473
        assume "z \<in> A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   474
        with L greatest_i greatest_a show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   475
          by (rule_tac trans [where y = a]) (auto dest: greatest_Lower_above)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   476
      qed
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   477
    next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   478
      fix y
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   479
      assume y: "y \<in> Lower (insert x A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   480
      show "y \<sqsubseteq> i"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   481
      proof (rule greatest_le [OF greatest_i], rule Lower_memI)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   482
	fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   483
	assume z: "z \<in> {a, x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   484
	then show "y \<sqsubseteq> z"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   485
	proof
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   486
          have y': "y \<in> Lower A"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   487
            apply (rule subsetD [where A = "Lower (insert x A)"])
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   488
            apply (rule Lower_antimono) apply clarify apply assumption
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   489
            done
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   490
          assume "z = a"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   491
          with y' greatest_a show ?thesis by (fast dest: greatest_le)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   492
	next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   493
          assume "z \<in> {x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   494
          with y L show ?thesis by blast
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   495
	qed
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   496
      qed (rule Lower_closed [THEN subsetD])
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   497
    next
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   498
      from L show "insert x A \<subseteq> L" by simp
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   499
      from greatest_i show "i \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   500
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   501
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   502
    fix g
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   503
    assume greatest_g: "greatest g (Lower (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   504
    show "g = i"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   505
    proof (rule greatest_unique)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   506
      show "greatest i (Lower (insert x A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   507
      proof (rule greatest_LowerI)
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   508
        fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   509
        assume "z \<in> insert x A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   510
        then show "i \<sqsubseteq> z"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   511
	proof
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   512
          assume "z = x" then show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   513
            by (simp add: greatest_Lower_above [OF greatest_i] L La)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   514
	next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   515
          assume "z \<in> A"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   516
          with L greatest_i greatest_a show ?thesis
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   517
            by (rule_tac trans [where y = a]) (auto dest: greatest_Lower_above)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   518
        qed
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   519
      next
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   520
        fix y
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   521
        assume y: "y \<in> Lower (insert x A)"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   522
        show "y \<sqsubseteq> i"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   523
        proof (rule greatest_le [OF greatest_i], rule Lower_memI)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   524
          fix z
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   525
          assume z: "z \<in> {a, x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   526
          then show "y \<sqsubseteq> z"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   527
          proof
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   528
            have y': "y \<in> Lower A"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   529
	      apply (rule subsetD [where A = "Lower (insert x A)"])
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   530
	      apply (rule Lower_antimono) apply clarify apply assumption
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   531
	      done
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   532
            assume "z = a"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   533
            with y' greatest_a show ?thesis by (fast dest: greatest_le)
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   534
	  next
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   535
            assume "z \<in> {x}"
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   536
            with y L show ?thesis by blast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   537
	  qed
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   538
        qed (rule Lower_closed [THEN subsetD])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   539
      next
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   540
        from L show "insert x A \<subseteq> L" by simp
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   541
        from greatest_i show "i \<in> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   542
      qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   543
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   544
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   545
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   546
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   547
lemma (in lattice) finite_inf_greatest:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   548
  "[| finite A; A \<subseteq> L; A ~= {} |] ==> greatest (\<Sqinter>A) (Lower A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   549
proof (induct set: Finites)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   550
  case empty then show ?case by simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   551
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 14751
diff changeset
   552
  case (insert x A)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   553
  show ?case
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   554
  proof (cases "A = {}")
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   555
    case True
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   556
    with insert show ?thesis by (simp add: inf_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   557
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   558
    case False
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   559
    from insert show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   560
    proof (rule_tac inf_insertI)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   561
      from False insert show "greatest (\<Sqinter>A) (Lower A)" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   562
    qed simp_all
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   563
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   564
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   565
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   566
lemma (in lattice) finite_inf_insertI:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   567
  assumes P: "!!i. greatest i (Lower (insert x A)) ==> P i"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   568
    and xA: "finite A"  "x \<in> L"  "A \<subseteq> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   569
  shows "P (\<Sqinter> (insert x A))"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   570
proof (cases "A = {}")
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   571
  case True with P and xA show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   572
    by (simp add: inf_of_singletonI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   573
next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   574
  case False with P and xA show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   575
    by (simp add: inf_insertI finite_inf_greatest)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   576
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   577
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   578
lemma (in lattice) finite_inf_closed:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   579
  "[| finite A; A \<subseteq> L; A ~= {} |] ==> \<Sqinter>A \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   580
proof (induct set: Finites)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   581
  case empty then show ?case by simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   582
next
15328
35951e6a7855 mod because of change in finite set induction
nipkow
parents: 14751
diff changeset
   583
  case insert then show ?case
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   584
    by (rule_tac finite_inf_insertI) (simp_all)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   585
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   586
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   587
lemma (in lattice) meet_left:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   588
  "[| x \<in> L; y \<in> L |] ==> x \<sqinter> y \<sqsubseteq> x"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   589
  by (rule meetI [folded meet_def]) (blast dest: greatest_mem)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   590
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   591
lemma (in lattice) meet_right:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   592
  "[| x \<in> L; y \<in> L |] ==> x \<sqinter> y \<sqsubseteq> y"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   593
  by (rule meetI [folded meet_def]) (blast dest: greatest_mem)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   594
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   595
lemma (in lattice) inf_of_two_greatest:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   596
  "[| x \<in> L; y \<in> L |] ==> greatest (\<Sqinter> {x, y}) (Lower {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   597
proof (unfold inf_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   598
  assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   599
  with inf_of_two_exists obtain s where "greatest s (Lower {x, y})" by fast
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   600
  with L
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   601
  show "greatest (THE xa. greatest xa (Lower {x, y})) (Lower {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   602
  by (fast intro: theI2 greatest_unique)  (* blast fails *)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   603
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   604
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   605
lemma (in lattice) meet_le:
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   606
  assumes sub: "z \<sqsubseteq> x"  "z \<sqsubseteq> y"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   607
    and L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   608
  shows "z \<sqsubseteq> x \<sqinter> y"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   609
proof (rule meetI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   610
  fix i
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   611
  assume "greatest i (Lower {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   612
  with sub L show "z \<sqsubseteq> i" by (fast elim: greatest_le intro: Lower_memI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   613
qed
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   614
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   615
lemma (in lattice) meet_assoc_lemma:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   616
  assumes L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   617
  shows "x \<sqinter> (y \<sqinter> z) = \<Sqinter>{x, y, z}"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   618
proof (rule finite_inf_insertI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   619
  txt {* The textbook argument in Jacobson I, p 457 *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   620
  fix i
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   621
  assume inf: "greatest i (Lower {x, y, z})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   622
  show "x \<sqinter> (y \<sqinter> z) = i"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   623
  proof (rule anti_sym)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   624
    from inf L show "i \<sqsubseteq> x \<sqinter> (y \<sqinter> z)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   625
      by (fastsimp intro!: meet_le elim: greatest_Lower_above)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   626
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   627
    from inf L show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> i"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   628
    by (erule_tac greatest_le)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   629
      (blast intro!: Lower_memI intro: trans meet_left meet_right meet_closed)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   630
  qed (simp_all add: L greatest_closed [OF inf])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   631
qed (simp_all add: L)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   632
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   633
lemma (in order_syntax) meet_comm:
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   634
  "x \<sqinter> y = y \<sqinter> x"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   635
  by (unfold meet_def) (simp add: insert_commute)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   636
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   637
lemma (in lattice) meet_assoc:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   638
  assumes L: "x \<in> L"  "y \<in> L"  "z \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   639
  shows "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   640
proof -
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   641
  have "(x \<sqinter> y) \<sqinter> z = z \<sqinter> (x \<sqinter> y)" by (simp only: meet_comm)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   642
  also from L have "... = \<Sqinter> {z, x, y}" by (simp add: meet_assoc_lemma)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   643
  also from L have "... = \<Sqinter> {x, y, z}" by (simp add: insert_commute)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   644
  also from L have "... = x \<sqinter> (y \<sqinter> z)" by (simp add: meet_assoc_lemma)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   645
  finally show ?thesis .
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   646
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   647
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   648
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   649
subsection {* Total Orders *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   650
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   651
locale total_order = lattice +
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   652
  assumes total: "[| x \<in> L; y \<in> L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   653
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   654
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   655
text {* Introduction rule: the usual definition of total order *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   656
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   657
lemma (in partial_order) total_orderI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   658
  assumes total: "!!x y. [| x \<in> L; y \<in> L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   659
  shows "total_order L le"
19984
29bb4659f80a Method intro_locales replaced by intro_locales and unfold_locales.
ballarin
parents: 19931
diff changeset
   660
proof intro_locales
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   661
  show "lattice_axioms L le"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   662
  proof (rule lattice_axioms.intro)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   663
    fix x y
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   664
    assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   665
    show "EX s. least s (Upper {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   666
    proof -
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   667
      note total L
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   668
      moreover
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   669
      {
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   670
        assume "x \<sqsubseteq> y"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   671
        with L have "least y (Upper {x, y})"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   672
          by (rule_tac least_UpperI) auto
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   673
      }
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   674
      moreover
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   675
      {
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   676
        assume "y \<sqsubseteq> x"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   677
        with L have "least x (Upper {x, y})"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   678
          by (rule_tac least_UpperI) auto
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   679
      }
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   680
      ultimately show ?thesis by blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   681
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   682
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   683
    fix x y
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   684
    assume L: "x \<in> L"  "y \<in> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   685
    show "EX i. greatest i (Lower {x, y})"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   686
    proof -
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   687
      note total L
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   688
      moreover
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   689
      {
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   690
        assume "y \<sqsubseteq> x"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   691
        with L have "greatest y (Lower {x, y})"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   692
          by (rule_tac greatest_LowerI) auto
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   693
      }
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   694
      moreover
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   695
      {
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   696
        assume "x \<sqsubseteq> y"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   697
        with L have "greatest x (Lower {x, y})"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   698
          by (rule_tac greatest_LowerI) auto
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   699
      }
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   700
      ultimately show ?thesis by blast
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   701
    qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   702
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   703
qed (assumption | rule total_order_axioms.intro)+
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   704
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   705
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   706
subsection {* Complete lattices *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   707
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   708
locale complete_lattice = lattice +
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   709
  assumes sup_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   710
    "[| A \<subseteq> L |] ==> EX s. order_syntax.least L le s (order_syntax.Upper L le A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   711
    and inf_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   712
    "[| A \<subseteq> L |] ==> EX i. order_syntax.greatest L le i (order_syntax.Lower L le A)"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   713
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   714
text {* Introduction rule: the usual definition of complete lattice *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   715
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   716
lemma (in partial_order) complete_latticeI:
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   717
  assumes sup_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   718
    "!!A. [| A \<subseteq> L |] ==> EX s. least s (Upper A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   719
    and inf_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   720
    "!!A. [| A \<subseteq> L |] ==> EX i. greatest i (Lower A)"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   721
  shows "complete_lattice L le"
19984
29bb4659f80a Method intro_locales replaced by intro_locales and unfold_locales.
ballarin
parents: 19931
diff changeset
   722
proof intro_locales
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   723
  show "lattice_axioms L le"
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   724
    by (rule lattice_axioms.intro) (blast intro: sup_exists inf_exists)+
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   725
qed (assumption | rule complete_lattice_axioms.intro)+
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   726
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   727
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
   728
  top ("\<top>") where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   729
  "\<top> == sup L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   730
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   731
definition (in order_syntax)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21049
diff changeset
   732
  bottom ("\<bottom>") where
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   733
  "\<bottom> == inf L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   734
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   735
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   736
lemma (in complete_lattice) supI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   737
  "[| !!l. least l (Upper A) ==> P l; A \<subseteq> L |]
14651
02b8f3bcf7fe improved notation;
wenzelm
parents: 14577
diff changeset
   738
  ==> P (\<Squnion>A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   739
proof (unfold sup_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   740
  assume L: "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   741
    and P: "!!l. least l (Upper A) ==> P l"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   742
  with sup_exists obtain s where "least s (Upper A)" by blast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   743
  with L show "P (THE l. least l (Upper A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   744
  by (fast intro: theI2 least_unique P)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   745
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   746
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   747
lemma (in complete_lattice) sup_closed [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   748
  "A \<subseteq> L ==> \<Squnion>A \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   749
  by (rule supI) simp_all
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   750
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   751
lemma (in complete_lattice) top_closed [simp, intro]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   752
  "\<top> \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   753
  by (unfold top_def) simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   754
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   755
lemma (in complete_lattice) infI:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   756
  "[| !!i. greatest i (Lower A) ==> P i; A \<subseteq> L |]
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   757
  ==> P (\<Sqinter>A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   758
proof (unfold inf_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   759
  assume L: "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   760
    and P: "!!l. greatest l (Lower A) ==> P l"
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   761
  with inf_exists obtain s where "greatest s (Lower A)" by blast
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   762
  with L show "P (THE l. greatest l (Lower A))"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   763
  by (fast intro: theI2 greatest_unique P)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   764
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   765
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   766
lemma (in complete_lattice) inf_closed [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   767
  "A \<subseteq> L ==> \<Sqinter>A \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   768
  by (rule infI) simp_all
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   769
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   770
lemma (in complete_lattice) bottom_closed [simp, intro]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   771
  "\<bottom> \<in> L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   772
  by (unfold bottom_def) simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   773
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   774
text {* Jacobson: Theorem 8.1 *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   775
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   776
lemma (in order_syntax) Lower_empty [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   777
  "Lower {} = L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   778
  by (unfold Lower_def) simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   779
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   780
lemma (in order_syntax) Upper_empty [simp]:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   781
  "Upper {} = L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   782
  by (unfold Upper_def) simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   783
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   784
theorem (in partial_order) complete_lattice_criterion1:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   785
  assumes top_exists: "EX g. greatest g L"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   786
    and inf_exists:
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   787
      "!!A. [| A \<subseteq> L; A ~= {} |] ==> EX i. greatest i (Lower A)"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   788
  shows "complete_lattice L le"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   789
proof (rule complete_latticeI)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   790
  from top_exists obtain top where top: "greatest top L" ..
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   791
  fix A
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   792
  assume L: "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   793
  let ?B = "Upper A"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   794
  from L top have "top \<in> ?B" by (fast intro!: Upper_memI intro: greatest_le)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   795
  then have B_non_empty: "?B ~= {}" by fast
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   796
  have B_L: "?B \<subseteq> L" by simp
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   797
  from inf_exists [OF B_L B_non_empty]
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   798
  obtain b where b_inf_B: "greatest b (Lower ?B)" ..
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   799
  have "least b (Upper A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   800
apply (rule least_UpperI)
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   801
   apply (rule greatest_le [where A = "Lower ?B"])
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   802
    apply (rule b_inf_B)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   803
   apply (rule Lower_memI)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   804
    apply (erule UpperD)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   805
     apply assumption
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   806
    apply (rule L)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   807
   apply (fast intro: L [THEN subsetD])
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   808
  apply (erule greatest_Lower_above [OF b_inf_B])
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   809
  apply simp
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   810
 apply (rule L)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   811
apply (rule greatest_closed [OF b_inf_B]) (* rename rule: _closed *)
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   812
done
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   813
  then show "EX s. least s (Upper A)" ..
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   814
next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   815
  fix A
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   816
  assume L: "A \<subseteq> L"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   817
  show "EX i. greatest i (Lower A)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   818
  proof (cases "A = {}")
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   819
    case True then show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   820
      by (simp add: top_exists)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   821
  next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   822
    case False with L show ?thesis
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   823
      by (rule inf_exists)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   824
  qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   825
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   826
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   827
(* TODO: prove dual version *)
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   828
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
   829
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   830
subsection {* Examples *}
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   831
20318
0e0ea63fe768 Restructured algebra library, added ideals and quotient rings.
ballarin
parents: 19984
diff changeset
   832
subsubsection {* Powerset of a Set is a Complete Lattice *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   833
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   834
theorem powerset_is_complete_lattice:
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   835
  "complete_lattice (Pow A) (op \<subseteq>)"
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   836
  (is "complete_lattice ?L ?le")
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   837
proof (rule partial_order.complete_latticeI)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   838
  show "partial_order ?L ?le"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   839
    by (rule partial_order.intro) auto
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   840
next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   841
  fix B
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   842
  assume "B \<subseteq> ?L"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   843
  then have "order_syntax.least ?L ?le (\<Union> B) (order_syntax.Upper ?L ?le B)"
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   844
    by (fastsimp intro!: order_syntax.least_UpperI simp: order_syntax.Upper_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   845
  then show "EX s. order_syntax.least ?L ?le s (order_syntax.Upper ?L ?le B)" ..
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   846
next
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   847
  fix B
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   848
  assume "B \<subseteq> ?L"
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   849
  then have "order_syntax.greatest ?L ?le (\<Inter> B \<inter> A) (order_syntax.Lower ?L ?le B)"
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   850
    txt {* @{term "\<Inter> B"} is not the infimum of @{term B}:
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   851
      @{term "\<Inter> {} = UNIV"} which is in general bigger than @{term "A"}! *}
21041
60e418260b4d Order and lattice structures no longer based on records.
ballarin
parents: 20318
diff changeset
   852
    by (fastsimp intro!: order_syntax.greatest_LowerI simp: order_syntax.Lower_def)
21049
379542c9d951 Stylistic improvements.
ballarin
parents: 21041
diff changeset
   853
  then show "EX i. order_syntax.greatest ?L ?le i (order_syntax.Lower ?L ?le B)" ..
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   854
qed
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   855
14751
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
   856
text {* An other example, that of the lattice of subgroups of a group,
0d7850e27fed Change of theory hierarchy: Group is now based in Lattice.
ballarin
parents: 14706
diff changeset
   857
  can be found in Group theory (Section~\ref{sec:subgroup-lattice}). *}
14551
2cb6ff394bfb Various changes to HOL-Algebra;
ballarin
parents:
diff changeset
   858
14693
4deda204e1d8 improved syntax;
wenzelm
parents: 14666
diff changeset
   859
end