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