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