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