clarified abstract and concrete boolean algebras
authorhaftmann
Thu, 05 Aug 2021 07:12:49 +0000
changeset 74391 7c5842b06114
parent 74390 7d3e818fe21f
child 74392 94c27a7a0d39
child 74394 d36e40f3c171
clarified abstract and concrete boolean algebras
NEWS
src/HOL/Analysis/Path_Connected.thy
src/HOL/Bit_Operations.thy
src/HOL/Boolean_Algebra.thy
src/HOL/Boolean_Algebras.thy
src/HOL/Fun.thy
src/HOL/Hilbert_Choice.thy
src/HOL/Lattices.thy
src/HOL/Set.thy
--- a/NEWS	Thu Aug 05 07:12:49 2021 +0000
+++ b/NEWS	Thu Aug 05 07:12:49 2021 +0000
@@ -191,11 +191,18 @@
 
 * Theory Bit_Operations is now part of HOL-Main. Minor INCOMPATIBILITY.
 
+* Simplified class hierarchy for bit operations: bit operations reside
+in classes (semi)ring_bit_operations, class semiring_bit_shifts is
+gone.
+
 * Abbreviation "max_word" has been moved to session Word_Lib in the AFP,
 as also have constants "shiftl1", "shiftr1", "sshiftr1", "bshiftr1",
 "setBit", "clearBit". See there further the changelog in theory Guide.
 INCOMPATIBILITY.
 
+* Reorganized classes and locales for boolean algebras.
+INCOMPATIBILITY.
+
 * New simp rules: less_exp, min.absorb1, min.absorb2, min.absorb3,
 min.absorb4, max.absorb1, max.absorb2, max.absorb3, max.absorb4. Minor
 INCOMPATIBILITY.
--- a/src/HOL/Analysis/Path_Connected.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Analysis/Path_Connected.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -3483,7 +3483,7 @@
     fixes S :: "'a::real_normed_vector set"
     assumes "bounded S"
     shows  "outside(frontier S) \<subseteq> - closure S"
-  unfolding outside_inside Lattices.boolean_algebra_class.compl_le_compl_iff
+  unfolding outside_inside boolean_algebra_class.compl_le_compl_iff
 proof -
   { assume "interior S \<subseteq> inside (frontier S)"
     hence "interior S \<union> inside (frontier S) = inside (frontier S)"
--- a/src/HOL/Bit_Operations.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Bit_Operations.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -1326,17 +1326,14 @@
 sublocale "and": semilattice_neutr \<open>(AND)\<close> \<open>- 1\<close>
   by standard (rule bit_eqI, simp add: bit_and_iff)
 
-sublocale bit: boolean_algebra \<open>(AND)\<close> \<open>(OR)\<close> NOT 0 \<open>- 1\<close>
-  rewrites \<open>bit.xor = (XOR)\<close>
-proof -
-  interpret bit: boolean_algebra \<open>(AND)\<close> \<open>(OR)\<close> NOT 0 \<open>- 1\<close>
-    by standard (auto simp add: bit_and_iff bit_or_iff bit_not_iff intro: bit_eqI)
-  show \<open>boolean_algebra (AND) (OR) NOT 0 (- 1)\<close>
-    by standard
-  show \<open>boolean_algebra.xor (AND) (OR) NOT = (XOR)\<close>
-    by (rule ext, rule ext, rule bit_eqI)
-      (auto simp add: bit.xor_def bit_and_iff bit_or_iff bit_xor_iff bit_not_iff)
-qed
+sublocale bit: abstract_boolean_algebra \<open>(AND)\<close> \<open>(OR)\<close> NOT 0 \<open>- 1\<close>
+  by standard (auto simp add: bit_and_iff bit_or_iff bit_not_iff intro: bit_eqI)
+
+sublocale bit: abstract_boolean_algebra_sym_diff \<open>(AND)\<close> \<open>(OR)\<close> NOT 0 \<open>- 1\<close> \<open>(XOR)\<close>
+  apply standard
+  apply (rule bit_eqI)
+  apply (auto simp add: bit_simps)
+  done
 
 lemma and_eq_not_not_or:
   \<open>a AND b = NOT (NOT a OR NOT b)\<close>
@@ -3565,8 +3562,6 @@
       \<^item> (Bounded) conversion from and to a list of bits: @{thm horner_sum_bit_eq_take_bit [where ?'a = int, no_vars]}
 \<close>
 
-find_theorems \<open>(_ AND _) * _ = _\<close>
-
 no_notation
   "and"  (infixr \<open>AND\<close> 64)
     and or  (infixr \<open>OR\<close>  59)
--- a/src/HOL/Boolean_Algebra.thy	Thu Aug 05 07:12:49 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,296 +0,0 @@
-(*  Title:      HOL/Boolean_Algebra.thy
-    Author:     Brian Huffman
-*)
-
-section \<open>Abstract boolean Algebras\<close>
-
-theory Boolean_Algebra
-  imports Lattices
-begin
-
-locale boolean_algebra = conj: abel_semigroup "(\<^bold>\<sqinter>)" + disj: abel_semigroup "(\<^bold>\<squnion>)"
-  for conj :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "\<^bold>\<sqinter>" 70)
-    and disj :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "\<^bold>\<squnion>" 65) +
-  fixes compl :: "'a \<Rightarrow> 'a"  ("\<^bold>- _" [81] 80)
-    and zero :: "'a"  ("\<^bold>0")
-    and one  :: "'a"  ("\<^bold>1")
-  assumes conj_disj_distrib: "x \<^bold>\<sqinter> (y \<^bold>\<squnion> z) = (x \<^bold>\<sqinter> y) \<^bold>\<squnion> (x \<^bold>\<sqinter> z)"
-    and disj_conj_distrib: "x \<^bold>\<squnion> (y \<^bold>\<sqinter> z) = (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (x \<^bold>\<squnion> z)"
-    and conj_one_right: "x \<^bold>\<sqinter> \<^bold>1 = x"
-    and disj_zero_right: "x \<^bold>\<squnion> \<^bold>0 = x"
-    and conj_cancel_right [simp]: "x \<^bold>\<sqinter> \<^bold>- x = \<^bold>0"
-    and disj_cancel_right [simp]: "x \<^bold>\<squnion> \<^bold>- x = \<^bold>1"
-begin
-
-sublocale conj: semilattice_neutr "(\<^bold>\<sqinter>)" "\<^bold>1"
-proof
-  show "x \<^bold>\<sqinter> \<^bold>1 = x" for x
-    by (fact conj_one_right)
-  show "x \<^bold>\<sqinter> x = x" for x
-  proof -
-    have "x \<^bold>\<sqinter> x = (x \<^bold>\<sqinter> x) \<^bold>\<squnion> \<^bold>0"
-      by (simp add: disj_zero_right)
-    also have "\<dots> = (x \<^bold>\<sqinter> x) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- x)"
-      by simp
-    also have "\<dots> = x \<^bold>\<sqinter> (x \<^bold>\<squnion> \<^bold>- x)"
-      by (simp only: conj_disj_distrib)
-    also have "\<dots> = x \<^bold>\<sqinter> \<^bold>1"
-      by simp
-    also have "\<dots> = x"
-      by (simp add: conj_one_right)
-    finally show ?thesis .
-  qed
-qed
-
-sublocale disj: semilattice_neutr "(\<^bold>\<squnion>)" "\<^bold>0"
-proof
-  show "x \<^bold>\<squnion> \<^bold>0 = x" for x
-    by (fact disj_zero_right)
-  show "x \<^bold>\<squnion> x = x" for x
-  proof -
-    have "x \<^bold>\<squnion> x = (x \<^bold>\<squnion> x) \<^bold>\<sqinter> \<^bold>1"
-      by simp
-    also have "\<dots> = (x \<^bold>\<squnion> x) \<^bold>\<sqinter> (x \<^bold>\<squnion> \<^bold>- x)"
-      by simp
-    also have "\<dots> = x \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- x)"
-      by (simp only: disj_conj_distrib)
-    also have "\<dots> = x \<^bold>\<squnion> \<^bold>0"
-      by simp
-    also have "\<dots> = x"
-      by (simp add: disj_zero_right)
-    finally show ?thesis .
-  qed
-qed
-
-
-subsection \<open>Complement\<close>
-
-lemma complement_unique:
-  assumes 1: "a \<^bold>\<sqinter> x = \<^bold>0"
-  assumes 2: "a \<^bold>\<squnion> x = \<^bold>1"
-  assumes 3: "a \<^bold>\<sqinter> y = \<^bold>0"
-  assumes 4: "a \<^bold>\<squnion> y = \<^bold>1"
-  shows "x = y"
-proof -
-  from 1 3 have "(a \<^bold>\<sqinter> x) \<^bold>\<squnion> (x \<^bold>\<sqinter> y) = (a \<^bold>\<sqinter> y) \<^bold>\<squnion> (x \<^bold>\<sqinter> y)"
-    by simp
-  then have "(x \<^bold>\<sqinter> a) \<^bold>\<squnion> (x \<^bold>\<sqinter> y) = (y \<^bold>\<sqinter> a) \<^bold>\<squnion> (y \<^bold>\<sqinter> x)"
-    by (simp add: ac_simps)
-  then have "x \<^bold>\<sqinter> (a \<^bold>\<squnion> y) = y \<^bold>\<sqinter> (a \<^bold>\<squnion> x)"
-    by (simp add: conj_disj_distrib)
-  with 2 4 have "x \<^bold>\<sqinter> \<^bold>1 = y \<^bold>\<sqinter> \<^bold>1"
-    by simp
-  then show "x = y"
-    by simp
-qed
-
-lemma compl_unique: "x \<^bold>\<sqinter> y = \<^bold>0 \<Longrightarrow> x \<^bold>\<squnion> y = \<^bold>1 \<Longrightarrow> \<^bold>- x = y"
-  by (rule complement_unique [OF conj_cancel_right disj_cancel_right])
-
-lemma double_compl [simp]: "\<^bold>- (\<^bold>- x) = x"
-proof (rule compl_unique)
-  show "\<^bold>- x \<^bold>\<sqinter> x = \<^bold>0"
-    by (simp only: conj_cancel_right conj.commute)
-  show "\<^bold>- x \<^bold>\<squnion> x = \<^bold>1"
-    by (simp only: disj_cancel_right disj.commute)
-qed
-
-lemma compl_eq_compl_iff [simp]: 
-  \<open>\<^bold>- x = \<^bold>- y \<longleftrightarrow> x = y\<close>  (is \<open>?P \<longleftrightarrow> ?Q\<close>)
-proof
-  assume \<open>?Q\<close>
-  then show ?P by simp
-next
-  assume \<open>?P\<close>
-  then have \<open>\<^bold>- (\<^bold>- x) = \<^bold>- (\<^bold>- y)\<close>
-    by simp
-  then show ?Q
-    by simp
-qed
-
-
-subsection \<open>Conjunction\<close>
-
-lemma conj_zero_right [simp]: "x \<^bold>\<sqinter> \<^bold>0 = \<^bold>0"
-  using conj.left_idem conj_cancel_right by fastforce
-
-lemma compl_one [simp]: "\<^bold>- \<^bold>1 = \<^bold>0"
-  by (rule compl_unique [OF conj_zero_right disj_zero_right])
-
-lemma conj_zero_left [simp]: "\<^bold>0 \<^bold>\<sqinter> x = \<^bold>0"
-  by (subst conj.commute) (rule conj_zero_right)
-
-lemma conj_cancel_left [simp]: "\<^bold>- x \<^bold>\<sqinter> x = \<^bold>0"
-  by (subst conj.commute) (rule conj_cancel_right)
-
-lemma conj_disj_distrib2: "(y \<^bold>\<squnion> z) \<^bold>\<sqinter> x = (y \<^bold>\<sqinter> x) \<^bold>\<squnion> (z \<^bold>\<sqinter> x)"
-  by (simp only: conj.commute conj_disj_distrib)
-
-lemmas conj_disj_distribs = conj_disj_distrib conj_disj_distrib2
-
-lemma conj_assoc: "(x \<^bold>\<sqinter> y) \<^bold>\<sqinter> z = x \<^bold>\<sqinter> (y \<^bold>\<sqinter> z)"
-  by (fact ac_simps)
-
-lemma conj_commute: "x \<^bold>\<sqinter> y = y \<^bold>\<sqinter> x"
-  by (fact ac_simps)
-
-lemmas conj_left_commute = conj.left_commute
-lemmas conj_ac = conj.assoc conj.commute conj.left_commute
-
-lemma conj_one_left: "\<^bold>1 \<^bold>\<sqinter> x = x"
-  by (fact conj.left_neutral)
-
-lemma conj_left_absorb: "x \<^bold>\<sqinter> (x \<^bold>\<sqinter> y) = x \<^bold>\<sqinter> y"
-  by (fact conj.left_idem)
-
-lemma conj_absorb: "x \<^bold>\<sqinter> x = x"
-  by (fact conj.idem)
-
-
-subsection \<open>Disjunction\<close>
-
-interpretation dual: boolean_algebra "(\<^bold>\<squnion>)" "(\<^bold>\<sqinter>)" compl \<open>\<^bold>1\<close> \<open>\<^bold>0\<close>
-  apply standard
-       apply (rule disj_conj_distrib)
-      apply (rule conj_disj_distrib)
-     apply simp_all
-  done
-
-lemma compl_zero [simp]: "\<^bold>- \<^bold>0 = \<^bold>1"
-  by (fact dual.compl_one)
-
-lemma disj_one_right [simp]: "x \<^bold>\<squnion> \<^bold>1 = \<^bold>1"
-  by (fact dual.conj_zero_right)
-
-lemma disj_one_left [simp]: "\<^bold>1 \<^bold>\<squnion> x = \<^bold>1"
-  by (fact dual.conj_zero_left)
-
-lemma disj_cancel_left [simp]: "\<^bold>- x \<^bold>\<squnion> x = \<^bold>1"
-  by (rule dual.conj_cancel_left)
-
-lemma disj_conj_distrib2: "(y \<^bold>\<sqinter> z) \<^bold>\<squnion> x = (y \<^bold>\<squnion> x) \<^bold>\<sqinter> (z \<^bold>\<squnion> x)"
-  by (rule dual.conj_disj_distrib2)
-
-lemmas disj_conj_distribs = disj_conj_distrib disj_conj_distrib2
-
-lemma disj_assoc: "(x \<^bold>\<squnion> y) \<^bold>\<squnion> z = x \<^bold>\<squnion> (y \<^bold>\<squnion> z)"
-  by (fact ac_simps)
-
-lemma disj_commute: "x \<^bold>\<squnion> y = y \<^bold>\<squnion> x"
-  by (fact ac_simps)
-
-lemmas disj_left_commute = disj.left_commute
-
-lemmas disj_ac = disj.assoc disj.commute disj.left_commute
-
-lemma disj_zero_left: "\<^bold>0 \<^bold>\<squnion> x = x"
-  by (fact disj.left_neutral)
-
-lemma disj_left_absorb: "x \<^bold>\<squnion> (x \<^bold>\<squnion> y) = x \<^bold>\<squnion> y"
-  by (fact disj.left_idem)
-
-lemma disj_absorb: "x \<^bold>\<squnion> x = x"
-  by (fact disj.idem)
-
-
-subsection \<open>De Morgan's Laws\<close>
-
-lemma de_Morgan_conj [simp]: "\<^bold>- (x \<^bold>\<sqinter> y) = \<^bold>- x \<^bold>\<squnion> \<^bold>- y"
-proof (rule compl_unique)
-  have "(x \<^bold>\<sqinter> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = ((x \<^bold>\<sqinter> y) \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> ((x \<^bold>\<sqinter> y) \<^bold>\<sqinter> \<^bold>- y)"
-    by (rule conj_disj_distrib)
-  also have "\<dots> = (y \<^bold>\<sqinter> (x \<^bold>\<sqinter> \<^bold>- x)) \<^bold>\<squnion> (x \<^bold>\<sqinter> (y \<^bold>\<sqinter> \<^bold>- y))"
-    by (simp only: conj_ac)
-  finally show "(x \<^bold>\<sqinter> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = \<^bold>0"
-    by (simp only: conj_cancel_right conj_zero_right disj_zero_right)
-next
-  have "(x \<^bold>\<sqinter> y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = (x \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y)) \<^bold>\<sqinter> (y \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y))"
-    by (rule disj_conj_distrib2)
-  also have "\<dots> = (\<^bold>- y \<^bold>\<squnion> (x \<^bold>\<squnion> \<^bold>- x)) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> (y \<^bold>\<squnion> \<^bold>- y))"
-    by (simp only: disj_ac)
-  finally show "(x \<^bold>\<sqinter> y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = \<^bold>1"
-    by (simp only: disj_cancel_right disj_one_right conj_one_right)
-qed
-
-lemma de_Morgan_disj [simp]: "\<^bold>- (x \<^bold>\<squnion> y) = \<^bold>- x \<^bold>\<sqinter> \<^bold>- y"
-  using dual.boolean_algebra_axioms by (rule boolean_algebra.de_Morgan_conj)
-
-
-subsection \<open>Symmetric Difference\<close>
-
-definition xor :: "'a \<Rightarrow> 'a \<Rightarrow> 'a"  (infixr "\<^bold>\<ominus>" 65)
-  where "x \<^bold>\<ominus> y = (x \<^bold>\<sqinter> \<^bold>- y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> y)"
-
-sublocale xor: comm_monoid xor \<open>\<^bold>0\<close>
-proof
-  fix x y z :: 'a
-  let ?t = "(x \<^bold>\<sqinter> y \<^bold>\<sqinter> z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z)"
-  have "?t \<^bold>\<squnion> (z \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (z \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- y) = ?t \<^bold>\<squnion> (x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- y) \<^bold>\<squnion> (x \<^bold>\<sqinter> z \<^bold>\<sqinter> \<^bold>- z)"
-    by (simp only: conj_cancel_right conj_zero_right)
-  then show "(x \<^bold>\<ominus> y) \<^bold>\<ominus> z = x \<^bold>\<ominus> (y \<^bold>\<ominus> z)"
-    by (simp only: xor_def de_Morgan_disj de_Morgan_conj double_compl)
-      (simp only: conj_disj_distribs conj_ac disj_ac)
-  show "x \<^bold>\<ominus> y = y \<^bold>\<ominus> x"
-    by (simp only: xor_def conj_commute disj_commute)
-  show "x \<^bold>\<ominus> \<^bold>0 = x"
-    by (simp add: xor_def)
-qed
-
-lemmas xor_assoc = xor.assoc
-lemmas xor_commute = xor.commute
-lemmas xor_left_commute = xor.left_commute
-
-lemmas xor_ac = xor.assoc xor.commute xor.left_commute
-
-lemma xor_def2: "x \<^bold>\<ominus> y = (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y)"
-  using conj.commute conj_disj_distrib2 disj.commute xor_def by auto
-
-lemma xor_zero_right: "x \<^bold>\<ominus> \<^bold>0 = x"
-  by (fact xor.comm_neutral)
-
-lemma xor_zero_left: "\<^bold>0 \<^bold>\<ominus> x = x"
-  by (fact xor.left_neutral)
-
-lemma xor_one_right [simp]: "x \<^bold>\<ominus> \<^bold>1 = \<^bold>- x"
-  by (simp only: xor_def compl_one conj_zero_right conj_one_right disj_zero_left)
-
-lemma xor_one_left [simp]: "\<^bold>1 \<^bold>\<ominus> x = \<^bold>- x"
-  by (subst xor_commute) (rule xor_one_right)
-
-lemma xor_self [simp]: "x \<^bold>\<ominus> x = \<^bold>0"
-  by (simp only: xor_def conj_cancel_right conj_cancel_left disj_zero_right)
-
-lemma xor_left_self [simp]: "x \<^bold>\<ominus> (x \<^bold>\<ominus> y) = y"
-  by (simp only: xor_assoc [symmetric] xor_self xor_zero_left)
-
-lemma xor_compl_left [simp]: "\<^bold>- x \<^bold>\<ominus> y = \<^bold>- (x \<^bold>\<ominus> y)"
-  by (simp add: ac_simps flip: xor_one_left)
-
-lemma xor_compl_right [simp]: "x \<^bold>\<ominus> \<^bold>- y = \<^bold>- (x \<^bold>\<ominus> y)"
-  using xor_commute xor_compl_left by auto
-
-lemma xor_cancel_right: "x \<^bold>\<ominus> \<^bold>- x = \<^bold>1"
-  by (simp only: xor_compl_right xor_self compl_zero)
-
-lemma xor_cancel_left: "\<^bold>- x \<^bold>\<ominus> x = \<^bold>1"
-  by (simp only: xor_compl_left xor_self compl_zero)
-
-lemma conj_xor_distrib: "x \<^bold>\<sqinter> (y \<^bold>\<ominus> z) = (x \<^bold>\<sqinter> y) \<^bold>\<ominus> (x \<^bold>\<sqinter> z)"
-proof -
-  have *: "(x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z) =
-        (y \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (z \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z)"
-    by (simp only: conj_cancel_right conj_zero_right disj_zero_left)
-  then show "x \<^bold>\<sqinter> (y \<^bold>\<ominus> z) = (x \<^bold>\<sqinter> y) \<^bold>\<ominus> (x \<^bold>\<sqinter> z)"
-    by (simp (no_asm_use) only:
-        xor_def de_Morgan_disj de_Morgan_conj double_compl
-        conj_disj_distribs conj_ac disj_ac)
-qed
-
-lemma conj_xor_distrib2: "(y \<^bold>\<ominus> z) \<^bold>\<sqinter> x = (y \<^bold>\<sqinter> x) \<^bold>\<ominus> (z \<^bold>\<sqinter> x)"
-  by (simp add: conj.commute conj_xor_distrib)
-
-lemmas conj_xor_distribs = conj_xor_distrib conj_xor_distrib2
-
-end
-
-end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/Boolean_Algebras.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -0,0 +1,573 @@
+(*  Title:      HOL/Boolean_Algebras.thy
+    Author:     Brian Huffman
+    Author:     Florian Haftmann
+*)
+
+section \<open>Boolean Algebras\<close>
+
+theory Boolean_Algebras
+  imports Lattices
+begin
+
+subsection \<open>Abstract boolean algebra\<close>
+
+locale abstract_boolean_algebra = conj: abel_semigroup \<open>(\<^bold>\<sqinter>)\<close> + disj: abel_semigroup \<open>(\<^bold>\<squnion>)\<close>
+  for conj :: \<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>  (infixr \<open>\<^bold>\<sqinter>\<close> 70)
+    and disj :: \<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>  (infixr \<open>\<^bold>\<squnion>\<close> 65) +
+  fixes compl :: \<open>'a \<Rightarrow> 'a\<close>  (\<open>\<^bold>- _\<close> [81] 80)
+    and zero :: \<open>'a\<close>  (\<open>\<^bold>0\<close>)
+    and one  :: \<open>'a\<close>  (\<open>\<^bold>1\<close>)
+  assumes conj_disj_distrib: \<open>x \<^bold>\<sqinter> (y \<^bold>\<squnion> z) = (x \<^bold>\<sqinter> y) \<^bold>\<squnion> (x \<^bold>\<sqinter> z)\<close>
+    and disj_conj_distrib: \<open>x \<^bold>\<squnion> (y \<^bold>\<sqinter> z) = (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (x \<^bold>\<squnion> z)\<close>
+    and conj_one_right: \<open>x \<^bold>\<sqinter> \<^bold>1 = x\<close>
+    and disj_zero_right: \<open>x \<^bold>\<squnion> \<^bold>0 = x\<close>
+    and conj_cancel_right [simp]: \<open>x \<^bold>\<sqinter> \<^bold>- x = \<^bold>0\<close>
+    and disj_cancel_right [simp]: \<open>x \<^bold>\<squnion> \<^bold>- x = \<^bold>1\<close>
+begin
+
+sublocale conj: semilattice_neutr \<open>(\<^bold>\<sqinter>)\<close> \<open>\<^bold>1\<close>
+proof
+  show "x \<^bold>\<sqinter> \<^bold>1 = x" for x 
+    by (fact conj_one_right)
+  show "x \<^bold>\<sqinter> x = x" for x
+  proof -
+    have "x \<^bold>\<sqinter> x = (x \<^bold>\<sqinter> x) \<^bold>\<squnion> \<^bold>0"
+      by (simp add: disj_zero_right)
+    also have "\<dots> = (x \<^bold>\<sqinter> x) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- x)"
+      by simp
+    also have "\<dots> = x \<^bold>\<sqinter> (x \<^bold>\<squnion> \<^bold>- x)"
+      by (simp only: conj_disj_distrib)
+    also have "\<dots> = x \<^bold>\<sqinter> \<^bold>1"
+      by simp
+    also have "\<dots> = x"
+      by (simp add: conj_one_right)
+    finally show ?thesis .
+  qed
+qed
+
+sublocale disj: semilattice_neutr \<open>(\<^bold>\<squnion>)\<close> \<open>\<^bold>0\<close>
+proof
+  show "x \<^bold>\<squnion> \<^bold>0 = x" for x
+    by (fact disj_zero_right)
+  show "x \<^bold>\<squnion> x = x" for x
+  proof -
+    have "x \<^bold>\<squnion> x = (x \<^bold>\<squnion> x) \<^bold>\<sqinter> \<^bold>1"
+      by simp
+    also have "\<dots> = (x \<^bold>\<squnion> x) \<^bold>\<sqinter> (x \<^bold>\<squnion> \<^bold>- x)"
+      by simp
+    also have "\<dots> = x \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- x)"
+      by (simp only: disj_conj_distrib)
+    also have "\<dots> = x \<^bold>\<squnion> \<^bold>0"
+      by simp
+    also have "\<dots> = x"
+      by (simp add: disj_zero_right)
+    finally show ?thesis .
+  qed
+qed
+
+
+subsubsection \<open>Complement\<close>
+
+lemma complement_unique:
+  assumes 1: "a \<^bold>\<sqinter> x = \<^bold>0"
+  assumes 2: "a \<^bold>\<squnion> x = \<^bold>1"
+  assumes 3: "a \<^bold>\<sqinter> y = \<^bold>0"
+  assumes 4: "a \<^bold>\<squnion> y = \<^bold>1"
+  shows "x = y"
+proof -
+  from 1 3 have "(a \<^bold>\<sqinter> x) \<^bold>\<squnion> (x \<^bold>\<sqinter> y) = (a \<^bold>\<sqinter> y) \<^bold>\<squnion> (x \<^bold>\<sqinter> y)"
+    by simp
+  then have "(x \<^bold>\<sqinter> a) \<^bold>\<squnion> (x \<^bold>\<sqinter> y) = (y \<^bold>\<sqinter> a) \<^bold>\<squnion> (y \<^bold>\<sqinter> x)"
+    by (simp add: ac_simps)
+  then have "x \<^bold>\<sqinter> (a \<^bold>\<squnion> y) = y \<^bold>\<sqinter> (a \<^bold>\<squnion> x)"
+    by (simp add: conj_disj_distrib)
+  with 2 4 have "x \<^bold>\<sqinter> \<^bold>1 = y \<^bold>\<sqinter> \<^bold>1"
+    by simp
+  then show "x = y"
+    by simp
+qed
+
+lemma compl_unique: "x \<^bold>\<sqinter> y = \<^bold>0 \<Longrightarrow> x \<^bold>\<squnion> y = \<^bold>1 \<Longrightarrow> \<^bold>- x = y"
+  by (rule complement_unique [OF conj_cancel_right disj_cancel_right])
+
+lemma double_compl [simp]: "\<^bold>- (\<^bold>- x) = x"
+proof (rule compl_unique)
+  show "\<^bold>- x \<^bold>\<sqinter> x = \<^bold>0"
+    by (simp only: conj_cancel_right conj.commute)
+  show "\<^bold>- x \<^bold>\<squnion> x = \<^bold>1"
+    by (simp only: disj_cancel_right disj.commute)
+qed
+
+lemma compl_eq_compl_iff [simp]: 
+  \<open>\<^bold>- x = \<^bold>- y \<longleftrightarrow> x = y\<close>  (is \<open>?P \<longleftrightarrow> ?Q\<close>)
+proof
+  assume \<open>?Q\<close>
+  then show ?P by simp
+next
+  assume \<open>?P\<close>
+  then have \<open>\<^bold>- (\<^bold>- x) = \<^bold>- (\<^bold>- y)\<close>
+    by simp
+  then show ?Q
+    by simp
+qed
+
+
+subsubsection \<open>Conjunction\<close>
+
+lemma conj_zero_right [simp]: "x \<^bold>\<sqinter> \<^bold>0 = \<^bold>0"
+  using conj.left_idem conj_cancel_right by fastforce
+
+lemma compl_one [simp]: "\<^bold>- \<^bold>1 = \<^bold>0"
+  by (rule compl_unique [OF conj_zero_right disj_zero_right])
+
+lemma conj_zero_left [simp]: "\<^bold>0 \<^bold>\<sqinter> x = \<^bold>0"
+  by (subst conj.commute) (rule conj_zero_right)
+
+lemma conj_cancel_left [simp]: "\<^bold>- x \<^bold>\<sqinter> x = \<^bold>0"
+  by (subst conj.commute) (rule conj_cancel_right)
+
+lemma conj_disj_distrib2: "(y \<^bold>\<squnion> z) \<^bold>\<sqinter> x = (y \<^bold>\<sqinter> x) \<^bold>\<squnion> (z \<^bold>\<sqinter> x)"
+  by (simp only: conj.commute conj_disj_distrib)
+
+lemmas conj_disj_distribs = conj_disj_distrib conj_disj_distrib2
+
+
+subsubsection \<open>Disjunction\<close>
+
+context
+begin
+
+interpretation dual: abstract_boolean_algebra \<open>(\<^bold>\<squnion>)\<close> \<open>(\<^bold>\<sqinter>)\<close> compl \<open>\<^bold>1\<close> \<open>\<^bold>0\<close>
+  apply standard
+       apply (rule disj_conj_distrib)
+      apply (rule conj_disj_distrib)
+     apply simp_all
+  done
+
+lemma disj_one_right [simp]: "x \<^bold>\<squnion> \<^bold>1 = \<^bold>1"
+  by (fact dual.conj_zero_right)
+
+lemma compl_zero [simp]: "\<^bold>- \<^bold>0 = \<^bold>1"
+  by (fact dual.compl_one)
+
+lemma disj_one_left [simp]: "\<^bold>1 \<^bold>\<squnion> x = \<^bold>1"
+  by (fact dual.conj_zero_left)
+
+lemma disj_cancel_left [simp]: "\<^bold>- x \<^bold>\<squnion> x = \<^bold>1"
+  by (fact dual.conj_cancel_left)
+
+lemma disj_conj_distrib2: "(y \<^bold>\<sqinter> z) \<^bold>\<squnion> x = (y \<^bold>\<squnion> x) \<^bold>\<sqinter> (z \<^bold>\<squnion> x)"
+  by (fact dual.conj_disj_distrib2)
+
+lemmas disj_conj_distribs = disj_conj_distrib disj_conj_distrib2
+
+end
+
+
+subsubsection \<open>De Morgan's Laws\<close>
+
+lemma de_Morgan_conj [simp]: "\<^bold>- (x \<^bold>\<sqinter> y) = \<^bold>- x \<^bold>\<squnion> \<^bold>- y"
+proof (rule compl_unique)
+  have "(x \<^bold>\<sqinter> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = ((x \<^bold>\<sqinter> y) \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> ((x \<^bold>\<sqinter> y) \<^bold>\<sqinter> \<^bold>- y)"
+    by (rule conj_disj_distrib)
+  also have "\<dots> = (y \<^bold>\<sqinter> (x \<^bold>\<sqinter> \<^bold>- x)) \<^bold>\<squnion> (x \<^bold>\<sqinter> (y \<^bold>\<sqinter> \<^bold>- y))"
+    by (simp only: ac_simps)
+  finally show "(x \<^bold>\<sqinter> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = \<^bold>0"
+    by (simp only: conj_cancel_right conj_zero_right disj_zero_right)
+next
+  have "(x \<^bold>\<sqinter> y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = (x \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y)) \<^bold>\<sqinter> (y \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y))"
+    by (rule disj_conj_distrib2)
+  also have "\<dots> = (\<^bold>- y \<^bold>\<squnion> (x \<^bold>\<squnion> \<^bold>- x)) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> (y \<^bold>\<squnion> \<^bold>- y))"
+    by (simp only: ac_simps)
+  finally show "(x \<^bold>\<sqinter> y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y) = \<^bold>1"
+    by (simp only: disj_cancel_right disj_one_right conj_one_right)
+qed
+
+context
+begin
+
+interpretation dual: abstract_boolean_algebra \<open>(\<^bold>\<squnion>)\<close> \<open>(\<^bold>\<sqinter>)\<close> compl \<open>\<^bold>1\<close> \<open>\<^bold>0\<close>
+  apply standard
+       apply (rule disj_conj_distrib)
+      apply (rule conj_disj_distrib)
+     apply simp_all
+  done
+
+lemma de_Morgan_disj [simp]: "\<^bold>- (x \<^bold>\<squnion> y) = \<^bold>- x \<^bold>\<sqinter> \<^bold>- y"
+  by (fact dual.de_Morgan_conj)
+
+end
+
+end
+
+
+subsection \<open>Symmetric Difference\<close>
+
+locale abstract_boolean_algebra_sym_diff = abstract_boolean_algebra +
+  fixes xor :: \<open>'a \<Rightarrow> 'a \<Rightarrow> 'a\<close>  (infixr \<open>\<^bold>\<ominus>\<close> 65)
+  assumes xor_def : \<open>x \<^bold>\<ominus> y = (x \<^bold>\<sqinter> \<^bold>- y) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> y)\<close>
+begin
+
+sublocale xor: comm_monoid xor \<open>\<^bold>0\<close>
+proof
+  fix x y z :: 'a
+  let ?t = "(x \<^bold>\<sqinter> y \<^bold>\<sqinter> z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (\<^bold>- x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z)"
+  have "?t \<^bold>\<squnion> (z \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (z \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- y) = ?t \<^bold>\<squnion> (x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- y) \<^bold>\<squnion> (x \<^bold>\<sqinter> z \<^bold>\<sqinter> \<^bold>- z)"
+    by (simp only: conj_cancel_right conj_zero_right)
+  then show "(x \<^bold>\<ominus> y) \<^bold>\<ominus> z = x \<^bold>\<ominus> (y \<^bold>\<ominus> z)"
+    by (simp only: xor_def de_Morgan_disj de_Morgan_conj double_compl)
+      (simp only: conj_disj_distribs conj_ac ac_simps)
+  show "x \<^bold>\<ominus> y = y \<^bold>\<ominus> x"
+    by (simp only: xor_def ac_simps)
+  show "x \<^bold>\<ominus> \<^bold>0 = x"
+    by (simp add: xor_def)
+qed
+
+lemma xor_def2:
+  \<open>x \<^bold>\<ominus> y = (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y)\<close>
+proof -
+  note xor_def [of x y]
+  also have \<open>x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<squnion> \<^bold>- x \<^bold>\<sqinter> y = ((x \<^bold>\<squnion> \<^bold>- x) \<^bold>\<sqinter> (\<^bold>- y \<^bold>\<squnion> \<^bold>- x)) \<^bold>\<sqinter> (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (\<^bold>- y \<^bold>\<squnion> y)\<close>
+    by (simp add: ac_simps disj_conj_distribs)
+  also have \<open>\<dots> = (x \<^bold>\<squnion> y) \<^bold>\<sqinter> (\<^bold>- x \<^bold>\<squnion> \<^bold>- y)\<close>
+    by (simp add: ac_simps)
+  finally show ?thesis .
+qed
+
+lemma xor_one_right [simp]: "x \<^bold>\<ominus> \<^bold>1 = \<^bold>- x"
+  by (simp only: xor_def compl_one conj_zero_right conj_one_right disj.left_neutral)
+
+lemma xor_one_left [simp]: "\<^bold>1 \<^bold>\<ominus> x = \<^bold>- x"
+  using xor_one_right [of x] by (simp add: ac_simps)
+
+lemma xor_self [simp]: "x \<^bold>\<ominus> x = \<^bold>0"
+  by (simp only: xor_def conj_cancel_right conj_cancel_left disj_zero_right)
+
+lemma xor_left_self [simp]: "x \<^bold>\<ominus> (x \<^bold>\<ominus> y) = y"
+  by (simp only: xor.assoc [symmetric] xor_self xor.left_neutral)
+
+lemma xor_compl_left [simp]: "\<^bold>- x \<^bold>\<ominus> y = \<^bold>- (x \<^bold>\<ominus> y)"
+  by (simp add: ac_simps flip: xor_one_left)
+
+lemma xor_compl_right [simp]: "x \<^bold>\<ominus> \<^bold>- y = \<^bold>- (x \<^bold>\<ominus> y)"
+  using xor.commute xor_compl_left by auto
+
+lemma xor_cancel_right [simp]: "x \<^bold>\<ominus> \<^bold>- x = \<^bold>1"
+  by (simp only: xor_compl_right xor_self compl_zero)
+
+lemma xor_cancel_left [simp]: "\<^bold>- x \<^bold>\<ominus> x = \<^bold>1"
+  by (simp only: xor_compl_left xor_self compl_zero)
+
+lemma conj_xor_distrib: "x \<^bold>\<sqinter> (y \<^bold>\<ominus> z) = (x \<^bold>\<sqinter> y) \<^bold>\<ominus> (x \<^bold>\<sqinter> z)"
+proof -
+  have *: "(x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z) =
+        (y \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (z \<^bold>\<sqinter> x \<^bold>\<sqinter> \<^bold>- x) \<^bold>\<squnion> (x \<^bold>\<sqinter> y \<^bold>\<sqinter> \<^bold>- z) \<^bold>\<squnion> (x \<^bold>\<sqinter> \<^bold>- y \<^bold>\<sqinter> z)"
+    by (simp only: conj_cancel_right conj_zero_right disj.left_neutral)
+  then show "x \<^bold>\<sqinter> (y \<^bold>\<ominus> z) = (x \<^bold>\<sqinter> y) \<^bold>\<ominus> (x \<^bold>\<sqinter> z)"
+    by (simp (no_asm_use) only:
+        xor_def de_Morgan_disj de_Morgan_conj double_compl
+        conj_disj_distribs ac_simps)
+qed
+
+lemma conj_xor_distrib2: "(y \<^bold>\<ominus> z) \<^bold>\<sqinter> x = (y \<^bold>\<sqinter> x) \<^bold>\<ominus> (z \<^bold>\<sqinter> x)"
+  by (simp add: conj.commute conj_xor_distrib)
+
+lemmas conj_xor_distribs = conj_xor_distrib conj_xor_distrib2
+
+end
+
+
+subsection \<open>Type classes\<close>
+
+class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
+  assumes inf_compl_bot: \<open>x \<sqinter> - x = \<bottom>\<close>
+    and sup_compl_top: \<open>x \<squnion> - x = \<top>\<close>
+  assumes diff_eq: \<open>x - y = x \<sqinter> - y\<close>
+begin
+
+sublocale boolean_algebra: abstract_boolean_algebra \<open>(\<sqinter>)\<close> \<open>(\<squnion>)\<close> uminus \<bottom> \<top>
+  apply standard
+       apply (rule inf_sup_distrib1)
+      apply (rule sup_inf_distrib1)
+     apply (simp_all add: ac_simps inf_compl_bot sup_compl_top)
+  done
+
+lemma compl_inf_bot: "- x \<sqinter> x = \<bottom>"
+  by (fact boolean_algebra.conj_cancel_left)
+
+lemma compl_sup_top: "- x \<squnion> x = \<top>"
+  by (fact boolean_algebra.disj_cancel_left)
+
+lemma compl_unique:
+  assumes "x \<sqinter> y = \<bottom>"
+    and "x \<squnion> y = \<top>"
+  shows "- x = y"
+  using assms by (rule boolean_algebra.compl_unique)
+
+lemma double_compl: "- (- x) = x"
+  by (fact boolean_algebra.double_compl)
+
+lemma compl_eq_compl_iff: "- x = - y \<longleftrightarrow> x = y"
+  by (fact boolean_algebra.compl_eq_compl_iff)
+
+lemma compl_bot_eq: "- \<bottom> = \<top>"
+  by (fact boolean_algebra.compl_zero)
+
+lemma compl_top_eq: "- \<top> = \<bottom>"
+  by (fact boolean_algebra.compl_one)
+
+lemma compl_inf: "- (x \<sqinter> y) = - x \<squnion> - y"
+  by (fact boolean_algebra.de_Morgan_conj)
+
+lemma compl_sup: "- (x \<squnion> y) = - x \<sqinter> - y"
+  by (fact boolean_algebra.de_Morgan_disj)
+
+lemma compl_mono:
+  assumes "x \<le> y"
+  shows "- y \<le> - x"
+proof -
+  from assms have "x \<squnion> y = y" by (simp only: le_iff_sup)
+  then have "- (x \<squnion> y) = - y" by simp
+  then have "- x \<sqinter> - y = - y" by simp
+  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
+  then show ?thesis by (simp only: le_iff_inf)
+qed
+
+lemma compl_le_compl_iff [simp]: "- x \<le> - y \<longleftrightarrow> y \<le> x"
+  by (auto dest: compl_mono)
+
+lemma compl_le_swap1:
+  assumes "y \<le> - x"
+  shows "x \<le> -y"
+proof -
+  from assms have "- (- x) \<le> - y" by (simp only: compl_le_compl_iff)
+  then show ?thesis by simp
+qed
+
+lemma compl_le_swap2:
+  assumes "- y \<le> x"
+  shows "- x \<le> y"
+proof -
+  from assms have "- x \<le> - (- y)" by (simp only: compl_le_compl_iff)
+  then show ?thesis by simp
+qed
+
+lemma compl_less_compl_iff [simp]: "- x < - y \<longleftrightarrow> y < x"
+  by (auto simp add: less_le)
+
+lemma compl_less_swap1:
+  assumes "y < - x"
+  shows "x < - y"
+proof -
+  from assms have "- (- x) < - y" by (simp only: compl_less_compl_iff)
+  then show ?thesis by simp
+qed
+
+lemma compl_less_swap2:
+  assumes "- y < x"
+  shows "- x < y"
+proof -
+  from assms have "- x < - (- y)"
+    by (simp only: compl_less_compl_iff)
+  then show ?thesis by simp
+qed
+
+lemma sup_cancel_left1: \<open>x \<squnion> a \<squnion> (- x \<squnion> b) = \<top>\<close>
+  by (simp add: ac_simps)
+
+lemma sup_cancel_left2: \<open>- x \<squnion> a \<squnion> (x \<squnion> b) = \<top>\<close>
+  by (simp add: ac_simps)
+
+lemma inf_cancel_left1: \<open>x \<sqinter> a \<sqinter> (- x \<sqinter> b) = \<bottom>\<close>
+  by (simp add: ac_simps)
+
+lemma inf_cancel_left2: \<open>- x \<sqinter> a \<sqinter> (x \<sqinter> b) = \<bottom>\<close>
+  by (simp add: ac_simps)
+
+lemma sup_compl_top_left1 [simp]: \<open>- x \<squnion> (x \<squnion> y) = \<top>\<close>
+  by (simp add: sup_assoc [symmetric])
+
+lemma sup_compl_top_left2 [simp]: \<open>x \<squnion> (- x \<squnion> y) = \<top>\<close>
+  using sup_compl_top_left1 [of "- x" y] by simp
+
+lemma inf_compl_bot_left1 [simp]: \<open>- x \<sqinter> (x \<sqinter> y) = \<bottom>\<close>
+  by (simp add: inf_assoc [symmetric])
+
+lemma inf_compl_bot_left2 [simp]: \<open>x \<sqinter> (- x \<sqinter> y) = \<bottom>\<close>
+  using inf_compl_bot_left1 [of "- x" y] by simp
+
+lemma inf_compl_bot_right [simp]: \<open>x \<sqinter> (y \<sqinter> - x) = \<bottom>\<close>
+  by (subst inf_left_commute) simp
+
+end
+
+
+subsection \<open>Lattice on \<^typ>\<open>bool\<close>\<close>
+
+instantiation bool :: boolean_algebra
+begin
+
+definition bool_Compl_def [simp]: "uminus = Not"
+
+definition bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
+
+definition [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
+
+definition [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
+
+instance by standard auto
+
+end
+
+lemma sup_boolI1: "P \<Longrightarrow> P \<squnion> Q"
+  by simp
+
+lemma sup_boolI2: "Q \<Longrightarrow> P \<squnion> Q"
+  by simp
+
+lemma sup_boolE: "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
+  by auto
+
+instance "fun" :: (type, boolean_algebra) boolean_algebra
+  by standard (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
+
+
+subsection \<open>Lattice on unary and binary predicates\<close>
+
+lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
+  by (simp add: inf_fun_def)
+
+lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
+  by (simp add: inf_fun_def)
+
+lemma inf1E: "(A \<sqinter> B) x \<Longrightarrow> (A x \<Longrightarrow> B x \<Longrightarrow> P) \<Longrightarrow> P"
+  by (simp add: inf_fun_def)
+
+lemma inf2E: "(A \<sqinter> B) x y \<Longrightarrow> (A x y \<Longrightarrow> B x y \<Longrightarrow> P) \<Longrightarrow> P"
+  by (simp add: inf_fun_def)
+
+lemma inf1D1: "(A \<sqinter> B) x \<Longrightarrow> A x"
+  by (rule inf1E)
+
+lemma inf2D1: "(A \<sqinter> B) x y \<Longrightarrow> A x y"
+  by (rule inf2E)
+
+lemma inf1D2: "(A \<sqinter> B) x \<Longrightarrow> B x"
+  by (rule inf1E)
+
+lemma inf2D2: "(A \<sqinter> B) x y \<Longrightarrow> B x y"
+  by (rule inf2E)
+
+lemma sup1I1: "A x \<Longrightarrow> (A \<squnion> B) x"
+  by (simp add: sup_fun_def)
+
+lemma sup2I1: "A x y \<Longrightarrow> (A \<squnion> B) x y"
+  by (simp add: sup_fun_def)
+
+lemma sup1I2: "B x \<Longrightarrow> (A \<squnion> B) x"
+  by (simp add: sup_fun_def)
+
+lemma sup2I2: "B x y \<Longrightarrow> (A \<squnion> B) x y"
+  by (simp add: sup_fun_def)
+
+lemma sup1E: "(A \<squnion> B) x \<Longrightarrow> (A x \<Longrightarrow> P) \<Longrightarrow> (B x \<Longrightarrow> P) \<Longrightarrow> P"
+  by (simp add: sup_fun_def) iprover
+
+lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
+  by (simp add: sup_fun_def) iprover
+
+text \<open> \<^medskip> Classical introduction rule: no commitment to \<open>A\<close> vs \<open>B\<close>.\<close>
+
+lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
+  by (auto simp add: sup_fun_def)
+
+lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"
+  by (auto simp add: sup_fun_def)
+
+
+subsection \<open>Simproc setup\<close>
+
+locale boolean_algebra_cancel
+begin
+
+lemma sup1: "(A::'a::semilattice_sup) \<equiv> sup k a \<Longrightarrow> sup A b \<equiv> sup k (sup a b)"
+  by (simp only: ac_simps)
+
+lemma sup2: "(B::'a::semilattice_sup) \<equiv> sup k b \<Longrightarrow> sup a B \<equiv> sup k (sup a b)"
+  by (simp only: ac_simps)
+
+lemma sup0: "(a::'a::bounded_semilattice_sup_bot) \<equiv> sup a bot"
+  by simp
+
+lemma inf1: "(A::'a::semilattice_inf) \<equiv> inf k a \<Longrightarrow> inf A b \<equiv> inf k (inf a b)"
+  by (simp only: ac_simps)
+
+lemma inf2: "(B::'a::semilattice_inf) \<equiv> inf k b \<Longrightarrow> inf a B \<equiv> inf k (inf a b)"
+  by (simp only: ac_simps)
+
+lemma inf0: "(a::'a::bounded_semilattice_inf_top) \<equiv> inf a top"
+  by simp
+
+end
+
+ML_file \<open>Tools/boolean_algebra_cancel.ML\<close>
+
+simproc_setup boolean_algebra_cancel_sup ("sup a b::'a::boolean_algebra") =
+  \<open>fn phi => fn ss => try Boolean_Algebra_Cancel.cancel_sup_conv\<close>
+
+simproc_setup boolean_algebra_cancel_inf ("inf a b::'a::boolean_algebra") =
+  \<open>fn phi => fn ss => try Boolean_Algebra_Cancel.cancel_inf_conv\<close>
+
+
+context boolean_algebra
+begin
+    
+lemma shunt1: "(x \<sqinter> y \<le> z) \<longleftrightarrow> (x \<le> -y \<squnion> z)"
+proof
+  assume "x \<sqinter> y \<le> z"
+  hence  "-y \<squnion> (x \<sqinter> y) \<le> -y \<squnion> z"
+    using sup.mono by blast
+  hence "-y \<squnion> x \<le> -y \<squnion> z"
+    by (simp add: sup_inf_distrib1)
+  thus "x \<le> -y \<squnion> z"
+    by simp
+next
+  assume "x \<le> -y \<squnion> z"
+  hence "x \<sqinter> y \<le> (-y \<squnion> z) \<sqinter> y"
+    using inf_mono by auto
+  thus  "x \<sqinter> y \<le> z"
+    using inf.boundedE inf_sup_distrib2 by auto
+qed
+
+lemma shunt2: "(x \<sqinter> -y \<le> z) \<longleftrightarrow> (x \<le> y \<squnion> z)"
+  by (simp add: shunt1)
+
+lemma inf_shunt: "(x \<sqinter> y = \<bottom>) \<longleftrightarrow> (x \<le> - y)"
+  by (simp add: order.eq_iff shunt1)
+  
+lemma sup_shunt: "(x \<squnion> y = \<top>) \<longleftrightarrow> (- x \<le> y)"
+  using inf_shunt [of \<open>- x\<close> \<open>- y\<close>, symmetric] 
+  by (simp flip: compl_sup compl_top_eq)
+
+lemma diff_shunt_var: "(x - y = \<bottom>) \<longleftrightarrow> (x \<le> y)"
+  by (simp add: diff_eq inf_shunt)
+
+lemma sup_neg_inf:
+  \<open>p \<le> q \<squnion> r \<longleftrightarrow> p \<sqinter> -q \<le> r\<close>  (is \<open>?P \<longleftrightarrow> ?Q\<close>)
+proof
+  assume ?P
+  then have \<open>p \<sqinter> - q \<le> (q \<squnion> r) \<sqinter> - q\<close>
+    by (rule inf_mono) simp
+  then show ?Q
+    by (simp add: inf_sup_distrib2)
+next
+  assume ?Q
+  then have \<open>p \<sqinter> - q \<squnion> q \<le> r \<squnion> q\<close>
+    by (rule sup_mono) simp
+  then show ?P
+    by (simp add: sup_inf_distrib ac_simps)
+qed
+
+end
+
+end
--- a/src/HOL/Fun.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Fun.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -93,7 +93,7 @@
 lemma (in group_add) minus_comp_minus [simp]: "uminus \<circ> uminus = id"
   by (simp add: fun_eq_iff)
 
-lemma (in Lattices.boolean_algebra) minus_comp_minus [simp]: "uminus \<circ> uminus = id"
+lemma (in boolean_algebra) minus_comp_minus [simp]: "uminus \<circ> uminus = id"
   by (simp add: fun_eq_iff)
 
 code_printing
--- a/src/HOL/Hilbert_Choice.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Hilbert_Choice.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -1170,18 +1170,6 @@
 
 end
 
-context complete_boolean_algebra
-begin
-
-lemma dual_complete_boolean_algebra:
-  "class.complete_boolean_algebra Sup Inf sup (\<ge>) (>) inf \<top> \<bottom> (\<lambda>x y. x \<squnion> - y) uminus"
-  by (rule class.complete_boolean_algebra.intro,
-      rule dual_complete_distrib_lattice,
-      rule dual_boolean_algebra)
-end
-
-
-
 instantiation set :: (type) complete_distrib_lattice
 begin
 instance proof (standard, clarsimp)
--- a/src/HOL/Lattices.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Lattices.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -462,7 +462,7 @@
 end
 
 
-subsection \<open>Bounded lattices and boolean algebras\<close>
+subsection \<open>Bounded lattices\<close>
 
 class bounded_semilattice_inf_top = semilattice_inf + order_top
 begin
@@ -549,196 +549,6 @@
 
 end
 
-class boolean_algebra = distrib_lattice + bounded_lattice + minus + uminus +
-  assumes inf_compl_bot: "x \<sqinter> - x = \<bottom>"
-    and sup_compl_top: "x \<squnion> - x = \<top>"
-  assumes diff_eq: "x - y = x \<sqinter> - y"
-begin
-
-lemma dual_boolean_algebra:
-  "class.boolean_algebra (\<lambda>x y. x \<squnion> - y) uminus sup greater_eq greater inf \<top> \<bottom>"
-  by (rule class.boolean_algebra.intro,
-      rule dual_bounded_lattice,
-      rule dual_distrib_lattice)
-    (unfold_locales, auto simp add: inf_compl_bot sup_compl_top diff_eq)
-
-lemma compl_inf_bot [simp]: "- x \<sqinter> x = \<bottom>"
-  by (simp add: inf_commute inf_compl_bot)
-
-lemma compl_sup_top [simp]: "- x \<squnion> x = \<top>"
-  by (simp add: sup_commute sup_compl_top)
-
-lemma compl_unique:
-  assumes "x \<sqinter> y = \<bottom>"
-    and "x \<squnion> y = \<top>"
-  shows "- x = y"
-proof -
-  have "(x \<sqinter> - x) \<squnion> (- x \<sqinter> y) = (x \<sqinter> y) \<squnion> (- x \<sqinter> y)"
-    using inf_compl_bot assms(1) by simp
-  then have "(- x \<sqinter> x) \<squnion> (- x \<sqinter> y) = (y \<sqinter> x) \<squnion> (y \<sqinter> - x)"
-    by (simp add: inf_commute)
-  then have "- x \<sqinter> (x \<squnion> y) = y \<sqinter> (x \<squnion> - x)"
-    by (simp add: inf_sup_distrib1)
-  then have "- x \<sqinter> \<top> = y \<sqinter> \<top>"
-    using sup_compl_top assms(2) by simp
-  then show "- x = y" by simp
-qed
-
-lemma double_compl [simp]: "- (- x) = x"
-  using compl_inf_bot compl_sup_top by (rule compl_unique)
-
-lemma compl_eq_compl_iff [simp]: "- x = - y \<longleftrightarrow> x = y"
-proof
-  assume "- x = - y"
-  then have "- (- x) = - (- y)" by (rule arg_cong)
-  then show "x = y" by simp
-next
-  assume "x = y"
-  then show "- x = - y" by simp
-qed
-
-lemma compl_bot_eq [simp]: "- \<bottom> = \<top>"
-proof -
-  from sup_compl_top have "\<bottom> \<squnion> - \<bottom> = \<top>" .
-  then show ?thesis by simp
-qed
-
-lemma compl_top_eq [simp]: "- \<top> = \<bottom>"
-proof -
-  from inf_compl_bot have "\<top> \<sqinter> - \<top> = \<bottom>" .
-  then show ?thesis by simp
-qed
-
-lemma compl_inf [simp]: "- (x \<sqinter> y) = - x \<squnion> - y"
-proof (rule compl_unique)
-  have "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = (y \<sqinter> (x \<sqinter> - x)) \<squnion> (x \<sqinter> (y \<sqinter> - y))"
-    by (simp only: inf_sup_distrib inf_aci)
-  then show "(x \<sqinter> y) \<sqinter> (- x \<squnion> - y) = \<bottom>"
-    by (simp add: inf_compl_bot)
-next
-  have "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = (- y \<squnion> (x \<squnion> - x)) \<sqinter> (- x \<squnion> (y \<squnion> - y))"
-    by (simp only: sup_inf_distrib sup_aci)
-  then show "(x \<sqinter> y) \<squnion> (- x \<squnion> - y) = \<top>"
-    by (simp add: sup_compl_top)
-qed
-
-lemma compl_sup [simp]: "- (x \<squnion> y) = - x \<sqinter> - y"
-  using dual_boolean_algebra
-  by (rule boolean_algebra.compl_inf)
-
-lemma compl_mono:
-  assumes "x \<le> y"
-  shows "- y \<le> - x"
-proof -
-  from assms have "x \<squnion> y = y" by (simp only: le_iff_sup)
-  then have "- (x \<squnion> y) = - y" by simp
-  then have "- x \<sqinter> - y = - y" by simp
-  then have "- y \<sqinter> - x = - y" by (simp only: inf_commute)
-  then show ?thesis by (simp only: le_iff_inf)
-qed
-
-lemma compl_le_compl_iff [simp]: "- x \<le> - y \<longleftrightarrow> y \<le> x"
-  by (auto dest: compl_mono)
-
-lemma compl_le_swap1:
-  assumes "y \<le> - x"
-  shows "x \<le> -y"
-proof -
-  from assms have "- (- x) \<le> - y" by (simp only: compl_le_compl_iff)
-  then show ?thesis by simp
-qed
-
-lemma compl_le_swap2:
-  assumes "- y \<le> x"
-  shows "- x \<le> y"
-proof -
-  from assms have "- x \<le> - (- y)" by (simp only: compl_le_compl_iff)
-  then show ?thesis by simp
-qed
-
-lemma compl_less_compl_iff [simp]: "- x < - y \<longleftrightarrow> y < x"
-  by (auto simp add: less_le)
-
-lemma compl_less_swap1:
-  assumes "y < - x"
-  shows "x < - y"
-proof -
-  from assms have "- (- x) < - y" by (simp only: compl_less_compl_iff)
-  then show ?thesis by simp
-qed
-
-lemma compl_less_swap2:
-  assumes "- y < x"
-  shows "- x < y"
-proof -
-  from assms have "- x < - (- y)"
-    by (simp only: compl_less_compl_iff)
-  then show ?thesis by simp
-qed
-
-lemma sup_cancel_left1: "sup (sup x a) (sup (- x) b) = top"
-  by (simp add: ac_simps sup_compl_top)
-
-lemma sup_cancel_left2: "sup (sup (- x) a) (sup x b) = top"
-  by (simp add: ac_simps sup_compl_top)
-
-lemma inf_cancel_left1: "inf (inf x a) (inf (- x) b) = bot"
-  by (simp add: ac_simps inf_compl_bot)
-
-lemma inf_cancel_left2: "inf (inf (- x) a) (inf x b) = bot"
-  by (simp add: ac_simps inf_compl_bot)
-
-declare inf_compl_bot [simp]
-  and sup_compl_top [simp]
-
-lemma sup_compl_top_left1 [simp]: "sup (- x) (sup x y) = top"
-  by (simp add: sup_assoc[symmetric])
-
-lemma sup_compl_top_left2 [simp]: "sup x (sup (- x) y) = top"
-  using sup_compl_top_left1[of "- x" y] by simp
-
-lemma inf_compl_bot_left1 [simp]: "inf (- x) (inf x y) = bot"
-  by (simp add: inf_assoc[symmetric])
-
-lemma inf_compl_bot_left2 [simp]: "inf x (inf (- x) y) = bot"
-  using inf_compl_bot_left1[of "- x" y] by simp
-
-lemma inf_compl_bot_right [simp]: "inf x (inf y (- x)) = bot"
-  by (subst inf_left_commute) simp
-
-end
-
-locale boolean_algebra_cancel
-begin
-
-lemma sup1: "(A::'a::semilattice_sup) \<equiv> sup k a \<Longrightarrow> sup A b \<equiv> sup k (sup a b)"
-  by (simp only: ac_simps)
-
-lemma sup2: "(B::'a::semilattice_sup) \<equiv> sup k b \<Longrightarrow> sup a B \<equiv> sup k (sup a b)"
-  by (simp only: ac_simps)
-
-lemma sup0: "(a::'a::bounded_semilattice_sup_bot) \<equiv> sup a bot"
-  by simp
-
-lemma inf1: "(A::'a::semilattice_inf) \<equiv> inf k a \<Longrightarrow> inf A b \<equiv> inf k (inf a b)"
-  by (simp only: ac_simps)
-
-lemma inf2: "(B::'a::semilattice_inf) \<equiv> inf k b \<Longrightarrow> inf a B \<equiv> inf k (inf a b)"
-  by (simp only: ac_simps)
-
-lemma inf0: "(a::'a::bounded_semilattice_inf_top) \<equiv> inf a top"
-  by simp
-
-end
-
-ML_file \<open>Tools/boolean_algebra_cancel.ML\<close>
-
-simproc_setup boolean_algebra_cancel_sup ("sup a b::'a::boolean_algebra") =
-  \<open>fn phi => fn ss => try Boolean_Algebra_Cancel.cancel_sup_conv\<close>
-
-simproc_setup boolean_algebra_cancel_inf ("inf a b::'a::boolean_algebra") =
-  \<open>fn phi => fn ss => try Boolean_Algebra_Cancel.cancel_inf_conv\<close>
-
 
 subsection \<open>\<open>min/max\<close> as special case of lattice\<close>
 
@@ -853,33 +663,6 @@
 qed
 
 
-subsection \<open>Lattice on \<^typ>\<open>bool\<close>\<close>
-
-instantiation bool :: boolean_algebra
-begin
-
-definition bool_Compl_def [simp]: "uminus = Not"
-
-definition bool_diff_def [simp]: "A - B \<longleftrightarrow> A \<and> \<not> B"
-
-definition [simp]: "P \<sqinter> Q \<longleftrightarrow> P \<and> Q"
-
-definition [simp]: "P \<squnion> Q \<longleftrightarrow> P \<or> Q"
-
-instance by standard auto
-
-end
-
-lemma sup_boolI1: "P \<Longrightarrow> P \<squnion> Q"
-  by simp
-
-lemma sup_boolI2: "Q \<Longrightarrow> P \<squnion> Q"
-  by simp
-
-lemma sup_boolE: "P \<squnion> Q \<Longrightarrow> (P \<Longrightarrow> R) \<Longrightarrow> (Q \<Longrightarrow> R) \<Longrightarrow> R"
-  by auto
-
-
 subsection \<open>Lattice on \<^typ>\<open>_ \<Rightarrow> _\<close>\<close>
 
 instantiation "fun" :: (type, semilattice_sup) semilattice_sup
@@ -938,60 +721,4 @@
 
 end
 
-instance "fun" :: (type, boolean_algebra) boolean_algebra
-  by standard (rule ext, simp_all add: inf_compl_bot sup_compl_top diff_eq)+
-
-
-subsection \<open>Lattice on unary and binary predicates\<close>
-
-lemma inf1I: "A x \<Longrightarrow> B x \<Longrightarrow> (A \<sqinter> B) x"
-  by (simp add: inf_fun_def)
-
-lemma inf2I: "A x y \<Longrightarrow> B x y \<Longrightarrow> (A \<sqinter> B) x y"
-  by (simp add: inf_fun_def)
-
-lemma inf1E: "(A \<sqinter> B) x \<Longrightarrow> (A x \<Longrightarrow> B x \<Longrightarrow> P) \<Longrightarrow> P"
-  by (simp add: inf_fun_def)
-
-lemma inf2E: "(A \<sqinter> B) x y \<Longrightarrow> (A x y \<Longrightarrow> B x y \<Longrightarrow> P) \<Longrightarrow> P"
-  by (simp add: inf_fun_def)
-
-lemma inf1D1: "(A \<sqinter> B) x \<Longrightarrow> A x"
-  by (rule inf1E)
-
-lemma inf2D1: "(A \<sqinter> B) x y \<Longrightarrow> A x y"
-  by (rule inf2E)
-
-lemma inf1D2: "(A \<sqinter> B) x \<Longrightarrow> B x"
-  by (rule inf1E)
-
-lemma inf2D2: "(A \<sqinter> B) x y \<Longrightarrow> B x y"
-  by (rule inf2E)
-
-lemma sup1I1: "A x \<Longrightarrow> (A \<squnion> B) x"
-  by (simp add: sup_fun_def)
-
-lemma sup2I1: "A x y \<Longrightarrow> (A \<squnion> B) x y"
-  by (simp add: sup_fun_def)
-
-lemma sup1I2: "B x \<Longrightarrow> (A \<squnion> B) x"
-  by (simp add: sup_fun_def)
-
-lemma sup2I2: "B x y \<Longrightarrow> (A \<squnion> B) x y"
-  by (simp add: sup_fun_def)
-
-lemma sup1E: "(A \<squnion> B) x \<Longrightarrow> (A x \<Longrightarrow> P) \<Longrightarrow> (B x \<Longrightarrow> P) \<Longrightarrow> P"
-  by (simp add: sup_fun_def) iprover
-
-lemma sup2E: "(A \<squnion> B) x y \<Longrightarrow> (A x y \<Longrightarrow> P) \<Longrightarrow> (B x y \<Longrightarrow> P) \<Longrightarrow> P"
-  by (simp add: sup_fun_def) iprover
-
-text \<open> \<^medskip> Classical introduction rule: no commitment to \<open>A\<close> vs \<open>B\<close>.\<close>
-
-lemma sup1CI: "(\<not> B x \<Longrightarrow> A x) \<Longrightarrow> (A \<squnion> B) x"
-  by (auto simp add: sup_fun_def)
-
-lemma sup2CI: "(\<not> B x y \<Longrightarrow> A x y) \<Longrightarrow> (A \<squnion> B) x y"
-  by (auto simp add: sup_fun_def)
-
 end
--- a/src/HOL/Set.thy	Thu Aug 05 07:12:49 2021 +0000
+++ b/src/HOL/Set.thy	Thu Aug 05 07:12:49 2021 +0000
@@ -7,7 +7,7 @@
 section \<open>Set theory for higher-order logic\<close>
 
 theory Set
-  imports Lattices Boolean_Algebra
+  imports Lattices Boolean_Algebras
 begin
 
 subsection \<open>Sets as predicates\<close>