state
stringlengths
0
159k
srcUpToTactic
stringlengths
387
167k
nextTactic
stringlengths
3
9k
declUpToTactic
stringlengths
22
11.5k
declId
stringlengths
38
95
decl
stringlengths
16
1.89k
file_tag
stringlengths
17
73
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± s : z βŠ” x βŠ“ y = x \ y βŠ” x βŠ“ y i : z βŠ“ (x βŠ“ y) = x \ y βŠ“ (x βŠ“ y) ⊒ x \ y = z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i
exact (eq_of_inf_eq_sup_eq i s).symm
theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i
Mathlib.Order.BooleanAlgebra.127_0.ewE75DLNneOU8G5
theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by
rw [sup_inf_self]
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by
Mathlib.Order.BooleanAlgebra.142_0.ewE75DLNneOU8G5
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y \ x βŠ” (x βŠ” x βŠ“ y) = y βŠ“ x βŠ” y \ x βŠ” x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by
ac_rfl
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by
Mathlib.Order.BooleanAlgebra.142_0.ewE75DLNneOU8G5
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y βŠ“ x βŠ” y \ x βŠ” x = y βŠ” x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by
rw [sup_inf_sdiff]
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by
Mathlib.Order.BooleanAlgebra.142_0.ewE75DLNneOU8G5
private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ βŠ₯ = x βŠ“ y βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by
rw [inf_inf_sdiff]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y βŠ“ x \ y = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by
rw [sup_inf_sdiff]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
rw [inf_sup_left]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
ac_rfl
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
rw [inf_idem]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by
rw [inf_sup_right, @inf_comm _ _ x y]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y = x βŠ“ y \ x βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by
rw [inf_inf_sdiff, bot_sup_eq]
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ x βŠ“ x \ y = x βŠ“ x \ y βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by
ac_rfl
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ x \ y βŠ“ y \ x = x \ y βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by
rw [inf_of_le_right sdiff_le']
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by
Mathlib.Order.BooleanAlgebra.148_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by
rw [sup_inf_sdiff]
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by
Mathlib.Order.BooleanAlgebra.167_0.ewE75DLNneOU8G5
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (x βŠ“ y βŠ” x \ y) βŠ“ y \ x = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by
rw [inf_sup_right]
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by
Mathlib.Order.BooleanAlgebra.167_0.ewE75DLNneOU8G5
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by
rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq]
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by
Mathlib.Order.BooleanAlgebra.167_0.ewE75DLNneOU8G5
@[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y \ x βŠ“ x = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by
rw [inf_comm, inf_sdiff_self_right]
@[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by
Mathlib.Order.BooleanAlgebra.175_0.ewE75DLNneOU8G5
@[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x✝ y✝ z✝ : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± src✝¹ : GeneralizedBooleanAlgebra Ξ± := inst✝ src✝ : OrderBot Ξ± := toOrderBot y x z : Ξ± h : y \ x ≀ z ⊒ y \ x = x βŠ“ y \ x βŠ” z βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by
rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq]
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by
Mathlib.Order.BooleanAlgebra.180_0.ewE75DLNneOU8G5
instance (priority
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x✝ y✝ z✝ : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± src✝¹ : GeneralizedBooleanAlgebra Ξ± := inst✝ src✝ : OrderBot Ξ± := toOrderBot y x z : Ξ± h : y \ x ≀ z ⊒ y βŠ” (x βŠ” z) = y \ x βŠ” x βŠ” z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by
rw [← sup_assoc, ← @sdiff_sup_self' _ x y]
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by
Mathlib.Order.BooleanAlgebra.180_0.ewE75DLNneOU8G5
instance (priority
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x✝ y✝ z✝ : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± src✝¹ : GeneralizedBooleanAlgebra Ξ± := inst✝ src✝ : OrderBot Ξ± := toOrderBot y x z : Ξ± h : y \ x ≀ z ⊒ y \ x βŠ” x βŠ” z = x βŠ” z βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by
ac_rfl
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by
Mathlib.Order.BooleanAlgebra.180_0.ewE75DLNneOU8G5
instance (priority
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x✝ y✝ z✝ : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± src✝¹ : GeneralizedBooleanAlgebra Ξ± := inst✝ src✝ : OrderBot Ξ± := toOrderBot y x z : Ξ± h : y ≀ x βŠ” z ⊒ x βŠ” z βŠ” x ≀ z βŠ” x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by
rw [sup_assoc, sup_comm, sup_assoc, sup_idem]
instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by
Mathlib.Order.BooleanAlgebra.180_0.ewE75DLNneOU8G5
instance (priority
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : x ≀ y ∧ Disjoint x z ⊒ x ≀ y \ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by
rw [← h.2.sdiff_eq_left]
lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by
Mathlib.Order.BooleanAlgebra.217_0.ewE75DLNneOU8G5
lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : x ≀ y ∧ Disjoint x z ⊒ x \ z ≀ y \ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left];
exact sdiff_le_sdiff_right h.1
lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left];
Mathlib.Order.BooleanAlgebra.217_0.ewE75DLNneOU8G5
lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hi : Disjoint x z hs : x βŠ” z = y h : y βŠ“ x = x ⊒ y βŠ“ x βŠ” z = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by
rw [h, hs]
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by
Mathlib.Order.BooleanAlgebra.228_0.ewE75DLNneOU8G5
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hi : Disjoint x z hs : x βŠ” z = y h : y βŠ“ x = x ⊒ y βŠ“ x βŠ“ z = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by
rw [h, hi.eq_bot]
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by
Mathlib.Order.BooleanAlgebra.228_0.ewE75DLNneOU8G5
theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hd : Disjoint x z hz : z ≀ y hs : y ≀ x βŠ” z ⊒ y βŠ“ x βŠ” z = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by
rw [← inf_eq_right] at hs
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by
Mathlib.Order.BooleanAlgebra.233_0.ewE75DLNneOU8G5
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hd : Disjoint x z hz : z ≀ y hs : (x βŠ” z) βŠ“ y = y ⊒ y βŠ“ x βŠ” z = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs
rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs
Mathlib.Order.BooleanAlgebra.233_0.ewE75DLNneOU8G5
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hd : Disjoint x z hz : z ≀ y hs : y ≀ x βŠ” z ⊒ y βŠ“ x βŠ“ z = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by
rw [inf_assoc, hd.eq_bot, inf_bot_eq]
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by
Mathlib.Order.BooleanAlgebra.233_0.ewE75DLNneOU8G5
protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : Disjoint z (y \ x) ⊒ z βŠ” y \ x ≀ x βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by
rw [sup_sdiff_cancel_right hx]
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by
Mathlib.Order.BooleanAlgebra.244_0.ewE75DLNneOU8G5
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : Disjoint z (y \ x) ⊒ z βŠ” y \ x ≀ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx]
refine' le_trans (sup_le_sup_left sdiff_le z) _
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx]
Mathlib.Order.BooleanAlgebra.244_0.ewE75DLNneOU8G5
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : Disjoint z (y \ x) ⊒ z βŠ” y ≀ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _
rw [sup_eq_right.2 hz]
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _
Mathlib.Order.BooleanAlgebra.244_0.ewE75DLNneOU8G5
theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y ⊒ z βŠ“ y \ x = βŠ₯ ↔ z ≀ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by
rw [← disjoint_iff]
theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by
Mathlib.Order.BooleanAlgebra.260_0.ewE75DLNneOU8G5
theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y ⊒ Disjoint z (y \ x) ↔ z ≀ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff]
exact disjoint_sdiff_iff_le hz hx
theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff]
Mathlib.Order.BooleanAlgebra.260_0.ewE75DLNneOU8G5
theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ y = z βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by
apply le_antisymm
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ y ≀ z βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β·
conv_lhs => rw [← sup_inf_sdiff y x]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β·
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
rw [← sup_inf_sdiff y x]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
rw [← sup_inf_sdiff y x]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
rw [← sup_inf_sdiff y x]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ y βŠ“ x βŠ” y \ x ≀ z βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x]
apply sup_le_sup_right
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x]
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a.h₁ Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ y βŠ“ x ≀ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right
rwa [inf_eq_right.2 hx]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ z βŠ” y \ x ≀ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β·
apply le_trans
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β·
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a.a Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ z βŠ” y \ x ≀ ?a.b✝
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β·
apply sup_le_sup_right hz
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β·
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
case a.a Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x ≀ z ⊒ y βŠ” y \ x ≀ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β·
rw [sup_sdiff_left]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β·
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : y = z βŠ” y \ x ⊒ x ≀ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by
conv_lhs at H => rw [← sup_sdiff_cancel_right hx]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : y = z βŠ” y \ x | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
rw [← sup_sdiff_cancel_right hx]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : y = z βŠ” y \ x | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
rw [← sup_sdiff_cancel_right hx]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : y = z βŠ” y \ x | y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
rw [← sup_sdiff_cancel_right hx]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H =>
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x βŠ” y \ x = z βŠ” y \ x ⊒ x ≀ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx]
refine' le_of_inf_le_sup_le _ H.le
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx]
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x βŠ” y \ x = z βŠ” y \ x ⊒ x βŠ“ y \ x ≀ z βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le
rw [inf_sdiff_self_right]
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hz : z ≀ y hx : x ≀ y H : x βŠ” y \ x = z βŠ” y \ x ⊒ βŠ₯ ≀ z βŠ“ y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right]
exact bot_le
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right]
Mathlib.Order.BooleanAlgebra.266_0.ewE75DLNneOU8G5
theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by
rw [sup_inf_left]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by
rw [@inf_sup_left _ _ y]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by
ac_rfl
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by
rw [sup_inf_sdiff, sup_inf_sdiff]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by
ac_rfl
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by
rw [sup_inf_self, sup_inf_self, inf_idem]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by
rw [inf_sup_left]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by
rw [inf_sup_right]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by
ac_rfl
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by
rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by
Mathlib.Order.BooleanAlgebra.283_0.ewE75DLNneOU8G5
theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : y \ x = y \ z ⊒ y βŠ“ x βŠ“ ?m.20748 h = y βŠ“ z βŠ“ ?m.20748 h
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by
rw [inf_inf_sdiff, h, inf_inf_sdiff]
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by
Mathlib.Order.BooleanAlgebra.301_0.ewE75DLNneOU8G5
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : y \ x = y \ z ⊒ y βŠ“ x βŠ” y \ x = y βŠ“ z βŠ” y \ x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by
rw [sup_inf_sdiff, h, sup_inf_sdiff]
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by
Mathlib.Order.BooleanAlgebra.301_0.ewE75DLNneOU8G5
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : y βŠ“ x = y βŠ“ z ⊒ y \ x = y \ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by
rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by
Mathlib.Order.BooleanAlgebra.301_0.ewE75DLNneOU8G5
theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ y = x ↔ x \ y = x \ βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by
rw [sdiff_bot]
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by
Mathlib.Order.BooleanAlgebra.307_0.ewE75DLNneOU8G5
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y = x βŠ“ βŠ₯ ↔ Disjoint y x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by
rw [inf_bot_eq, inf_comm, disjoint_iff]
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by
Mathlib.Order.BooleanAlgebra.307_0.ewE75DLNneOU8G5
theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ y = x ↔ Disjoint x y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by
rw [sdiff_eq_self_iff_disjoint, disjoint_comm]
theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by
Mathlib.Order.BooleanAlgebra.314_0.ewE75DLNneOU8G5
theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hx : y ≀ x hy : y β‰  βŠ₯ ⊒ x \ y < x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by
refine' sdiff_le.lt_of_ne fun h => hy _
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by
Mathlib.Order.BooleanAlgebra.318_0.ewE75DLNneOU8G5
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hx : y ≀ x hy : y β‰  βŠ₯ h : x \ y = x ⊒ y = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _
rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _
Mathlib.Order.BooleanAlgebra.318_0.ewE75DLNneOU8G5
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hx : y ≀ x hy : y β‰  βŠ₯ h : x βŠ“ y = βŠ₯ ⊒ y = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h
rw [← h, inf_eq_right.mpr hx]
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h
Mathlib.Order.BooleanAlgebra.318_0.ewE75DLNneOU8G5
theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by
rw [inf_assoc]
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by
Mathlib.Order.BooleanAlgebra.334_0.ewE75DLNneOU8G5
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y βŠ“ z) βŠ” y \ z = (x βŠ” y \ z) βŠ“ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by
rw [sup_inf_right, sup_inf_sdiff]
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by
Mathlib.Order.BooleanAlgebra.334_0.ewE75DLNneOU8G5
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (x βŠ” y \ z) βŠ“ y = x βŠ“ y βŠ” y \ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by
rw [inf_sup_right, inf_sdiff_left]
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by
Mathlib.Order.BooleanAlgebra.334_0.ewE75DLNneOU8G5
theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by
rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ (y \ z) = z βŠ“ x βŠ” x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff]
apply sdiff_unique
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff]
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
case s Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β·
calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β·
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by
rw [sup_inf_right]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by
ac_rfl
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by
rw [sup_inf_self, sup_sdiff_left, ← sup_assoc]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by
rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y)
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by
rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y)))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by
ac_rfl
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by
rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) = x
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by
rw [sup_inf_self, sup_comm, inf_sup_self]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
case i Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β·
calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β·
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by
rw [inf_sup_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by
ac_rfl
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y = x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by
rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ y \ z βŠ“ x \ y = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by
conv_lhs => rw [← inf_sdiff_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± | x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
rw [← inf_sdiff_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± | x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
rw [← inf_sdiff_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± | x βŠ“ y \ z βŠ“ x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
rw [← inf_sdiff_left]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs =>
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y))
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by
ac_rfl
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) = βŠ₯
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by
rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq]
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by
Mathlib.Order.BooleanAlgebra.341_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ y βŠ” x βŠ“ y βŠ“ z = z βŠ“ x βŠ“ y βŠ” x \ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by
ac_rfl
theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by
Mathlib.Order.BooleanAlgebra.365_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ z βŠ“ x βŠ“ y βŠ” x \ y = x \ y βŠ” x βŠ“ z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by
rw [sup_inf_inf_sdiff, sup_comm, inf_comm]
theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by
Mathlib.Order.BooleanAlgebra.365_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : z ≀ x ⊒ x \ (y \ z) = x \ y βŠ” z
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] #align sdiff_sdiff_right' sdiff_sdiff_right' theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by
rw [sdiff_sdiff_right', inf_eq_right.2 h]
theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by
Mathlib.Order.BooleanAlgebra.372_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± ⊒ x \ (x \ y) = x βŠ“ y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] #align sdiff_sdiff_right' sdiff_sdiff_right' theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by rw [sdiff_sdiff_right', inf_eq_right.2 h] #align sdiff_sdiff_eq_sdiff_sup sdiff_sdiff_eq_sdiff_sup @[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y := by
rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq]
@[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y := by
Mathlib.Order.BooleanAlgebra.376_0.ewE75DLNneOU8G5
@[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± h : y ≀ x ⊒ x \ (x \ y) = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] #align sdiff_sdiff_right' sdiff_sdiff_right' theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by rw [sdiff_sdiff_right', inf_eq_right.2 h] #align sdiff_sdiff_eq_sdiff_sup sdiff_sdiff_eq_sdiff_sup @[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y := by rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq] #align sdiff_sdiff_right_self sdiff_sdiff_right_self theorem sdiff_sdiff_eq_self (h : y ≀ x) : x \ (x \ y) = y := by
rw [sdiff_sdiff_right_self, inf_of_le_right h]
theorem sdiff_sdiff_eq_self (h : y ≀ x) : x \ (x \ y) = y := by
Mathlib.Order.BooleanAlgebra.381_0.ewE75DLNneOU8G5
theorem sdiff_sdiff_eq_self (h : y ≀ x) : x \ (x \ y) = y
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hy : y ≀ x h : x \ y = z ⊒ x \ z = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] #align sdiff_sdiff_right' sdiff_sdiff_right' theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by rw [sdiff_sdiff_right', inf_eq_right.2 h] #align sdiff_sdiff_eq_sdiff_sup sdiff_sdiff_eq_sdiff_sup @[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y := by rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq] #align sdiff_sdiff_right_self sdiff_sdiff_right_self theorem sdiff_sdiff_eq_self (h : y ≀ x) : x \ (x \ y) = y := by rw [sdiff_sdiff_right_self, inf_of_le_right h] #align sdiff_sdiff_eq_self sdiff_sdiff_eq_self theorem sdiff_eq_symm (hy : y ≀ x) (h : x \ y = z) : x \ z = y := by
rw [← h, sdiff_sdiff_eq_self hy]
theorem sdiff_eq_symm (hy : y ≀ x) (h : x \ y = z) : x \ z = y := by
Mathlib.Order.BooleanAlgebra.385_0.ewE75DLNneOU8G5
theorem sdiff_eq_symm (hy : y ≀ x) (h : x \ y = z) : x \ z = y
Mathlib_Order_BooleanAlgebra
Ξ± : Type u Ξ² : Type u_1 w x y z : Ξ± inst✝ : GeneralizedBooleanAlgebra Ξ± hxz : x ≀ z hyz : y ≀ z h : z \ x = z \ y ⊒ x = y
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Bryan Gin-ge Chen -/ import Mathlib.Order.Heyting.Basic #align_import order.boolean_algebra from "leanprover-community/mathlib"@"9ac7c0c8c4d7a535ec3e5b34b8859aab9233b2f4" /-! # (Generalized) Boolean algebras A Boolean algebra is a bounded distributive lattice with a complement operator. Boolean algebras generalize the (classical) logic of propositions and the lattice of subsets of a set. Generalized Boolean algebras may be less familiar, but they are essentially Boolean algebras which do not necessarily have a top element (`⊀`) (and hence not all elements may have complements). One example in mathlib is `Finset Ξ±`, the type of all finite subsets of an arbitrary (not-necessarily-finite) type `Ξ±`. `GeneralizedBooleanAlgebra Ξ±` is defined to be a distributive lattice with bottom (`βŠ₯`) admitting a *relative* complement operator, written using "set difference" notation as `x \ y` (`sdiff x y`). For convenience, the `BooleanAlgebra` type class is defined to extend `GeneralizedBooleanAlgebra` so that it is also bundled with a `\` operator. (A terminological point: `x \ y` is the complement of `y` relative to the interval `[βŠ₯, x]`. We do not yet have relative complements for arbitrary intervals, as we do not even have lattice intervals.) ## Main declarations * `GeneralizedBooleanAlgebra`: a type class for generalized Boolean algebras * `BooleanAlgebra`: a type class for Boolean algebras. * `Prop.booleanAlgebra`: the Boolean algebra instance on `Prop` ## Implementation notes The `sup_inf_sdiff` and `inf_inf_sdiff` axioms for the relative complement operator in `GeneralizedBooleanAlgebra` are taken from [Wikipedia](https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations). [Stone's paper introducing generalized Boolean algebras][Stone1935] does not define a relative complement operator `a \ b` for all `a`, `b`. Instead, the postulates there amount to an assumption that for all `a, b : Ξ±` where `a ≀ b`, the equations `x βŠ” a = b` and `x βŠ“ a = βŠ₯` have a solution `x`. `Disjoint.sdiff_unique` proves that this `x` is in fact `b \ a`. ## References * <https://en.wikipedia.org/wiki/Boolean_algebra_(structure)#Generalizations> * [*Postulates for Boolean Algebras and Generalized Boolean Algebras*, M.H. Stone][Stone1935] * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] ## Tags generalized Boolean algebras, Boolean algebras, lattices, sdiff, compl -/ open Function OrderDual universe u v variable {Ξ± : Type u} {Ξ² : Type*} {w x y z : Ξ±} /-! ### Generalized Boolean algebras Some of the lemmas in this section are from: * [*Lattice Theory: Foundation*, George GrΓ€tzer][Gratzer2011] * <https://ncatlab.org/nlab/show/relative+complement> * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> -/ /-- A generalized Boolean algebra is a distributive lattice with `βŠ₯` and a relative complement operation `\` (called `sdiff`, after "set difference") satisfying `(a βŠ“ b) βŠ” (a \ b) = a` and `(a βŠ“ b) βŠ“ (a \ b) = βŠ₯`, i.e. `a \ b` is the complement of `b` in `a`. This is a generalization of Boolean algebras which applies to `Finset Ξ±` for arbitrary (not-necessarily-`Fintype`) `Ξ±`. -/ class GeneralizedBooleanAlgebra (Ξ± : Type u) extends DistribLattice Ξ±, SDiff Ξ±, Bot Ξ± where /-- For any `a`, `b`, `(a βŠ“ b) βŠ” (a / b) = a` -/ sup_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ” a \ b = a /-- For any `a`, `b`, `(a βŠ“ b) βŠ“ (a / b) = βŠ₯` -/ inf_inf_sdiff : βˆ€ a b : Ξ±, a βŠ“ b βŠ“ a \ b = βŠ₯ #align generalized_boolean_algebra GeneralizedBooleanAlgebra -- We might want an `IsCompl_of` predicate (for relative complements) generalizing `IsCompl`, -- however we'd need another type class for lattices with bot, and all the API for that. section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] @[simp] theorem sup_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ” x \ y = x := GeneralizedBooleanAlgebra.sup_inf_sdiff _ _ #align sup_inf_sdiff sup_inf_sdiff @[simp] theorem inf_inf_sdiff (x y : Ξ±) : x βŠ“ y βŠ“ x \ y = βŠ₯ := GeneralizedBooleanAlgebra.inf_inf_sdiff _ _ #align inf_inf_sdiff inf_inf_sdiff @[simp] theorem sup_sdiff_inf (x y : Ξ±) : x \ y βŠ” x βŠ“ y = x := by rw [sup_comm, sup_inf_sdiff] #align sup_sdiff_inf sup_sdiff_inf @[simp] theorem inf_sdiff_inf (x y : Ξ±) : x \ y βŠ“ (x βŠ“ y) = βŠ₯ := by rw [inf_comm, inf_inf_sdiff] #align inf_sdiff_inf inf_sdiff_inf -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toOrderBot : OrderBot Ξ± := { GeneralizedBooleanAlgebra.toBot with bot_le := fun a => by rw [← inf_inf_sdiff a a, inf_assoc] exact inf_le_left } #align generalized_boolean_algebra.to_order_bot GeneralizedBooleanAlgebra.toOrderBot theorem disjoint_inf_sdiff : Disjoint (x βŠ“ y) (x \ y) := disjoint_iff_inf_le.mpr (inf_inf_sdiff x y).le #align disjoint_inf_sdiff disjoint_inf_sdiff -- TODO: in distributive lattices, relative complements are unique when they exist theorem sdiff_unique (s : x βŠ“ y βŠ” z = x) (i : x βŠ“ y βŠ“ z = βŠ₯) : x \ y = z := by conv_rhs at s => rw [← sup_inf_sdiff x y, sup_comm] rw [sup_comm] at s conv_rhs at i => rw [← inf_inf_sdiff x y, inf_comm] rw [inf_comm] at i exact (eq_of_inf_eq_sup_eq i s).symm #align sdiff_unique sdiff_unique -- Use `sdiff_le` private theorem sdiff_le' : x \ y ≀ x := calc x \ y ≀ x βŠ“ y βŠ” x \ y := le_sup_right _ = x := sup_inf_sdiff x y -- Use `sdiff_sup_self` private theorem sdiff_sup_self' : y \ x βŠ” x = y βŠ” x := calc y \ x βŠ” x = y \ x βŠ” (x βŠ” x βŠ“ y) := by rw [sup_inf_self] _ = y βŠ“ x βŠ” y \ x βŠ” x := by ac_rfl _ = y βŠ” x := by rw [sup_inf_sdiff] @[simp] theorem sdiff_inf_sdiff : x \ y βŠ“ y \ x = βŠ₯ := Eq.symm <| calc βŠ₯ = x βŠ“ y βŠ“ x \ y := by rw [inf_inf_sdiff] _ = x βŠ“ (y βŠ“ x βŠ” y \ x) βŠ“ x \ y := by rw [sup_inf_sdiff] _ = (x βŠ“ (y βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_sup_left] _ = (y βŠ“ (x βŠ“ x) βŠ” x βŠ“ y \ x) βŠ“ x \ y := by ac_rfl _ = (y βŠ“ x βŠ” x βŠ“ y \ x) βŠ“ x \ y := by rw [inf_idem] _ = x βŠ“ y βŠ“ x \ y βŠ” x βŠ“ y \ x βŠ“ x \ y := by rw [inf_sup_right, @inf_comm _ _ x y] _ = x βŠ“ y \ x βŠ“ x \ y := by rw [inf_inf_sdiff, bot_sup_eq] _ = x βŠ“ x \ y βŠ“ y \ x := by ac_rfl _ = x \ y βŠ“ y \ x := by rw [inf_of_le_right sdiff_le'] #align sdiff_inf_sdiff sdiff_inf_sdiff theorem disjoint_sdiff_sdiff : Disjoint (x \ y) (y \ x) := disjoint_iff_inf_le.mpr sdiff_inf_sdiff.le #align disjoint_sdiff_sdiff disjoint_sdiff_sdiff @[simp] theorem inf_sdiff_self_right : x βŠ“ y \ x = βŠ₯ := calc x βŠ“ y \ x = (x βŠ“ y βŠ” x \ y) βŠ“ y \ x := by rw [sup_inf_sdiff] _ = x βŠ“ y βŠ“ y \ x βŠ” x \ y βŠ“ y \ x := by rw [inf_sup_right] _ = βŠ₯ := by rw [@inf_comm _ _ x y, inf_inf_sdiff, sdiff_inf_sdiff, bot_sup_eq] #align inf_sdiff_self_right inf_sdiff_self_right @[simp] theorem inf_sdiff_self_left : y \ x βŠ“ x = βŠ₯ := by rw [inf_comm, inf_sdiff_self_right] #align inf_sdiff_self_left inf_sdiff_self_left -- see Note [lower instance priority] instance (priority := 100) GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra Ξ± := { β€ΉGeneralizedBooleanAlgebra Ξ±β€Ί, GeneralizedBooleanAlgebra.toOrderBot with sdiff := (Β· \ Β·), sdiff_le_iff := fun y x z => ⟨fun h => le_of_inf_le_sup_le (le_of_eq (calc y βŠ“ y \ x = y \ x := inf_of_le_right sdiff_le' _ = x βŠ“ y \ x βŠ” z βŠ“ y \ x := by rw [inf_eq_right.2 h, inf_sdiff_self_right, bot_sup_eq] _ = (x βŠ” z) βŠ“ y \ x := inf_sup_right.symm)) (calc y βŠ” y \ x = y := sup_of_le_left sdiff_le' _ ≀ y βŠ” (x βŠ” z) := le_sup_left _ = y \ x βŠ” x βŠ” z := by rw [← sup_assoc, ← @sdiff_sup_self' _ x y] _ = x βŠ” z βŠ” y \ x := by ac_rfl), fun h => le_of_inf_le_sup_le (calc y \ x βŠ“ x = βŠ₯ := inf_sdiff_self_left _ ≀ z βŠ“ x := bot_le) (calc y \ x βŠ” x = y βŠ” x := sdiff_sup_self' _ ≀ x βŠ” z βŠ” x := sup_le_sup_right h x _ ≀ z βŠ” x := by rw [sup_assoc, sup_comm, sup_assoc, sup_idem])⟩ } #align generalized_boolean_algebra.to_generalized_coheyting_algebra GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra theorem disjoint_sdiff_self_left : Disjoint (y \ x) x := disjoint_iff_inf_le.mpr inf_sdiff_self_left.le #align disjoint_sdiff_self_left disjoint_sdiff_self_left theorem disjoint_sdiff_self_right : Disjoint x (y \ x) := disjoint_iff_inf_le.mpr inf_sdiff_self_right.le #align disjoint_sdiff_self_right disjoint_sdiff_self_right lemma le_sdiff : x ≀ y \ z ↔ x ≀ y ∧ Disjoint x z := ⟨fun h ↦ ⟨h.trans sdiff_le, disjoint_sdiff_self_left.mono_left h⟩, fun h ↦ by rw [← h.2.sdiff_eq_left]; exact sdiff_le_sdiff_right h.1⟩ #align le_sdiff le_sdiff @[simp] lemma sdiff_eq_left : x \ y = x ↔ Disjoint x y := ⟨fun h ↦ disjoint_sdiff_self_left.mono_left h.ge, Disjoint.sdiff_eq_left⟩ #align sdiff_eq_left sdiff_eq_left /- TODO: we could make an alternative constructor for `GeneralizedBooleanAlgebra` using `Disjoint x (y \ x)` and `x βŠ” (y \ x) = y` as axioms. -/ theorem Disjoint.sdiff_eq_of_sup_eq (hi : Disjoint x z) (hs : x βŠ” z = y) : y \ x = z := have h : y βŠ“ x = x := inf_eq_right.2 <| le_sup_left.trans hs.le sdiff_unique (by rw [h, hs]) (by rw [h, hi.eq_bot]) #align disjoint.sdiff_eq_of_sup_eq Disjoint.sdiff_eq_of_sup_eq protected theorem Disjoint.sdiff_unique (hd : Disjoint x z) (hz : z ≀ y) (hs : y ≀ x βŠ” z) : y \ x = z := sdiff_unique (by rw [← inf_eq_right] at hs rwa [sup_inf_right, inf_sup_right, @sup_comm _ _ x, inf_sup_self, inf_comm, @sup_comm _ _ z, hs, sup_eq_left]) (by rw [inf_assoc, hd.eq_bot, inf_bot_eq]) #align disjoint.sdiff_unique Disjoint.sdiff_unique -- cf. `IsCompl.disjoint_left_iff` and `IsCompl.disjoint_right_iff` theorem disjoint_sdiff_iff_le (hz : z ≀ y) (hx : x ≀ y) : Disjoint z (y \ x) ↔ z ≀ x := ⟨fun H => le_of_inf_le_sup_le (le_trans H.le_bot bot_le) (by rw [sup_sdiff_cancel_right hx] refine' le_trans (sup_le_sup_left sdiff_le z) _ rw [sup_eq_right.2 hz]), fun H => disjoint_sdiff_self_right.mono_left H⟩ #align disjoint_sdiff_iff_le disjoint_sdiff_iff_le -- cf. `IsCompl.le_left_iff` and `IsCompl.le_right_iff` theorem le_iff_disjoint_sdiff (hz : z ≀ y) (hx : x ≀ y) : z ≀ x ↔ Disjoint z (y \ x) := (disjoint_sdiff_iff_le hz hx).symm #align le_iff_disjoint_sdiff le_iff_disjoint_sdiff -- cf. `IsCompl.inf_left_eq_bot_iff` and `IsCompl.inf_right_eq_bot_iff` theorem inf_sdiff_eq_bot_iff (hz : z ≀ y) (hx : x ≀ y) : z βŠ“ y \ x = βŠ₯ ↔ z ≀ x := by rw [← disjoint_iff] exact disjoint_sdiff_iff_le hz hx #align inf_sdiff_eq_bot_iff inf_sdiff_eq_bot_iff -- cf. `IsCompl.left_le_iff` and `IsCompl.right_le_iff` theorem le_iff_eq_sup_sdiff (hz : z ≀ y) (hx : x ≀ y) : x ≀ z ↔ y = z βŠ” y \ x := ⟨fun H => by apply le_antisymm Β· conv_lhs => rw [← sup_inf_sdiff y x] apply sup_le_sup_right rwa [inf_eq_right.2 hx] Β· apply le_trans Β· apply sup_le_sup_right hz Β· rw [sup_sdiff_left], fun H => by conv_lhs at H => rw [← sup_sdiff_cancel_right hx] refine' le_of_inf_le_sup_le _ H.le rw [inf_sdiff_self_right] exact bot_le⟩ #align le_iff_eq_sup_sdiff le_iff_eq_sup_sdiff -- cf. `IsCompl.sup_inf` theorem sdiff_sup : y \ (x βŠ” z) = y \ x βŠ“ y \ z := sdiff_unique (calc y βŠ“ (x βŠ” z) βŠ” y \ x βŠ“ y \ z = (y βŠ“ (x βŠ” z) βŠ” y \ x) βŠ“ (y βŠ“ (x βŠ” z) βŠ” y \ z) := by rw [sup_inf_left] _ = (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ x) βŠ“ (y βŠ“ x βŠ” y βŠ“ z βŠ” y \ z) := by rw [@inf_sup_left _ _ y] _ = (y βŠ“ z βŠ” (y βŠ“ x βŠ” y \ x)) βŠ“ (y βŠ“ x βŠ” (y βŠ“ z βŠ” y \ z)) := by ac_rfl _ = (y βŠ“ z βŠ” y) βŠ“ (y βŠ“ x βŠ” y) := by rw [sup_inf_sdiff, sup_inf_sdiff] _ = (y βŠ” y βŠ“ z) βŠ“ (y βŠ” y βŠ“ x) := by ac_rfl _ = y := by rw [sup_inf_self, sup_inf_self, inf_idem]) (calc y βŠ“ (x βŠ” z) βŠ“ (y \ x βŠ“ y \ z) = (y βŠ“ x βŠ” y βŠ“ z) βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_left] _ = y βŠ“ x βŠ“ (y \ x βŠ“ y \ z) βŠ” y βŠ“ z βŠ“ (y \ x βŠ“ y \ z) := by rw [inf_sup_right] _ = y βŠ“ x βŠ“ y \ x βŠ“ y \ z βŠ” y \ x βŠ“ (y \ z βŠ“ (y βŠ“ z)) := by ac_rfl _ = βŠ₯ := by rw [inf_inf_sdiff, bot_inf_eq, bot_sup_eq, @inf_comm _ _ (y \ z), inf_inf_sdiff, inf_bot_eq]) #align sdiff_sup sdiff_sup theorem sdiff_eq_sdiff_iff_inf_eq_inf : y \ x = y \ z ↔ y βŠ“ x = y βŠ“ z := ⟨fun h => eq_of_inf_eq_sup_eq (by rw [inf_inf_sdiff, h, inf_inf_sdiff]) (by rw [sup_inf_sdiff, h, sup_inf_sdiff]), fun h => by rw [← sdiff_inf_self_right, ← sdiff_inf_self_right z y, inf_comm, h, inf_comm]⟩ #align sdiff_eq_sdiff_iff_inf_eq_inf sdiff_eq_sdiff_iff_inf_eq_inf theorem sdiff_eq_self_iff_disjoint : x \ y = x ↔ Disjoint y x := calc x \ y = x ↔ x \ y = x \ βŠ₯ := by rw [sdiff_bot] _ ↔ x βŠ“ y = x βŠ“ βŠ₯ := sdiff_eq_sdiff_iff_inf_eq_inf _ ↔ Disjoint y x := by rw [inf_bot_eq, inf_comm, disjoint_iff] #align sdiff_eq_self_iff_disjoint sdiff_eq_self_iff_disjoint theorem sdiff_eq_self_iff_disjoint' : x \ y = x ↔ Disjoint x y := by rw [sdiff_eq_self_iff_disjoint, disjoint_comm] #align sdiff_eq_self_iff_disjoint' sdiff_eq_self_iff_disjoint' theorem sdiff_lt (hx : y ≀ x) (hy : y β‰  βŠ₯) : x \ y < x := by refine' sdiff_le.lt_of_ne fun h => hy _ rw [sdiff_eq_self_iff_disjoint', disjoint_iff] at h rw [← h, inf_eq_right.mpr hx] #align sdiff_lt sdiff_lt @[simp] theorem le_sdiff_iff : x ≀ y \ x ↔ x = βŠ₯ := ⟨fun h => disjoint_self.1 (disjoint_sdiff_self_right.mono_right h), fun h => h.le.trans bot_le⟩ #align le_sdiff_iff le_sdiff_iff theorem sdiff_lt_sdiff_right (h : x < y) (hz : z ≀ x) : x \ z < y \ z := (sdiff_le_sdiff_right h.le).lt_of_not_le fun h' => h.not_le <| le_sdiff_sup.trans <| sup_le_of_le_sdiff_right h' hz #align sdiff_lt_sdiff_right sdiff_lt_sdiff_right theorem sup_inf_inf_sdiff : x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ y βŠ” y \ z := calc x βŠ“ y βŠ“ z βŠ” y \ z = x βŠ“ (y βŠ“ z) βŠ” y \ z := by rw [inf_assoc] _ = (x βŠ” y \ z) βŠ“ y := by rw [sup_inf_right, sup_inf_sdiff] _ = x βŠ“ y βŠ” y \ z := by rw [inf_sup_right, inf_sdiff_left] #align sup_inf_inf_sdiff sup_inf_inf_sdiff theorem sdiff_sdiff_right : x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := by rw [sup_comm, inf_comm, ← inf_assoc, sup_inf_inf_sdiff] apply sdiff_unique Β· calc x βŠ“ y \ z βŠ” (z βŠ“ x βŠ” x \ y) = (x βŠ” (z βŠ“ x βŠ” x \ y)) βŠ“ (y \ z βŠ” (z βŠ“ x βŠ” x \ y)) := by rw [sup_inf_right] _ = (x βŠ” x βŠ“ z βŠ” x \ y) βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x \ y)) := by ac_rfl _ = x βŠ“ (y \ z βŠ” x βŠ“ z βŠ” x \ y) := by rw [sup_inf_self, sup_sdiff_left, ← sup_assoc] _ = x βŠ“ (y \ z βŠ“ (z βŠ” y) βŠ” x βŠ“ (z βŠ” y) βŠ” x \ y) := by rw [sup_inf_left, sdiff_sup_self', inf_sup_right, @sup_comm _ _ y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” x βŠ“ y) βŠ” x \ y) := by rw [inf_sdiff_sup_right, @inf_sup_left _ _ x z y] _ = x βŠ“ (y \ z βŠ” (x βŠ“ z βŠ” (x βŠ“ y βŠ” x \ y))) := by ac_rfl _ = x βŠ“ (y \ z βŠ” (x βŠ” x βŠ“ z)) := by rw [sup_inf_sdiff, @sup_comm _ _ (x βŠ“ z)] _ = x := by rw [sup_inf_self, sup_comm, inf_sup_self] Β· calc x βŠ“ y \ z βŠ“ (z βŠ“ x βŠ” x \ y) = x βŠ“ y \ z βŠ“ (z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sup_left] _ = x βŠ“ (y \ z βŠ“ z βŠ“ x) βŠ” x βŠ“ y \ z βŠ“ x \ y := by ac_rfl _ = x βŠ“ y \ z βŠ“ x \ y := by rw [inf_sdiff_self_left, bot_inf_eq, inf_bot_eq, bot_sup_eq] _ = x βŠ“ (y \ z βŠ“ y) βŠ“ x \ y := by conv_lhs => rw [← inf_sdiff_left] _ = x βŠ“ (y \ z βŠ“ (y βŠ“ x \ y)) := by ac_rfl _ = βŠ₯ := by rw [inf_sdiff_self_right, inf_bot_eq, inf_bot_eq] #align sdiff_sdiff_right sdiff_sdiff_right theorem sdiff_sdiff_right' : x \ (y \ z) = x \ y βŠ” x βŠ“ z := calc x \ (y \ z) = x \ y βŠ” x βŠ“ y βŠ“ z := sdiff_sdiff_right _ = z βŠ“ x βŠ“ y βŠ” x \ y := by ac_rfl _ = x \ y βŠ” x βŠ“ z := by rw [sup_inf_inf_sdiff, sup_comm, inf_comm] #align sdiff_sdiff_right' sdiff_sdiff_right' theorem sdiff_sdiff_eq_sdiff_sup (h : z ≀ x) : x \ (y \ z) = x \ y βŠ” z := by rw [sdiff_sdiff_right', inf_eq_right.2 h] #align sdiff_sdiff_eq_sdiff_sup sdiff_sdiff_eq_sdiff_sup @[simp] theorem sdiff_sdiff_right_self : x \ (x \ y) = x βŠ“ y := by rw [sdiff_sdiff_right, inf_idem, sdiff_self, bot_sup_eq] #align sdiff_sdiff_right_self sdiff_sdiff_right_self theorem sdiff_sdiff_eq_self (h : y ≀ x) : x \ (x \ y) = y := by rw [sdiff_sdiff_right_self, inf_of_le_right h] #align sdiff_sdiff_eq_self sdiff_sdiff_eq_self theorem sdiff_eq_symm (hy : y ≀ x) (h : x \ y = z) : x \ z = y := by rw [← h, sdiff_sdiff_eq_self hy] #align sdiff_eq_symm sdiff_eq_symm theorem sdiff_eq_comm (hy : y ≀ x) (hz : z ≀ x) : x \ y = z ↔ x \ z = y := ⟨sdiff_eq_symm hy, sdiff_eq_symm hz⟩ #align sdiff_eq_comm sdiff_eq_comm theorem eq_of_sdiff_eq_sdiff (hxz : x ≀ z) (hyz : y ≀ z) (h : z \ x = z \ y) : x = y := by
rw [← sdiff_sdiff_eq_self hxz, h, sdiff_sdiff_eq_self hyz]
theorem eq_of_sdiff_eq_sdiff (hxz : x ≀ z) (hyz : y ≀ z) (h : z \ x = z \ y) : x = y := by
Mathlib.Order.BooleanAlgebra.393_0.ewE75DLNneOU8G5
theorem eq_of_sdiff_eq_sdiff (hxz : x ≀ z) (hyz : y ≀ z) (h : z \ x = z \ y) : x = y
Mathlib_Order_BooleanAlgebra