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