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