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 v
Ξ± : Type u_1
instβ : Sup Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_idem : β (a : Ξ±), a β a = a
a b c : Ξ±
hac : a β€ c
hbc : 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
| show (a β b) β c = c | /--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
| Mathlib.Order.Lattice.80_0.wE3igZl9MFbJBfv | /--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβ : Sup Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_idem : β (a : Ξ±), a β a = a
a b c : Ξ±
hac : a β€ c
hbc : b β€ c
β’ a β b β c = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
| rwa [sup_assoc, hbc] | /--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
| Mathlib.Order.Lattice.80_0.wE3igZl9MFbJBfv | /--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β b β€ a β§ a β€ a β b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by | simp [le_rfl] | @[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by | Mathlib.Order.Lattice.164_0.wE3igZl9MFbJBfv | @[simp]
theorem sup_eq_left : a β b = a β b β€ a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β b β€ b β§ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by | simp [le_rfl] | @[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by | Mathlib.Order.Lattice.169_0.wE3igZl9MFbJBfv | @[simp]
theorem sup_eq_right : a β b = b β a β€ b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β€ b β β c, 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
| constructor | theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
| Mathlib.Order.Lattice.207_0.wE3igZl9MFbJBfv | theorem le_iff_exists_sup : a β€ b β β c, b = a β c | Mathlib_Order_Lattice |
case mp
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β€ b β β c, 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· | intro h | theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· | Mathlib.Order.Lattice.207_0.wE3igZl9MFbJBfv | theorem le_iff_exists_sup : a β€ b β β c, b = a β c | Mathlib_Order_Lattice |
case mp
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
h : a β€ b
β’ β c, 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
| exact β¨b, (sup_eq_right.mpr h).symmβ© | theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
| Mathlib.Order.Lattice.207_0.wE3igZl9MFbJBfv | theorem le_iff_exists_sup : a β€ b β β c, b = a β c | Mathlib_Order_Lattice |
case mpr
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ (β c, b = a β c) β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· | rintro β¨c, rfl : _ = _ β _β© | theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· | Mathlib.Order.Lattice.207_0.wE3igZl9MFbJBfv | theorem le_iff_exists_sup : a β€ b β β c, b = a β c | Mathlib_Order_Lattice |
case mpr.intro
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a cβ d c : Ξ±
β’ a β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
| exact le_sup_left | theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
| Mathlib.Order.Lattice.207_0.wE3igZl9MFbJBfv | theorem le_iff_exists_sup : a β€ b β β c, b = a β c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by | simp | theorem sup_idem : a β a = a := by | Mathlib.Order.Lattice.231_0.wE3igZl9MFbJBfv | theorem sup_idem : a β a = a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β b = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by | apply le_antisymm | theorem sup_comm : a β b = b β a := by | Mathlib.Order.Lattice.237_0.wE3igZl9MFbJBfv | theorem sup_comm : a β b = b β a | Mathlib_Order_Lattice |
case a
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β b β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> | simp | theorem sup_comm : a β b = b β a := by apply le_antisymm <;> | Mathlib.Order.Lattice.237_0.wE3igZl9MFbJBfv | theorem sup_comm : a β b = b β a | Mathlib_Order_Lattice |
case a
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ b β a β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> | simp | theorem sup_comm : a β b = b β a := by apply le_antisymm <;> | Mathlib.Order.Lattice.237_0.wE3igZl9MFbJBfv | theorem sup_comm : a β b = b β a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d x : Ξ±
β’ a β b β c β€ x β a β (b β c) β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by | simp only [sup_le_iff] | theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by | Mathlib.Order.Lattice.243_0.wE3igZl9MFbJBfv | theorem sup_assoc : a β b β c = a β (b β c) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d x : Ξ±
β’ (a β€ x β§ b β€ x) β§ c β€ x β a β€ x β§ b β€ x β§ c β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; | rw [and_assoc] | theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; | Mathlib.Order.Lattice.243_0.wE3igZl9MFbJBfv | theorem sup_assoc : a β b β c = a β (b β c) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d a b c : Ξ±
β’ a β b β c = c β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
| rw [sup_comm, @sup_comm _ _ a, sup_assoc] | theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
| Mathlib.Order.Lattice.250_0.wE3igZl9MFbJBfv | theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by | simp | theorem sup_left_idem : a β (a β b) = a β b := by | Mathlib.Order.Lattice.255_0.wE3igZl9MFbJBfv | theorem sup_left_idem : a β (a β b) = a β b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
a b c d : Ξ±
β’ a β b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by | simp | theorem sup_right_idem : a β b β b = a β b := by | Mathlib.Order.Lattice.259_0.wE3igZl9MFbJBfv | theorem sup_right_idem : a β b β b = a β b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d a b c : Ξ±
β’ a β (b β c) = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
| rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a] | theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
| Mathlib.Order.Lattice.262_0.wE3igZl9MFbJBfv | theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d a b c : Ξ±
β’ a β b β c = a β c β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
| rw [sup_assoc, sup_assoc, @sup_comm _ _ b] | theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
| Mathlib.Order.Lattice.266_0.wE3igZl9MFbJBfv | theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ dβ a b c d : Ξ±
β’ a β b β (c β d) = a β c β (b β d) | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
| rw [sup_assoc, sup_left_comm b, β sup_assoc] | theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
| Mathlib.Order.Lattice.270_0.wE3igZl9MFbJBfv | theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
| rw [sup_sup_sup_comm, sup_idem] | theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
| Mathlib.Order.Lattice.274_0.wE3igZl9MFbJBfv | theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±
aβ bβ cβ d 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
| rw [sup_sup_sup_comm, sup_idem] | theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
| Mathlib.Order.Lattice.278_0.wE3igZl9MFbJBfv | theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b cβ d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
x y c : Ξ±
β’ x β y β€ c β x β y β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by | simp only [sup_le_iff] | theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by | Mathlib.Order.Lattice.311_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b cβ d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
x y c : Ξ±
β’ x β y β€ c β x β€ c β§ y β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; | rw [β H, @sup_le_iff Ξ± A, H, H] | theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; | Mathlib.Order.Lattice.311_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
β’ toSup = toSup | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by | ext | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by | Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case sup.h.h
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; | apply SemilatticeSup.ext_sup H | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; | Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeSup Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toSup = toSup
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
| cases A | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
| Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
B : SemilatticeSup Ξ±
toSupβ : Sup Ξ±
toPartialOrderβ : PartialOrder Ξ±
le_sup_leftβ : β (a b : Ξ±), a β€ a β b
le_sup_rightβ : β (a b : Ξ±), b β€ a β b
sup_leβ : β (a b c : Ξ±), a β€ c β b β€ c β a β b β€ c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toSup = toSup
β’ mk le_sup_leftβ le_sup_rightβ sup_leβ = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
| cases B | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
| Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toSupβΒΉ : Sup Ξ±
toPartialOrderβΒΉ : PartialOrder Ξ±
le_sup_leftβΒΉ : β (a b : Ξ±), a β€ a β b
le_sup_rightβΒΉ : β (a b : Ξ±), b β€ a β b
sup_leβΒΉ : β (a b c : Ξ±), a β€ c β b β€ c β a β b β€ c
toSupβ : Sup Ξ±
toPartialOrderβ : PartialOrder Ξ±
le_sup_leftβ : β (a b : Ξ±), a β€ a β b
le_sup_rightβ : β (a b : Ξ±), b β€ a β b
sup_leβ : β (a b c : Ξ±), a β€ c β b β€ c β a β b β€ c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toSup = toSup
β’ mk le_sup_leftβΒΉ le_sup_rightβΒΉ sup_leβΒΉ = mk le_sup_leftβ le_sup_rightβ sup_leβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
| cases PartialOrder.ext H | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
| Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk.refl
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeSup Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toSupβΒΉ : Sup Ξ±
toPartialOrderβ : PartialOrder Ξ±
le_sup_leftβΒΉ : β (a b : Ξ±), a β€ a β b
le_sup_rightβΒΉ : β (a b : Ξ±), b β€ a β b
sup_leβΒΉ : β (a b c : Ξ±), a β€ c β b β€ c β a β b β€ c
toSupβ : Sup Ξ±
le_sup_leftβ : β (a b : Ξ±), a β€ a β b
le_sup_rightβ : β (a b : Ξ±), b β€ a β b
sup_leβ : β (a b c : Ξ±), a β€ c β b β€ c β a β b β€ c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toSup = toSup
β’ mk le_sup_leftβΒΉ le_sup_rightβΒΉ sup_leβΒΉ = mk le_sup_leftβ le_sup_rightβ sup_leβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
| congr | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
| Mathlib.Order.Lattice.318_0.wE3igZl9MFbJBfv | theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±
a b c d : Ξ±
β’ a β b β€ a β§ a β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by | simp [le_rfl] | @[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by | Mathlib.Order.Lattice.421_0.wE3igZl9MFbJBfv | @[simp]
theorem inf_eq_left : a β b = a β a β€ b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±
a b c d : Ξ±
β’ a β b β€ b β§ b β€ a β b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by | simp [le_rfl] | @[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by | Mathlib.Order.Lattice.426_0.wE3igZl9MFbJBfv | @[simp]
theorem inf_eq_right : a β b = b β b β€ a | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b cβ d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
x y c : Ξ±
β’ c β€ x β y β c β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by | simp only [le_inf_iff] | theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by | Mathlib.Order.Lattice.555_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b cβ d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
x y c : Ξ±
β’ c β€ x β y β c β€ x β§ c β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; | rw [β H, @le_inf_iff Ξ± A, H, H] | theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; | Mathlib.Order.Lattice.555_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
β’ toInf = toInf | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by | ext | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by | Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case inf.h.h
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; | apply SemilatticeInf.ext_inf H | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; | Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : SemilatticeInf Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toInf = toInf
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
| cases A | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
| Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
B : SemilatticeInf Ξ±
toInfβ : Inf Ξ±
toPartialOrderβ : PartialOrder Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toInf = toInf
β’ mk inf_le_leftβ inf_le_rightβ le_infβ = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
| cases B | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
| Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toInfβΒΉ : Inf Ξ±
toPartialOrderβΒΉ : PartialOrder Ξ±
inf_le_leftβΒΉ : β (a b : Ξ±), a β b β€ a
inf_le_rightβΒΉ : β (a b : Ξ±), a β b β€ b
le_infβΒΉ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
toInfβ : Inf Ξ±
toPartialOrderβ : PartialOrder Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toInf = toInf
β’ mk inf_le_leftβΒΉ inf_le_rightβΒΉ le_infβΒΉ = mk inf_le_leftβ inf_le_rightβ le_infβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
| cases PartialOrder.ext H | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
| Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk.refl
Ξ±β : Type u
Ξ² : Type v
instβ : SemilatticeInf Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toInfβΒΉ : Inf Ξ±
toPartialOrderβ : PartialOrder Ξ±
inf_le_leftβΒΉ : β (a b : Ξ±), a β b β€ a
inf_le_rightβΒΉ : β (a b : Ξ±), a β b β€ b
le_infβΒΉ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
toInfβ : Inf Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
ss : toInf = toInf
β’ mk inf_le_leftβΒΉ inf_le_rightβΒΉ le_infβΒΉ = mk inf_le_leftβ inf_le_rightβ le_infβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
| congr | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
| Mathlib.Order.Lattice.562_0.wE3igZl9MFbJBfv | theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβ : Inf Ξ±
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_idem : β (a : Ξ±), a β a = a
β’ SemilatticeInf Ξ± | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
| haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
| Mathlib.Order.Lattice.583_0.wE3igZl9MFbJBfv | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβ : Inf Ξ±
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_idem : β (a : Ξ±), a β a = a
this : SemilatticeSup Ξ±α΅α΅
β’ SemilatticeInf Ξ± | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
| haveI i := OrderDual.semilatticeInf Ξ±α΅α΅ | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
| Mathlib.Order.Lattice.583_0.wE3igZl9MFbJBfv | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβ : Inf Ξ±
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_idem : β (a : Ξ±), a β a = a
this : SemilatticeSup Ξ±α΅α΅
i : SemilatticeInf Ξ±α΅α΅α΅α΅
β’ SemilatticeInf Ξ± | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
| exact i | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
| Mathlib.Order.Lattice.583_0.wE3igZl9MFbJBfv | /--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_idem : β (a : Ξ±), a β a = a
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_idem : β (a : Ξ±), a β a = a
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
a b : Ξ±
h : a β b = b
β’ b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by | rw [β h, inf_comm, inf_sup_self] | /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by | Mathlib.Order.Lattice.609_0.wE3igZl9MFbJBfv | /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_idem : β (a : Ξ±), a β a = a
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_idem : β (a : Ξ±), a β a = a
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
a b : Ξ±
h : b β a = a
β’ a β b = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by | rw [β h, sup_comm, sup_inf_self] | /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by | Mathlib.Order.Lattice.609_0.wE3igZl9MFbJBfv | /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
b : Ξ±
β’ b β b = b β b β (b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by | rw [inf_sup_self] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by | Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
b : Ξ±
β’ b β b β (b β b) = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by | rw [sup_inf_self] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by | Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
b : Ξ±
β’ b β b = b β (b β b β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by | rw [sup_inf_self] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by | Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
b : Ξ±
β’ b β (b β b β b) = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by | rw [inf_sup_self] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by | Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
| rw [partial_order_eq] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
| apply inf_le_left | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
a b : Ξ±
β’ a β b β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
| rw [partial_order_eq] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
a b : Ξ±
β’ a β b β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
| apply inf_le_right | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
a b c : Ξ±
β’ a β€ b β a β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
| rw [partial_order_eq] | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
Ξ± : Type u_1
instβΒΉ : Sup Ξ±
instβ : Inf Ξ±
sup_comm : β (a b : Ξ±), a β b = b β a
sup_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
inf_comm : β (a b : Ξ±), a β b = b β a
inf_assoc : β (a b c : Ξ±), a β b β c = a β (b β c)
sup_inf_self : β (a b : Ξ±), a β a β b = a
inf_sup_self : β (a b : Ξ±), a β (a β b) = a
sup_idem : β (b : Ξ±), b β b = b
inf_idem : β (b : Ξ±), b β b = b
semilatt_inf_inst : SemilatticeInf Ξ± := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
semilatt_sup_inst : SemilatticeSup Ξ± := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
partial_order_eq : SemilatticeSup.toPartialOrder = SemilatticeInf.toPartialOrder
a b c : Ξ±
β’ a β€ b β a β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
| apply le_inf | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
| Mathlib.Order.Lattice.625_0.wE3igZl9MFbJBfv | /-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by | simp [le_antisymm_iff, and_comm] | theorem sup_le_inf : a β b β€ a β b β a = b := by | Mathlib.Order.Lattice.671_0.wE3igZl9MFbJBfv | theorem sup_le_inf : a β b β€ a β b β a = b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by | rw [β inf_le_sup.ge_iff_eq, sup_le_inf] | @[simp] lemma inf_eq_sup : a β b = a β b β a = b := by | Mathlib.Order.Lattice.674_0.wE3igZl9MFbJBfv | @[simp] lemma inf_eq_sup : a β b = a β b β a = b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by | rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup] | @[simp] lemma inf_lt_sup : a β b < a β b β a β b := by | Mathlib.Order.Lattice.678_0.wE3igZl9MFbJBfv | @[simp] lemma inf_lt_sup : a β b < a β b β a β b | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
| refine' β¨fun h β¦ _, _β© | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
| Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_1
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
h : a β b = c β§ a β b = c
β’ a = c β§ b = c
case refine'_2 Ξ± : Type u Ξ² : Type v instβ : Lattice Ξ± a b c d : Ξ± β’ a = c β§ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
| { obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h } | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
| Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_1
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
h : 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ | obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm) | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ | Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_1
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a c d : Ξ±
h : a β a = c β§ a β a = c
β’ a = c β§ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
| simpa using h | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
| Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_2
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ a = c β§ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
| { rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© } | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
| Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_2
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ a = c β§ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ | rintro β¨rfl, rflβ© | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ | Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
case refine'_2.intro
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
b d : Ξ±
β’ b β b = b β§ b β b = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
| exact β¨inf_idem, sup_idemβ© | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
| Mathlib.Order.Lattice.681_0.wE3igZl9MFbJBfv | lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ a β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by | simp | theorem inf_sup_self : a β (a β b) = a := by | Mathlib.Order.Lattice.703_0.wE3igZl9MFbJBfv | theorem inf_sup_self : a β (a β b) = a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ a β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by | simp | theorem sup_inf_self : a β a β b = a := by | Mathlib.Order.Lattice.706_0.wE3igZl9MFbJBfv | theorem sup_inf_self : a β a β b = a | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : Lattice Ξ±
a b c d : Ξ±
β’ a β b = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by | rw [sup_eq_right, β inf_eq_left] | theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by | Mathlib.Order.Lattice.709_0.wE3igZl9MFbJBfv | theorem sup_eq_iff_inf_eq : a β b = b β a β b = a | Mathlib_Order_Lattice |
Ξ±β : Type u
Ξ² : Type v
instβ : Lattice Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
A B : Lattice Ξ±
H : β (x y : Ξ±), x β€ y β x β€ y
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| cases A | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
| Mathlib.Order.Lattice.712_0.wE3igZl9MFbJBfv | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk
Ξ±β : Type u
Ξ² : Type v
instβ : Lattice Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
B : Lattice Ξ±
toSemilatticeSupβ : SemilatticeSup Ξ±
toInfβ : Inf Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
β’ mk inf_le_leftβ inf_le_rightβ le_infβ = 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
| cases B | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
| Mathlib.Order.Lattice.712_0.wE3igZl9MFbJBfv | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk
Ξ±β : Type u
Ξ² : Type v
instβ : Lattice Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toSemilatticeSupβΒΉ : SemilatticeSup Ξ±
toInfβΒΉ : Inf Ξ±
inf_le_leftβΒΉ : β (a b : Ξ±), a β b β€ a
inf_le_rightβΒΉ : β (a b : Ξ±), a β b β€ b
le_infβΒΉ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
toSemilatticeSupβ : SemilatticeSup Ξ±
toInfβ : Inf Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
β’ mk inf_le_leftβΒΉ inf_le_rightβΒΉ le_infβΒΉ = mk inf_le_leftβ inf_le_rightβ le_infβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
| cases SemilatticeSup.ext H | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
| Mathlib.Order.Lattice.712_0.wE3igZl9MFbJBfv | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk.refl
Ξ±β : Type u
Ξ² : Type v
instβ : Lattice Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toSemilatticeSupβ : SemilatticeSup Ξ±
toInfβΒΉ : Inf Ξ±
inf_le_leftβΒΉ : β (a b : Ξ±), a β b β€ a
inf_le_rightβΒΉ : β (a b : Ξ±), a β b β€ b
le_infβΒΉ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
toInfβ : Inf Ξ±
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
β’ mk inf_le_leftβΒΉ inf_le_rightβΒΉ le_infβΒΉ = mk inf_le_leftβ inf_le_rightβ le_infβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
| cases SemilatticeInf.ext H | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
| Mathlib.Order.Lattice.712_0.wE3igZl9MFbJBfv | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
case mk.mk.refl.refl
Ξ±β : Type u
Ξ² : Type v
instβ : Lattice Ξ±β
a b c d : Ξ±β
Ξ± : Type u_1
toSemilatticeSupβ : SemilatticeSup Ξ±
toInfβ : Inf Ξ±
inf_le_leftβΒΉ : β (a b : Ξ±), a β b β€ a
inf_le_rightβΒΉ : β (a b : Ξ±), a β b β€ b
le_infβΒΉ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
inf_le_leftβ : β (a b : Ξ±), a β b β€ a
inf_le_rightβ : β (a b : Ξ±), a β b β€ b
le_infβ : β (a b c : Ξ±), a β€ b β a β€ c β a β€ b β c
H : β (x y : Ξ±), x β€ y β x β€ y
β’ mk inf_le_leftβΒΉ inf_le_rightβΒΉ le_infβΒΉ = mk inf_le_leftβ inf_le_rightβ le_infβ | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
| congr | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
| Mathlib.Order.Lattice.712_0.wE3igZl9MFbJBfv | theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ y β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
| simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true] | theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
| Mathlib.Order.Lattice.756_0.wE3igZl9MFbJBfv | theorem sup_inf_right : y β z β x = (y β x) β (z β x) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ x β (y β z) = x β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by | rw [inf_sup_self] | theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by | Mathlib.Order.Lattice.760_0.wE3igZl9MFbJBfv | theorem inf_sup_left : x β (y β z) = x β y β x β z | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ x β (x β z) β (y β z) = x β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by | simp only [inf_assoc, sup_inf_right, eq_self_iff_true] | theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by | Mathlib.Order.Lattice.760_0.wE3igZl9MFbJBfv | theorem inf_sup_left : x β (y β z) = x β y β x β z | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ x β (x β y β z) = (x β x β y) β (x β y β z) | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by | rw [sup_inf_self] | theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by | Mathlib.Order.Lattice.760_0.wE3igZl9MFbJBfv | theorem inf_sup_left : x β (y β z) = x β y β x β z | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ (x β x β y) β (x β y β z) = (x β y β x) β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by | rw [sup_comm] | theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by | Mathlib.Order.Lattice.760_0.wE3igZl9MFbJBfv | theorem inf_sup_left : x β (y β z) = x β y β x β z | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ (x β y β x) β (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by | rw [sup_inf_left] | theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by | Mathlib.Order.Lattice.760_0.wE3igZl9MFbJBfv | theorem inf_sup_left : x β (y β z) = x β y β x β z | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
β’ (y β 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
| simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true] | theorem inf_sup_right : (y β z) β x = y β x β z β x := by
| Mathlib.Order.Lattice.773_0.wE3igZl9MFbJBfv | theorem inf_sup_right : (y β z) β x = y β x β z β x | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : DistribLattice Ξ±
x y z : Ξ±
hβ : x β z β€ y β z
hβ : x β z β€ y β z
β’ y β z β x = (y β x) β (x β z) | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by | rw [sup_inf_right, @sup_comm _ _ x] | theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by | Mathlib.Order.Lattice.777_0.wE3igZl9MFbJBfv | theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
aβ bβ c d a b : Ξ±
p : Ξ± β Prop
ha : p a
hb : p b
h : a β€ b
β’ p (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by | rwa [sup_eq_right.2 h] | theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by | Mathlib.Order.Lattice.830_0.wE3igZl9MFbJBfv | theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
aβ bβ c d a b : Ξ±
p : Ξ± β Prop
ha : p a
hb : p b
h : b β€ a
β’ p (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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
| rwa [sup_eq_left.2 h] | theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
| Mathlib.Order.Lattice.830_0.wE3igZl9MFbJBfv | theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
| exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ© | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
| Mathlib.Order.Lattice.835_0.wE3igZl9MFbJBfv | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
h : a β€ b β c
bc : c β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by | rwa [sup_eq_left.2 bc] at h | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by | Mathlib.Order.Lattice.835_0.wE3igZl9MFbJBfv | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
h : a β€ b β c
bc : b β€ c
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by | rwa [sup_eq_right.2 bc] at h | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by | Mathlib.Order.Lattice.835_0.wE3igZl9MFbJBfv | @[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
| exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ© | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
| Mathlib.Order.Lattice.844_0.wE3igZl9MFbJBfv | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
h : a < b β c
bc : c β€ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by | rwa [sup_eq_left.2 bc] at h | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by | Mathlib.Order.Lattice.844_0.wE3igZl9MFbJBfv | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβ : LinearOrder Ξ±
a b c d : Ξ±
h : a < b β c
bc : b β€ c
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by | rwa [sup_eq_right.2 bc] at h | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by | Mathlib.Order.Lattice.844_0.wE3igZl9MFbJBfv | @[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeSup Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
β’ (fun x x_1 => x β x_1) = maxDefault | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
| ext x y | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
| Mathlib.Order.Lattice.891_0.wE3igZl9MFbJBfv | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case h.h
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeSup Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
β’ x β y = maxDefault 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
| unfold maxDefault | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
| Mathlib.Order.Lattice.891_0.wE3igZl9MFbJBfv | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case h.h
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeSup Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
β’ x β y = if x β€ y then y else 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
| split_ifs with h' | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
| Mathlib.Order.Lattice.891_0.wE3igZl9MFbJBfv | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case pos
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeSup Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
h' : x β€ y
β’ x β y = y
case neg
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeSup Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
h' : Β¬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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
| exacts [sup_of_le_right h', sup_of_le_left $ (total_of (Β· β€ Β·) x y).resolve_left h'] | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
| Mathlib.Order.Lattice.891_0.wE3igZl9MFbJBfv | theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeInf Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
β’ (fun x x_1 => x β x_1) = minDefault | /-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
exacts [sup_of_le_right h', sup_of_le_left $ (total_of (Β· β€ Β·) x y).resolve_left h']
#align sup_eq_max_default sup_eq_maxDefault
theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
| ext x y | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
| Mathlib.Order.Lattice.900_0.wE3igZl9MFbJBfv | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case h.h
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeInf Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
β’ x β y = minDefault 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
exacts [sup_of_le_right h', sup_of_le_left $ (total_of (Β· β€ Β·) x y).resolve_left h']
#align sup_eq_max_default sup_eq_maxDefault
theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
| unfold minDefault | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
| Mathlib.Order.Lattice.900_0.wE3igZl9MFbJBfv | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case h.h
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeInf Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
β’ x β y = if x β€ y then x else 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
exacts [sup_of_le_right h', sup_of_le_left $ (total_of (Β· β€ Β·) x y).resolve_left h']
#align sup_eq_max_default sup_eq_maxDefault
theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold minDefault
| split_ifs with h' | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold minDefault
| Mathlib.Order.Lattice.900_0.wE3igZl9MFbJBfv | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
case pos
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeInf Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
h' : x β€ y
β’ x β y = x
case neg
Ξ± : Type u
Ξ² : Type v
instβΒ² : SemilatticeInf Ξ±
instβΒΉ : DecidableRel fun x x_1 => x β€ x_1
instβ : IsTotal Ξ± fun x x_1 => x β€ x_1
x y : Ξ±
h' : Β¬x β€ y
β’ 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
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Init.Order.Defs
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.Core
#align_import order.lattice from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c"
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (greatest lower bound, or `sup`) or
meet (least upper bound, or `inf`) operations. Lattices are posets that are both
join-semilattices and meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `β` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `β` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `β` and `β` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a β b`: the supremum or join of `a` and `b`
* `a β b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v}
#align le_antisymm' le_antisymm
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`β` which is the least element larger than both factors. -/
class SemilatticeSup (Ξ± : Type u) extends Sup Ξ±, PartialOrder Ξ± where
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : β a b : Ξ±, a β€ a β b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : β a b : Ξ±, b β€ a β b
/-- The supremum is the *least* upper bound -/
protected sup_le : β a b c : Ξ±, a β€ c β b β€ c β a β b β€ c
#align semilattice_sup SemilatticeSup
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {Ξ± : Type*} [Sup Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_idem : β a : Ξ±, a β a = a) :
SemilatticeSup Ξ± where
sup := (Β· β Β·)
le a b := a β b = b
le_refl := sup_idem
le_trans a b c hab hbc := by
-- Porting note: dsimp doesn't work here?
-- This is the same issue as discussed at https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/unfolding.20earlier.20fields
show a β c = c
rw [β hbc, β sup_assoc, hab]
le_antisymm a b hab hba := by
rwa [β hba, sup_comm]
le_sup_left a b := show a β (a β b) = a β b by rw [β sup_assoc, sup_idem]
le_sup_right a b := show b β (a β b) = a β b by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by
show (a β b) β c = c
rwa [sup_assoc, hbc]
#align semilattice_sup.mk' SemilatticeSup.mk'
instance instSupOrderDual (Ξ± : Type*) [Inf Ξ±] : Sup Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
instance instInfOrderDual (Ξ± : Type*) [Sup Ξ±] : Inf Ξ±α΅α΅ :=
β¨((Β· β Β·) : Ξ± β Ξ± β Ξ±)β©
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c d : Ξ±}
@[simp]
theorem le_sup_left : a β€ a β b :=
SemilatticeSup.le_sup_left a b
#align le_sup_left le_sup_left
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_left' : a β€ a β b :=
le_sup_left
#align le_sup_left' le_sup_left'
@[simp]
theorem le_sup_right : b β€ a β b :=
SemilatticeSup.le_sup_right a b
#align le_sup_right le_sup_right
-- Porting note: no ematch attribute
--@[ematch]
theorem le_sup_right' : b β€ a β b :=
le_sup_right
#align le_sup_right' le_sup_right'
theorem le_sup_of_le_left (h : c β€ a) : c β€ a β b :=
le_trans h le_sup_left
#align le_sup_of_le_left le_sup_of_le_left
theorem le_sup_of_le_right (h : c β€ b) : c β€ a β b :=
le_trans h le_sup_right
#align le_sup_of_le_right le_sup_of_le_right
theorem lt_sup_of_lt_left (h : c < a) : c < a β b :=
h.trans_le le_sup_left
#align lt_sup_of_lt_left lt_sup_of_lt_left
theorem lt_sup_of_lt_right (h : c < b) : c < a β b :=
h.trans_le le_sup_right
#align lt_sup_of_lt_right lt_sup_of_lt_right
theorem sup_le : a β€ c β b β€ c β a β b β€ c :=
SemilatticeSup.sup_le a b c
#align sup_le sup_le
@[simp]
theorem sup_le_iff : a β b β€ c β a β€ c β§ b β€ c :=
β¨fun h : a β b β€ c => β¨le_trans le_sup_left h, le_trans le_sup_right hβ©,
fun β¨hβ, hββ© => sup_le hβ hββ©
#align sup_le_iff sup_le_iff
@[simp]
theorem sup_eq_left : a β b = a β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_left sup_eq_left
@[simp]
theorem sup_eq_right : a β b = b β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align sup_eq_right sup_eq_right
@[simp]
theorem left_eq_sup : a = a β b β b β€ a :=
eq_comm.trans sup_eq_left
#align left_eq_sup left_eq_sup
@[simp]
theorem right_eq_sup : b = a β b β a β€ b :=
eq_comm.trans sup_eq_right
#align right_eq_sup right_eq_sup
alias β¨_, sup_of_le_leftβ© := sup_eq_left
#align sup_of_le_left sup_of_le_left
alias β¨le_of_sup_eq, sup_of_le_rightβ© := sup_eq_right
#align sup_of_le_right sup_of_le_right
#align le_of_sup_eq le_of_sup_eq
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a β b β Β¬b β€ a :=
le_sup_left.lt_iff_ne.trans $ not_congr left_eq_sup
#align left_lt_sup left_lt_sup
@[simp]
theorem right_lt_sup : b < a β b β Β¬a β€ b :=
le_sup_right.lt_iff_ne.trans $ not_congr right_eq_sup
#align right_lt_sup right_lt_sup
theorem left_or_right_lt_sup (h : a β b) : a < a β b β¨ b < a β b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
#align left_or_right_lt_sup left_or_right_lt_sup
theorem le_iff_exists_sup : a β€ b β β c, b = a β c := by
constructor
Β· intro h
exact β¨b, (sup_eq_right.mpr h).symmβ©
Β· rintro β¨c, rfl : _ = _ β _β©
exact le_sup_left
#align le_iff_exists_sup le_iff_exists_sup
@[gcongr]
theorem sup_le_sup (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
sup_le (le_sup_of_le_left hβ) (le_sup_of_le_right hβ)
#align sup_le_sup sup_le_sup
@[gcongr]
theorem sup_le_sup_left (hβ : a β€ b) (c) : c β a β€ c β b :=
sup_le_sup le_rfl hβ
#align sup_le_sup_left sup_le_sup_left
@[gcongr]
theorem sup_le_sup_right (hβ : a β€ b) (c) : a β c β€ b β c :=
sup_le_sup hβ le_rfl
#align sup_le_sup_right sup_le_sup_right
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_idem : a β a = a := by simp
#align sup_idem sup_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@sup_idem _ _β©
theorem sup_comm : a β b = b β a := by apply le_antisymm <;> simp
#align sup_comm sup_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@sup_comm _ _β©
theorem sup_assoc : a β b β c = a β (b β c) :=
eq_of_forall_ge_iff $ fun x => by simp only [sup_le_iff]; rw [and_assoc]
#align sup_assoc sup_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@sup_assoc _ _β©
theorem sup_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a := by
rw [sup_comm, @sup_comm _ _ a, sup_assoc]
#align sup_left_right_swap sup_left_right_swap
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_left_idem : a β (a β b) = a β b := by simp
#align sup_left_idem sup_left_idem
-- Porting note: was @[simp], but now proved by simp so not needed.
theorem sup_right_idem : a β b β b = a β b := by simp
#align sup_right_idem sup_right_idem
theorem sup_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) := by
rw [β sup_assoc, β sup_assoc, @sup_comm Ξ± _ a]
#align sup_left_comm sup_left_comm
theorem sup_right_comm (a b c : Ξ±) : a β b β c = a β c β b := by
rw [sup_assoc, sup_assoc, @sup_comm _ _ b]
#align sup_right_comm sup_right_comm
theorem sup_sup_sup_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) := by
rw [sup_assoc, sup_left_comm b, β sup_assoc]
#align sup_sup_sup_comm sup_sup_sup_comm
theorem sup_sup_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_left sup_sup_distrib_left
theorem sup_sup_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) := by
rw [sup_sup_sup_comm, sup_idem]
#align sup_sup_distrib_right sup_sup_distrib_right
theorem sup_congr_left (hb : b β€ a β c) (hc : c β€ a β b) : a β b = a β c :=
(sup_le le_sup_left hb).antisymm $ sup_le le_sup_left hc
#align sup_congr_left sup_congr_left
theorem sup_congr_right (ha : a β€ b β c) (hb : b β€ a β c) : a β c = b β c :=
(sup_le ha le_sup_right).antisymm $ sup_le hb le_sup_right
#align sup_congr_right sup_congr_right
theorem sup_eq_sup_iff_left : a β b = a β c β b β€ a β c β§ c β€ a β b :=
β¨fun h => β¨h βΈ le_sup_right, h.symm βΈ le_sup_rightβ©, fun h => sup_congr_left h.1 h.2β©
#align sup_eq_sup_iff_left sup_eq_sup_iff_left
theorem sup_eq_sup_iff_right : a β c = b β c β a β€ b β c β§ b β€ a β c :=
β¨fun h => β¨h βΈ le_sup_left, h.symm βΈ le_sup_leftβ©, fun h => sup_congr_right h.1 h.2β©
#align sup_eq_sup_iff_right sup_eq_sup_iff_right
theorem Ne.lt_sup_or_lt_sup (hab : a β b) : a < a β b β¨ b < a β b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
#align ne.lt_sup_or_lt_sup Ne.lt_sup_or_lt_sup
/-- If `f` is monotone, `g` is antitone, and `f β€ g`, then for all `a`, `b` we have `f a β€ g b`. -/
theorem Monotone.forall_le_of_antitone {Ξ² : Type*} [Preorder Ξ²] {f g : Ξ± β Ξ²} (hf : Monotone f)
(hg : Antitone g) (h : f β€ g) (m n : Ξ±) : f m β€ g n :=
calc
f m β€ f (m β n) := hf le_sup_left
_ β€ g (m β n) := h _
_ β€ g n := hg le_sup_right
#align monotone.forall_le_of_antitone Monotone.forall_le_of_antitone
theorem SemilatticeSup.ext_sup {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_ge_iff $ fun c => by simp only [sup_le_iff]; rw [β H, @sup_le_iff Ξ± A, H, H]
#align semilattice_sup.ext_sup SemilatticeSup.ext_sup
theorem SemilatticeSup.ext {Ξ±} {A B : SemilatticeSup Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toSup = B.toSup := by ext; apply SemilatticeSup.ext_sup H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_sup.ext SemilatticeSup.ext
theorem ite_le_sup (s s' : Ξ±) (P : Prop) [Decidable P] : ite P s s' β€ s β s' :=
if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
#align ite_le_sup ite_le_sup
end SemilatticeSup
/-!
### Meet-semilattices
-/
/-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order
with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation
`β` which is the greatest element smaller than both factors. -/
class SemilatticeInf (Ξ± : Type u) extends Inf Ξ±, PartialOrder Ξ± where
/-- The infimum is a lower bound on the first argument -/
protected inf_le_left : β a b : Ξ±, a β b β€ a
/-- The infimum is a lower bound on the second argument -/
protected inf_le_right : β a b : Ξ±, a β b β€ b
/-- The infimum is the *greatest* lower bound -/
protected le_inf : β a b c : Ξ±, a β€ b β a β€ c β a β€ b β c
#align semilattice_inf SemilatticeInf
instance OrderDual.semilatticeSup (Ξ±) [SemilatticeInf Ξ±] : SemilatticeSup Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Sup Ξ±α΅α΅)
le_sup_left := @SemilatticeInf.inf_le_left Ξ± _
le_sup_right := @SemilatticeInf.inf_le_right Ξ± _
sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf Ξ± _ _ _ _ hca hcb
instance OrderDual.semilatticeInf (Ξ±) [SemilatticeSup Ξ±] : SemilatticeInf Ξ±α΅α΅ where
__ := inferInstanceAs (PartialOrder Ξ±α΅α΅)
__ := inferInstanceAs (Inf Ξ±α΅α΅)
inf_le_left := @le_sup_left Ξ± _
inf_le_right := @le_sup_right Ξ± _
le_inf := fun _ _ _ hca hcb => @sup_le Ξ± _ _ _ _ hca hcb
theorem SemilatticeSup.dual_dual (Ξ± : Type*) [H : SemilatticeSup Ξ±] :
OrderDual.semilatticeSup Ξ±α΅α΅ = H :=
SemilatticeSup.ext $ fun _ _ => Iff.rfl
#align semilattice_sup.dual_dual SemilatticeSup.dual_dual
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c d : Ξ±}
@[simp]
theorem inf_le_left : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left inf_le_left
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_left' : a β b β€ a :=
SemilatticeInf.inf_le_left a b
#align inf_le_left' inf_le_left'
@[simp]
theorem inf_le_right : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right inf_le_right
-- Porting note: no ematch attribute
--@[ematch]
theorem inf_le_right' : a β b β€ b :=
SemilatticeInf.inf_le_right a b
#align inf_le_right' inf_le_right'
theorem le_inf : a β€ b β a β€ c β a β€ b β c :=
SemilatticeInf.le_inf a b c
#align le_inf le_inf
theorem inf_le_of_left_le (h : a β€ c) : a β b β€ c :=
le_trans inf_le_left h
#align inf_le_of_left_le inf_le_of_left_le
theorem inf_le_of_right_le (h : b β€ c) : a β b β€ c :=
le_trans inf_le_right h
#align inf_le_of_right_le inf_le_of_right_le
theorem inf_lt_of_left_lt (h : a < c) : a β b < c :=
lt_of_le_of_lt inf_le_left h
#align inf_lt_of_left_lt inf_lt_of_left_lt
theorem inf_lt_of_right_lt (h : b < c) : a β b < c :=
lt_of_le_of_lt inf_le_right h
#align inf_lt_of_right_lt inf_lt_of_right_lt
@[simp]
theorem le_inf_iff : a β€ b β c β a β€ b β§ a β€ c :=
@sup_le_iff Ξ±α΅α΅ _ _ _ _
#align le_inf_iff le_inf_iff
@[simp]
theorem inf_eq_left : a β b = a β a β€ b :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_left inf_eq_left
@[simp]
theorem inf_eq_right : a β b = b β b β€ a :=
le_antisymm_iff.trans $ by simp [le_rfl]
#align inf_eq_right inf_eq_right
@[simp]
theorem left_eq_inf : a = a β b β a β€ b :=
eq_comm.trans inf_eq_left
#align left_eq_inf left_eq_inf
@[simp]
theorem right_eq_inf : b = a β b β b β€ a :=
eq_comm.trans inf_eq_right
#align right_eq_inf right_eq_inf
alias β¨le_of_inf_eq, inf_of_le_leftβ© := inf_eq_left
#align inf_of_le_left inf_of_le_left
#align le_of_inf_eq le_of_inf_eq
alias β¨_, inf_of_le_rightβ© := inf_eq_right
#align inf_of_le_right inf_of_le_right
attribute [simp] inf_of_le_left inf_of_le_right
@[simp]
theorem inf_lt_left : a β b < a β Β¬a β€ b :=
@left_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_left inf_lt_left
@[simp]
theorem inf_lt_right : a β b < b β Β¬b β€ a :=
@right_lt_sup Ξ±α΅α΅ _ _ _
#align inf_lt_right inf_lt_right
theorem inf_lt_left_or_right (h : a β b) : a β b < a β¨ a β b < b :=
@left_or_right_lt_sup Ξ±α΅α΅ _ _ _ h
#align inf_lt_left_or_right inf_lt_left_or_right
@[gcongr]
theorem inf_le_inf (hβ : a β€ b) (hβ : c β€ d) : a β c β€ b β d :=
@sup_le_sup Ξ±α΅α΅ _ _ _ _ _ hβ hβ
#align inf_le_inf inf_le_inf
@[gcongr]
theorem inf_le_inf_right (a : Ξ±) {b c : Ξ±} (h : b β€ c) : b β a β€ c β a :=
inf_le_inf h le_rfl
#align inf_le_inf_right inf_le_inf_right
@[gcongr]
theorem inf_le_inf_left (a : Ξ±) {b c : Ξ±} (h : b β€ c) : a β b β€ a β c :=
inf_le_inf le_rfl h
#align inf_le_inf_left inf_le_inf_left
-- Porting note: was @[simp]
theorem inf_idem : a β a = a :=
@sup_idem Ξ±α΅α΅ _ _
#align inf_idem inf_idem
instance : IsIdempotent Ξ± (Β· β Β·) :=
β¨@inf_idem _ _β©
theorem inf_comm : a β b = b β a :=
@sup_comm Ξ±α΅α΅ _ _ _
#align inf_comm inf_comm
instance : IsCommutative Ξ± (Β· β Β·) :=
β¨@inf_comm _ _β©
theorem inf_assoc : a β b β c = a β (b β c) :=
@sup_assoc Ξ±α΅α΅ _ a b c
#align inf_assoc inf_assoc
instance : IsAssociative Ξ± (Β· β Β·) :=
β¨@inf_assoc _ _β©
theorem inf_left_right_swap (a b c : Ξ±) : a β b β c = c β b β a :=
@sup_left_right_swap Ξ±α΅α΅ _ _ _ _
#align inf_left_right_swap inf_left_right_swap
-- Porting note: was @[simp]
theorem inf_left_idem : a β (a β b) = a β b :=
@sup_left_idem Ξ±α΅α΅ _ a b
#align inf_left_idem inf_left_idem
-- Porting note: was @[simp]
theorem inf_right_idem : a β b β b = a β b :=
@sup_right_idem Ξ±α΅α΅ _ a b
#align inf_right_idem inf_right_idem
theorem inf_left_comm (a b c : Ξ±) : a β (b β c) = b β (a β c) :=
@sup_left_comm Ξ±α΅α΅ _ a b c
#align inf_left_comm inf_left_comm
theorem inf_right_comm (a b c : Ξ±) : a β b β c = a β c β b :=
@sup_right_comm Ξ±α΅α΅ _ a b c
#align inf_right_comm inf_right_comm
theorem inf_inf_inf_comm (a b c d : Ξ±) : a β b β (c β d) = a β c β (b β d) :=
@sup_sup_sup_comm Ξ±α΅α΅ _ _ _ _ _
#align inf_inf_inf_comm inf_inf_inf_comm
theorem inf_inf_distrib_left (a b c : Ξ±) : a β (b β c) = a β b β (a β c) :=
@sup_sup_distrib_left Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_left inf_inf_distrib_left
theorem inf_inf_distrib_right (a b c : Ξ±) : a β b β c = a β c β (b β c) :=
@sup_sup_distrib_right Ξ±α΅α΅ _ _ _ _
#align inf_inf_distrib_right inf_inf_distrib_right
theorem inf_congr_left (hb : a β c β€ b) (hc : a β b β€ c) : a β b = a β c :=
@sup_congr_left Ξ±α΅α΅ _ _ _ _ hb hc
#align inf_congr_left inf_congr_left
theorem inf_congr_right (h1 : b β c β€ a) (h2 : a β c β€ b) : a β c = b β c :=
@sup_congr_right Ξ±α΅α΅ _ _ _ _ h1 h2
#align inf_congr_right inf_congr_right
theorem inf_eq_inf_iff_left : a β b = a β c β a β c β€ b β§ a β b β€ c :=
@sup_eq_sup_iff_left Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_left inf_eq_inf_iff_left
theorem inf_eq_inf_iff_right : a β c = b β c β b β c β€ a β§ a β c β€ b :=
@sup_eq_sup_iff_right Ξ±α΅α΅ _ _ _ _
#align inf_eq_inf_iff_right inf_eq_inf_iff_right
theorem Ne.inf_lt_or_inf_lt : a β b β a β b < a β¨ a β b < b :=
@Ne.lt_sup_or_lt_sup Ξ±α΅α΅ _ _ _
#align ne.inf_lt_or_inf_lt Ne.inf_lt_or_inf_lt
theorem SemilatticeInf.ext_inf {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y)
(x y : Ξ±) :
(haveI := A; x β y) = x β y :=
eq_of_forall_le_iff $ fun c => by simp only [le_inf_iff]; rw [β H, @le_inf_iff Ξ± A, H, H]
#align semilattice_inf.ext_inf SemilatticeInf.ext_inf
theorem SemilatticeInf.ext {Ξ±} {A B : SemilatticeInf Ξ±}
(H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
have ss : A.toInf = B.toInf := by ext; apply SemilatticeInf.ext_inf H
cases A
cases B
cases PartialOrder.ext H
congr
#align semilattice_inf.ext SemilatticeInf.ext
theorem SemilatticeInf.dual_dual (Ξ± : Type*) [H : SemilatticeInf Ξ±] :
OrderDual.semilatticeInf Ξ±α΅α΅ = H :=
SemilatticeInf.ext $ fun _ _ => Iff.rfl
#align semilattice_inf.dual_dual SemilatticeInf.dual_dual
theorem inf_le_ite (s s' : Ξ±) (P : Prop) [Decidable P] : s β s' β€ ite P s s' :=
@ite_le_sup Ξ±α΅α΅ _ _ _ _ _
#align inf_le_ite inf_le_ite
end SemilatticeInf
/--
A type with a commutative, associative and idempotent binary `inf` operation has the structure of a
meet-semilattice.
The partial order is defined so that `a β€ b` unfolds to `b β a = a`; cf. `inf_eq_right`.
-/
def SemilatticeInf.mk' {Ξ± : Type*} [Inf Ξ±] (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a) :
SemilatticeInf Ξ± := by
haveI : SemilatticeSup Ξ±α΅α΅ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem
haveI i := OrderDual.semilatticeInf Ξ±α΅α΅
exact i
#align semilattice_inf.mk' SemilatticeInf.mk'
/-!
### Lattices
-/
/-- A lattice is a join-semilattice which is also a meet-semilattice. -/
class Lattice (Ξ± : Type u) extends SemilatticeSup Ξ±, SemilatticeInf Ξ±
#align lattice Lattice
instance OrderDual.lattice (Ξ±) [Lattice Ξ±] : Lattice Ξ±α΅α΅ :=
{ OrderDual.semilatticeSup Ξ±, OrderDual.semilatticeInf Ξ± with }
/-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree
if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a β a β b = a`)
and `inf_sup_self` (`a β (a β b) = a`). -/
theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
{Ξ± : Type*} [Sup Ξ±] [Inf Ξ±]
(sup_comm : β a b : Ξ±, a β b = b β a) (sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c))
(sup_idem : β a : Ξ±, a β a = a) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_idem : β a : Ξ±, a β a = a)
(sup_inf_self : β a b : Ξ±, a β a β b = a) (inf_sup_self : β a b : Ξ±, a β (a β b) = a) :
@SemilatticeSup.toPartialOrder _ (SemilatticeSup.mk' sup_comm sup_assoc sup_idem) =
@SemilatticeInf.toPartialOrder _ (SemilatticeInf.mk' inf_comm inf_assoc inf_idem) :=
PartialOrder.ext $ fun a b =>
show a β b = b β b β a = a from
β¨fun h => by rw [β h, inf_comm, inf_sup_self], fun h => by rw [β h, sup_comm, sup_inf_self]β©
#align semilattice_sup_mk'_partial_order_eq_semilattice_inf_mk'_partial_order semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder
/-- A type with a pair of commutative and associative binary operations which satisfy two absorption
laws relating the two operations has the structure of a lattice.
The partial order is defined so that `a β€ b` unfolds to `a β b = b`; cf. `sup_eq_right`.
-/
def Lattice.mk' {Ξ± : Type*} [Sup Ξ±] [Inf Ξ±] (sup_comm : β a b : Ξ±, a β b = b β a)
(sup_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (inf_comm : β a b : Ξ±, a β b = b β a)
(inf_assoc : β a b c : Ξ±, a β b β c = a β (b β c)) (sup_inf_self : β a b : Ξ±, a β a β b = a)
(inf_sup_self : β a b : Ξ±, a β (a β b) = a) : Lattice Ξ± :=
have sup_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β b β (b β b) := by rw [inf_sup_self]
_ = b := by rw [sup_inf_self]
have inf_idem : β b : Ξ±, b β b = b := fun b =>
calc
b β b = b β (b β b β b) := by rw [sup_inf_self]
_ = b := by rw [inf_sup_self]
let semilatt_inf_inst := SemilatticeInf.mk' inf_comm inf_assoc inf_idem
let semilatt_sup_inst := SemilatticeSup.mk' sup_comm sup_assoc sup_idem
have partial_order_eq : @SemilatticeSup.toPartialOrder _ semilatt_sup_inst =
@SemilatticeInf.toPartialOrder _ semilatt_inf_inst :=
semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder _ _ _ _ _ _
sup_inf_self inf_sup_self
{ semilatt_sup_inst, semilatt_inf_inst with
inf_le_left := fun a b => by
rw [partial_order_eq]
apply inf_le_left,
inf_le_right := fun a b => by
rw [partial_order_eq]
apply inf_le_right,
le_inf := fun a b c => by
rw [partial_order_eq]
apply le_inf }
#align lattice.mk' Lattice.mk'
section Lattice
variable [Lattice Ξ±] {a b c d : Ξ±}
theorem inf_le_sup : a β b β€ a β b :=
inf_le_left.trans le_sup_left
#align inf_le_sup inf_le_sup
-- Porting note: was @[simp]
theorem sup_le_inf : a β b β€ a β b β a = b := by simp [le_antisymm_iff, and_comm]
#align sup_le_inf sup_le_inf
@[simp] lemma inf_eq_sup : a β b = a β b β a = b := by rw [β inf_le_sup.ge_iff_eq, sup_le_inf]
#align inf_eq_sup inf_eq_sup
@[simp] lemma sup_eq_inf : a β b = a β b β a = b := eq_comm.trans inf_eq_sup
#align sup_eq_inf sup_eq_inf
@[simp] lemma inf_lt_sup : a β b < a β b β a β b := by rw [inf_le_sup.lt_iff_ne, Ne.def, inf_eq_sup]
#align inf_lt_sup inf_lt_sup
lemma inf_eq_and_sup_eq_iff : a β b = c β§ a β b = c β a = c β§ b = c := by
refine' β¨fun h β¦ _, _β©
{ obtain rfl := sup_eq_inf.1 (h.2.trans h.1.symm)
simpa using h }
{ rintro β¨rfl, rflβ©
exact β¨inf_idem, sup_idemβ© }
#align inf_eq_and_sup_eq_iff inf_eq_and_sup_eq_iff
/-!
#### Distributivity laws
-/
-- TODO: better names?
theorem sup_inf_le : a β b β c β€ (a β b) β (a β c) :=
le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _)
#align sup_inf_le sup_inf_le
theorem le_inf_sup : a β b β a β c β€ a β (b β c) :=
sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right)
#align le_inf_sup le_inf_sup
theorem inf_sup_self : a β (a β b) = a := by simp
#align inf_sup_self inf_sup_self
theorem sup_inf_self : a β a β b = a := by simp
#align sup_inf_self sup_inf_self
theorem sup_eq_iff_inf_eq : a β b = b β a β b = a := by rw [sup_eq_right, β inf_eq_left]
#align sup_eq_iff_inf_eq sup_eq_iff_inf_eq
theorem Lattice.ext {Ξ±} {A B : Lattice Ξ±} (H : β x y : Ξ±, (haveI := A; x β€ y) β x β€ y) :
A = B := by
cases A
cases B
cases SemilatticeSup.ext H
cases SemilatticeInf.ext H
congr
#align lattice.ext Lattice.ext
end Lattice
/-!
### Distributive lattices
-/
/-- A distributive lattice is a lattice that satisfies any of four
equivalent distributive properties (of `sup` over `inf` or `inf` over `sup`,
on the left or right).
The definition here chooses `le_sup_inf`: `(x β y) β (x β z) β€ x β (y β z)`. To prove distributivity
from the dual law, use `DistribLattice.of_inf_sup_le`.
A classic example of a distributive lattice
is the lattice of subsets of a set, and in fact this example is
generic in the sense that every distributive lattice is realizable
as a sublattice of a powerset lattice. -/
class DistribLattice (Ξ±) extends Lattice Ξ± where
/-- The infimum distributes over the supremum -/
protected le_sup_inf : β x y z : Ξ±, (x β y) β (x β z) β€ x β y β z
#align distrib_lattice DistribLattice
section DistribLattice
variable [DistribLattice Ξ±] {x y z : Ξ±}
theorem le_sup_inf : β {x y z : Ξ±}, (x β y) β (x β z) β€ x β y β z :=
fun {x y z} => DistribLattice.le_sup_inf x y z
#align le_sup_inf le_sup_inf
theorem sup_inf_left : x β y β z = (x β y) β (x β z) :=
le_antisymm sup_inf_le le_sup_inf
#align sup_inf_left sup_inf_left
theorem sup_inf_right : y β z β x = (y β x) β (z β x) := by
simp only [sup_inf_left, fun y : Ξ± => @sup_comm Ξ± _ y x, eq_self_iff_true]
#align sup_inf_right sup_inf_right
theorem inf_sup_left : x β (y β z) = x β y β x β z :=
calc
x β (y β z) = x β (x β z) β (y β z) := by rw [inf_sup_self]
_ = x β (x β y β z) := by simp only [inf_assoc, sup_inf_right, eq_self_iff_true]
_ = (x β x β y) β (x β y β z) := by rw [sup_inf_self]
_ = (x β y β x) β (x β y β z) := by rw [sup_comm]
_ = x β y β x β z := by rw [sup_inf_left]
#align inf_sup_left inf_sup_left
instance OrderDual.distribLattice (Ξ± : Type*) [DistribLattice Ξ±] : DistribLattice Ξ±α΅α΅ where
__ := inferInstanceAs (Lattice Ξ±α΅α΅)
le_sup_inf := fun _ _ _ => le_of_eq (@inf_sup_left Ξ±).symm
theorem inf_sup_right : (y β z) β x = y β x β z β x := by
simp only [inf_sup_left, fun y : Ξ± => @inf_comm Ξ± _ y x, eq_self_iff_true]
#align inf_sup_right inf_sup_right
theorem le_of_inf_le_sup_le (hβ : x β z β€ y β z) (hβ : x β z β€ y β z) : x β€ y :=
calc
x β€ y β z β x := le_sup_right
_ = (y β x) β (x β z) := by rw [sup_inf_right, @sup_comm _ _ x]
_ β€ (y β x) β (y β z) := inf_le_inf_left _ hβ
_ = y β x β z := sup_inf_left.symm
_ β€ y β y β z := sup_le_sup_left hβ _
_ β€ _ := sup_le (le_refl y) inf_le_left
#align le_of_inf_le_sup_le le_of_inf_le_sup_le
theorem eq_of_inf_eq_sup_eq {Ξ± : Type u} [DistribLattice Ξ±] {a b c : Ξ±} (hβ : b β a = c β a)
(hβ : b β a = c β a) :
b = c :=
le_antisymm (le_of_inf_le_sup_le (le_of_eq hβ) (le_of_eq hβ))
(le_of_inf_le_sup_le (le_of_eq hβ.symm) (le_of_eq hβ.symm))
#align eq_of_inf_eq_sup_eq eq_of_inf_eq_sup_eq
end DistribLattice
-- See note [reducible non-instances]
/-- Prove distributivity of an existing lattice from the dual distributive law. -/
@[reducible]
def DistribLattice.ofInfSupLe [Lattice Ξ±] (inf_sup_le : β a b c : Ξ±, a β (b β c) β€ a β b β a β c) :
DistribLattice Ξ± :=
{ le_sup_inf := (@OrderDual.distribLattice Ξ±α΅α΅ {inferInstanceAs (Lattice Ξ±α΅α΅) with
le_sup_inf := inf_sup_le}).le_sup_inf, }
#align distrib_lattice.of_inf_sup_le DistribLattice.ofInfSupLe
/-!
### Lattices derived from linear orders
-/
-- see Note [lower instance priority]
instance (priority := 100) LinearOrder.toLattice {Ξ± : Type u} [o : LinearOrder Ξ±] : Lattice Ξ± :=
{ o with
sup := max,
le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := fun _ _ _ => max_le,
inf := min,
inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := fun _ _ _ => le_min }
section LinearOrder
variable [LinearOrder Ξ±] {a b c d : Ξ±}
theorem sup_eq_max : a β b = max a b :=
rfl
#align sup_eq_max sup_eq_max
theorem inf_eq_min : a β b = min a b :=
rfl
#align inf_eq_min inf_eq_min
theorem sup_ind (a b : Ξ±) {p : Ξ± β Prop} (ha : p a) (hb : p b) : p (a β b) :=
(IsTotal.total a b).elim (fun h : a β€ b => by rwa [sup_eq_right.2 h]) fun h => by
rwa [sup_eq_left.2 h]
#align sup_ind sup_ind
@[simp]
theorem le_sup_iff : a β€ b β c β a β€ b β¨ a β€ c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
#align le_sup_iff le_sup_iff
@[simp]
theorem lt_sup_iff : a < b β c β a < b β¨ a < c := by
exact β¨fun h =>
(le_total c b).imp
(fun bc => by rwa [sup_eq_left.2 bc] at h)
(fun bc => by rwa [sup_eq_right.2 bc] at h),
fun h => h.elim lt_sup_of_lt_left lt_sup_of_lt_rightβ©
#align lt_sup_iff lt_sup_iff
-- Porting note: why does sup_ind need an explicit motive?
@[simp]
theorem sup_lt_iff : b β c < a β b < a β§ c < a :=
β¨fun h => β¨le_sup_left.trans_lt h, le_sup_right.trans_lt hβ©,
fun h => @sup_ind Ξ± _ b c (fun x => x < a) h.1 h.2β©
#align sup_lt_iff sup_lt_iff
theorem inf_ind (a b : Ξ±) {p : Ξ± β Prop} : p a β p b β p (a β b) :=
@sup_ind Ξ±α΅α΅ _ _ _ _
#align inf_ind inf_ind
@[simp]
theorem inf_le_iff : b β c β€ a β b β€ a β¨ c β€ a :=
@le_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_le_iff inf_le_iff
@[simp]
theorem inf_lt_iff : b β c < a β b < a β¨ c < a :=
@lt_sup_iff Ξ±α΅α΅ _ _ _ _
#align inf_lt_iff inf_lt_iff
@[simp]
theorem lt_inf_iff : a < b β c β a < b β§ a < c :=
@sup_lt_iff Ξ±α΅α΅ _ _ _ _
#align lt_inf_iff lt_inf_iff
variable (a b c d)
theorem max_max_max_comm : max (max a b) (max c d) = max (max a c) (max b d) :=
sup_sup_sup_comm _ _ _ _
#align max_max_max_comm max_max_max_comm
theorem min_min_min_comm : min (min a b) (min c d) = min (min a c) (min b d) :=
inf_inf_inf_comm _ _ _ _
#align min_min_min_comm min_min_min_comm
end LinearOrder
theorem sup_eq_maxDefault [SemilatticeSup Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (maxDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold maxDefault
split_ifs with h'
exacts [sup_of_le_right h', sup_of_le_left $ (total_of (Β· β€ Β·) x y).resolve_left h']
#align sup_eq_max_default sup_eq_maxDefault
theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold minDefault
split_ifs with h'
| exacts [inf_of_le_left h', inf_of_le_right $ (total_of (Β· β€ Β·) x y).resolve_left h'] | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) := by
ext x y
unfold minDefault
split_ifs with h'
| Mathlib.Order.Lattice.900_0.wE3igZl9MFbJBfv | theorem inf_eq_minDefault [SemilatticeInf Ξ±] [DecidableRel ((Β· β€ Β·) : Ξ± β Ξ± β Prop)]
[IsTotal Ξ± (Β· β€ Β·)] :
(Β· β Β·) = (minDefault : Ξ± β Ξ± β Ξ±) | Mathlib_Order_Lattice |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.