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