src/HOL/Algebra/Lattice.thy
author nipkow
Fri Nov 13 14:14:04 2009 +0100 (2009-11-13)
changeset 33657 a4179bf442d1
parent 32960 69916a850301
child 35847 19f1f7066917
permissions -rw-r--r--
renamed lemmas "anti_sym" -> "antisym"
ballarin@14551
     1
(*
ballarin@27714
     2
  Title:     HOL/Algebra/Lattice.thy
ballarin@14551
     3
  Author:    Clemens Ballarin, started 7 November 2003
ballarin@14551
     4
  Copyright: Clemens Ballarin
ballarin@27714
     5
ballarin@27717
     6
Most congruence rules by Stephan Hohe.
ballarin@14551
     7
*)
ballarin@14551
     8
ballarin@27700
     9
theory Lattice imports Congruence begin
ballarin@14551
    10
ballarin@20318
    11
section {* Orders and Lattices *}
ballarin@14751
    12
ballarin@14551
    13
subsection {* Partial Orders *}
ballarin@14551
    14
ballarin@27713
    15
record 'a gorder = "'a eq_object" +
ballarin@22063
    16
  le :: "['a, 'a] => bool" (infixl "\<sqsubseteq>\<index>" 50)
ballarin@21041
    17
ballarin@29237
    18
locale weak_partial_order = equivalence L for L (structure) +
ballarin@27713
    19
  assumes le_refl [intro, simp]:
ballarin@27713
    20
      "x \<in> carrier L ==> x \<sqsubseteq> x"
nipkow@33657
    21
    and weak_le_antisym [intro]:
ballarin@27713
    22
      "[| x \<sqsubseteq> y; y \<sqsubseteq> x; x \<in> carrier L; y \<in> carrier L |] ==> x .= y"
ballarin@27713
    23
    and le_trans [trans]:
ballarin@27713
    24
      "[| x \<sqsubseteq> y; y \<sqsubseteq> z; x \<in> carrier L; y \<in> carrier L; z \<in> carrier L |] ==> x \<sqsubseteq> z"
ballarin@27713
    25
    and le_cong:
ballarin@27713
    26
      "\<lbrakk> x .= y; z .= w; x \<in> carrier L; y \<in> carrier L; z \<in> carrier L; w \<in> carrier L \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z \<longleftrightarrow> y \<sqsubseteq> w"
ballarin@22063
    27
ballarin@22063
    28
constdefs (structure L)
ballarin@22063
    29
  lless :: "[_, 'a, 'a] => bool" (infixl "\<sqsubset>\<index>" 50)
ballarin@27713
    30
  "x \<sqsubset> y == x \<sqsubseteq> y & x .\<noteq> y"
ballarin@27713
    31
ballarin@27713
    32
ballarin@27713
    33
subsubsection {* The order relation *}
ballarin@27713
    34
ballarin@27713
    35
context weak_partial_order begin
ballarin@27713
    36
ballarin@27713
    37
lemma le_cong_l [intro, trans]:
ballarin@27713
    38
  "\<lbrakk> x .= y; y \<sqsubseteq> z; x \<in> carrier L; y \<in> carrier L; z \<in> carrier L \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"
ballarin@27713
    39
  by (auto intro: le_cong [THEN iffD2])
ballarin@27713
    40
ballarin@27713
    41
lemma le_cong_r [intro, trans]:
ballarin@27713
    42
  "\<lbrakk> x \<sqsubseteq> y; y .= z; x \<in> carrier L; y \<in> carrier L; z \<in> carrier L \<rbrakk> \<Longrightarrow> x \<sqsubseteq> z"
ballarin@27713
    43
  by (auto intro: le_cong [THEN iffD1])
ballarin@27713
    44
ballarin@27714
    45
lemma weak_refl [intro, simp]: "\<lbrakk> x .= y; x \<in> carrier L; y \<in> carrier L \<rbrakk> \<Longrightarrow> x \<sqsubseteq> y"
ballarin@27713
    46
  by (simp add: le_cong_l)
ballarin@27713
    47
ballarin@27713
    48
end
ballarin@27713
    49
ballarin@27713
    50
lemma weak_llessI:
ballarin@27713
    51
  fixes R (structure)
ballarin@27713
    52
  assumes "x \<sqsubseteq> y" and "~(x .= y)"
ballarin@27713
    53
  shows "x \<sqsubset> y"
ballarin@27713
    54
  using assms unfolding lless_def by simp
ballarin@27713
    55
ballarin@27713
    56
lemma lless_imp_le:
ballarin@27713
    57
  fixes R (structure)
ballarin@27713
    58
  assumes "x \<sqsubset> y"
ballarin@27713
    59
  shows "x \<sqsubseteq> y"
ballarin@27713
    60
  using assms unfolding lless_def by simp
ballarin@27713
    61
ballarin@27713
    62
lemma weak_lless_imp_not_eq:
ballarin@27713
    63
  fixes R (structure)
ballarin@27713
    64
  assumes "x \<sqsubset> y"
ballarin@27713
    65
  shows "\<not> (x .= y)"
ballarin@27713
    66
  using assms unfolding lless_def by simp
ballarin@22063
    67
ballarin@27713
    68
lemma weak_llessE:
ballarin@27713
    69
  fixes R (structure)
ballarin@27713
    70
  assumes p: "x \<sqsubset> y" and e: "\<lbrakk>x \<sqsubseteq> y; \<not> (x .= y)\<rbrakk> \<Longrightarrow> P"
ballarin@27713
    71
  shows "P"
ballarin@27713
    72
  using p by (blast dest: lless_imp_le weak_lless_imp_not_eq e)
ballarin@27713
    73
ballarin@27713
    74
lemma (in weak_partial_order) lless_cong_l [trans]:
ballarin@27713
    75
  assumes xx': "x .= x'"
ballarin@27713
    76
    and xy: "x' \<sqsubset> y"
ballarin@27713
    77
    and carr: "x \<in> carrier L" "x' \<in> carrier L" "y \<in> carrier L"
ballarin@27713
    78
  shows "x \<sqsubset> y"
ballarin@27713
    79
  using assms unfolding lless_def by (auto intro: trans sym)
ballarin@27713
    80
ballarin@27713
    81
lemma (in weak_partial_order) lless_cong_r [trans]:
ballarin@27713
    82
  assumes xy: "x \<sqsubset> y"
ballarin@27713
    83
    and  yy': "y .= y'"
ballarin@27713
    84
    and carr: "x \<in> carrier L" "y \<in> carrier L" "y' \<in> carrier L"
ballarin@27713
    85
  shows "x \<sqsubset> y'"
ballarin@27713
    86
  using assms unfolding lless_def by (auto intro: trans sym)
ballarin@27713
    87
ballarin@27713
    88
ballarin@27713
    89
lemma (in weak_partial_order) lless_antisym:
ballarin@27713
    90
  assumes "a \<in> carrier L" "b \<in> carrier L"
ballarin@27713
    91
    and "a \<sqsubset> b" "b \<sqsubset> a"
ballarin@27713
    92
  shows "P"
ballarin@27713
    93
  using assms
ballarin@27713
    94
  by (elim weak_llessE) auto
ballarin@27713
    95
ballarin@27713
    96
lemma (in weak_partial_order) lless_trans [trans]:
ballarin@27713
    97
  assumes "a \<sqsubset> b" "b \<sqsubset> c"
ballarin@27713
    98
    and carr[simp]: "a \<in> carrier L" "b \<in> carrier L" "c \<in> carrier L"
ballarin@27713
    99
  shows "a \<sqsubset> c"
ballarin@27713
   100
  using assms unfolding lless_def by (blast dest: le_trans intro: sym)
ballarin@27713
   101
ballarin@27713
   102
ballarin@27713
   103
subsubsection {* Upper and lower bounds of a set *}
ballarin@27713
   104
ballarin@27713
   105
constdefs (structure L)
ballarin@22063
   106
  Upper :: "[_, 'a set] => 'a set"
ballarin@27713
   107
  "Upper L A == {u. (ALL x. x \<in> A \<inter> carrier L --> x \<sqsubseteq> u)} \<inter> carrier L"
ballarin@22063
   108
ballarin@22063
   109
  Lower :: "[_, 'a set] => 'a set"
ballarin@27713
   110
  "Lower L A == {l. (ALL x. x \<in> A \<inter> carrier L --> l \<sqsubseteq> x)} \<inter> carrier L"
ballarin@22063
   111
ballarin@27713
   112
lemma Upper_closed [intro!, simp]:
ballarin@22063
   113
  "Upper L A \<subseteq> carrier L"
ballarin@14551
   114
  by (unfold Upper_def) clarify
ballarin@14551
   115
ballarin@27700
   116
lemma Upper_memD [dest]:
ballarin@22063
   117
  fixes L (structure)
ballarin@27713
   118
  shows "[| u \<in> Upper L A; x \<in> A; A \<subseteq> carrier L |] ==> x \<sqsubseteq> u \<and> u \<in> carrier L"
wenzelm@14693
   119
  by (unfold Upper_def) blast
ballarin@14551
   120
ballarin@27713
   121
lemma (in weak_partial_order) Upper_elemD [dest]:
ballarin@27713
   122
  "[| u .\<in> Upper L A; u \<in> carrier L; x \<in> A; A \<subseteq> carrier L |] ==> x \<sqsubseteq> u"
ballarin@27713
   123
  unfolding Upper_def elem_def
ballarin@27713
   124
  by (blast dest: sym)
ballarin@27713
   125
ballarin@22063
   126
lemma Upper_memI:
ballarin@22063
   127
  fixes L (structure)
ballarin@22063
   128
  shows "[| !! y. y \<in> A ==> y \<sqsubseteq> x; x \<in> carrier L |] ==> x \<in> Upper L A"
wenzelm@14693
   129
  by (unfold Upper_def) blast
ballarin@14551
   130
ballarin@27713
   131
lemma (in weak_partial_order) Upper_elemI:
ballarin@27713
   132
  "[| !! y. y \<in> A ==> y \<sqsubseteq> x; x \<in> carrier L |] ==> x .\<in> Upper L A"
ballarin@27713
   133
  unfolding Upper_def by blast
ballarin@27713
   134
ballarin@22063
   135
lemma Upper_antimono:
ballarin@22063
   136
  "A \<subseteq> B ==> Upper L B \<subseteq> Upper L A"
ballarin@14551
   137
  by (unfold Upper_def) blast
ballarin@14551
   138
ballarin@27713
   139
lemma (in weak_partial_order) Upper_is_closed [simp]:
ballarin@27713
   140
  "A \<subseteq> carrier L ==> is_closed (Upper L A)"
ballarin@27713
   141
  by (rule is_closedI) (blast intro: Upper_memI)+
wenzelm@14651
   142
ballarin@27713
   143
lemma (in weak_partial_order) Upper_mem_cong:
ballarin@27713
   144
  assumes a'carr: "a' \<in> carrier L" and Acarr: "A \<subseteq> carrier L"
ballarin@27713
   145
    and aa': "a .= a'"
ballarin@27713
   146
    and aelem: "a \<in> Upper L A"
ballarin@27713
   147
  shows "a' \<in> Upper L A"
ballarin@27713
   148
proof (rule Upper_memI[OF _ a'carr])
ballarin@27713
   149
  fix y
ballarin@27713
   150
  assume yA: "y \<in> A"
ballarin@27713
   151
  hence "y \<sqsubseteq> a" by (intro Upper_memD[OF aelem, THEN conjunct1] Acarr)
ballarin@27713
   152
  also note aa'
ballarin@27713
   153
  finally
ballarin@27713
   154
      show "y \<sqsubseteq> a'"
ballarin@27713
   155
      by (simp add: a'carr subsetD[OF Acarr yA] subsetD[OF Upper_closed aelem])
ballarin@27713
   156
qed
ballarin@27713
   157
ballarin@27713
   158
lemma (in weak_partial_order) Upper_cong:
ballarin@27713
   159
  assumes Acarr: "A \<subseteq> carrier L" and A'carr: "A' \<subseteq> carrier L"
ballarin@27713
   160
    and AA': "A {.=} A'"
ballarin@27713
   161
  shows "Upper L A = Upper L A'"
ballarin@27713
   162
unfolding Upper_def
ballarin@27713
   163
apply rule
ballarin@27713
   164
 apply (rule, clarsimp) defer 1
ballarin@27713
   165
 apply (rule, clarsimp) defer 1
ballarin@27713
   166
proof -
ballarin@27713
   167
  fix x a'
ballarin@27713
   168
  assume carr: "x \<in> carrier L" "a' \<in> carrier L"
ballarin@27713
   169
    and a'A': "a' \<in> A'"
ballarin@27713
   170
  assume aLxCond[rule_format]: "\<forall>a. a \<in> A \<and> a \<in> carrier L \<longrightarrow> a \<sqsubseteq> x"
ballarin@14551
   171
ballarin@27713
   172
  from AA' and a'A' have "\<exists>a\<in>A. a' .= a" by (rule set_eqD2)
ballarin@27713
   173
  from this obtain a
ballarin@27713
   174
      where aA: "a \<in> A"
ballarin@27713
   175
      and a'a: "a' .= a"
ballarin@27713
   176
      by auto
ballarin@27713
   177
  note [simp] = subsetD[OF Acarr aA] carr
ballarin@27713
   178
ballarin@27713
   179
  note a'a
ballarin@27713
   180
  also have "a \<sqsubseteq> x" by (simp add: aLxCond aA)
ballarin@27713
   181
  finally show "a' \<sqsubseteq> x" by simp
ballarin@27713
   182
next
ballarin@27713
   183
  fix x a
ballarin@27713
   184
  assume carr: "x \<in> carrier L" "a \<in> carrier L"
ballarin@27713
   185
    and aA: "a \<in> A"
ballarin@27713
   186
  assume a'LxCond[rule_format]: "\<forall>a'. a' \<in> A' \<and> a' \<in> carrier L \<longrightarrow> a' \<sqsubseteq> x"
ballarin@27713
   187
ballarin@27713
   188
  from AA' and aA have "\<exists>a'\<in>A'. a .= a'" by (rule set_eqD1)
ballarin@27713
   189
  from this obtain a'
ballarin@27713
   190
      where a'A': "a' \<in> A'"
ballarin@27713
   191
      and aa': "a .= a'"
ballarin@27713
   192
      by auto
ballarin@27713
   193
  note [simp] = subsetD[OF A'carr a'A'] carr
ballarin@27713
   194
ballarin@27713
   195
  note aa'
ballarin@27713
   196
  also have "a' \<sqsubseteq> x" by (simp add: a'LxCond a'A')
ballarin@27713
   197
  finally show "a \<sqsubseteq> x" by simp
ballarin@27713
   198
qed
ballarin@27713
   199
ballarin@27713
   200
lemma Lower_closed [intro!, simp]:
ballarin@22063
   201
  "Lower L A \<subseteq> carrier L"
ballarin@14551
   202
  by (unfold Lower_def) clarify
ballarin@14551
   203
ballarin@27700
   204
lemma Lower_memD [dest]:
ballarin@22063
   205
  fixes L (structure)
ballarin@27713
   206
  shows "[| l \<in> Lower L A; x \<in> A; A \<subseteq> carrier L |] ==> l \<sqsubseteq> x \<and> l \<in> carrier L"
wenzelm@14693
   207
  by (unfold Lower_def) blast
ballarin@14551
   208
ballarin@22063
   209
lemma Lower_memI:
ballarin@22063
   210
  fixes L (structure)
ballarin@22063
   211
  shows "[| !! y. y \<in> A ==> x \<sqsubseteq> y; x \<in> carrier L |] ==> x \<in> Lower L A"
wenzelm@14693
   212
  by (unfold Lower_def) blast
ballarin@14551
   213
ballarin@22063
   214
lemma Lower_antimono:
ballarin@22063
   215
  "A \<subseteq> B ==> Lower L B \<subseteq> Lower L A"
ballarin@14551
   216
  by (unfold Lower_def) blast
ballarin@14551
   217
ballarin@27713
   218
lemma (in weak_partial_order) Lower_is_closed [simp]:
ballarin@27713
   219
  "A \<subseteq> carrier L \<Longrightarrow> is_closed (Lower L A)"
ballarin@27713
   220
  by (rule is_closedI) (blast intro: Lower_memI dest: sym)+
wenzelm@14651
   221
ballarin@27713
   222
lemma (in weak_partial_order) Lower_mem_cong:
ballarin@27713
   223
  assumes a'carr: "a' \<in> carrier L" and Acarr: "A \<subseteq> carrier L"
ballarin@27713
   224
    and aa': "a .= a'"
ballarin@27713
   225
    and aelem: "a \<in> Lower L A"
ballarin@27713
   226
  shows "a' \<in> Lower L A"
ballarin@27713
   227
using assms Lower_closed[of L A]
ballarin@27713
   228
by (intro Lower_memI) (blast intro: le_cong_l[OF aa'[symmetric]])
ballarin@27713
   229
ballarin@27713
   230
lemma (in weak_partial_order) Lower_cong:
ballarin@27713
   231
  assumes Acarr: "A \<subseteq> carrier L" and A'carr: "A' \<subseteq> carrier L"
ballarin@27713
   232
    and AA': "A {.=} A'"
ballarin@27713
   233
  shows "Lower L A = Lower L A'"
ballarin@27713
   234
using Lower_memD[of y]
ballarin@27713
   235
unfolding Lower_def
ballarin@27713
   236
apply safe
ballarin@27713
   237
 apply clarsimp defer 1
ballarin@27713
   238
 apply clarsimp defer 1
ballarin@27713
   239
proof -
ballarin@27713
   240
  fix x a'
ballarin@27713
   241
  assume carr: "x \<in> carrier L" "a' \<in> carrier L"
ballarin@27713
   242
    and a'A': "a' \<in> A'"
ballarin@27713
   243
  assume "\<forall>a. a \<in> A \<and> a \<in> carrier L \<longrightarrow> x \<sqsubseteq> a"
ballarin@27713
   244
  hence aLxCond: "\<And>a. \<lbrakk>a \<in> A; a \<in> carrier L\<rbrakk> \<Longrightarrow> x \<sqsubseteq> a" by fast
ballarin@27713
   245
ballarin@27713
   246
  from AA' and a'A' have "\<exists>a\<in>A. a' .= a" by (rule set_eqD2)
ballarin@27713
   247
  from this obtain a
ballarin@27713
   248
      where aA: "a \<in> A"
ballarin@27713
   249
      and a'a: "a' .= a"
ballarin@27713
   250
      by auto
ballarin@27713
   251
ballarin@27713
   252
  from aA and subsetD[OF Acarr aA]
ballarin@27713
   253
      have "x \<sqsubseteq> a" by (rule aLxCond)
ballarin@27713
   254
  also note a'a[symmetric]
ballarin@27713
   255
  finally
ballarin@27713
   256
      show "x \<sqsubseteq> a'" by (simp add: carr subsetD[OF Acarr aA])
ballarin@27713
   257
next
ballarin@27713
   258
  fix x a
ballarin@27713
   259
  assume carr: "x \<in> carrier L" "a \<in> carrier L"
ballarin@27713
   260
    and aA: "a \<in> A"
ballarin@27713
   261
  assume "\<forall>a'. a' \<in> A' \<and> a' \<in> carrier L \<longrightarrow> x \<sqsubseteq> a'"
ballarin@27713
   262
  hence a'LxCond: "\<And>a'. \<lbrakk>a' \<in> A'; a' \<in> carrier L\<rbrakk> \<Longrightarrow> x \<sqsubseteq> a'" by fast+
ballarin@27713
   263
ballarin@27713
   264
  from AA' and aA have "\<exists>a'\<in>A'. a .= a'" by (rule set_eqD1)
ballarin@27713
   265
  from this obtain a'
ballarin@27713
   266
      where a'A': "a' \<in> A'"
ballarin@27713
   267
      and aa': "a .= a'"
ballarin@27713
   268
      by auto
ballarin@27713
   269
  from a'A' and subsetD[OF A'carr a'A']
ballarin@27713
   270
      have "x \<sqsubseteq> a'" by (rule a'LxCond)
ballarin@27713
   271
  also note aa'[symmetric]
ballarin@27713
   272
  finally show "x \<sqsubseteq> a" by (simp add: carr subsetD[OF A'carr a'A'])
ballarin@27713
   273
qed
ballarin@27713
   274
ballarin@27713
   275
ballarin@27713
   276
subsubsection {* Least and greatest, as predicate *}
ballarin@27713
   277
ballarin@27713
   278
constdefs (structure L)
ballarin@27713
   279
  least :: "[_, 'a, 'a set] => bool"
ballarin@27713
   280
  "least L l A == A \<subseteq> carrier L & l \<in> A & (ALL x : A. l \<sqsubseteq> x)"
ballarin@27713
   281
ballarin@27713
   282
  greatest :: "[_, 'a, 'a set] => bool"
ballarin@27713
   283
  "greatest L g A == A \<subseteq> carrier L & g \<in> A & (ALL x : A. x \<sqsubseteq> g)"
ballarin@27713
   284
wenzelm@30363
   285
text (in weak_partial_order) {* Could weaken these to @{term "l \<in> carrier L \<and> l
wenzelm@30363
   286
  .\<in> A"} and @{term "g \<in> carrier L \<and> g .\<in> A"}. *}
ballarin@14551
   287
ballarin@27700
   288
lemma least_closed [intro, simp]:
ballarin@27713
   289
  "least L l A ==> l \<in> carrier L"
ballarin@14551
   290
  by (unfold least_def) fast
ballarin@14551
   291
ballarin@22063
   292
lemma least_mem:
ballarin@22063
   293
  "least L l A ==> l \<in> A"
ballarin@14551
   294
  by (unfold least_def) fast
ballarin@14551
   295
ballarin@27713
   296
lemma (in weak_partial_order) weak_least_unique:
ballarin@27713
   297
  "[| least L x A; least L y A |] ==> x .= y"
ballarin@14551
   298
  by (unfold least_def) blast
ballarin@14551
   299
ballarin@22063
   300
lemma least_le:
ballarin@22063
   301
  fixes L (structure)
ballarin@22063
   302
  shows "[| least L x A; a \<in> A |] ==> x \<sqsubseteq> a"
ballarin@14551
   303
  by (unfold least_def) fast
ballarin@14551
   304
ballarin@27713
   305
lemma (in weak_partial_order) least_cong:
ballarin@27713
   306
  "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==> least L x A = least L x' A"
ballarin@27713
   307
  by (unfold least_def) (auto dest: sym)
ballarin@27713
   308
wenzelm@30363
   309
text (in weak_partial_order) {* @{const least} is not congruent in the second parameter for 
wenzelm@30363
   310
  @{term "A {.=} A'"} *}
ballarin@27713
   311
ballarin@27713
   312
lemma (in weak_partial_order) least_Upper_cong_l:
ballarin@27713
   313
  assumes "x .= x'"
ballarin@27713
   314
    and "x \<in> carrier L" "x' \<in> carrier L"
ballarin@27713
   315
    and "A \<subseteq> carrier L"
ballarin@27713
   316
  shows "least L x (Upper L A) = least L x' (Upper L A)"
ballarin@27713
   317
  apply (rule least_cong) using assms by auto
ballarin@27713
   318
ballarin@27713
   319
lemma (in weak_partial_order) least_Upper_cong_r:
ballarin@27713
   320
  assumes Acarrs: "A \<subseteq> carrier L" "A' \<subseteq> carrier L" (* unneccessary with current Upper? *)
ballarin@27713
   321
    and AA': "A {.=} A'"
ballarin@27713
   322
  shows "least L x (Upper L A) = least L x (Upper L A')"
ballarin@27713
   323
apply (subgoal_tac "Upper L A = Upper L A'", simp)
ballarin@27713
   324
by (rule Upper_cong) fact+
ballarin@27713
   325
ballarin@22063
   326
lemma least_UpperI:
ballarin@22063
   327
  fixes L (structure)
ballarin@14551
   328
  assumes above: "!! x. x \<in> A ==> x \<sqsubseteq> s"
ballarin@22063
   329
    and below: "!! y. y \<in> Upper L A ==> s \<sqsubseteq> y"
ballarin@22063
   330
    and L: "A \<subseteq> carrier L"  "s \<in> carrier L"
ballarin@22063
   331
  shows "least L s (Upper L A)"
wenzelm@14693
   332
proof -
ballarin@22063
   333
  have "Upper L A \<subseteq> carrier L" by simp
ballarin@22063
   334
  moreover from above L have "s \<in> Upper L A" by (simp add: Upper_def)
ballarin@22063
   335
  moreover from below have "ALL x : Upper L A. s \<sqsubseteq> x" by fast
wenzelm@14693
   336
  ultimately show ?thesis by (simp add: least_def)
ballarin@14551
   337
qed
ballarin@14551
   338
ballarin@27713
   339
lemma least_Upper_above:
ballarin@27713
   340
  fixes L (structure)
ballarin@27713
   341
  shows "[| least L s (Upper L A); x \<in> A; A \<subseteq> carrier L |] ==> x \<sqsubseteq> s"
ballarin@27713
   342
  by (unfold least_def) blast
ballarin@14551
   343
ballarin@27700
   344
lemma greatest_closed [intro, simp]:
ballarin@27713
   345
  "greatest L l A ==> l \<in> carrier L"
ballarin@14551
   346
  by (unfold greatest_def) fast
ballarin@14551
   347
ballarin@22063
   348
lemma greatest_mem:
ballarin@22063
   349
  "greatest L l A ==> l \<in> A"
ballarin@14551
   350
  by (unfold greatest_def) fast
ballarin@14551
   351
ballarin@27713
   352
lemma (in weak_partial_order) weak_greatest_unique:
ballarin@27713
   353
  "[| greatest L x A; greatest L y A |] ==> x .= y"
ballarin@14551
   354
  by (unfold greatest_def) blast
ballarin@14551
   355
ballarin@22063
   356
lemma greatest_le:
ballarin@22063
   357
  fixes L (structure)
ballarin@22063
   358
  shows "[| greatest L x A; a \<in> A |] ==> a \<sqsubseteq> x"
ballarin@14551
   359
  by (unfold greatest_def) fast
ballarin@14551
   360
ballarin@27713
   361
lemma (in weak_partial_order) greatest_cong:
ballarin@27713
   362
  "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==>
ballarin@27713
   363
  greatest L x A = greatest L x' A"
ballarin@27713
   364
  by (unfold greatest_def) (auto dest: sym)
ballarin@27713
   365
wenzelm@30363
   366
text (in weak_partial_order) {* @{const greatest} is not congruent in the second parameter for 
wenzelm@30363
   367
  @{term "A {.=} A'"} *}
ballarin@27713
   368
ballarin@27713
   369
lemma (in weak_partial_order) greatest_Lower_cong_l:
ballarin@27713
   370
  assumes "x .= x'"
ballarin@27713
   371
    and "x \<in> carrier L" "x' \<in> carrier L"
ballarin@27713
   372
    and "A \<subseteq> carrier L" (* unneccessary with current Lower *)
ballarin@27713
   373
  shows "greatest L x (Lower L A) = greatest L x' (Lower L A)"
ballarin@27713
   374
  apply (rule greatest_cong) using assms by auto
ballarin@27713
   375
ballarin@27713
   376
lemma (in weak_partial_order) greatest_Lower_cong_r:
ballarin@27713
   377
  assumes Acarrs: "A \<subseteq> carrier L" "A' \<subseteq> carrier L"
ballarin@27713
   378
    and AA': "A {.=} A'"
ballarin@27713
   379
  shows "greatest L x (Lower L A) = greatest L x (Lower L A')"
ballarin@27713
   380
apply (subgoal_tac "Lower L A = Lower L A'", simp)
ballarin@27713
   381
by (rule Lower_cong) fact+
ballarin@27713
   382
ballarin@22063
   383
lemma greatest_LowerI:
ballarin@22063
   384
  fixes L (structure)
ballarin@14551
   385
  assumes below: "!! x. x \<in> A ==> i \<sqsubseteq> x"
ballarin@22063
   386
    and above: "!! y. y \<in> Lower L A ==> y \<sqsubseteq> i"
ballarin@22063
   387
    and L: "A \<subseteq> carrier L"  "i \<in> carrier L"
ballarin@22063
   388
  shows "greatest L i (Lower L A)"
wenzelm@14693
   389
proof -
ballarin@22063
   390
  have "Lower L A \<subseteq> carrier L" by simp
ballarin@22063
   391
  moreover from below L have "i \<in> Lower L A" by (simp add: Lower_def)
ballarin@22063
   392
  moreover from above have "ALL x : Lower L A. x \<sqsubseteq> i" by fast
wenzelm@14693
   393
  ultimately show ?thesis by (simp add: greatest_def)
ballarin@14551
   394
qed
ballarin@14551
   395
ballarin@27700
   396
lemma greatest_Lower_below:
ballarin@22063
   397
  fixes L (structure)
ballarin@22063
   398
  shows "[| greatest L i (Lower L A); x \<in> A; A \<subseteq> carrier L |] ==> i \<sqsubseteq> x"
ballarin@14551
   399
  by (unfold greatest_def) blast
ballarin@14551
   400
ballarin@27713
   401
text {* Supremum and infimum *}
ballarin@27713
   402
ballarin@27713
   403
constdefs (structure L)
ballarin@27713
   404
  sup :: "[_, 'a set] => 'a" ("\<Squnion>\<index>_" [90] 90)
ballarin@27713
   405
  "\<Squnion>A == SOME x. least L x (Upper L A)"
ballarin@27713
   406
ballarin@27713
   407
  inf :: "[_, 'a set] => 'a" ("\<Sqinter>\<index>_" [90] 90)
ballarin@27713
   408
  "\<Sqinter>A == SOME x. greatest L x (Lower L A)"
ballarin@27713
   409
ballarin@27713
   410
  join :: "[_, 'a, 'a] => 'a" (infixl "\<squnion>\<index>" 65)
ballarin@27713
   411
  "x \<squnion> y == \<Squnion> {x, y}"
ballarin@27713
   412
ballarin@27713
   413
  meet :: "[_, 'a, 'a] => 'a" (infixl "\<sqinter>\<index>" 70)
ballarin@27713
   414
  "x \<sqinter> y == \<Sqinter> {x, y}"
ballarin@27713
   415
ballarin@27713
   416
ballarin@27713
   417
subsection {* Lattices *}
ballarin@27713
   418
ballarin@27713
   419
locale weak_upper_semilattice = weak_partial_order +
ballarin@27713
   420
  assumes sup_of_two_exists:
ballarin@27713
   421
    "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
ballarin@27713
   422
ballarin@27713
   423
locale weak_lower_semilattice = weak_partial_order +
ballarin@27713
   424
  assumes inf_of_two_exists:
ballarin@27713
   425
    "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. greatest L s (Lower L {x, y})"
ballarin@27713
   426
ballarin@27713
   427
locale weak_lattice = weak_upper_semilattice + weak_lower_semilattice
ballarin@27713
   428
wenzelm@14666
   429
ballarin@14551
   430
subsubsection {* Supremum *}
ballarin@14551
   431
ballarin@27713
   432
lemma (in weak_upper_semilattice) joinI:
ballarin@22063
   433
  "[| !!l. least L l (Upper L {x, y}) ==> P l; x \<in> carrier L; y \<in> carrier L |]
ballarin@14551
   434
  ==> P (x \<squnion> y)"
ballarin@14551
   435
proof (unfold join_def sup_def)
ballarin@22063
   436
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@22063
   437
    and P: "!!l. least L l (Upper L {x, y}) ==> P l"
ballarin@22063
   438
  with sup_of_two_exists obtain s where "least L s (Upper L {x, y})" by fast
ballarin@27713
   439
  with L show "P (SOME l. least L l (Upper L {x, y}))"
ballarin@27713
   440
    by (fast intro: someI2 P)
ballarin@14551
   441
qed
ballarin@14551
   442
ballarin@27713
   443
lemma (in weak_upper_semilattice) join_closed [simp]:
ballarin@22063
   444
  "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<squnion> y \<in> carrier L"
ballarin@27700
   445
  by (rule joinI) (rule least_closed)
ballarin@14551
   446
ballarin@27713
   447
lemma (in weak_upper_semilattice) join_cong_l:
ballarin@27713
   448
  assumes carr: "x \<in> carrier L" "x' \<in> carrier L" "y \<in> carrier L"
ballarin@27713
   449
    and xx': "x .= x'"
ballarin@27713
   450
  shows "x \<squnion> y .= x' \<squnion> y"
ballarin@27713
   451
proof (rule joinI, rule joinI)
ballarin@27713
   452
  fix a b
ballarin@27713
   453
  from xx' carr
ballarin@27713
   454
      have seq: "{x, y} {.=} {x', y}" by (rule set_eq_pairI)
ballarin@27713
   455
ballarin@27713
   456
  assume leasta: "least L a (Upper L {x, y})"
ballarin@27713
   457
  assume "least L b (Upper L {x', y})"
ballarin@27713
   458
  with carr
ballarin@27713
   459
      have leastb: "least L b (Upper L {x, y})"
ballarin@27713
   460
      by (simp add: least_Upper_cong_r[OF _ _ seq])
ballarin@27713
   461
ballarin@27713
   462
  from leasta leastb
ballarin@27713
   463
      show "a .= b" by (rule weak_least_unique)
ballarin@27713
   464
qed (rule carr)+
ballarin@14551
   465
ballarin@27713
   466
lemma (in weak_upper_semilattice) join_cong_r:
ballarin@27713
   467
  assumes carr: "x \<in> carrier L" "y \<in> carrier L" "y' \<in> carrier L"
ballarin@27713
   468
    and yy': "y .= y'"
ballarin@27713
   469
  shows "x \<squnion> y .= x \<squnion> y'"
ballarin@27713
   470
proof (rule joinI, rule joinI)
ballarin@27713
   471
  fix a b
ballarin@27713
   472
  have "{x, y} = {y, x}" by fast
ballarin@27713
   473
  also from carr yy'
ballarin@27713
   474
      have "{y, x} {.=} {y', x}" by (intro set_eq_pairI)
ballarin@27713
   475
  also have "{y', x} = {x, y'}" by fast
ballarin@27713
   476
  finally
ballarin@27713
   477
      have seq: "{x, y} {.=} {x, y'}" .
ballarin@14551
   478
ballarin@27713
   479
  assume leasta: "least L a (Upper L {x, y})"
ballarin@27713
   480
  assume "least L b (Upper L {x, y'})"
ballarin@27713
   481
  with carr
ballarin@27713
   482
      have leastb: "least L b (Upper L {x, y})"
ballarin@27713
   483
      by (simp add: least_Upper_cong_r[OF _ _ seq])
ballarin@27713
   484
ballarin@27713
   485
  from leasta leastb
ballarin@27713
   486
      show "a .= b" by (rule weak_least_unique)
ballarin@27713
   487
qed (rule carr)+
ballarin@27713
   488
ballarin@27713
   489
lemma (in weak_partial_order) sup_of_singletonI:      (* only reflexivity needed ? *)
ballarin@27713
   490
  "x \<in> carrier L ==> least L x (Upper L {x})"
ballarin@27713
   491
  by (rule least_UpperI) auto
ballarin@27713
   492
ballarin@27713
   493
lemma (in weak_partial_order) weak_sup_of_singleton [simp]:
ballarin@27713
   494
  "x \<in> carrier L ==> \<Squnion>{x} .= x"
ballarin@27713
   495
  unfolding sup_def
ballarin@27713
   496
  by (rule someI2) (auto intro: weak_least_unique sup_of_singletonI)
ballarin@27713
   497
ballarin@27713
   498
lemma (in weak_partial_order) sup_of_singleton_closed [simp]:
ballarin@27713
   499
  "x \<in> carrier L \<Longrightarrow> \<Squnion>{x} \<in> carrier L"
ballarin@27713
   500
  unfolding sup_def
ballarin@27713
   501
  by (rule someI2) (auto intro: sup_of_singletonI)
wenzelm@14666
   502
wenzelm@14666
   503
text {* Condition on @{text A}: supremum exists. *}
ballarin@14551
   504
ballarin@27713
   505
lemma (in weak_upper_semilattice) sup_insertI:
ballarin@22063
   506
  "[| !!s. least L s (Upper L (insert x A)) ==> P s;
ballarin@22063
   507
  least L a (Upper L A); x \<in> carrier L; A \<subseteq> carrier L |]
wenzelm@14693
   508
  ==> P (\<Squnion>(insert x A))"
ballarin@14551
   509
proof (unfold sup_def)
ballarin@22063
   510
  assume L: "x \<in> carrier L"  "A \<subseteq> carrier L"
ballarin@22063
   511
    and P: "!!l. least L l (Upper L (insert x A)) ==> P l"
ballarin@22063
   512
    and least_a: "least L a (Upper L A)"
ballarin@22063
   513
  from L least_a have La: "a \<in> carrier L" by simp
ballarin@14551
   514
  from L sup_of_two_exists least_a
ballarin@22063
   515
  obtain s where least_s: "least L s (Upper L {a, x})" by blast
ballarin@27713
   516
  show "P (SOME l. least L l (Upper L (insert x A)))"
ballarin@27713
   517
  proof (rule someI2)
ballarin@22063
   518
    show "least L s (Upper L (insert x A))"
ballarin@14551
   519
    proof (rule least_UpperI)
ballarin@14551
   520
      fix z
wenzelm@14693
   521
      assume "z \<in> insert x A"
wenzelm@14693
   522
      then show "z \<sqsubseteq> s"
wenzelm@14693
   523
      proof
wenzelm@14693
   524
        assume "z = x" then show ?thesis
wenzelm@14693
   525
          by (simp add: least_Upper_above [OF least_s] L La)
wenzelm@14693
   526
      next
wenzelm@14693
   527
        assume "z \<in> A"
wenzelm@14693
   528
        with L least_s least_a show ?thesis
ballarin@27713
   529
          by (rule_tac le_trans [where y = a]) (auto dest: least_Upper_above)
wenzelm@14693
   530
      qed
wenzelm@14693
   531
    next
wenzelm@14693
   532
      fix y
ballarin@22063
   533
      assume y: "y \<in> Upper L (insert x A)"
wenzelm@14693
   534
      show "s \<sqsubseteq> y"
wenzelm@14693
   535
      proof (rule least_le [OF least_s], rule Upper_memI)
wenzelm@32960
   536
        fix z
wenzelm@32960
   537
        assume z: "z \<in> {a, x}"
wenzelm@32960
   538
        then show "z \<sqsubseteq> y"
wenzelm@32960
   539
        proof
ballarin@22063
   540
          have y': "y \<in> Upper L A"
ballarin@22063
   541
            apply (rule subsetD [where A = "Upper L (insert x A)"])
wenzelm@23463
   542
             apply (rule Upper_antimono)
wenzelm@32960
   543
             apply blast
wenzelm@32960
   544
            apply (rule y)
wenzelm@14693
   545
            done
wenzelm@14693
   546
          assume "z = a"
wenzelm@14693
   547
          with y' least_a show ?thesis by (fast dest: least_le)
wenzelm@32960
   548
        next
wenzelm@32960
   549
          assume "z \<in> {x}"  (* FIXME "z = x"; declare specific elim rule for "insert x {}" (!?) *)
wenzelm@14693
   550
          with y L show ?thesis by blast
wenzelm@32960
   551
        qed
wenzelm@23350
   552
      qed (rule Upper_closed [THEN subsetD, OF y])
wenzelm@14693
   553
    next
ballarin@22063
   554
      from L show "insert x A \<subseteq> carrier L" by simp
ballarin@22063
   555
      from least_s show "s \<in> carrier L" by simp
ballarin@14551
   556
    qed
wenzelm@23350
   557
  qed (rule P)
ballarin@14551
   558
qed
ballarin@14551
   559
ballarin@27713
   560
lemma (in weak_upper_semilattice) finite_sup_least:
ballarin@22063
   561
  "[| finite A; A \<subseteq> carrier L; A ~= {} |] ==> least L (\<Squnion>A) (Upper L A)"
berghofe@22265
   562
proof (induct set: finite)
wenzelm@14693
   563
  case empty
wenzelm@14693
   564
  then show ?case by simp
ballarin@14551
   565
next
nipkow@15328
   566
  case (insert x A)
ballarin@14551
   567
  show ?case
ballarin@14551
   568
  proof (cases "A = {}")
ballarin@14551
   569
    case True
ballarin@27713
   570
    with insert show ?thesis
ballarin@27713
   571
      by simp (simp add: least_cong [OF weak_sup_of_singleton]
wenzelm@32960
   572
        sup_of_singleton_closed sup_of_singletonI)
wenzelm@32960
   573
        (* The above step is hairy; least_cong can make simp loop.
wenzelm@32960
   574
        Would want special version of simp to apply least_cong. *)
ballarin@14551
   575
  next
ballarin@14551
   576
    case False
ballarin@22063
   577
    with insert have "least L (\<Squnion>A) (Upper L A)" by simp
wenzelm@14693
   578
    with _ show ?thesis
wenzelm@14693
   579
      by (rule sup_insertI) (simp_all add: insert [simplified])
ballarin@14551
   580
  qed
ballarin@14551
   581
qed
ballarin@14551
   582
ballarin@27713
   583
lemma (in weak_upper_semilattice) finite_sup_insertI:
ballarin@22063
   584
  assumes P: "!!l. least L l (Upper L (insert x A)) ==> P l"
ballarin@22063
   585
    and xA: "finite A"  "x \<in> carrier L"  "A \<subseteq> carrier L"
ballarin@14551
   586
  shows "P (\<Squnion> (insert x A))"
ballarin@14551
   587
proof (cases "A = {}")
ballarin@14551
   588
  case True with P and xA show ?thesis
ballarin@27713
   589
    by (simp add: finite_sup_least)
ballarin@14551
   590
next
ballarin@14551
   591
  case False with P and xA show ?thesis
ballarin@14551
   592
    by (simp add: sup_insertI finite_sup_least)
ballarin@14551
   593
qed
ballarin@14551
   594
ballarin@27713
   595
lemma (in weak_upper_semilattice) finite_sup_closed [simp]:
ballarin@22063
   596
  "[| finite A; A \<subseteq> carrier L; A ~= {} |] ==> \<Squnion>A \<in> carrier L"
berghofe@22265
   597
proof (induct set: finite)
ballarin@14551
   598
  case empty then show ?case by simp
ballarin@14551
   599
next
nipkow@15328
   600
  case insert then show ?case
wenzelm@14693
   601
    by - (rule finite_sup_insertI, simp_all)
ballarin@14551
   602
qed
ballarin@14551
   603
ballarin@27713
   604
lemma (in weak_upper_semilattice) join_left:
ballarin@22063
   605
  "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> x \<squnion> y"
wenzelm@14693
   606
  by (rule joinI [folded join_def]) (blast dest: least_mem)
ballarin@14551
   607
ballarin@27713
   608
lemma (in weak_upper_semilattice) join_right:
ballarin@22063
   609
  "[| x \<in> carrier L; y \<in> carrier L |] ==> y \<sqsubseteq> x \<squnion> y"
wenzelm@14693
   610
  by (rule joinI [folded join_def]) (blast dest: least_mem)
ballarin@14551
   611
ballarin@27713
   612
lemma (in weak_upper_semilattice) sup_of_two_least:
ballarin@22063
   613
  "[| x \<in> carrier L; y \<in> carrier L |] ==> least L (\<Squnion>{x, y}) (Upper L {x, y})"
ballarin@14551
   614
proof (unfold sup_def)
ballarin@22063
   615
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@22063
   616
  with sup_of_two_exists obtain s where "least L s (Upper L {x, y})" by fast
ballarin@27713
   617
  with L show "least L (SOME z. least L z (Upper L {x, y})) (Upper L {x, y})"
ballarin@27713
   618
  by (fast intro: someI2 weak_least_unique)  (* blast fails *)
ballarin@14551
   619
qed
ballarin@14551
   620
ballarin@27713
   621
lemma (in weak_upper_semilattice) join_le:
wenzelm@14693
   622
  assumes sub: "x \<sqsubseteq> z"  "y \<sqsubseteq> z"
wenzelm@23350
   623
    and x: "x \<in> carrier L" and y: "y \<in> carrier L" and z: "z \<in> carrier L"
ballarin@14551
   624
  shows "x \<squnion> y \<sqsubseteq> z"
wenzelm@23350
   625
proof (rule joinI [OF _ x y])
ballarin@14551
   626
  fix s
ballarin@22063
   627
  assume "least L s (Upper L {x, y})"
wenzelm@23350
   628
  with sub z show "s \<sqsubseteq> z" by (fast elim: least_le intro: Upper_memI)
ballarin@14551
   629
qed
wenzelm@14693
   630
ballarin@27713
   631
lemma (in weak_upper_semilattice) weak_join_assoc_lemma:
ballarin@22063
   632
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
   633
  shows "x \<squnion> (y \<squnion> z) .= \<Squnion>{x, y, z}"
ballarin@14551
   634
proof (rule finite_sup_insertI)
wenzelm@14651
   635
  -- {* The textbook argument in Jacobson I, p 457 *}
ballarin@14551
   636
  fix s
ballarin@22063
   637
  assume sup: "least L s (Upper L {x, y, z})"
ballarin@27713
   638
  show "x \<squnion> (y \<squnion> z) .= s"
nipkow@33657
   639
  proof (rule weak_le_antisym)
ballarin@14551
   640
    from sup L show "x \<squnion> (y \<squnion> z) \<sqsubseteq> s"
ballarin@14551
   641
      by (fastsimp intro!: join_le elim: least_Upper_above)
ballarin@14551
   642
  next
ballarin@14551
   643
    from sup L show "s \<sqsubseteq> x \<squnion> (y \<squnion> z)"
ballarin@14551
   644
    by (erule_tac least_le)
ballarin@27713
   645
      (blast intro!: Upper_memI intro: le_trans join_left join_right join_closed)
ballarin@27700
   646
  qed (simp_all add: L least_closed [OF sup])
ballarin@14551
   647
qed (simp_all add: L)
ballarin@14551
   648
ballarin@27713
   649
text {* Commutativity holds for @{text "="}. *}
ballarin@27713
   650
ballarin@22063
   651
lemma join_comm:
ballarin@22063
   652
  fixes L (structure)
ballarin@22063
   653
  shows "x \<squnion> y = y \<squnion> x"
ballarin@14551
   654
  by (unfold join_def) (simp add: insert_commute)
ballarin@14551
   655
ballarin@27713
   656
lemma (in weak_upper_semilattice) weak_join_assoc:
ballarin@22063
   657
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
   658
  shows "(x \<squnion> y) \<squnion> z .= x \<squnion> (y \<squnion> z)"
ballarin@14551
   659
proof -
ballarin@27713
   660
  (* FIXME: could be simplified by improved simp: uniform use of .=,
ballarin@27713
   661
     omit [symmetric] in last step. *)
ballarin@14551
   662
  have "(x \<squnion> y) \<squnion> z = z \<squnion> (x \<squnion> y)" by (simp only: join_comm)
ballarin@27713
   663
  also from L have "... .= \<Squnion>{z, x, y}" by (simp add: weak_join_assoc_lemma)
wenzelm@14693
   664
  also from L have "... = \<Squnion>{x, y, z}" by (simp add: insert_commute)
ballarin@27713
   665
  also from L have "... .= x \<squnion> (y \<squnion> z)" by (simp add: weak_join_assoc_lemma [symmetric])
ballarin@27713
   666
  finally show ?thesis by (simp add: L)
ballarin@14551
   667
qed
ballarin@14551
   668
wenzelm@14693
   669
ballarin@14551
   670
subsubsection {* Infimum *}
ballarin@14551
   671
ballarin@27713
   672
lemma (in weak_lower_semilattice) meetI:
ballarin@22063
   673
  "[| !!i. greatest L i (Lower L {x, y}) ==> P i;
ballarin@22063
   674
  x \<in> carrier L; y \<in> carrier L |]
ballarin@14551
   675
  ==> P (x \<sqinter> y)"
ballarin@14551
   676
proof (unfold meet_def inf_def)
ballarin@22063
   677
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@22063
   678
    and P: "!!g. greatest L g (Lower L {x, y}) ==> P g"
ballarin@22063
   679
  with inf_of_two_exists obtain i where "greatest L i (Lower L {x, y})" by fast
ballarin@27713
   680
  with L show "P (SOME g. greatest L g (Lower L {x, y}))"
ballarin@27713
   681
  by (fast intro: someI2 weak_greatest_unique P)
ballarin@14551
   682
qed
ballarin@14551
   683
ballarin@27713
   684
lemma (in weak_lower_semilattice) meet_closed [simp]:
ballarin@22063
   685
  "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqinter> y \<in> carrier L"
ballarin@27700
   686
  by (rule meetI) (rule greatest_closed)
ballarin@14551
   687
ballarin@27713
   688
lemma (in weak_lower_semilattice) meet_cong_l:
ballarin@27713
   689
  assumes carr: "x \<in> carrier L" "x' \<in> carrier L" "y \<in> carrier L"
ballarin@27713
   690
    and xx': "x .= x'"
ballarin@27713
   691
  shows "x \<sqinter> y .= x' \<sqinter> y"
ballarin@27713
   692
proof (rule meetI, rule meetI)
ballarin@27713
   693
  fix a b
ballarin@27713
   694
  from xx' carr
ballarin@27713
   695
      have seq: "{x, y} {.=} {x', y}" by (rule set_eq_pairI)
ballarin@27713
   696
ballarin@27713
   697
  assume greatesta: "greatest L a (Lower L {x, y})"
ballarin@27713
   698
  assume "greatest L b (Lower L {x', y})"
ballarin@27713
   699
  with carr
ballarin@27713
   700
      have greatestb: "greatest L b (Lower L {x, y})"
ballarin@27713
   701
      by (simp add: greatest_Lower_cong_r[OF _ _ seq])
ballarin@27713
   702
ballarin@27713
   703
  from greatesta greatestb
ballarin@27713
   704
      show "a .= b" by (rule weak_greatest_unique)
ballarin@27713
   705
qed (rule carr)+
ballarin@14551
   706
ballarin@27713
   707
lemma (in weak_lower_semilattice) meet_cong_r:
ballarin@27713
   708
  assumes carr: "x \<in> carrier L" "y \<in> carrier L" "y' \<in> carrier L"
ballarin@27713
   709
    and yy': "y .= y'"
ballarin@27713
   710
  shows "x \<sqinter> y .= x \<sqinter> y'"
ballarin@27713
   711
proof (rule meetI, rule meetI)
ballarin@27713
   712
  fix a b
ballarin@27713
   713
  have "{x, y} = {y, x}" by fast
ballarin@27713
   714
  also from carr yy'
ballarin@27713
   715
      have "{y, x} {.=} {y', x}" by (intro set_eq_pairI)
ballarin@27713
   716
  also have "{y', x} = {x, y'}" by fast
ballarin@27713
   717
  finally
ballarin@27713
   718
      have seq: "{x, y} {.=} {x, y'}" .
ballarin@27713
   719
ballarin@27713
   720
  assume greatesta: "greatest L a (Lower L {x, y})"
ballarin@27713
   721
  assume "greatest L b (Lower L {x, y'})"
ballarin@27713
   722
  with carr
ballarin@27713
   723
      have greatestb: "greatest L b (Lower L {x, y})"
ballarin@27713
   724
      by (simp add: greatest_Lower_cong_r[OF _ _ seq])
ballarin@14551
   725
ballarin@27713
   726
  from greatesta greatestb
ballarin@27713
   727
      show "a .= b" by (rule weak_greatest_unique)
ballarin@27713
   728
qed (rule carr)+
ballarin@27713
   729
ballarin@27713
   730
lemma (in weak_partial_order) inf_of_singletonI:      (* only reflexivity needed ? *)
ballarin@27713
   731
  "x \<in> carrier L ==> greatest L x (Lower L {x})"
ballarin@27713
   732
  by (rule greatest_LowerI) auto
ballarin@14551
   733
ballarin@27713
   734
lemma (in weak_partial_order) weak_inf_of_singleton [simp]:
ballarin@27713
   735
  "x \<in> carrier L ==> \<Sqinter>{x} .= x"
ballarin@27713
   736
  unfolding inf_def
ballarin@27713
   737
  by (rule someI2) (auto intro: weak_greatest_unique inf_of_singletonI)
ballarin@27713
   738
ballarin@27713
   739
lemma (in weak_partial_order) inf_of_singleton_closed:
ballarin@27713
   740
  "x \<in> carrier L ==> \<Sqinter>{x} \<in> carrier L"
ballarin@27713
   741
  unfolding inf_def
ballarin@27713
   742
  by (rule someI2) (auto intro: inf_of_singletonI)
ballarin@27713
   743
ballarin@27713
   744
text {* Condition on @{text A}: infimum exists. *}
ballarin@27713
   745
ballarin@27713
   746
lemma (in weak_lower_semilattice) inf_insertI:
ballarin@22063
   747
  "[| !!i. greatest L i (Lower L (insert x A)) ==> P i;
ballarin@22063
   748
  greatest L a (Lower L A); x \<in> carrier L; A \<subseteq> carrier L |]
wenzelm@14693
   749
  ==> P (\<Sqinter>(insert x A))"
ballarin@14551
   750
proof (unfold inf_def)
ballarin@22063
   751
  assume L: "x \<in> carrier L"  "A \<subseteq> carrier L"
ballarin@22063
   752
    and P: "!!g. greatest L g (Lower L (insert x A)) ==> P g"
ballarin@22063
   753
    and greatest_a: "greatest L a (Lower L A)"
ballarin@22063
   754
  from L greatest_a have La: "a \<in> carrier L" by simp
ballarin@14551
   755
  from L inf_of_two_exists greatest_a
ballarin@22063
   756
  obtain i where greatest_i: "greatest L i (Lower L {a, x})" by blast
ballarin@27713
   757
  show "P (SOME g. greatest L g (Lower L (insert x A)))"
ballarin@27713
   758
  proof (rule someI2)
ballarin@22063
   759
    show "greatest L i (Lower L (insert x A))"
ballarin@14551
   760
    proof (rule greatest_LowerI)
ballarin@14551
   761
      fix z
wenzelm@14693
   762
      assume "z \<in> insert x A"
wenzelm@14693
   763
      then show "i \<sqsubseteq> z"
wenzelm@14693
   764
      proof
wenzelm@14693
   765
        assume "z = x" then show ?thesis
ballarin@27700
   766
          by (simp add: greatest_Lower_below [OF greatest_i] L La)
wenzelm@14693
   767
      next
wenzelm@14693
   768
        assume "z \<in> A"
wenzelm@14693
   769
        with L greatest_i greatest_a show ?thesis
ballarin@27713
   770
          by (rule_tac le_trans [where y = a]) (auto dest: greatest_Lower_below)
wenzelm@14693
   771
      qed
wenzelm@14693
   772
    next
wenzelm@14693
   773
      fix y
ballarin@22063
   774
      assume y: "y \<in> Lower L (insert x A)"
wenzelm@14693
   775
      show "y \<sqsubseteq> i"
wenzelm@14693
   776
      proof (rule greatest_le [OF greatest_i], rule Lower_memI)
wenzelm@32960
   777
        fix z
wenzelm@32960
   778
        assume z: "z \<in> {a, x}"
wenzelm@32960
   779
        then show "y \<sqsubseteq> z"
wenzelm@32960
   780
        proof
ballarin@22063
   781
          have y': "y \<in> Lower L A"
ballarin@22063
   782
            apply (rule subsetD [where A = "Lower L (insert x A)"])
wenzelm@23463
   783
            apply (rule Lower_antimono)
wenzelm@32960
   784
             apply blast
wenzelm@32960
   785
            apply (rule y)
wenzelm@14693
   786
            done
wenzelm@14693
   787
          assume "z = a"
wenzelm@14693
   788
          with y' greatest_a show ?thesis by (fast dest: greatest_le)
wenzelm@32960
   789
        next
wenzelm@14693
   790
          assume "z \<in> {x}"
wenzelm@14693
   791
          with y L show ?thesis by blast
wenzelm@32960
   792
        qed
wenzelm@23350
   793
      qed (rule Lower_closed [THEN subsetD, OF y])
wenzelm@14693
   794
    next
ballarin@22063
   795
      from L show "insert x A \<subseteq> carrier L" by simp
ballarin@22063
   796
      from greatest_i show "i \<in> carrier L" by simp
ballarin@14551
   797
    qed
wenzelm@23350
   798
  qed (rule P)
ballarin@14551
   799
qed
ballarin@14551
   800
ballarin@27713
   801
lemma (in weak_lower_semilattice) finite_inf_greatest:
ballarin@22063
   802
  "[| finite A; A \<subseteq> carrier L; A ~= {} |] ==> greatest L (\<Sqinter>A) (Lower L A)"
berghofe@22265
   803
proof (induct set: finite)
ballarin@14551
   804
  case empty then show ?case by simp
ballarin@14551
   805
next
nipkow@15328
   806
  case (insert x A)
ballarin@14551
   807
  show ?case
ballarin@14551
   808
  proof (cases "A = {}")
ballarin@14551
   809
    case True
ballarin@27713
   810
    with insert show ?thesis
ballarin@27713
   811
      by simp (simp add: greatest_cong [OF weak_inf_of_singleton]
wenzelm@32960
   812
        inf_of_singleton_closed inf_of_singletonI)
ballarin@14551
   813
  next
ballarin@14551
   814
    case False
ballarin@14551
   815
    from insert show ?thesis
ballarin@14551
   816
    proof (rule_tac inf_insertI)
ballarin@22063
   817
      from False insert show "greatest L (\<Sqinter>A) (Lower L A)" by simp
ballarin@14551
   818
    qed simp_all
ballarin@14551
   819
  qed
ballarin@14551
   820
qed
ballarin@14551
   821
ballarin@27713
   822
lemma (in weak_lower_semilattice) finite_inf_insertI:
ballarin@22063
   823
  assumes P: "!!i. greatest L i (Lower L (insert x A)) ==> P i"
ballarin@22063
   824
    and xA: "finite A"  "x \<in> carrier L"  "A \<subseteq> carrier L"
ballarin@14551
   825
  shows "P (\<Sqinter> (insert x A))"
ballarin@14551
   826
proof (cases "A = {}")
ballarin@14551
   827
  case True with P and xA show ?thesis
ballarin@27713
   828
    by (simp add: finite_inf_greatest)
ballarin@14551
   829
next
ballarin@14551
   830
  case False with P and xA show ?thesis
ballarin@14551
   831
    by (simp add: inf_insertI finite_inf_greatest)
ballarin@14551
   832
qed
ballarin@14551
   833
ballarin@27713
   834
lemma (in weak_lower_semilattice) finite_inf_closed [simp]:
ballarin@22063
   835
  "[| finite A; A \<subseteq> carrier L; A ~= {} |] ==> \<Sqinter>A \<in> carrier L"
berghofe@22265
   836
proof (induct set: finite)
ballarin@14551
   837
  case empty then show ?case by simp
ballarin@14551
   838
next
nipkow@15328
   839
  case insert then show ?case
ballarin@14551
   840
    by (rule_tac finite_inf_insertI) (simp_all)
ballarin@14551
   841
qed
ballarin@14551
   842
ballarin@27713
   843
lemma (in weak_lower_semilattice) meet_left:
ballarin@22063
   844
  "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqinter> y \<sqsubseteq> x"
wenzelm@14693
   845
  by (rule meetI [folded meet_def]) (blast dest: greatest_mem)
ballarin@14551
   846
ballarin@27713
   847
lemma (in weak_lower_semilattice) meet_right:
ballarin@22063
   848
  "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqinter> y \<sqsubseteq> y"
wenzelm@14693
   849
  by (rule meetI [folded meet_def]) (blast dest: greatest_mem)
ballarin@14551
   850
ballarin@27713
   851
lemma (in weak_lower_semilattice) inf_of_two_greatest:
ballarin@22063
   852
  "[| x \<in> carrier L; y \<in> carrier L |] ==>
ballarin@22063
   853
  greatest L (\<Sqinter> {x, y}) (Lower L {x, y})"
ballarin@14551
   854
proof (unfold inf_def)
ballarin@22063
   855
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@22063
   856
  with inf_of_two_exists obtain s where "greatest L s (Lower L {x, y})" by fast
ballarin@14551
   857
  with L
ballarin@27713
   858
  show "greatest L (SOME z. greatest L z (Lower L {x, y})) (Lower L {x, y})"
ballarin@27713
   859
  by (fast intro: someI2 weak_greatest_unique)  (* blast fails *)
ballarin@14551
   860
qed
ballarin@14551
   861
ballarin@27713
   862
lemma (in weak_lower_semilattice) meet_le:
wenzelm@14693
   863
  assumes sub: "z \<sqsubseteq> x"  "z \<sqsubseteq> y"
wenzelm@23350
   864
    and x: "x \<in> carrier L" and y: "y \<in> carrier L" and z: "z \<in> carrier L"
ballarin@14551
   865
  shows "z \<sqsubseteq> x \<sqinter> y"
wenzelm@23350
   866
proof (rule meetI [OF _ x y])
ballarin@14551
   867
  fix i
ballarin@22063
   868
  assume "greatest L i (Lower L {x, y})"
wenzelm@23350
   869
  with sub z show "z \<sqsubseteq> i" by (fast elim: greatest_le intro: Lower_memI)
ballarin@14551
   870
qed
wenzelm@14693
   871
ballarin@27713
   872
lemma (in weak_lower_semilattice) weak_meet_assoc_lemma:
ballarin@22063
   873
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
   874
  shows "x \<sqinter> (y \<sqinter> z) .= \<Sqinter>{x, y, z}"
ballarin@14551
   875
proof (rule finite_inf_insertI)
ballarin@14551
   876
  txt {* The textbook argument in Jacobson I, p 457 *}
ballarin@14551
   877
  fix i
ballarin@22063
   878
  assume inf: "greatest L i (Lower L {x, y, z})"
ballarin@27713
   879
  show "x \<sqinter> (y \<sqinter> z) .= i"
nipkow@33657
   880
  proof (rule weak_le_antisym)
ballarin@14551
   881
    from inf L show "i \<sqsubseteq> x \<sqinter> (y \<sqinter> z)"
ballarin@27700
   882
      by (fastsimp intro!: meet_le elim: greatest_Lower_below)
ballarin@14551
   883
  next
ballarin@14551
   884
    from inf L show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> i"
ballarin@14551
   885
    by (erule_tac greatest_le)
ballarin@27713
   886
      (blast intro!: Lower_memI intro: le_trans meet_left meet_right meet_closed)
ballarin@27700
   887
  qed (simp_all add: L greatest_closed [OF inf])
ballarin@14551
   888
qed (simp_all add: L)
ballarin@14551
   889
ballarin@22063
   890
lemma meet_comm:
ballarin@22063
   891
  fixes L (structure)
ballarin@22063
   892
  shows "x \<sqinter> y = y \<sqinter> x"
ballarin@14551
   893
  by (unfold meet_def) (simp add: insert_commute)
ballarin@14551
   894
ballarin@27713
   895
lemma (in weak_lower_semilattice) weak_meet_assoc:
ballarin@22063
   896
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
   897
  shows "(x \<sqinter> y) \<sqinter> z .= x \<sqinter> (y \<sqinter> z)"
ballarin@14551
   898
proof -
ballarin@27713
   899
  (* FIXME: improved simp, see weak_join_assoc above *)
ballarin@14551
   900
  have "(x \<sqinter> y) \<sqinter> z = z \<sqinter> (x \<sqinter> y)" by (simp only: meet_comm)
ballarin@27713
   901
  also from L have "... .= \<Sqinter> {z, x, y}" by (simp add: weak_meet_assoc_lemma)
ballarin@14551
   902
  also from L have "... = \<Sqinter> {x, y, z}" by (simp add: insert_commute)
ballarin@27713
   903
  also from L have "... .= x \<sqinter> (y \<sqinter> z)" by (simp add: weak_meet_assoc_lemma [symmetric])
ballarin@27713
   904
  finally show ?thesis by (simp add: L)
ballarin@14551
   905
qed
ballarin@14551
   906
wenzelm@14693
   907
ballarin@14551
   908
subsection {* Total Orders *}
ballarin@14551
   909
ballarin@27713
   910
locale weak_total_order = weak_partial_order +
ballarin@22063
   911
  assumes total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
ballarin@14551
   912
ballarin@14551
   913
text {* Introduction rule: the usual definition of total order *}
ballarin@14551
   914
ballarin@27713
   915
lemma (in weak_partial_order) weak_total_orderI:
ballarin@22063
   916
  assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
ballarin@27713
   917
  shows "weak_total_order L"
haftmann@28823
   918
  proof qed (rule total)
ballarin@24087
   919
ballarin@24087
   920
text {* Total orders are lattices. *}
ballarin@24087
   921
ballarin@29242
   922
sublocale weak_total_order < weak: weak_lattice
haftmann@28823
   923
proof
ballarin@24087
   924
  fix x y
ballarin@24087
   925
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@24087
   926
  show "EX s. least L s (Upper L {x, y})"
ballarin@24087
   927
  proof -
ballarin@24087
   928
    note total L
ballarin@24087
   929
    moreover
ballarin@24087
   930
    {
ballarin@24087
   931
      assume "x \<sqsubseteq> y"
ballarin@24087
   932
      with L have "least L y (Upper L {x, y})"
ballarin@24087
   933
        by (rule_tac least_UpperI) auto
ballarin@24087
   934
    }
ballarin@24087
   935
    moreover
ballarin@24087
   936
    {
ballarin@24087
   937
      assume "y \<sqsubseteq> x"
ballarin@24087
   938
      with L have "least L x (Upper L {x, y})"
ballarin@24087
   939
        by (rule_tac least_UpperI) auto
ballarin@24087
   940
    }
ballarin@24087
   941
    ultimately show ?thesis by blast
ballarin@14551
   942
  qed
ballarin@24087
   943
next
ballarin@24087
   944
  fix x y
ballarin@24087
   945
  assume L: "x \<in> carrier L"  "y \<in> carrier L"
ballarin@24087
   946
  show "EX i. greatest L i (Lower L {x, y})"
ballarin@24087
   947
  proof -
ballarin@24087
   948
    note total L
ballarin@24087
   949
    moreover
ballarin@24087
   950
    {
ballarin@24087
   951
      assume "y \<sqsubseteq> x"
ballarin@24087
   952
      with L have "greatest L y (Lower L {x, y})"
ballarin@24087
   953
        by (rule_tac greatest_LowerI) auto
ballarin@24087
   954
    }
ballarin@24087
   955
    moreover
ballarin@24087
   956
    {
ballarin@24087
   957
      assume "x \<sqsubseteq> y"
ballarin@24087
   958
      with L have "greatest L x (Lower L {x, y})"
ballarin@24087
   959
        by (rule_tac greatest_LowerI) auto
ballarin@24087
   960
    }
ballarin@24087
   961
    ultimately show ?thesis by blast
ballarin@24087
   962
  qed
ballarin@24087
   963
qed
ballarin@14551
   964
wenzelm@14693
   965
ballarin@27717
   966
subsection {* Complete Lattices *}
ballarin@14551
   967
ballarin@27713
   968
locale weak_complete_lattice = weak_lattice +
ballarin@14551
   969
  assumes sup_exists:
ballarin@22063
   970
    "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
ballarin@14551
   971
    and inf_exists:
ballarin@22063
   972
    "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
ballarin@21041
   973
ballarin@14551
   974
text {* Introduction rule: the usual definition of complete lattice *}
ballarin@14551
   975
ballarin@27713
   976
lemma (in weak_partial_order) weak_complete_latticeI:
ballarin@14551
   977
  assumes sup_exists:
ballarin@22063
   978
    "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
ballarin@14551
   979
    and inf_exists:
ballarin@22063
   980
    "!!A. [| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
ballarin@27713
   981
  shows "weak_complete_lattice L"
haftmann@28823
   982
  proof qed (auto intro: sup_exists inf_exists)
ballarin@14551
   983
ballarin@22063
   984
constdefs (structure L)
ballarin@22063
   985
  top :: "_ => 'a" ("\<top>\<index>")
ballarin@22063
   986
  "\<top> == sup L (carrier L)"
ballarin@21041
   987
ballarin@22063
   988
  bottom :: "_ => 'a" ("\<bottom>\<index>")
ballarin@22063
   989
  "\<bottom> == inf L (carrier L)"
ballarin@14551
   990
ballarin@14551
   991
ballarin@27713
   992
lemma (in weak_complete_lattice) supI:
ballarin@22063
   993
  "[| !!l. least L l (Upper L A) ==> P l; A \<subseteq> carrier L |]
wenzelm@14651
   994
  ==> P (\<Squnion>A)"
ballarin@14551
   995
proof (unfold sup_def)
ballarin@22063
   996
  assume L: "A \<subseteq> carrier L"
ballarin@22063
   997
    and P: "!!l. least L l (Upper L A) ==> P l"
ballarin@22063
   998
  with sup_exists obtain s where "least L s (Upper L A)" by blast
ballarin@27713
   999
  with L show "P (SOME l. least L l (Upper L A))"
ballarin@27713
  1000
  by (fast intro: someI2 weak_least_unique P)
ballarin@14551
  1001
qed
ballarin@14551
  1002
ballarin@27713
  1003
lemma (in weak_complete_lattice) sup_closed [simp]:
ballarin@22063
  1004
  "A \<subseteq> carrier L ==> \<Squnion>A \<in> carrier L"
ballarin@14551
  1005
  by (rule supI) simp_all
ballarin@14551
  1006
ballarin@27713
  1007
lemma (in weak_complete_lattice) top_closed [simp, intro]:
ballarin@22063
  1008
  "\<top> \<in> carrier L"
ballarin@14551
  1009
  by (unfold top_def) simp
ballarin@14551
  1010
ballarin@27713
  1011
lemma (in weak_complete_lattice) infI:
ballarin@22063
  1012
  "[| !!i. greatest L i (Lower L A) ==> P i; A \<subseteq> carrier L |]
wenzelm@14693
  1013
  ==> P (\<Sqinter>A)"
ballarin@14551
  1014
proof (unfold inf_def)
ballarin@22063
  1015
  assume L: "A \<subseteq> carrier L"
ballarin@22063
  1016
    and P: "!!l. greatest L l (Lower L A) ==> P l"
ballarin@22063
  1017
  with inf_exists obtain s where "greatest L s (Lower L A)" by blast
ballarin@27713
  1018
  with L show "P (SOME l. greatest L l (Lower L A))"
ballarin@27713
  1019
  by (fast intro: someI2 weak_greatest_unique P)
ballarin@14551
  1020
qed
ballarin@14551
  1021
ballarin@27713
  1022
lemma (in weak_complete_lattice) inf_closed [simp]:
ballarin@22063
  1023
  "A \<subseteq> carrier L ==> \<Sqinter>A \<in> carrier L"
ballarin@14551
  1024
  by (rule infI) simp_all
ballarin@14551
  1025
ballarin@27713
  1026
lemma (in weak_complete_lattice) bottom_closed [simp, intro]:
ballarin@22063
  1027
  "\<bottom> \<in> carrier L"
ballarin@14551
  1028
  by (unfold bottom_def) simp
ballarin@14551
  1029
ballarin@14551
  1030
text {* Jacobson: Theorem 8.1 *}
ballarin@14551
  1031
ballarin@22063
  1032
lemma Lower_empty [simp]:
ballarin@22063
  1033
  "Lower L {} = carrier L"
ballarin@14551
  1034
  by (unfold Lower_def) simp
ballarin@14551
  1035
ballarin@22063
  1036
lemma Upper_empty [simp]:
ballarin@22063
  1037
  "Upper L {} = carrier L"
ballarin@14551
  1038
  by (unfold Upper_def) simp
ballarin@14551
  1039
ballarin@27713
  1040
theorem (in weak_partial_order) weak_complete_lattice_criterion1:
ballarin@27713
  1041
  assumes top_exists: "EX g. greatest L g (carrier L)"
ballarin@27713
  1042
    and inf_exists:
ballarin@27713
  1043
      "!!A. [| A \<subseteq> carrier L; A ~= {} |] ==> EX i. greatest L i (Lower L A)"
ballarin@27713
  1044
  shows "weak_complete_lattice L"
ballarin@27713
  1045
proof (rule weak_complete_latticeI)
ballarin@27713
  1046
  from top_exists obtain top where top: "greatest L top (carrier L)" ..
ballarin@27713
  1047
  fix A
ballarin@27713
  1048
  assume L: "A \<subseteq> carrier L"
ballarin@27713
  1049
  let ?B = "Upper L A"
ballarin@27713
  1050
  from L top have "top \<in> ?B" by (fast intro!: Upper_memI intro: greatest_le)
ballarin@27713
  1051
  then have B_non_empty: "?B ~= {}" by fast
ballarin@27713
  1052
  have B_L: "?B \<subseteq> carrier L" by simp
ballarin@27713
  1053
  from inf_exists [OF B_L B_non_empty]
ballarin@27713
  1054
  obtain b where b_inf_B: "greatest L b (Lower L ?B)" ..
ballarin@27713
  1055
  have "least L b (Upper L A)"
ballarin@27713
  1056
apply (rule least_UpperI)
ballarin@27713
  1057
   apply (rule greatest_le [where A = "Lower L ?B"])
ballarin@27713
  1058
    apply (rule b_inf_B)
ballarin@27713
  1059
   apply (rule Lower_memI)
ballarin@27713
  1060
    apply (erule Upper_memD [THEN conjunct1])
ballarin@27713
  1061
     apply assumption
ballarin@27713
  1062
    apply (rule L)
ballarin@27713
  1063
   apply (fast intro: L [THEN subsetD])
ballarin@27713
  1064
  apply (erule greatest_Lower_below [OF b_inf_B])
ballarin@27713
  1065
  apply simp
ballarin@27713
  1066
 apply (rule L)
ballarin@27713
  1067
apply (rule greatest_closed [OF b_inf_B])
ballarin@27713
  1068
done
ballarin@27713
  1069
  then show "EX s. least L s (Upper L A)" ..
ballarin@27713
  1070
next
ballarin@27713
  1071
  fix A
ballarin@27713
  1072
  assume L: "A \<subseteq> carrier L"
ballarin@27713
  1073
  show "EX i. greatest L i (Lower L A)"
ballarin@27713
  1074
  proof (cases "A = {}")
ballarin@27713
  1075
    case True then show ?thesis
ballarin@27713
  1076
      by (simp add: top_exists)
ballarin@27713
  1077
  next
ballarin@27713
  1078
    case False with L show ?thesis
ballarin@27713
  1079
      by (rule inf_exists)
ballarin@27713
  1080
  qed
ballarin@27713
  1081
qed
ballarin@27713
  1082
ballarin@27713
  1083
(* TODO: prove dual version *)
ballarin@27713
  1084
ballarin@27713
  1085
ballarin@27713
  1086
subsection {* Orders and Lattices where @{text eq} is the Equality *}
ballarin@27713
  1087
ballarin@27713
  1088
locale partial_order = weak_partial_order +
ballarin@27713
  1089
  assumes eq_is_equal: "op .= = op ="
ballarin@27713
  1090
begin
ballarin@27713
  1091
nipkow@33657
  1092
declare weak_le_antisym [rule del]
ballarin@27713
  1093
nipkow@33657
  1094
lemma le_antisym [intro]:
ballarin@27713
  1095
  "[| x \<sqsubseteq> y; y \<sqsubseteq> x; x \<in> carrier L; y \<in> carrier L |] ==> x = y"
nipkow@33657
  1096
  using weak_le_antisym unfolding eq_is_equal .
ballarin@27713
  1097
ballarin@27713
  1098
lemma lless_eq:
ballarin@27713
  1099
  "x \<sqsubset> y \<longleftrightarrow> x \<sqsubseteq> y & x \<noteq> y"
ballarin@27713
  1100
  unfolding lless_def by (simp add: eq_is_equal)
ballarin@27713
  1101
ballarin@27713
  1102
lemma lless_asym:
ballarin@27713
  1103
  assumes "a \<in> carrier L" "b \<in> carrier L"
ballarin@27713
  1104
    and "a \<sqsubset> b" "b \<sqsubset> a"
ballarin@27713
  1105
  shows "P"
ballarin@27713
  1106
  using assms unfolding lless_eq by auto
ballarin@27713
  1107
ballarin@27713
  1108
end
ballarin@27713
  1109
ballarin@27713
  1110
ballarin@27717
  1111
text {* Least and greatest, as predicate *}
ballarin@27713
  1112
ballarin@27713
  1113
lemma (in partial_order) least_unique:
ballarin@27713
  1114
  "[| least L x A; least L y A |] ==> x = y"
ballarin@27713
  1115
  using weak_least_unique unfolding eq_is_equal .
ballarin@27713
  1116
ballarin@27713
  1117
lemma (in partial_order) greatest_unique:
ballarin@27713
  1118
  "[| greatest L x A; greatest L y A |] ==> x = y"
ballarin@27713
  1119
  using weak_greatest_unique unfolding eq_is_equal .
ballarin@27713
  1120
ballarin@27713
  1121
ballarin@27717
  1122
text {* Lattices *}
ballarin@27713
  1123
ballarin@27713
  1124
locale upper_semilattice = partial_order +
ballarin@27713
  1125
  assumes sup_of_two_exists:
ballarin@27713
  1126
    "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
ballarin@27713
  1127
ballarin@29242
  1128
sublocale upper_semilattice < weak: weak_upper_semilattice
haftmann@28823
  1129
  proof qed (rule sup_of_two_exists)
ballarin@27713
  1130
ballarin@27713
  1131
locale lower_semilattice = partial_order +
ballarin@27713
  1132
  assumes inf_of_two_exists:
ballarin@27713
  1133
    "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. greatest L s (Lower L {x, y})"
ballarin@27713
  1134
ballarin@29242
  1135
sublocale lower_semilattice < weak: weak_lower_semilattice
haftmann@28823
  1136
  proof qed (rule inf_of_two_exists)
ballarin@27713
  1137
ballarin@27713
  1138
locale lattice = upper_semilattice + lower_semilattice
ballarin@27713
  1139
ballarin@27713
  1140
ballarin@27717
  1141
text {* Supremum *}
ballarin@27713
  1142
ballarin@27714
  1143
declare (in partial_order) weak_sup_of_singleton [simp del]
ballarin@27713
  1144
ballarin@27714
  1145
lemma (in partial_order) sup_of_singleton [simp]:
ballarin@27713
  1146
  "x \<in> carrier L ==> \<Squnion>{x} = x"
ballarin@27713
  1147
  using weak_sup_of_singleton unfolding eq_is_equal .
ballarin@27713
  1148
ballarin@27714
  1149
lemma (in upper_semilattice) join_assoc_lemma:
ballarin@27713
  1150
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
  1151
  shows "x \<squnion> (y \<squnion> z) = \<Squnion>{x, y, z}"
ballarin@27714
  1152
  using weak_join_assoc_lemma L unfolding eq_is_equal .
ballarin@27713
  1153
ballarin@27713
  1154
lemma (in upper_semilattice) join_assoc:
ballarin@27713
  1155
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
  1156
  shows "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
ballarin@27714
  1157
  using weak_join_assoc L unfolding eq_is_equal .
ballarin@27713
  1158
ballarin@27713
  1159
ballarin@27717
  1160
text {* Infimum *}
ballarin@27713
  1161
ballarin@27714
  1162
declare (in partial_order) weak_inf_of_singleton [simp del]
ballarin@27713
  1163
ballarin@27714
  1164
lemma (in partial_order) inf_of_singleton [simp]:
ballarin@27713
  1165
  "x \<in> carrier L ==> \<Sqinter>{x} = x"
ballarin@27713
  1166
  using weak_inf_of_singleton unfolding eq_is_equal .
ballarin@27713
  1167
ballarin@27713
  1168
text {* Condition on @{text A}: infimum exists. *}
ballarin@27713
  1169
ballarin@27714
  1170
lemma (in lower_semilattice) meet_assoc_lemma:
ballarin@27713
  1171
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
  1172
  shows "x \<sqinter> (y \<sqinter> z) = \<Sqinter>{x, y, z}"
ballarin@27714
  1173
  using weak_meet_assoc_lemma L unfolding eq_is_equal .
ballarin@27713
  1174
ballarin@27713
  1175
lemma (in lower_semilattice) meet_assoc:
ballarin@27713
  1176
  assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
ballarin@27713
  1177
  shows "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
ballarin@27714
  1178
  using weak_meet_assoc L unfolding eq_is_equal .
ballarin@27713
  1179
ballarin@27713
  1180
ballarin@27717
  1181
text {* Total Orders *}
ballarin@27713
  1182
ballarin@27713
  1183
locale total_order = partial_order +
haftmann@28823
  1184
  assumes total_order_total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
ballarin@27713
  1185
ballarin@29242
  1186
sublocale total_order < weak: weak_total_order
haftmann@28823
  1187
  proof qed (rule total_order_total)
ballarin@27713
  1188
ballarin@27713
  1189
text {* Introduction rule: the usual definition of total order *}
ballarin@27713
  1190
ballarin@27713
  1191
lemma (in partial_order) total_orderI:
ballarin@27713
  1192
  assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
ballarin@27713
  1193
  shows "total_order L"
haftmann@28823
  1194
  proof qed (rule total)
ballarin@27713
  1195
ballarin@27713
  1196
text {* Total orders are lattices. *}
ballarin@27713
  1197
ballarin@29242
  1198
sublocale total_order < weak: lattice
haftmann@28823
  1199
  proof qed (auto intro: sup_of_two_exists inf_of_two_exists)
ballarin@27713
  1200
ballarin@27713
  1201
ballarin@27717
  1202
text {* Complete lattices *}
ballarin@27713
  1203
ballarin@27713
  1204
locale complete_lattice = lattice +
ballarin@27713
  1205
  assumes sup_exists:
ballarin@27713
  1206
    "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
ballarin@27713
  1207
    and inf_exists:
ballarin@27713
  1208
    "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
ballarin@27713
  1209
ballarin@29242
  1210
sublocale complete_lattice < weak: weak_complete_lattice
haftmann@28823
  1211
  proof qed (auto intro: sup_exists inf_exists)
ballarin@27713
  1212
ballarin@27713
  1213
text {* Introduction rule: the usual definition of complete lattice *}
ballarin@27713
  1214
ballarin@27713
  1215
lemma (in partial_order) complete_latticeI:
ballarin@27713
  1216
  assumes sup_exists:
ballarin@27713
  1217
    "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
ballarin@27713
  1218
    and inf_exists:
ballarin@27713
  1219
    "!!A. [| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
ballarin@27713
  1220
  shows "complete_lattice L"
haftmann@28823
  1221
  proof qed (auto intro: sup_exists inf_exists)
ballarin@27713
  1222
ballarin@14551
  1223
theorem (in partial_order) complete_lattice_criterion1:
ballarin@22063
  1224
  assumes top_exists: "EX g. greatest L g (carrier L)"
ballarin@14551
  1225
    and inf_exists:
ballarin@22063
  1226
      "!!A. [| A \<subseteq> carrier L; A ~= {} |] ==> EX i. greatest L i (Lower L A)"
ballarin@22063
  1227
  shows "complete_lattice L"
ballarin@14551
  1228
proof (rule complete_latticeI)
ballarin@22063
  1229
  from top_exists obtain top where top: "greatest L top (carrier L)" ..
ballarin@14551
  1230
  fix A
ballarin@22063
  1231
  assume L: "A \<subseteq> carrier L"
ballarin@22063
  1232
  let ?B = "Upper L A"
ballarin@14551
  1233
  from L top have "top \<in> ?B" by (fast intro!: Upper_memI intro: greatest_le)
ballarin@14551
  1234
  then have B_non_empty: "?B ~= {}" by fast
ballarin@22063
  1235
  have B_L: "?B \<subseteq> carrier L" by simp
ballarin@14551
  1236
  from inf_exists [OF B_L B_non_empty]
ballarin@22063
  1237
  obtain b where b_inf_B: "greatest L b (Lower L ?B)" ..
ballarin@22063
  1238
  have "least L b (Upper L A)"
ballarin@14551
  1239
apply (rule least_UpperI)
ballarin@22063
  1240
   apply (rule greatest_le [where A = "Lower L ?B"])
ballarin@14551
  1241
    apply (rule b_inf_B)
ballarin@14551
  1242
   apply (rule Lower_memI)
ballarin@27713
  1243
    apply (erule Upper_memD [THEN conjunct1])
ballarin@14551
  1244
     apply assumption
ballarin@14551
  1245
    apply (rule L)
ballarin@14551
  1246
   apply (fast intro: L [THEN subsetD])
ballarin@27700
  1247
  apply (erule greatest_Lower_below [OF b_inf_B])
ballarin@14551
  1248
  apply simp
ballarin@14551
  1249
 apply (rule L)
ballarin@27700
  1250
apply (rule greatest_closed [OF b_inf_B])
ballarin@14551
  1251
done
ballarin@22063
  1252
  then show "EX s. least L s (Upper L A)" ..
ballarin@14551
  1253
next
ballarin@14551
  1254
  fix A
ballarin@22063
  1255
  assume L: "A \<subseteq> carrier L"
ballarin@22063
  1256
  show "EX i. greatest L i (Lower L A)"
ballarin@14551
  1257
  proof (cases "A = {}")
ballarin@14551
  1258
    case True then show ?thesis
ballarin@14551
  1259
      by (simp add: top_exists)
ballarin@14551
  1260
  next
ballarin@14551
  1261
    case False with L show ?thesis
ballarin@14551
  1262
      by (rule inf_exists)
ballarin@14551
  1263
  qed
ballarin@14551
  1264
qed
ballarin@14551
  1265
ballarin@14551
  1266
(* TODO: prove dual version *)
ballarin@14551
  1267
ballarin@20318
  1268
ballarin@14551
  1269
subsection {* Examples *}
ballarin@14551
  1270
ballarin@27717
  1271
subsubsection {* The Powerset of a Set is a Complete Lattice *}
ballarin@14551
  1272
ballarin@14551
  1273
theorem powerset_is_complete_lattice:
ballarin@27713
  1274
  "complete_lattice (| carrier = Pow A, eq = op =, le = op \<subseteq> |)"
ballarin@22063
  1275
  (is "complete_lattice ?L")
ballarin@14551
  1276
proof (rule partial_order.complete_latticeI)
ballarin@22063
  1277
  show "partial_order ?L"
haftmann@28823
  1278
    proof qed auto
ballarin@14551
  1279
next
ballarin@14551
  1280
  fix B
berghofe@26805
  1281
  assume B: "B \<subseteq> carrier ?L"
berghofe@26805
  1282
  show "EX s. least ?L s (Upper ?L B)"
berghofe@26805
  1283
  proof
berghofe@26805
  1284
    from B show "least ?L (\<Union> B) (Upper ?L B)"
berghofe@26805
  1285
      by (fastsimp intro!: least_UpperI simp: Upper_def)
berghofe@26805
  1286
  qed
ballarin@14551
  1287
next
ballarin@14551
  1288
  fix B
berghofe@26805
  1289
  assume B: "B \<subseteq> carrier ?L"
berghofe@26805
  1290
  show "EX i. greatest ?L i (Lower ?L B)"
berghofe@26805
  1291
  proof
berghofe@26805
  1292
    from B show "greatest ?L (\<Inter> B \<inter> A) (Lower ?L B)"
berghofe@26805
  1293
      txt {* @{term "\<Inter> B"} is not the infimum of @{term B}:
wenzelm@32960
  1294
        @{term "\<Inter> {} = UNIV"} which is in general bigger than @{term "A"}! *}
berghofe@26805
  1295
      by (fastsimp intro!: greatest_LowerI simp: Lower_def)
berghofe@26805
  1296
  qed
ballarin@14551
  1297
qed
ballarin@14551
  1298
ballarin@14751
  1299
text {* An other example, that of the lattice of subgroups of a group,
ballarin@14751
  1300
  can be found in Group theory (Section~\ref{sec:subgroup-lattice}). *}
ballarin@14551
  1301
wenzelm@14693
  1302
end