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 Ξ±
β’ (x \ y) \ z = 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by | rw [sdiff_sdiff_left, sdiff_sup] | theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by | Mathlib.Order.BooleanAlgebra.397_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z \ (x \ y β y \ x) = (z \ x β z β x β y) β (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]
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by | rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right] | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by | Mathlib.Order.BooleanAlgebra.400_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (z \ x β z β x β y) β (z \ y β z β y β x) = z β (z \ x β y) β (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]
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by | rw [sup_inf_left, sup_comm, sup_inf_sdiff] | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by | Mathlib.Order.BooleanAlgebra.400_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z β (z \ x β y) β (z \ y β z β y β x) = z β (z \ x β y) β (z β (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]),
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by | rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff] | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by | Mathlib.Order.BooleanAlgebra.400_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z β (z \ x β y) β (z β (z \ y β x)) = z β z β (z \ 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]),
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by | ac_rfl | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by | Mathlib.Order.BooleanAlgebra.400_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z β z β (z \ x β y) β (z \ y β x) = z β (z \ 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]),
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by | rw [inf_idem] | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by | Mathlib.Order.BooleanAlgebra.400_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z \ (x \ y) β z \ (y \ x) = (z \ x β z β x β y) β (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]
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by | rw [sdiff_sdiff_right, sdiff_sdiff_right] | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by | Mathlib.Order.BooleanAlgebra.411_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (z \ x β z β x β y) β (z \ y β z β y β x) = (z \ x β z β y β 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]
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by | ac_rfl | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by | Mathlib.Order.BooleanAlgebra.411_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ z \ x β z \ y β z β y β x = z β 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by | ac_rfl | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by | Mathlib.Order.BooleanAlgebra.411_0.ewE75DLNneOU8G5 | theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
hcb : z β€ y
β’ (x \ z) \ (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]
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
| rw [le_antisymm_iff, sdiff_le_comm] | lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
| Mathlib.Order.BooleanAlgebra.424_0.ewE75DLNneOU8G5 | lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
hcb : z β€ y
β’ (x \ z) \ (x \ y) β€ y \ z β§ 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
| exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ© | lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
| Mathlib.Order.BooleanAlgebra.424_0.ewE75DLNneOU8G5 | lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β y β z β x \ z β y \ z = (x β y β z β x \ 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by | rw [sup_inf_left] | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (x β y β z β x \ z) β (x β y β z β y \ z) = (x β y β (z β x) β x \ 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by | rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right] | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (x β y β (z β x) β x \ z) β (x β y β z β y \ z) = (y β (x β (x β z)) β x \ 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by | ac_rfl | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) = (y β x β x \ z) β (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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by | rw [inf_sup_self, sup_inf_inf_sdiff] | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (y β x β x \ z) β (x β y β y \ z) = 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by | rw [@inf_comm _ _ y, sup_inf_left] | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β y β z β (x \ z β y \ z) = x β y β (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β©
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by | ac_rfl | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β y β (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β©
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by | rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq] | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by | Mathlib.Order.BooleanAlgebra.429_0.ewE75DLNneOU8G5 | theorem inf_sdiff : (x β y) \ z = x \ z β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β y β z β x β y \ z = 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by | rw [inf_assoc] | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by | Mathlib.Order.BooleanAlgebra.444_0.ewE75DLNneOU8G5 | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β (y β z β 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]
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by | rw [sup_inf_sdiff] | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by | Mathlib.Order.BooleanAlgebra.444_0.ewE75DLNneOU8G5 | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β y β z β (x β y \ z) = x β 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by | ac_rfl | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by | Mathlib.Order.BooleanAlgebra.444_0.ewE75DLNneOU8G5 | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x β 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]
_ = (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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by | rw [inf_inf_sdiff, inf_bot_eq] | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by | Mathlib.Order.BooleanAlgebra.444_0.ewE75DLNneOU8G5 | theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x \ 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]β©
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
| rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc] | theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
| Mathlib.Order.BooleanAlgebra.455_0.ewE75DLNneOU8G5 | theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
a b c : Ξ±
β’ a β b \ c = (a β b) \ (a β c) | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
| rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc] | theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
| Mathlib.Order.BooleanAlgebra.459_0.ewE75DLNneOU8G5 | theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
a b c : Ξ±
β’ a \ b β c = (a β c) \ (b β c) | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
| simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left] | theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
| Mathlib.Order.BooleanAlgebra.463_0.ewE75DLNneOU8G5 | theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ Disjoint (x \ z) y β Disjoint 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
| simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc] | theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
| Mathlib.Order.BooleanAlgebra.467_0.ewE75DLNneOU8G5 | theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ 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])
(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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by | rw [sup_inf_left] | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by | Mathlib.Order.BooleanAlgebra.471_0.ewE75DLNneOU8G5 | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (x \ y β y \ x β x) β (x \ y β y \ x β y) = (x \ y β x β y \ x) β (x \ 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])
(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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by | ac_rfl | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by | Mathlib.Order.BooleanAlgebra.471_0.ewE75DLNneOU8G5 | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (x \ y β x β y \ x) β (x \ y β (y \ x β y)) = (x β y \ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by | rw [sup_sdiff_right, sup_sdiff_right] | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by | Mathlib.Order.BooleanAlgebra.471_0.ewE75DLNneOU8G5 | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
β’ (x β y \ x) β (x \ 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])
(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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by | rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem] | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by | Mathlib.Order.BooleanAlgebra.471_0.ewE75DLNneOU8G5 | theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : y < z \ x
hxz : 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]; 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
| rw [β sup_sdiff_cancel_right hxz] | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
| Mathlib.Order.BooleanAlgebra.480_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : y < z \ x
hxz : x β€ z
β’ x β 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
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
| refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _ | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
| Mathlib.Order.BooleanAlgebra.480_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : y < z \ x
hxz : x β€ z
h' : x β 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
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
| rw [β sdiff_idem] | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
| Mathlib.Order.BooleanAlgebra.480_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : y < z \ x
hxz : x β€ z
h' : x β z \ x β€ x β y
β’ (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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
| exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
| Mathlib.Order.BooleanAlgebra.480_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : x < z \ y
hyz : 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
| rw [β sdiff_sup_cancel hyz] | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
| Mathlib.Order.BooleanAlgebra.487_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : x < z \ y
hyz : y β€ z
β’ x β y < 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]),
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
| refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _ | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
| Mathlib.Order.BooleanAlgebra.487_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : x < z \ y
hyz : y β€ z
h' : z \ y β 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]),
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
| rw [β sdiff_idem] | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
| Mathlib.Order.BooleanAlgebra.487_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : GeneralizedBooleanAlgebra Ξ±
h : x < z \ y
hyz : y β€ z
h' : z \ y β y β€ x β 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
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
| exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
| Mathlib.Order.BooleanAlgebra.487_0.ewE75DLNneOU8G5 | theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβΒΉ : GeneralizedBooleanAlgebra Ξ±
instβ : OrderTop Ξ±
srcβΒ² : GeneralizedBooleanAlgebra Ξ± := instβΒΉ
srcβΒΉ : OrderBot Ξ± := toOrderBot
srcβ : OrderTop Ξ± := instβ
xβΒΉ xβ : Ξ±
β’ xβΒΉ \ xβ = 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
| erw [β inf_sdiff_assoc, inf_top_eq] | /-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
| Mathlib.Order.BooleanAlgebra.551_0.ewE75DLNneOU8G5 | /-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
srcβ : BooleanAlgebra Ξ± := instβ
a b : Ξ±
β’ a β b β a \ b = a | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by | rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq] | instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by | Mathlib.Order.BooleanAlgebra.600_0.ewE75DLNneOU8G5 | instance (priority | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
srcβ : BooleanAlgebra Ξ± := instβ
a b : Ξ±
β’ a β b β 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
Β· 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
| rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] | instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
| Mathlib.Order.BooleanAlgebra.600_0.ewE75DLNneOU8G5 | instance (priority | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
srcβΒΉ : BooleanAlgebra Ξ± := instβ
srcβ : GeneralizedCoheytingAlgebra Ξ± := GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra
a b c : Ξ±
β’ a β€ b β¨ c β a β b β€ c | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by | rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le] | instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by | Mathlib.Order.BooleanAlgebra.609_0.ewE75DLNneOU8G5 | instance (priority | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
srcβΒΉ : BooleanAlgebra Ξ± := instβ
srcβ : GeneralizedCoheytingAlgebra Ξ± := GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra
a : Ξ±
β’ β€ \ a = οΏ’a | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by | rw [sdiff_eq, top_inf_eq] | instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by | Mathlib.Order.BooleanAlgebra.609_0.ewE75DLNneOU8G5 | instance (priority | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
srcβΒΉ : BooleanAlgebra Ξ± := instβ
srcβ : GeneralizedCoheytingAlgebra Ξ± := GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra
a : Ξ±
β’ aαΆ = οΏ’a | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; | rfl | instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; | Mathlib.Order.BooleanAlgebra.609_0.ewE75DLNneOU8G5 | instance (priority | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : x = yαΆ
β’ IsCompl 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
| rw [h] | theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
| Mathlib.Order.BooleanAlgebra.627_0.ewE75DLNneOU8G5 | theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : x = yαΆ
β’ IsCompl 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
| exact isCompl_compl.symm | theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
| Mathlib.Order.BooleanAlgebra.627_0.ewE75DLNneOU8G5 | theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : xαΆ = y
β’ IsCompl 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
| rw [β h] | theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
| Mathlib.Order.BooleanAlgebra.633_0.ewE75DLNneOU8G5 | theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : xαΆ = y
β’ IsCompl 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
| exact isCompl_compl | theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
| Mathlib.Order.BooleanAlgebra.633_0.ewE75DLNneOU8G5 | theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
| rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl] | theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
| Mathlib.Order.BooleanAlgebra.639_0.ewE75DLNneOU8G5 | theorem compl_eq_comm : xαΆ = y β yαΆ = x | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
| rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl] | theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
| Mathlib.Order.BooleanAlgebra.643_0.ewE75DLNneOU8G5 | theorem eq_compl_comm : x = yαΆ β y = xαΆ | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : 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]
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by | have h := compl_le_compl h | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by | Mathlib.Order.BooleanAlgebra.697_0.ewE75DLNneOU8G5 | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
hβ : yαΆ β€ xαΆ
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
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; | simp at h | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; | Mathlib.Order.BooleanAlgebra.697_0.ewE75DLNneOU8G5 | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
hβ : yαΆ β€ xαΆ
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
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; | assumption | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; | Mathlib.Order.BooleanAlgebra.697_0.ewE75DLNneOU8G5 | @[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
h : 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]
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
| simpa only [compl_compl] using compl_le_compl h | theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
| Mathlib.Order.BooleanAlgebra.705_0.ewE75DLNneOU8G5 | theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ xαΆ β€ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by | simpa using le_compl_self (a := xαΆ) | @[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by | Mathlib.Order.BooleanAlgebra.713_0.ewE75DLNneOU8G5 | @[simp] theorem compl_le_self : xαΆ β€ x β x = β€ | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβΒΉ : BooleanAlgebra Ξ±
instβ : Nontrivial Ξ±
β’ xαΆ < 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
| simpa using lt_compl_self (a := xαΆ) | @[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
| Mathlib.Order.BooleanAlgebra.715_0.ewE75DLNneOU8G5 | @[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by | rw [sdiff_eq, compl_compl] | @[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by | Mathlib.Order.BooleanAlgebra.718_0.ewE75DLNneOU8G5 | @[simp]
theorem sdiff_compl : x \ yαΆ = x β y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ x β 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 _
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by | rw [β sdiff_eq, sup_inf_sdiff _ _] | @[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by | Mathlib.Order.BooleanAlgebra.732_0.ewE75DLNneOU8G5 | @[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ (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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
| rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm] | @[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
| Mathlib.Order.BooleanAlgebra.736_0.ewE75DLNneOU8G5 | @[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by | rw [sdiff_compl, sdiff_eq, inf_comm] | theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by | Mathlib.Order.BooleanAlgebra.746_0.ewE75DLNneOU8G5 | theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ Disjoint 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
| rw [β le_compl_iff_disjoint_left, compl_compl] | theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
| Mathlib.Order.BooleanAlgebra.754_0.ewE75DLNneOU8G5 | theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instβ : BooleanAlgebra Ξ±
β’ Disjoint 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
| rw [β le_compl_iff_disjoint_right, compl_compl] | theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
| Mathlib.Order.BooleanAlgebra.758_0.ewE75DLNneOU8G5 | theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y | Mathlib_Order_BooleanAlgebra |
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by | constructor | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case left
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ (x β xαΆ).1 β€ β₯.1 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> | simp | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case right
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ (x β xαΆ).2 β€ β₯.2 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> | simp | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ β€ β€ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by | constructor | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case left
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ β€.1 β€ (x β xαΆ).1 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> | simp | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case right
Ξ±β : Type u
Ξ²β : Type u_1
w xβ y z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x : Ξ± Γ Ξ²
β’ β€.2 β€ (x β xαΆ).2 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> | simp | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x y : Ξ± Γ Ξ²
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by | ext | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case a
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x y : Ξ± Γ Ξ²
β’ (x \ y).1 = (x β yαΆ).1 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> | simp [sdiff_eq] | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case a
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x y : Ξ± Γ Ξ²
β’ (x \ y).2 = (x β yαΆ).2 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> | simp [sdiff_eq] | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
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]
_ = 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by | ext | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case a
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x y : Ξ± Γ Ξ²
β’ (x β¨ y).1 = (y β xαΆ).1 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> | simp [himp_eq] | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
case a
Ξ±β : Type u
Ξ²β : Type u_1
w xβ yβ z : Ξ±β
Ξ± : Type ?u.69761
Ξ² : Type ?u.69764
instβΒΉ : BooleanAlgebra Ξ±
instβ : BooleanAlgebra Ξ²
srcβΒΉ : HeytingAlgebra (Ξ± Γ Ξ²) := heytingAlgebra
srcβ : DistribLattice (Ξ± Γ Ξ²) := distribLattice Ξ± Ξ²
x y : Ξ± Γ Ξ²
β’ (x β¨ y).2 = (y β xαΆ).2 | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> | simp [himp_eq] | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> | Mathlib.Order.BooleanAlgebra.784_0.ewE75DLNneOU8G5 | instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββ΄ : Sup Ξ±
instβΒ³ : Inf Ξ±
instβΒ² : Bot Ξ±
instβΒΉ : SDiff Ξ±
instβ : GeneralizedBooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_bot : f β₯ = β₯
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβΒΉ : GeneralizedCoheytingAlgebra Ξ± := Injective.generalizedCoheytingAlgebra f hf map_sup map_inf map_bot map_sdiff
srcβ : DistribLattice Ξ± := Injective.distribLattice f hf map_sup map_inf
a b : Ξ±
β’ f (a β b β a \ b) = f a | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by | erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff] | /-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by | Mathlib.Order.BooleanAlgebra.828_0.ewE75DLNneOU8G5 | /-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββ΄ : Sup Ξ±
instβΒ³ : Inf Ξ±
instβΒ² : Bot Ξ±
instβΒΉ : SDiff Ξ±
instβ : GeneralizedBooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_bot : f β₯ = β₯
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβΒΉ : GeneralizedCoheytingAlgebra Ξ± := Injective.generalizedCoheytingAlgebra f hf map_sup map_inf map_bot map_sdiff
srcβ : DistribLattice Ξ± := Injective.distribLattice f hf map_sup map_inf
a b : Ξ±
β’ f (a β b β a \ b) = f β₯ | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by | erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] | /-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by | Mathlib.Order.BooleanAlgebra.828_0.ewE75DLNneOU8G5 | /-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββΆ : Sup Ξ±
instββ΅ : Inf Ξ±
instββ΄ : Top Ξ±
instβΒ³ : Bot Ξ±
instβΒ² : HasCompl Ξ±
instβΒΉ : SDiff Ξ±
instβ : BooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_top : f β€ = β€
map_bot : f β₯ = β₯
map_compl : β (a : Ξ±), f aαΆ = (f a)αΆ
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβ : GeneralizedBooleanAlgebra Ξ± := Injective.generalizedBooleanAlgebra f hf map_sup map_inf map_bot map_sdiff
a : Ξ±
β’ f a β f aαΆ = f β₯ | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by | rw [map_compl, inf_compl_eq_bot, map_bot] | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by | Mathlib.Order.BooleanAlgebra.842_0.ewE75DLNneOU8G5 | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββΆ : Sup Ξ±
instββ΅ : Inf Ξ±
instββ΄ : Top Ξ±
instβΒ³ : Bot Ξ±
instβΒ² : HasCompl Ξ±
instβΒΉ : SDiff Ξ±
instβ : BooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_top : f β€ = β€
map_bot : f β₯ = β₯
map_compl : β (a : Ξ±), f aαΆ = (f a)αΆ
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβ : GeneralizedBooleanAlgebra Ξ± := Injective.generalizedBooleanAlgebra f hf map_sup map_inf map_bot map_sdiff
a : Ξ±
β’ f a β f aαΆ = f β€ | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by | rw [map_compl, sup_compl_eq_top, map_top] | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by | Mathlib.Order.BooleanAlgebra.842_0.ewE75DLNneOU8G5 | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββΆ : Sup Ξ±
instββ΅ : Inf Ξ±
instββ΄ : Top Ξ±
instβΒ³ : Bot Ξ±
instβΒ² : HasCompl Ξ±
instβΒΉ : SDiff Ξ±
instβ : BooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_top : f β€ = β€
map_bot : f β₯ = β₯
map_compl : β (a : Ξ±), f aαΆ = (f a)αΆ
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβ : GeneralizedBooleanAlgebra Ξ± := Injective.generalizedBooleanAlgebra f hf map_sup map_inf map_bot map_sdiff
a b : Ξ±
β’ a \ b = 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
Β· 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
| refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_)) | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
| Mathlib.Order.BooleanAlgebra.842_0.ewE75DLNneOU8G5 | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
instββΆ : Sup Ξ±
instββ΅ : Inf Ξ±
instββ΄ : Top Ξ±
instβΒ³ : Bot Ξ±
instβΒ² : HasCompl Ξ±
instβΒΉ : SDiff Ξ±
instβ : BooleanAlgebra Ξ²
f : Ξ± β Ξ²
hf : Injective f
map_sup : β (a b : Ξ±), f (a β b) = f a β f b
map_inf : β (a b : Ξ±), f (a β b) = f a β f b
map_top : f β€ = β€
map_bot : f β₯ = β₯
map_compl : β (a : Ξ±), f aαΆ = (f a)αΆ
map_sdiff : β (a b : Ξ±), f (a \ b) = f a \ f b
srcβ : GeneralizedBooleanAlgebra Ξ± := Injective.generalizedBooleanAlgebra f hf map_sup map_inf map_bot map_sdiff
a b : Ξ±
β’ f a β (f b)αΆ = f (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
Β· 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
| rw [map_inf, map_compl] | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
| Mathlib.Order.BooleanAlgebra.842_0.ewE75DLNneOU8G5 | /-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± | Mathlib_Order_BooleanAlgebra |
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
β’ BooleanAlgebra PUnit.{?u.90848 + 1} | /-
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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
| refine'
{ PUnit.biheytingAlgebra with
.. } | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
| Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_1
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
β’ β (x y z : PUnit.{?u.90854 + 1}), (x β y) β (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]; 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | intros | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_1
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
xβ yβ zβ : PUnit.{?u.90854 + 1}
β’ (xβ β yβ) β (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]; 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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | trivial | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_2
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
β’ β (x : PUnit.{?u.90854 + 1}), 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | intros | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_2
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
xβ : PUnit.{?u.90854 + 1}
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | trivial | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_3
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
β’ β (x : PUnit.{?u.90854 + 1}), β€ β€ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | intros | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_3
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
xβ : PUnit.{?u.90854 + 1}
β’ β€ β€ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | trivial | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_4
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
β’ β (x y : PUnit.{?u.90854 + 1}), 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | intros | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_4
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
xβ yβ : PUnit.{?u.90854 + 1}
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | trivial | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_5
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
β’ β (x y : PUnit.{?u.90854 + 1}), 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | intros | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> ( | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
case refine'_5
Ξ± : Type u
Ξ² : Type u_1
w x y z : Ξ±
srcβ : BiheytingAlgebra PUnit.{?u.90854 + 1} := biheytingAlgebra
xβ yβ : PUnit.{?u.90854 + 1}
β’ 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]
#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]
#align eq_of_sdiff_eq_sdiff eq_of_sdiff_eq_sdiff
theorem sdiff_sdiff_left' : (x \ y) \ z = x \ y β x \ z := by rw [sdiff_sdiff_left, sdiff_sup]
#align sdiff_sdiff_left' sdiff_sdiff_left'
theorem sdiff_sdiff_sup_sdiff : z \ (x \ y β y \ x) = z β (z \ x β y) β (z \ y β x) :=
calc
z \ (x \ y β y \ x) = (z \ x β z β x β y) β (z \ y β z β y β x) :=
by rw [sdiff_sup, sdiff_sdiff_right, sdiff_sdiff_right]
_ = z β (z \ x β y) β (z \ y β z β y β x) := by rw [sup_inf_left, sup_comm, sup_inf_sdiff]
_ = z β (z \ x β y) β (z β (z \ y β x)) :=
by rw [sup_inf_left, @sup_comm _ _ (z \ y), sup_inf_sdiff]
_ = z β z β (z \ x β y) β (z \ y β x) := by ac_rfl
_ = z β (z \ x β y) β (z \ y β x) := by rw [inf_idem]
#align sdiff_sdiff_sup_sdiff sdiff_sdiff_sup_sdiff
theorem sdiff_sdiff_sup_sdiff' : z \ (x \ y β y \ x) = z β x β y β z \ x β z \ y :=
calc
z \ (x \ y β y \ x) = z \ (x \ y) β z \ (y \ x) := sdiff_sup
_ = (z \ x β z β x β y) β (z \ y β z β y β x) := by rw [sdiff_sdiff_right, sdiff_sdiff_right]
_ = (z \ x β z β y β x) β (z \ y β z β y β x) := by ac_rfl
_ = z \ x β z \ y β z β y β x := sup_inf_right.symm
_ = z β x β y β z \ x β z \ y := by ac_rfl
#align sdiff_sdiff_sup_sdiff' sdiff_sdiff_sup_sdiff'
lemma sdiff_sdiff_sdiff_cancel_left (hca : z β€ x) : (x \ y) \ (x \ z) = z \ y :=
sdiff_sdiff_sdiff_le_sdiff.antisymm <|
(disjoint_sdiff_self_right.mono_left sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_right hca
lemma sdiff_sdiff_sdiff_cancel_right (hcb : z β€ y) : (x \ z) \ (y \ z) = x \ y := by
rw [le_antisymm_iff, sdiff_le_comm]
exact β¨sdiff_sdiff_sdiff_le_sdiff,
(disjoint_sdiff_self_left.mono_right sdiff_le).le_sdiff_of_le_left <| sdiff_le_sdiff_left hcbβ©
theorem inf_sdiff : (x β y) \ z = x \ z β y \ z :=
sdiff_unique
(calc
x β y β z β x \ z β y \ z = (x β y β z β x \ z) β (x β y β z β y \ z) := by rw [sup_inf_left]
_ = (x β y β (z β x) β x \ z) β (x β y β z β y \ z) :=
by rw [sup_inf_right, sup_sdiff_self_right, inf_sup_right, inf_sdiff_sup_right]
_ = (y β (x β (x β z)) β x \ z) β (x β y β z β y \ z) := by ac_rfl
_ = (y β x β x \ z) β (x β y β y \ z) := by rw [inf_sup_self, sup_inf_inf_sdiff]
_ = x β y β x \ z β y \ z := by rw [@inf_comm _ _ y, sup_inf_left]
_ = x β y := sup_eq_left.2 (inf_le_inf sdiff_le sdiff_le))
(calc
x β y β z β (x \ z β y \ z) = x β y β (z β x \ z) β y \ z := by ac_rfl
_ = β₯ := by rw [inf_sdiff_self_right, inf_bot_eq, bot_inf_eq])
#align inf_sdiff inf_sdiff
theorem inf_sdiff_assoc : (x β y) \ z = x β y \ z :=
sdiff_unique
(calc
x β y β z β x β y \ z = x β (y β z) β x β y \ z := by rw [inf_assoc]
_ = x β (y β z β y \ z) := inf_sup_left.symm
_ = x β y := by rw [sup_inf_sdiff])
(calc
x β y β z β (x β y \ z) = x β x β (y β z β y \ z) := by ac_rfl
_ = β₯ := by rw [inf_inf_sdiff, inf_bot_eq])
#align inf_sdiff_assoc inf_sdiff_assoc
theorem inf_sdiff_right_comm : x \ z β y = (x β y) \ z := by
rw [@inf_comm _ _ x, inf_comm, inf_sdiff_assoc]
#align inf_sdiff_right_comm inf_sdiff_right_comm
theorem inf_sdiff_distrib_left (a b c : Ξ±) : a β b \ c = (a β b) \ (a β c) := by
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
#align inf_sdiff_distrib_left inf_sdiff_distrib_left
theorem inf_sdiff_distrib_right (a b c : Ξ±) : a \ b β c = (a β c) \ (b β c) := by
simp_rw [@inf_comm _ _ _ c, inf_sdiff_distrib_left]
#align inf_sdiff_distrib_right inf_sdiff_distrib_right
theorem disjoint_sdiff_comm : Disjoint (x \ z) y β Disjoint x (y \ z) := by
simp_rw [disjoint_iff, inf_sdiff_right_comm, inf_sdiff_assoc]
#align disjoint_sdiff_comm disjoint_sdiff_comm
theorem sup_eq_sdiff_sup_sdiff_sup_inf : x β y = x \ y β y \ x β x β y :=
Eq.symm <|
calc
x \ y β y \ x β x β y = (x \ y β y \ x β x) β (x \ y β y \ x β y) := by rw [sup_inf_left]
_ = (x \ y β x β y \ x) β (x \ y β (y \ x β y)) := by ac_rfl
_ = (x β y \ x) β (x \ y β y) := by rw [sup_sdiff_right, sup_sdiff_right]
_ = x β y := by rw [sup_sdiff_self_right, sup_sdiff_self_left, inf_idem]
#align sup_eq_sdiff_sup_sdiff_sup_inf sup_eq_sdiff_sup_sdiff_sup_inf
theorem sup_lt_of_lt_sdiff_left (h : y < z \ x) (hxz : x β€ z) : x β y < z := by
rw [β sup_sdiff_cancel_right hxz]
refine' (sup_le_sup_left h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_left h').trans sdiff_le
#align sup_lt_of_lt_sdiff_left sup_lt_of_lt_sdiff_left
theorem sup_lt_of_lt_sdiff_right (h : x < z \ y) (hyz : y β€ z) : x β y < z := by
rw [β sdiff_sup_cancel hyz]
refine' (sup_le_sup_right h.le _).lt_of_not_le fun h' => h.not_le _
rw [β sdiff_idem]
exact (sdiff_le_sdiff_of_sup_le_sup_right h').trans sdiff_le
#align sup_lt_of_lt_sdiff_right sup_lt_of_lt_sdiff_right
instance Prod.instGeneralizedBooleanAlgebra [GeneralizedBooleanAlgebra Ξ²] :
GeneralizedBooleanAlgebra (Ξ± Γ Ξ²) where
sup_inf_sdiff _ _ := Prod.ext (sup_inf_sdiff _ _) (sup_inf_sdiff _ _)
inf_inf_sdiff _ _ := Prod.ext (inf_inf_sdiff _ _) (inf_inf_sdiff _ _)
-- Porting note:
-- Once `pi_instance` has been ported, this is just `by pi_instance`.
instance Pi.instGeneralizedBooleanAlgebra {ΞΉ : Type*} {Ξ± : ΞΉ β Type*}
[β i, GeneralizedBooleanAlgebra (Ξ± i)] : GeneralizedBooleanAlgebra (β i, Ξ± i) where
sup_inf_sdiff := fun f g => funext fun a => sup_inf_sdiff (f a) (g a)
inf_inf_sdiff := fun f g => funext fun a => inf_inf_sdiff (f a) (g a)
#align pi.generalized_boolean_algebra Pi.instGeneralizedBooleanAlgebra
end GeneralizedBooleanAlgebra
/-!
### Boolean algebras
-/
/-- A Boolean algebra is a bounded distributive lattice with a complement operator `αΆ` such that
`x β xαΆ = β₯` and `x β xαΆ = β€`. For convenience, it must also provide a set difference operation `\`
and a Heyting implication `β¨` satisfying `x \ y = x β yαΆ` and `x β¨ y = y β xαΆ`.
This is a generalization of (classical) logic of propositions, or the powerset lattice.
Since `BoundedOrder`, `OrderBot`, and `OrderTop` are mixins that require `LE`
to be present at define-time, the `extends` mechanism does not work with them.
Instead, we extend using the underlying `Bot` and `Top` data typeclasses, and replicate the
order axioms of those classes here. A "forgetful" instance back to `BoundedOrder` is provided.
-/
class BooleanAlgebra (Ξ± : Type u) extends
DistribLattice Ξ±, HasCompl Ξ±, SDiff Ξ±, HImp Ξ±, Top Ξ±, Bot Ξ± where
/-- The infimum of `x` and `xαΆ` is at most `β₯` -/
inf_compl_le_bot : β x : Ξ±, x β xαΆ β€ β₯
/-- The supremum of `x` and `xαΆ` is at least `β€` -/
top_le_sup_compl : β x : Ξ±, β€ β€ x β xαΆ
/-- `β€` is the greatest element -/
le_top : β a : Ξ±, a β€ β€
/-- `β₯` is the least element -/
bot_le : β a : Ξ±, β₯ β€ a
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff := fun x y => x β yαΆ
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp := fun x y => y β xαΆ
/-- `x \ y` is equal to `x β yαΆ` -/
sdiff_eq : β x y : Ξ±, x \ y = x β yαΆ := by aesop
/-- `x β¨ y` is equal to `y β xαΆ` -/
himp_eq : β x y : Ξ±, x β¨ y = y β xαΆ := by aesop
#align boolean_algebra BooleanAlgebra
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBoundedOrder [h : BooleanAlgebra Ξ±] : BoundedOrder Ξ± :=
{ h with }
#align boolean_algebra.to_bounded_order BooleanAlgebra.toBoundedOrder
-- See note [reducible non instances]
/-- A bounded generalized boolean algebra is a boolean algebra. -/
@[reducible]
def GeneralizedBooleanAlgebra.toBooleanAlgebra [GeneralizedBooleanAlgebra Ξ±] [OrderTop Ξ±] :
BooleanAlgebra Ξ± :=
{ βΉGeneralizedBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toOrderBot, βΉOrderTop Ξ±βΊ with
compl := fun a => β€ \ a,
inf_compl_le_bot := fun _ => disjoint_sdiff_self_right.le_bot,
top_le_sup_compl := fun _ => le_sup_sdiff,
sdiff_eq := fun _ _ => by
-- Porting note: changed `rw` to `erw` here.
-- https://github.com/leanprover-community/mathlib4/issues/5164
erw [β inf_sdiff_assoc, inf_top_eq] }
#align generalized_boolean_algebra.to_boolean_algebra GeneralizedBooleanAlgebra.toBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±]
theorem inf_compl_eq_bot' : x β xαΆ = β₯ :=
bot_unique <| BooleanAlgebra.inf_compl_le_bot x
#align inf_compl_eq_bot' inf_compl_eq_bot'
@[simp]
theorem sup_compl_eq_top : x β xαΆ = β€ :=
top_unique <| BooleanAlgebra.top_le_sup_compl x
#align sup_compl_eq_top sup_compl_eq_top
@[simp]
theorem compl_sup_eq_top : xαΆ β x = β€ :=
sup_comm.trans sup_compl_eq_top
#align compl_sup_eq_top compl_sup_eq_top
theorem isCompl_compl : IsCompl x xαΆ :=
IsCompl.of_eq inf_compl_eq_bot' sup_compl_eq_top
#align is_compl_compl isCompl_compl
theorem sdiff_eq : x \ y = x β yαΆ :=
BooleanAlgebra.sdiff_eq x y
#align sdiff_eq sdiff_eq
theorem himp_eq : x β¨ y = y β xαΆ :=
BooleanAlgebra.himp_eq x y
#align himp_eq himp_eq
instance (priority := 100) BooleanAlgebra.toComplementedLattice : ComplementedLattice Ξ± :=
β¨fun x => β¨xαΆ, isCompl_complβ©β©
#align boolean_algebra.to_complemented_lattice BooleanAlgebra.toComplementedLattice
-- see Note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toGeneralizedBooleanAlgebra :
GeneralizedBooleanAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ with
sup_inf_sdiff := fun a b => by rw [sdiff_eq, β inf_sup_left, sup_compl_eq_top, inf_top_eq],
inf_inf_sdiff := fun a b => by
rw [sdiff_eq, β inf_inf_distrib_left, inf_compl_eq_bot', inf_bot_eq] }
#align boolean_algebra.to_generalized_boolean_algebra BooleanAlgebra.toGeneralizedBooleanAlgebra
-- See note [lower instance priority]
instance (priority := 100) BooleanAlgebra.toBiheytingAlgebra : BiheytingAlgebra Ξ± :=
{ βΉBooleanAlgebra Ξ±βΊ, GeneralizedBooleanAlgebra.toGeneralizedCoheytingAlgebra with
hnot := compl,
le_himp_iff := fun a b c => by rw [himp_eq, isCompl_compl.le_sup_right_iff_inf_left_le],
himp_bot := fun _ => _root_.himp_eq.trans bot_sup_eq,
top_sdiff := fun a => by rw [sdiff_eq, top_inf_eq]; rfl }
#align boolean_algebra.to_biheyting_algebra BooleanAlgebra.toBiheytingAlgebra
@[simp]
theorem hnot_eq_compl : οΏ’x = xαΆ :=
rfl
#align hnot_eq_compl hnot_eq_compl
/- NOTE: Is this theorem needed at all or can we use `top_sdiff'`. -/
theorem top_sdiff : β€ \ x = xαΆ :=
top_sdiff' x
#align top_sdiff top_sdiff
theorem eq_compl_iff_isCompl : x = yαΆ β IsCompl x y :=
β¨fun h => by
rw [h]
exact isCompl_compl.symm, IsCompl.eq_complβ©
#align eq_compl_iff_is_compl eq_compl_iff_isCompl
theorem compl_eq_iff_isCompl : xαΆ = y β IsCompl x y :=
β¨fun h => by
rw [β h]
exact isCompl_compl, IsCompl.compl_eqβ©
#align compl_eq_iff_is_compl compl_eq_iff_isCompl
theorem compl_eq_comm : xαΆ = y β yαΆ = x := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align compl_eq_comm compl_eq_comm
theorem eq_compl_comm : x = yαΆ β y = xαΆ := by
rw [eq_comm, compl_eq_iff_isCompl, eq_compl_iff_isCompl]
#align eq_compl_comm eq_compl_comm
@[simp]
theorem compl_compl (x : Ξ±) : xαΆαΆ = x :=
(@isCompl_compl _ x _).symm.compl_eq
#align compl_compl compl_compl
theorem compl_comp_compl : compl β compl = @id Ξ± :=
funext compl_compl
#align compl_comp_compl compl_comp_compl
@[simp]
theorem compl_involutive : Function.Involutive (compl : Ξ± β Ξ±) :=
compl_compl
#align compl_involutive compl_involutive
theorem compl_bijective : Function.Bijective (compl : Ξ± β Ξ±) :=
compl_involutive.bijective
#align compl_bijective compl_bijective
theorem compl_surjective : Function.Surjective (compl : Ξ± β Ξ±) :=
compl_involutive.surjective
#align compl_surjective compl_surjective
theorem compl_injective : Function.Injective (compl : Ξ± β Ξ±) :=
compl_involutive.injective
#align compl_injective compl_injective
@[simp]
theorem compl_inj_iff : xαΆ = yαΆ β x = y :=
compl_injective.eq_iff
#align compl_inj_iff compl_inj_iff
theorem IsCompl.compl_eq_iff (h : IsCompl x y) : zαΆ = y β z = x :=
h.compl_eq βΈ compl_inj_iff
#align is_compl.compl_eq_iff IsCompl.compl_eq_iff
@[simp]
theorem compl_eq_top : xαΆ = β€ β x = β₯ :=
isCompl_bot_top.compl_eq_iff
#align compl_eq_top compl_eq_top
@[simp]
theorem compl_eq_bot : xαΆ = β₯ β x = β€ :=
isCompl_top_bot.compl_eq_iff
#align compl_eq_bot compl_eq_bot
@[simp]
theorem compl_inf : (x β y)αΆ = xαΆ β yαΆ :=
hnot_inf_distrib _ _
#align compl_inf compl_inf
@[simp]
theorem compl_le_compl_iff_le : yαΆ β€ xαΆ β x β€ y :=
β¨fun h => by have h := compl_le_compl h; simp at h; assumption, compl_le_complβ©
#align compl_le_compl_iff_le compl_le_compl_iff_le
@[simp] lemma compl_lt_compl_iff_lt : yαΆ < xαΆ β x < y :=
lt_iff_lt_of_le_iff_le' compl_le_compl_iff_le compl_le_compl_iff_le
theorem compl_le_of_compl_le (h : yαΆ β€ x) : xαΆ β€ y := by
simpa only [compl_compl] using compl_le_compl h
#align compl_le_of_compl_le compl_le_of_compl_le
theorem compl_le_iff_compl_le : xαΆ β€ y β yαΆ β€ x :=
β¨compl_le_of_compl_le, compl_le_of_compl_leβ©
#align compl_le_iff_compl_le compl_le_iff_compl_le
@[simp] theorem compl_le_self : xαΆ β€ x β x = β€ := by simpa using le_compl_self (a := xαΆ)
@[simp] theorem compl_lt_self [Nontrivial Ξ±] : xαΆ < x β x = β€ := by
simpa using lt_compl_self (a := xαΆ)
@[simp]
theorem sdiff_compl : x \ yαΆ = x β y := by rw [sdiff_eq, compl_compl]
#align sdiff_compl sdiff_compl
instance OrderDual.booleanAlgebra (Ξ±) [BooleanAlgebra Ξ±] : BooleanAlgebra Ξ±α΅α΅ :=
{ OrderDual.distribLattice Ξ±, OrderDual.boundedOrder Ξ± with
compl := fun a => toDual (ofDual aαΆ),
sdiff :=
fun a b => toDual (ofDual b β¨ ofDual a), himp := fun a b => toDual (ofDual b \ ofDual a),
inf_compl_le_bot := fun a => (@codisjoint_hnot_right _ _ (ofDual a)).top_le,
top_le_sup_compl := fun a => (@disjoint_compl_right _ _ (ofDual a)).le_bot,
sdiff_eq := fun _ _ => @himp_eq Ξ± _ _ _,
himp_eq := fun _ _ => @sdiff_eq Ξ± _ _ _, }
@[simp]
theorem sup_inf_inf_compl : x β y β x β yαΆ = x := by rw [β sdiff_eq, sup_inf_sdiff _ _]
#align sup_inf_inf_compl sup_inf_inf_compl
@[simp]
theorem compl_sdiff : (x \ y)αΆ = x β¨ y := by
rw [sdiff_eq, himp_eq, compl_inf, compl_compl, sup_comm]
#align compl_sdiff compl_sdiff
@[simp]
theorem compl_himp : (x β¨ y)αΆ = x \ y :=
@compl_sdiff Ξ±α΅α΅ _ _ _
#align compl_himp compl_himp
theorem compl_sdiff_compl : xαΆ \ yαΆ = y \ x := by rw [sdiff_compl, sdiff_eq, inf_comm]
#align compl_sdiff_compl compl_sdiff_compl
@[simp]
theorem compl_himp_compl : xαΆ β¨ yαΆ = y β¨ x :=
@compl_sdiff_compl Ξ±α΅α΅ _ _ _
#align compl_himp_compl compl_himp_compl
theorem disjoint_compl_left_iff : Disjoint xαΆ y β y β€ x := by
rw [β le_compl_iff_disjoint_left, compl_compl]
#align disjoint_compl_left_iff disjoint_compl_left_iff
theorem disjoint_compl_right_iff : Disjoint x yαΆ β x β€ y := by
rw [β le_compl_iff_disjoint_right, compl_compl]
#align disjoint_compl_right_iff disjoint_compl_right_iff
theorem codisjoint_himp_self_left : Codisjoint (x β¨ y) x :=
@disjoint_sdiff_self_left Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_left codisjoint_himp_self_left
theorem codisjoint_himp_self_right : Codisjoint x (x β¨ y) :=
@disjoint_sdiff_self_right Ξ±α΅α΅ _ _ _
#align codisjoint_himp_self_right codisjoint_himp_self_right
theorem himp_le : x β¨ y β€ z β y β€ z β§ Codisjoint x z :=
(@le_sdiff Ξ±α΅α΅ _ _ _ _).trans <| and_congr_right' $ @Codisjoint_comm _ (_) _ _ _
#align himp_le himp_le
end BooleanAlgebra
instance Prop.booleanAlgebra : BooleanAlgebra Prop :=
{ Prop.heytingAlgebra, GeneralizedHeytingAlgebra.toDistribLattice with
compl := Not,
himp_eq := fun p q => propext imp_iff_or_not,
inf_compl_le_bot := fun p β¨Hp, Hpcβ© => Hpc Hp,
top_le_sup_compl := fun p _ => Classical.em p }
#align Prop.boolean_algebra Prop.booleanAlgebra
instance Prod.booleanAlgebra (Ξ± Ξ²) [BooleanAlgebra Ξ±] [BooleanAlgebra Ξ²] :
BooleanAlgebra (Ξ± Γ Ξ²) where
__ := Prod.heytingAlgebra
__ := Prod.distribLattice Ξ± Ξ²
himp_eq x y := by ext <;> simp [himp_eq]
sdiff_eq x y := by ext <;> simp [sdiff_eq]
inf_compl_le_bot x := by constructor <;> simp
top_le_sup_compl x := by constructor <;> simp
instance Pi.booleanAlgebra {ΞΉ : Type u} {Ξ± : ΞΉ β Type v} [β i, BooleanAlgebra (Ξ± i)] :
BooleanAlgebra (β i, Ξ± i) :=
{ Pi.sdiff, Pi.heytingAlgebra, @Pi.distribLattice ΞΉ Ξ± _ with
sdiff_eq := fun _ _ => funext fun _ => sdiff_eq,
himp_eq := fun _ _ => funext fun _ => himp_eq,
inf_compl_le_bot := fun _ _ => BooleanAlgebra.inf_compl_le_bot _,
top_le_sup_compl := fun _ _ => BooleanAlgebra.top_le_sup_compl _ }
#align pi.boolean_algebra Pi.booleanAlgebra
instance Bool.instBooleanAlgebra : BooleanAlgebra Bool where
__ := Bool.linearOrder
__ := Bool.boundedOrder
__ := Bool.instDistribLattice
compl := not
inf_compl_le_bot a := a.and_not_self.le
top_le_sup_compl a := a.or_not_self.ge
@[simp]
theorem Bool.sup_eq_bor : (Β· β Β·) = or :=
rfl
#align bool.sup_eq_bor Bool.sup_eq_bor
@[simp]
theorem Bool.inf_eq_band : (Β· β Β·) = and :=
rfl
#align bool.inf_eq_band Bool.inf_eq_band
@[simp]
theorem Bool.compl_eq_bnot : HasCompl.compl = not :=
rfl
#align bool.compl_eq_bnot Bool.compl_eq_bnot
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedBooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.generalizedBooleanAlgebra [Sup Ξ±] [Inf Ξ±] [Bot Ξ±] [SDiff Ξ±]
[GeneralizedBooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_bot : f β₯ = β₯) (map_sdiff : β a b, f (a \ b) = f a \ f b) :
GeneralizedBooleanAlgebra Ξ± :=
{ hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff,
hf.distribLattice f map_sup map_inf with
sup_inf_sdiff := fun a b => hf <| by erw [map_sup, map_sdiff, map_inf, sup_inf_sdiff],
inf_inf_sdiff := fun a b => hf <| by erw [map_inf, map_sdiff, map_inf, inf_inf_sdiff, map_bot] }
#align function.injective.generalized_boolean_algebra Function.Injective.generalizedBooleanAlgebra
-- See note [reducible non-instances]
/-- Pullback a `BooleanAlgebra` along an injection. -/
@[reducible]
protected def Function.Injective.booleanAlgebra [Sup Ξ±] [Inf Ξ±] [Top Ξ±] [Bot Ξ±] [HasCompl Ξ±]
[SDiff Ξ±] [BooleanAlgebra Ξ²] (f : Ξ± β Ξ²) (hf : Injective f)
(map_sup : β a b, f (a β b) = f a β f b) (map_inf : β a b, f (a β b) = f a β f b)
(map_top : f β€ = β€) (map_bot : f β₯ = β₯) (map_compl : β a, f aαΆ = (f a)αΆ)
(map_sdiff : β a b, f (a \ b) = f a \ f b) : BooleanAlgebra Ξ± :=
{ hf.generalizedBooleanAlgebra f map_sup map_inf map_bot map_sdiff with
compl := compl,
top := β€,
le_top := fun a => (@le_top Ξ² _ _ _).trans map_top.ge,
bot_le := fun a => map_bot.le.trans bot_le,
inf_compl_le_bot :=
fun a => ((map_inf _ _).trans <| by rw [map_compl, inf_compl_eq_bot, map_bot]).le,
top_le_sup_compl :=
fun a => ((map_sup _ _).trans <| by rw [map_compl, sup_compl_eq_top, map_top]).ge,
sdiff_eq := fun a b => by
refine hf ((map_sdiff _ _).trans (sdiff_eq.trans ?_))
rw [map_inf, map_compl] }
#align function.injective.boolean_algebra Function.Injective.booleanAlgebra
end lift
instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | trivial | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit := by
refine'
{ PUnit.biheytingAlgebra with
.. } <;> (intros; | Mathlib.Order.BooleanAlgebra.865_0.ewE75DLNneOU8G5 | instance PUnit.booleanAlgebra : BooleanAlgebra PUnit | Mathlib_Order_BooleanAlgebra |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp ppred pred : Pair K
nth_s_eq : Stream'.Seq.get? g.s n = some gp
nth_conts_aux_eq : continuantsAux g n = ppred
succ_nth_conts_aux_eq : continuantsAux g (n + 1) = pred
β’ continuantsAux g (n + 2) = { a := gp.b * pred.a + gp.a * ppred.a, b := gp.b * pred.b + gp.a * ppred.b } | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by | simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator] | theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by | Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.26_0.nOytPSFGrohRR6p | theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp ppred pred : Pair K
nth_s_eq : Stream'.Seq.get? g.s n = some gp
nth_conts_aux_eq : continuantsAux g n = ppred
succ_nth_conts_aux_eq : continuantsAux g (n + 1) = pred
β’ continuants g (n + 1) = { a := gp.b * pred.a + gp.a * ppred.a, b := gp.b * pred.b + gp.a * ppred.b } | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
| simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq] | theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.33_0.nOytPSFGrohRR6p | theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp ppred pred : Pair K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
nth_conts_eq : continuants g n = ppred
succ_nth_conts_eq : continuants g (n + 1) = pred
β’ continuants g (n + 2) = { a := gp.b * pred.a + gp.a * ppred.a, b := gp.b * pred.b + gp.a * ppred.b } | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
| rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.41_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp ppred pred : Pair K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
nth_conts_eq : continuantsAux g (n + 1) = ppred
succ_nth_conts_eq : continuantsAux g (n + 1 + 1) = pred
β’ continuants g (n + 2) = { a := gp.b * pred.a + gp.a * ppred.a, b := gp.b * pred.b + gp.a * ppred.b } | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
| exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.41_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
ppredA predA : K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
nth_num_eq : numerators g n = ppredA
succ_nth_num_eq : numerators g (n + 1) = predA
β’ numerators g (n + 2) = gp.b * predA + gp.a * ppredA | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
#align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
| obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.49_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
ppredA predA : K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
nth_num_eq : numerators g n = ppredA
succ_nth_num_eq : numerators g (n + 1) = predA
β’ β conts, continuants g n = conts β§ conts.a = ppredA
case intro.intro.refl
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
predA : K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
succ_nth_num_eq : numerators g (n + 1) = predA
ppredConts : Pair K
nth_conts_eq : continuants g n = ppredConts
nth_num_eq : numerators g n = ppredConts.a
β’ numerators g (n + 2) = gp.b * predA + gp.a * ppredConts.a | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
#align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
| exact exists_conts_a_of_num nth_num_eq | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.49_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
case intro.intro.refl
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
predA : K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
succ_nth_num_eq : numerators g (n + 1) = predA
ppredConts : Pair K
nth_conts_eq : continuants g n = ppredConts
nth_num_eq : numerators g n = ppredConts.a
β’ numerators g (n + 2) = gp.b * predA + gp.a * ppredConts.a | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
#align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
| obtain β¨predConts, succ_nth_conts_eq, β¨rflβ©β© :
β conts, g.continuants (n + 1) = conts β§ conts.a = predA | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.49_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
predA : K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
succ_nth_num_eq : numerators g (n + 1) = predA
ppredConts : Pair K
nth_conts_eq : continuants g n = ppredConts
nth_num_eq : numerators g n = ppredConts.a
β’ β conts, continuants g (n + 1) = conts β§ conts.a = predA
case intro.intro.refl.intro.intro.refl
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
ppredConts : Pair K
nth_conts_eq : continuants g n = ppredConts
nth_num_eq : numerators g n = ppredConts.a
predConts : Pair K
succ_nth_conts_eq : continuants g (n + 1) = predConts
succ_nth_num_eq : numerators g (n + 1) = predConts.a
β’ numerators g (n + 2) = gp.b * predConts.a + gp.a * ppredConts.a | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
#align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
obtain β¨predConts, succ_nth_conts_eq, β¨rflβ©β© :
β conts, g.continuants (n + 1) = conts β§ conts.a = predA
| exact exists_conts_a_of_num succ_nth_num_eq | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
obtain β¨predConts, succ_nth_conts_eq, β¨rflβ©β© :
β conts, g.continuants (n + 1) = conts β§ conts.a = predA
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.49_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
case intro.intro.refl.intro.intro.refl
K : Type u_1
g : GeneralizedContinuedFraction K
n : β
instβ : DivisionRing K
gp : Pair K
succ_nth_s_eq : Stream'.Seq.get? g.s (n + 1) = some gp
ppredConts : Pair K
nth_conts_eq : continuants g n = ppredConts
nth_num_eq : numerators g n = ppredConts.a
predConts : Pair K
succ_nth_conts_eq : continuants g (n + 1) = predConts
succ_nth_num_eq : numerators g (n + 1) = predConts.a
β’ numerators g (n + 2) = gp.b * predConts.a + gp.a * ppredConts.a | /-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Translations
#align_import algebra.continued_fractions.continuants_recurrence from "leanprover-community/mathlib"@"5f11361a98ae4acd77f5c1837686f6f0102cdc25"
/-!
# Recurrence Lemmas for the `continuants` Function of Continued Fractions.
## Summary
Given a generalized continued fraction `g`, for all `n β₯ 1`, we prove that the `continuants`
function indeed satisfies the following recurrences:
- `Aβ = bβ * Aβββ + aβ * Aβββ`, and
- `Bβ = bβ * Bβββ + aβ * Bβββ`.
-/
namespace GeneralizedContinuedFraction
variable {K : Type*} {g : GeneralizedContinuedFraction K} {n : β} [DivisionRing K]
theorem continuantsAux_recurrence {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuantsAux (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© :=
by simp [*, continuantsAux, nextContinuants, nextDenominator, nextNumerator]
#align generalized_continued_fraction.continuants_aux_recurrence GeneralizedContinuedFraction.continuantsAux_recurrence
theorem continuants_recurrenceAux {gp ppred pred : Pair K} (nth_s_eq : g.s.get? n = some gp)
(nth_conts_aux_eq : g.continuantsAux n = ppred)
(succ_nth_conts_aux_eq : g.continuantsAux (n + 1) = pred) :
g.continuants (n + 1) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
simp [nth_cont_eq_succ_nth_cont_aux,
continuantsAux_recurrence nth_s_eq nth_conts_aux_eq succ_nth_conts_aux_eq]
#align generalized_continued_fraction.continuants_recurrence_aux GeneralizedContinuedFraction.continuants_recurrenceAux
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ` and `Bβ = bβ * Bβββ + aβ * Bβββ`. -/
theorem continuants_recurrence {gp ppred pred : Pair K} (succ_nth_s_eq : g.s.get? (n + 1) = some gp)
(nth_conts_eq : g.continuants n = ppred) (succ_nth_conts_eq : g.continuants (n + 1) = pred) :
g.continuants (n + 2) = β¨gp.b * pred.a + gp.a * ppred.a, gp.b * pred.b + gp.a * ppred.bβ© := by
rw [nth_cont_eq_succ_nth_cont_aux] at nth_conts_eq succ_nth_conts_eq
exact continuants_recurrenceAux succ_nth_s_eq nth_conts_eq succ_nth_conts_eq
#align generalized_continued_fraction.continuants_recurrence GeneralizedContinuedFraction.continuants_recurrence
/-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
obtain β¨predConts, succ_nth_conts_eq, β¨rflβ©β© :
β conts, g.continuants (n + 1) = conts β§ conts.a = predA
exact exists_conts_a_of_num succ_nth_num_eq
| rw [num_eq_conts_a, continuants_recurrence succ_nth_s_eq nth_conts_eq succ_nth_conts_eq] | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA := by
obtain β¨ppredConts, nth_conts_eq, β¨rflβ©β© : β conts, g.continuants n = conts β§ conts.a = ppredA
exact exists_conts_a_of_num nth_num_eq
obtain β¨predConts, succ_nth_conts_eq, β¨rflβ©β© :
β conts, g.continuants (n + 1) = conts β§ conts.a = predA
exact exists_conts_a_of_num succ_nth_num_eq
| Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence.49_0.nOytPSFGrohRR6p | /-- Shows that `Aβ = bβ * Aβββ + aβ * Aβββ`. -/
theorem numerators_recurrence {gp : Pair K} {ppredA predA : K}
(succ_nth_s_eq : g.s.get? (n + 1) = some gp) (nth_num_eq : g.numerators n = ppredA)
(succ_nth_num_eq : g.numerators (n + 1) = predA) :
g.numerators (n + 2) = gp.b * predA + gp.a * ppredA | Mathlib_Algebra_ContinuedFractions_ContinuantsRecurrence |
Subsets and Splits