src/HOL/Algebra/Lattice.thy
changeset 61382 efac889fccbc
parent 61169 4de9ff3ea29a
child 61565 352c73a689da
equal deleted inserted replaced
61381:ddca85598c65 61382:efac889fccbc
     7 
     7 
     8 theory Lattice
     8 theory Lattice
     9 imports Congruence
     9 imports Congruence
    10 begin
    10 begin
    11 
    11 
    12 section {* Orders and Lattices *}
    12 section \<open>Orders and Lattices\<close>
    13 
    13 
    14 subsection {* Partial Orders *}
    14 subsection \<open>Partial Orders\<close>
    15 
    15 
    16 record 'a gorder = "'a eq_object" +
    16 record 'a gorder = "'a eq_object" +
    17   le :: "['a, 'a] => bool" (infixl "\<sqsubseteq>\<index>" 50)
    17   le :: "['a, 'a] => bool" (infixl "\<sqsubseteq>\<index>" 50)
    18 
    18 
    19 locale weak_partial_order = equivalence L for L (structure) +
    19 locale weak_partial_order = equivalence L for L (structure) +
    30 definition
    30 definition
    31   lless :: "[_, 'a, 'a] => bool" (infixl "\<sqsubset>\<index>" 50)
    31   lless :: "[_, 'a, 'a] => bool" (infixl "\<sqsubset>\<index>" 50)
    32   where "x \<sqsubset>\<^bsub>L\<^esub> y \<longleftrightarrow> x \<sqsubseteq>\<^bsub>L\<^esub> y & x .\<noteq>\<^bsub>L\<^esub> y"
    32   where "x \<sqsubset>\<^bsub>L\<^esub> y \<longleftrightarrow> x \<sqsubseteq>\<^bsub>L\<^esub> y & x .\<noteq>\<^bsub>L\<^esub> y"
    33 
    33 
    34 
    34 
    35 subsubsection {* The order relation *}
    35 subsubsection \<open>The order relation\<close>
    36 
    36 
    37 context weak_partial_order
    37 context weak_partial_order
    38 begin
    38 begin
    39 
    39 
    40 lemma le_cong_l [intro, trans]:
    40 lemma le_cong_l [intro, trans]:
   101     and carr[simp]: "a \<in> carrier L" "b \<in> carrier L" "c \<in> carrier L"
   101     and carr[simp]: "a \<in> carrier L" "b \<in> carrier L" "c \<in> carrier L"
   102   shows "a \<sqsubset> c"
   102   shows "a \<sqsubset> c"
   103   using assms unfolding lless_def by (blast dest: le_trans intro: sym)
   103   using assms unfolding lless_def by (blast dest: le_trans intro: sym)
   104 
   104 
   105 
   105 
   106 subsubsection {* Upper and lower bounds of a set *}
   106 subsubsection \<open>Upper and lower bounds of a set\<close>
   107 
   107 
   108 definition
   108 definition
   109   Upper :: "[_, 'a set] => 'a set"
   109   Upper :: "[_, 'a set] => 'a set"
   110   where "Upper L A = {u. (ALL x. x \<in> A \<inter> carrier L --> x \<sqsubseteq>\<^bsub>L\<^esub> u)} \<inter> carrier L"
   110   where "Upper L A = {u. (ALL x. x \<in> A \<inter> carrier L --> x \<sqsubseteq>\<^bsub>L\<^esub> u)} \<inter> carrier L"
   111 
   111 
   274   also note aa'[symmetric]
   274   also note aa'[symmetric]
   275   finally show "x \<sqsubseteq> a" by (simp add: carr subsetD[OF A'carr a'A'])
   275   finally show "x \<sqsubseteq> a" by (simp add: carr subsetD[OF A'carr a'A'])
   276 qed
   276 qed
   277 
   277 
   278 
   278 
   279 subsubsection {* Least and greatest, as predicate *}
   279 subsubsection \<open>Least and greatest, as predicate\<close>
   280 
   280 
   281 definition
   281 definition
   282   least :: "[_, 'a, 'a set] => bool"
   282   least :: "[_, 'a, 'a set] => bool"
   283   where "least L l A \<longleftrightarrow> A \<subseteq> carrier L & l \<in> A & (ALL x : A. l \<sqsubseteq>\<^bsub>L\<^esub> x)"
   283   where "least L l A \<longleftrightarrow> A \<subseteq> carrier L & l \<in> A & (ALL x : A. l \<sqsubseteq>\<^bsub>L\<^esub> x)"
   284 
   284 
   285 definition
   285 definition
   286   greatest :: "[_, 'a, 'a set] => bool"
   286   greatest :: "[_, 'a, 'a set] => bool"
   287   where "greatest L g A \<longleftrightarrow> A \<subseteq> carrier L & g \<in> A & (ALL x : A. x \<sqsubseteq>\<^bsub>L\<^esub> g)"
   287   where "greatest L g A \<longleftrightarrow> A \<subseteq> carrier L & g \<in> A & (ALL x : A. x \<sqsubseteq>\<^bsub>L\<^esub> g)"
   288 
   288 
   289 text (in weak_partial_order) {* Could weaken these to @{term "l \<in> carrier L \<and> l
   289 text (in weak_partial_order) \<open>Could weaken these to @{term "l \<in> carrier L \<and> l
   290   .\<in> A"} and @{term "g \<in> carrier L \<and> g .\<in> A"}. *}
   290   .\<in> A"} and @{term "g \<in> carrier L \<and> g .\<in> A"}.\<close>
   291 
   291 
   292 lemma least_closed [intro, simp]:
   292 lemma least_closed [intro, simp]:
   293   "least L l A ==> l \<in> carrier L"
   293   "least L l A ==> l \<in> carrier L"
   294   by (unfold least_def) fast
   294   by (unfold least_def) fast
   295 
   295 
   308 
   308 
   309 lemma (in weak_partial_order) least_cong:
   309 lemma (in weak_partial_order) least_cong:
   310   "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==> least L x A = least L x' A"
   310   "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==> least L x A = least L x' A"
   311   by (unfold least_def) (auto dest: sym)
   311   by (unfold least_def) (auto dest: sym)
   312 
   312 
   313 text (in weak_partial_order) {* @{const least} is not congruent in the second parameter for 
   313 text (in weak_partial_order) \<open>@{const least} is not congruent in the second parameter for 
   314   @{term "A {.=} A'"} *}
   314   @{term "A {.=} A'"}\<close>
   315 
   315 
   316 lemma (in weak_partial_order) least_Upper_cong_l:
   316 lemma (in weak_partial_order) least_Upper_cong_l:
   317   assumes "x .= x'"
   317   assumes "x .= x'"
   318     and "x \<in> carrier L" "x' \<in> carrier L"
   318     and "x \<in> carrier L" "x' \<in> carrier L"
   319     and "A \<subseteq> carrier L"
   319     and "A \<subseteq> carrier L"
   365 lemma (in weak_partial_order) greatest_cong:
   365 lemma (in weak_partial_order) greatest_cong:
   366   "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==>
   366   "[| x .= x'; x \<in> carrier L; x' \<in> carrier L; is_closed A |] ==>
   367   greatest L x A = greatest L x' A"
   367   greatest L x A = greatest L x' A"
   368   by (unfold greatest_def) (auto dest: sym)
   368   by (unfold greatest_def) (auto dest: sym)
   369 
   369 
   370 text (in weak_partial_order) {* @{const greatest} is not congruent in the second parameter for 
   370 text (in weak_partial_order) \<open>@{const greatest} is not congruent in the second parameter for 
   371   @{term "A {.=} A'"} *}
   371   @{term "A {.=} A'"}\<close>
   372 
   372 
   373 lemma (in weak_partial_order) greatest_Lower_cong_l:
   373 lemma (in weak_partial_order) greatest_Lower_cong_l:
   374   assumes "x .= x'"
   374   assumes "x .= x'"
   375     and "x \<in> carrier L" "x' \<in> carrier L"
   375     and "x \<in> carrier L" "x' \<in> carrier L"
   376     and "A \<subseteq> carrier L" (* unneccessary with current Lower *)
   376     and "A \<subseteq> carrier L" (* unneccessary with current Lower *)
   400 lemma greatest_Lower_below:
   400 lemma greatest_Lower_below:
   401   fixes L (structure)
   401   fixes L (structure)
   402   shows "[| greatest L i (Lower L A); x \<in> A; A \<subseteq> carrier L |] ==> i \<sqsubseteq> x"
   402   shows "[| greatest L i (Lower L A); x \<in> A; A \<subseteq> carrier L |] ==> i \<sqsubseteq> x"
   403   by (unfold greatest_def) blast
   403   by (unfold greatest_def) blast
   404 
   404 
   405 text {* Supremum and infimum *}
   405 text \<open>Supremum and infimum\<close>
   406 
   406 
   407 definition
   407 definition
   408   sup :: "[_, 'a set] => 'a" ("\<Squnion>\<index>_" [90] 90)
   408   sup :: "[_, 'a set] => 'a" ("\<Squnion>\<index>_" [90] 90)
   409   where "\<Squnion>\<^bsub>L\<^esub>A = (SOME x. least L x (Upper L A))"
   409   where "\<Squnion>\<^bsub>L\<^esub>A = (SOME x. least L x (Upper L A))"
   410 
   410 
   419 definition
   419 definition
   420   meet :: "[_, 'a, 'a] => 'a" (infixl "\<sqinter>\<index>" 70)
   420   meet :: "[_, 'a, 'a] => 'a" (infixl "\<sqinter>\<index>" 70)
   421   where "x \<sqinter>\<^bsub>L\<^esub> y = \<Sqinter>\<^bsub>L\<^esub>{x, y}"
   421   where "x \<sqinter>\<^bsub>L\<^esub> y = \<Sqinter>\<^bsub>L\<^esub>{x, y}"
   422 
   422 
   423 
   423 
   424 subsection {* Lattices *}
   424 subsection \<open>Lattices\<close>
   425 
   425 
   426 locale weak_upper_semilattice = weak_partial_order +
   426 locale weak_upper_semilattice = weak_partial_order +
   427   assumes sup_of_two_exists:
   427   assumes sup_of_two_exists:
   428     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
   428     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
   429 
   429 
   432     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. greatest L s (Lower L {x, y})"
   432     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. greatest L s (Lower L {x, y})"
   433 
   433 
   434 locale weak_lattice = weak_upper_semilattice + weak_lower_semilattice
   434 locale weak_lattice = weak_upper_semilattice + weak_lower_semilattice
   435 
   435 
   436 
   436 
   437 subsubsection {* Supremum *}
   437 subsubsection \<open>Supremum\<close>
   438 
   438 
   439 lemma (in weak_upper_semilattice) joinI:
   439 lemma (in weak_upper_semilattice) joinI:
   440   "[| !!l. least L l (Upper L {x, y}) ==> P l; x \<in> carrier L; y \<in> carrier L |]
   440   "[| !!l. least L l (Upper L {x, y}) ==> P l; x \<in> carrier L; y \<in> carrier L |]
   441   ==> P (x \<squnion> y)"
   441   ==> P (x \<squnion> y)"
   442 proof (unfold join_def sup_def)
   442 proof (unfold join_def sup_def)
   505 lemma (in weak_partial_order) sup_of_singleton_closed [simp]:
   505 lemma (in weak_partial_order) sup_of_singleton_closed [simp]:
   506   "x \<in> carrier L \<Longrightarrow> \<Squnion>{x} \<in> carrier L"
   506   "x \<in> carrier L \<Longrightarrow> \<Squnion>{x} \<in> carrier L"
   507   unfolding sup_def
   507   unfolding sup_def
   508   by (rule someI2) (auto intro: sup_of_singletonI)
   508   by (rule someI2) (auto intro: sup_of_singletonI)
   509 
   509 
   510 text {* Condition on @{text A}: supremum exists. *}
   510 text \<open>Condition on @{text A}: supremum exists.\<close>
   511 
   511 
   512 lemma (in weak_upper_semilattice) sup_insertI:
   512 lemma (in weak_upper_semilattice) sup_insertI:
   513   "[| !!s. least L s (Upper L (insert x A)) ==> P s;
   513   "[| !!s. least L s (Upper L (insert x A)) ==> P s;
   514   least L a (Upper L A); x \<in> carrier L; A \<subseteq> carrier L |]
   514   least L a (Upper L A); x \<in> carrier L; A \<subseteq> carrier L |]
   515   ==> P (\<Squnion>(insert x A))"
   515   ==> P (\<Squnion>(insert x A))"
   636 
   636 
   637 lemma (in weak_upper_semilattice) weak_join_assoc_lemma:
   637 lemma (in weak_upper_semilattice) weak_join_assoc_lemma:
   638   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
   638   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
   639   shows "x \<squnion> (y \<squnion> z) .= \<Squnion>{x, y, z}"
   639   shows "x \<squnion> (y \<squnion> z) .= \<Squnion>{x, y, z}"
   640 proof (rule finite_sup_insertI)
   640 proof (rule finite_sup_insertI)
   641   -- {* The textbook argument in Jacobson I, p 457 *}
   641   -- \<open>The textbook argument in Jacobson I, p 457\<close>
   642   fix s
   642   fix s
   643   assume sup: "least L s (Upper L {x, y, z})"
   643   assume sup: "least L s (Upper L {x, y, z})"
   644   show "x \<squnion> (y \<squnion> z) .= s"
   644   show "x \<squnion> (y \<squnion> z) .= s"
   645   proof (rule weak_le_antisym)
   645   proof (rule weak_le_antisym)
   646     from sup L show "x \<squnion> (y \<squnion> z) \<sqsubseteq> s"
   646     from sup L show "x \<squnion> (y \<squnion> z) \<sqsubseteq> s"
   650     by (erule_tac least_le)
   650     by (erule_tac least_le)
   651       (blast intro!: Upper_memI intro: le_trans join_left join_right join_closed)
   651       (blast intro!: Upper_memI intro: le_trans join_left join_right join_closed)
   652   qed (simp_all add: L least_closed [OF sup])
   652   qed (simp_all add: L least_closed [OF sup])
   653 qed (simp_all add: L)
   653 qed (simp_all add: L)
   654 
   654 
   655 text {* Commutativity holds for @{text "="}. *}
   655 text \<open>Commutativity holds for @{text "="}.\<close>
   656 
   656 
   657 lemma join_comm:
   657 lemma join_comm:
   658   fixes L (structure)
   658   fixes L (structure)
   659   shows "x \<squnion> y = y \<squnion> x"
   659   shows "x \<squnion> y = y \<squnion> x"
   660   by (unfold join_def) (simp add: insert_commute)
   660   by (unfold join_def) (simp add: insert_commute)
   671   also from L have "... .= x \<squnion> (y \<squnion> z)" by (simp add: weak_join_assoc_lemma [symmetric])
   671   also from L have "... .= x \<squnion> (y \<squnion> z)" by (simp add: weak_join_assoc_lemma [symmetric])
   672   finally show ?thesis by (simp add: L)
   672   finally show ?thesis by (simp add: L)
   673 qed
   673 qed
   674 
   674 
   675 
   675 
   676 subsubsection {* Infimum *}
   676 subsubsection \<open>Infimum\<close>
   677 
   677 
   678 lemma (in weak_lower_semilattice) meetI:
   678 lemma (in weak_lower_semilattice) meetI:
   679   "[| !!i. greatest L i (Lower L {x, y}) ==> P i;
   679   "[| !!i. greatest L i (Lower L {x, y}) ==> P i;
   680   x \<in> carrier L; y \<in> carrier L |]
   680   x \<in> carrier L; y \<in> carrier L |]
   681   ==> P (x \<sqinter> y)"
   681   ==> P (x \<sqinter> y)"
   745 lemma (in weak_partial_order) inf_of_singleton_closed:
   745 lemma (in weak_partial_order) inf_of_singleton_closed:
   746   "x \<in> carrier L ==> \<Sqinter>{x} \<in> carrier L"
   746   "x \<in> carrier L ==> \<Sqinter>{x} \<in> carrier L"
   747   unfolding inf_def
   747   unfolding inf_def
   748   by (rule someI2) (auto intro: inf_of_singletonI)
   748   by (rule someI2) (auto intro: inf_of_singletonI)
   749 
   749 
   750 text {* Condition on @{text A}: infimum exists. *}
   750 text \<open>Condition on @{text A}: infimum exists.\<close>
   751 
   751 
   752 lemma (in weak_lower_semilattice) inf_insertI:
   752 lemma (in weak_lower_semilattice) inf_insertI:
   753   "[| !!i. greatest L i (Lower L (insert x A)) ==> P i;
   753   "[| !!i. greatest L i (Lower L (insert x A)) ==> P i;
   754   greatest L a (Lower L A); x \<in> carrier L; A \<subseteq> carrier L |]
   754   greatest L a (Lower L A); x \<in> carrier L; A \<subseteq> carrier L |]
   755   ==> P (\<Sqinter>(insert x A))"
   755   ==> P (\<Sqinter>(insert x A))"
   877 
   877 
   878 lemma (in weak_lower_semilattice) weak_meet_assoc_lemma:
   878 lemma (in weak_lower_semilattice) weak_meet_assoc_lemma:
   879   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
   879   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
   880   shows "x \<sqinter> (y \<sqinter> z) .= \<Sqinter>{x, y, z}"
   880   shows "x \<sqinter> (y \<sqinter> z) .= \<Sqinter>{x, y, z}"
   881 proof (rule finite_inf_insertI)
   881 proof (rule finite_inf_insertI)
   882   txt {* The textbook argument in Jacobson I, p 457 *}
   882   txt \<open>The textbook argument in Jacobson I, p 457\<close>
   883   fix i
   883   fix i
   884   assume inf: "greatest L i (Lower L {x, y, z})"
   884   assume inf: "greatest L i (Lower L {x, y, z})"
   885   show "x \<sqinter> (y \<sqinter> z) .= i"
   885   show "x \<sqinter> (y \<sqinter> z) .= i"
   886   proof (rule weak_le_antisym)
   886   proof (rule weak_le_antisym)
   887     from inf L show "i \<sqsubseteq> x \<sqinter> (y \<sqinter> z)"
   887     from inf L show "i \<sqsubseteq> x \<sqinter> (y \<sqinter> z)"
   909   also from L have "... .= x \<sqinter> (y \<sqinter> z)" by (simp add: weak_meet_assoc_lemma [symmetric])
   909   also from L have "... .= x \<sqinter> (y \<sqinter> z)" by (simp add: weak_meet_assoc_lemma [symmetric])
   910   finally show ?thesis by (simp add: L)
   910   finally show ?thesis by (simp add: L)
   911 qed
   911 qed
   912 
   912 
   913 
   913 
   914 subsection {* Total Orders *}
   914 subsection \<open>Total Orders\<close>
   915 
   915 
   916 locale weak_total_order = weak_partial_order +
   916 locale weak_total_order = weak_partial_order +
   917   assumes total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
   917   assumes total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
   918 
   918 
   919 text {* Introduction rule: the usual definition of total order *}
   919 text \<open>Introduction rule: the usual definition of total order\<close>
   920 
   920 
   921 lemma (in weak_partial_order) weak_total_orderI:
   921 lemma (in weak_partial_order) weak_total_orderI:
   922   assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
   922   assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
   923   shows "weak_total_order L"
   923   shows "weak_total_order L"
   924   by standard (rule total)
   924   by standard (rule total)
   925 
   925 
   926 text {* Total orders are lattices. *}
   926 text \<open>Total orders are lattices.\<close>
   927 
   927 
   928 sublocale weak_total_order < weak: weak_lattice
   928 sublocale weak_total_order < weak: weak_lattice
   929 proof
   929 proof
   930   fix x y
   930   fix x y
   931   assume L: "x \<in> carrier L"  "y \<in> carrier L"
   931   assume L: "x \<in> carrier L"  "y \<in> carrier L"
   967     ultimately show ?thesis by blast
   967     ultimately show ?thesis by blast
   968   qed
   968   qed
   969 qed
   969 qed
   970 
   970 
   971 
   971 
   972 subsection {* Complete Lattices *}
   972 subsection \<open>Complete Lattices\<close>
   973 
   973 
   974 locale weak_complete_lattice = weak_lattice +
   974 locale weak_complete_lattice = weak_lattice +
   975   assumes sup_exists:
   975   assumes sup_exists:
   976     "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
   976     "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
   977     and inf_exists:
   977     and inf_exists:
   978     "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
   978     "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
   979 
   979 
   980 text {* Introduction rule: the usual definition of complete lattice *}
   980 text \<open>Introduction rule: the usual definition of complete lattice\<close>
   981 
   981 
   982 lemma (in weak_partial_order) weak_complete_latticeI:
   982 lemma (in weak_partial_order) weak_complete_latticeI:
   983   assumes sup_exists:
   983   assumes sup_exists:
   984     "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
   984     "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
   985     and inf_exists:
   985     and inf_exists:
  1032 
  1032 
  1033 lemma (in weak_complete_lattice) bottom_closed [simp, intro]:
  1033 lemma (in weak_complete_lattice) bottom_closed [simp, intro]:
  1034   "\<bottom> \<in> carrier L"
  1034   "\<bottom> \<in> carrier L"
  1035   by (unfold bottom_def) simp
  1035   by (unfold bottom_def) simp
  1036 
  1036 
  1037 text {* Jacobson: Theorem 8.1 *}
  1037 text \<open>Jacobson: Theorem 8.1\<close>
  1038 
  1038 
  1039 lemma Lower_empty [simp]:
  1039 lemma Lower_empty [simp]:
  1040   "Lower L {} = carrier L"
  1040   "Lower L {} = carrier L"
  1041   by (unfold Lower_def) simp
  1041   by (unfold Lower_def) simp
  1042 
  1042 
  1088 qed
  1088 qed
  1089 
  1089 
  1090 (* TODO: prove dual version *)
  1090 (* TODO: prove dual version *)
  1091 
  1091 
  1092 
  1092 
  1093 subsection {* Orders and Lattices where @{text eq} is the Equality *}
  1093 subsection \<open>Orders and Lattices where @{text eq} is the Equality\<close>
  1094 
  1094 
  1095 locale partial_order = weak_partial_order +
  1095 locale partial_order = weak_partial_order +
  1096   assumes eq_is_equal: "op .= = op ="
  1096   assumes eq_is_equal: "op .= = op ="
  1097 begin
  1097 begin
  1098 
  1098 
  1113   using assms unfolding lless_eq by auto
  1113   using assms unfolding lless_eq by auto
  1114 
  1114 
  1115 end
  1115 end
  1116 
  1116 
  1117 
  1117 
  1118 text {* Least and greatest, as predicate *}
  1118 text \<open>Least and greatest, as predicate\<close>
  1119 
  1119 
  1120 lemma (in partial_order) least_unique:
  1120 lemma (in partial_order) least_unique:
  1121   "[| least L x A; least L y A |] ==> x = y"
  1121   "[| least L x A; least L y A |] ==> x = y"
  1122   using weak_least_unique unfolding eq_is_equal .
  1122   using weak_least_unique unfolding eq_is_equal .
  1123 
  1123 
  1124 lemma (in partial_order) greatest_unique:
  1124 lemma (in partial_order) greatest_unique:
  1125   "[| greatest L x A; greatest L y A |] ==> x = y"
  1125   "[| greatest L x A; greatest L y A |] ==> x = y"
  1126   using weak_greatest_unique unfolding eq_is_equal .
  1126   using weak_greatest_unique unfolding eq_is_equal .
  1127 
  1127 
  1128 
  1128 
  1129 text {* Lattices *}
  1129 text \<open>Lattices\<close>
  1130 
  1130 
  1131 locale upper_semilattice = partial_order +
  1131 locale upper_semilattice = partial_order +
  1132   assumes sup_of_two_exists:
  1132   assumes sup_of_two_exists:
  1133     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
  1133     "[| x \<in> carrier L; y \<in> carrier L |] ==> EX s. least L s (Upper L {x, y})"
  1134 
  1134 
  1143   by standard (rule inf_of_two_exists)
  1143   by standard (rule inf_of_two_exists)
  1144 
  1144 
  1145 locale lattice = upper_semilattice + lower_semilattice
  1145 locale lattice = upper_semilattice + lower_semilattice
  1146 
  1146 
  1147 
  1147 
  1148 text {* Supremum *}
  1148 text \<open>Supremum\<close>
  1149 
  1149 
  1150 declare (in partial_order) weak_sup_of_singleton [simp del]
  1150 declare (in partial_order) weak_sup_of_singleton [simp del]
  1151 
  1151 
  1152 lemma (in partial_order) sup_of_singleton [simp]:
  1152 lemma (in partial_order) sup_of_singleton [simp]:
  1153   "x \<in> carrier L ==> \<Squnion>{x} = x"
  1153   "x \<in> carrier L ==> \<Squnion>{x} = x"
  1162   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1162   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1163   shows "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
  1163   shows "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)"
  1164   using weak_join_assoc L unfolding eq_is_equal .
  1164   using weak_join_assoc L unfolding eq_is_equal .
  1165 
  1165 
  1166 
  1166 
  1167 text {* Infimum *}
  1167 text \<open>Infimum\<close>
  1168 
  1168 
  1169 declare (in partial_order) weak_inf_of_singleton [simp del]
  1169 declare (in partial_order) weak_inf_of_singleton [simp del]
  1170 
  1170 
  1171 lemma (in partial_order) inf_of_singleton [simp]:
  1171 lemma (in partial_order) inf_of_singleton [simp]:
  1172   "x \<in> carrier L ==> \<Sqinter>{x} = x"
  1172   "x \<in> carrier L ==> \<Sqinter>{x} = x"
  1173   using weak_inf_of_singleton unfolding eq_is_equal .
  1173   using weak_inf_of_singleton unfolding eq_is_equal .
  1174 
  1174 
  1175 text {* Condition on @{text A}: infimum exists. *}
  1175 text \<open>Condition on @{text A}: infimum exists.\<close>
  1176 
  1176 
  1177 lemma (in lower_semilattice) meet_assoc_lemma:
  1177 lemma (in lower_semilattice) meet_assoc_lemma:
  1178   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1178   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1179   shows "x \<sqinter> (y \<sqinter> z) = \<Sqinter>{x, y, z}"
  1179   shows "x \<sqinter> (y \<sqinter> z) = \<Sqinter>{x, y, z}"
  1180   using weak_meet_assoc_lemma L unfolding eq_is_equal .
  1180   using weak_meet_assoc_lemma L unfolding eq_is_equal .
  1183   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1183   assumes L: "x \<in> carrier L"  "y \<in> carrier L"  "z \<in> carrier L"
  1184   shows "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
  1184   shows "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)"
  1185   using weak_meet_assoc L unfolding eq_is_equal .
  1185   using weak_meet_assoc L unfolding eq_is_equal .
  1186 
  1186 
  1187 
  1187 
  1188 text {* Total Orders *}
  1188 text \<open>Total Orders\<close>
  1189 
  1189 
  1190 locale total_order = partial_order +
  1190 locale total_order = partial_order +
  1191   assumes total_order_total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
  1191   assumes total_order_total: "[| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
  1192 
  1192 
  1193 sublocale total_order < weak: weak_total_order
  1193 sublocale total_order < weak: weak_total_order
  1194   by standard (rule total_order_total)
  1194   by standard (rule total_order_total)
  1195 
  1195 
  1196 text {* Introduction rule: the usual definition of total order *}
  1196 text \<open>Introduction rule: the usual definition of total order\<close>
  1197 
  1197 
  1198 lemma (in partial_order) total_orderI:
  1198 lemma (in partial_order) total_orderI:
  1199   assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
  1199   assumes total: "!!x y. [| x \<in> carrier L; y \<in> carrier L |] ==> x \<sqsubseteq> y | y \<sqsubseteq> x"
  1200   shows "total_order L"
  1200   shows "total_order L"
  1201   by standard (rule total)
  1201   by standard (rule total)
  1202 
  1202 
  1203 text {* Total orders are lattices. *}
  1203 text \<open>Total orders are lattices.\<close>
  1204 
  1204 
  1205 sublocale total_order < weak: lattice
  1205 sublocale total_order < weak: lattice
  1206   by standard (auto intro: sup_of_two_exists inf_of_two_exists)
  1206   by standard (auto intro: sup_of_two_exists inf_of_two_exists)
  1207 
  1207 
  1208 
  1208 
  1209 text {* Complete lattices *}
  1209 text \<open>Complete lattices\<close>
  1210 
  1210 
  1211 locale complete_lattice = lattice +
  1211 locale complete_lattice = lattice +
  1212   assumes sup_exists:
  1212   assumes sup_exists:
  1213     "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
  1213     "[| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
  1214     and inf_exists:
  1214     and inf_exists:
  1215     "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
  1215     "[| A \<subseteq> carrier L |] ==> EX i. greatest L i (Lower L A)"
  1216 
  1216 
  1217 sublocale complete_lattice < weak: weak_complete_lattice
  1217 sublocale complete_lattice < weak: weak_complete_lattice
  1218   by standard (auto intro: sup_exists inf_exists)
  1218   by standard (auto intro: sup_exists inf_exists)
  1219 
  1219 
  1220 text {* Introduction rule: the usual definition of complete lattice *}
  1220 text \<open>Introduction rule: the usual definition of complete lattice\<close>
  1221 
  1221 
  1222 lemma (in partial_order) complete_latticeI:
  1222 lemma (in partial_order) complete_latticeI:
  1223   assumes sup_exists:
  1223   assumes sup_exists:
  1224     "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
  1224     "!!A. [| A \<subseteq> carrier L |] ==> EX s. least L s (Upper L A)"
  1225     and inf_exists:
  1225     and inf_exists:
  1271 qed
  1271 qed
  1272 
  1272 
  1273 (* TODO: prove dual version *)
  1273 (* TODO: prove dual version *)
  1274 
  1274 
  1275 
  1275 
  1276 subsection {* Examples *}
  1276 subsection \<open>Examples\<close>
  1277 
  1277 
  1278 subsubsection {* The Powerset of a Set is a Complete Lattice *}
  1278 subsubsection \<open>The Powerset of a Set is a Complete Lattice\<close>
  1279 
  1279 
  1280 theorem powerset_is_complete_lattice:
  1280 theorem powerset_is_complete_lattice:
  1281   "complete_lattice \<lparr>carrier = Pow A, eq = op =, le = op \<subseteq>\<rparr>"
  1281   "complete_lattice \<lparr>carrier = Pow A, eq = op =, le = op \<subseteq>\<rparr>"
  1282   (is "complete_lattice ?L")
  1282   (is "complete_lattice ?L")
  1283 proof (rule partial_order.complete_latticeI)
  1283 proof (rule partial_order.complete_latticeI)
  1291   then show "EX s. least ?L s (Upper ?L B)" ..
  1291   then show "EX s. least ?L s (Upper ?L B)" ..
  1292 next
  1292 next
  1293   fix B
  1293   fix B
  1294   assume "B \<subseteq> carrier ?L"
  1294   assume "B \<subseteq> carrier ?L"
  1295   then have "greatest ?L (\<Inter>B \<inter> A) (Lower ?L B)"
  1295   then have "greatest ?L (\<Inter>B \<inter> A) (Lower ?L B)"
  1296     txt {* @{term "\<Inter>B"} is not the infimum of @{term B}:
  1296     txt \<open>@{term "\<Inter>B"} is not the infimum of @{term B}:
  1297       @{term "\<Inter>{} = UNIV"} which is in general bigger than @{term "A"}! *}
  1297       @{term "\<Inter>{} = UNIV"} which is in general bigger than @{term "A"}!\<close>
  1298     by (fastforce intro!: greatest_LowerI simp: Lower_def)
  1298     by (fastforce intro!: greatest_LowerI simp: Lower_def)
  1299   then show "EX i. greatest ?L i (Lower ?L B)" ..
  1299   then show "EX i. greatest ?L i (Lower ?L B)" ..
  1300 qed
  1300 qed
  1301 
  1301 
  1302 text {* An other example, that of the lattice of subgroups of a group,
  1302 text \<open>An other example, that of the lattice of subgroups of a group,
  1303   can be found in Group theory (Section~\ref{sec:subgroup-lattice}). *}
  1303   can be found in Group theory (Section~\ref{sec:subgroup-lattice}).\<close>
  1304 
  1304 
  1305 end
  1305 end