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