src/HOL/Lattices.thy
changeset 60758 d8d85a8172b5
parent 59545 12a6088ed195
child 61076 bdc1e2f0a86a
equal deleted inserted replaced
60757:c09598a97436 60758:d8d85a8172b5
     1 (*  Title:      HOL/Lattices.thy
     1 (*  Title:      HOL/Lattices.thy
     2     Author:     Tobias Nipkow
     2     Author:     Tobias Nipkow
     3 *)
     3 *)
     4 
     4 
     5 section {* Abstract lattices *}
     5 section \<open>Abstract lattices\<close>
     6 
     6 
     7 theory Lattices
     7 theory Lattices
     8 imports Groups
     8 imports Groups
     9 begin
     9 begin
    10 
    10 
    11 subsection {* Abstract semilattice *}
    11 subsection \<open>Abstract semilattice\<close>
    12 
    12 
    13 text {*
    13 text \<open>
    14   These locales provide a basic structure for interpretation into
    14   These locales provide a basic structure for interpretation into
    15   bigger structures;  extensions require careful thinking, otherwise
    15   bigger structures;  extensions require careful thinking, otherwise
    16   undesired effects may occur due to interpretation.
    16   undesired effects may occur due to interpretation.
    17 *}
    17 \<close>
    18 
    18 
    19 no_notation times (infixl "*" 70)
    19 no_notation times (infixl "*" 70)
    20 no_notation Groups.one ("1")
    20 no_notation Groups.one ("1")
    21 
    21 
    22 locale semilattice = abel_semigroup +
    22 locale semilattice = abel_semigroup +
    71     by (simp_all add: order_iff commute)
    71     by (simp_all add: order_iff commute)
    72   then have "a = a * (b * c)"
    72   then have "a = a * (b * c)"
    73     by simp
    73     by simp
    74   then have "a = (a * b) * c"
    74   then have "a = (a * b) * c"
    75     by (simp add: assoc)
    75     by (simp add: assoc)
    76   with `a = a * b` [symmetric] have "a = a * c" by simp
    76   with \<open>a = a * b\<close> [symmetric] have "a = a * c" by simp
    77   then show "a \<preceq> c" by (rule orderI)
    77   then show "a \<preceq> c" by (rule orderI)
    78 qed
    78 qed
    79 
    79 
    80 lemma cobounded1 [simp]:
    80 lemma cobounded1 [simp]:
    81   "a * b \<preceq> a"
    81   "a * b \<preceq> a"
   151 
   151 
   152 notation times (infixl "*" 70)
   152 notation times (infixl "*" 70)
   153 notation Groups.one ("1")
   153 notation Groups.one ("1")
   154 
   154 
   155 
   155 
   156 subsection {* Syntactic infimum and supremum operations *}
   156 subsection \<open>Syntactic infimum and supremum operations\<close>
   157 
   157 
   158 class inf =
   158 class inf =
   159   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
   159   fixes inf :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 70)
   160 
   160 
   161 class sup = 
   161 class sup = 
   162   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
   162   fixes sup :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<squnion>" 65)
   163 
   163 
   164 
   164 
   165 subsection {* Concrete lattices *}
   165 subsection \<open>Concrete lattices\<close>
   166 
   166 
   167 notation
   167 notation
   168   less_eq  (infix "\<sqsubseteq>" 50) and
   168   less_eq  (infix "\<sqsubseteq>" 50) and
   169   less  (infix "\<sqsubset>" 50)
   169   less  (infix "\<sqsubset>" 50)
   170 
   170 
   177   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
   177   assumes sup_ge1 [simp]: "x \<sqsubseteq> x \<squnion> y"
   178   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
   178   and sup_ge2 [simp]: "y \<sqsubseteq> x \<squnion> y"
   179   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
   179   and sup_least: "y \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> y \<squnion> z \<sqsubseteq> x"
   180 begin
   180 begin
   181 
   181 
   182 text {* Dual lattice *}
   182 text \<open>Dual lattice\<close>
   183 
   183 
   184 lemma dual_semilattice:
   184 lemma dual_semilattice:
   185   "class.semilattice_inf sup greater_eq greater"
   185   "class.semilattice_inf sup greater_eq greater"
   186 by (rule class.semilattice_inf.intro, rule dual_order)
   186 by (rule class.semilattice_inf.intro, rule dual_order)
   187   (unfold_locales, simp_all add: sup_least)
   187   (unfold_locales, simp_all add: sup_least)
   189 end
   189 end
   190 
   190 
   191 class lattice = semilattice_inf + semilattice_sup
   191 class lattice = semilattice_inf + semilattice_sup
   192 
   192 
   193 
   193 
   194 subsubsection {* Intro and elim rules*}
   194 subsubsection \<open>Intro and elim rules\<close>
   195 
   195 
   196 context semilattice_inf
   196 context semilattice_inf
   197 begin
   197 begin
   198 
   198 
   199 lemma le_infI1:
   199 lemma le_infI1:
   264   by (auto simp add: mono_def intro: Lattices.sup_least)
   264   by (auto simp add: mono_def intro: Lattices.sup_least)
   265 
   265 
   266 end
   266 end
   267 
   267 
   268 
   268 
   269 subsubsection {* Equational laws *}
   269 subsubsection \<open>Equational laws\<close>
   270 
   270 
   271 context semilattice_inf
   271 context semilattice_inf
   272 begin
   272 begin
   273 
   273 
   274 sublocale inf!: semilattice inf
   274 sublocale inf!: semilattice inf
   371 
   371 
   372 lemmas inf_sup_aci = inf_aci sup_aci
   372 lemmas inf_sup_aci = inf_aci sup_aci
   373 
   373 
   374 lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
   374 lemmas inf_sup_ord = inf_le1 inf_le2 sup_ge1 sup_ge2
   375 
   375 
   376 text{* Towards distributivity *}
   376 text\<open>Towards distributivity\<close>
   377 
   377 
   378 lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   378 lemma distrib_sup_le: "x \<squnion> (y \<sqinter> z) \<sqsubseteq> (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   379   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   379   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   380 
   380 
   381 lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
   381 lemma distrib_inf_le: "(x \<sqinter> y) \<squnion> (x \<sqinter> z) \<sqsubseteq> x \<sqinter> (y \<squnion> z)"
   382   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   382   by (auto intro: le_infI1 le_infI2 le_supI1 le_supI2)
   383 
   383 
   384 text{* If you have one of them, you have them all. *}
   384 text\<open>If you have one of them, you have them all.\<close>
   385 
   385 
   386 lemma distrib_imp1:
   386 lemma distrib_imp1:
   387 assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   387 assumes D: "!!x y z. x \<sqinter> (y \<squnion> z) = (x \<sqinter> y) \<squnion> (x \<sqinter> z)"
   388 shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   388 shows "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   389 proof-
   389 proof-
   409   finally show ?thesis .
   409   finally show ?thesis .
   410 qed
   410 qed
   411 
   411 
   412 end
   412 end
   413 
   413 
   414 subsubsection {* Strict order *}
   414 subsubsection \<open>Strict order\<close>
   415 
   415 
   416 context semilattice_inf
   416 context semilattice_inf
   417 begin
   417 begin
   418 
   418 
   419 lemma less_infI1:
   419 lemma less_infI1:
   440   by (rule semilattice_inf.less_infI2)
   440   by (rule semilattice_inf.less_infI2)
   441 
   441 
   442 end
   442 end
   443 
   443 
   444 
   444 
   445 subsection {* Distributive lattices *}
   445 subsection \<open>Distributive lattices\<close>
   446 
   446 
   447 class distrib_lattice = lattice +
   447 class distrib_lattice = lattice +
   448   assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   448   assumes sup_inf_distrib1: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)"
   449 
   449 
   450 context distrib_lattice
   450 context distrib_lattice
   477   sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
   477   sup_inf_distrib1 sup_inf_distrib2 inf_sup_distrib1 inf_sup_distrib2
   478 
   478 
   479 end
   479 end
   480 
   480 
   481 
   481 
   482 subsection {* Bounded lattices and boolean algebras *}
   482 subsection \<open>Bounded lattices and boolean algebras\<close>
   483 
   483 
   484 class bounded_semilattice_inf_top = semilattice_inf + order_top
   484 class bounded_semilattice_inf_top = semilattice_inf + order_top
   485 begin
   485 begin
   486 
   486 
   487 sublocale inf_top!: semilattice_neutr inf top
   487 sublocale inf_top!: semilattice_neutr inf top
   708 qed
   708 qed
   709 
   709 
   710 end
   710 end
   711 
   711 
   712 
   712 
   713 subsection {* @{text "min/max"} as special case of lattice *}
   713 subsection \<open>@{text "min/max"} as special case of lattice\<close>
   714 
   714 
   715 context linorder
   715 context linorder
   716 begin
   716 begin
   717 
   717 
   718 sublocale min!: semilattice_order min less_eq less
   718 sublocale min!: semilattice_order min less_eq less
   786 
   786 
   787 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   787 lemma sup_max: "sup = (max \<Colon> 'a\<Colon>{semilattice_sup, linorder} \<Rightarrow> 'a \<Rightarrow> 'a)"
   788   by (auto intro: antisym simp add: max_def fun_eq_iff)
   788   by (auto intro: antisym simp add: max_def fun_eq_iff)
   789 
   789 
   790 
   790 
   791 subsection {* Uniqueness of inf and sup *}
   791 subsection \<open>Uniqueness of inf and sup\<close>
   792 
   792 
   793 lemma (in semilattice_inf) inf_unique:
   793 lemma (in semilattice_inf) inf_unique:
   794   fixes f (infixl "\<triangle>" 70)
   794   fixes f (infixl "\<triangle>" 70)
   795   assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
   795   assumes le1: "\<And>x y. x \<triangle> y \<sqsubseteq> x" and le2: "\<And>x y. x \<triangle> y \<sqsubseteq> y"
   796   and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
   796   and greatest: "\<And>x y z. x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<triangle> z"
   813   have leI: "\<And>x y z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<nabla> y \<sqsubseteq> z" by (blast intro: least)
   813   have leI: "\<And>x y z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> x \<nabla> y \<sqsubseteq> z" by (blast intro: least)
   814   show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
   814   show "x \<nabla> y \<sqsubseteq> x \<squnion> y" by (rule leI) simp_all
   815 qed
   815 qed
   816 
   816 
   817 
   817 
   818 subsection {* Lattice on @{typ bool} *}
   818 subsection \<open>Lattice on @{typ bool}\<close>
   819 
   819 
   820 instantiation bool :: boolean_algebra
   820 instantiation bool :: boolean_algebra
   821 begin
   821 begin
   822 
   822 
   823 definition
   823 definition
   848 lemma sup_boolE:
   848 lemma sup_boolE:
   849   "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
   849   "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
   850   by auto
   850   by auto
   851 
   851 
   852 
   852 
   853 subsection {* Lattice on @{typ "_ \<Rightarrow> _"} *}
   853 subsection \<open>Lattice on @{typ "_ \<Rightarrow> _"}\<close>
   854 
   854 
   855 instantiation "fun" :: (type, semilattice_sup) semilattice_sup
   855 instantiation "fun" :: (type, semilattice_sup) semilattice_sup
   856 begin
   856 begin
   857 
   857 
   858 definition
   858 definition
   919 
   919 
   920 instance "fun" :: (type, boolean_algebra) boolean_algebra proof
   920 instance "fun" :: (type, boolean_algebra) boolean_algebra proof
   921 qed (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
   921 qed (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
   922 
   922 
   923 
   923 
   924 subsection {* Lattice on unary and binary predicates *}
   924 subsection \<open>Lattice on unary and binary predicates\<close>
   925 
   925 
   926 lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
   926 lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
   927   by (simp add: inf_fun_def)
   927   by (simp add: inf_fun_def)
   928 
   928 
   929 lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
   929 lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
   963   by (simp add: sup_fun_def) iprover
   963   by (simp add: sup_fun_def) iprover
   964 
   964 
   965 lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
   965 lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
   966   by (simp add: sup_fun_def) iprover
   966   by (simp add: sup_fun_def) iprover
   967 
   967 
   968 text {*
   968 text \<open>
   969   \medskip Classical introduction rule: no commitment to @{text A} vs
   969   \medskip Classical introduction rule: no commitment to @{text A} vs
   970   @{text B}.
   970   @{text B}.
   971 *}
   971 \<close>
   972 
   972 
   973 lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
   973 lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
   974   by (auto simp add: sup_fun_def)
   974   by (auto simp add: sup_fun_def)
   975 
   975 
   976 lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"
   976 lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"