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 |
Subsets and Splits