path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
Order\Category\CompleteLat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.BddLat
import Mathlib.Order.Hom.CompleteLattice
/-!
# The category of complete lattices
This file defines `CompleteLat`, the category of complete lattices.
-/
universe u
open CategoryTheory
/-- The category of complete lattices. -/
def CompleteLat :=
Bundled CompleteLattice
namespace CompleteLat
instance : CoeSort CompleteLat Type* :=
Bundled.coeSort
instance (X : CompleteLat) : CompleteLattice X :=
X.str
/-- Construct a bundled `CompleteLat` from a `CompleteLattice`. -/
def of (α : Type*) [CompleteLattice α] : CompleteLat :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [CompleteLattice α] : ↥(of α) = α :=
rfl
instance : Inhabited CompleteLat :=
⟨of PUnit⟩
instance : BundledHom @CompleteLatticeHom where
toFun _ _ f := f.toFun
id := @CompleteLatticeHom.id
comp := @CompleteLatticeHom.comp
hom_ext _ _ _ _ h := DFunLike.coe_injective h
deriving instance LargeCategory for CompleteLat
instance : ConcreteCategory CompleteLat := by
dsimp [CompleteLat]; infer_instance
instance hasForgetToBddLat : HasForget₂ CompleteLat BddLat where
forget₂ :=
{ obj := fun X => BddLat.of X
map := fun {X Y} => CompleteLatticeHom.toBoundedLatticeHom }
forget_comp := rfl
/-- Constructs an isomorphism of complete lattices from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : CompleteLat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : CompleteLatticeHom _ _) -- Porting note (#11215): TODO, wrong?
inv := (e.symm : CompleteLatticeHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : CompleteLat ⥤ CompleteLat where
obj X := of Xᵒᵈ
map {X Y} := CompleteLatticeHom.dual
/-- The equivalence between `CompleteLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : CompleteLat ≌ CompleteLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end CompleteLat
theorem completeLat_dual_comp_forget_to_bddLat :
CompleteLat.dual ⋙ forget₂ CompleteLat BddLat =
forget₂ CompleteLat BddLat ⋙ BddLat.dual :=
rfl
|
Order\Category\DistLat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.Lat
/-!
# The category of distributive lattices
This file defines `DistLat`, the category of distributive lattices.
Note that [`DistLat`](https://ncatlab.org/nlab/show/DistLat) in the literature doesn't always
correspond to `DistLat` as we don't require bottom or top elements. Instead, this `DistLat`
corresponds to `BddDistLat`.
-/
universe u
open CategoryTheory
/-- The category of distributive lattices. -/
def DistLat :=
Bundled DistribLattice
namespace DistLat
instance : CoeSort DistLat Type* :=
Bundled.coeSort
instance (X : DistLat) : DistribLattice X :=
X.str
/-- Construct a bundled `DistLat` from a `DistribLattice` underlying type and typeclass. -/
def of (α : Type*) [DistribLattice α] : DistLat :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [DistribLattice α] : ↥(of α) = α :=
rfl
instance : Inhabited DistLat :=
⟨of PUnit⟩
instance : BundledHom.ParentProjection @DistribLattice.toLattice :=
⟨⟩
deriving instance LargeCategory for DistLat
instance : ConcreteCategory DistLat :=
BundledHom.concreteCategory _
instance hasForgetToLat : HasForget₂ DistLat Lat :=
BundledHom.forget₂ _ _
/-- Constructs an equivalence between distributive lattices from an order isomorphism between them.
-/
@[simps]
def Iso.mk {α β : DistLat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : LatticeHom α β)
inv := (e.symm : LatticeHom β α)
hom_inv_id := by
ext
exact e.symm_apply_apply _
inv_hom_id := by
ext
exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : DistLat ⥤ DistLat where
obj X := of Xᵒᵈ
map := LatticeHom.dual
/-- The equivalence between `DistLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : DistLat ≌ DistLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X) fun _ => rfl
counitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X) fun _ => rfl
end DistLat
theorem distLat_dual_comp_forget_to_Lat :
DistLat.dual ⋙ forget₂ DistLat Lat = forget₂ DistLat Lat ⋙ Lat.dual :=
rfl
|
Order\Category\FinBddDistLat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Fintype.Order
import Mathlib.Order.Category.BddDistLat
import Mathlib.Order.Category.FinPartOrd
/-!
# The category of finite bounded distributive lattices
This file defines `FinBddDistLat`, the category of finite distributive lattices with
bounded lattice homomorphisms.
-/
universe u
open CategoryTheory
/-- The category of finite distributive lattices with bounded lattice morphisms. -/
structure FinBddDistLat where
toBddDistLat : BddDistLat
[isFintype : Fintype toBddDistLat]
namespace FinBddDistLat
instance : CoeSort FinBddDistLat Type* :=
⟨fun X => X.toBddDistLat⟩
instance (X : FinBddDistLat) : DistribLattice X :=
X.toBddDistLat.toDistLat.str
instance (X : FinBddDistLat) : BoundedOrder X :=
X.toBddDistLat.isBoundedOrder
attribute [instance] FinBddDistLat.isFintype
/-- Construct a bundled `FinBddDistLat` from a `Nonempty` `BoundedOrder` `DistribLattice`. -/
def of (α : Type*) [DistribLattice α] [BoundedOrder α] [Fintype α] : FinBddDistLat :=
-- Porting note: was `⟨⟨⟨α⟩⟩⟩`
-- see https://github.com/leanprover-community/mathlib4/issues/4998
⟨⟨{α := α}⟩⟩
/-- Construct a bundled `FinBddDistLat` from a `Nonempty` `BoundedOrder` `DistribLattice`. -/
def of' (α : Type*) [DistribLattice α] [Fintype α] [Nonempty α] : FinBddDistLat :=
haveI := Fintype.toBoundedOrder α
-- Porting note: was `⟨⟨⟨α⟩⟩⟩`
-- see https://github.com/leanprover-community/mathlib4/issues/4998
⟨⟨{α := α}⟩⟩
instance : Inhabited FinBddDistLat :=
⟨of PUnit⟩
instance largeCategory : LargeCategory FinBddDistLat :=
InducedCategory.category toBddDistLat
instance concreteCategory : ConcreteCategory FinBddDistLat :=
InducedCategory.concreteCategory toBddDistLat
instance hasForgetToBddDistLat : HasForget₂ FinBddDistLat BddDistLat :=
InducedCategory.hasForget₂ FinBddDistLat.toBddDistLat
instance hasForgetToFinPartOrd : HasForget₂ FinBddDistLat FinPartOrd where
forget₂.obj X := FinPartOrd.of X
forget₂.map {X Y} f := (show BoundedLatticeHom X Y from f : X →o Y)
/-- Constructs an equivalence between finite distributive lattices from an order isomorphism
between them. -/
@[simps]
def Iso.mk {α β : FinBddDistLat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedLatticeHom α β)
inv := (e.symm : BoundedLatticeHom β α)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
example {X Y : FinBddDistLat} : (X ⟶ Y) = BoundedLatticeHom X Y :=
rfl
/-- `OrderDual` as a functor. -/
@[simps]
def dual : FinBddDistLat ⥤ FinBddDistLat where
obj X := of Xᵒᵈ
map {X Y} := BoundedLatticeHom.dual
/-- The equivalence between `FinBddDistLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : FinBddDistLat ≌ FinBddDistLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end FinBddDistLat
theorem finBddDistLat_dual_comp_forget_to_bddDistLat :
FinBddDistLat.dual ⋙ forget₂ FinBddDistLat BddDistLat =
forget₂ FinBddDistLat BddDistLat ⋙ BddDistLat.dual :=
rfl
|
Order\Category\FinBoolAlg.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Fintype.Powerset
import Mathlib.Order.Category.BoolAlg
import Mathlib.Order.Category.FinBddDistLat
import Mathlib.Order.Hom.CompleteLattice
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.Set.Subsingleton
/-!
# The category of finite boolean algebras
This file defines `FinBoolAlg`, the category of finite boolean algebras.
## TODO
Birkhoff's representation for finite Boolean algebras.
```
FintypeCat_to_FinBoolAlg_op.left_op ⋙ FinBoolAlg.dual ≅
FintypeCat_to_FinBoolAlg_op.left_op
```
`FinBoolAlg` is essentially small.
-/
universe u
open CategoryTheory OrderDual Opposite
/-- The category of finite boolean algebras with bounded lattice morphisms. -/
structure FinBoolAlg where
toBoolAlg : BoolAlg
[isFintype : Fintype toBoolAlg]
namespace FinBoolAlg
instance : CoeSort FinBoolAlg Type* :=
⟨fun X => X.toBoolAlg⟩
instance (X : FinBoolAlg) : BooleanAlgebra X :=
X.toBoolAlg.str
attribute [instance] FinBoolAlg.isFintype
-- Porting note: linter says this is a syntactic tautology now
-- @[simp]
-- theorem coe_toBoolAlg (X : FinBoolAlg) : ↥X.toBoolAlg = ↥X :=
-- rfl
/-- Construct a bundled `FinBoolAlg` from `BooleanAlgebra` + `Fintype`. -/
def of (α : Type*) [BooleanAlgebra α] [Fintype α] : FinBoolAlg :=
⟨{α := α}⟩
@[simp]
theorem coe_of (α : Type*) [BooleanAlgebra α] [Fintype α] : ↥(of α) = α :=
rfl
instance : Inhabited FinBoolAlg :=
⟨of PUnit⟩
instance largeCategory : LargeCategory FinBoolAlg :=
InducedCategory.category FinBoolAlg.toBoolAlg
instance concreteCategory : ConcreteCategory FinBoolAlg :=
InducedCategory.concreteCategory FinBoolAlg.toBoolAlg
instance instFunLike {X Y : FinBoolAlg} : FunLike (X ⟶ Y) X Y :=
BoundedLatticeHom.instFunLike
-- Porting note: added
-- TODO: in all of the earlier bundled order categories,
-- we should be constructing instances analogous to this,
-- rather than directly coercions to functions.
instance instBoundedLatticeHomClass {X Y : FinBoolAlg} : BoundedLatticeHomClass (X ⟶ Y) X Y :=
BoundedLatticeHom.instBoundedLatticeHomClass
instance hasForgetToBoolAlg : HasForget₂ FinBoolAlg BoolAlg :=
InducedCategory.hasForget₂ FinBoolAlg.toBoolAlg
instance hasForgetToFinBddDistLat : HasForget₂ FinBoolAlg FinBddDistLat where
forget₂.obj X := FinBddDistLat.of X
forget₂.map f := f
forget_comp := rfl
instance forgetToBoolAlg_full : (forget₂ FinBoolAlg BoolAlg).Full :=
InducedCategory.full _
instance forgetToBoolAlgFaithful : (forget₂ FinBoolAlg BoolAlg).Faithful :=
InducedCategory.faithful _
@[simps]
instance hasForgetToFinPartOrd : HasForget₂ FinBoolAlg FinPartOrd where
forget₂.obj X := FinPartOrd.of X
forget₂.map {X Y} f := show OrderHom X Y from ↑(show BoundedLatticeHom X Y from f)
instance forgetToFinPartOrdFaithful : (forget₂ FinBoolAlg FinPartOrd).Faithful :=
-- Porting note: original code
-- ⟨fun {X Y} f g h =>
-- haveI := congr_arg (coeFn : _ → X → Y) h
-- DFunLike.coe_injective this⟩
-- Porting note: the coercions to functions for the various bundled order categories
-- are quite inconsistent. We need to go back through and make all these files uniform.
⟨fun {X Y} f g h => by
dsimp at *
apply DFunLike.coe_injective
dsimp
ext x
apply_fun (fun f => f x) at h
exact h ⟩
/-- Constructs an equivalence between finite Boolean algebras from an order isomorphism between
them. -/
@[simps]
def Iso.mk {α β : FinBoolAlg.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : BoundedLatticeHom α β)
inv := (e.symm : BoundedLatticeHom β α)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : FinBoolAlg ⥤ FinBoolAlg where
obj X := of Xᵒᵈ
map {X Y} := BoundedLatticeHom.dual
/-- The equivalence between `FinBoolAlg` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : FinBoolAlg ≌ FinBoolAlg where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end FinBoolAlg
theorem finBoolAlg_dual_comp_forget_to_finBddDistLat :
FinBoolAlg.dual ⋙ forget₂ FinBoolAlg FinBddDistLat =
forget₂ FinBoolAlg FinBddDistLat ⋙ FinBddDistLat.dual :=
rfl
/-- The powerset functor. `Set` as a functor. -/
@[simps]
def fintypeToFinBoolAlgOp : FintypeCat ⥤ FinBoolAlgᵒᵖ where
obj X := op <| FinBoolAlg.of (Set X)
map {X Y} f :=
Quiver.Hom.op <| (CompleteLatticeHom.setPreimage f : BoundedLatticeHom (Set Y) (Set X))
|
Order\Category\FinPartOrd.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.CategoryTheory.FintypeCat
import Mathlib.Order.Category.PartOrd
/-!
# The category of finite partial orders
This defines `FinPartOrd`, the category of finite partial orders.
Note: `FinPartOrd` is *not* a subcategory of `BddOrd` because finite orders are not necessarily
bounded.
## TODO
`FinPartOrd` is equivalent to a small category.
-/
universe u v
open CategoryTheory
/-- The category of finite partial orders with monotone functions. -/
structure FinPartOrd where
toPartOrd : PartOrd
[isFintype : Fintype toPartOrd]
namespace FinPartOrd
instance : CoeSort FinPartOrd Type* :=
⟨fun X => X.toPartOrd⟩
instance (X : FinPartOrd) : PartialOrder X :=
X.toPartOrd.str
attribute [instance] FinPartOrd.isFintype
-- synTaut
/-- Construct a bundled `FinPartOrd` from `PartialOrder` + `Fintype`. -/
def of (α : Type*) [PartialOrder α] [Fintype α] : FinPartOrd :=
⟨⟨α, inferInstance⟩⟩
@[simp]
theorem coe_of (α : Type*) [PartialOrder α] [Fintype α] : ↥(of α) = α := rfl
instance : Inhabited FinPartOrd :=
⟨of PUnit⟩
instance largeCategory : LargeCategory FinPartOrd :=
InducedCategory.category FinPartOrd.toPartOrd
instance concreteCategory : ConcreteCategory FinPartOrd :=
InducedCategory.concreteCategory FinPartOrd.toPartOrd
instance hasForgetToPartOrd : HasForget₂ FinPartOrd PartOrd :=
InducedCategory.hasForget₂ FinPartOrd.toPartOrd
instance hasForgetToFintype : HasForget₂ FinPartOrd FintypeCat where
forget₂ :=
{ obj := fun X => ⟨X, inferInstance⟩
-- Porting note: Originally `map := fun X Y => coeFn`
map := fun {X Y} (f : OrderHom X Y) => ⇑f }
/-- Constructs an isomorphism of finite partial orders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : FinPartOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom _ _)
inv := (e.symm : OrderHom _ _)
hom_inv_id := by
ext
exact e.symm_apply_apply _
inv_hom_id := by
ext
exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : FinPartOrd ⥤ FinPartOrd where
obj X := of Xᵒᵈ
map {X Y} := OrderHom.dual
/-- The equivalence between `FinPartOrd` and itself induced by `OrderDual` both ways. -/
@[simps! functor inverse]
def dualEquiv : FinPartOrd ≌ FinPartOrd :=
CategoryTheory.Equivalence.mk dual dual
(NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X)
(NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X)
end FinPartOrd
theorem FinPartOrd_dual_comp_forget_to_partOrd :
FinPartOrd.dual ⋙ forget₂ FinPartOrd PartOrd =
forget₂ FinPartOrd PartOrd ⋙ PartOrd.dual := rfl
|
Order\Category\Frm.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.Lat
import Mathlib.Order.Hom.CompleteLattice
import Mathlib.Topology.Category.CompHaus.Basic
import Mathlib.Topology.Sets.Opens
/-!
# The category of frames
This file defines `Frm`, the category of frames.
## References
* [nLab, *Frm*](https://ncatlab.org/nlab/show/Frm)
-/
universe u
open CategoryTheory Opposite Order TopologicalSpace
/-- The category of frames. -/
def Frm :=
Bundled Frame
namespace Frm
instance : CoeSort Frm Type* :=
Bundled.coeSort
instance (X : Frm) : Frame X :=
X.str
/-- Construct a bundled `Frm` from a `Frame`. -/
def of (α : Type*) [Frame α] : Frm :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [Frame α] : ↥(of α) = α := rfl
instance : Inhabited Frm :=
⟨of PUnit⟩
/-- An abbreviation of `FrameHom` that assumes `Frame` instead of the weaker `CompleteLattice`.
Necessary for the category theory machinery. -/
abbrev Hom (α β : Type*) [Frame α] [Frame β] : Type _ :=
FrameHom α β
instance bundledHom : BundledHom Hom where
toFun {α β} _ _ := ((↑) : FrameHom α β → α → β)
id {α} _ := FrameHom.id α
comp _ _ _ := FrameHom.comp
hom_ext _ _ := DFunLike.coe_injective
-- Porting note: Originally `deriving instance LargeCategory, ConcreteCategory for Frm`
-- see https://github.com/leanprover-community/mathlib4/issues/5020
deriving instance LargeCategory, Category for Frm
instance : ConcreteCategory Frm := by
unfold Frm
infer_instance
instance hasForgetToLat : HasForget₂ Frm Lat where
forget₂ :=
{ obj := fun X => ⟨X, _⟩
map := fun {X Y} => FrameHom.toLatticeHom }
/-- Constructs an isomorphism of frames from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : Frm.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : FrameHom _ _)
inv := (e.symm : FrameHom _ _)
hom_inv_id := by
ext
exact e.symm_apply_apply _
inv_hom_id := by
ext
exact e.apply_symm_apply _
end Frm
/-- The forgetful functor from `TopCatᵒᵖ` to `Frm`. -/
@[simps]
def topCatOpToFrm : TopCatᵒᵖ ⥤ Frm where
obj X := Frm.of (Opens (unop X : TopCat))
map f := Opens.comap <| Quiver.Hom.unop f
map_id X := Opens.comap_id
-- Note, `CompHaus` is too strong. We only need `T0Space`.
instance CompHausOpToFrame.faithful : (compHausToTop.op ⋙ topCatOpToFrm.{u}).Faithful :=
⟨fun h => Quiver.Hom.unop_inj <| Opens.comap_injective h⟩
|
Order\Category\HeytAlg.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.BddDistLat
import Mathlib.Order.Heyting.Hom
/-!
# The category of Heyting algebras
This file defines `HeytAlg`, the category of Heyting algebras.
-/
universe u
open CategoryTheory Opposite Order
/-- The category of Heyting algebras. -/
def HeytAlg :=
Bundled HeytingAlgebra
namespace HeytAlg
instance : CoeSort HeytAlg Type* :=
Bundled.coeSort
instance (X : HeytAlg) : HeytingAlgebra X :=
X.str
/-- Construct a bundled `HeytAlg` from a `HeytingAlgebra`. -/
def of (α : Type*) [HeytingAlgebra α] : HeytAlg :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [HeytingAlgebra α] : ↥(of α) = α :=
rfl
instance : Inhabited HeytAlg :=
⟨of PUnit⟩
instance bundledHom : BundledHom HeytingHom where
toFun α β [HeytingAlgebra α] [HeytingAlgebra β] := (DFunLike.coe : HeytingHom α β → α → β)
id := @HeytingHom.id
comp := @HeytingHom.comp
hom_ext α β [HeytingAlgebra α] [HeytingAlgebra β] := DFunLike.coe_injective
deriving instance LargeCategory for HeytAlg
-- Porting note: deriving failed.
-- see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory HeytAlg := by
dsimp [HeytAlg]
infer_instance
-- Porting note: No idea why it does not find this instance...
instance {X Y : HeytAlg.{u}} : FunLike (X ⟶ Y) ↑X ↑Y :=
HeytingHom.instFunLike
-- Porting note: No idea why it does not find this instance...
instance {X Y : HeytAlg.{u}} : HeytingHomClass (X ⟶ Y) ↑X ↑Y :=
HeytingHom.instHeytingHomClass
@[simps]
instance hasForgetToLat : HasForget₂ HeytAlg BddDistLat where
forget₂ :=
{ obj := fun X => BddDistLat.of X
map := fun {X Y} f => (f : BoundedLatticeHom X Y) }
/-- Constructs an isomorphism of Heyting algebras from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : HeytAlg.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : HeytingHom _ _)
inv := (e.symm : HeytingHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
end HeytAlg
|
Order\Category\Lat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.PartOrd
import Mathlib.Order.Hom.Lattice
/-!
# The category of lattices
This defines `Lat`, the category of lattices.
Note that `Lat` doesn't correspond to the literature definition of [`Lat`]
(https://ncatlab.org/nlab/show/Lat) as we don't require bottom or top elements. Instead, `Lat`
corresponds to `BddLat`.
## TODO
The free functor from `Lat` to `BddLat` is `X → WithTop (WithBot X)`.
-/
universe u
open CategoryTheory
/-- The category of lattices. -/
def Lat :=
Bundled Lattice
namespace Lat
instance : CoeSort Lat Type* :=
Bundled.coeSort
instance (X : Lat) : Lattice X :=
X.str
/-- Construct a bundled `Lat` from a `Lattice`. -/
def of (α : Type*) [Lattice α] : Lat :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [Lattice α] : ↥(of α) = α :=
rfl
instance : Inhabited Lat :=
⟨of Bool⟩
instance : BundledHom @LatticeHom where
toFun _ _ f := f.toFun
id := @LatticeHom.id
comp := @LatticeHom.comp
hom_ext _ _ _ _ h := DFunLike.coe_injective h
instance : LargeCategory.{u} Lat :=
BundledHom.category LatticeHom
instance : ConcreteCategory Lat :=
BundledHom.concreteCategory LatticeHom
instance hasForgetToPartOrd : HasForget₂ Lat PartOrd where
forget₂ :=
{ obj := fun X => Bundled.mk X inferInstance
map := fun {X Y} (f : LatticeHom X Y) => (f : OrderHom X Y) }
/-- Constructs an isomorphism of lattices from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : Lat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : LatticeHom _ _)
inv := (e.symm : LatticeHom _ _)
hom_inv_id := by
ext
exact e.symm_apply_apply _
inv_hom_id := by
ext
exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : Lat ⥤ Lat where
obj X := of Xᵒᵈ
map := LatticeHom.dual
/-- The equivalence between `Lat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : Lat ≌ Lat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end Lat
theorem Lat_dual_comp_forget_to_partOrd :
Lat.dual ⋙ forget₂ Lat PartOrd = forget₂ Lat PartOrd ⋙ PartOrd.dual :=
rfl
|
Order\Category\LinOrd.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Order.Category.Lat
/-!
# Category of linear orders
This defines `LinOrd`, the category of linear orders with monotone maps.
-/
open CategoryTheory
universe u
/-- The category of linear orders. -/
def LinOrd :=
Bundled LinearOrder
namespace LinOrd
instance : BundledHom.ParentProjection @LinearOrder.toPartialOrder :=
⟨⟩
deriving instance LargeCategory for LinOrd
-- Porting note: Probably see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory LinOrd :=
BundledHom.concreteCategory _
instance : CoeSort LinOrd Type* :=
Bundled.coeSort
/-- Construct a bundled `LinOrd` from the underlying type and typeclass. -/
def of (α : Type*) [LinearOrder α] : LinOrd :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [LinearOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited LinOrd :=
⟨of PUnit⟩
instance (α : LinOrd) : LinearOrder α :=
α.str
instance hasForgetToLat : HasForget₂ LinOrd Lat where
forget₂ :=
{ obj := fun X => Lat.of X
map := fun {X Y} (f : OrderHom _ _) => OrderHomClass.toLatticeHom X Y f }
/-- Constructs an equivalence between linear orders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : LinOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom _ _)
inv := (e.symm : OrderHom _ _)
hom_inv_id := by
ext x
exact e.symm_apply_apply x
inv_hom_id := by
ext x
exact e.apply_symm_apply x
/-- `OrderDual` as a functor. -/
@[simps]
def dual : LinOrd ⥤ LinOrd where
obj X := of Xᵒᵈ
map := OrderHom.dual
/-- The equivalence between `LinOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : LinOrd ≌ LinOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end LinOrd
theorem linOrd_dual_comp_forget_to_Lat :
LinOrd.dual ⋙ forget₂ LinOrd Lat = forget₂ LinOrd Lat ⋙ Lat.dual :=
rfl
|
Order\Category\NonemptyFinLinOrd.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.Fintype.Order
import Mathlib.Data.Set.Finite
import Mathlib.Order.Category.FinPartOrd
import Mathlib.Order.Category.LinOrd
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
import Mathlib.Data.Set.Subsingleton
/-!
# Nonempty finite linear orders
This defines `NonemptyFinLinOrd`, the category of nonempty finite linear
orders with monotone maps. This is the index category for simplicial objects.
Note: `NonemptyFinLinOrd` is *not* a subcategory of `FinBddDistLat` because its morphisms do not
preserve `⊥` and `⊤`.
-/
universe u v
open CategoryTheory CategoryTheory.Limits
/-- A typeclass for nonempty finite linear orders. -/
class NonemptyFiniteLinearOrder (α : Type*) extends Fintype α, LinearOrder α where
Nonempty : Nonempty α := by infer_instance
attribute [instance] NonemptyFiniteLinearOrder.Nonempty
instance (priority := 100) NonemptyFiniteLinearOrder.toBoundedOrder (α : Type*)
[NonemptyFiniteLinearOrder α] : BoundedOrder α :=
Fintype.toBoundedOrder α
instance PUnit.nonemptyFiniteLinearOrder : NonemptyFiniteLinearOrder PUnit where
instance Fin.nonemptyFiniteLinearOrder (n : ℕ) : NonemptyFiniteLinearOrder (Fin (n + 1)) where
instance ULift.nonemptyFiniteLinearOrder (α : Type u) [NonemptyFiniteLinearOrder α] :
NonemptyFiniteLinearOrder (ULift.{v} α) :=
{ LinearOrder.lift' Equiv.ulift (Equiv.injective _) with }
instance (α : Type*) [NonemptyFiniteLinearOrder α] : NonemptyFiniteLinearOrder αᵒᵈ :=
{ OrderDual.fintype α with }
/-- The category of nonempty finite linear orders. -/
def NonemptyFinLinOrd :=
Bundled NonemptyFiniteLinearOrder
namespace NonemptyFinLinOrd
instance : BundledHom.ParentProjection @NonemptyFiniteLinearOrder.toLinearOrder :=
⟨⟩
deriving instance LargeCategory for NonemptyFinLinOrd
-- Porting note: probably see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory NonemptyFinLinOrd :=
BundledHom.concreteCategory _
instance : CoeSort NonemptyFinLinOrd Type* :=
Bundled.coeSort
/-- Construct a bundled `NonemptyFinLinOrd` from the underlying type and typeclass. -/
def of (α : Type*) [NonemptyFiniteLinearOrder α] : NonemptyFinLinOrd :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [NonemptyFiniteLinearOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited NonemptyFinLinOrd :=
⟨of PUnit⟩
instance (α : NonemptyFinLinOrd) : NonemptyFiniteLinearOrder α :=
α.str
instance hasForgetToLinOrd : HasForget₂ NonemptyFinLinOrd LinOrd :=
BundledHom.forget₂ _ _
instance hasForgetToFinPartOrd : HasForget₂ NonemptyFinLinOrd FinPartOrd where
forget₂ :=
{ obj := fun X => FinPartOrd.of X
map := @fun X Y => id }
/-- Constructs an equivalence between nonempty finite linear orders from an order isomorphism
between them. -/
@[simps]
def Iso.mk {α β : NonemptyFinLinOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom _ _)
inv := (e.symm : OrderHom _ _)
hom_inv_id := by
ext x
exact e.symm_apply_apply x
inv_hom_id := by
ext x
exact e.apply_symm_apply x
/-- `OrderDual` as a functor. -/
@[simps]
def dual : NonemptyFinLinOrd ⥤ NonemptyFinLinOrd where
obj X := of Xᵒᵈ
map := OrderHom.dual
/-- The equivalence between `NonemptyFinLinOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : NonemptyFinLinOrd ≌ NonemptyFinLinOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
instance {A B : NonemptyFinLinOrd.{u}} : FunLike (A ⟶ B) A B where
coe f := ⇑(show OrderHom A B from f)
coe_injective' _ _ h := by
ext x
exact congr_fun h x
-- porting note (#10670): this instance was not necessary in mathlib
instance {A B : NonemptyFinLinOrd.{u}} : OrderHomClass (A ⟶ B) A B where
map_rel f _ _ h := f.monotone h
theorem mono_iff_injective {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) :
Mono f ↔ Function.Injective f := by
refine ⟨?_, ConcreteCategory.mono_of_injective f⟩
intro
intro a₁ a₂ h
let X := NonemptyFinLinOrd.of (ULift (Fin 1))
let g₁ : X ⟶ A := ⟨fun _ => a₁, fun _ _ _ => by rfl⟩
let g₂ : X ⟶ A := ⟨fun _ => a₂, fun _ _ _ => by rfl⟩
change g₁ (ULift.up (0 : Fin 1)) = g₂ (ULift.up (0 : Fin 1))
have eq : g₁ ≫ f = g₂ ≫ f := by
ext
exact h
rw [cancel_mono] at eq
rw [eq]
-- Porting note: added to ease the following proof
lemma forget_map_apply {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) (a : A) :
(forget NonemptyFinLinOrd).map f a = (f : OrderHom A B).toFun a := rfl
theorem epi_iff_surjective {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) :
Epi f ↔ Function.Surjective f := by
constructor
· intro
dsimp only [Function.Surjective]
by_contra! hf'
rcases hf' with ⟨m, hm⟩
let Y := NonemptyFinLinOrd.of (ULift (Fin 2))
let p₁ : B ⟶ Y :=
⟨fun b => if b < m then ULift.up 0 else ULift.up 1, fun x₁ x₂ h => by
simp only
split_ifs with h₁ h₂ h₂
any_goals apply Fin.zero_le
· exfalso
exact h₁ (lt_of_le_of_lt h h₂)
· rfl⟩
let p₂ : B ⟶ Y :=
⟨fun b => if b ≤ m then ULift.up 0 else ULift.up 1, fun x₁ x₂ h => by
simp only
split_ifs with h₁ h₂ h₂
any_goals apply Fin.zero_le
· exfalso
exact h₁ (h.trans h₂)
· rfl⟩
have h : p₁ m = p₂ m := by
congr
rw [← cancel_epi f]
ext a
simp only [coe_of, comp_apply]
change ite _ _ _ = ite _ _ _
split_ifs with h₁ h₂ h₂
any_goals rfl
· exfalso
exact h₂ (le_of_lt h₁)
· exfalso
exact hm a (eq_of_le_of_not_lt h₂ h₁)
simp [Y, DFunLike.coe] at h
· intro h
exact ConcreteCategory.epi_of_surjective f h
instance : SplitEpiCategory NonemptyFinLinOrd.{u} :=
⟨fun {X Y} f hf => by
have H : ∀ y : Y, Nonempty (f ⁻¹' {y}) := by
rw [epi_iff_surjective] at hf
intro y
exact Nonempty.intro ⟨(hf y).choose, (hf y).choose_spec⟩
let φ : Y → X := fun y => (H y).some.1
have hφ : ∀ y : Y, f (φ y) = y := fun y => (H y).some.2
refine IsSplitEpi.mk' ⟨⟨φ, ?_⟩, ?_⟩
swap
· ext b
apply hφ
· intro a b
contrapose
intro h
simp only [not_le] at h ⊢
suffices b ≤ a by
apply lt_of_le_of_ne this
rintro rfl
exfalso
simp at h
have H : f (φ b) ≤ f (φ a) := f.monotone (le_of_lt h)
simpa only [hφ] using H⟩
instance : HasStrongEpiMonoFactorisations NonemptyFinLinOrd.{u} :=
⟨fun {X Y} f => by
letI : NonemptyFiniteLinearOrder (Set.image f ⊤) := ⟨by infer_instance⟩
let I := NonemptyFinLinOrd.of (Set.image f ⊤)
let e : X ⟶ I := ⟨fun x => ⟨f x, ⟨x, by tauto⟩⟩, fun x₁ x₂ h => f.monotone h⟩
let m : I ⟶ Y := ⟨fun y => y.1, by tauto⟩
haveI : Epi e := by
rw [epi_iff_surjective]
rintro ⟨_, y, h, rfl⟩
exact ⟨y, rfl⟩
haveI : StrongEpi e := strongEpi_of_epi e
haveI : Mono m := ConcreteCategory.mono_of_injective _ (fun x y h => Subtype.ext h)
exact ⟨⟨I, m, e, rfl⟩⟩⟩
end NonemptyFinLinOrd
theorem nonemptyFinLinOrd_dual_comp_forget_to_linOrd :
NonemptyFinLinOrd.dual ⋙ forget₂ NonemptyFinLinOrd LinOrd =
forget₂ NonemptyFinLinOrd LinOrd ⋙ LinOrd.dual :=
rfl
/-- The forgetful functor `NonemptyFinLinOrd ⥤ FinPartOrd` and `OrderDual` commute. -/
def nonemptyFinLinOrdDualCompForgetToFinPartOrd :
NonemptyFinLinOrd.dual ⋙ forget₂ NonemptyFinLinOrd FinPartOrd ≅
forget₂ NonemptyFinLinOrd FinPartOrd ⋙ FinPartOrd.dual where
hom := { app := fun X => OrderHom.id }
inv := { app := fun X => OrderHom.id }
|
Order\Category\OmegaCompletePartialOrder.lean | /-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Order.OmegaCompletePartialOrder
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.ConcreteCategory.BundledHom
/-!
# Category of types with an omega complete partial order
In this file, we bundle the class `OmegaCompletePartialOrder` into a
concrete category and prove that continuous functions also form
an `OmegaCompletePartialOrder`.
## Main definitions
* `ωCPO`
* an instance of `Category` and `ConcreteCategory`
-/
open CategoryTheory
universe u v
/-- The category of types with an omega complete partial order. -/
def ωCPO : Type (u + 1) :=
Bundled OmegaCompletePartialOrder
namespace ωCPO
open OmegaCompletePartialOrder
instance : BundledHom @ContinuousHom where
toFun := @ContinuousHom.Simps.apply
id := @ContinuousHom.id
comp := @ContinuousHom.comp
hom_ext := @ContinuousHom.coe_inj
-- Porting note: `deriving instance ConcreteCategory` didn't work.
deriving instance LargeCategory for ωCPO
instance : ConcreteCategory ωCPO := by unfold ωCPO; infer_instance
instance : CoeSort ωCPO Type* :=
Bundled.coeSort
/-- Construct a bundled ωCPO from the underlying type and typeclass. -/
def of (α : Type*) [OmegaCompletePartialOrder α] : ωCPO :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [OmegaCompletePartialOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited ωCPO :=
⟨of PUnit⟩
instance (α : ωCPO) : OmegaCompletePartialOrder α :=
α.str
section
open CategoryTheory.Limits
namespace HasProducts
/-- The pi-type gives a cone for a product. -/
def product {J : Type v} (f : J → ωCPO.{v}) : Fan f :=
Fan.mk (of (∀ j, f j)) fun j => .mk (Pi.evalOrderHom j) fun _ => rfl
/-- The pi-type is a limit cone for the product. -/
def isProduct (J : Type v) (f : J → ωCPO) : IsLimit (product f) where
lift s :=
-- Porting note: Original proof didn't have `.toFun`
⟨⟨fun t j => (s.π.app ⟨j⟩).toFun t, fun x y h j => (s.π.app ⟨j⟩).monotone h⟩,
fun x => funext fun j => (s.π.app ⟨j⟩).continuous x⟩
uniq s m w := by
ext t; funext j -- Porting note: Originally `ext t j`
change m.toFun t j = (s.π.app ⟨j⟩).toFun t
rw [← w ⟨j⟩]
rfl
fac s j := rfl
instance (J : Type v) (f : J → ωCPO.{v}) : HasProduct f :=
HasLimit.mk ⟨_, isProduct _ f⟩
end HasProducts
instance omegaCompletePartialOrderEqualizer {α β : Type*} [OmegaCompletePartialOrder α]
[OmegaCompletePartialOrder β] (f g : α →𝒄 β) :
OmegaCompletePartialOrder { a : α // f a = g a } :=
OmegaCompletePartialOrder.subtype _ fun c hc => by
rw [f.continuous, g.continuous]
congr 1
apply OrderHom.ext; funext x -- Porting note: Originally `ext`
apply hc _ ⟨_, rfl⟩
namespace HasEqualizers
/-- The equalizer inclusion function as a `ContinuousHom`. -/
def equalizerι {α β : Type*} [OmegaCompletePartialOrder α] [OmegaCompletePartialOrder β]
(f g : α →𝒄 β) : { a : α // f a = g a } →𝒄 α :=
.mk (OrderHom.Subtype.val _) fun _ => rfl
/-- A construction of the equalizer fork. -/
-- Porting note: Changed `{ a // f a = g a }` to `{ a // f.toFun a = g.toFun a }`
def equalizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : Fork f g :=
Fork.ofι (P := ωCPO.of { a // f.toFun a = g.toFun a }) (equalizerι f g)
(ContinuousHom.ext _ _ fun x => x.2)
/-- The equalizer fork is a limit. -/
def isEqualizer {X Y : ωCPO.{v}} (f g : X ⟶ Y) : IsLimit (equalizer f g) :=
Fork.IsLimit.mk' _ fun s =>
-- Porting note: Changed `s.ι x` to `s.ι.toFun x`
⟨{ toFun := fun x => ⟨s.ι.toFun x, by apply ContinuousHom.congr_fun s.condition⟩
monotone' := fun x y h => s.ι.monotone h
cont := fun x => Subtype.ext (s.ι.continuous x) }, by ext; rfl, fun hm => by
apply ContinuousHom.ext _ _ fun x => Subtype.ext ?_ -- Porting note: Originally `ext`
apply ContinuousHom.congr_fun hm⟩
end HasEqualizers
instance : HasProducts.{v} ωCPO.{v} :=
fun _ => { has_limit := fun _ => hasLimitOfIso Discrete.natIsoFunctor.symm }
instance {X Y : ωCPO.{v}} (f g : X ⟶ Y) : HasLimit (parallelPair f g) :=
HasLimit.mk ⟨_, HasEqualizers.isEqualizer f g⟩
instance : HasEqualizers ωCPO.{v} :=
hasEqualizers_of_hasLimit_parallelPair _
instance : HasLimits ωCPO.{v} :=
has_limits_of_hasEqualizers_and_products
end
end ωCPO
|
Order\Category\PartOrd.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Order.Antisymmetrization
import Mathlib.Order.Category.Preord
import Mathlib.CategoryTheory.Adjunction.Basic
/-!
# Category of partial orders
This defines `PartOrd`, the category of partial orders with monotone maps.
-/
open CategoryTheory
universe u
/-- The category of partially ordered types. -/
def PartOrd :=
Bundled PartialOrder
namespace PartOrd
instance : BundledHom.ParentProjection @PartialOrder.toPreorder :=
⟨⟩
deriving instance LargeCategory for PartOrd
-- Porting note: probably see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory PartOrd :=
BundledHom.concreteCategory _
instance : CoeSort PartOrd Type* :=
Bundled.coeSort
/-- Construct a bundled PartOrd from the underlying type and typeclass. -/
def of (α : Type*) [PartialOrder α] : PartOrd :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [PartialOrder α] : ↥(of α) = α :=
rfl
instance : Inhabited PartOrd :=
⟨of PUnit⟩
instance (α : PartOrd) : PartialOrder α :=
α.str
instance hasForgetToPreord : HasForget₂ PartOrd Preord :=
BundledHom.forget₂ _ _
/-- Constructs an equivalence between partial orders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : PartOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom α β)
inv := (e.symm : OrderHom β α)
hom_inv_id := by
ext x
exact e.symm_apply_apply x
inv_hom_id := by
ext x
exact e.apply_symm_apply x
/-- `OrderDual` as a functor. -/
@[simps]
def dual : PartOrd ⥤ PartOrd where
obj X := of Xᵒᵈ
map := OrderHom.dual
/-- The equivalence between `PartOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : PartOrd ≌ PartOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end PartOrd
theorem partOrd_dual_comp_forget_to_preord :
PartOrd.dual ⋙ forget₂ PartOrd Preord =
forget₂ PartOrd Preord ⋙ Preord.dual :=
rfl
/-- `Antisymmetrization` as a functor. It is the free functor. -/
def preordToPartOrd : Preord.{u} ⥤ PartOrd where
obj X := PartOrd.of (Antisymmetrization X (· ≤ ·))
map f := f.antisymmetrization
map_id X := by
ext x
exact Quotient.inductionOn' x fun x => Quotient.map'_mk'' _ (fun a b => id) _
map_comp f g := by
ext x
exact Quotient.inductionOn' x fun x => OrderHom.antisymmetrization_apply_mk _ _
/-- `preordToPartOrd` is left adjoint to the forgetful functor, meaning it is the free
functor from `Preord` to `PartOrd`. -/
def preordToPartOrdForgetAdjunction :
preordToPartOrd.{u} ⊣ forget₂ PartOrd Preord :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun _ _ =>
{ toFun := fun f =>
⟨f.toFun ∘ toAntisymmetrization (· ≤ ·), f.mono.comp toAntisymmetrization_mono⟩
invFun := fun f =>
⟨fun a => Quotient.liftOn' a f.toFun (fun _ _ h => (AntisymmRel.image h f.mono).eq),
fun a b => Quotient.inductionOn₂' a b fun _ _ h => f.mono h⟩
left_inv := fun _ =>
OrderHom.ext _ _ <| funext fun x => Quotient.inductionOn' x fun _ => rfl
right_inv := fun _ => OrderHom.ext _ _ <| funext fun _ => rfl }
homEquiv_naturality_left_symm := fun _ _ =>
OrderHom.ext _ _ <| funext fun x => Quotient.inductionOn' x fun _ => rfl
homEquiv_naturality_right := fun _ _ => OrderHom.ext _ _ <| funext fun _ => rfl }
-- The `simpNF` linter would complain as `Functor.comp_obj`, `Preord.dual_obj` both apply to LHS
-- of `preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd_hom_app_coe`
/-- `PreordToPartOrd` and `OrderDual` commute. -/
@[simps! inv_app_coe, simps! (config := .lemmasOnly) hom_app_coe]
def preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd :
preordToPartOrd.{u} ⋙ PartOrd.dual ≅ Preord.dual ⋙ preordToPartOrd :=
NatIso.ofComponents (fun _ => PartOrd.Iso.mk <| OrderIso.dualAntisymmetrization _)
(fun _ => OrderHom.ext _ _ <| funext fun x => Quotient.inductionOn' x fun _ => rfl)
-- This lemma was always bad, but the linter only noticed after lean4#2644
attribute [nolint simpNF] preordToPartOrdCompToDualIsoToDualCompPreordToPartOrd_inv_app_coe
|
Order\Category\Preord.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.ConcreteCategory.BundledHom
import Mathlib.Order.Hom.Basic
import Mathlib.Order.CompleteBooleanAlgebra
/-!
# Category of preorders
This defines `Preord`, the category of preorders with monotone maps.
-/
universe u
open CategoryTheory
/-- The category of preorders. -/
def Preord :=
Bundled Preorder
namespace Preord
instance : BundledHom @OrderHom where
toFun := @OrderHom.toFun
id := @OrderHom.id
comp := @OrderHom.comp
hom_ext := @OrderHom.ext
deriving instance LargeCategory for Preord
-- Porting note: probably see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory Preord :=
BundledHom.concreteCategory _
instance : CoeSort Preord Type* :=
Bundled.coeSort
/-- Construct a bundled Preord from the underlying type and typeclass. -/
def of (α : Type*) [Preorder α] : Preord :=
Bundled.of α
@[simp]
theorem coe_of (α : Type*) [Preorder α] : ↥(of α) = α :=
rfl
instance : Inhabited Preord :=
⟨of PUnit⟩
instance (α : Preord) : Preorder α :=
α.str
/-- Constructs an equivalence between preorders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : Preord.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom α β)
inv := (e.symm : OrderHom β α)
hom_inv_id := by
ext x
exact e.symm_apply_apply x
inv_hom_id := by
ext x
exact e.apply_symm_apply x
/-- `OrderDual` as a functor. -/
@[simps]
def dual : Preord ⥤ Preord where
obj X := of Xᵒᵈ
map := OrderHom.dual
/-- The equivalence between `Preord` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : Preord ≌ Preord where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end Preord
/-- The embedding of `Preord` into `Cat`.
-/
@[simps]
def preordToCat : Preord.{u} ⥤ Cat where
obj X := Cat.of X.1
map f := f.monotone.functor
instance : preordToCat.{u}.Faithful where
map_injective h := by ext x; exact Functor.congr_obj h x
instance : preordToCat.{u}.Full where
map_surjective {X Y} f := ⟨⟨f.obj, @CategoryTheory.Functor.monotone X Y _ _ f⟩, rfl⟩
|
Order\Category\Semilat.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Category.PartOrd
import Mathlib.Order.Hom.Lattice
/-!
# The categories of semilattices
This defines `SemilatSupCat` and `SemilatInfCat`, the categories of sup-semilattices with a bottom
element and inf-semilattices with a top element.
## References
* [nLab, *semilattice*](https://ncatlab.org/nlab/show/semilattice)
-/
universe u
open CategoryTheory
/-- The category of sup-semilattices with a bottom element. -/
structure SemilatSupCat : Type (u + 1) where
/-- The underlying type of a sup-semilattice with a bottom element. -/
protected X : Type u
[isSemilatticeSup : SemilatticeSup X]
[isOrderBot : OrderBot.{u} X]
/-- The category of inf-semilattices with a top element. -/
structure SemilatInfCat : Type (u + 1) where
/-- The underlying type of an inf-semilattice with a top element. -/
protected X : Type u
[isSemilatticeInf : SemilatticeInf X]
[isOrderTop : OrderTop.{u} X]
namespace SemilatSupCat
instance : CoeSort SemilatSupCat Type* :=
⟨SemilatSupCat.X⟩
attribute [instance] isSemilatticeSup isOrderBot
/-- Construct a bundled `SemilatSupCat` from a `SemilatticeSup`. -/
def of (α : Type*) [SemilatticeSup α] [OrderBot α] : SemilatSupCat :=
⟨α⟩
@[simp]
theorem coe_of (α : Type*) [SemilatticeSup α] [OrderBot α] : ↥(of α) = α :=
rfl
instance : Inhabited SemilatSupCat :=
⟨of PUnit⟩
instance : LargeCategory.{u} SemilatSupCat where
Hom X Y := SupBotHom X Y
id X := SupBotHom.id X
comp f g := g.comp f
id_comp := SupBotHom.comp_id
comp_id := SupBotHom.id_comp
assoc _ _ _ := SupBotHom.comp_assoc _ _ _
-- Porting note: added
-- see https://github.com/leanprover-community/mathlib4/issues/5017
instance instFunLike (X Y : SemilatSupCat) : FunLike (X ⟶ Y) X Y :=
show FunLike (SupBotHom X Y) X Y from inferInstance
instance : ConcreteCategory SemilatSupCat where
forget :=
{ obj := SemilatSupCat.X
map := DFunLike.coe }
forget_faithful := ⟨(DFunLike.coe_injective ·)⟩
instance hasForgetToPartOrd : HasForget₂ SemilatSupCat PartOrd where
forget₂ :=
-- Porting note: was ⟨X⟩, see https://github.com/leanprover-community/mathlib4/issues/4998
{ obj := fun X => {α := X}
-- Porting note: was `map := fun f => f`
map := fun f => ⟨f.toSupHom, OrderHomClass.mono f.toSupHom⟩ }
@[simp]
theorem coe_forget_to_partOrd (X : SemilatSupCat) :
↥((forget₂ SemilatSupCat PartOrd).obj X) = ↥X :=
rfl
end SemilatSupCat
namespace SemilatInfCat
instance : CoeSort SemilatInfCat Type* :=
⟨SemilatInfCat.X⟩
attribute [instance] isSemilatticeInf isOrderTop
/-- Construct a bundled `SemilatInfCat` from a `SemilatticeInf`. -/
def of (α : Type*) [SemilatticeInf α] [OrderTop α] : SemilatInfCat :=
⟨α⟩
@[simp]
theorem coe_of (α : Type*) [SemilatticeInf α] [OrderTop α] : ↥(of α) = α :=
rfl
instance : Inhabited SemilatInfCat :=
⟨of PUnit⟩
instance : LargeCategory.{u} SemilatInfCat where
Hom X Y := InfTopHom X Y
id X := InfTopHom.id X
comp f g := g.comp f
id_comp := InfTopHom.comp_id
comp_id := InfTopHom.id_comp
assoc _ _ _ := InfTopHom.comp_assoc _ _ _
-- Porting note (#10754): added instance
instance instFunLike (X Y : SemilatInfCat) : FunLike (X ⟶ Y) X Y :=
show FunLike (InfTopHom X Y) X Y from inferInstance
instance : ConcreteCategory SemilatInfCat where
forget :=
{ obj := SemilatInfCat.X
map := DFunLike.coe }
forget_faithful := ⟨(DFunLike.coe_injective ·)⟩
instance hasForgetToPartOrd : HasForget₂ SemilatInfCat PartOrd where
forget₂ :=
{ obj := fun X => ⟨X, inferInstance⟩
-- Porting note: was `map := fun f => f`
map := fun f => ⟨f.toInfHom, OrderHomClass.mono f.toInfHom⟩ }
@[simp]
theorem coe_forget_to_partOrd (X : SemilatInfCat) :
↥((forget₂ SemilatInfCat PartOrd).obj X) = ↥X :=
rfl
end SemilatInfCat
/-! ### Order dual -/
namespace SemilatSupCat
/-- Constructs an isomorphism of lattices from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : SemilatSupCat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : SupBotHom _ _)
inv := (e.symm : SupBotHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : SemilatSupCat ⥤ SemilatInfCat where
obj X := SemilatInfCat.of Xᵒᵈ
map {X Y} := SupBotHom.dual
end SemilatSupCat
namespace SemilatInfCat
/-- Constructs an isomorphism of lattices from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : SemilatInfCat.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : InfTopHom _ _)
inv := (e.symm : InfTopHom _ _)
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps]
def dual : SemilatInfCat ⥤ SemilatSupCat where
obj X := SemilatSupCat.of Xᵒᵈ
map {X Y} := InfTopHom.dual
end SemilatInfCat
/-- The equivalence between `SemilatSupCat` and `SemilatInfCat` induced by `OrderDual` both ways. -/
@[simps functor inverse]
def SemilatSupCatEquivSemilatInfCat : SemilatSupCat ≌ SemilatInfCat where
functor := SemilatSupCat.dual
inverse := SemilatInfCat.dual
unitIso := NatIso.ofComponents fun X => SemilatSupCat.Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => SemilatInfCat.Iso.mk <| OrderIso.dualDual X
theorem SemilatSupCat_dual_comp_forget_to_partOrd :
SemilatSupCat.dual ⋙ forget₂ SemilatInfCat PartOrd =
forget₂ SemilatSupCat PartOrd ⋙ PartOrd.dual :=
rfl
theorem SemilatInfCat_dual_comp_forget_to_partOrd :
SemilatInfCat.dual ⋙ forget₂ SemilatSupCat PartOrd =
forget₂ SemilatInfCat PartOrd ⋙ PartOrd.dual :=
rfl
|
Order\CompactlyGenerated\Basic.lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.Atoms
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.RelIso.Set
import Mathlib.Order.SupClosed
import Mathlib.Order.SupIndep
import Mathlib.Order.Zorn
import Mathlib.Data.Finset.Order
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Data.Finite.Set
import Mathlib.Tactic.TFAE
/-!
# Compactness properties for complete lattices
For complete lattices, there are numerous equivalent ways to express the fact that the relation `>`
is well-founded. In this file we define three especially-useful characterisations and provide
proofs that they are indeed equivalent to well-foundedness.
## Main definitions
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `CompleteLattice.IsCompactElement`
* `IsCompactlyGenerated`
## Main results
The main result is that the following four conditions are equivalent for a complete lattice:
* `well_founded (>)`
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `∀ k, CompleteLattice.IsCompactElement k`
This is demonstrated by means of the following four lemmas:
* `CompleteLattice.WellFounded.isSupFiniteCompact`
* `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact`
* `CompleteLattice.IsSupClosedCompact.wellFounded`
* `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact`
We also show well-founded lattices are compactly generated
(`CompleteLattice.isCompactlyGenerated_of_wellFounded`).
## References
- [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu]
## Tags
complete lattice, well-founded, compact
-/
open Set
variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α}
namespace CompleteLattice
variable (α)
/-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset
contains its `sSup`. -/
def IsSupClosedCompact : Prop :=
∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s
/-- A compactness property for a complete lattice is that any subset has a finite subset with the
same `sSup`. -/
def IsSupFiniteCompact : Prop :=
∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id
/-- An element `k` of a complete lattice is said to be compact if any set with `sSup`
above `k` has a finite subset with `sSup` above `k`. Such an element is also called
"finite" or "S-compact". -/
def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) :=
∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id
theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) :
CompleteLattice.IsCompactElement k ↔
∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by
classical
constructor
· intro H ι s hs
obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs
have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop
choose f hf using this
refine ⟨Finset.univ.image f, ht'.trans ?_⟩
rw [Finset.sup_le_iff]
intro b hb
rw [← show s (f ⟨b, hb⟩) = id b from hf _]
exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb))
· intro H s hs
obtain ⟨t, ht⟩ :=
H s Subtype.val
(by
delta iSup
rwa [Subtype.range_coe])
refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩
rw [Finset.sup_le_iff]
exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx)
/-- An element `k` is compact if and only if any directed set with `sSup` above
`k` already got above `k` at some point in the set. -/
theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) :
IsCompactElement k ↔
∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by
classical
constructor
· intro hk s hne hdir hsup
obtain ⟨t, ht⟩ := hk s hsup
-- certainly every element of t is below something in s, since ↑t ⊆ s.
have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩
obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s
exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩
· intro hk s hsup
-- Consider the set of finite joins of elements of the (plain) set s.
let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id }
-- S is directed, nonempty, and still has sup above k.
have dir_US : DirectedOn (· ≤ ·) S := by
rintro x ⟨c, hc⟩ y ⟨d, hd⟩
use x ⊔ y
constructor
· use c ∪ d
constructor
· simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff]
· simp only [hc.right, hd.right, Finset.sup_union]
simp only [and_self_iff, le_sup_left, le_sup_right]
have sup_S : sSup s ≤ sSup S := by
apply sSup_le_sSup
intro x hx
use {x}
simpa only [and_true_iff, id, Finset.coe_singleton, eq_self_iff_true,
Finset.sup_singleton, Set.singleton_subset_iff]
have Sne : S.Nonempty := by
suffices ⊥ ∈ S from Set.nonempty_of_mem this
use ∅
simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, eq_self_iff_true,
and_self_iff]
-- Now apply the defn of compact and finish.
obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S)
obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS
use t
exact ⟨htS, by rwa [← htsup]⟩
theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*}
(f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by
classical
let g : Finset ι → α := fun s => ⨆ i ∈ s, f i
have h1 : DirectedOn (· ≤ ·) (Set.range g) := by
rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩
exact
⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left,
iSup_le_iSup_of_subset Finset.subset_union_right⟩
have h2 : k ≤ sSup (Set.range g) :=
h.trans
(iSup_le fun i =>
le_sSup_of_le ⟨{i}, rfl⟩
(le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl)))
obtain ⟨-, ⟨s, rfl⟩, hs⟩ :=
(isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g)
h1 h2
exact ⟨s, hs⟩
/-- A compact element `k` has the property that any directed set lying strictly below `k` has
its `sSup` strictly below `k`. -/
theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α}
(hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s)
(hbelow : ∀ x ∈ s, x < k) : sSup s < k := by
rw [isCompactElement_iff_le_of_directed_sSup_le] at hk
by_contra h
have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le
replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩
obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le
obtain hxk := hbelow x hxs
exact hxk.ne (hxk.le.antisymm hkx)
theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β)
(h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by
classical
rw [isCompactElement_iff_le_of_directed_sSup_le]
intro d hemp hdir hsup
rw [← Function.id_comp f]
rw [← Finset.sup_image]
apply Finset.sup_le_of_le_directed d hemp hdir
rintro x hx
obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx
specialize h p hps
rw [isCompactElement_iff_le_of_directed_sSup_le] at h
specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup)
simpa only [exists_prop]
theorem WellFounded.isSupFiniteCompact (h : WellFounded ((· > ·) : α → α → Prop)) :
IsSupFiniteCompact α := fun s => by
let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x }
obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := h.has_min S ⟨⊥, ∅, by simp⟩
refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩
· classical
rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y))
(hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)]
simp
· rw [Finset.sup_id_eq_sSup]
exact sSup_le_sSup ht₁
theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) :
IsSupClosedCompact α := by
intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h
rcases t.eq_empty_or_nonempty with h | h
· subst h
rw [Finset.sup_empty] at ht₂
rw [ht₂]
simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne]
· rw [ht₂]
exact hsc.finsetSup_mem h ht₁
theorem IsSupClosedCompact.wellFounded (h : IsSupClosedCompact α) :
WellFounded ((· > ·) : α → α → Prop) := by
refine RelEmbedding.wellFounded_iff_no_descending_seq.mpr ⟨fun a => ?_⟩
suffices sSup (Set.range a) ∈ Set.range a by
obtain ⟨n, hn⟩ := Set.mem_range.mp this
have h' : sSup (Set.range a) < a (n + 1) := by
change _ > _
simp [← hn, a.map_rel_iff]
apply lt_irrefl (a (n + 1))
apply lt_of_le_of_lt _ h'
apply le_sSup
apply Set.mem_range_self
apply h (Set.range a)
· use a 37
apply Set.mem_range_self
· rintro x ⟨m, hm⟩ y ⟨n, hn⟩
use m ⊔ n
rw [← hm, ← hn]
apply RelHomClass.map_sup a
theorem isSupFiniteCompact_iff_all_elements_compact :
IsSupFiniteCompact α ↔ ∀ k : α, IsCompactElement k := by
refine ⟨fun h k s hs => ?_, fun h s => ?_⟩
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h s
use t, hts
rwa [← htsup]
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h (sSup s) s (by rfl)
have : sSup s = t.sup id := by
suffices t.sup id ≤ sSup s by apply le_antisymm <;> assumption
simp only [id, Finset.sup_le_iff]
intro x hx
exact le_sSup _ _ (hts hx)
exact ⟨t, hts, this⟩
open List in
theorem wellFounded_characterisations : List.TFAE
[WellFounded ((· > ·) : α → α → Prop),
IsSupFiniteCompact α, IsSupClosedCompact α, ∀ k : α, IsCompactElement k] := by
tfae_have 1 → 2
· exact WellFounded.isSupFiniteCompact α
tfae_have 2 → 3
· exact IsSupFiniteCompact.isSupClosedCompact α
tfae_have 3 → 1
· exact IsSupClosedCompact.wellFounded α
tfae_have 2 ↔ 4
· exact isSupFiniteCompact_iff_all_elements_compact α
tfae_finish
theorem wellFounded_iff_isSupFiniteCompact :
WellFounded ((· > ·) : α → α → Prop) ↔ IsSupFiniteCompact α :=
(wellFounded_characterisations α).out 0 1
theorem isSupFiniteCompact_iff_isSupClosedCompact : IsSupFiniteCompact α ↔ IsSupClosedCompact α :=
(wellFounded_characterisations α).out 1 2
theorem isSupClosedCompact_iff_wellFounded :
IsSupClosedCompact α ↔ WellFounded ((· > ·) : α → α → Prop) :=
(wellFounded_characterisations α).out 2 0
alias ⟨_, IsSupFiniteCompact.wellFounded⟩ := wellFounded_iff_isSupFiniteCompact
alias ⟨_, IsSupClosedCompact.isSupFiniteCompact⟩ := isSupFiniteCompact_iff_isSupClosedCompact
alias ⟨_, _root_.WellFounded.isSupClosedCompact⟩ := isSupClosedCompact_iff_wellFounded
variable {α}
theorem WellFounded.finite_of_setIndependent (h : WellFounded ((· > ·) : α → α → Prop)) {s : Set α}
(hs : SetIndependent s) : s.Finite := by
classical
refine Set.not_infinite.mp fun contra => ?_
obtain ⟨t, ht₁, ht₂⟩ := WellFounded.isSupFiniteCompact α h s
replace contra : ∃ x : α, x ∈ s ∧ x ≠ ⊥ ∧ x ∉ t := by
have : (s \ (insert ⊥ t : Finset α)).Infinite := contra.diff (Finset.finite_toSet _)
obtain ⟨x, hx₁, hx₂⟩ := this.nonempty
exact ⟨x, hx₁, by simpa [not_or] using hx₂⟩
obtain ⟨x, hx₀, hx₁, hx₂⟩ := contra
replace hs : x ⊓ sSup s = ⊥ := by
have := hs.mono (by simp [ht₁, hx₀, -Set.union_singleton] : ↑t ∪ {x} ≤ s) (by simp : x ∈ _)
simpa [Disjoint, hx₂, ← t.sup_id_eq_sSup, ← ht₂] using this.eq_bot
apply hx₁
rw [← hs, eq_comm, inf_eq_left]
exact le_sSup _ _ hx₀
theorem WellFounded.finite_ne_bot_of_independent (hwf : WellFounded ((· > ·) : α → α → Prop))
{ι : Type*} {t : ι → α} (ht : Independent t) : Set.Finite {i | t i ≠ ⊥} := by
refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn
exact WellFounded.finite_of_setIndependent hwf ht.setIndependent_range
theorem WellFounded.finite_of_independent (hwf : WellFounded ((· > ·) : α → α → Prop)) {ι : Type*}
{t : ι → α} (ht : Independent t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι :=
haveI := (WellFounded.finite_of_setIndependent hwf ht.setIndependent_range).to_subtype
Finite.of_injective_finite_range (ht.injective h_ne_bot)
end CompleteLattice
/-- A complete lattice is said to be compactly generated if any
element is the `sSup` of compact elements. -/
class IsCompactlyGenerated (α : Type*) [CompleteLattice α] : Prop where
/-- In a compactly generated complete lattice,
every element is the `sSup` of some set of compact elements. -/
exists_sSup_eq : ∀ x : α, ∃ s : Set α, (∀ x ∈ s, CompleteLattice.IsCompactElement x) ∧ sSup s = x
section
variable [IsCompactlyGenerated α] {a b : α} {s : Set α}
@[simp]
theorem sSup_compact_le_eq (b) :
sSup { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } = b := by
rcases IsCompactlyGenerated.exists_sSup_eq b with ⟨s, hs, rfl⟩
exact le_antisymm (sSup_le fun c hc => hc.2) (sSup_le_sSup fun c cs => ⟨hs c cs, le_sSup cs⟩)
@[simp]
theorem sSup_compact_eq_top : sSup { a : α | CompleteLattice.IsCompactElement a } = ⊤ := by
refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_compact_le_eq ⊤)
exact (and_iff_left le_top).symm
theorem le_iff_compact_le_imp {a b : α} :
a ≤ b ↔ ∀ c : α, CompleteLattice.IsCompactElement c → c ≤ a → c ≤ b :=
⟨fun ab c _ ca => le_trans ca ab, fun h => by
rw [← sSup_compact_le_eq a, ← sSup_compact_le_eq b]
exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩
/-- This property is sometimes referred to as `α` being upper continuous. -/
theorem DirectedOn.inf_sSup_eq (h : DirectedOn (· ≤ ·) s) : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b :=
le_antisymm
(by
rw [le_iff_compact_le_imp]
by_cases hs : s.Nonempty
· intro c hc hcinf
rw [le_inf_iff] at hcinf
rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] at hc
rcases hc s hs h hcinf.2 with ⟨d, ds, cd⟩
refine (le_inf hcinf.1 cd).trans (le_trans ?_ (le_iSup₂ d ds))
rfl
· rw [Set.not_nonempty_iff_eq_empty] at hs
simp [hs])
iSup_inf_le_inf_sSup
/-- This property is sometimes referred to as `α` being upper continuous. -/
protected theorem DirectedOn.sSup_inf_eq (h : DirectedOn (· ≤ ·) s) :
sSup s ⊓ a = ⨆ b ∈ s, b ⊓ a := by
simp_rw [inf_comm _ a, h.inf_sSup_eq]
protected theorem Directed.inf_iSup_eq (h : Directed (· ≤ ·) f) :
(a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by
rw [iSup, h.directedOn_range.inf_sSup_eq, iSup_range]
protected theorem Directed.iSup_inf_eq (h : Directed (· ≤ ·) f) :
(⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by
rw [iSup, h.directedOn_range.sSup_inf_eq, iSup_range]
protected theorem DirectedOn.disjoint_sSup_right (h : DirectedOn (· ≤ ·) s) :
Disjoint a (sSup s) ↔ ∀ ⦃b⦄, b ∈ s → Disjoint a b := by
simp_rw [disjoint_iff, h.inf_sSup_eq, iSup_eq_bot]
protected theorem DirectedOn.disjoint_sSup_left (h : DirectedOn (· ≤ ·) s) :
Disjoint (sSup s) a ↔ ∀ ⦃b⦄, b ∈ s → Disjoint b a := by
simp_rw [disjoint_iff, h.sSup_inf_eq, iSup_eq_bot]
protected theorem Directed.disjoint_iSup_right (h : Directed (· ≤ ·) f) :
Disjoint a (⨆ i, f i) ↔ ∀ i, Disjoint a (f i) := by
simp_rw [disjoint_iff, h.inf_iSup_eq, iSup_eq_bot]
protected theorem Directed.disjoint_iSup_left (h : Directed (· ≤ ·) f) :
Disjoint (⨆ i, f i) a ↔ ∀ i, Disjoint (f i) a := by
simp_rw [disjoint_iff, h.iSup_inf_eq, iSup_eq_bot]
/-- This property is equivalent to `α` being upper continuous. -/
theorem inf_sSup_eq_iSup_inf_sup_finset :
a ⊓ sSup s = ⨆ (t : Finset α) (_ : ↑t ⊆ s), a ⊓ t.sup id :=
le_antisymm
(by
rw [le_iff_compact_le_imp]
intro c hc hcinf
rw [le_inf_iff] at hcinf
rcases hc s hcinf.2 with ⟨t, ht1, ht2⟩
refine (le_inf hcinf.1 ht2).trans (le_trans ?_ (le_iSup₂ t ht1))
rfl)
(iSup_le fun t =>
iSup_le fun h => inf_le_inf_left _ ((Finset.sup_id_eq_sSup t).symm ▸ sSup_le_sSup h))
theorem CompleteLattice.setIndependent_iff_finite {s : Set α} :
CompleteLattice.SetIndependent s ↔
∀ t : Finset α, ↑t ⊆ s → CompleteLattice.SetIndependent (↑t : Set α) :=
⟨fun hs t ht => hs.mono ht, fun h a ha => by
rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot]
intro t
rw [iSup_eq_bot, Finset.sup_id_eq_sSup]
intro ht
classical
have h' := (h (insert a t) ?_ (t.mem_insert_self a)).eq_bot
· rwa [Finset.coe_insert, Set.insert_diff_self_of_not_mem] at h'
exact fun con => ((Set.mem_diff a).1 (ht con)).2 (Set.mem_singleton a)
· rw [Finset.coe_insert, Set.insert_subset_iff]
exact ⟨ha, Set.Subset.trans ht diff_subset⟩⟩
lemma CompleteLattice.independent_iff_supIndep_of_injOn {ι : Type*} {f : ι → α}
(hf : InjOn f {i | f i ≠ ⊥}) :
CompleteLattice.Independent f ↔ ∀ (s : Finset ι), s.SupIndep f := by
refine ⟨fun h ↦ h.supIndep', fun h ↦ CompleteLattice.independent_def'.mpr fun i ↦ ?_⟩
simp_rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot, ← disjoint_iff]
intro s hs
classical
rw [← Finset.sup_erase_bot]
set t := s.erase ⊥
replace hf : InjOn f (f ⁻¹' t) := fun i hi j _ hij ↦ by
refine hf ?_ ?_ hij <;> aesop (add norm simp [t])
have : (Finset.erase (insert i (t.preimage _ hf)) i).image f = t := by
ext a
simp only [Finset.mem_preimage, Finset.mem_erase, ne_eq, Finset.mem_insert, true_or, not_true,
Finset.erase_insert_eq_erase, not_and, Finset.mem_image, t]
refine ⟨by aesop, fun ⟨ha, has⟩ ↦ ?_⟩
obtain ⟨j, hj, rfl⟩ := hs has
exact ⟨j, ⟨hj, ha, has⟩, rfl⟩
rw [← this, Finset.sup_image]
specialize h (insert i (t.preimage _ hf))
rw [Finset.supIndep_iff_disjoint_erase] at h
exact h i (Finset.mem_insert_self i _)
theorem CompleteLattice.setIndependent_iUnion_of_directed {η : Type*} {s : η → Set α}
(hs : Directed (· ⊆ ·) s) (h : ∀ i, CompleteLattice.SetIndependent (s i)) :
CompleteLattice.SetIndependent (⋃ i, s i) := by
by_cases hη : Nonempty η
· rw [CompleteLattice.setIndependent_iff_finite]
intro t ht
obtain ⟨I, fi, hI⟩ := Set.finite_subset_iUnion t.finite_toSet ht
obtain ⟨i, hi⟩ := hs.finset_le fi.toFinset
exact (h i).mono
(Set.Subset.trans hI <| Set.iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj))
· rintro a ⟨_, ⟨i, _⟩, _⟩
exfalso
exact hη ⟨i⟩
theorem CompleteLattice.independent_sUnion_of_directed {s : Set (Set α)} (hs : DirectedOn (· ⊆ ·) s)
(h : ∀ a ∈ s, CompleteLattice.SetIndependent a) : CompleteLattice.SetIndependent (⋃₀ s) := by
rw [Set.sUnion_eq_iUnion]
exact CompleteLattice.setIndependent_iUnion_of_directed hs.directed_val (by simpa using h)
end
namespace CompleteLattice
theorem isCompactlyGenerated_of_wellFounded (h : WellFounded ((· > ·) : α → α → Prop)) :
IsCompactlyGenerated α := by
rw [wellFounded_iff_isSupFiniteCompact, isSupFiniteCompact_iff_all_elements_compact] at h
-- x is the join of the set of compact elements {x}
exact ⟨fun x => ⟨{x}, ⟨fun x _ => h x, sSup_singleton⟩⟩⟩
/-- A compact element `k` has the property that any `b < k` lies below a "maximal element below
`k`", which is to say `[⊥, k]` is coatomic. -/
theorem Iic_coatomic_of_compact_element {k : α} (h : IsCompactElement k) :
IsCoatomic (Set.Iic k) := by
constructor
rintro ⟨b, hbk⟩
obtain rfl | H := eq_or_ne b k
· left; ext; simp only [Set.Iic.coe_top, Subtype.coe_mk]
right
have ⟨a, a₀, ba, h⟩ := zorn_nonempty_partialOrder₀ (Set.Iio k) ?_ b (lt_of_le_of_ne hbk H)
· refine ⟨⟨a, le_of_lt a₀⟩, ⟨ne_of_lt a₀, fun c hck => by_contradiction fun c₀ => ?_⟩, ba⟩
cases h c.1 (lt_of_le_of_ne c.2 fun con => c₀ (Subtype.ext con)) hck.le
exact lt_irrefl _ hck
· intro S SC cC I _
by_cases hS : S.Nonempty
· refine ⟨sSup S, h.directed_sSup_lt_of_lt hS cC.directedOn SC, ?_⟩
intro; apply le_sSup
exact
⟨b, lt_of_le_of_ne hbk H, by
simp only [Set.not_nonempty_iff_eq_empty.mp hS, Set.mem_empty_iff_false, forall_const,
forall_prop_of_false, not_false_iff]⟩
theorem coatomic_of_top_compact (h : IsCompactElement (⊤ : α)) : IsCoatomic α :=
(@OrderIso.IicTop α _ _).isCoatomic_iff.mp (Iic_coatomic_of_compact_element h)
end CompleteLattice
section
variable [IsModularLattice α] [IsCompactlyGenerated α]
instance (priority := 100) isAtomic_of_complementedLattice [ComplementedLattice α] : IsAtomic α :=
⟨fun b => by
by_cases h : { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } ⊆ {⊥}
· left
rw [← sSup_compact_le_eq b, sSup_eq_bot]
exact h
· rcases Set.not_subset.1 h with ⟨c, ⟨hc, hcb⟩, hcbot⟩
right
have hc' := CompleteLattice.Iic_coatomic_of_compact_element hc
rw [← isAtomic_iff_isCoatomic] at hc'
haveI := hc'
obtain con | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le (⟨c, le_refl c⟩ : Set.Iic c)
· exfalso
apply hcbot
simp only [Subtype.ext_iff, Set.Iic.coe_bot, Subtype.coe_mk] at con
exact con
rw [← Subtype.coe_le_coe, Subtype.coe_mk] at hac
exact ⟨a, ha.of_isAtom_coe_Iic, hac.trans hcb⟩⟩
/-- See [Lemma 5.1][calugareanu]. -/
instance (priority := 100) isAtomistic_of_complementedLattice [ComplementedLattice α] :
IsAtomistic α :=
⟨fun b =>
⟨{ a | IsAtom a ∧ a ≤ b }, by
symm
have hle : sSup { a : α | IsAtom a ∧ a ≤ b } ≤ b := sSup_le fun _ => And.right
apply (lt_or_eq_of_le hle).resolve_left _
intro con
obtain ⟨c, hc⟩ := exists_isCompl (⟨sSup { a : α | IsAtom a ∧ a ≤ b }, hle⟩ : Set.Iic b)
obtain rfl | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le c
· exact ne_of_lt con (Subtype.ext_iff.1 (eq_top_of_isCompl_bot hc))
· apply ha.1
rw [eq_bot_iff]
apply le_trans (le_inf _ hac) hc.disjoint.le_bot
rw [← Subtype.coe_le_coe, Subtype.coe_mk]
exact le_sSup ⟨ha.of_isAtom_coe_Iic, a.2⟩, fun _ => And.left⟩⟩
/-!
Now we will prove that a compactly generated modular atomistic lattice is a complemented lattice.
Most explicitly, every element is the complement of a supremum of indepedendent atoms.
-/
/-- In an atomic lattice, every element `b` has a complement of the form `sSup s`, where each
element of `s` is an atom. See also `complementedLattice_of_sSup_atoms_eq_top`. -/
theorem exists_setIndependent_isCompl_sSup_atoms (h : sSup { a : α | IsAtom a } = ⊤) (b : α) :
∃ s : Set α, CompleteLattice.SetIndependent s ∧
IsCompl b (sSup s) ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := by
-- porting note(https://github.com/leanprover-community/mathlib4/issues/5732):
-- `obtain` chokes on the placeholder.
have := zorn_subset
{s : Set α | CompleteLattice.SetIndependent s ∧ Disjoint b (sSup s) ∧ ∀ a ∈ s, IsAtom a}
fun c hc1 hc2 =>
⟨⋃₀ c,
⟨CompleteLattice.independent_sUnion_of_directed hc2.directedOn fun s hs => (hc1 hs).1, ?_,
fun a ⟨s, sc, as⟩ => (hc1 sc).2.2 a as⟩,
fun _ => Set.subset_sUnion_of_mem⟩
swap
· rw [sSup_sUnion, ← sSup_image, DirectedOn.disjoint_sSup_right]
· rintro _ ⟨s, hs, rfl⟩
exact (hc1 hs).2.1
· rw [directedOn_image]
exact hc2.directedOn.mono @fun s t => sSup_le_sSup
obtain ⟨s, ⟨s_ind, b_inf_Sup_s, s_atoms⟩, s_max⟩ := this
refine ⟨s, s_ind, ⟨b_inf_Sup_s, ?_⟩, s_atoms⟩
rw [codisjoint_iff_le_sup, ← h, sSup_le_iff]
intro a ha
rw [← inf_eq_left]
refine (ha.le_iff.mp inf_le_left).resolve_left fun con => ha.1 ?_
rw [← con, eq_comm, inf_eq_left]
refine (le_sSup ?_).trans le_sup_right
rw [← disjoint_iff] at con
have a_dis_Sup_s : Disjoint a (sSup s) := con.mono_right le_sup_right
-- Porting note: The two following `fun x hx => _` are no-op
rw [← s_max (s ∪ {a}) ⟨fun x hx => _, _, fun x hx => _⟩ Set.subset_union_left]
· exact Set.mem_union_right _ (Set.mem_singleton _)
· intro x hx
rw [Set.mem_union, Set.mem_singleton_iff] at hx
obtain rfl | xa := eq_or_ne x a
· simp only [Set.mem_singleton, Set.insert_diff_of_mem, Set.union_singleton]
exact con.mono_right ((sSup_le_sSup Set.diff_subset).trans le_sup_right)
· have h : (s ∪ {a}) \ {x} = s \ {x} ∪ {a} := by
simp only [Set.union_singleton]
rw [Set.insert_diff_of_not_mem]
rw [Set.mem_singleton_iff]
exact Ne.symm xa
rw [h, sSup_union, sSup_singleton]
apply
(s_ind (hx.resolve_right xa)).disjoint_sup_right_of_disjoint_sup_left
(a_dis_Sup_s.mono_right _).symm
rw [← sSup_insert, Set.insert_diff_singleton, Set.insert_eq_of_mem (hx.resolve_right xa)]
· rw [sSup_union, sSup_singleton]
exact b_inf_Sup_s.disjoint_sup_right_of_disjoint_sup_left con.symm
· intro x hx
rw [Set.mem_union, Set.mem_singleton_iff] at hx
obtain hx | rfl := hx
· exact s_atoms x hx
· exact ha
theorem exists_setIndependent_of_sSup_atoms_eq_top (h : sSup { a : α | IsAtom a } = ⊤) :
∃ s : Set α, CompleteLattice.SetIndependent s ∧ sSup s = ⊤ ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a :=
let ⟨s, s_ind, s_top, s_atoms⟩ := exists_setIndependent_isCompl_sSup_atoms h ⊥
⟨s, s_ind, eq_top_of_isCompl_bot s_top.symm, s_atoms⟩
/-- See [Theorem 6.6][calugareanu]. -/
theorem complementedLattice_of_sSup_atoms_eq_top (h : sSup { a : α | IsAtom a } = ⊤) :
ComplementedLattice α :=
⟨fun b =>
let ⟨s, _, s_top, _⟩ := exists_setIndependent_isCompl_sSup_atoms h b
⟨sSup s, s_top⟩⟩
/-- See [Theorem 6.6][calugareanu]. -/
theorem complementedLattice_of_isAtomistic [IsAtomistic α] : ComplementedLattice α :=
complementedLattice_of_sSup_atoms_eq_top sSup_atoms_eq_top
theorem complementedLattice_iff_isAtomistic : ComplementedLattice α ↔ IsAtomistic α := by
constructor <;> intros
· exact isAtomistic_of_complementedLattice
· exact complementedLattice_of_isAtomistic
end
|
Order\CompactlyGenerated\Intervals.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.CompleteLatticeIntervals
import Mathlib.Order.CompactlyGenerated.Basic
/-!
# Results about compactness properties for intervals in complete lattices
-/
variable {ι α : Type*} [CompleteLattice α]
namespace Set.Iic
theorem isCompactElement {a : α} {b : Iic a} (h : CompleteLattice.IsCompactElement (b : α)) :
CompleteLattice.IsCompactElement b := by
simp only [CompleteLattice.isCompactElement_iff, Finset.sup_eq_iSup] at h ⊢
intro ι s hb
replace hb : (b : α) ≤ iSup ((↑) ∘ s) := le_trans hb <| (coe_iSup s) ▸ le_refl _
obtain ⟨t, ht⟩ := h ι ((↑) ∘ s) hb
exact ⟨t, (by simpa using ht : (b : α) ≤ _)⟩
instance instIsCompactlyGenerated [IsCompactlyGenerated α] {a : α} :
IsCompactlyGenerated (Iic a) := by
refine ⟨fun ⟨x, (hx : x ≤ a)⟩ ↦ ?_⟩
obtain ⟨s, hs, rfl⟩ := IsCompactlyGenerated.exists_sSup_eq x
rw [sSup_le_iff] at hx
let f : s → Iic a := fun y ↦ ⟨y, hx _ y.property⟩
refine ⟨range f, ?_, ?_⟩
· rintro - ⟨⟨y, hy⟩, hy', rfl⟩
exact isCompactElement (hs _ hy)
· rw [Subtype.ext_iff]
change sSup (((↑) : Iic a → α) '' (range f)) = sSup s
congr
ext b
simpa [f] using hx b
end Set.Iic
open Set (Iic)
theorem complementedLattice_of_complementedLattice_Iic
[IsModularLattice α] [IsCompactlyGenerated α]
{s : Set ι} {f : ι → α}
(h : ∀ i ∈ s, ComplementedLattice <| Iic (f i))
(h' : ⨆ i ∈ s, f i = ⊤) :
ComplementedLattice α := by
apply complementedLattice_of_sSup_atoms_eq_top
have : ∀ i ∈ s, ∃ t : Set α, f i = sSup t ∧ ∀ a ∈ t, IsAtom a := fun i hi ↦ by
replace h := complementedLattice_iff_isAtomistic.mp (h i hi)
obtain ⟨u, hu, hu'⟩ := eq_sSup_atoms (⊤ : Iic (f i))
refine ⟨(↑) '' u, ?_, ?_⟩
· replace hu : f i = ↑(sSup u) := Subtype.ext_iff.mp hu
simp_rw [hu, Iic.coe_sSup]
· rintro b ⟨⟨a, ha'⟩, ha, rfl⟩
exact IsAtom.of_isAtom_coe_Iic (hu' _ ha)
choose t ht ht' using this
let u : Set α := ⋃ i, ⋃ hi : i ∈ s, t i hi
have hu₁ : u ⊆ {a | IsAtom a} := by
rintro a ⟨-, ⟨i, rfl⟩, ⟨-, ⟨hi, rfl⟩, ha : a ∈ t i hi⟩⟩
exact ht' i hi a ha
have hu₂ : sSup u = ⨆ i ∈ s, f i := by simp_rw [u, sSup_iUnion, biSup_congr' ht]
rw [eq_top_iff, ← h', ← hu₂]
exact sSup_le_sSup hu₁
|
Order\ConditionallyCompleteLattice\Basic.lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.WellFounded
import Mathlib.Data.Set.Image
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.Lattice
/-!
# Theory of conditionally complete lattices.
A conditionally complete lattice is a lattice in which every non-empty bounded subset `s`
has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`.
Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders.
The theory is very comparable to the theory of complete lattices, except that suitable
boundedness and nonemptiness assumptions have to be added to most statements.
We introduce two predicates `BddAbove` and `BddBelow` to express this boundedness, prove
their basic properties, and then go on to prove most useful properties of `sSup` and `sInf`
in conditionally complete lattices.
To differentiate the statements between complete lattices and conditionally complete
lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`.
For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`,
while `csInf_le` is the same statement in conditionally complete lattices
with an additional assumption that `s` is bounded below.
-/
open Function OrderDual Set
variable {α β γ : Type*} {ι : Sort*}
section
/-!
Extension of `sSup` and `sInf` from a preorder `α` to `WithTop α` and `WithBot α`
-/
variable [Preorder α]
open Classical in
noncomputable instance WithTop.instSupSet [SupSet α] :
SupSet (WithTop α) :=
⟨fun S =>
if ⊤ ∈ S then ⊤ else if BddAbove ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α) then
↑(sSup ((fun (a : α) ↦ (a : WithTop α)) ⁻¹' S : Set α)) else ⊤⟩
open Classical in
noncomputable instance WithTop.instInfSet [InfSet α] : InfSet (WithTop α) :=
⟨fun S => if S ⊆ {⊤} ∨ ¬BddBelow S then ⊤ else ↑(sInf ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α))⟩
noncomputable instance WithBot.instSupSet [SupSet α] : SupSet (WithBot α) :=
⟨(WithTop.instInfSet (α := αᵒᵈ)).sInf⟩
noncomputable instance WithBot.instInfSet [InfSet α] :
InfSet (WithBot α) :=
⟨(WithTop.instSupSet (α := αᵒᵈ)).sSup⟩
theorem WithTop.sSup_eq [SupSet α] {s : Set (WithTop α)} (hs : ⊤ ∉ s)
(hs' : BddAbove ((↑) ⁻¹' s : Set α)) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) :=
(if_neg hs).trans <| if_pos hs'
theorem WithTop.sInf_eq [InfSet α] {s : Set (WithTop α)} (hs : ¬s ⊆ {⊤}) (h's : BddBelow s) :
sInf s = ↑(sInf ((↑) ⁻¹' s) : α) :=
if_neg <| by simp [hs, h's]
theorem WithBot.sInf_eq [InfSet α] {s : Set (WithBot α)} (hs : ⊥ ∉ s)
(hs' : BddBelow ((↑) ⁻¹' s : Set α)) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) :=
(if_neg hs).trans <| if_pos hs'
theorem WithBot.sSup_eq [SupSet α] {s : Set (WithBot α)} (hs : ¬s ⊆ {⊥}) (h's : BddAbove s) :
sSup s = ↑(sSup ((↑) ⁻¹' s) : α) :=
WithTop.sInf_eq (α := αᵒᵈ) hs h's
@[simp]
theorem WithTop.sInf_empty [InfSet α] : sInf (∅ : Set (WithTop α)) = ⊤ :=
if_pos <| by simp
@[simp]
theorem WithTop.iInf_empty [IsEmpty ι] [InfSet α] (f : ι → WithTop α) :
⨅ i, f i = ⊤ := by rw [iInf, range_eq_empty, WithTop.sInf_empty]
theorem WithTop.coe_sInf' [InfSet α] {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) :
↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by
classical
obtain ⟨x, hx⟩ := hs
change _ = ite _ _ _
split_ifs with h
· rcases h with h1 | h2
· cases h1 (mem_image_of_mem _ hx)
· exact (h2 (Monotone.map_bddBelow coe_mono h's)).elim
· rw [preimage_image_eq]
exact Option.some_injective _
@[norm_cast]
theorem WithTop.coe_iInf [Nonempty ι] [InfSet α] {f : ι → α} (hf : BddBelow (range f)) :
↑(⨅ i, f i) = (⨅ i, f i : WithTop α) := by
rw [iInf, iInf, WithTop.coe_sInf' (range_nonempty f) hf, ← range_comp, Function.comp_def]
theorem WithTop.coe_sSup' [SupSet α] {s : Set α} (hs : BddAbove s) :
↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by
classical
change _ = ite _ _ _
rw [if_neg, preimage_image_eq, if_pos hs]
· exact Option.some_injective _
· rintro ⟨x, _, ⟨⟩⟩
@[norm_cast]
theorem WithTop.coe_iSup [SupSet α] (f : ι → α) (h : BddAbove (Set.range f)) :
↑(⨆ i, f i) = (⨆ i, f i : WithTop α) := by
rw [iSup, iSup, WithTop.coe_sSup' h, ← range_comp, Function.comp_def]
@[simp]
theorem WithBot.sSup_empty [SupSet α] : sSup (∅ : Set (WithBot α)) = ⊥ :=
WithTop.sInf_empty (α := αᵒᵈ)
@[deprecated (since := "2024-06-10")] alias WithBot.csSup_empty := WithBot.sSup_empty
@[simp]
theorem WithBot.ciSup_empty [IsEmpty ι] [SupSet α] (f : ι → WithBot α) :
⨆ i, f i = ⊥ :=
WithTop.iInf_empty (α := αᵒᵈ) _
@[norm_cast]
theorem WithBot.coe_sSup' [SupSet α] {s : Set α} (hs : s.Nonempty) (h's : BddAbove s) :
↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithBot α) :=
WithTop.coe_sInf' (α := αᵒᵈ) hs h's
@[norm_cast]
theorem WithBot.coe_iSup [Nonempty ι] [SupSet α] {f : ι → α} (hf : BddAbove (range f)) :
↑(⨆ i, f i) = (⨆ i, f i : WithBot α) :=
WithTop.coe_iInf (α := αᵒᵈ) hf
@[norm_cast]
theorem WithBot.coe_sInf' [InfSet α] {s : Set α} (hs : BddBelow s) :
↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithBot α) :=
WithTop.coe_sSup' (α := αᵒᵈ) hs
@[norm_cast]
theorem WithBot.coe_iInf [InfSet α] (f : ι → α) (h : BddBelow (Set.range f)) :
↑(⨅ i, f i) = (⨅ i, f i : WithBot α) :=
WithTop.coe_iSup (α := αᵒᵈ) _ h
end
/-- A conditionally complete lattice is a lattice in which
every nonempty subset which is bounded above has a supremum, and
every nonempty subset which is bounded below has an infimum.
Typical examples are real numbers or natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete lattices, we prefix sInf and subₛ by a c everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLattice (α : Type*) extends Lattice α, SupSet α, InfSet α where
/-- `a ≤ sSup s` for all `a ∈ s`. -/
le_csSup : ∀ s a, BddAbove s → a ∈ s → a ≤ sSup s
/-- `sSup s ≤ a` for all `a ∈ upperBounds s`. -/
csSup_le : ∀ s a, Set.Nonempty s → a ∈ upperBounds s → sSup s ≤ a
/-- `sInf s ≤ a` for all `a ∈ s`. -/
csInf_le : ∀ s a, BddBelow s → a ∈ s → sInf s ≤ a
/-- `a ≤ sInf s` for all `a ∈ lowerBounds s`. -/
le_csInf : ∀ s a, Set.Nonempty s → a ∈ lowerBounds s → a ≤ sInf s
-- Porting note: mathlib3 used `renaming`
/-- A conditionally complete linear order is a linear order in which
every nonempty subset which is bounded above has a supremum, and
every nonempty subset which is bounded below has an infimum.
Typical examples are real numbers or natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete linear orders, we prefix sInf and sSup by a c everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLinearOrder (α : Type*) extends ConditionallyCompleteLattice α where
/-- A `ConditionallyCompleteLinearOrder` is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
decidableLE : DecidableRel (· ≤ · : α → α → Prop)
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
decidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ decidableLE
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
decidableLT : DecidableRel (· < · : α → α → Prop) :=
@decidableLTOfDecidableLE _ _ decidableLE
/-- If a set is not bounded above, its supremum is by convention `sSup ∅`. -/
csSup_of_not_bddAbove : ∀ s, ¬BddAbove s → sSup s = sSup (∅ : Set α)
/-- If a set is not bounded below, its infimum is by convention `sInf ∅`. -/
csInf_of_not_bddBelow : ∀ s, ¬BddBelow s → sInf s = sInf (∅ : Set α)
instance ConditionallyCompleteLinearOrder.toLinearOrder [ConditionallyCompleteLinearOrder α] :
LinearOrder α :=
{ ‹ConditionallyCompleteLinearOrder α› with
max := Sup.sup, min := Inf.inf,
min_def := fun a b ↦ by
by_cases hab : a = b
· simp [hab]
· rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂)
· simp [h₁]
· simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂]
max_def := fun a b ↦ by
by_cases hab : a = b
· simp [hab]
· rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂)
· simp [h₁]
· simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] }
/-- A conditionally complete linear order with `Bot` is a linear order with least element, in which
every nonempty subset which is bounded above has a supremum, and every nonempty subset (necessarily
bounded below) has an infimum. A typical example is the natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete linear orders, we prefix `sInf` and `sSup` by a c everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLinearOrderBot (α : Type*) extends ConditionallyCompleteLinearOrder α,
Bot α where
/-- `⊥` is the least element -/
bot_le : ∀ x : α, ⊥ ≤ x
/-- The supremum of the empty set is `⊥` -/
csSup_empty : sSup ∅ = ⊥
-- see Note [lower instance priority]
instance (priority := 100) ConditionallyCompleteLinearOrderBot.toOrderBot
[h : ConditionallyCompleteLinearOrderBot α] : OrderBot α :=
{ h with }
-- see Note [lower instance priority]
/-- A complete lattice is a conditionally complete lattice, as there are no restrictions
on the properties of sInf and sSup in a complete lattice. -/
instance (priority := 100) CompleteLattice.toConditionallyCompleteLattice [CompleteLattice α] :
ConditionallyCompleteLattice α :=
{ ‹CompleteLattice α› with
le_csSup := by intros; apply le_sSup; assumption
csSup_le := by intros; apply sSup_le; assumption
csInf_le := by intros; apply sInf_le; assumption
le_csInf := by intros; apply le_sInf; assumption }
-- see Note [lower instance priority]
instance (priority := 100) CompleteLinearOrder.toConditionallyCompleteLinearOrderBot {α : Type*}
[h : CompleteLinearOrder α] : ConditionallyCompleteLinearOrderBot α :=
{ CompleteLattice.toConditionallyCompleteLattice, h with
csSup_empty := sSup_empty
csSup_of_not_bddAbove := fun s H ↦ (H (OrderTop.bddAbove s)).elim
csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim }
open scoped Classical in
/-- A well founded linear order is conditionally complete, with a bottom element. -/
noncomputable abbrev IsWellOrder.conditionallyCompleteLinearOrderBot (α : Type*)
[i₁ : _root_.LinearOrder α] [i₂ : OrderBot α] [h : IsWellOrder α (· < ·)] :
ConditionallyCompleteLinearOrderBot α :=
{ i₁, i₂, LinearOrder.toLattice with
sInf := fun s => if hs : s.Nonempty then h.wf.min s hs else ⊥
csInf_le := fun s a _ has => by
have s_ne : s.Nonempty := ⟨a, has⟩
simpa [s_ne] using not_lt.1 (h.wf.not_lt_min s s_ne has)
le_csInf := fun s a hs has => by
simp only [hs, dif_pos]
exact has (h.wf.min_mem s hs)
sSup := fun s => if hs : (upperBounds s).Nonempty then h.wf.min _ hs else ⊥
le_csSup := fun s a hs has => by
have h's : (upperBounds s).Nonempty := hs
simp only [h's, dif_pos]
exact h.wf.min_mem _ h's has
csSup_le := fun s a _ has => by
have h's : (upperBounds s).Nonempty := ⟨a, has⟩
simp only [h's, dif_pos]
simpa using h.wf.not_lt_min _ h's has
csSup_empty := by simpa using eq_bot_iff.2 (not_lt.1 <| h.wf.not_lt_min _ _ <| mem_univ ⊥)
csSup_of_not_bddAbove := by
intro s H
have B : ¬((upperBounds s).Nonempty) := H
simp only [B, dite_false, upperBounds_empty, univ_nonempty, dite_true]
exact le_antisymm bot_le (WellFounded.min_le _ (mem_univ _))
csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim }
namespace OrderDual
instance instConditionallyCompleteLattice (α : Type*) [ConditionallyCompleteLattice α] :
ConditionallyCompleteLattice αᵒᵈ :=
{ OrderDual.instInf α, OrderDual.instSup α, OrderDual.instLattice α with
le_csSup := ConditionallyCompleteLattice.csInf_le (α := α)
csSup_le := ConditionallyCompleteLattice.le_csInf (α := α)
le_csInf := ConditionallyCompleteLattice.csSup_le (α := α)
csInf_le := ConditionallyCompleteLattice.le_csSup (α := α) }
instance (α : Type*) [ConditionallyCompleteLinearOrder α] : ConditionallyCompleteLinearOrder αᵒᵈ :=
{ OrderDual.instConditionallyCompleteLattice α, OrderDual.instLinearOrder α with
csSup_of_not_bddAbove := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow (α := α)
csInf_of_not_bddBelow := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove (α := α) }
end OrderDual
/-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `sup` function
that returns the least upper bound of a nonempty set which is bounded above. Usually this
constructor provides poor definitional equalities. If other fields are known explicitly, they
should be provided; for example, if `inf` is known explicitly, construct the
`ConditionallyCompleteLattice` instance as
```
instance : ConditionallyCompleteLattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, sInf
..conditionallyCompleteLatticeOfsSup my_T _ }
```
-/
def conditionallyCompleteLatticeOfsSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α]
(bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α))
(bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α))
(isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) :
ConditionallyCompleteLattice α :=
{ H1, H2 with
sup := fun a b => sSup {a, b}
le_sup_left := fun a b =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _)
le_sup_right := fun a b =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1
(mem_insert_of_mem _ (mem_singleton _))
sup_le := fun a b _ hac hbc =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).2
(forall_insert_of_forall (forall_eq.mpr hbc) hac)
inf := fun a b => sSup (lowerBounds {a, b})
inf_le_left := fun a b =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
(bddBelow_pair a b)).2
fun _ hc => hc <| mem_insert _ _
inf_le_right := fun a b =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
(bddBelow_pair a b)).2
fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _)
le_inf := fun c a b hca hcb =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
⟨c, forall_insert_of_forall (forall_eq.mpr hcb) hca⟩).1
(forall_insert_of_forall (forall_eq.mpr hcb) hca)
sInf := fun s => sSup (lowerBounds s)
csSup_le := fun s a hs ha => (isLUB_sSup s ⟨a, ha⟩ hs).2 ha
le_csSup := fun s a hs ha => (isLUB_sSup s hs ⟨a, ha⟩).1 ha
csInf_le := fun s a hs ha =>
(isLUB_sSup (lowerBounds s) (Nonempty.bddAbove_lowerBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha
le_csInf := fun s a hs ha =>
(isLUB_sSup (lowerBounds s) hs.bddAbove_lowerBounds ⟨a, ha⟩).1 ha }
/-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `inf` function
that returns the greatest lower bound of a nonempty set which is bounded below. Usually this
constructor provides poor definitional equalities. If other fields are known explicitly, they
should be provided; for example, if `inf` is known explicitly, construct the
`ConditionallyCompleteLattice` instance as
```
instance : ConditionallyCompleteLattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, sSup
..conditionallyCompleteLatticeOfsInf my_T _ }
```
-/
def conditionallyCompleteLatticeOfsInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α]
(bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α))
(bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α))
(isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) :
ConditionallyCompleteLattice α :=
{ H1, H2 with
inf := fun a b => sInf {a, b}
inf_le_left := fun a b =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _)
inf_le_right := fun a b =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1
(mem_insert_of_mem _ (mem_singleton _))
le_inf := fun _ a b hca hcb =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).2
(forall_insert_of_forall (forall_eq.mpr hcb) hca)
sup := fun a b => sInf (upperBounds {a, b})
le_sup_left := fun a b =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
(bddAbove_pair a b)).2
fun _ hc => hc <| mem_insert _ _
le_sup_right := fun a b =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
(bddAbove_pair a b)).2
fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _)
sup_le := fun a b c hac hbc =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
⟨c, forall_insert_of_forall (forall_eq.mpr hbc) hac⟩).1
(forall_insert_of_forall (forall_eq.mpr hbc) hac)
sSup := fun s => sInf (upperBounds s)
le_csInf := fun s a hs ha => (isGLB_sInf s ⟨a, ha⟩ hs).2 ha
csInf_le := fun s a hs ha => (isGLB_sInf s hs ⟨a, ha⟩).1 ha
le_csSup := fun s a hs ha =>
(isGLB_sInf (upperBounds s) (Nonempty.bddBelow_upperBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha
csSup_le := fun s a hs ha =>
(isGLB_sInf (upperBounds s) hs.bddBelow_upperBounds ⟨a, ha⟩).1 ha }
/-- A version of `conditionallyCompleteLatticeOfsSup` when we already know that `α` is a lattice.
This should only be used when it is both hard and unnecessary to provide `inf` explicitly. -/
def conditionallyCompleteLatticeOfLatticeOfsSup (α : Type*) [H1 : Lattice α] [SupSet α]
(isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) :
ConditionallyCompleteLattice α :=
{ H1,
conditionallyCompleteLatticeOfsSup α
(fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩)
(fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩)
isLUB_sSup with }
/-- A version of `conditionallyCompleteLatticeOfsInf` when we already know that `α` is a lattice.
This should only be used when it is both hard and unnecessary to provide `sup` explicitly. -/
def conditionallyCompleteLatticeOfLatticeOfsInf (α : Type*) [H1 : Lattice α] [InfSet α]
(isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) :
ConditionallyCompleteLattice α :=
{ H1,
conditionallyCompleteLatticeOfsInf α
(fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩)
(fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩)
isGLB_sInf with }
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] {s t : Set α} {a b : α}
theorem le_csSup (h₁ : BddAbove s) (h₂ : a ∈ s) : a ≤ sSup s :=
ConditionallyCompleteLattice.le_csSup s a h₁ h₂
theorem csSup_le (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, b ≤ a) : sSup s ≤ a :=
ConditionallyCompleteLattice.csSup_le s a h₁ h₂
theorem csInf_le (h₁ : BddBelow s) (h₂ : a ∈ s) : sInf s ≤ a :=
ConditionallyCompleteLattice.csInf_le s a h₁ h₂
theorem le_csInf (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, a ≤ b) : a ≤ sInf s :=
ConditionallyCompleteLattice.le_csInf s a h₁ h₂
theorem le_csSup_of_le (hs : BddAbove s) (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s :=
le_trans h (le_csSup hs hb)
theorem csInf_le_of_le (hs : BddBelow s) (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a :=
le_trans (csInf_le hs hb) h
theorem csSup_le_csSup (ht : BddAbove t) (hs : s.Nonempty) (h : s ⊆ t) : sSup s ≤ sSup t :=
csSup_le hs fun _ ha => le_csSup ht (h ha)
theorem csInf_le_csInf (ht : BddBelow t) (hs : s.Nonempty) (h : s ⊆ t) : sInf t ≤ sInf s :=
le_csInf hs fun _ ha => csInf_le ht (h ha)
theorem le_csSup_iff (h : BddAbove s) (hs : s.Nonempty) :
a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b :=
⟨fun h _ hb => le_trans h (csSup_le hs hb), fun hb => hb _ fun _ => le_csSup h⟩
theorem csInf_le_iff (h : BddBelow s) (hs : s.Nonempty) : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a :=
⟨fun h _ hb => le_trans (le_csInf hs hb) h, fun hb => hb _ fun _ => csInf_le h⟩
theorem isLUB_csSup (ne : s.Nonempty) (H : BddAbove s) : IsLUB s (sSup s) :=
⟨fun _ => le_csSup H, fun _ => csSup_le ne⟩
theorem isLUB_ciSup [Nonempty ι] {f : ι → α} (H : BddAbove (range f)) :
IsLUB (range f) (⨆ i, f i) :=
isLUB_csSup (range_nonempty f) H
theorem isLUB_ciSup_set {f : β → α} {s : Set β} (H : BddAbove (f '' s)) (Hne : s.Nonempty) :
IsLUB (f '' s) (⨆ i : s, f i) := by
rw [← sSup_image']
exact isLUB_csSup (Hne.image _) H
theorem isGLB_csInf (ne : s.Nonempty) (H : BddBelow s) : IsGLB s (sInf s) :=
⟨fun _ => csInf_le H, fun _ => le_csInf ne⟩
theorem isGLB_ciInf [Nonempty ι] {f : ι → α} (H : BddBelow (range f)) :
IsGLB (range f) (⨅ i, f i) :=
isGLB_csInf (range_nonempty f) H
theorem isGLB_ciInf_set {f : β → α} {s : Set β} (H : BddBelow (f '' s)) (Hne : s.Nonempty) :
IsGLB (f '' s) (⨅ i : s, f i) :=
isLUB_ciSup_set (α := αᵒᵈ) H Hne
theorem ciSup_le_iff [Nonempty ι] {f : ι → α} {a : α} (hf : BddAbove (range f)) :
iSup f ≤ a ↔ ∀ i, f i ≤ a :=
(isLUB_le_iff <| isLUB_ciSup hf).trans forall_mem_range
theorem le_ciInf_iff [Nonempty ι] {f : ι → α} {a : α} (hf : BddBelow (range f)) :
a ≤ iInf f ↔ ∀ i, a ≤ f i :=
(le_isGLB_iff <| isGLB_ciInf hf).trans forall_mem_range
theorem ciSup_set_le_iff {ι : Type*} {s : Set ι} {f : ι → α} {a : α} (hs : s.Nonempty)
(hf : BddAbove (f '' s)) : ⨆ i : s, f i ≤ a ↔ ∀ i ∈ s, f i ≤ a :=
(isLUB_le_iff <| isLUB_ciSup_set hf hs).trans forall_mem_image
theorem le_ciInf_set_iff {ι : Type*} {s : Set ι} {f : ι → α} {a : α} (hs : s.Nonempty)
(hf : BddBelow (f '' s)) : (a ≤ ⨅ i : s, f i) ↔ ∀ i ∈ s, a ≤ f i :=
(le_isGLB_iff <| isGLB_ciInf_set hf hs).trans forall_mem_image
theorem IsLUB.csSup_eq (H : IsLUB s a) (ne : s.Nonempty) : sSup s = a :=
(isLUB_csSup ne ⟨a, H.1⟩).unique H
theorem IsLUB.ciSup_eq [Nonempty ι] {f : ι → α} (H : IsLUB (range f) a) : ⨆ i, f i = a :=
H.csSup_eq (range_nonempty f)
theorem IsLUB.ciSup_set_eq {s : Set β} {f : β → α} (H : IsLUB (f '' s) a) (Hne : s.Nonempty) :
⨆ i : s, f i = a :=
IsLUB.csSup_eq (image_eq_range f s ▸ H) (image_eq_range f s ▸ Hne.image f)
/-- A greatest element of a set is the supremum of this set. -/
theorem IsGreatest.csSup_eq (H : IsGreatest s a) : sSup s = a :=
H.isLUB.csSup_eq H.nonempty
theorem IsGreatest.csSup_mem (H : IsGreatest s a) : sSup s ∈ s :=
H.csSup_eq.symm ▸ H.1
theorem IsGLB.csInf_eq (H : IsGLB s a) (ne : s.Nonempty) : sInf s = a :=
(isGLB_csInf ne ⟨a, H.1⟩).unique H
theorem IsGLB.ciInf_eq [Nonempty ι] {f : ι → α} (H : IsGLB (range f) a) : ⨅ i, f i = a :=
H.csInf_eq (range_nonempty f)
theorem IsGLB.ciInf_set_eq {s : Set β} {f : β → α} (H : IsGLB (f '' s) a) (Hne : s.Nonempty) :
⨅ i : s, f i = a :=
IsGLB.csInf_eq (image_eq_range f s ▸ H) (image_eq_range f s ▸ Hne.image f)
/-- A least element of a set is the infimum of this set. -/
theorem IsLeast.csInf_eq (H : IsLeast s a) : sInf s = a :=
H.isGLB.csInf_eq H.nonempty
theorem IsLeast.csInf_mem (H : IsLeast s a) : sInf s ∈ s :=
H.csInf_eq.symm ▸ H.1
theorem subset_Icc_csInf_csSup (hb : BddBelow s) (ha : BddAbove s) : s ⊆ Icc (sInf s) (sSup s) :=
fun _ hx => ⟨csInf_le hb hx, le_csSup ha hx⟩
theorem csSup_le_iff (hb : BddAbove s) (hs : s.Nonempty) : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a :=
isLUB_le_iff (isLUB_csSup hs hb)
theorem le_csInf_iff (hb : BddBelow s) (hs : s.Nonempty) : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b :=
le_isGLB_iff (isGLB_csInf hs hb)
theorem csSup_lower_bounds_eq_csInf {s : Set α} (h : BddBelow s) (hs : s.Nonempty) :
sSup (lowerBounds s) = sInf s :=
(isLUB_csSup h <| hs.mono fun _ hx _ hy => hy hx).unique (isGLB_csInf hs h).isLUB
theorem csInf_upper_bounds_eq_csSup {s : Set α} (h : BddAbove s) (hs : s.Nonempty) :
sInf (upperBounds s) = sSup s :=
(isGLB_csInf h <| hs.mono fun _ hx _ hy => hy hx).unique (isLUB_csSup hs h).isGLB
theorem not_mem_of_lt_csInf {x : α} {s : Set α} (h : x < sInf s) (hs : BddBelow s) : x ∉ s :=
fun hx => lt_irrefl _ (h.trans_le (csInf_le hs hx))
theorem not_mem_of_csSup_lt {x : α} {s : Set α} (h : sSup s < x) (hs : BddAbove s) : x ∉ s :=
not_mem_of_lt_csInf (α := αᵒᵈ) h hs
/-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b`
is larger than all elements of `s`, and that this is not the case of any `w<b`.
See `sSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/
theorem csSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.Nonempty) (H : ∀ a ∈ s, a ≤ b)
(H' : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b :=
(eq_of_le_of_not_lt (csSup_le hs H)) fun hb =>
let ⟨_, ha, ha'⟩ := H' _ hb
lt_irrefl _ <| ha'.trans_le <| le_csSup ⟨b, H⟩ ha
/-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b`
is smaller than all elements of `s`, and that this is not the case of any `w>b`.
See `sInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/
theorem csInf_eq_of_forall_ge_of_forall_gt_exists_lt :
s.Nonempty → (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b :=
csSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ)
/-- `b < sSup s` when there is an element `a` in `s` with `b < a`, when `s` is bounded above.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness above for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the `CompleteLattice` case. -/
theorem lt_csSup_of_lt (hs : BddAbove s) (ha : a ∈ s) (h : b < a) : b < sSup s :=
lt_of_lt_of_le h (le_csSup hs ha)
/-- `sInf s < b` when there is an element `a` in `s` with `a < b`, when `s` is bounded below.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness below for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the `CompleteLattice` case. -/
theorem csInf_lt_of_lt : BddBelow s → a ∈ s → a < b → sInf s < b :=
lt_csSup_of_lt (α := αᵒᵈ)
/-- If all elements of a nonempty set `s` are less than or equal to all elements
of a nonempty set `t`, then there exists an element between these sets. -/
theorem exists_between_of_forall_le (sne : s.Nonempty) (tne : t.Nonempty)
(hst : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : (upperBounds s ∩ lowerBounds t).Nonempty :=
⟨sInf t, fun x hx => le_csInf tne <| hst x hx, fun _ hy => csInf_le (sne.mono hst) hy⟩
/-- The supremum of a singleton is the element of the singleton-/
@[simp]
theorem csSup_singleton (a : α) : sSup {a} = a :=
isGreatest_singleton.csSup_eq
/-- The infimum of a singleton is the element of the singleton-/
@[simp]
theorem csInf_singleton (a : α) : sInf {a} = a :=
isLeast_singleton.csInf_eq
@[simp]
theorem csSup_pair (a b : α) : sSup {a, b} = a ⊔ b :=
(@isLUB_pair _ _ a b).csSup_eq (insert_nonempty _ _)
@[simp]
theorem csInf_pair (a b : α) : sInf {a, b} = a ⊓ b :=
(@isGLB_pair _ _ a b).csInf_eq (insert_nonempty _ _)
/-- If a set is bounded below and above, and nonempty, its infimum is less than or equal to
its supremum. -/
theorem csInf_le_csSup (hb : BddBelow s) (ha : BddAbove s) (ne : s.Nonempty) : sInf s ≤ sSup s :=
isGLB_le_isLUB (isGLB_csInf ne hb) (isLUB_csSup ne ha) ne
/-- The `sSup` of a union of two sets is the max of the suprema of each subset, under the
assumptions that all sets are bounded above and nonempty. -/
theorem csSup_union (hs : BddAbove s) (sne : s.Nonempty) (ht : BddAbove t) (tne : t.Nonempty) :
sSup (s ∪ t) = sSup s ⊔ sSup t :=
((isLUB_csSup sne hs).union (isLUB_csSup tne ht)).csSup_eq sne.inl
/-- The `sInf` of a union of two sets is the min of the infima of each subset, under the assumptions
that all sets are bounded below and nonempty. -/
theorem csInf_union (hs : BddBelow s) (sne : s.Nonempty) (ht : BddBelow t) (tne : t.Nonempty) :
sInf (s ∪ t) = sInf s ⊓ sInf t :=
csSup_union (α := αᵒᵈ) hs sne ht tne
/-- The supremum of an intersection of two sets is bounded by the minimum of the suprema of each
set, if all sets are bounded above and nonempty. -/
theorem csSup_inter_le (hs : BddAbove s) (ht : BddAbove t) (hst : (s ∩ t).Nonempty) :
sSup (s ∩ t) ≤ sSup s ⊓ sSup t :=
(csSup_le hst) fun _ hx => le_inf (le_csSup hs hx.1) (le_csSup ht hx.2)
/-- The infimum of an intersection of two sets is bounded below by the maximum of the
infima of each set, if all sets are bounded below and nonempty. -/
theorem le_csInf_inter :
BddBelow s → BddBelow t → (s ∩ t).Nonempty → sInf s ⊔ sInf t ≤ sInf (s ∩ t) :=
csSup_inter_le (α := αᵒᵈ)
/-- The supremum of `insert a s` is the maximum of `a` and the supremum of `s`, if `s` is
nonempty and bounded above. -/
theorem csSup_insert (hs : BddAbove s) (sne : s.Nonempty) : sSup (insert a s) = a ⊔ sSup s :=
((isLUB_csSup sne hs).insert a).csSup_eq (insert_nonempty a s)
/-- The infimum of `insert a s` is the minimum of `a` and the infimum of `s`, if `s` is
nonempty and bounded below. -/
theorem csInf_insert (hs : BddBelow s) (sne : s.Nonempty) : sInf (insert a s) = a ⊓ sInf s :=
csSup_insert (α := αᵒᵈ) hs sne
@[simp]
theorem csInf_Icc (h : a ≤ b) : sInf (Icc a b) = a :=
(isGLB_Icc h).csInf_eq (nonempty_Icc.2 h)
@[simp]
theorem csInf_Ici : sInf (Ici a) = a :=
isLeast_Ici.csInf_eq
@[simp]
theorem csInf_Ico (h : a < b) : sInf (Ico a b) = a :=
(isGLB_Ico h).csInf_eq (nonempty_Ico.2 h)
@[simp]
theorem csInf_Ioc [DenselyOrdered α] (h : a < b) : sInf (Ioc a b) = a :=
(isGLB_Ioc h).csInf_eq (nonempty_Ioc.2 h)
@[simp]
theorem csInf_Ioi [NoMaxOrder α] [DenselyOrdered α] : sInf (Ioi a) = a :=
csInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (fun _ => le_of_lt) fun w hw => by
simpa using exists_between hw
@[simp]
theorem csInf_Ioo [DenselyOrdered α] (h : a < b) : sInf (Ioo a b) = a :=
(isGLB_Ioo h).csInf_eq (nonempty_Ioo.2 h)
@[simp]
theorem csSup_Icc (h : a ≤ b) : sSup (Icc a b) = b :=
(isLUB_Icc h).csSup_eq (nonempty_Icc.2 h)
@[simp]
theorem csSup_Ico [DenselyOrdered α] (h : a < b) : sSup (Ico a b) = b :=
(isLUB_Ico h).csSup_eq (nonempty_Ico.2 h)
@[simp]
theorem csSup_Iic : sSup (Iic a) = a :=
isGreatest_Iic.csSup_eq
@[simp]
theorem csSup_Iio [NoMinOrder α] [DenselyOrdered α] : sSup (Iio a) = a :=
csSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (fun _ => le_of_lt) fun w hw => by
simpa [and_comm] using exists_between hw
@[simp]
theorem csSup_Ioc (h : a < b) : sSup (Ioc a b) = b :=
(isLUB_Ioc h).csSup_eq (nonempty_Ioc.2 h)
@[simp]
theorem csSup_Ioo [DenselyOrdered α] (h : a < b) : sSup (Ioo a b) = b :=
(isLUB_Ioo h).csSup_eq (nonempty_Ioo.2 h)
/-- The indexed supremum of a function is bounded above by a uniform bound-/
theorem ciSup_le [Nonempty ι] {f : ι → α} {c : α} (H : ∀ x, f x ≤ c) : iSup f ≤ c :=
csSup_le (range_nonempty f) (by rwa [forall_mem_range])
/-- The indexed supremum of a function is bounded below by the value taken at one point-/
theorem le_ciSup {f : ι → α} (H : BddAbove (range f)) (c : ι) : f c ≤ iSup f :=
le_csSup H (mem_range_self _)
theorem le_ciSup_of_le {f : ι → α} (H : BddAbove (range f)) (c : ι) (h : a ≤ f c) : a ≤ iSup f :=
le_trans h (le_ciSup H c)
/-- The indexed supremum of two functions are comparable if the functions are pointwise comparable-/
theorem ciSup_mono {f g : ι → α} (B : BddAbove (range g)) (H : ∀ x, f x ≤ g x) :
iSup f ≤ iSup g := by
cases isEmpty_or_nonempty ι
· rw [iSup_of_empty', iSup_of_empty']
· exact ciSup_le fun x => le_ciSup_of_le B x (H x)
theorem le_ciSup_set {f : β → α} {s : Set β} (H : BddAbove (f '' s)) {c : β} (hc : c ∈ s) :
f c ≤ ⨆ i : s, f i :=
(le_csSup H <| mem_image_of_mem f hc).trans_eq sSup_image'
/-- The indexed infimum of two functions are comparable if the functions are pointwise comparable-/
theorem ciInf_mono {f g : ι → α} (B : BddBelow (range f)) (H : ∀ x, f x ≤ g x) : iInf f ≤ iInf g :=
ciSup_mono (α := αᵒᵈ) B H
/-- The indexed minimum of a function is bounded below by a uniform lower bound-/
theorem le_ciInf [Nonempty ι] {f : ι → α} {c : α} (H : ∀ x, c ≤ f x) : c ≤ iInf f :=
ciSup_le (α := αᵒᵈ) H
/-- The indexed infimum of a function is bounded above by the value taken at one point-/
theorem ciInf_le {f : ι → α} (H : BddBelow (range f)) (c : ι) : iInf f ≤ f c :=
le_ciSup (α := αᵒᵈ) H c
theorem ciInf_le_of_le {f : ι → α} (H : BddBelow (range f)) (c : ι) (h : f c ≤ a) : iInf f ≤ a :=
le_ciSup_of_le (α := αᵒᵈ) H c h
theorem ciInf_set_le {f : β → α} {s : Set β} (H : BddBelow (f '' s)) {c : β} (hc : c ∈ s) :
⨅ i : s, f i ≤ f c :=
le_ciSup_set (α := αᵒᵈ) H hc
@[simp]
theorem ciSup_const [hι : Nonempty ι] {a : α} : ⨆ _ : ι, a = a := by
rw [iSup, range_const, csSup_singleton]
@[simp]
theorem ciInf_const [Nonempty ι] {a : α} : ⨅ _ : ι, a = a :=
ciSup_const (α := αᵒᵈ)
@[simp]
theorem ciSup_unique [Unique ι] {s : ι → α} : ⨆ i, s i = s default := by
have : ∀ i, s i = s default := fun i => congr_arg s (Unique.eq_default i)
simp only [this, ciSup_const]
@[simp]
theorem ciInf_unique [Unique ι] {s : ι → α} : ⨅ i, s i = s default :=
ciSup_unique (α := αᵒᵈ)
theorem ciSup_subsingleton [Subsingleton ι] (i : ι) (s : ι → α) : ⨆ i, s i = s i :=
@ciSup_unique α ι _ ⟨⟨i⟩, fun j => Subsingleton.elim j i⟩ _
theorem ciInf_subsingleton [Subsingleton ι] (i : ι) (s : ι → α) : ⨅ i, s i = s i :=
@ciInf_unique α ι _ ⟨⟨i⟩, fun j => Subsingleton.elim j i⟩ _
@[simp]
theorem ciSup_pos {p : Prop} {f : p → α} (hp : p) : ⨆ h : p, f h = f hp :=
ciSup_subsingleton hp f
@[simp]
theorem ciInf_pos {p : Prop} {f : p → α} (hp : p) : ⨅ h : p, f h = f hp :=
ciSup_pos (α := αᵒᵈ) hp
lemma ciSup_neg {p : Prop} {f : p → α} (hp : ¬ p) :
⨆ (h : p), f h = sSup (∅ : Set α) := by
rw [iSup]
congr
rwa [range_eq_empty_iff, isEmpty_Prop]
lemma ciInf_neg {p : Prop} {f : p → α} (hp : ¬ p) :
⨅ (h : p), f h = sInf (∅ : Set α) :=
ciSup_neg (α := αᵒᵈ) hp
lemma ciSup_eq_ite {p : Prop} [Decidable p] {f : p → α} :
(⨆ h : p, f h) = if h : p then f h else sSup (∅ : Set α) := by
by_cases H : p <;> simp [ciSup_neg, H]
lemma ciInf_eq_ite {p : Prop} [Decidable p] {f : p → α} :
(⨅ h : p, f h) = if h : p then f h else sInf (∅ : Set α) :=
ciSup_eq_ite (α := αᵒᵈ)
theorem cbiSup_eq_of_forall {p : ι → Prop} {f : Subtype p → α} (hp : ∀ i, p i) :
⨆ (i) (h : p i), f ⟨i, h⟩ = iSup f := by
simp only [hp, ciSup_unique]
simp only [iSup]
congr
apply Subset.antisymm
· rintro - ⟨i, rfl⟩
simp [hp i]
· rintro - ⟨i, rfl⟩
simp
theorem cbiInf_eq_of_forall {p : ι → Prop} {f : Subtype p → α} (hp : ∀ i, p i) :
⨅ (i) (h : p i), f ⟨i, h⟩ = iInf f :=
cbiSup_eq_of_forall (α := αᵒᵈ) hp
/-- Introduction rule to prove that `b` is the supremum of `f`: it suffices to check that `b`
is larger than `f i` for all `i`, and that this is not the case of any `w<b`.
See `iSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/
theorem ciSup_eq_of_forall_le_of_forall_lt_exists_gt [Nonempty ι] {f : ι → α} (h₁ : ∀ i, f i ≤ b)
(h₂ : ∀ w, w < b → ∃ i, w < f i) : ⨆ i : ι, f i = b :=
csSup_eq_of_forall_le_of_forall_lt_exists_gt (range_nonempty f) (forall_mem_range.mpr h₁)
fun w hw => exists_range_iff.mpr <| h₂ w hw
-- Porting note: in mathlib3 `by exact` is not needed
/-- Introduction rule to prove that `b` is the infimum of `f`: it suffices to check that `b`
is smaller than `f i` for all `i`, and that this is not the case of any `w>b`.
See `iInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/
theorem ciInf_eq_of_forall_ge_of_forall_gt_exists_lt [Nonempty ι] {f : ι → α} (h₁ : ∀ i, b ≤ f i)
(h₂ : ∀ w, b < w → ∃ i, f i < w) : ⨅ i : ι, f i = b := by
exact ciSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ) (f := ‹_›) ‹_› ‹_›
/-- **Nested intervals lemma**: if `f` is a monotone sequence, `g` is an antitone sequence, and
`f n ≤ g n` for all `n`, then `⨆ n, f n` belongs to all the intervals `[f n, g n]`. -/
theorem Monotone.ciSup_mem_iInter_Icc_of_antitone [SemilatticeSup β] {f g : β → α} (hf : Monotone f)
(hg : Antitone g) (h : f ≤ g) : (⨆ n, f n) ∈ ⋂ n, Icc (f n) (g n) := by
refine mem_iInter.2 fun n => ?_
haveI : Nonempty β := ⟨n⟩
have : ∀ m, f m ≤ g n := fun m => hf.forall_le_of_antitone hg h m n
exact ⟨le_ciSup ⟨g <| n, forall_mem_range.2 this⟩ _, ciSup_le this⟩
/-- Nested intervals lemma: if `[f n, g n]` is an antitone sequence of nonempty
closed intervals, then `⨆ n, f n` belongs to all the intervals `[f n, g n]`. -/
theorem ciSup_mem_iInter_Icc_of_antitone_Icc [SemilatticeSup β] {f g : β → α}
(h : Antitone fun n => Icc (f n) (g n)) (h' : ∀ n, f n ≤ g n) :
(⨆ n, f n) ∈ ⋂ n, Icc (f n) (g n) :=
Monotone.ciSup_mem_iInter_Icc_of_antitone
(fun _ n hmn => ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).1)
(fun _ n hmn => ((Icc_subset_Icc_iff (h' n)).1 (h hmn)).2) h'
/-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that
1) `b` is an upper bound
2) every other upper bound `b'` satisfies `b ≤ b'`. -/
theorem csSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.Nonempty) (h_is_ub : ∀ a ∈ s, a ≤ b)
(h_b_le_ub : ∀ ub, (∀ a ∈ s, a ≤ ub) → b ≤ ub) : sSup s = b :=
(csSup_le hs h_is_ub).antisymm ((h_b_le_ub _) fun _ => le_csSup ⟨b, h_is_ub⟩)
lemma Set.Iic_ciInf [Nonempty ι] {f : ι → α} (hf : BddBelow (range f)) :
Iic (⨅ i, f i) = ⋂ i, Iic (f i) := by
apply Subset.antisymm
· rintro x hx - ⟨i, rfl⟩
exact hx.trans (ciInf_le hf _)
· rintro x hx
apply le_ciInf
simpa using hx
lemma Set.Ici_ciSup [Nonempty ι] {f : ι → α} (hf : BddAbove (range f)) :
Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
Iic_ciInf (α := αᵒᵈ) hf
lemma sup_eq_top_of_top_mem [OrderTop α] (h : ⊤ ∈ s) : sSup s = ⊤ :=
top_unique <| le_csSup (OrderTop.bddAbove s) h
lemma inf_eq_bot_of_bot_mem [OrderBot α] (h : ⊥ ∈ s) : sInf s = ⊥ :=
bot_unique <| csInf_le (OrderBot.bddBelow s) h
theorem ciSup_subtype [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : Subtype p → α}
(hf : BddAbove (Set.range f)) (hf' : sSup ∅ ≤ iSup f) :
iSup f = ⨆ (i) (h : p i), f ⟨i, h⟩ := by
classical
refine le_antisymm (ciSup_le ?_) ?_
· intro ⟨i, h⟩
have : f ⟨i, h⟩ = (fun i : ι ↦ ⨆ (h : p i), f ⟨i, h⟩) i := by simp [h]
rw [this]
refine le_ciSup (f := (fun i : ι ↦ ⨆ (h : p i), f ⟨i, h⟩)) ?_ i
simp_rw [ciSup_eq_ite]
refine (hf.union (bddAbove_singleton (a := sSup ∅))).mono ?_
intro
simp only [Set.mem_range, Set.union_singleton, Set.mem_insert_iff, Subtype.exists,
forall_exists_index]
intro b hb
split_ifs at hb
· exact Or.inr ⟨_, _, hb⟩
· simp_all
· refine ciSup_le fun i ↦ ?_
simp_rw [ciSup_eq_ite]
split_ifs
· exact le_ciSup hf ?_
· exact hf'
theorem ciInf_subtype [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : Subtype p → α}
(hf : BddBelow (Set.range f)) (hf' : iInf f ≤ sInf ∅) :
iInf f = ⨅ (i) (h : p i), f ⟨i, h⟩ :=
ciSup_subtype (α := αᵒᵈ) hf hf'
theorem ciSup_subtype' [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : ∀ i, p i → α}
(hf : BddAbove (Set.range (fun i : Subtype p ↦ f i i.prop)))
(hf' : sSup ∅ ≤ ⨆ (i : Subtype p), f i i.prop) :
⨆ (i) (h), f i h = ⨆ x : Subtype p, f x x.property :=
(ciSup_subtype (f := fun x => f x.val x.property) hf hf').symm
theorem ciInf_subtype' [Nonempty ι] {p : ι → Prop} [Nonempty (Subtype p)] {f : ∀ i, p i → α}
(hf : BddBelow (Set.range (fun i : Subtype p ↦ f i i.prop)))
(hf' : ⨅ (i : Subtype p), f i i.prop ≤ sInf ∅) :
⨅ (i) (h), f i h = ⨅ x : Subtype p, f x x.property :=
(ciInf_subtype (f := fun x => f x.val x.property) hf hf').symm
theorem ciSup_subtype'' {ι} [Nonempty ι] {s : Set ι} (hs : s.Nonempty) {f : ι → α}
(hf : BddAbove (Set.range fun i : s ↦ f i)) (hf' : sSup ∅ ≤ ⨆ i : s, f i) :
⨆ i : s, f i = ⨆ (t : ι) (_ : t ∈ s), f t :=
haveI : Nonempty s := Set.Nonempty.to_subtype hs
ciSup_subtype hf hf'
theorem ciInf_subtype'' {ι} [Nonempty ι] {s : Set ι} (hs : s.Nonempty) {f : ι → α}
(hf : BddBelow (Set.range fun i : s ↦ f i)) (hf' : ⨅ i : s, f i ≤ sInf ∅) :
⨅ i : s, f i = ⨅ (t : ι) (_ : t ∈ s), f t :=
haveI : Nonempty s := Set.Nonempty.to_subtype hs
ciInf_subtype hf hf'
theorem csSup_image [Nonempty β] {s : Set β} (hs : s.Nonempty) {f : β → α}
(hf : BddAbove (Set.range fun i : s ↦ f i)) (hf' : sSup ∅ ≤ ⨆ i : s, f i) :
sSup (f '' s) = ⨆ a ∈ s, f a := by
rw [← ciSup_subtype'' hs hf hf', iSup, Set.image_eq_range]
theorem csInf_image [Nonempty β] {s : Set β} (hs : s.Nonempty) {f : β → α}
(hf : BddBelow (Set.range fun i : s ↦ f i)) (hf' : ⨅ i : s, f i ≤ sInf ∅) :
sInf (f '' s) = ⨅ a ∈ s, f a :=
csSup_image (α := αᵒᵈ) hs hf hf'
lemma ciSup_image {α ι ι' : Type*} [ConditionallyCompleteLattice α] [Nonempty ι] [Nonempty ι']
{s : Set ι} (hs : s.Nonempty) {f : ι → ι'} {g : ι' → α}
(hf : BddAbove (Set.range fun i : s ↦ g (f i))) (hg' : sSup ∅ ≤ ⨆ i : s, g (f i)) :
⨆ i ∈ (f '' s), g i = ⨆ x ∈ s, g (f x) := by
have hg : BddAbove (Set.range fun i : f '' s ↦ g i) := by
simpa [bddAbove_def] using hf
have hf' : sSup ∅ ≤ ⨆ i : f '' s, g i := by
refine hg'.trans ?_
have : Nonempty s := Set.Nonempty.to_subtype hs
refine ciSup_le ?_
intro ⟨i, h⟩
obtain ⟨t, ht⟩ : ∃ t : f '' s, g t = g (f (Subtype.mk i h)) := by
have : f i ∈ f '' s := Set.mem_image_of_mem _ h
exact ⟨⟨f i, this⟩, by simp [this]⟩
rw [← ht]
refine le_ciSup_set ?_ t.prop
simpa [bddAbove_def] using hf
rw [← csSup_image (by simpa using hs) hg hf', ← csSup_image hs hf hg', ← Set.image_comp, comp_def]
lemma ciInf_image {α ι ι' : Type*} [ConditionallyCompleteLattice α] [Nonempty ι] [Nonempty ι']
{s : Set ι} (hs : s.Nonempty) {f : ι → ι'} {g : ι' → α}
(hf : BddBelow (Set.range fun i : s ↦ g (f i))) (hg' : ⨅ i : s, g (f i) ≤ sInf ∅) :
⨅ i ∈ (f '' s), g i = ⨅ x ∈ s, g (f x) :=
ciSup_image (α := αᵒᵈ) hs hf hg'
end ConditionallyCompleteLattice
instance Pi.conditionallyCompleteLattice {ι : Type*} {α : ι → Type*}
[∀ i, ConditionallyCompleteLattice (α i)] : ConditionallyCompleteLattice (∀ i, α i) :=
{ Pi.instLattice, Pi.supSet, Pi.infSet with
le_csSup := fun s f ⟨g, hg⟩ hf i =>
le_csSup ⟨g i, Set.forall_mem_range.2 fun ⟨f', hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩
csSup_le := fun s f hs hf i =>
(csSup_le (by haveI := hs.to_subtype; apply range_nonempty)) fun b ⟨⟨g, hg⟩, hb⟩ =>
hb ▸ hf hg i
csInf_le := fun s f ⟨g, hg⟩ hf i =>
csInf_le ⟨g i, Set.forall_mem_range.2 fun ⟨f', hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩
le_csInf := fun s f hs hf i =>
(le_csInf (by haveI := hs.to_subtype; apply range_nonempty)) fun b ⟨⟨g, hg⟩, hb⟩ =>
hb ▸ hf hg i }
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] {s t : Set α} {a b : α}
/-- When `b < sSup s`, there is an element `a` in `s` with `b < a`, if `s` is nonempty and the order
is a linear order. -/
theorem exists_lt_of_lt_csSup (hs : s.Nonempty) (hb : b < sSup s) : ∃ a ∈ s, b < a := by
contrapose! hb
exact csSup_le hs hb
/-- Indexed version of the above lemma `exists_lt_of_lt_csSup`.
When `b < iSup f`, there is an element `i` such that `b < f i`.
-/
theorem exists_lt_of_lt_ciSup [Nonempty ι] {f : ι → α} (h : b < iSup f) : ∃ i, b < f i :=
let ⟨_, ⟨i, rfl⟩, h⟩ := exists_lt_of_lt_csSup (range_nonempty f) h
⟨i, h⟩
/-- When `sInf s < b`, there is an element `a` in `s` with `a < b`, if `s` is nonempty and the order
is a linear order. -/
theorem exists_lt_of_csInf_lt (hs : s.Nonempty) (hb : sInf s < b) : ∃ a ∈ s, a < b :=
exists_lt_of_lt_csSup (α := αᵒᵈ) hs hb
/-- Indexed version of the above lemma `exists_lt_of_csInf_lt`
When `iInf f < a`, there is an element `i` such that `f i < a`.
-/
theorem exists_lt_of_ciInf_lt [Nonempty ι] {f : ι → α} (h : iInf f < a) : ∃ i, f i < a :=
exists_lt_of_lt_ciSup (α := αᵒᵈ) h
theorem csSup_of_not_bddAbove {s : Set α} (hs : ¬BddAbove s) : sSup s = sSup ∅ :=
ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove s hs
theorem csSup_eq_univ_of_not_bddAbove {s : Set α} (hs : ¬BddAbove s) : sSup s = sSup univ := by
rw [csSup_of_not_bddAbove hs, csSup_of_not_bddAbove (s := univ)]
contrapose! hs
exact hs.mono (subset_univ _)
theorem csInf_of_not_bddBelow {s : Set α} (hs : ¬BddBelow s) : sInf s = sInf ∅ :=
ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow s hs
theorem csInf_eq_univ_of_not_bddBelow {s : Set α} (hs : ¬BddBelow s) : sInf s = sInf univ :=
csSup_eq_univ_of_not_bddAbove (α := αᵒᵈ) hs
/-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then
`s` and `t` have the same supremum. This holds even when the sets may be empty or unbounded. -/
theorem csSup_eq_csSup_of_forall_exists_le {s t : Set α}
(hs : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) (ht : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) :
sSup s = sSup t := by
rcases eq_empty_or_nonempty s with rfl|s_ne
· have : t = ∅ := eq_empty_of_forall_not_mem (fun y yt ↦ by simpa using ht y yt)
rw [this]
rcases eq_empty_or_nonempty t with rfl|t_ne
· have : s = ∅ := eq_empty_of_forall_not_mem (fun x xs ↦ by simpa using hs x xs)
rw [this]
by_cases B : BddAbove s ∨ BddAbove t
· have Bs : BddAbove s := by
rcases B with hB|⟨b, hb⟩
· exact hB
· refine ⟨b, fun x hx ↦ ?_⟩
rcases hs x hx with ⟨y, hy, hxy⟩
exact hxy.trans (hb hy)
have Bt : BddAbove t := by
rcases B with ⟨b, hb⟩|hB
· refine ⟨b, fun y hy ↦ ?_⟩
rcases ht y hy with ⟨x, hx, hyx⟩
exact hyx.trans (hb hx)
· exact hB
apply le_antisymm
· apply csSup_le s_ne (fun x hx ↦ ?_)
rcases hs x hx with ⟨y, yt, hxy⟩
exact hxy.trans (le_csSup Bt yt)
· apply csSup_le t_ne (fun y hy ↦ ?_)
rcases ht y hy with ⟨x, xs, hyx⟩
exact hyx.trans (le_csSup Bs xs)
· simp [csSup_of_not_bddAbove, (not_or.1 B).1, (not_or.1 B).2]
/-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then
`s` and `t` have the same infimum. This holds even when the sets may be empty or unbounded. -/
theorem csInf_eq_csInf_of_forall_exists_le {s t : Set α}
(hs : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) (ht : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) :
sInf s = sInf t :=
csSup_eq_csSup_of_forall_exists_le (α := αᵒᵈ) hs ht
lemma sSup_iUnion_Iic (f : ι → α) : sSup (⋃ (i : ι), Iic (f i)) = ⨆ i, f i := by
apply csSup_eq_csSup_of_forall_exists_le
· rintro x ⟨-, ⟨i, rfl⟩, hi⟩
exact ⟨f i, mem_range_self _, hi⟩
· rintro x ⟨i, rfl⟩
exact ⟨f i, mem_iUnion_of_mem i le_rfl, le_rfl⟩
lemma sInf_iUnion_Ici (f : ι → α) : sInf (⋃ (i : ι), Ici (f i)) = ⨅ i, f i :=
sSup_iUnion_Iic (α := αᵒᵈ) f
theorem cbiSup_eq_of_not_forall {p : ι → Prop} {f : Subtype p → α} (hp : ¬ (∀ i, p i)) :
⨆ (i) (h : p i), f ⟨i, h⟩ = iSup f ⊔ sSup ∅ := by
classical
rcases not_forall.1 hp with ⟨i₀, hi₀⟩
have : Nonempty ι := ⟨i₀⟩
simp only [ciSup_eq_ite]
by_cases H : BddAbove (range f)
· have B : BddAbove (range fun i ↦ if h : p i then f ⟨i, h⟩ else sSup ∅) := by
rcases H with ⟨c, hc⟩
refine ⟨c ⊔ sSup ∅, ?_⟩
rintro - ⟨i, rfl⟩
by_cases hi : p i
· simp only [hi, dite_true, le_sup_iff, hc (mem_range_self _), true_or]
· simp only [hi, dite_false, le_sup_right]
apply le_antisymm
· apply ciSup_le (fun i ↦ ?_)
by_cases hi : p i
· simp only [hi, dite_true, le_sup_iff]
left
exact le_ciSup H _
· simp [hi]
· apply sup_le
· rcases isEmpty_or_nonempty (Subtype p) with hp|hp
· rw [iSup_of_empty']
convert le_ciSup B i₀
simp [hi₀]
· apply ciSup_le
rintro ⟨i, hi⟩
convert le_ciSup B i
simp [hi]
· convert le_ciSup B i₀
simp [hi₀]
· have : iSup f = sSup (∅ : Set α) := csSup_of_not_bddAbove H
simp only [this, le_refl, sup_of_le_left]
apply csSup_of_not_bddAbove
contrapose! H
apply H.mono
rintro - ⟨i, rfl⟩
convert mem_range_self i.1
simp [i.2]
theorem cbiInf_eq_of_not_forall {p : ι → Prop} {f : Subtype p → α} (hp : ¬ (∀ i, p i)) :
⨅ (i) (h : p i), f ⟨i, h⟩ = iInf f ⊓ sInf ∅ :=
cbiSup_eq_of_not_forall (α := αᵒᵈ) hp
open Function
variable [IsWellOrder α (· < ·)]
theorem sInf_eq_argmin_on (hs : s.Nonempty) : sInf s = argminOn id wellFounded_lt s hs :=
IsLeast.csInf_eq ⟨argminOn_mem _ _ _ _, fun _ ha => argminOn_le id _ _ ha⟩
theorem isLeast_csInf (hs : s.Nonempty) : IsLeast s (sInf s) := by
rw [sInf_eq_argmin_on hs]
exact ⟨argminOn_mem _ _ _ _, fun a ha => argminOn_le id _ _ ha⟩
theorem le_csInf_iff' (hs : s.Nonempty) : b ≤ sInf s ↔ b ∈ lowerBounds s :=
le_isGLB_iff (isLeast_csInf hs).isGLB
theorem csInf_mem (hs : s.Nonempty) : sInf s ∈ s :=
(isLeast_csInf hs).1
theorem ciInf_mem [Nonempty ι] (f : ι → α) : iInf f ∈ range f :=
csInf_mem (range_nonempty f)
theorem MonotoneOn.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β}
(hf : MonotoneOn f s) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) :=
(hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm
theorem Monotone.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β}
(hf : Monotone f) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) :=
(hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm
end ConditionallyCompleteLinearOrder
/-!
### Lemmas about a conditionally complete linear order with bottom element
In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions.
-/
section ConditionallyCompleteLinearOrderBot
@[simp]
theorem csInf_univ [ConditionallyCompleteLinearOrder α] [OrderBot α] : sInf (univ : Set α) = ⊥ :=
isLeast_univ.csInf_eq
variable [ConditionallyCompleteLinearOrderBot α] {s : Set α} {f : ι → α} {a : α}
@[simp]
theorem csSup_empty : (sSup ∅ : α) = ⊥ :=
ConditionallyCompleteLinearOrderBot.csSup_empty
@[simp]
theorem ciSup_of_empty [IsEmpty ι] (f : ι → α) : ⨆ i, f i = ⊥ := by
rw [iSup_of_empty', csSup_empty]
theorem ciSup_false (f : False → α) : ⨆ i, f i = ⊥ :=
ciSup_of_empty f
theorem isLUB_csSup' {s : Set α} (hs : BddAbove s) : IsLUB s (sSup s) := by
rcases eq_empty_or_nonempty s with (rfl | hne)
· simp only [csSup_empty, isLUB_empty]
· exact isLUB_csSup hne hs
theorem csSup_le_iff' {s : Set α} (hs : BddAbove s) {a : α} : sSup s ≤ a ↔ ∀ x ∈ s, x ≤ a :=
isLUB_le_iff (isLUB_csSup' hs)
theorem csSup_le' {s : Set α} {a : α} (h : a ∈ upperBounds s) : sSup s ≤ a :=
(csSup_le_iff' ⟨a, h⟩).2 h
theorem le_csSup_iff' {s : Set α} {a : α} (h : BddAbove s) :
a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b :=
⟨fun h _ hb => le_trans h (csSup_le' hb), fun hb => hb _ fun _ => le_csSup h⟩
theorem le_ciSup_iff' {s : ι → α} {a : α} (h : BddAbove (range s)) :
a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by simp [iSup, h, le_csSup_iff', upperBounds]
theorem le_csInf_iff'' {s : Set α} {a : α} (ne : s.Nonempty) :
a ≤ sInf s ↔ ∀ b : α, b ∈ s → a ≤ b :=
le_csInf_iff (OrderBot.bddBelow _) ne
theorem le_ciInf_iff' [Nonempty ι] {f : ι → α} {a : α} : a ≤ iInf f ↔ ∀ i, a ≤ f i :=
le_ciInf_iff (OrderBot.bddBelow _)
theorem csInf_le' (h : a ∈ s) : sInf s ≤ a := csInf_le (OrderBot.bddBelow _) h
theorem ciInf_le' (f : ι → α) (i : ι) : iInf f ≤ f i := ciInf_le (OrderBot.bddBelow _) _
lemma ciInf_le_of_le' (c : ι) : f c ≤ a → iInf f ≤ a := ciInf_le_of_le (OrderBot.bddBelow _) _
theorem exists_lt_of_lt_csSup' {s : Set α} {a : α} (h : a < sSup s) : ∃ b ∈ s, a < b := by
contrapose! h
exact csSup_le' h
theorem ciSup_le_iff' {f : ι → α} (h : BddAbove (range f)) {a : α} :
⨆ i, f i ≤ a ↔ ∀ i, f i ≤ a :=
(csSup_le_iff' h).trans forall_mem_range
theorem ciSup_le' {f : ι → α} {a : α} (h : ∀ i, f i ≤ a) : ⨆ i, f i ≤ a :=
csSup_le' <| forall_mem_range.2 h
theorem exists_lt_of_lt_ciSup' {f : ι → α} {a : α} (h : a < ⨆ i, f i) : ∃ i, a < f i := by
contrapose! h
exact ciSup_le' h
theorem ciSup_mono' {ι'} {f : ι → α} {g : ι' → α} (hg : BddAbove (range g))
(h : ∀ i, ∃ i', f i ≤ g i') : iSup f ≤ iSup g :=
ciSup_le' fun i => Exists.elim (h i) (le_ciSup_of_le hg)
theorem csInf_le_csInf' {s t : Set α} (h₁ : t.Nonempty) (h₂ : t ⊆ s) : sInf s ≤ sInf t :=
csInf_le_csInf (OrderBot.bddBelow s) h₁ h₂
lemma ciSup_or' (p q : Prop) (f : p ∨ q → α) :
⨆ (h : p ∨ q), f h = (⨆ h : p, f (.inl h)) ⊔ ⨆ h : q, f (.inr h) := by
by_cases hp : p <;> by_cases hq : q
· simp [hp, hq]
· simp [hp, hq]
· simp [hp, hq]
· simp [hp, hq]
end ConditionallyCompleteLinearOrderBot
namespace WithTop
variable [ConditionallyCompleteLinearOrderBot α]
/-- The `sSup` of a non-empty set is its least upper bound for a conditionally
complete lattice with a top. -/
theorem isLUB_sSup' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)}
(hs : s.Nonempty) : IsLUB s (sSup s) := by
classical
constructor
· show ite _ _ _ ∈ _
split_ifs with h₁ h₂
· intro _ _
exact le_top
· rintro (⟨⟩ | a) ha
· contradiction
apply coe_le_coe.2
exact le_csSup h₂ ha
· intro _ _
exact le_top
· show ite _ _ _ ∈ _
split_ifs with h₁ h₂
· rintro (⟨⟩ | a) ha
· exact le_rfl
· exact False.elim (not_top_le_coe a (ha h₁))
· rintro (⟨⟩ | b) hb
· exact le_top
refine coe_le_coe.2 (csSup_le ?_ ?_)
· rcases hs with ⟨⟨⟩ | b, hb⟩
· exact absurd hb h₁
· exact ⟨b, hb⟩
· intro a ha
exact coe_le_coe.1 (hb ha)
· rintro (⟨⟩ | b) hb
· exact le_rfl
· exfalso
apply h₂
use b
intro a ha
exact coe_le_coe.1 (hb ha)
-- Porting note: in mathlib3 `dsimp only [sSup]` was not needed, we used `show IsLUB ∅ (ite _ _ _)`
theorem isLUB_sSup (s : Set (WithTop α)) : IsLUB s (sSup s) := by
rcases s.eq_empty_or_nonempty with hs | hs
· rw [hs]
dsimp only [sSup]
show IsLUB ∅ _
split_ifs with h₁ h₂
· cases h₁
· rw [preimage_empty, csSup_empty]
exact isLUB_empty
· exfalso
apply h₂
use ⊥
rintro a ⟨⟩
exact isLUB_sSup' hs
/-- The `sInf` of a bounded-below set is its greatest lower bound for a conditionally
complete lattice with a top. -/
theorem isGLB_sInf' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)}
(hs : BddBelow s) : IsGLB s (sInf s) := by
classical
constructor
· show ite _ _ _ ∈ _
simp only [hs, not_true_eq_false, or_false]
split_ifs with h
· intro a ha
exact top_le_iff.2 (Set.mem_singleton_iff.1 (h ha))
· rintro (⟨⟩ | a) ha
· exact le_top
refine coe_le_coe.2 (csInf_le ?_ ha)
rcases hs with ⟨⟨⟩ | b, hb⟩
· exfalso
apply h
intro c hc
rw [mem_singleton_iff, ← top_le_iff]
exact hb hc
use b
intro c hc
exact coe_le_coe.1 (hb hc)
· show ite _ _ _ ∈ _
simp only [hs, not_true_eq_false, or_false]
split_ifs with h
· intro _ _
exact le_top
· rintro (⟨⟩ | a) ha
· exfalso
apply h
intro b hb
exact Set.mem_singleton_iff.2 (top_le_iff.1 (ha hb))
· refine coe_le_coe.2 (le_csInf ?_ ?_)
· classical
contrapose! h
rintro (⟨⟩ | a) ha
· exact mem_singleton ⊤
· exact (not_nonempty_iff_eq_empty.2 h ⟨a, ha⟩).elim
· intro b hb
rw [← coe_le_coe]
exact ha hb
theorem isGLB_sInf (s : Set (WithTop α)) : IsGLB s (sInf s) := by
by_cases hs : BddBelow s
· exact isGLB_sInf' hs
· exfalso
apply hs
use ⊥
intro _ _
exact bot_le
noncomputable instance : CompleteLinearOrder (WithTop α) where
__ := linearOrder
__ := LinearOrder.toBiheytingAlgebra
le_sSup s := (isLUB_sSup s).1
sSup_le s := (isLUB_sSup s).2
le_sInf s := (isGLB_sInf s).2
sInf_le s := (isGLB_sInf s).1
/-- A version of `WithTop.coe_sSup'` with a more convenient but less general statement. -/
@[norm_cast]
theorem coe_sSup {s : Set α} (hb : BddAbove s) : ↑(sSup s) = (⨆ a ∈ s, ↑a : WithTop α) := by
rw [coe_sSup' hb, sSup_image]
/-- A version of `WithTop.coe_sInf'` with a more convenient but less general statement. -/
@[norm_cast]
theorem coe_sInf {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) :
↑(sInf s) = (⨅ a ∈ s, ↑a : WithTop α) := by
rw [coe_sInf' hs h's, sInf_image]
end WithTop
namespace Monotone
variable [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} (h_mono : Monotone f)
/-! A monotone function into a conditionally complete lattice preserves the ordering properties of
`sSup` and `sInf`. -/
theorem le_csSup_image {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddAbove s) :
f c ≤ sSup (f '' s) :=
le_csSup (map_bddAbove h_mono h_bdd) (mem_image_of_mem f hcs)
theorem csSup_image_le {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ upperBounds s) :
sSup (f '' s) ≤ f B :=
csSup_le (Nonempty.image f hs) (h_mono.mem_upperBounds_image hB)
-- Porting note: in mathlib3 `f'` is not needed
theorem csInf_image_le {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddBelow s) :
sInf (f '' s) ≤ f c := by
let f' : αᵒᵈ → βᵒᵈ := f
exact le_csSup_image (α := αᵒᵈ) (β := βᵒᵈ)
(show Monotone f' from fun x y hxy => h_mono hxy) hcs h_bdd
-- Porting note: in mathlib3 `f'` is not needed
theorem le_csInf_image {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ lowerBounds s) :
f B ≤ sInf (f '' s) := by
let f' : αᵒᵈ → βᵒᵈ := f
exact csSup_image_le (α := αᵒᵈ) (β := βᵒᵈ)
(show Monotone f' from fun x y hxy => h_mono hxy) hs hB
end Monotone
namespace GaloisConnection
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι] {l : α → β}
{u : β → α}
theorem l_csSup (gc : GaloisConnection l u) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) :
l (sSup s) = ⨆ x : s, l x :=
Eq.symm <| IsLUB.ciSup_set_eq (gc.isLUB_l_image <| isLUB_csSup hne hbdd) hne
theorem l_csSup' (gc : GaloisConnection l u) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) :
l (sSup s) = sSup (l '' s) := by rw [gc.l_csSup hne hbdd, sSup_image']
theorem l_ciSup (gc : GaloisConnection l u) {f : ι → α} (hf : BddAbove (range f)) :
l (⨆ i, f i) = ⨆ i, l (f i) := by rw [iSup, gc.l_csSup (range_nonempty _) hf, iSup_range']
theorem l_ciSup_set (gc : GaloisConnection l u) {s : Set γ} {f : γ → α} (hf : BddAbove (f '' s))
(hne : s.Nonempty) : l (⨆ i : s, f i) = ⨆ i : s, l (f i) := by
haveI := hne.to_subtype
rw [image_eq_range] at hf
exact gc.l_ciSup hf
theorem u_csInf (gc : GaloisConnection l u) {s : Set β} (hne : s.Nonempty) (hbdd : BddBelow s) :
u (sInf s) = ⨅ x : s, u x :=
gc.dual.l_csSup hne hbdd
theorem u_csInf' (gc : GaloisConnection l u) {s : Set β} (hne : s.Nonempty) (hbdd : BddBelow s) :
u (sInf s) = sInf (u '' s) :=
gc.dual.l_csSup' hne hbdd
theorem u_ciInf (gc : GaloisConnection l u) {f : ι → β} (hf : BddBelow (range f)) :
u (⨅ i, f i) = ⨅ i, u (f i) :=
gc.dual.l_ciSup hf
theorem u_ciInf_set (gc : GaloisConnection l u) {s : Set γ} {f : γ → β} (hf : BddBelow (f '' s))
(hne : s.Nonempty) : u (⨅ i : s, f i) = ⨅ i : s, u (f i) :=
gc.dual.l_ciSup_set hf hne
end GaloisConnection
namespace OrderIso
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [Nonempty ι]
theorem map_csSup (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) :
e (sSup s) = ⨆ x : s, e x :=
e.to_galoisConnection.l_csSup hne hbdd
theorem map_csSup' (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddAbove s) :
e (sSup s) = sSup (e '' s) :=
e.to_galoisConnection.l_csSup' hne hbdd
theorem map_ciSup (e : α ≃o β) {f : ι → α} (hf : BddAbove (range f)) :
e (⨆ i, f i) = ⨆ i, e (f i) :=
e.to_galoisConnection.l_ciSup hf
theorem map_ciSup_set (e : α ≃o β) {s : Set γ} {f : γ → α} (hf : BddAbove (f '' s))
(hne : s.Nonempty) : e (⨆ i : s, f i) = ⨆ i : s, e (f i) :=
e.to_galoisConnection.l_ciSup_set hf hne
theorem map_csInf (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddBelow s) :
e (sInf s) = ⨅ x : s, e x :=
e.dual.map_csSup hne hbdd
theorem map_csInf' (e : α ≃o β) {s : Set α} (hne : s.Nonempty) (hbdd : BddBelow s) :
e (sInf s) = sInf (e '' s) :=
e.dual.map_csSup' hne hbdd
theorem map_ciInf (e : α ≃o β) {f : ι → α} (hf : BddBelow (range f)) :
e (⨅ i, f i) = ⨅ i, e (f i) :=
e.dual.map_ciSup hf
theorem map_ciInf_set (e : α ≃o β) {s : Set γ} {f : γ → α} (hf : BddBelow (f '' s))
(hne : s.Nonempty) : e (⨅ i : s, f i) = ⨅ i : s, e (f i) :=
e.dual.map_ciSup_set hf hne
end OrderIso
/-!
### Supremum/infimum of `Set.image2`
A collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under
a binary function whose partial evaluations are lower/upper adjoints of Galois connections.
-/
section
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β]
[ConditionallyCompleteLattice γ] {f : α → β → γ} {s : Set α} {t : Set β}
variable {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β}
theorem csSup_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) (hs₀ : s.Nonempty) (hs₁ : BddAbove s)
(ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (image2 l s t) = l (sSup s) (sSup t) := by
refine eq_of_forall_ge_iff fun c => ?_
rw [csSup_le_iff (hs₁.image2 (fun _ => (h₁ _).monotone_l) (fun _ => (h₂ _).monotone_l) ht₁)
(hs₀.image2 ht₀),
forall_image2_iff, forall₂_swap, (h₂ _).le_iff_le, csSup_le_iff ht₁ ht₀]
simp_rw [← (h₂ _).le_iff_le, (h₁ _).le_iff_le, csSup_le_iff hs₁ hs₀]
theorem csSup_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sSup s) (sInf t) :=
csSup_image2_eq_csSup_csSup (β := βᵒᵈ) h₁ h₂
theorem csSup_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sSup (image2 l s t) = l (sInf s) (sSup t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) h₁ h₂
theorem csSup_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sInf s) (sInf t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sInf s) (sInf t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) (γ := γᵒᵈ) (u₁ := l₁) (u₂ := l₂)
(fun _ => (h₁ _).dual) fun _ => (h₂ _).dual
theorem csInf_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sInf s) (sSup t) :=
csInf_image2_eq_csInf_csInf (β := βᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) :
s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sSup s) (sInf t) :=
csInf_image2_eq_csInf_csInf (α := αᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
s.Nonempty → BddAbove s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sSup s) (sSup t) :=
csInf_image2_eq_csInf_csInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
end
section WithTopBot
/-!
### Complete lattice structure on `WithTop (WithBot α)`
If `α` is a `ConditionallyCompleteLattice`, then we show that `WithTop α` and `WithBot α`
also inherit the structure of conditionally complete lattices. Furthermore, we show
that `WithTop (WithBot α)` and `WithBot (WithTop α)` naturally inherit the structure of a
complete lattice. Note that for `α` a conditionally complete lattice, `sSup` and `sInf` both return
junk values for sets which are empty or unbounded. The extension of `sSup` to `WithTop α` fixes
the unboundedness problem and the extension to `WithBot α` fixes the problem with
the empty set.
This result can be used to show that the extended reals `[-∞, ∞]` are a complete linear order.
-/
/-- Adding a top element to a conditionally complete lattice
gives a conditionally complete lattice -/
noncomputable instance WithTop.conditionallyCompleteLattice {α : Type*}
[ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithTop α) :=
{ lattice, instSupSet, instInfSet with
le_csSup := fun _ a _ haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS
csSup_le := fun _ _ hS haS => (WithTop.isLUB_sSup' hS).2 haS
csInf_le := fun _ _ hS haS => (WithTop.isGLB_sInf' hS).1 haS
le_csInf := fun _ a _ haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS }
/-- Adding a bottom element to a conditionally complete lattice
gives a conditionally complete lattice -/
noncomputable instance WithBot.conditionallyCompleteLattice {α : Type*}
[ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithBot α) :=
{ WithBot.lattice with
le_csSup := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csInf_le
csSup_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csInf
csInf_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csSup
le_csInf := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csSup_le }
open Classical in
-- Porting note: `convert @bot_le (WithTop (WithBot α)) _ _ a` was `convert bot_le`
noncomputable instance WithTop.WithBot.completeLattice {α : Type*}
[ConditionallyCompleteLattice α] : CompleteLattice (WithTop (WithBot α)) :=
{ instInfSet, instSupSet, boundedOrder, lattice with
le_sSup := fun S a haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS
sSup_le := fun S a ha => by
rcases S.eq_empty_or_nonempty with h | h
· show ite _ _ _ ≤ a
split_ifs with h₁ h₂
· rw [h] at h₁
cases h₁
· convert bot_le (a := a)
-- Porting note: previous proof relied on convert unfolding
-- the definition of ⊥
apply congr_arg
simp only [h, preimage_empty, WithBot.sSup_empty]
· exfalso
apply h₂
use ⊥
rw [h]
rintro b ⟨⟩
· exact (WithTop.isLUB_sSup' h).2 ha
sInf_le := fun S a haS =>
show ite _ _ _ ≤ a by
simp only [OrderBot.bddBelow, not_true_eq_false, or_false]
split_ifs with h₁
· cases' a with a
· exact le_rfl
cases h₁ haS
· cases a
· exact le_top
· apply WithTop.coe_le_coe.2
refine csInf_le ?_ haS
use ⊥
intro b _
exact bot_le
le_sInf := fun S a haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS }
noncomputable instance WithTop.WithBot.completeLinearOrder {α : Type*}
[ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithTop (WithBot α)) :=
-- FIXME: Spread notation doesn't work
{ completeLattice, linearOrder, LinearOrder.toBiheytingAlgebra with }
noncomputable instance WithBot.WithTop.completeLattice {α : Type*}
[ConditionallyCompleteLattice α] : CompleteLattice (WithBot (WithTop α)) :=
{ instInfSet, instSupSet, instBoundedOrder, lattice with
le_sSup := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sInf_le
sSup_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sInf
sInf_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sSup
le_sInf := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sSup_le }
noncomputable instance WithBot.WithTop.completeLinearOrder {α : Type*}
[ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithBot (WithTop α)) :=
{ completeLattice, linearOrder, LinearOrder.toBiheytingAlgebra with }
namespace WithTop
variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α}
lemma iSup_coe_eq_top : ⨆ x, (f x : WithTop α) = ⊤ ↔ ¬BddAbove (range f) := by
rw [iSup_eq_top, not_bddAbove_iff]
refine ⟨fun hf r => ?_, fun hf a ha => ?_⟩
· rcases hf r (WithTop.coe_lt_top r) with ⟨i, hi⟩
exact ⟨f i, ⟨i, rfl⟩, WithTop.coe_lt_coe.mp hi⟩
· rcases hf (a.untop ha.ne) with ⟨-, ⟨i, rfl⟩, hi⟩
exact ⟨i, by simpa only [WithTop.coe_untop _ ha.ne] using WithTop.coe_lt_coe.mpr hi⟩
lemma iSup_coe_lt_top : ⨆ x, (f x : WithTop α) < ⊤ ↔ BddAbove (range f) :=
lt_top_iff_ne_top.trans iSup_coe_eq_top.not_left
lemma iInf_coe_eq_top : ⨅ x, (f x : WithTop α) = ⊤ ↔ IsEmpty ι := by simp [isEmpty_iff]
lemma iInf_coe_lt_top : ⨅ i, (f i : WithTop α) < ⊤ ↔ Nonempty ι := by
rw [lt_top_iff_ne_top, Ne, iInf_coe_eq_top, not_isEmpty_iff]
end WithTop
end WithTopBot
-- Guard against import creep
assert_not_exists Multiset
|
Order\ConditionallyCompleteLattice\Finset.lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Data.Set.Finite
/-!
# Conditionally complete lattices and finite sets.
-/
open Set
variable {ι α β γ : Type*}
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] {s t : Set α} {a b : α}
theorem Finset.Nonempty.csSup_eq_max' {s : Finset α} (h : s.Nonempty) : sSup ↑s = s.max' h :=
eq_of_forall_ge_iff fun _ => (csSup_le_iff s.bddAbove h.to_set).trans (s.max'_le_iff h).symm
theorem Finset.Nonempty.csInf_eq_min' {s : Finset α} (h : s.Nonempty) : sInf ↑s = s.min' h :=
@Finset.Nonempty.csSup_eq_max' αᵒᵈ _ s h
theorem Finset.Nonempty.csSup_mem {s : Finset α} (h : s.Nonempty) : sSup (s : Set α) ∈ s := by
rw [h.csSup_eq_max']
exact s.max'_mem _
theorem Finset.Nonempty.csInf_mem {s : Finset α} (h : s.Nonempty) : sInf (s : Set α) ∈ s :=
@Finset.Nonempty.csSup_mem αᵒᵈ _ _ h
theorem Set.Nonempty.csSup_mem (h : s.Nonempty) (hs : s.Finite) : sSup s ∈ s := by
lift s to Finset α using hs
exact Finset.Nonempty.csSup_mem h
theorem Set.Nonempty.csInf_mem (h : s.Nonempty) (hs : s.Finite) : sInf s ∈ s :=
@Set.Nonempty.csSup_mem αᵒᵈ _ _ h hs
theorem Set.Finite.csSup_lt_iff (hs : s.Finite) (h : s.Nonempty) : sSup s < a ↔ ∀ x ∈ s, x < a :=
⟨fun h _ hx => (le_csSup hs.bddAbove hx).trans_lt h, fun H => H _ <| h.csSup_mem hs⟩
theorem Set.Finite.lt_csInf_iff (hs : s.Finite) (h : s.Nonempty) : a < sInf s ↔ ∀ x ∈ s, a < x :=
@Set.Finite.csSup_lt_iff αᵒᵈ _ _ _ hs h
end ConditionallyCompleteLinearOrder
/-!
### Relation between `sSup` / `sInf` and `Finset.sup'` / `Finset.inf'`
Like the `Sup` of a `ConditionallyCompleteLattice`, `Finset.sup'` also requires the set to be
non-empty. As a result, we can translate between the two.
-/
namespace Finset
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
theorem sup'_eq_csSup_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) :
s.sup' H f = sSup (f '' s) :=
eq_of_forall_ge_iff fun a => by
simp [csSup_le_iff (s.finite_toSet.image f).bddAbove (H.to_set.image f)]
theorem inf'_eq_csInf_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) :
s.inf' H f = sInf (f '' s) :=
sup'_eq_csSup_image (α := αᵒᵈ) _ H _
theorem sup'_id_eq_csSup (s : Finset α) (hs) : s.sup' hs id = sSup s := by
rw [sup'_eq_csSup_image s hs, Set.image_id]
theorem inf'_id_eq_csInf (s : Finset α) (hs) : s.inf' hs id = sInf s :=
sup'_id_eq_csSup (α := αᵒᵈ) _ hs
variable [Fintype ι] [Nonempty ι]
lemma sup'_univ_eq_ciSup (f : ι → α) : univ.sup' univ_nonempty f = ⨆ i, f i := by
simp [sup'_eq_csSup_image, iSup]
lemma inf'_univ_eq_ciInf (f : ι → α) : univ.inf' univ_nonempty f = ⨅ i, f i := by
simp [inf'_eq_csInf_image, iInf]
end ConditionallyCompleteLattice
section ConditionallyCompleteLinearOrderBot
variable [ConditionallyCompleteLinearOrderBot α]
lemma sup_univ_eq_ciSup [Fintype ι] (f : ι → α) : univ.sup f = ⨆ i, f i :=
le_antisymm
(Finset.sup_le fun _ _ => le_ciSup (finite_range _).bddAbove _)
(ciSup_le' fun _ => Finset.le_sup (mem_univ _))
end ConditionallyCompleteLinearOrderBot
end Finset
|
Order\ConditionallyCompleteLattice\Group.lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
/-!
# Conditionally complete lattices and groups.
-/
section Group
variable {α : Type*} {ι : Sort*} {ι' : Sort*} [Nonempty ι] [Nonempty ι']
[ConditionallyCompleteLattice α] [Group α]
@[to_additive]
theorem le_mul_ciInf [CovariantClass α α (· * ·) (· ≤ ·)] {a : α} {g : α} {h : ι → α}
(H : ∀ j, a ≤ g * h j) : a ≤ g * iInf h :=
inv_mul_le_iff_le_mul.mp <| le_ciInf fun _ => inv_mul_le_iff_le_mul.mpr <| H _
@[to_additive]
theorem mul_ciSup_le [CovariantClass α α (· * ·) (· ≤ ·)] {a : α} {g : α} {h : ι → α}
(H : ∀ j, g * h j ≤ a) : g * iSup h ≤ a :=
le_mul_ciInf (α := αᵒᵈ) H
@[to_additive]
theorem le_ciInf_mul [CovariantClass α α (Function.swap (· * ·)) (· ≤ ·)] {a : α} {g : ι → α}
{h : α} (H : ∀ i, a ≤ g i * h) : a ≤ iInf g * h :=
mul_inv_le_iff_le_mul.mp <| le_ciInf fun _ => mul_inv_le_iff_le_mul.mpr <| H _
@[to_additive]
theorem ciSup_mul_le [CovariantClass α α (Function.swap (· * ·)) (· ≤ ·)] {a : α} {g : ι → α}
{h : α} (H : ∀ i, g i * h ≤ a) : iSup g * h ≤ a :=
le_ciInf_mul (α := αᵒᵈ) H
@[to_additive]
theorem le_ciInf_mul_ciInf [CovariantClass α α (· * ·) (· ≤ ·)]
[CovariantClass α α (Function.swap (· * ·)) (· ≤ ·)] {a : α} {g : ι → α} {h : ι' → α}
(H : ∀ i j, a ≤ g i * h j) : a ≤ iInf g * iInf h :=
le_ciInf_mul fun _ => le_mul_ciInf <| H _
@[to_additive]
theorem ciSup_mul_ciSup_le [CovariantClass α α (· * ·) (· ≤ ·)]
[CovariantClass α α (Function.swap (· * ·)) (· ≤ ·)] {a : α} {g : ι → α} {h : ι' → α}
(H : ∀ i j, g i * h j ≤ a) : iSup g * iSup h ≤ a :=
ciSup_mul_le fun _ => mul_ciSup_le <| H _
end Group
|
Order\Extension\Linear.lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.Order.Zorn
/-!
# Extend a partial order to a linear order
This file constructs a linear order which is an extension of the given partial order, using Zorn's
lemma.
-/
universe u
open Set
/-- Any partial order can be extended to a linear order.
-/
theorem extend_partialOrder {α : Type u} (r : α → α → Prop) [IsPartialOrder α r] :
∃ s : α → α → Prop, IsLinearOrder α s ∧ r ≤ s := by
let S := { s | IsPartialOrder α s }
have hS : ∀ c, c ⊆ S → IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ S, ∀ z ∈ c, z ≤ ub := by
rintro c hc₁ hc₂ s hs
haveI := (hc₁ hs).1
refine ⟨sSup c, ?_, fun z hz => le_sSup hz⟩
refine
{ refl := ?_
trans := ?_
antisymm := ?_ } <;>
simp_rw [binary_relation_sSup_iff]
· intro x
exact ⟨s, hs, refl x⟩
· rintro x y z ⟨s₁, h₁s₁, h₂s₁⟩ ⟨s₂, h₁s₂, h₂s₂⟩
haveI : IsPartialOrder _ _ := hc₁ h₁s₁
haveI : IsPartialOrder _ _ := hc₁ h₁s₂
cases' hc₂.total h₁s₁ h₁s₂ with h h
· exact ⟨s₂, h₁s₂, _root_.trans (h _ _ h₂s₁) h₂s₂⟩
· exact ⟨s₁, h₁s₁, _root_.trans h₂s₁ (h _ _ h₂s₂)⟩
· rintro x y ⟨s₁, h₁s₁, h₂s₁⟩ ⟨s₂, h₁s₂, h₂s₂⟩
haveI : IsPartialOrder _ _ := hc₁ h₁s₁
haveI : IsPartialOrder _ _ := hc₁ h₁s₂
cases' hc₂.total h₁s₁ h₁s₂ with h h
· exact antisymm (h _ _ h₂s₁) h₂s₂
· apply antisymm h₂s₁ (h _ _ h₂s₂)
obtain ⟨s, hs₁ : IsPartialOrder _ _, rs, hs₂⟩ := zorn_nonempty_partialOrder₀ S hS r ‹_›
haveI : IsPartialOrder α s := hs₁
refine ⟨s, { total := ?_, refl := hs₁.refl, trans := hs₁.trans, antisymm := hs₁.antisymm } , rs⟩
intro x y
by_contra! h
let s' x' y' := s x' y' ∨ s x' x ∧ s y y'
rw [← hs₂ s' _ fun _ _ ↦ Or.inl] at h
· apply h.1 (Or.inr ⟨refl _, refl _⟩)
· refine
{ refl := fun x ↦ Or.inl (refl _)
trans := ?_
antisymm := ?_ }
· rintro a b c (ab | ⟨ax : s a x, yb : s y b⟩) (bc | ⟨bx : s b x, yc : s y c⟩)
· exact Or.inl (_root_.trans ab bc)
· exact Or.inr ⟨_root_.trans ab bx, yc⟩
· exact Or.inr ⟨ax, _root_.trans yb bc⟩
· exact Or.inr ⟨ax, yc⟩
rintro a b (ab | ⟨ax : s a x, yb : s y b⟩) (ba | ⟨bx : s b x, ya : s y a⟩)
· exact antisymm ab ba
· exact (h.2 (_root_.trans ya (_root_.trans ab bx))).elim
· exact (h.2 (_root_.trans yb (_root_.trans ba ax))).elim
· exact (h.2 (_root_.trans yb bx)).elim
/-- A type alias for `α`, intended to extend a partial order on `α` to a linear order. -/
def LinearExtension (α : Type u) : Type u :=
α
noncomputable instance {α : Type u} [PartialOrder α] : LinearOrder (LinearExtension α) where
le := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose
le_refl := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.1.1.1
le_trans := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.1.2.1
le_antisymm := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.1.2.1
le_total := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.1.2.1
decidableLE := Classical.decRel _
/-- The embedding of `α` into `LinearExtension α` as an order homomorphism. -/
def toLinearExtension {α : Type u} [PartialOrder α] : α →o LinearExtension α where
toFun x := x
monotone' := (extend_partialOrder ((· ≤ ·) : α → α → Prop)).choose_spec.2
instance {α : Type u} [Inhabited α] : Inhabited (LinearExtension α) :=
⟨(default : α)⟩
|
Order\Extension\Well.lean | /-
Copyright (c) 2022 Yaël Dillies, Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Junyan Xu
-/
import Mathlib.Data.Prod.Lex
import Mathlib.SetTheory.Ordinal.Arithmetic
/-!
# Extend a well-founded order to a well-order
This file constructs a well-order (linear well-founded order) which is an extension of a given
well-founded order.
## Proof idea
We can map our order into two well-orders:
* the first map respects the order but isn't necessarily injective. Namely, this is the *rank*
function `WellFounded.rank : α → Ordinal`.
* the second map is injective but doesn't necessarily respect the order. This is an arbitrary
embedding into `Cardinal` given by `embeddingToCardinal`.
Then their lexicographic product is a well-founded linear order which our original order injects in.
## Porting notes
The definition in `mathlib` 3 used an auxiliary well-founded order on `α` lifted from `Cardinal`
instead of `Cardinal`. The new definition is definitionally equal to the `mathlib` 3 version but
avoids non-standard instances.
## Tags
well founded relation, well order, extension
-/
universe u
variable {α : Type u} {r : α → α → Prop}
namespace WellFounded
variable (hwf : WellFounded r)
/-- An arbitrary well order on `α` that extends `r`.
The construction maps `r` into two well-orders: the first map is `WellFounded.rank`, which is not
necessarily injective but respects the order `r`; the other map is the identity (with an arbitrarily
chosen well-order on `α`), which is injective but doesn't respect `r`.
By taking the lexicographic product of the two, we get both properties, so we can pull it back and
get a well-order that extend our original order `r`. Another way to view this is that we choose an
arbitrary well-order to serve as a tiebreak between two elements of same rank.
-/
noncomputable def wellOrderExtension : LinearOrder α :=
@LinearOrder.lift' α (Ordinal ×ₗ Cardinal) _ (fun a : α => (hwf.rank a, embeddingToCardinal a))
fun _ _ h => embeddingToCardinal.injective <| congr_arg Prod.snd h
instance wellOrderExtension.isWellFounded_lt : IsWellFounded α hwf.wellOrderExtension.lt :=
⟨InvImage.wf (fun a : α => (hwf.rank a, embeddingToCardinal a)) <|
Ordinal.lt_wf.prod_lex Cardinal.lt_wf⟩
/-- Any well-founded relation can be extended to a well-ordering on that type. -/
theorem exists_well_order_ge : ∃ s, r ≤ s ∧ IsWellOrder α s :=
⟨hwf.wellOrderExtension.lt, fun _ _ h => Prod.Lex.left _ _ (hwf.rank_lt_of_rel h), ⟨⟩⟩
end WellFounded
/-- A type alias for `α`, intended to extend a well-founded order on `α` to a well-order. -/
def WellOrderExtension (α : Type*) : Type _ := α
instance [Inhabited α] : Inhabited (WellOrderExtension α) := ‹_›
/-- "Identity" equivalence between a well-founded order and its well-order extension. -/
def toWellOrderExtension : α ≃ WellOrderExtension α :=
Equiv.refl _
noncomputable instance [LT α] [WellFoundedLT α] : LinearOrder (WellOrderExtension α) :=
(IsWellFounded.wf : @WellFounded α (· < ·)).wellOrderExtension
instance WellOrderExtension.wellFoundedLT [LT α] [WellFoundedLT α] :
WellFoundedLT (WellOrderExtension α) :=
WellFounded.wellOrderExtension.isWellFounded_lt _
theorem toWellOrderExtension_strictMono [Preorder α] [WellFoundedLT α] :
StrictMono (toWellOrderExtension : α → WellOrderExtension α) := fun _ _ h =>
Prod.Lex.left _ _ <| WellFounded.rank_lt_of_rel _ h
|
Order\Filter\Archimedean.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Tactic.GCongr
/-!
# `Filter.atTop` filter and archimedean (semi)rings/fields
In this file we prove that for a linear ordered archimedean semiring `R` and a function `f : α → ℕ`,
the function `Nat.cast ∘ f : α → R` tends to `Filter.atTop` along a filter `l` if and only if so
does `f`. We also prove that `Nat.cast : ℕ → R` tends to `Filter.atTop` along `Filter.atTop`, as
well as version of these two results for `ℤ` (and a ring `R`) and `ℚ` (and a field `R`).
-/
variable {α R : Type*}
open Filter Set Function
@[simp]
theorem Nat.comap_cast_atTop [StrictOrderedSemiring R] [Archimedean R] :
comap ((↑) : ℕ → R) atTop = atTop :=
comap_embedding_atTop (fun _ _ => Nat.cast_le) exists_nat_ge
theorem tendsto_natCast_atTop_iff [StrictOrderedSemiring R] [Archimedean R] {f : α → ℕ}
{l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop :=
tendsto_atTop_embedding (fun _ _ => Nat.cast_le) exists_nat_ge
@[deprecated (since := "2024-04-17")]
alias tendsto_nat_cast_atTop_iff := tendsto_natCast_atTop_iff
theorem tendsto_natCast_atTop_atTop [OrderedSemiring R] [Archimedean R] :
Tendsto ((↑) : ℕ → R) atTop atTop :=
Nat.mono_cast.tendsto_atTop_atTop exists_nat_ge
@[deprecated (since := "2024-04-17")]
alias tendsto_nat_cast_atTop_atTop := tendsto_natCast_atTop_atTop
theorem Filter.Eventually.natCast_atTop [OrderedSemiring R] [Archimedean R] {p : R → Prop}
(h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℕ) in atTop, p n :=
tendsto_natCast_atTop_atTop.eventually h
@[deprecated (since := "2024-04-17")]
alias Filter.Eventually.nat_cast_atTop := Filter.Eventually.natCast_atTop
@[simp] theorem Int.comap_cast_atTop [StrictOrderedRing R] [Archimedean R] :
comap ((↑) : ℤ → R) atTop = atTop :=
comap_embedding_atTop (fun _ _ => Int.cast_le) fun r =>
let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, mod_cast hn⟩
@[simp]
theorem Int.comap_cast_atBot [StrictOrderedRing R] [Archimedean R] :
comap ((↑) : ℤ → R) atBot = atBot :=
comap_embedding_atBot (fun _ _ => Int.cast_le) fun r =>
let ⟨n, hn⟩ := exists_nat_ge (-r)
⟨-n, by simpa [neg_le] using hn⟩
theorem tendsto_intCast_atTop_iff [StrictOrderedRing R] [Archimedean R] {f : α → ℤ}
{l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by
rw [← @Int.comap_cast_atTop R, tendsto_comap_iff]; rfl
@[deprecated (since := "2024-04-17")]
alias tendsto_int_cast_atTop_iff := tendsto_intCast_atTop_iff
theorem tendsto_intCast_atBot_iff [StrictOrderedRing R] [Archimedean R] {f : α → ℤ}
{l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by
rw [← @Int.comap_cast_atBot R, tendsto_comap_iff]; rfl
@[deprecated (since := "2024-04-17")]
alias tendsto_int_cast_atBot_iff := tendsto_intCast_atBot_iff
theorem tendsto_intCast_atTop_atTop [StrictOrderedRing R] [Archimedean R] :
Tendsto ((↑) : ℤ → R) atTop atTop :=
tendsto_intCast_atTop_iff.2 tendsto_id
@[deprecated (since := "2024-04-17")]
alias tendsto_int_cast_atTop_atTop := tendsto_intCast_atTop_atTop
theorem Filter.Eventually.intCast_atTop [StrictOrderedRing R] [Archimedean R] {p : R → Prop}
(h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℤ) in atTop, p n := by
rw [← Int.comap_cast_atTop (R := R)]; exact h.comap _
@[deprecated (since := "2024-04-17")]
alias Filter.Eventually.int_cast_atTop := Filter.Eventually.intCast_atTop
theorem Filter.Eventually.intCast_atBot [StrictOrderedRing R] [Archimedean R] {p : R → Prop}
(h : ∀ᶠ (x : R) in atBot, p x) : ∀ᶠ (n : ℤ) in atBot, p n := by
rw [← Int.comap_cast_atBot (R := R)]; exact h.comap _
@[deprecated (since := "2024-04-17")]
alias Filter.Eventually.int_cast_atBot := Filter.Eventually.intCast_atBot
@[simp]
theorem Rat.comap_cast_atTop [LinearOrderedField R] [Archimedean R] :
comap ((↑) : ℚ → R) atTop = atTop :=
comap_embedding_atTop (fun _ _ => Rat.cast_le) fun r =>
let ⟨n, hn⟩ := exists_nat_ge r; ⟨n, by simpa⟩
@[simp] theorem Rat.comap_cast_atBot [LinearOrderedField R] [Archimedean R] :
comap ((↑) : ℚ → R) atBot = atBot :=
comap_embedding_atBot (fun _ _ => Rat.cast_le) fun r =>
let ⟨n, hn⟩ := exists_nat_ge (-r)
⟨-n, by simpa [neg_le]⟩
theorem tendsto_ratCast_atTop_iff [LinearOrderedField R] [Archimedean R] {f : α → ℚ}
{l : Filter α} : Tendsto (fun n => (f n : R)) l atTop ↔ Tendsto f l atTop := by
rw [← @Rat.comap_cast_atTop R, tendsto_comap_iff]; rfl
@[deprecated (since := "2024-04-17")]
alias tendsto_rat_cast_atTop_iff := tendsto_ratCast_atTop_iff
theorem tendsto_ratCast_atBot_iff [LinearOrderedField R] [Archimedean R] {f : α → ℚ}
{l : Filter α} : Tendsto (fun n => (f n : R)) l atBot ↔ Tendsto f l atBot := by
rw [← @Rat.comap_cast_atBot R, tendsto_comap_iff]; rfl
@[deprecated (since := "2024-04-17")]
alias tendsto_rat_cast_atBot_iff := tendsto_ratCast_atBot_iff
theorem Filter.Eventually.ratCast_atTop [LinearOrderedField R] [Archimedean R] {p : R → Prop}
(h : ∀ᶠ (x : R) in atTop, p x) : ∀ᶠ (n : ℚ) in atTop, p n := by
rw [← Rat.comap_cast_atTop (R := R)]; exact h.comap _
@[deprecated (since := "2024-04-17")]
alias Filter.Eventually.rat_cast_atTop := Filter.Eventually.ratCast_atTop
theorem Filter.Eventually.ratCast_atBot [LinearOrderedField R] [Archimedean R] {p : R → Prop}
(h : ∀ᶠ (x : R) in atBot, p x) : ∀ᶠ (n : ℚ) in atBot, p n := by
rw [← Rat.comap_cast_atBot (R := R)]; exact h.comap _
@[deprecated (since := "2024-04-17")]
alias Filter.Eventually.rat_cast_atBot := Filter.Eventually.ratCast_atBot
theorem atTop_hasAntitoneBasis_of_archimedean [OrderedSemiring R] [Archimedean R] :
(atTop : Filter R).HasAntitoneBasis fun n : ℕ => Ici n :=
hasAntitoneBasis_atTop.comp_mono Nat.mono_cast tendsto_natCast_atTop_atTop
theorem atTop_hasCountableBasis_of_archimedean [StrictOrderedSemiring R] [Archimedean R] :
(atTop : Filter R).HasCountableBasis (fun _ : ℕ => True) fun n => Ici n :=
⟨atTop_hasAntitoneBasis_of_archimedean.1, to_countable _⟩
-- Porting note (#11215): TODO: generalize to a `StrictOrderedRing`
theorem atBot_hasCountableBasis_of_archimedean [LinearOrderedRing R] [Archimedean R] :
(atBot : Filter R).HasCountableBasis (fun _ : ℤ => True) fun m => Iic m :=
{ countable := to_countable _
toHasBasis :=
atBot_basis.to_hasBasis
(fun x _ => let ⟨m, hm⟩ := exists_int_lt x; ⟨m, trivial, Iic_subset_Iic.2 hm.le⟩)
fun m _ => ⟨m, trivial, Subset.rfl⟩ }
instance (priority := 100) atTop_isCountablyGenerated_of_archimedean [StrictOrderedSemiring R]
[Archimedean R] : (atTop : Filter R).IsCountablyGenerated :=
atTop_hasCountableBasis_of_archimedean.isCountablyGenerated
instance (priority := 100) atBot_isCountablyGenerated_of_archimedean [LinearOrderedRing R]
[Archimedean R] : (atBot : Filter R).IsCountablyGenerated :=
atBot_hasCountableBasis_of_archimedean.isCountablyGenerated
namespace Filter
variable {l : Filter α} {f : α → R} {r : R}
section LinearOrderedSemiring
variable [LinearOrderedSemiring R] [Archimedean R]
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `Filter.Tendsto.const_mul_atTop`). -/
theorem Tendsto.const_mul_atTop' (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop := by
refine tendsto_atTop.2 fun b => ?_
obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr
rw [nsmul_eq_mul'] at hn
filter_upwards [tendsto_atTop.1 hf (n * max b 0)] with x hx
calc
b ≤ 1 * max b 0 := by
{ rw [one_mul]
exact le_max_left _ _ }
_ ≤ r * n * max b 0 := by gcongr
_ = r * (n * max b 0) := by rw [mul_assoc]
_ ≤ r * f x := by gcongr
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `Filter.Tendsto.atTop_mul_const`). -/
theorem Tendsto.atTop_mul_const' (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop := by
refine tendsto_atTop.2 fun b => ?_
obtain ⟨n : ℕ, hn : 1 ≤ n • r⟩ := Archimedean.arch 1 hr
have hn' : 1 ≤ (n : R) * r := by rwa [nsmul_eq_mul] at hn
filter_upwards [tendsto_atTop.1 hf (max b 0 * n)] with x hx
calc
b ≤ max b 0 * 1 := by
{ rw [mul_one]
exact le_max_left _ _ }
_ ≤ max b 0 * (n * r) := by gcongr
_ = max b 0 * n * r := by rw [mul_assoc]
_ ≤ f x * r := by gcongr
end LinearOrderedSemiring
section LinearOrderedRing
variable [LinearOrderedRing R] [Archimedean R]
/-- See also `Filter.Tendsto.atTop_mul_const_of_neg` for a version of this lemma for
`LinearOrderedField`s which does not require the `Archimedean` assumption. -/
theorem Tendsto.atTop_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot := by
simpa only [tendsto_neg_atTop_iff, mul_neg] using hf.atTop_mul_const' (neg_pos.mpr hr)
/-- See also `Filter.Tendsto.atBot_mul_const` for a version of this lemma for
`LinearOrderedField`s which does not require the `Archimedean` assumption. -/
theorem Tendsto.atBot_mul_const' (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot := by
simp only [← tendsto_neg_atTop_iff, ← neg_mul] at hf ⊢
exact hf.atTop_mul_const' hr
/-- See also `Filter.Tendsto.atBot_mul_const_of_neg` for a version of this lemma for
`LinearOrderedField`s which does not require the `Archimedean` assumption. -/
theorem Tendsto.atBot_mul_const_of_neg' (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop := by
simpa only [mul_neg, tendsto_neg_atBot_iff] using hf.atBot_mul_const' (neg_pos.2 hr)
@[deprecated (since := "2024-05-06")]
alias Tendsto.atTop_mul_neg_const' := Tendsto.atTop_mul_const_of_neg'
@[deprecated (since := "2024-05-06")]
alias Tendsto.atBot_mul_neg_const' := Tendsto.atBot_mul_const_of_neg'
end LinearOrderedRing
section LinearOrderedCancelAddCommMonoid
variable [LinearOrderedCancelAddCommMonoid R] [Archimedean R]
theorem Tendsto.atTop_nsmul_const {f : α → ℕ} (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x • r) l atTop := by
refine tendsto_atTop.mpr fun s => ?_
obtain ⟨n : ℕ, hn : s ≤ n • r⟩ := Archimedean.arch s hr
exact (tendsto_atTop.mp hf n).mono fun a ha => hn.trans (nsmul_le_nsmul_left hr.le ha)
end LinearOrderedCancelAddCommMonoid
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup R] [Archimedean R]
theorem Tendsto.atTop_nsmul_neg_const {f : α → ℕ} (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x • r) l atBot := by simpa using hf.atTop_nsmul_const (neg_pos.2 hr)
theorem Tendsto.atTop_zsmul_const {f : α → ℤ} (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x • r) l atTop := by
refine tendsto_atTop.mpr fun s => ?_
obtain ⟨n : ℕ, hn : s ≤ n • r⟩ := Archimedean.arch s hr
replace hn : s ≤ (n : ℤ) • r := by simpa
exact (tendsto_atTop.mp hf n).mono fun a ha => hn.trans (zsmul_le_zsmul hr.le ha)
theorem Tendsto.atTop_zsmul_neg_const {f : α → ℤ} (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x • r) l atBot := by simpa using hf.atTop_zsmul_const (neg_pos.2 hr)
theorem Tendsto.atBot_zsmul_const {f : α → ℤ} (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x • r) l atBot := by
simp only [← tendsto_neg_atTop_iff, ← neg_zsmul] at hf ⊢
exact hf.atTop_zsmul_const hr
theorem Tendsto.atBot_zsmul_neg_const {f : α → ℤ} (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x • r) l atTop := by simpa using hf.atBot_zsmul_const (neg_pos.2 hr)
end LinearOrderedAddCommGroup
end Filter
|
Order\Filter\AtTopBot.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Field.Defs
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Data.Finset.Preimage
import Mathlib.Order.Interval.Set.Disjoint
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.Bases
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Algebra.Order.Field.Unbundled.Basic
/-!
# `Filter.atTop` and `Filter.atBot` filters on preorders, monoids and groups.
In this file we define the filters
* `Filter.atTop`: corresponds to `n → +∞`;
* `Filter.atBot`: corresponds to `n → -∞`.
Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.
-/
variable {ι ι' α β γ : Type*}
open Set
namespace Filter
/-- `atTop` is the filter representing the limit `→ ∞` on an ordered set.
It is generated by the collection of up-sets `{b | a ≤ b}`.
(The preorder need not have a top element for this to be well defined,
and indeed is trivial when a top element exists.) -/
def atTop [Preorder α] : Filter α :=
⨅ a, 𝓟 (Ici a)
/-- `atBot` is the filter representing the limit `→ -∞` on an ordered set.
It is generated by the collection of down-sets `{b | b ≤ a}`.
(The preorder need not have a bottom element for this to be well defined,
and indeed is trivial when a bottom element exists.) -/
def atBot [Preorder α] : Filter α :=
⨅ a, 𝓟 (Iic a)
theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ :=
mem_iInf_of_mem a <| Subset.refl _
theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) :=
mem_atTop a
theorem Ioi_mem_atTop [Preorder α] [NoMaxOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) :=
let ⟨z, hz⟩ := exists_gt x
mem_of_superset (mem_atTop z) fun _ h => lt_of_lt_of_le hz h
theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ :=
mem_iInf_of_mem a <| Subset.refl _
theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) :=
mem_atBot a
theorem Iio_mem_atBot [Preorder α] [NoMinOrder α] (x : α) : Iio x ∈ (atBot : Filter α) :=
let ⟨z, hz⟩ := exists_lt x
mem_of_superset (mem_atBot z) fun _ h => lt_of_le_of_lt h hz
theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) :=
disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _)
theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) :=
@disjoint_atBot_principal_Ioi αᵒᵈ _ _
theorem disjoint_atTop_principal_Iic [Preorder α] [NoMaxOrder α] (x : α) :
Disjoint atTop (𝓟 (Iic x)) :=
disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x)
(mem_principal_self _)
theorem disjoint_atBot_principal_Ici [Preorder α] [NoMinOrder α] (x : α) :
Disjoint atBot (𝓟 (Ici x)) :=
@disjoint_atTop_principal_Iic αᵒᵈ _ _ _
theorem disjoint_pure_atTop [Preorder α] [NoMaxOrder α] (x : α) : Disjoint (pure x) atTop :=
Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <|
mem_pure.2 right_mem_Iic
theorem disjoint_pure_atBot [Preorder α] [NoMinOrder α] (x : α) : Disjoint (pure x) atBot :=
@disjoint_pure_atTop αᵒᵈ _ _ _
theorem not_tendsto_const_atTop [Preorder α] [NoMaxOrder α] (x : α) (l : Filter β) [l.NeBot] :
¬Tendsto (fun _ => x) l atTop :=
tendsto_const_pure.not_tendsto (disjoint_pure_atTop x)
theorem not_tendsto_const_atBot [Preorder α] [NoMinOrder α] (x : α) (l : Filter β) [l.NeBot] :
¬Tendsto (fun _ => x) l atBot :=
tendsto_const_pure.not_tendsto (disjoint_pure_atBot x)
theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] :
Disjoint (atBot : Filter α) atTop := by
rcases exists_pair_ne α with ⟨x, y, hne⟩
by_cases hle : x ≤ y
· refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y)
exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le
· refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x)
exact Iic_disjoint_Ici.2 hle
theorem disjoint_atTop_atBot [PartialOrder α] [Nontrivial α] : Disjoint (atTop : Filter α) atBot :=
disjoint_atBot_atTop.symm
theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x :=
mem_atTop a
theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a :=
mem_atBot a
theorem eventually_gt_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, a < x :=
Ioi_mem_atTop a
theorem eventually_ne_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a :=
(eventually_gt_atTop a).mono fun _ => ne_of_gt
protected theorem Tendsto.eventually_gt_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c < f x :=
hf.eventually (eventually_gt_atTop c)
protected theorem Tendsto.eventually_ge_atTop [Preorder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c ≤ f x :=
hf.eventually (eventually_ge_atTop c)
protected theorem Tendsto.eventually_ne_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, f x ≠ c :=
hf.eventually (eventually_ne_atTop c)
protected theorem Tendsto.eventually_ne_atTop' [Preorder β] [NoMaxOrder β] {f : α → β}
{l : Filter α} (hf : Tendsto f l atTop) (c : α) : ∀ᶠ x in l, x ≠ c :=
(hf.eventually_ne_atTop (f c)).mono fun _ => ne_of_apply_ne f
theorem eventually_lt_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x < a :=
Iio_mem_atBot a
theorem eventually_ne_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a :=
(eventually_lt_atBot a).mono fun _ => ne_of_lt
protected theorem Tendsto.eventually_lt_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x < c :=
hf.eventually (eventually_lt_atBot c)
protected theorem Tendsto.eventually_le_atBot [Preorder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≤ c :=
hf.eventually (eventually_le_atBot c)
protected theorem Tendsto.eventually_ne_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α}
(hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≠ c :=
hf.eventually (eventually_ne_atBot c)
theorem eventually_forall_ge_atTop [Preorder α] {p : α → Prop} :
(∀ᶠ x in atTop, ∀ y, x ≤ y → p y) ↔ ∀ᶠ x in atTop, p x := by
refine ⟨fun h ↦ h.mono fun x hx ↦ hx x le_rfl, fun h ↦ ?_⟩
rcases (hasBasis_iInf_principal_finite _).eventually_iff.1 h with ⟨S, hSf, hS⟩
refine mem_iInf_of_iInter hSf (V := fun x ↦ Ici x.1) (fun _ ↦ Subset.rfl) fun x hx y hy ↦ ?_
simp only [mem_iInter] at hS hx
exact hS fun z hz ↦ le_trans (hx ⟨z, hz⟩) hy
theorem eventually_forall_le_atBot [Preorder α] {p : α → Prop} :
(∀ᶠ x in atBot, ∀ y, y ≤ x → p y) ↔ ∀ᶠ x in atBot, p x :=
eventually_forall_ge_atTop (α := αᵒᵈ)
theorem Tendsto.eventually_forall_ge_atTop [Preorder β] {l : Filter α}
{p : β → Prop} {f : α → β} (hf : Tendsto f l atTop) (h_evtl : ∀ᶠ x in atTop, p x) :
∀ᶠ x in l, ∀ y, f x ≤ y → p y := by
rw [← Filter.eventually_forall_ge_atTop] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap
theorem Tendsto.eventually_forall_le_atBot [Preorder β] {l : Filter α}
{p : β → Prop} {f : α → β} (hf : Tendsto f l atBot) (h_evtl : ∀ᶠ x in atBot, p x) :
∀ᶠ x in l, ∀ y, y ≤ f x → p y := by
rw [← Filter.eventually_forall_le_atBot] at h_evtl; exact (h_evtl.comap f).filter_mono hf.le_comap
instance (priority := 200) atTop.isCountablyGenerated [Preorder α] [Countable α] :
(atTop : Filter <| α).IsCountablyGenerated :=
isCountablyGenerated_seq _
instance (priority := 200) atBot.isCountablyGenerated [Preorder α] [Countable α] :
(atBot : Filter <| α).IsCountablyGenerated :=
isCountablyGenerated_seq _
theorem _root_.IsTop.atTop_eq [Preorder α] {a : α} (ha : IsTop a) : atTop = 𝓟 (Ici a) :=
(iInf_le _ _).antisymm <| le_iInf fun b ↦ principal_mono.2 <| Ici_subset_Ici.2 <| ha b
theorem _root_.IsBot.atBot_eq [Preorder α] {a : α} (ha : IsBot a) : atBot = 𝓟 (Iic a) :=
ha.toDual.atTop_eq
theorem OrderTop.atTop_eq (α) [PartialOrder α] [OrderTop α] : (atTop : Filter α) = pure ⊤ := by
rw [isTop_top.atTop_eq, Ici_top, principal_singleton]
theorem OrderBot.atBot_eq (α) [PartialOrder α] [OrderBot α] : (atBot : Filter α) = pure ⊥ :=
@OrderTop.atTop_eq αᵒᵈ _ _
@[nontriviality]
theorem Subsingleton.atTop_eq (α) [Subsingleton α] [Preorder α] : (atTop : Filter α) = ⊤ := by
refine top_unique fun s hs x => ?_
rw [atTop, ciInf_subsingleton x, mem_principal] at hs
exact hs left_mem_Ici
@[nontriviality]
theorem Subsingleton.atBot_eq (α) [Subsingleton α] [Preorder α] : (atBot : Filter α) = ⊤ :=
@Subsingleton.atTop_eq αᵒᵈ _ _
theorem tendsto_atTop_pure [PartialOrder α] [OrderTop α] (f : α → β) :
Tendsto f atTop (pure <| f ⊤) :=
(OrderTop.atTop_eq α).symm ▸ tendsto_pure_pure _ _
theorem tendsto_atBot_pure [PartialOrder α] [OrderBot α] (f : α → β) :
Tendsto f atBot (pure <| f ⊥) :=
@tendsto_atTop_pure αᵒᵈ _ _ _ _
section IsDirected
variable [Preorder α] [IsDirected α (· ≤ ·)] {p : α → Prop}
theorem hasAntitoneBasis_atTop [Nonempty α] : (@atTop α _).HasAntitoneBasis Ici :=
.iInf_principal fun _ _ ↦ Ici_subset_Ici.2
theorem atTop_basis [Nonempty α] : (@atTop α _).HasBasis (fun _ => True) Ici :=
hasAntitoneBasis_atTop.1
theorem atTop_eq_generate_Ici : atTop = generate (range (Ici (α := α))) := by
rcases isEmpty_or_nonempty α with hα|hα
· simp only [eq_iff_true_of_subsingleton]
· simp [(atTop_basis (α := α)).eq_generate, range]
lemma atTop_basis_Ioi [Nonempty α] [NoMaxOrder α] : (@atTop α _).HasBasis (fun _ => True) Ioi :=
atTop_basis.to_hasBasis (fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩) fun a ha =>
(exists_gt a).imp fun _b hb => ⟨ha, Ici_subset_Ioi.2 hb⟩
lemma atTop_basis_Ioi' [NoMaxOrder α] (a : α) : atTop.HasBasis (a < ·) Ioi := by
have : Nonempty α := ⟨a⟩
refine atTop_basis_Ioi.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩
obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b
obtain ⟨d, hcd⟩ := exists_gt c
exact ⟨d, hac.trans_lt hcd, Ioi_subset_Ioi (hbc.trans hcd.le)⟩
variable [Nonempty α]
theorem atTop_basis' (a : α) : (@atTop α _).HasBasis (fun x => a ≤ x) Ici := by
refine atTop_basis.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩
obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b
exact ⟨c, hac, Ici_subset_Ici.2 hbc⟩
@[instance]
lemma atTop_neBot : NeBot (atTop : Filter α) := atTop_basis.neBot_iff.2 fun _ => nonempty_Ici
@[simp] lemma mem_atTop_sets {s : Set α} : s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s :=
atTop_basis.mem_iff.trans <| exists_congr fun _ => true_and_iff _
@[simp] lemma eventually_atTop : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b := mem_atTop_sets
theorem frequently_atTop : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b ≥ a, p b :=
atTop_basis.frequently_iff.trans <| by simp
alias ⟨Eventually.exists_forall_of_atTop, _⟩ := eventually_atTop
alias ⟨Frequently.forall_exists_of_atTop, _⟩ := frequently_atTop
lemma exists_eventually_atTop {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atTop, r a b) ↔ ∀ᶠ a₀ in atTop, ∃ b, ∀ a ≥ a₀, r a b := by
simp_rw [eventually_atTop, ← exists_swap (α := α)]
exact exists_congr fun a ↦ .symm <| forall_ge_iff <| Monotone.exists fun _ _ _ hb H n hn ↦
H n (hb.trans hn)
theorem map_atTop_eq {f : α → β} : atTop.map f = ⨅ a, 𝓟 (f '' { a' | a ≤ a' }) :=
(atTop_basis.map f).eq_iInf
theorem frequently_atTop' [NoMaxOrder α] : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b > a, p b :=
atTop_basis_Ioi.frequently_iff.trans <| by simp
lemma atTop_countable_basis [Countable α] :
HasCountableBasis (atTop : Filter α) (fun _ => True) Ici :=
{ atTop_basis with countable := to_countable _ }
end IsDirected
section IsCodirected
variable [Preorder α] [IsDirected α (· ≥ ·)] {p : α → Prop}
lemma atBot_basis_Iio [Nonempty α] [NoMinOrder α] : (@atBot α _).HasBasis (fun _ => True) Iio :=
atTop_basis_Ioi (α := αᵒᵈ)
lemma atBot_basis_Iio' [NoMinOrder α] (a : α) : atBot.HasBasis (· < a) Iio :=
atTop_basis_Ioi' (α := αᵒᵈ) a
variable [Nonempty α]
lemma atBot_basis : (@atBot α _).HasBasis (fun _ => True) Iic := atTop_basis (α := αᵒᵈ)
lemma atBot_basis' (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic := atTop_basis' (α := αᵒᵈ) _
@[instance] lemma atBot_neBot : NeBot (atBot : Filter α) := atTop_neBot (α := αᵒᵈ)
@[simp] lemma mem_atBot_sets {s : Set α} : s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s :=
mem_atTop_sets (α := αᵒᵈ)
@[simp] lemma eventually_atBot : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b := mem_atBot_sets
theorem frequently_atBot : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b ≤ a, p b := frequently_atTop (α := αᵒᵈ)
alias ⟨Eventually.exists_forall_of_atBot, _⟩ := eventually_atBot
alias ⟨Frequently.forall_exists_of_atBot, _⟩ := frequently_atBot
lemma exists_eventually_atBot {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atBot, r a b) ↔ ∀ᶠ a₀ in atBot, ∃ b, ∀ a ≤ a₀, r a b := by
simp_rw [eventually_atBot, ← exists_swap (α := α)]
exact exists_congr fun a ↦ .symm <| forall_le_iff <| Antitone.exists fun _ _ _ hb H n hn ↦
H n (hn.trans hb)
theorem map_atBot_eq {f : α → β} : atBot.map f = ⨅ a, 𝓟 (f '' { a' | a' ≤ a }) :=
map_atTop_eq (α := αᵒᵈ)
theorem frequently_atBot' [NoMinOrder α] : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b < a, p b :=
frequently_atTop' (α := αᵒᵈ)
lemma atBot_countable_basis [Countable α] :
HasCountableBasis (atBot : Filter α) (fun _ => True) Iic :=
{ atBot_basis with countable := to_countable _ }
end IsCodirected
theorem tendsto_atTop [Preorder β] {m : α → β} {f : Filter α} :
Tendsto m f atTop ↔ ∀ b, ∀ᶠ a in f, b ≤ m a := by
simp only [atTop, tendsto_iInf, tendsto_principal, mem_Ici]
theorem tendsto_atBot [Preorder β] {m : α → β} {f : Filter α} :
Tendsto m f atBot ↔ ∀ b, ∀ᶠ a in f, m a ≤ b :=
@tendsto_atTop α βᵒᵈ _ m f
theorem tendsto_atTop_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂)
(h₁ : Tendsto f₁ l atTop) : Tendsto f₂ l atTop :=
tendsto_atTop.2 fun b => by filter_upwards [tendsto_atTop.1 h₁ b, h] with x using le_trans
theorem tendsto_atBot_mono' [Preorder β] (l : Filter α) ⦃f₁ f₂ : α → β⦄ (h : f₁ ≤ᶠ[l] f₂) :
Tendsto f₂ l atBot → Tendsto f₁ l atBot :=
@tendsto_atTop_mono' _ βᵒᵈ _ _ _ _ h
theorem tendsto_atTop_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
Tendsto f l atTop → Tendsto g l atTop :=
tendsto_atTop_mono' l <| eventually_of_forall h
theorem tendsto_atBot_mono [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ n, f n ≤ g n) :
Tendsto g l atBot → Tendsto f l atBot :=
@tendsto_atTop_mono _ βᵒᵈ _ _ _ _ h
lemma atTop_eq_generate_of_forall_exists_le [LinearOrder α] {s : Set α} (hs : ∀ x, ∃ y ∈ s, x ≤ y) :
(atTop : Filter α) = generate (Ici '' s) := by
rw [atTop_eq_generate_Ici]
apply le_antisymm
· rw [le_generate_iff]
rintro - ⟨y, -, rfl⟩
exact mem_generate_of_mem ⟨y, rfl⟩
· rw [le_generate_iff]
rintro - ⟨x, -, -, rfl⟩
rcases hs x with ⟨y, ys, hy⟩
have A : Ici y ∈ generate (Ici '' s) := mem_generate_of_mem (mem_image_of_mem _ ys)
have B : Ici y ⊆ Ici x := Ici_subset_Ici.2 hy
exact sets_of_superset (generate (Ici '' s)) A B
lemma atTop_eq_generate_of_not_bddAbove [LinearOrder α] {s : Set α} (hs : ¬ BddAbove s) :
(atTop : Filter α) = generate (Ici '' s) := by
refine atTop_eq_generate_of_forall_exists_le fun x ↦ ?_
obtain ⟨y, hy, hy'⟩ := not_bddAbove_iff.mp hs x
exact ⟨y, hy, hy'.le⟩
end Filter
namespace OrderIso
open Filter
variable [Preorder α] [Preorder β]
@[simp]
theorem comap_atTop (e : α ≃o β) : comap e atTop = atTop := by
simp [atTop, ← e.surjective.iInf_comp]
@[simp]
theorem comap_atBot (e : α ≃o β) : comap e atBot = atBot :=
e.dual.comap_atTop
@[simp]
theorem map_atTop (e : α ≃o β) : map (e : α → β) atTop = atTop := by
rw [← e.comap_atTop, map_comap_of_surjective e.surjective]
@[simp]
theorem map_atBot (e : α ≃o β) : map (e : α → β) atBot = atBot :=
e.dual.map_atTop
theorem tendsto_atTop (e : α ≃o β) : Tendsto e atTop atTop :=
e.map_atTop.le
theorem tendsto_atBot (e : α ≃o β) : Tendsto e atBot atBot :=
e.map_atBot.le
@[simp]
theorem tendsto_atTop_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) :
Tendsto (fun x => e (f x)) l atTop ↔ Tendsto f l atTop := by
rw [← e.comap_atTop, tendsto_comap_iff, Function.comp_def]
@[simp]
theorem tendsto_atBot_iff {l : Filter γ} {f : γ → α} (e : α ≃o β) :
Tendsto (fun x => e (f x)) l atBot ↔ Tendsto f l atBot :=
e.dual.tendsto_atTop_iff
end OrderIso
namespace Filter
/-!
### Sequences
-/
theorem extraction_of_frequently_atTop' {P : ℕ → Prop} (h : ∀ N, ∃ n > N, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
choose u hu hu' using h
refine ⟨fun n => u^[n + 1] 0, strictMono_nat_of_lt_succ fun n => ?_, fun n => ?_⟩
· exact Trans.trans (hu _) (Function.iterate_succ_apply' _ _ _).symm
· simpa only [Function.iterate_succ_apply'] using hu' _
theorem extraction_of_frequently_atTop {P : ℕ → Prop} (h : ∃ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
rw [frequently_atTop'] at h
exact extraction_of_frequently_atTop' h
theorem extraction_of_eventually_atTop {P : ℕ → Prop} (h : ∀ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) :=
extraction_of_frequently_atTop h.frequently
theorem extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := by
simp only [frequently_atTop'] at h
choose u hu hu' using h
use (fun n => Nat.recOn n (u 0 0) fun n v => u (n + 1) v : ℕ → ℕ)
constructor
· apply strictMono_nat_of_lt_succ
intro n
apply hu
· intro n
cases n <;> simp [hu']
theorem extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_frequently fun n => (h n).frequently
theorem extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_eventually (by simp [eventually_atTop, h])
theorem Eventually.atTop_of_arithmetic {p : ℕ → Prop} {n : ℕ} (hn : n ≠ 0)
(hp : ∀ k < n, ∀ᶠ a in atTop, p (n * a + k)) : ∀ᶠ a in atTop, p a := by
simp only [eventually_atTop] at hp ⊢
choose! N hN using hp
refine ⟨(Finset.range n).sup (n * N ·), fun b hb => ?_⟩
rw [← Nat.div_add_mod b n]
have hlt := Nat.mod_lt b hn.bot_lt
refine hN _ hlt _ ?_
rw [ge_iff_le, Nat.le_div_iff_mul_le hn.bot_lt, mul_comm]
exact (Finset.le_sup (f := (n * N ·)) (Finset.mem_range.2 hlt)).trans hb
section IsDirected
variable [Preorder α] [IsDirected α (· ≤ ·)] {F : Filter β} {u : α → β}
theorem inf_map_atTop_neBot_iff [Nonempty α] :
NeBot (F ⊓ map u atTop) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by
simp_rw [inf_neBot_iff_frequently_left, frequently_map, frequently_atTop]; rfl
variable [Preorder β]
lemma exists_le_of_tendsto_atTop (h : Tendsto u atTop atTop) (a : α) (b : β) :
∃ a' ≥ a, b ≤ u a' := by
have : Nonempty α := ⟨a⟩
have : ∀ᶠ x in atTop, a ≤ x ∧ b ≤ u x :=
(eventually_ge_atTop a).and (h.eventually <| eventually_ge_atTop b)
exact this.exists
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem exists_le_of_tendsto_atBot (h : Tendsto u atTop atBot) :
∀ a b, ∃ a' ≥ a, u a' ≤ b := exists_le_of_tendsto_atTop (β := βᵒᵈ) h
theorem exists_lt_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto u atTop atTop) (a : α) (b : β) :
∃ a' ≥ a, b < u a' := by
cases' exists_gt b with b' hb'
rcases exists_le_of_tendsto_atTop h a b' with ⟨a', ha', ha''⟩
exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem exists_lt_of_tendsto_atBot [NoMinOrder β] (h : Tendsto u atTop atBot) :
∀ a b, ∃ a' ≥ a, u a' < b := exists_lt_of_tendsto_atTop (β := βᵒᵈ) h
end IsDirected
section IsCodirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {F : Filter β} {u : α → β}
theorem inf_map_atBot_neBot_iff : NeBot (F ⊓ map u atBot) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U :=
inf_map_atTop_neBot_iff (α := αᵒᵈ)
end IsCodirected
/-- If `u` is a sequence which is unbounded above,
then after any point, it reaches a value strictly greater than all previous values.
-/
theorem high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β} (hu : Tendsto u atTop atTop) :
∀ N, ∃ n ≥ N, ∀ k < n, u k < u n := by
intro N
obtain ⟨k : ℕ, - : k ≤ N, hku : ∀ l ≤ N, u l ≤ u k⟩ : ∃ k ≤ N, ∀ l ≤ N, u l ≤ u k :=
exists_max_image _ u (finite_le_nat N) ⟨N, le_refl N⟩
have ex : ∃ n ≥ N, u k < u n := exists_lt_of_tendsto_atTop hu _ _
obtain ⟨n : ℕ, hnN : n ≥ N, hnk : u k < u n, hn_min : ∀ m, m < n → N ≤ m → u m ≤ u k⟩ :
∃ n ≥ N, u k < u n ∧ ∀ m, m < n → N ≤ m → u m ≤ u k := by
rcases Nat.findX ex with ⟨n, ⟨hnN, hnk⟩, hn_min⟩
push_neg at hn_min
exact ⟨n, hnN, hnk, hn_min⟩
use n, hnN
rintro (l : ℕ) (hl : l < n)
have hlk : u l ≤ u k := by
cases' (le_total l N : l ≤ N ∨ N ≤ l) with H H
· exact hku l H
· exact hn_min l hl H
calc
u l ≤ u k := hlk
_ < u n := hnk
-- see Note [nolint_ge]
/-- If `u` is a sequence which is unbounded below,
then after any point, it reaches a value strictly smaller than all previous values.
-/
-- @[nolint ge_or_gt] Porting note: restore attribute
theorem low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β} (hu : Tendsto u atTop atBot) :
∀ N, ∃ n ≥ N, ∀ k < n, u n < u k :=
@high_scores βᵒᵈ _ _ _ hu
/-- If `u` is a sequence which is unbounded above,
then it `Frequently` reaches a value strictly greater than all previous values.
-/
theorem frequently_high_scores [LinearOrder β] [NoMaxOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atTop) : ∃ᶠ n in atTop, ∀ k < n, u k < u n := by
simpa [frequently_atTop] using high_scores hu
/-- If `u` is a sequence which is unbounded below,
then it `Frequently` reaches a value strictly smaller than all previous values.
-/
theorem frequently_low_scores [LinearOrder β] [NoMinOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atBot) : ∃ᶠ n in atTop, ∀ k < n, u n < u k :=
@frequently_high_scores βᵒᵈ _ _ _ hu
theorem strictMono_subseq_of_tendsto_atTop [LinearOrder β] [NoMaxOrder β] {u : ℕ → β}
(hu : Tendsto u atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) :=
let ⟨φ, h, h'⟩ := extraction_of_frequently_atTop (frequently_high_scores hu)
⟨φ, h, fun _ m hnm => h' m _ (h hnm)⟩
theorem strictMono_subseq_of_id_le {u : ℕ → ℕ} (hu : ∀ n, n ≤ u n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ StrictMono (u ∘ φ) :=
strictMono_subseq_of_tendsto_atTop (tendsto_atTop_mono hu tendsto_id)
theorem _root_.StrictMono.tendsto_atTop {φ : ℕ → ℕ} (h : StrictMono φ) : Tendsto φ atTop atTop :=
tendsto_atTop_mono h.id_le tendsto_id
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β] {l : Filter α} {f g : α → β}
theorem tendsto_atTop_add_nonneg_left' (hf : ∀ᶠ x in l, 0 ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_mono' l (hf.mono fun _ => le_add_of_nonneg_left) hg
theorem tendsto_atBot_add_nonpos_left' (hf : ∀ᶠ x in l, f x ≤ 0) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_left' _ βᵒᵈ _ _ _ _ hf hg
theorem tendsto_atTop_add_nonneg_left (hf : ∀ x, 0 ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_left' (eventually_of_forall hf) hg
theorem tendsto_atBot_add_nonpos_left (hf : ∀ x, f x ≤ 0) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_left _ βᵒᵈ _ _ _ _ hf hg
theorem tendsto_atTop_add_nonneg_right' (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, 0 ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_mono' l (monotone_mem (fun _ => le_add_of_nonneg_right) hg) hf
theorem tendsto_atBot_add_nonpos_right' (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ 0) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_right' _ βᵒᵈ _ _ _ _ hf hg
theorem tendsto_atTop_add_nonneg_right (hf : Tendsto f l atTop) (hg : ∀ x, 0 ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_right' hf (eventually_of_forall hg)
theorem tendsto_atBot_add_nonpos_right (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ 0) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_nonneg_right _ βᵒᵈ _ _ _ _ hf hg
theorem tendsto_atTop_add (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_nonneg_left' (tendsto_atTop.mp hf 0) hg
theorem tendsto_atBot_add (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add _ βᵒᵈ _ _ _ _ hf hg
theorem Tendsto.nsmul_atTop (hf : Tendsto f l atTop) {n : ℕ} (hn : 0 < n) :
Tendsto (fun x => n • f x) l atTop :=
tendsto_atTop.2 fun y =>
(tendsto_atTop.1 hf y).mp <|
(tendsto_atTop.1 hf 0).mono fun x h₀ hy =>
calc
y ≤ f x := hy
_ = 1 • f x := (one_nsmul _).symm
_ ≤ n • f x := nsmul_le_nsmul_left h₀ hn
theorem Tendsto.nsmul_atBot (hf : Tendsto f l atBot) {n : ℕ} (hn : 0 < n) :
Tendsto (fun x => n • f x) l atBot :=
@Tendsto.nsmul_atTop α βᵒᵈ _ l f hf n hn
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [OrderedCancelAddCommMonoid β] {l : Filter α} {f g : α → β}
theorem tendsto_atTop_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (C + b)).mono fun _ => le_of_add_le_add_left
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_const_left (C : β) (hf : Tendsto (fun x => C + f x) l atBot) :
Tendsto f l atBot :=
tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (C + b)).mono fun _ => le_of_add_le_add_left
theorem tendsto_atTop_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b + C)).mono fun _ => le_of_add_le_add_right
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_const_right (C : β) (hf : Tendsto (fun x => f x + C) l atBot) :
Tendsto f l atBot :=
tendsto_atBot.2 fun b => (tendsto_atBot.1 hf (b + C)).mono fun _ => le_of_add_le_add_right
theorem tendsto_atTop_of_add_bdd_above_left' (C) (hC : ∀ᶠ x in l, f x ≤ C)
(h : Tendsto (fun x => f x + g x) l atTop) : Tendsto g l atTop :=
tendsto_atTop_of_add_const_left C
(tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h)
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_left' (C) (hC : ∀ᶠ x in l, C ≤ f x)
(h : Tendsto (fun x => f x + g x) l atBot) : Tendsto g l atBot :=
tendsto_atBot_of_add_const_left C
(tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_right hx (g x)) h)
theorem tendsto_atTop_of_add_bdd_above_left (C) (hC : ∀ x, f x ≤ C) :
Tendsto (fun x => f x + g x) l atTop → Tendsto g l atTop :=
tendsto_atTop_of_add_bdd_above_left' C (univ_mem' hC)
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_left (C) (hC : ∀ x, C ≤ f x) :
Tendsto (fun x => f x + g x) l atBot → Tendsto g l atBot :=
tendsto_atBot_of_add_bdd_below_left' C (univ_mem' hC)
theorem tendsto_atTop_of_add_bdd_above_right' (C) (hC : ∀ᶠ x in l, g x ≤ C)
(h : Tendsto (fun x => f x + g x) l atTop) : Tendsto f l atTop :=
tendsto_atTop_of_add_const_right C
(tendsto_atTop_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h)
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_right' (C) (hC : ∀ᶠ x in l, C ≤ g x)
(h : Tendsto (fun x => f x + g x) l atBot) : Tendsto f l atBot :=
tendsto_atBot_of_add_const_right C
(tendsto_atBot_mono' l (hC.mono fun x hx => add_le_add_left hx (f x)) h)
theorem tendsto_atTop_of_add_bdd_above_right (C) (hC : ∀ x, g x ≤ C) :
Tendsto (fun x => f x + g x) l atTop → Tendsto f l atTop :=
tendsto_atTop_of_add_bdd_above_right' C (univ_mem' hC)
-- Porting note: the "order dual" trick timeouts
theorem tendsto_atBot_of_add_bdd_below_right (C) (hC : ∀ x, C ≤ g x) :
Tendsto (fun x => f x + g x) l atBot → Tendsto f l atBot :=
tendsto_atBot_of_add_bdd_below_right' C (univ_mem' hC)
end OrderedCancelAddCommMonoid
section OrderedGroup
variable [OrderedAddCommGroup β] (l : Filter α) {f g : α → β}
theorem tendsto_atTop_add_left_of_le' (C : β) (hf : ∀ᶠ x in l, C ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
@tendsto_atTop_of_add_bdd_above_left' _ _ _ l (fun x => -f x) (fun x => f x + g x) (-C) (by simpa)
(by simpa)
theorem tendsto_atBot_add_left_of_ge' (C : β) (hf : ∀ᶠ x in l, f x ≤ C) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_left_of_le' _ βᵒᵈ _ _ _ _ C hf hg
theorem tendsto_atTop_add_left_of_le (C : β) (hf : ∀ x, C ≤ f x) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_left_of_le' l C (univ_mem' hf) hg
theorem tendsto_atBot_add_left_of_ge (C : β) (hf : ∀ x, f x ≤ C) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_left_of_le _ βᵒᵈ _ _ _ _ C hf hg
theorem tendsto_atTop_add_right_of_le' (C : β) (hf : Tendsto f l atTop) (hg : ∀ᶠ x in l, C ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
@tendsto_atTop_of_add_bdd_above_right' _ _ _ l (fun x => f x + g x) (fun x => -g x) (-C)
(by simp [hg]) (by simp [hf])
theorem tendsto_atBot_add_right_of_ge' (C : β) (hf : Tendsto f l atBot) (hg : ∀ᶠ x in l, g x ≤ C) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_right_of_le' _ βᵒᵈ _ _ _ _ C hf hg
theorem tendsto_atTop_add_right_of_le (C : β) (hf : Tendsto f l atTop) (hg : ∀ x, C ≤ g x) :
Tendsto (fun x => f x + g x) l atTop :=
tendsto_atTop_add_right_of_le' l C hf (univ_mem' hg)
theorem tendsto_atBot_add_right_of_ge (C : β) (hf : Tendsto f l atBot) (hg : ∀ x, g x ≤ C) :
Tendsto (fun x => f x + g x) l atBot :=
@tendsto_atTop_add_right_of_le _ βᵒᵈ _ _ _ _ C hf hg
theorem tendsto_atTop_add_const_left (C : β) (hf : Tendsto f l atTop) :
Tendsto (fun x => C + f x) l atTop :=
tendsto_atTop_add_left_of_le' l C (univ_mem' fun _ => le_refl C) hf
theorem tendsto_atBot_add_const_left (C : β) (hf : Tendsto f l atBot) :
Tendsto (fun x => C + f x) l atBot :=
@tendsto_atTop_add_const_left _ βᵒᵈ _ _ _ C hf
theorem tendsto_atTop_add_const_right (C : β) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x + C) l atTop :=
tendsto_atTop_add_right_of_le' l C hf (univ_mem' fun _ => le_refl C)
theorem tendsto_atBot_add_const_right (C : β) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x + C) l atBot :=
@tendsto_atTop_add_const_right _ βᵒᵈ _ _ _ C hf
theorem map_neg_atBot : map (Neg.neg : β → β) atBot = atTop :=
(OrderIso.neg β).map_atBot
theorem map_neg_atTop : map (Neg.neg : β → β) atTop = atBot :=
(OrderIso.neg β).map_atTop
theorem comap_neg_atBot : comap (Neg.neg : β → β) atBot = atTop :=
(OrderIso.neg β).comap_atTop
theorem comap_neg_atTop : comap (Neg.neg : β → β) atTop = atBot :=
(OrderIso.neg β).comap_atBot
theorem tendsto_neg_atTop_atBot : Tendsto (Neg.neg : β → β) atTop atBot :=
(OrderIso.neg β).tendsto_atTop
theorem tendsto_neg_atBot_atTop : Tendsto (Neg.neg : β → β) atBot atTop :=
@tendsto_neg_atTop_atBot βᵒᵈ _
variable {l}
@[simp]
theorem tendsto_neg_atTop_iff : Tendsto (fun x => -f x) l atTop ↔ Tendsto f l atBot :=
(OrderIso.neg β).tendsto_atBot_iff
@[simp]
theorem tendsto_neg_atBot_iff : Tendsto (fun x => -f x) l atBot ↔ Tendsto f l atTop :=
(OrderIso.neg β).tendsto_atTop_iff
end OrderedGroup
section OrderedSemiring
variable [OrderedSemiring α] {l : Filter β} {f g : β → α}
theorem Tendsto.atTop_mul_atTop (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atTop := by
refine tendsto_atTop_mono' _ ?_ hg
filter_upwards [hg.eventually (eventually_ge_atTop 0),
hf.eventually (eventually_ge_atTop 1)] with _ using le_mul_of_one_le_left
theorem tendsto_mul_self_atTop : Tendsto (fun x : α => x * x) atTop atTop :=
tendsto_id.atTop_mul_atTop tendsto_id
/-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_atTop`. -/
theorem tendsto_pow_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : α => x ^ n) atTop atTop :=
tendsto_atTop_mono' _ ((eventually_ge_atTop 1).mono fun _x hx => le_self_pow hx hn) tendsto_id
end OrderedSemiring
theorem zero_pow_eventuallyEq [MonoidWithZero α] :
(fun n : ℕ => (0 : α) ^ n) =ᶠ[atTop] fun _ => 0 :=
eventually_atTop.2 ⟨1, fun _n hn ↦ zero_pow $ Nat.one_le_iff_ne_zero.1 hn⟩
section OrderedRing
variable [OrderedRing α] {l : Filter β} {f g : β → α}
theorem Tendsto.atTop_mul_atBot (hf : Tendsto f l atTop) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atBot := by
have := hf.atTop_mul_atTop <| tendsto_neg_atBot_atTop.comp hg
simpa only [(· ∘ ·), neg_mul_eq_mul_neg, neg_neg] using tendsto_neg_atTop_atBot.comp this
theorem Tendsto.atBot_mul_atTop (hf : Tendsto f l atBot) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atBot := by
have : Tendsto (fun x => -f x * g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop hg
simpa only [(· ∘ ·), neg_mul_eq_neg_mul, neg_neg] using tendsto_neg_atTop_atBot.comp this
theorem Tendsto.atBot_mul_atBot (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atTop := by
have : Tendsto (fun x => -f x * -g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop (tendsto_neg_atBot_atTop.comp hg)
simpa only [neg_mul_neg] using this
end OrderedRing
section LinearOrderedAddCommGroup
variable [LinearOrderedAddCommGroup α]
/-- $\lim_{x\to+\infty}|x|=+\infty$ -/
theorem tendsto_abs_atTop_atTop : Tendsto (abs : α → α) atTop atTop :=
tendsto_atTop_mono le_abs_self tendsto_id
/-- $\lim_{x\to-\infty}|x|=+\infty$ -/
theorem tendsto_abs_atBot_atTop : Tendsto (abs : α → α) atBot atTop :=
tendsto_atTop_mono neg_le_abs tendsto_neg_atBot_atTop
@[simp]
theorem comap_abs_atTop : comap (abs : α → α) atTop = atBot ⊔ atTop := by
refine
le_antisymm (((atTop_basis.comap _).le_basis_iff (atBot_basis.sup atTop_basis)).2 ?_)
(sup_le tendsto_abs_atBot_atTop.le_comap tendsto_abs_atTop_atTop.le_comap)
rintro ⟨a, b⟩ -
refine ⟨max (-a) b, trivial, fun x hx => ?_⟩
rw [mem_preimage, mem_Ici, le_abs', max_le_iff, ← min_neg_neg, le_min_iff, neg_neg] at hx
exact hx.imp And.left And.right
end LinearOrderedAddCommGroup
section LinearOrderedSemiring
variable [LinearOrderedSemiring α] {l : Filter β} {f : β → α}
theorem Tendsto.atTop_of_const_mul {c : α} (hc : 0 < c) (hf : Tendsto (fun x => c * f x) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (c * b)).mono
fun _x hx => le_of_mul_le_mul_left hx hc
theorem Tendsto.atTop_of_mul_const {c : α} (hc : 0 < c) (hf : Tendsto (fun x => f x * c) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * c)).mono
fun _x hx => le_of_mul_le_mul_right hx hc
@[simp]
theorem tendsto_pow_atTop_iff {n : ℕ} : Tendsto (fun x : α => x ^ n) atTop atTop ↔ n ≠ 0 :=
⟨fun h hn => by simp only [hn, pow_zero, not_tendsto_const_atTop] at h, tendsto_pow_atTop⟩
end LinearOrderedSemiring
theorem not_tendsto_pow_atTop_atBot [LinearOrderedRing α] :
∀ {n : ℕ}, ¬Tendsto (fun x : α => x ^ n) atTop atBot
| 0 => by simp [not_tendsto_const_atBot]
| n + 1 => (tendsto_pow_atTop n.succ_ne_zero).not_tendsto disjoint_atTop_atBot
section LinearOrderedSemifield
variable [LinearOrderedSemifield α] {l : Filter β} {f : β → α} {r c : α} {n : ℕ}
/-!
### Multiplication by constant: iff lemmas
-/
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_const_mul_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atTop :=
⟨fun h => h.atTop_of_const_mul hr, fun h =>
Tendsto.atTop_of_const_mul (inv_pos.2 hr) <| by simpa only [inv_mul_cancel_left₀ hr.ne'] ⟩
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_mul_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_pos hr
/-- If `r` is a positive constant, `x ↦ f x / r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
lemma tendsto_div_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atTop := by
simpa only [div_eq_mul_inv] using tendsto_mul_const_atTop_of_pos (inv_pos.2 hr)
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to infinity if and only if `0 < r. `-/
theorem tendsto_const_mul_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r := by
refine ⟨fun hrf => not_le.mp fun hr => ?_, fun hr => (tendsto_const_mul_atTop_of_pos hr).mpr h⟩
rcases ((h.eventually_ge_atTop 0).and (hrf.eventually_gt_atTop 0)).exists with ⟨x, hx, hrx⟩
exact (mul_nonpos_of_nonpos_of_nonneg hr hx).not_lt hrx
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to infinity if and only if `0 < r. `-/
theorem tendsto_mul_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_pos h]
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`x ↦ f x * r` tends to infinity if and only if `0 < r. `-/
lemma tendsto_div_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r := by
simp only [div_eq_mul_inv, tendsto_mul_const_atTop_iff_pos h, inv_pos]
/-- If `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.const_mul_atTop'` instead. -/
theorem Tendsto.const_mul_atTop (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_pos hr).2 hf
/-- If a function `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.atTop_mul_const'` instead. -/
theorem Tendsto.atTop_mul_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_pos hr).2 hf
/-- If a function `f` tends to infinity along a filter, then `f` divided by a positive
constant also tends to infinity. -/
theorem Tendsto.atTop_div_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x / r) l atTop := by
simpa only [div_eq_mul_inv] using hf.atTop_mul_const (inv_pos.2 hr)
theorem tendsto_const_mul_pow_atTop (hn : n ≠ 0) (hc : 0 < c) :
Tendsto (fun x => c * x ^ n) atTop atTop :=
Tendsto.const_mul_atTop hc (tendsto_pow_atTop hn)
theorem tendsto_const_mul_pow_atTop_iff :
Tendsto (fun x => c * x ^ n) atTop atTop ↔ n ≠ 0 ∧ 0 < c := by
refine ⟨fun h => ⟨?_, ?_⟩, fun h => tendsto_const_mul_pow_atTop h.1 h.2⟩
· rintro rfl
simp only [pow_zero, not_tendsto_const_atTop] at h
· rcases ((h.eventually_gt_atTop 0).and (eventually_ge_atTop 0)).exists with ⟨k, hck, hk⟩
exact pos_of_mul_pos_left hck (pow_nonneg hk _)
lemma tendsto_zpow_atTop_atTop {n : ℤ} (hn : 0 < n) : Tendsto (fun x : α ↦ x ^ n) atTop atTop := by
lift n to ℕ+ using hn; simp
end LinearOrderedSemifield
section LinearOrderedField
variable [LinearOrderedField α] {l : Filter β} {f : β → α} {r : α}
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_const_mul_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atBot := by
simpa only [← mul_neg, ← tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos hr
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_mul_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_pos hr
/-- If `r` is a positive constant, `fun x ↦ f x / r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
lemma tendsto_div_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_pos, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_const_mul_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atBot := by
simpa only [neg_mul, tendsto_neg_atBot_iff] using tendsto_const_mul_atBot_of_pos (neg_pos.2 hr)
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_mul_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_neg hr
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
lemma tendsto_div_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_of_neg, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_const_mul_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atTop := by
simpa only [neg_mul, tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos (neg_pos.2 hr)
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_mul_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_neg hr
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
lemma tendsto_div_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_neg, hr]
/-- The function `fun x ↦ r * f x` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_const_mul_atTop_iff [NeBot l] :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· simp [hr, hr.not_lt, tendsto_const_mul_atTop_of_neg]
· simp [not_tendsto_const_atTop]
· simp [hr, hr.not_lt, tendsto_const_mul_atTop_of_pos]
/-- The function `fun x ↦ f x * r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_mul_const_atTop_iff [NeBot l] :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff]
/-- The function `fun x ↦ f x / r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
lemma tendsto_div_const_atTop_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff]
/-- The function `fun x ↦ r * f x` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_const_mul_atBot_iff [NeBot l] :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [← tendsto_neg_atTop_iff, ← mul_neg, tendsto_const_mul_atTop_iff, neg_neg]
/-- The function `fun x ↦ f x * r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_mul_const_atBot_iff [NeBot l] :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff]
/-- The function `fun x ↦ f x / r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
lemma tendsto_div_const_atBot_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ r * f x` tends to infinity if and only if `r < 0. `-/
theorem tendsto_const_mul_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop ↔ r < 0 := by
simp [tendsto_const_mul_atTop_iff, h, h.not_tendsto disjoint_atBot_atTop]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x * r` tends to infinity if and only if `r < 0. `-/
theorem tendsto_mul_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_neg h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x / r` tends to infinity if and only if `r < 0. `-/
lemma tendsto_div_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atTop ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff_neg h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to negative infinity if and only if `0 < r. `-/
theorem tendsto_const_mul_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atBot_atTop]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to negative infinity if and only if `0 < r. `-/
theorem tendsto_mul_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_pos h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x / r` tends to negative infinity if and only if `0 < r. `-/
lemma tendsto_div_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_pos h]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ r * f x` tends to negative infinity if and only if `r < 0. `-/
theorem tendsto_const_mul_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot ↔ r < 0 := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atTop_atBot]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x * r` tends to negative infinity if and only if `r < 0. `-/
theorem tendsto_mul_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_neg h]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x / r` tends to negative infinity if and only if `r < 0. `-/
lemma tendsto_div_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_neg h]
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to negative infinity. -/
theorem Tendsto.const_mul_atTop_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_neg hr).2 hf
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to negative infinity. -/
theorem Tendsto.atTop_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_neg hr).2 hf
/-- If a function `f` tends to infinity along a filter,
then `f` divided by a negative constant tends to negative infinity. -/
lemma Tendsto.atTop_div_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot := (tendsto_div_const_atBot_of_neg hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the left) also tends to negative infinity. -/
theorem Tendsto.const_mul_atBot (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the right) also tends to negative infinity. -/
theorem Tendsto.atBot_mul_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` divided by
a positive constant also tends to negative infinity. -/
theorem Tendsto.atBot_div_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x / r) l atBot := (tendsto_div_const_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to positive infinity. -/
theorem Tendsto.const_mul_atBot_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_neg hr).2 hf
/-- If a function tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to positive infinity. -/
theorem Tendsto.atBot_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_neg hr).2 hf
theorem tendsto_neg_const_mul_pow_atTop {c : α} {n : ℕ} (hn : n ≠ 0) (hc : c < 0) :
Tendsto (fun x => c * x ^ n) atTop atBot :=
(tendsto_pow_atTop hn).const_mul_atTop_of_neg hc
theorem tendsto_const_mul_pow_atBot_iff {c : α} {n : ℕ} :
Tendsto (fun x => c * x ^ n) atTop atBot ↔ n ≠ 0 ∧ c < 0 := by
simp only [← tendsto_neg_atTop_iff, ← neg_mul, tendsto_const_mul_pow_atTop_iff, neg_pos]
@[deprecated (since := "2024-05-06")]
alias Tendsto.neg_const_mul_atTop := Tendsto.const_mul_atTop_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.atTop_mul_neg_const := Tendsto.atTop_mul_const_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.neg_const_mul_atBot := Tendsto.const_mul_atBot_of_neg
@[deprecated (since := "2024-05-06")]
alias Tendsto.atBot_mul_neg_const := Tendsto.atBot_mul_const_of_neg
end LinearOrderedField
open Filter
theorem tendsto_atTop_atTop_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f)
(h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atTop atTop :=
tendsto_iInf.2 fun b =>
tendsto_principal.2 <|
let ⟨a, ha⟩ := h b
mem_of_superset (mem_atTop a) fun _a' ha' => le_trans ha (hf ha')
theorem tendsto_atTop_atBot_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f)
(h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atTop atBot :=
@tendsto_atTop_atTop_of_monotone _ βᵒᵈ _ _ _ hf h
theorem tendsto_atBot_atBot_of_monotone [Preorder α] [Preorder β] {f : α → β} (hf : Monotone f)
(h : ∀ b, ∃ a, f a ≤ b) : Tendsto f atBot atBot :=
tendsto_iInf.2 fun b => tendsto_principal.2 <|
let ⟨a, ha⟩ := h b; mem_of_superset (mem_atBot a) fun _a' ha' => le_trans (hf ha') ha
theorem tendsto_atBot_atTop_of_antitone [Preorder α] [Preorder β] {f : α → β} (hf : Antitone f)
(h : ∀ b, ∃ a, b ≤ f a) : Tendsto f atBot atTop :=
@tendsto_atBot_atBot_of_monotone _ βᵒᵈ _ _ _ hf h
section IsDirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] {f : α → β} {l : Filter β}
theorem tendsto_atTop' : Tendsto f atTop l ↔ ∀ s ∈ l, ∃ a, ∀ b ≥ a, f b ∈ s := by
simp only [tendsto_def, mem_atTop_sets, mem_preimage]
theorem tendsto_atTop_principal {s : Set β} : Tendsto f atTop (𝓟 s) ↔ ∃ N, ∀ n ≥ N, f n ∈ s := by
simp_rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_atTop_sets, mem_preimage]
variable [Preorder β]
/-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/
theorem tendsto_atTop_atTop : Tendsto f atTop atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
tendsto_iInf.trans <| forall_congr' fun _ => tendsto_atTop_principal
theorem tendsto_atTop_atBot : Tendsto f atTop atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → f a ≤ b :=
tendsto_atTop_atTop (β := βᵒᵈ)
theorem tendsto_atTop_atTop_iff_of_monotone (hf : Monotone f) :
Tendsto f atTop atTop ↔ ∀ b : β, ∃ a, b ≤ f a :=
tendsto_atTop_atTop.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans h <| hf ha'⟩
theorem tendsto_atTop_atBot_iff_of_antitone (hf : Antitone f) :
Tendsto f atTop atBot ↔ ∀ b : β, ∃ a, f a ≤ b :=
tendsto_atTop_atTop_iff_of_monotone (β := βᵒᵈ) hf
end IsDirected
section IsCodirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {f : α → β} {l : Filter β}
theorem tendsto_atBot' : Tendsto f atBot l ↔ ∀ s ∈ l, ∃ a, ∀ b ≤ a, f b ∈ s :=
tendsto_atTop' (α := αᵒᵈ)
theorem tendsto_atBot_principal {s : Set β} : Tendsto f atBot (𝓟 s) ↔ ∃ N, ∀ n ≤ N, f n ∈ s :=
tendsto_atTop_principal (α := αᵒᵈ) (β := βᵒᵈ)
variable [Preorder β]
theorem tendsto_atBot_atTop : Tendsto f atBot atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → b ≤ f a :=
tendsto_atTop_atTop (α := αᵒᵈ)
theorem tendsto_atBot_atBot : Tendsto f atBot atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → f a ≤ b :=
tendsto_atTop_atTop (α := αᵒᵈ) (β := βᵒᵈ)
theorem tendsto_atBot_atBot_iff_of_monotone (hf : Monotone f) :
Tendsto f atBot atBot ↔ ∀ b : β, ∃ a, f a ≤ b :=
tendsto_atBot_atBot.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans (hf ha') h⟩
theorem tendsto_atBot_atTop_iff_of_antitone (hf : Antitone f) :
Tendsto f atBot atTop ↔ ∀ b : β, ∃ a, b ≤ f a :=
tendsto_atBot_atBot_iff_of_monotone (β := βᵒᵈ) hf
end IsCodirected
alias _root_.Monotone.tendsto_atTop_atTop := tendsto_atTop_atTop_of_monotone
alias _root_.Monotone.tendsto_atBot_atBot := tendsto_atBot_atBot_of_monotone
alias _root_.Monotone.tendsto_atTop_atTop_iff := tendsto_atTop_atTop_iff_of_monotone
alias _root_.Monotone.tendsto_atBot_atBot_iff := tendsto_atBot_atBot_iff_of_monotone
theorem comap_embedding_atTop [Preorder β] [Preorder γ] {e : β → γ}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) : comap e atTop = atTop :=
le_antisymm
(le_iInf fun b =>
le_principal_iff.2 <| mem_comap.2 ⟨Ici (e b), mem_atTop _, fun _ => (hm _ _).1⟩)
(tendsto_atTop_atTop_of_monotone (fun _ _ => (hm _ _).2) hu).le_comap
theorem comap_embedding_atBot [Preorder β] [Preorder γ] {e : β → γ}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) : comap e atBot = atBot :=
@comap_embedding_atTop βᵒᵈ γᵒᵈ _ _ e (Function.swap hm) hu
theorem tendsto_atTop_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, c ≤ e b) :
Tendsto (e ∘ f) l atTop ↔ Tendsto f l atTop := by
rw [← comap_embedding_atTop hm hu, tendsto_comap_iff]
/-- A function `f` goes to `-∞` independent of an order-preserving embedding `e`. -/
theorem tendsto_atBot_embedding [Preorder β] [Preorder γ] {f : α → β} {e : β → γ} {l : Filter α}
(hm : ∀ b₁ b₂, e b₁ ≤ e b₂ ↔ b₁ ≤ b₂) (hu : ∀ c, ∃ b, e b ≤ c) :
Tendsto (e ∘ f) l atBot ↔ Tendsto f l atBot :=
@tendsto_atTop_embedding α βᵒᵈ γᵒᵈ _ _ f e l (Function.swap hm) hu
theorem tendsto_finset_range : Tendsto Finset.range atTop atTop :=
Finset.range_mono.tendsto_atTop_atTop Finset.exists_nat_subset_range
theorem atTop_finset_eq_iInf : (atTop : Filter (Finset α)) = ⨅ x : α, 𝓟 (Ici {x}) := by
refine le_antisymm (le_iInf fun i => le_principal_iff.2 <| mem_atTop ({i} : Finset α)) ?_
refine
le_iInf fun s =>
le_principal_iff.2 <| mem_iInf_of_iInter s.finite_toSet (fun i => mem_principal_self _) ?_
simp only [subset_def, mem_iInter, SetCoe.forall, mem_Ici, Finset.le_iff_subset,
Finset.mem_singleton, Finset.subset_iff, forall_eq]
exact fun t => id
/-- If `f` is a monotone sequence of `Finset`s and each `x` belongs to one of `f n`, then
`Tendsto f atTop atTop`. -/
theorem tendsto_atTop_finset_of_monotone [Preorder β] {f : β → Finset α} (h : Monotone f)
(h' : ∀ x : α, ∃ n, x ∈ f n) : Tendsto f atTop atTop := by
simp only [atTop_finset_eq_iInf, tendsto_iInf, tendsto_principal]
intro a
rcases h' a with ⟨b, hb⟩
exact (eventually_ge_atTop b).mono fun b' hb' => (Finset.singleton_subset_iff.2 hb).trans (h hb')
alias _root_.Monotone.tendsto_atTop_finset := tendsto_atTop_finset_of_monotone
-- Porting note: add assumption `DecidableEq β` so that the lemma applies to any instance
theorem tendsto_finset_image_atTop_atTop [DecidableEq β] {i : β → γ} {j : γ → β}
(h : Function.LeftInverse j i) : Tendsto (Finset.image j) atTop atTop :=
(Finset.image_mono j).tendsto_atTop_finset fun a =>
⟨{i a}, by simp only [Finset.image_singleton, h a, Finset.mem_singleton]⟩
theorem tendsto_finset_preimage_atTop_atTop {f : α → β} (hf : Function.Injective f) :
Tendsto (fun s : Finset β => s.preimage f (hf.injOn)) atTop atTop :=
(Finset.monotone_preimage hf).tendsto_atTop_finset fun x =>
⟨{f x}, Finset.mem_preimage.2 <| Finset.mem_singleton_self _⟩
theorem prod_atTop_atTop_eq [Preorder α] [Preorder β] :
(atTop : Filter α) ×ˢ (atTop : Filter β) = (atTop : Filter (α × β)) := by
cases isEmpty_or_nonempty α
· subsingleton
cases isEmpty_or_nonempty β
· subsingleton
simpa [atTop, prod_iInf_left, prod_iInf_right, iInf_prod] using iInf_comm
theorem prod_atBot_atBot_eq [Preorder α] [Preorder β] :
(atBot : Filter α) ×ˢ (atBot : Filter β) = (atBot : Filter (α × β)) :=
@prod_atTop_atTop_eq αᵒᵈ βᵒᵈ _ _
theorem prod_map_atTop_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atTop ×ˢ map u₂ atTop = map (Prod.map u₁ u₂) atTop := by
rw [prod_map_map_eq, prod_atTop_atTop_eq, Prod.map_def]
theorem prod_map_atBot_eq {α₁ α₂ β₁ β₂ : Type*} [Preorder β₁] [Preorder β₂]
(u₁ : β₁ → α₁) (u₂ : β₂ → α₂) : map u₁ atBot ×ˢ map u₂ atBot = map (Prod.map u₁ u₂) atBot :=
@prod_map_atTop_eq _ _ β₁ᵒᵈ β₂ᵒᵈ _ _ _ _
theorem Tendsto.subseq_mem {F : Filter α} {V : ℕ → Set α} (h : ∀ n, V n ∈ F) {u : ℕ → α}
(hu : Tendsto u atTop F) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, u (φ n) ∈ V n :=
extraction_forall_of_eventually'
(fun n => tendsto_atTop'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n)
theorem tendsto_atBot_diagonal [Preorder α] : Tendsto (fun a : α => (a, a)) atBot atBot := by
rw [← prod_atBot_atBot_eq]
exact tendsto_id.prod_mk tendsto_id
theorem tendsto_atTop_diagonal [Preorder α] : Tendsto (fun a : α => (a, a)) atTop atTop := by
rw [← prod_atTop_atTop_eq]
exact tendsto_id.prod_mk tendsto_id
theorem Tendsto.prod_map_prod_atBot [Preorder γ] {F : Filter α} {G : Filter β} {f : α → γ}
{g : β → γ} (hf : Tendsto f F atBot) (hg : Tendsto g G atBot) :
Tendsto (Prod.map f g) (F ×ˢ G) atBot := by
rw [← prod_atBot_atBot_eq]
exact hf.prod_map hg
theorem Tendsto.prod_map_prod_atTop [Preorder γ] {F : Filter α} {G : Filter β} {f : α → γ}
{g : β → γ} (hf : Tendsto f F atTop) (hg : Tendsto g G atTop) :
Tendsto (Prod.map f g) (F ×ˢ G) atTop := by
rw [← prod_atTop_atTop_eq]
exact hf.prod_map hg
theorem Tendsto.prod_atBot [Preorder α] [Preorder γ] {f g : α → γ}
(hf : Tendsto f atBot atBot) (hg : Tendsto g atBot atBot) :
Tendsto (Prod.map f g) atBot atBot := by
rw [← prod_atBot_atBot_eq]
exact hf.prod_map_prod_atBot hg
theorem Tendsto.prod_atTop [Preorder α] [Preorder γ] {f g : α → γ}
(hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) :
Tendsto (Prod.map f g) atTop atTop := by
rw [← prod_atTop_atTop_eq]
exact hf.prod_map_prod_atTop hg
theorem eventually_atBot_prod_self [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)]
{p : α × α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k l, k ≤ a → l ≤ a → p (k, l) := by
simp [← prod_atBot_atBot_eq, (@atBot_basis α _ _).prod_self.eventually_iff]
theorem eventually_atTop_prod_self [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)]
{p : α × α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k l, a ≤ k → a ≤ l → p (k, l) :=
eventually_atBot_prod_self (α := αᵒᵈ)
theorem eventually_atBot_prod_self' [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)]
{p : α × α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ k ≤ a, ∀ l ≤ a, p (k, l) := by
simp only [eventually_atBot_prod_self, forall_cond_comm]
theorem eventually_atTop_prod_self' [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)]
{p : α × α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ k ≥ a, ∀ l ≥ a, p (k, l) := by
simp only [eventually_atTop_prod_self, forall_cond_comm]
theorem eventually_atTop_curry [Preorder α] [Preorder β] {p : α × β → Prop}
(hp : ∀ᶠ x : α × β in Filter.atTop, p x) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, p (k, l) := by
rw [← prod_atTop_atTop_eq] at hp
exact hp.curry
theorem eventually_atBot_curry [Preorder α] [Preorder β] {p : α × β → Prop}
(hp : ∀ᶠ x : α × β in Filter.atBot, p x) : ∀ᶠ k in atBot, ∀ᶠ l in atBot, p (k, l) :=
@eventually_atTop_curry αᵒᵈ βᵒᵈ _ _ _ hp
/-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connection above `b'`. -/
theorem map_atTop_eq_of_gc [SemilatticeSup α] [SemilatticeSup β] {f : α → β} (g : β → α) (b' : β)
(hf : Monotone f) (gc : ∀ a, ∀ b ≥ b', f a ≤ b ↔ a ≤ g b) (hgi : ∀ b ≥ b', b ≤ f (g b)) :
map f atTop = atTop := by
refine
le_antisymm
(hf.tendsto_atTop_atTop fun b => ⟨g (b ⊔ b'), le_sup_left.trans <| hgi _ le_sup_right⟩) ?_
have : Nonempty α := ⟨g b'⟩
rw [map_atTop_eq]
refine le_iInf fun a => iInf_le_of_le (f a ⊔ b') <| principal_mono.2 fun b hb => ?_
rw [mem_Ici, sup_le_iff] at hb
exact ⟨g b, (gc _ _ hb.2).1 hb.1, le_antisymm ((gc _ _ hb.2).2 le_rfl) (hgi _ hb.2)⟩
theorem map_atBot_eq_of_gc [SemilatticeInf α] [SemilatticeInf β] {f : α → β} (g : β → α) (b' : β)
(hf : Monotone f) (gc : ∀ a, ∀ b ≤ b', b ≤ f a ↔ g b ≤ a) (hgi : ∀ b ≤ b', f (g b) ≤ b) :
map f atBot = atBot :=
@map_atTop_eq_of_gc αᵒᵈ βᵒᵈ _ _ _ _ _ hf.dual gc hgi
theorem map_val_atTop_of_Ici_subset [SemilatticeSup α] {a : α} {s : Set α} (h : Ici a ⊆ s) :
map ((↑) : s → α) atTop = atTop := by
haveI : Nonempty s := ⟨⟨a, h le_rfl⟩⟩
have : Directed (· ≥ ·) fun x : s => 𝓟 (Ici x) := fun x y ↦ by
use ⟨x ⊔ y ⊔ a, h le_sup_right⟩
simp only [principal_mono, Ici_subset_Ici, ← Subtype.coe_le_coe, Subtype.coe_mk]
exact ⟨le_sup_left.trans le_sup_left, le_sup_right.trans le_sup_left⟩
simp only [le_antisymm_iff, atTop, le_iInf_iff, le_principal_iff, mem_map, mem_setOf_eq,
map_iInf_eq this, map_principal]
constructor
· intro x
refine mem_of_superset (mem_iInf_of_mem ⟨x ⊔ a, h le_sup_right⟩ (mem_principal_self _)) ?_
rintro _ ⟨y, hy, rfl⟩
exact le_trans le_sup_left (Subtype.coe_le_coe.2 hy)
· intro x
filter_upwards [mem_atTop (↑x ⊔ a)] with b hb
exact ⟨⟨b, h <| le_sup_right.trans hb⟩, Subtype.coe_le_coe.1 (le_sup_left.trans hb), rfl⟩
/-- The image of the filter `atTop` on `Ici a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ici_atTop [SemilatticeSup α] (a : α) : map ((↑) : Ici a → α) atTop = atTop :=
map_val_atTop_of_Ici_subset (Subset.refl _)
/-- The image of the filter `atTop` on `Ioi a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ioi_atTop [SemilatticeSup α] [NoMaxOrder α] (a : α) :
map ((↑) : Ioi a → α) atTop = atTop :=
let ⟨_b, hb⟩ := exists_gt a
map_val_atTop_of_Ici_subset <| Ici_subset_Ioi.2 hb
/-- The `atTop` filter for an open interval `Ioi a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ioi_eq [SemilatticeSup α] (a : α) : atTop = comap ((↑) : Ioi a → α) atTop := by
rcases isEmpty_or_nonempty (Ioi a) with h|⟨⟨b, hb⟩⟩
· subsingleton
· rw [← map_val_atTop_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map Subtype.coe_injective]
/-- The `atTop` filter for an open interval `Ici a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ici_eq [SemilatticeSup α] (a : α) : atTop = comap ((↑) : Ici a → α) atTop := by
rw [← map_val_Ici_atTop a, comap_map Subtype.coe_injective]
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iio_atBot [SemilatticeInf α] [NoMinOrder α] (a : α) :
map ((↑) : Iio a → α) atBot = atBot :=
@map_val_Ioi_atTop αᵒᵈ _ _ _
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iio_eq [SemilatticeInf α] (a : α) : atBot = comap ((↑) : Iio a → α) atBot :=
@atTop_Ioi_eq αᵒᵈ _ _
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iic_atBot [SemilatticeInf α] (a : α) : map ((↑) : Iic a → α) atBot = atBot :=
@map_val_Ici_atTop αᵒᵈ _ _
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iic_eq [SemilatticeInf α] (a : α) : atBot = comap ((↑) : Iic a → α) atBot :=
@atTop_Ici_eq αᵒᵈ _ _
theorem tendsto_Ioi_atTop [SemilatticeSup α] {a : α} {f : β → Ioi a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ioi_eq, tendsto_comap_iff, Function.comp_def]
theorem tendsto_Iio_atBot [SemilatticeInf α] {a : α} {f : β → Iio a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := by
rw [atBot_Iio_eq, tendsto_comap_iff, Function.comp_def]
theorem tendsto_Ici_atTop [SemilatticeSup α] {a : α} {f : β → Ici a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ici_eq, tendsto_comap_iff, Function.comp_def]
theorem tendsto_Iic_atBot [SemilatticeInf α] {a : α} {f : β → Iic a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot := by
rw [atBot_Iic_eq, tendsto_comap_iff, Function.comp_def]
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Ioi_atTop [SemilatticeSup α] [NoMaxOrder α] {a : α} {f : α → β}
{l : Filter β} : Tendsto (fun x : Ioi a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ioi_atTop a, tendsto_map'_iff, Function.comp_def]
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Ici_atTop [SemilatticeSup α] {a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Ici a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ici_atTop a, tendsto_map'_iff, Function.comp_def]
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Iio_atBot [SemilatticeInf α] [NoMinOrder α] {a : α} {f : α → β}
{l : Filter β} : Tendsto (fun x : Iio a => f x) atBot l ↔ Tendsto f atBot l := by
rw [← map_val_Iio_atBot a, tendsto_map'_iff, Function.comp_def]
@[simp, nolint simpNF] -- Porting note: linter claims that LHS doesn't simplify. It does.
theorem tendsto_comp_val_Iic_atBot [SemilatticeInf α] {a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Iic a => f x) atBot l ↔ Tendsto f atBot l := by
rw [← map_val_Iic_atBot a, tendsto_map'_iff, Function.comp_def]
theorem map_add_atTop_eq_nat (k : ℕ) : map (fun a => a + k) atTop = atTop :=
map_atTop_eq_of_gc (fun a => a - k) k (fun a b h => add_le_add_right h k)
(fun a b h => (le_tsub_iff_right h).symm) fun a h => by rw [tsub_add_cancel_of_le h]
theorem map_sub_atTop_eq_nat (k : ℕ) : map (fun a => a - k) atTop = atTop :=
map_atTop_eq_of_gc (fun a => a + k) 0 (fun a b h => tsub_le_tsub_right h _)
(fun a b _ => tsub_le_iff_right) fun b _ => by rw [add_tsub_cancel_right]
theorem tendsto_add_atTop_nat (k : ℕ) : Tendsto (fun a => a + k) atTop atTop :=
le_of_eq (map_add_atTop_eq_nat k)
theorem tendsto_sub_atTop_nat (k : ℕ) : Tendsto (fun a => a - k) atTop atTop :=
le_of_eq (map_sub_atTop_eq_nat k)
theorem tendsto_add_atTop_iff_nat {f : ℕ → α} {l : Filter α} (k : ℕ) :
Tendsto (fun n => f (n + k)) atTop l ↔ Tendsto f atTop l :=
show Tendsto (f ∘ fun n => n + k) atTop l ↔ Tendsto f atTop l by
rw [← tendsto_map'_iff, map_add_atTop_eq_nat]
theorem map_div_atTop_eq_nat (k : ℕ) (hk : 0 < k) : map (fun a => a / k) atTop = atTop :=
map_atTop_eq_of_gc (fun b => b * k + (k - 1)) 1 (fun a b h => Nat.div_le_div_right h)
-- Porting note: there was a parse error in `calc`, use `simp` instead
(fun a b _ => by simp only [← Nat.lt_succ_iff, Nat.div_lt_iff_lt_mul hk, Nat.succ_eq_add_one,
add_assoc, tsub_add_cancel_of_le (Nat.one_le_iff_ne_zero.2 hk.ne'), add_mul, one_mul])
fun b _ =>
calc
b = b * k / k := by rw [Nat.mul_div_cancel b hk]
_ ≤ (b * k + (k - 1)) / k := Nat.div_le_div_right <| Nat.le_add_right _ _
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
above, then `Tendsto u atTop atTop`. -/
theorem tendsto_atTop_atTop_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u)
(H : ¬BddAbove (range u)) : Tendsto u atTop atTop := by
apply h.tendsto_atTop_atTop
intro b
rcases not_bddAbove_iff.1 H b with ⟨_, ⟨N, rfl⟩, hN⟩
exact ⟨N, le_of_lt hN⟩
/-- If `u` is a monotone function with linear ordered codomain and the range of `u` is not bounded
below, then `Tendsto u atBot atBot`. -/
theorem tendsto_atBot_atBot_of_monotone' [Preorder ι] [LinearOrder α] {u : ι → α} (h : Monotone u)
(H : ¬BddBelow (range u)) : Tendsto u atBot atBot :=
@tendsto_atTop_atTop_of_monotone' ιᵒᵈ αᵒᵈ _ _ _ h.dual H
section IsDirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] {f : α → β}
theorem unbounded_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto f atTop atTop) :
¬BddAbove (range f) := by
rintro ⟨M, hM⟩
cases' mem_atTop_sets.mp (h <| Ioi_mem_atTop M) with a ha
apply lt_irrefl M
calc
M < f a := ha a le_rfl
_ ≤ M := hM (Set.mem_range_self a)
theorem unbounded_of_tendsto_atBot [NoMinOrder β] (h : Tendsto f atTop atBot) :
¬BddBelow (range f) := unbounded_of_tendsto_atTop (β := βᵒᵈ) h
end IsDirected
section IsCodirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] {f : α → β}
theorem unbounded_of_tendsto_atTop' [NoMaxOrder β] (h : Tendsto f atBot atTop) :
¬BddAbove (range f) := unbounded_of_tendsto_atTop (α := αᵒᵈ) h
theorem unbounded_of_tendsto_atBot' [NoMinOrder β] (h : Tendsto f atBot atBot) :
¬BddBelow (range f) := unbounded_of_tendsto_atTop (α := αᵒᵈ) (β := βᵒᵈ) h
end IsCodirected
/-- If a monotone function `u : ι → α` tends to `atTop` along *some* non-trivial filter `l`, then
it tends to `atTop` along `atTop`. -/
theorem tendsto_atTop_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α}
(h : Monotone u) [NeBot l] (hu : Tendsto u l atTop) : Tendsto u atTop atTop :=
h.tendsto_atTop_atTop fun b => (hu.eventually (mem_atTop b)).exists
/-- If a monotone function `u : ι → α` tends to `atBot` along *some* non-trivial filter `l`, then
it tends to `atBot` along `atBot`. -/
theorem tendsto_atBot_of_monotone_of_filter [Preorder ι] [Preorder α] {l : Filter ι} {u : ι → α}
(h : Monotone u) [NeBot l] (hu : Tendsto u l atBot) : Tendsto u atBot atBot :=
@tendsto_atTop_of_monotone_of_filter ιᵒᵈ αᵒᵈ _ _ _ _ h.dual _ hu
theorem tendsto_atTop_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι}
(h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atTop) :
Tendsto u atTop atTop :=
tendsto_atTop_of_monotone_of_filter h (tendsto_map' H)
theorem tendsto_atBot_of_monotone_of_subseq [Preorder ι] [Preorder α] {u : ι → α} {φ : ι' → ι}
(h : Monotone u) {l : Filter ι'} [NeBot l] (H : Tendsto (u ∘ φ) l atBot) :
Tendsto u atBot atBot :=
tendsto_atBot_of_monotone_of_filter h (tendsto_map' H)
/-- Let `f` and `g` be two maps to the same commutative monoid. This lemma gives a sufficient
condition for comparison of the filter `atTop.map (fun s ↦ ∏ b ∈ s, f b)` with
`atTop.map (fun s ↦ ∏ b ∈ s, g b)`. This is useful to compare the set of limit points of
`Π b in s, f b` as `s → atTop` with the similar set for `g`. -/
@[to_additive "Let `f` and `g` be two maps to the same commutative additive monoid. This lemma gives
a sufficient condition for comparison of the filter `atTop.map (fun s ↦ ∑ b ∈ s, f b)` with
`atTop.map (fun s ↦ ∑ b ∈ s, g b)`. This is useful to compare the set of limit points of
`∑ b ∈ s, f b` as `s → atTop` with the similar set for `g`."]
theorem map_atTop_finset_prod_le_of_prod_eq [CommMonoid α] {f : β → α} {g : γ → α}
(h_eq : ∀ u : Finset γ,
∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) :
(atTop.map fun s : Finset β => ∏ b ∈ s, f b) ≤
atTop.map fun s : Finset γ => ∏ x ∈ s, g x := by
classical
refine ((atTop_basis.map _).le_basis_iff (atTop_basis.map _)).2 fun b _ => ?_
let ⟨v, hv⟩ := h_eq b
refine ⟨v, trivial, ?_⟩
simpa [image_subset_iff] using hv
theorem HasAntitoneBasis.eventually_subset [Preorder ι] {l : Filter α} {s : ι → Set α}
(hl : l.HasAntitoneBasis s) {t : Set α} (ht : t ∈ l) : ∀ᶠ i in atTop, s i ⊆ t :=
let ⟨i, _, hi⟩ := hl.1.mem_iff.1 ht
(eventually_ge_atTop i).mono fun _j hj => (hl.antitone hj).trans hi
protected theorem HasAntitoneBasis.tendsto [Preorder ι] {l : Filter α} {s : ι → Set α}
(hl : l.HasAntitoneBasis s) {φ : ι → α} (h : ∀ i : ι, φ i ∈ s i) : Tendsto φ atTop l :=
fun _t ht => mem_map.2 <| (hl.eventually_subset ht).mono fun i hi => hi (h i)
theorem HasAntitoneBasis.comp_mono [Nonempty ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Preorder ι']
{l : Filter α}
{s : ι' → Set α} (hs : l.HasAntitoneBasis s) {φ : ι → ι'} (φ_mono : Monotone φ)
(hφ : Tendsto φ atTop atTop) : l.HasAntitoneBasis (s ∘ φ) :=
⟨hs.1.to_hasBasis
(fun n _ => (hφ.eventually_ge_atTop n).exists.imp fun _m hm => ⟨trivial, hs.antitone hm⟩)
fun n _ => ⟨φ n, trivial, Subset.rfl⟩,
hs.antitone.comp_monotone φ_mono⟩
theorem HasAntitoneBasis.comp_strictMono {l : Filter α} {s : ℕ → Set α} (hs : l.HasAntitoneBasis s)
{φ : ℕ → ℕ} (hφ : StrictMono φ) : l.HasAntitoneBasis (s ∘ φ) :=
hs.comp_mono hφ.monotone hφ.tendsto_atTop
/-- Given an antitone basis `s : ℕ → Set α` of a filter, extract an antitone subbasis `s ∘ φ`,
`φ : ℕ → ℕ`, such that `m < n` implies `r (φ m) (φ n)`. This lemma can be used to extract an
antitone basis with basis sets decreasing "sufficiently fast". -/
theorem HasAntitoneBasis.subbasis_with_rel {f : Filter α} {s : ℕ → Set α}
(hs : f.HasAntitoneBasis s) {r : ℕ → ℕ → Prop} (hr : ∀ m, ∀ᶠ n in atTop, r m n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ (∀ ⦃m n⦄, m < n → r (φ m) (φ n)) ∧ f.HasAntitoneBasis (s ∘ φ) := by
rsuffices ⟨φ, hφ, hrφ⟩ : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ m n, m < n → r (φ m) (φ n)
· exact ⟨φ, hφ, hrφ, hs.comp_strictMono hφ⟩
have : ∀ t : Set ℕ, t.Finite → ∀ᶠ n in atTop, ∀ m ∈ t, m < n ∧ r m n := fun t ht =>
(eventually_all_finite ht).2 fun m _ => (eventually_gt_atTop m).and (hr _)
rcases seq_of_forall_finite_exists fun t ht => (this t ht).exists with ⟨φ, hφ⟩
simp only [forall_mem_image, forall_and, mem_Iio] at hφ
exact ⟨φ, forall_swap.2 hφ.1, forall_swap.2 hφ.2⟩
/-- If `f` is a nontrivial countably generated filter, then there exists a sequence that converges
to `f`. -/
theorem exists_seq_tendsto (f : Filter α) [IsCountablyGenerated f] [NeBot f] :
∃ x : ℕ → α, Tendsto x atTop f := by
obtain ⟨B, h⟩ := f.exists_antitone_basis
choose x hx using fun n => Filter.nonempty_of_mem (h.mem n)
exact ⟨x, h.tendsto hx⟩
theorem exists_seq_monotone_tendsto_atTop_atTop (α : Type*) [SemilatticeSup α] [Nonempty α]
[(atTop : Filter α).IsCountablyGenerated] :
∃ xs : ℕ → α, Monotone xs ∧ Tendsto xs atTop atTop := by
obtain ⟨ys, h⟩ := exists_seq_tendsto (atTop : Filter α)
let xs : ℕ → α := fun n => Finset.sup' (Finset.range (n + 1)) Finset.nonempty_range_succ ys
have h_mono : Monotone xs := fun i j hij ↦ by
simp only [xs] -- Need to unfold `xs` and do alpha reduction, otherwise `gcongr` fails
gcongr
refine ⟨xs, h_mono, tendsto_atTop_mono (fun n ↦ Finset.le_sup' _ ?_) h⟩
simp
theorem exists_seq_antitone_tendsto_atTop_atBot (α : Type*) [SemilatticeInf α] [Nonempty α]
[h2 : (atBot : Filter α).IsCountablyGenerated] :
∃ xs : ℕ → α, Antitone xs ∧ Tendsto xs atTop atBot :=
@exists_seq_monotone_tendsto_atTop_atTop αᵒᵈ _ _ h2
/-- An abstract version of continuity of sequentially continuous functions on metric spaces:
if a filter `k` is countably generated then `Tendsto f k l` iff for every sequence `u`
converging to `k`, `f ∘ u` tends to `l`. -/
theorem tendsto_iff_seq_tendsto {f : α → β} {k : Filter α} {l : Filter β} [k.IsCountablyGenerated] :
Tendsto f k l ↔ ∀ x : ℕ → α, Tendsto x atTop k → Tendsto (f ∘ x) atTop l := by
refine ⟨fun h x hx => h.comp hx, fun H s hs => ?_⟩
contrapose! H
have : NeBot (k ⊓ 𝓟 (f ⁻¹' sᶜ)) := by simpa [neBot_iff, inf_principal_eq_bot]
rcases (k ⊓ 𝓟 (f ⁻¹' sᶜ)).exists_seq_tendsto with ⟨x, hx⟩
rw [tendsto_inf, tendsto_principal] at hx
refine ⟨x, hx.1, fun h => ?_⟩
rcases (hx.2.and (h hs)).exists with ⟨N, hnmem, hmem⟩
exact hnmem hmem
theorem tendsto_of_seq_tendsto {f : α → β} {k : Filter α} {l : Filter β} [k.IsCountablyGenerated] :
(∀ x : ℕ → α, Tendsto x atTop k → Tendsto (f ∘ x) atTop l) → Tendsto f k l :=
tendsto_iff_seq_tendsto.2
theorem eventually_iff_seq_eventually {ι : Type*} {l : Filter ι} {p : ι → Prop}
[l.IsCountablyGenerated] :
(∀ᶠ n in l, p n) ↔ ∀ x : ℕ → ι, Tendsto x atTop l → ∀ᶠ n : ℕ in atTop, p (x n) := by
simpa using tendsto_iff_seq_tendsto (f := id) (l := 𝓟 {x | p x})
theorem frequently_iff_seq_frequently {ι : Type*} {l : Filter ι} {p : ι → Prop}
[l.IsCountablyGenerated] :
(∃ᶠ n in l, p n) ↔ ∃ x : ℕ → ι, Tendsto x atTop l ∧ ∃ᶠ n : ℕ in atTop, p (x n) := by
simp only [Filter.Frequently, eventually_iff_seq_eventually (l := l)]
push_neg; rfl
theorem subseq_forall_of_frequently {ι : Type*} {x : ℕ → ι} {p : ι → Prop} {l : Filter ι}
(h_tendsto : Tendsto x atTop l) (h : ∃ᶠ n in atTop, p (x n)) :
∃ ns : ℕ → ℕ, Tendsto (fun n => x (ns n)) atTop l ∧ ∀ n, p (x (ns n)) := by
choose ns hge hns using frequently_atTop.1 h
exact ⟨ns, h_tendsto.comp (tendsto_atTop_mono hge tendsto_id), hns⟩
theorem exists_seq_forall_of_frequently {ι : Type*} {l : Filter ι} {p : ι → Prop}
[l.IsCountablyGenerated] (h : ∃ᶠ n in l, p n) :
∃ ns : ℕ → ι, Tendsto ns atTop l ∧ ∀ n, p (ns n) := by
rw [frequently_iff_seq_frequently] at h
obtain ⟨x, hx_tendsto, hx_freq⟩ := h
obtain ⟨n_to_n, h_tendsto, h_freq⟩ := subseq_forall_of_frequently hx_tendsto hx_freq
exact ⟨x ∘ n_to_n, h_tendsto, h_freq⟩
lemma frequently_iff_seq_forall {ι : Type*} {l : Filter ι} {p : ι → Prop}
[l.IsCountablyGenerated] :
(∃ᶠ n in l, p n) ↔ ∃ ns : ℕ → ι, Tendsto ns atTop l ∧ ∀ n, p (ns n) :=
⟨exists_seq_forall_of_frequently, fun ⟨_ns, hnsl, hpns⟩ ↦
hnsl.frequently <| frequently_of_forall hpns⟩
/-- A sequence converges if every subsequence has a convergent subsequence. -/
theorem tendsto_of_subseq_tendsto {ι : Type*} {x : ι → α} {f : Filter α} {l : Filter ι}
[l.IsCountablyGenerated]
(hxy : ∀ ns : ℕ → ι, Tendsto ns atTop l →
∃ ms : ℕ → ℕ, Tendsto (fun n => x (ns <| ms n)) atTop f) :
Tendsto x l f := by
contrapose! hxy
obtain ⟨s, hs, hfreq⟩ : ∃ s ∈ f, ∃ᶠ n in l, x n ∉ s := by
rwa [not_tendsto_iff_exists_frequently_nmem] at hxy
obtain ⟨y, hy_tendsto, hy_freq⟩ := exists_seq_forall_of_frequently hfreq
refine ⟨y, hy_tendsto, fun ms hms_tendsto ↦ ?_⟩
rcases (hms_tendsto.eventually_mem hs).exists with ⟨n, hn⟩
exact absurd hn <| hy_freq _
theorem subseq_tendsto_of_neBot {f : Filter α} [IsCountablyGenerated f] {u : ℕ → α}
(hx : NeBot (f ⊓ map u atTop)) : ∃ θ : ℕ → ℕ, StrictMono θ ∧ Tendsto (u ∘ θ) atTop f := by
rw [← Filter.push_pull', map_neBot_iff] at hx
rcases exists_seq_tendsto (comap u f ⊓ atTop) with ⟨φ, hφ⟩
rw [tendsto_inf, tendsto_comap_iff] at hφ
obtain ⟨ψ, hψ, hψφ⟩ : ∃ ψ : ℕ → ℕ, StrictMono ψ ∧ StrictMono (φ ∘ ψ) :=
strictMono_subseq_of_tendsto_atTop hφ.2
exact ⟨φ ∘ ψ, hψφ, hφ.1.comp hψ.tendsto_atTop⟩
end Filter
open Filter Finset
section
variable {R : Type*} [LinearOrderedSemiring R]
theorem exists_lt_mul_self (a : R) : ∃ x ≥ 0, a < x * x :=
let ⟨x, hxa, hx0⟩ :=
((tendsto_mul_self_atTop.eventually (eventually_gt_atTop a)).and (eventually_ge_atTop 0)).exists
⟨x, hx0, hxa⟩
theorem exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x :=
let ⟨x, hx0, hxa⟩ := exists_lt_mul_self a
⟨x, hx0, hxa.le⟩
end
theorem Monotone.piecewise_eventually_eq_iUnion {β : α → Type*} [Preorder ι] {s : ι → Set α}
[∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋃ i, s i)]
(hs : Monotone s) (f g : (a : α) → β a) (a : α) :
∀ᶠ i in atTop, (s i).piecewise f g a = (⋃ i, s i).piecewise f g a := by
rcases em (∃ i, a ∈ s i) with ⟨i, hi⟩ | ha
· refine (eventually_ge_atTop i).mono fun j hij ↦ ?_
simp only [Set.piecewise_eq_of_mem, hs hij hi, subset_iUnion _ _ hi]
· filter_upwards with i
simp only [Set.piecewise_eq_of_not_mem, not_exists.1 ha i, mt mem_iUnion.1 ha,
not_false_eq_true, exists_false]
theorem Antitone.piecewise_eventually_eq_iInter {β : α → Type*} [Preorder ι] {s : ι → Set α}
[∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋂ i, s i)]
(hs : Antitone s) (f g : (a : α) → β a) (a : α) :
∀ᶠ i in atTop, (s i).piecewise f g a = (⋂ i, s i).piecewise f g a := by
classical
convert ← (compl_anti.comp hs).piecewise_eventually_eq_iUnion g f a using 3
· convert congr_fun (Set.piecewise_compl (s _) g f) a
· simp only [(· ∘ ·), ← compl_iInter, Set.piecewise_compl]
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to a commutative monoid. Suppose that `f x = 1` outside of the range of `g`. Then the filters
`atTop.map (fun s ↦ ∏ i ∈ s, f (g i))` and `atTop.map (fun s ↦ ∏ i ∈ s, f i)` coincide.
The additive version of this lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions. -/
@[to_additive]
theorem Function.Injective.map_atTop_finset_prod_eq [CommMonoid α] {g : γ → β}
(hg : Function.Injective g) {f : β → α} (hf : ∀ x, x ∉ Set.range g → f x = 1) :
map (fun s => ∏ i ∈ s, f (g i)) atTop = map (fun s => ∏ i ∈ s, f i) atTop := by
haveI := Classical.decEq β
apply le_antisymm <;> refine map_atTop_finset_prod_le_of_prod_eq fun s => ?_
· refine ⟨s.preimage g hg.injOn, fun t ht => ?_⟩
refine ⟨t.image g ∪ s, Finset.subset_union_right, ?_⟩
rw [← Finset.prod_image hg.injOn]
refine (prod_subset subset_union_left ?_).symm
simp only [Finset.mem_union, Finset.mem_image]
refine fun y hy hyt => hf y (mt ?_ hyt)
rintro ⟨x, rfl⟩
exact ⟨x, ht (Finset.mem_preimage.2 <| hy.resolve_left hyt), rfl⟩
· refine ⟨s.image g, fun t ht => ?_⟩
simp only [← prod_preimage _ _ hg.injOn _ fun x _ => hf x]
exact ⟨_, (image_subset_iff_subset_preimage _).1 ht, rfl⟩
/-- Let `g : γ → β` be an injective function and `f : β → α` be a function from the codomain of `g`
to an additive commutative monoid. Suppose that `f x = 0` outside of the range of `g`. Then the
filters `atTop.map (fun s ↦ ∑ i ∈ s, f (g i))` and `atTop.map (fun s ↦ ∑ i ∈ s, f i)` coincide.
This lemma is used to prove the equality `∑' x, f (g x) = ∑' y, f y` under
the same assumptions. -/
add_decl_doc Function.Injective.map_atTop_finset_sum_eq
|
Order\Filter\Bases.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Data.Prod.PProd
import Mathlib.Data.Set.Countable
import Mathlib.Order.Filter.Prod
import Mathlib.Order.Filter.Ker
/-!
# Filter bases
A filter basis `B : FilterBasis α` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element of
the collection. Compared to filters, filter bases do not require that any set containing
an element of `B` belongs to `B`.
A filter basis `B` can be used to construct `B.filter : Filter α` such that a set belongs
to `B.filter` if and only if it contains an element of `B`.
Given an indexing type `ι`, a predicate `p : ι → Prop`, and a map `s : ι → Set α`,
the proposition `h : Filter.IsBasis p s` makes sure the range of `s` bounded by `p`
(ie. `s '' setOf p`) defines a filter basis `h.filterBasis`.
If one already has a filter `l` on `α`, `Filter.HasBasis l p s` (where `p : ι → Prop`
and `s : ι → Set α` as above) means that a set belongs to `l` if and
only if it contains some `s i` with `p i`. It implies `h : Filter.IsBasis p s`, and
`l = h.filterBasis.filter`. The point of this definition is that checking statements
involving elements of `l` often reduces to checking them on the basis elements.
We define a function `HasBasis.index (h : Filter.HasBasis l p s) (t) (ht : t ∈ l)` that returns
some index `i` such that `p i` and `s i ⊆ t`. This function can be useful to avoid manual
destruction of `h.mem_iff.mpr ht` using `cases` or `let`.
This file also introduces more restricted classes of bases, involving monotonicity or
countability. In particular, for `l : Filter α`, `l.IsCountablyGenerated` means
there is a countable set of sets which generates `s`. This is reformulated in term of bases,
and consequences are derived.
## Main statements
* `Filter.HasBasis.mem_iff`, `HasBasis.mem_of_superset`, `HasBasis.mem_of_mem` : restate `t ∈ f` in
terms of a basis;
* `Filter.basis_sets` : all sets of a filter form a basis;
* `Filter.HasBasis.inf`, `Filter.HasBasis.inf_principal`, `Filter.HasBasis.prod`,
`Filter.HasBasis.prod_self`, `Filter.HasBasis.map`, `Filter.HasBasis.comap` : combinators to
construct filters of `l ⊓ l'`, `l ⊓ 𝓟 t`, `l ×ˢ l'`, `l ×ˢ l`, `l.map f`, `l.comap f`
respectively;
* `Filter.HasBasis.le_iff`, `Filter.HasBasis.ge_iff`, `Filter.HasBasis.le_basis_iff` : restate
`l ≤ l'` in terms of bases.
* `Filter.HasBasis.tendsto_right_iff`, `Filter.HasBasis.tendsto_left_iff`,
`Filter.HasBasis.tendsto_iff` : restate `Tendsto f l l'` in terms of bases.
* `isCountablyGenerated_iff_exists_antitone_basis` : proves a filter is countably generated if and
only if it admits a basis parametrized by a decreasing sequence of sets indexed by `ℕ`.
* `tendsto_iff_seq_tendsto` : an abstract version of "sequentially continuous implies continuous".
## Implementation notes
As with `Set.iUnion`/`biUnion`/`Set.sUnion`, there are three different approaches to filter bases:
* `Filter.HasBasis l s`, `s : Set (Set α)`;
* `Filter.HasBasis l s`, `s : ι → Set α`;
* `Filter.HasBasis l p s`, `p : ι → Prop`, `s : ι → Set α`.
We use the latter one because, e.g., `𝓝 x` in an `EMetricSpace` or in a `MetricSpace` has a basis
of this form. The other two can be emulated using `s = id` or `p = fun _ ↦ True`.
With this approach sometimes one needs to `simp` the statement provided by the `Filter.HasBasis`
machinery, e.g., `simp only [true_and_iff]` or `simp only [forall_const]` can help with the case
`p = fun _ ↦ True`.
-/
open Set Filter
section sort
variable {α β γ : Type*} {ι ι' : Sort*}
/-- A filter basis `B` on a type `α` is a nonempty collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure FilterBasis (α : Type*) where
/-- Sets of a filter basis. -/
sets : Set (Set α)
/-- The set of filter basis sets is nonempty. -/
nonempty : sets.Nonempty
/-- The set of filter basis sets is directed downwards. -/
inter_sets {x y} : x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y
instance FilterBasis.nonempty_sets (B : FilterBasis α) : Nonempty B.sets :=
B.nonempty.to_subtype
-- Porting note: this instance was reducible but it doesn't work the same way in Lean 4
/-- If `B` is a filter basis on `α`, and `U` a subset of `α` then we can write `U ∈ B` as
on paper. -/
instance {α : Type*} : Membership (Set α) (FilterBasis α) :=
⟨fun U B => U ∈ B.sets⟩
@[simp] theorem FilterBasis.mem_sets {s : Set α} {B : FilterBasis α} : s ∈ B.sets ↔ s ∈ B := Iff.rfl
-- For illustration purposes, the filter basis defining `(atTop : Filter ℕ)`
instance : Inhabited (FilterBasis ℕ) :=
⟨{ sets := range Ici
nonempty := ⟨Ici 0, mem_range_self 0⟩
inter_sets := by
rintro _ _ ⟨n, rfl⟩ ⟨m, rfl⟩
exact ⟨Ici (max n m), mem_range_self _, Ici_inter_Ici.symm.subset⟩ }⟩
/-- View a filter as a filter basis. -/
def Filter.asBasis (f : Filter α) : FilterBasis α :=
⟨f.sets, ⟨univ, univ_mem⟩, fun {x y} hx hy => ⟨x ∩ y, inter_mem hx hy, subset_rfl⟩⟩
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- `is_basis p s` means the image of `s` bounded by `p` is a filter basis. -/
structure Filter.IsBasis (p : ι → Prop) (s : ι → Set α) : Prop where
/-- There exists at least one `i` that satisfies `p`. -/
nonempty : ∃ i, p i
/-- `s` is directed downwards on `i` such that `p i`. -/
inter : ∀ {i j}, p i → p j → ∃ k, p k ∧ s k ⊆ s i ∩ s j
namespace Filter
namespace IsBasis
/-- Constructs a filter basis from an indexed family of sets satisfying `IsBasis`. -/
protected def filterBasis {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s) : FilterBasis α where
sets := { t | ∃ i, p i ∧ s i = t }
nonempty :=
let ⟨i, hi⟩ := h.nonempty
⟨s i, ⟨i, hi, rfl⟩⟩
inter_sets := by
rintro _ _ ⟨i, hi, rfl⟩ ⟨j, hj, rfl⟩
rcases h.inter hi hj with ⟨k, hk, hk'⟩
exact ⟨_, ⟨k, hk, rfl⟩, hk'⟩
variable {p : ι → Prop} {s : ι → Set α} (h : IsBasis p s)
theorem mem_filterBasis_iff {U : Set α} : U ∈ h.filterBasis ↔ ∃ i, p i ∧ s i = U :=
Iff.rfl
end IsBasis
end Filter
namespace FilterBasis
/-- The filter associated to a filter basis. -/
protected def filter (B : FilterBasis α) : Filter α where
sets := { s | ∃ t ∈ B, t ⊆ s }
univ_sets := B.nonempty.imp fun s s_in => ⟨s_in, s.subset_univ⟩
sets_of_superset := fun ⟨s, s_in, h⟩ hxy => ⟨s, s_in, Set.Subset.trans h hxy⟩
inter_sets := fun ⟨_s, s_in, hs⟩ ⟨_t, t_in, ht⟩ =>
let ⟨u, u_in, u_sub⟩ := B.inter_sets s_in t_in
⟨u, u_in, u_sub.trans (inter_subset_inter hs ht)⟩
theorem mem_filter_iff (B : FilterBasis α) {U : Set α} : U ∈ B.filter ↔ ∃ s ∈ B, s ⊆ U :=
Iff.rfl
theorem mem_filter_of_mem (B : FilterBasis α) {U : Set α} : U ∈ B → U ∈ B.filter := fun U_in =>
⟨U, U_in, Subset.refl _⟩
theorem eq_iInf_principal (B : FilterBasis α) : B.filter = ⨅ s : B.sets, 𝓟 s := by
have : Directed (· ≥ ·) fun s : B.sets => 𝓟 (s : Set α) := by
rintro ⟨U, U_in⟩ ⟨V, V_in⟩
rcases B.inter_sets U_in V_in with ⟨W, W_in, W_sub⟩
use ⟨W, W_in⟩
simp only [le_principal_iff, mem_principal, Subtype.coe_mk]
exact subset_inter_iff.mp W_sub
ext U
simp [mem_filter_iff, mem_iInf_of_directed this]
protected theorem generate (B : FilterBasis α) : generate B.sets = B.filter := by
apply le_antisymm
· intro U U_in
rcases B.mem_filter_iff.mp U_in with ⟨V, V_in, h⟩
exact GenerateSets.superset (GenerateSets.basic V_in) h
· rw [le_generate_iff]
apply mem_filter_of_mem
end FilterBasis
namespace Filter
namespace IsBasis
variable {p : ι → Prop} {s : ι → Set α}
/-- Constructs a filter from an indexed family of sets satisfying `IsBasis`. -/
protected def filter (h : IsBasis p s) : Filter α :=
h.filterBasis.filter
protected theorem mem_filter_iff (h : IsBasis p s) {U : Set α} :
U ∈ h.filter ↔ ∃ i, p i ∧ s i ⊆ U := by
simp only [IsBasis.filter, FilterBasis.mem_filter_iff, mem_filterBasis_iff,
exists_exists_and_eq_and]
theorem filter_eq_generate (h : IsBasis p s) : h.filter = generate { U | ∃ i, p i ∧ s i = U } := by
erw [h.filterBasis.generate]; rfl
end IsBasis
-- Porting note: was `protected` in Lean 3 but `protected` didn't work; removed
/-- We say that a filter `l` has a basis `s : ι → Set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`. -/
structure HasBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α) : Prop where
/-- A set `t` belongs to a filter `l` iff it includes an element of the basis. -/
mem_iff' : ∀ t : Set α, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t
section SameType
variable {l l' : Filter α} {p : ι → Prop} {s : ι → Set α} {t : Set α} {i : ι} {p' : ι' → Prop}
{s' : ι' → Set α} {i' : ι'}
theorem hasBasis_generate (s : Set (Set α)) :
(generate s).HasBasis (fun t => Set.Finite t ∧ t ⊆ s) fun t => ⋂₀ t :=
⟨fun U => by simp only [mem_generate_iff, exists_prop, and_assoc, and_left_comm]⟩
/-- The smallest filter basis containing a given collection of sets. -/
def FilterBasis.ofSets (s : Set (Set α)) : FilterBasis α where
sets := sInter '' { t | Set.Finite t ∧ t ⊆ s }
nonempty := ⟨univ, ∅, ⟨⟨finite_empty, empty_subset s⟩, sInter_empty⟩⟩
inter_sets := by
rintro _ _ ⟨a, ⟨fina, suba⟩, rfl⟩ ⟨b, ⟨finb, subb⟩, rfl⟩
exact ⟨⋂₀ (a ∪ b), mem_image_of_mem _ ⟨fina.union finb, union_subset suba subb⟩,
(sInter_union _ _).subset⟩
lemma FilterBasis.ofSets_sets (s : Set (Set α)) :
(FilterBasis.ofSets s).sets = sInter '' { t | Set.Finite t ∧ t ⊆ s } :=
rfl
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
/-- Definition of `HasBasis` unfolded with implicit set argument. -/
theorem HasBasis.mem_iff (hl : l.HasBasis p s) : t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
hl.mem_iff' t
theorem HasBasis.eq_of_same_basis (hl : l.HasBasis p s) (hl' : l'.HasBasis p s) : l = l' := by
ext t
rw [hl.mem_iff, hl'.mem_iff]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem hasBasis_iff : l.HasBasis p s ↔ ∀ t, t ∈ l ↔ ∃ i, p i ∧ s i ⊆ t :=
⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩
theorem HasBasis.ex_mem (h : l.HasBasis p s) : ∃ i, p i :=
(h.mem_iff.mp univ_mem).imp fun _ => And.left
protected theorem HasBasis.nonempty (h : l.HasBasis p s) : Nonempty ι :=
nonempty_of_exists h.ex_mem
protected theorem IsBasis.hasBasis (h : IsBasis p s) : HasBasis h.filter p s :=
⟨fun t => by simp only [h.mem_filter_iff, exists_prop]⟩
protected theorem HasBasis.mem_of_superset (hl : l.HasBasis p s) (hi : p i) (ht : s i ⊆ t) :
t ∈ l :=
hl.mem_iff.2 ⟨i, hi, ht⟩
theorem HasBasis.mem_of_mem (hl : l.HasBasis p s) (hi : p i) : s i ∈ l :=
hl.mem_of_superset hi Subset.rfl
/-- Index of a basis set such that `s i ⊆ t` as an element of `Subtype p`. -/
noncomputable def HasBasis.index (h : l.HasBasis p s) (t : Set α) (ht : t ∈ l) : { i : ι // p i } :=
⟨(h.mem_iff.1 ht).choose, (h.mem_iff.1 ht).choose_spec.1⟩
theorem HasBasis.property_index (h : l.HasBasis p s) (ht : t ∈ l) : p (h.index t ht) :=
(h.index t ht).2
theorem HasBasis.set_index_mem (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ∈ l :=
h.mem_of_mem <| h.property_index _
theorem HasBasis.set_index_subset (h : l.HasBasis p s) (ht : t ∈ l) : s (h.index t ht) ⊆ t :=
(h.mem_iff.1 ht).choose_spec.2
theorem HasBasis.isBasis (h : l.HasBasis p s) : IsBasis p s where
nonempty := h.ex_mem
inter hi hj := by
simpa only [h.mem_iff] using inter_mem (h.mem_of_mem hi) (h.mem_of_mem hj)
theorem HasBasis.filter_eq (h : l.HasBasis p s) : h.isBasis.filter = l := by
ext U
simp [h.mem_iff, IsBasis.mem_filter_iff]
theorem HasBasis.eq_generate (h : l.HasBasis p s) : l = generate { U | ∃ i, p i ∧ s i = U } := by
rw [← h.isBasis.filter_eq_generate, h.filter_eq]
theorem generate_eq_generate_inter (s : Set (Set α)) :
generate s = generate (sInter '' { t | Set.Finite t ∧ t ⊆ s }) := by
rw [← FilterBasis.ofSets_sets, FilterBasis.generate, ← (hasBasis_generate s).filter_eq]; rfl
theorem ofSets_filter_eq_generate (s : Set (Set α)) :
(FilterBasis.ofSets s).filter = generate s := by
rw [← (FilterBasis.ofSets s).generate, FilterBasis.ofSets_sets, ← generate_eq_generate_inter]
protected theorem _root_.FilterBasis.hasBasis (B : FilterBasis α) :
HasBasis B.filter (fun s : Set α => s ∈ B) id :=
⟨fun _ => B.mem_filter_iff⟩
theorem HasBasis.to_hasBasis' (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → s' i' ∈ l) : l.HasBasis p' s' := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i', hi', ht⟩ => mem_of_superset (h' i' hi') ht⟩⟩
rcases hl.mem_iff.1 ht with ⟨i, hi, ht⟩
rcases h i hi with ⟨i', hi', hs's⟩
exact ⟨i', hi', hs's.trans ht⟩
theorem HasBasis.to_hasBasis (hl : l.HasBasis p s) (h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i)
(h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') : l.HasBasis p' s' :=
hl.to_hasBasis' h fun i' hi' =>
let ⟨i, hi, hss'⟩ := h' i' hi'
hl.mem_iff.2 ⟨i, hi, hss'⟩
protected lemma HasBasis.congr (hl : l.HasBasis p s) {p' s'} (hp : ∀ i, p i ↔ p' i)
(hs : ∀ i, p i → s i = s' i) : l.HasBasis p' s' :=
⟨fun t ↦ by simp only [hl.mem_iff, ← hp]; exact exists_congr fun i ↦
and_congr_right fun hi ↦ hs i hi ▸ Iff.rfl⟩
theorem HasBasis.to_subset (hl : l.HasBasis p s) {t : ι → Set α} (h : ∀ i, p i → t i ⊆ s i)
(ht : ∀ i, p i → t i ∈ l) : l.HasBasis p t :=
hl.to_hasBasis' (fun i hi => ⟨i, hi, h i hi⟩) ht
theorem HasBasis.eventually_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∀ᶠ x in l, q x) ↔ ∃ i, p i ∧ ∀ ⦃x⦄, x ∈ s i → q x := by simpa using hl.mem_iff
theorem HasBasis.frequently_iff (hl : l.HasBasis p s) {q : α → Prop} :
(∃ᶠ x in l, q x) ↔ ∀ i, p i → ∃ x ∈ s i, q x := by
simp only [Filter.Frequently, hl.eventually_iff]; push_neg; rfl
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.exists_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P t → P s) : (∃ s ∈ l, P s) ↔ ∃ i, p i ∧ P (s i) :=
⟨fun ⟨_s, hs, hP⟩ =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
⟨i, hi, mono his hP⟩,
fun ⟨i, hi, hP⟩ => ⟨s i, hl.mem_of_mem hi, hP⟩⟩
theorem HasBasis.forall_iff (hl : l.HasBasis p s) {P : Set α → Prop}
(mono : ∀ ⦃s t⦄, s ⊆ t → P s → P t) : (∀ s ∈ l, P s) ↔ ∀ i, p i → P (s i) :=
⟨fun H i hi => H (s i) <| hl.mem_of_mem hi, fun H _s hs =>
let ⟨i, hi, his⟩ := hl.mem_iff.1 hs
mono his (H i hi)⟩
protected theorem HasBasis.neBot_iff (hl : l.HasBasis p s) :
NeBot l ↔ ∀ {i}, p i → (s i).Nonempty :=
forall_mem_nonempty_iff_neBot.symm.trans <| hl.forall_iff fun _ _ => Nonempty.mono
theorem HasBasis.eq_bot_iff (hl : l.HasBasis p s) : l = ⊥ ↔ ∃ i, p i ∧ s i = ∅ :=
not_iff_not.1 <| neBot_iff.symm.trans <|
hl.neBot_iff.trans <| by simp only [not_exists, not_and, nonempty_iff_ne_empty]
theorem generate_neBot_iff {s : Set (Set α)} :
NeBot (generate s) ↔ ∀ t, t ⊆ s → t.Finite → (⋂₀ t).Nonempty :=
(hasBasis_generate s).neBot_iff.trans <| by simp only [← and_imp, and_comm]
theorem basis_sets (l : Filter α) : l.HasBasis (fun s : Set α => s ∈ l) id :=
⟨fun _ => exists_mem_subset_iff.symm⟩
theorem asBasis_filter (f : Filter α) : f.asBasis.filter = f :=
Filter.ext fun _ => exists_mem_subset_iff
theorem hasBasis_self {l : Filter α} {P : Set α → Prop} :
HasBasis l (fun s => s ∈ l ∧ P s) id ↔ ∀ t ∈ l, ∃ r ∈ l, P r ∧ r ⊆ t := by
simp only [hasBasis_iff, id, and_assoc]
exact forall_congr' fun s =>
⟨fun h => h.1, fun h => ⟨h, fun ⟨t, hl, _, hts⟩ => mem_of_superset hl hts⟩⟩
theorem HasBasis.comp_surjective (h : l.HasBasis p s) {g : ι' → ι} (hg : Function.Surjective g) :
l.HasBasis (p ∘ g) (s ∘ g) :=
⟨fun _ => h.mem_iff.trans hg.exists⟩
theorem HasBasis.comp_equiv (h : l.HasBasis p s) (e : ι' ≃ ι) : l.HasBasis (p ∘ e) (s ∘ e) :=
h.comp_surjective e.surjective
theorem HasBasis.to_image_id' (h : l.HasBasis p s) : l.HasBasis (fun t ↦ ∃ i, p i ∧ s i = t) id :=
⟨fun _ ↦ by simp [h.mem_iff]⟩
theorem HasBasis.to_image_id {ι : Type*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) :
l.HasBasis (· ∈ s '' {i | p i}) id :=
h.to_image_id'
/-- If `{s i | p i}` is a basis of a filter `l` and each `s i` includes `s j` such that
`p j ∧ q j`, then `{s j | p j ∧ q j}` is a basis of `l`. -/
theorem HasBasis.restrict (h : l.HasBasis p s) {q : ι → Prop}
(hq : ∀ i, p i → ∃ j, p j ∧ q j ∧ s j ⊆ s i) : l.HasBasis (fun i => p i ∧ q i) s := by
refine ⟨fun t => ⟨fun ht => ?_, fun ⟨i, hpi, hti⟩ => h.mem_iff.2 ⟨i, hpi.1, hti⟩⟩⟩
rcases h.mem_iff.1 ht with ⟨i, hpi, hti⟩
rcases hq i hpi with ⟨j, hpj, hqj, hji⟩
exact ⟨j, ⟨hpj, hqj⟩, hji.trans hti⟩
/-- If `{s i | p i}` is a basis of a filter `l` and `V ∈ l`, then `{s i | p i ∧ s i ⊆ V}`
is a basis of `l`. -/
theorem HasBasis.restrict_subset (h : l.HasBasis p s) {V : Set α} (hV : V ∈ l) :
l.HasBasis (fun i => p i ∧ s i ⊆ V) s :=
h.restrict fun _i hi => (h.mem_iff.1 (inter_mem hV (h.mem_of_mem hi))).imp fun _j hj =>
⟨hj.1, subset_inter_iff.1 hj.2⟩
theorem HasBasis.hasBasis_self_subset {p : Set α → Prop} (h : l.HasBasis (fun s => s ∈ l ∧ p s) id)
{V : Set α} (hV : V ∈ l) : l.HasBasis (fun s => s ∈ l ∧ p s ∧ s ⊆ V) id := by
simpa only [and_assoc] using h.restrict_subset hV
theorem HasBasis.ge_iff (hl' : l'.HasBasis p' s') : l ≤ l' ↔ ∀ i', p' i' → s' i' ∈ l :=
⟨fun h _i' hi' => h <| hl'.mem_of_mem hi', fun h _s hs =>
let ⟨_i', hi', hs⟩ := hl'.mem_iff.1 hs
mem_of_superset (h _ hi') hs⟩
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_iff (hl : l.HasBasis p s) : l ≤ l' ↔ ∀ t ∈ l', ∃ i, p i ∧ s i ⊆ t := by
simp only [le_def, hl.mem_iff]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.le_basis_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
l ≤ l' ↔ ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i' := by
simp only [hl'.ge_iff, hl.mem_iff]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.ext (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s')
(h : ∀ i, p i → ∃ i', p' i' ∧ s' i' ⊆ s i) (h' : ∀ i', p' i' → ∃ i, p i ∧ s i ⊆ s' i') :
l = l' := by
apply le_antisymm
· rw [hl.le_basis_iff hl']
simpa using h'
· rw [hl'.le_basis_iff hl]
simpa using h
theorem HasBasis.inf' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
⟨by
intro t
constructor
· simp only [mem_inf_iff, hl.mem_iff, hl'.mem_iff]
rintro ⟨t, ⟨i, hi, ht⟩, t', ⟨i', hi', ht'⟩, rfl⟩
exact ⟨⟨i, i'⟩, ⟨hi, hi'⟩, inter_subset_inter ht ht'⟩
· rintro ⟨⟨i, i'⟩, ⟨hi, hi'⟩, H⟩
exact mem_inf_of_inter (hl.mem_of_mem hi) (hl'.mem_of_mem hi') H⟩
theorem HasBasis.inf {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊓ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∩ s' i.2 :=
(hl.inf' hl').comp_equiv Equiv.pprodEquivProd.symm
theorem hasBasis_iInf' {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i))
fun If : Set ι × ∀ i, ι' i => ⋂ i ∈ If.1, s i (If.2 i) :=
⟨by
intro t
constructor
· simp only [mem_iInf', (hl _).mem_iff]
rintro ⟨I, hI, V, hV, -, rfl, -⟩
choose u hu using hV
exact ⟨⟨I, u⟩, ⟨hI, fun i _ => (hu i).1⟩, iInter₂_mono fun i _ => (hu i).2⟩
· rintro ⟨⟨I, f⟩, ⟨hI₁, hI₂⟩, hsub⟩
refine mem_of_superset ?_ hsub
exact (biInter_mem hI₁).mpr fun i hi => mem_iInf_of_mem i <| (hl i).mem_of_mem <| hI₂ _ hi⟩
theorem hasBasis_iInf {ι : Type*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨅ i, l i).HasBasis
(fun If : Σ I : Set ι, ∀ i : I, ι' i => If.1.Finite ∧ ∀ i : If.1, p i (If.2 i)) fun If =>
⋂ i : If.1, s i (If.2 i) := by
refine ⟨fun t => ⟨fun ht => ?_, ?_⟩⟩
· rcases (hasBasis_iInf' hl).mem_iff.mp ht with ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
exact ⟨⟨I, fun i => f i⟩, ⟨hI, Subtype.forall.mpr hf⟩, trans (iInter_subtype _ _) hsub⟩
· rintro ⟨⟨I, f⟩, ⟨hI, hf⟩, hsub⟩
refine mem_of_superset ?_ hsub
cases hI.nonempty_fintype
exact iInter_mem.2 fun i => mem_iInf_of_mem ↑i <| (hl i).mem_of_mem <| hf _
theorem hasBasis_iInf_of_directed' {ι : Type*} {ι' : ι → Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : Σi, ι' i => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Sigma.exists]
exact exists_congr fun i => (hl i).mem_iff
theorem hasBasis_iInf_of_directed {ι : Type*} {ι' : Sort _} [Nonempty ι] {l : ι → Filter α}
(s : ι → ι' → Set α) (p : ι → ι' → Prop) (hl : ∀ i, (l i).HasBasis (p i) (s i))
(h : Directed (· ≥ ·) l) :
(⨅ i, l i).HasBasis (fun ii' : ι × ι' => p ii'.1 ii'.2) fun ii' => s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_iInf_of_directed h, Prod.exists]
exact exists_congr fun i => (hl i).mem_iff
theorem hasBasis_biInf_of_directed' {ι : Type*} {ι' : ι → Sort _} {dom : Set ι}
(hdom : dom.Nonempty) {l : ι → Filter α} (s : ∀ i, ι' i → Set α) (p : ∀ i, ι' i → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : Σi, ι' i => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Sigma.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
theorem hasBasis_biInf_of_directed {ι : Type*} {ι' : Sort _} {dom : Set ι} (hdom : dom.Nonempty)
{l : ι → Filter α} (s : ι → ι' → Set α) (p : ι → ι' → Prop)
(hl : ∀ i ∈ dom, (l i).HasBasis (p i) (s i)) (h : DirectedOn (l ⁻¹'o GE.ge) dom) :
(⨅ i ∈ dom, l i).HasBasis (fun ii' : ι × ι' => ii'.1 ∈ dom ∧ p ii'.1 ii'.2) fun ii' =>
s ii'.1 ii'.2 := by
refine ⟨fun t => ?_⟩
rw [mem_biInf_of_directed h hdom, Prod.exists]
refine exists_congr fun i => ⟨?_, ?_⟩
· rintro ⟨hi, hti⟩
rcases (hl i hi).mem_iff.mp hti with ⟨b, hb, hbt⟩
exact ⟨b, ⟨hi, hb⟩, hbt⟩
· rintro ⟨b, ⟨hi, hb⟩, hibt⟩
exact ⟨hi, (hl i hi).mem_iff.mpr ⟨b, hb, hibt⟩⟩
theorem hasBasis_principal (t : Set α) : (𝓟 t).HasBasis (fun _ : Unit => True) fun _ => t :=
⟨fun U => by simp⟩
theorem hasBasis_pure (x : α) :
(pure x : Filter α).HasBasis (fun _ : Unit => True) fun _ => {x} := by
simp only [← principal_singleton, hasBasis_principal]
theorem HasBasis.sup' (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : PProd ι ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
⟨by
intro t
simp_rw [mem_sup, hl.mem_iff, hl'.mem_iff, PProd.exists, union_subset_iff,
← exists_and_right, ← exists_and_left]
simp only [and_assoc, and_left_comm]⟩
theorem HasBasis.sup {ι ι' : Type*} {p : ι → Prop} {s : ι → Set α} {p' : ι' → Prop}
{s' : ι' → Set α} (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
(l ⊔ l').HasBasis (fun i : ι × ι' => p i.1 ∧ p' i.2) fun i => s i.1 ∪ s' i.2 :=
(hl.sup' hl').comp_equiv Equiv.pprodEquivProd.symm
theorem hasBasis_iSup {ι : Sort*} {ι' : ι → Type*} {l : ι → Filter α} {p : ∀ i, ι' i → Prop}
{s : ∀ i, ι' i → Set α} (hl : ∀ i, (l i).HasBasis (p i) (s i)) :
(⨆ i, l i).HasBasis (fun f : ∀ i, ι' i => ∀ i, p i (f i)) fun f : ∀ i, ι' i => ⋃ i, s i (f i) :=
hasBasis_iff.mpr fun t => by
simp only [hasBasis_iff, (hl _).mem_iff, Classical.skolem, forall_and, iUnion_subset_iff,
mem_iSup]
theorem HasBasis.sup_principal (hl : l.HasBasis p s) (t : Set α) :
(l ⊔ 𝓟 t).HasBasis p fun i => s i ∪ t :=
⟨fun u => by
simp only [(hl.sup' (hasBasis_principal t)).mem_iff, PProd.exists, exists_prop, and_true_iff,
Unique.exists_iff]⟩
theorem HasBasis.sup_pure (hl : l.HasBasis p s) (x : α) :
(l ⊔ pure x).HasBasis p fun i => s i ∪ {x} := by
simp only [← principal_singleton, hl.sup_principal]
theorem HasBasis.inf_principal (hl : l.HasBasis p s) (s' : Set α) :
(l ⊓ 𝓟 s').HasBasis p fun i => s i ∩ s' :=
⟨fun t => by
simp only [mem_inf_principal, hl.mem_iff, subset_def, mem_setOf_eq, mem_inter_iff, and_imp]⟩
theorem HasBasis.principal_inf (hl : l.HasBasis p s) (s' : Set α) :
(𝓟 s' ⊓ l).HasBasis p fun i => s' ∩ s i := by
simpa only [inf_comm, inter_comm] using hl.inf_principal s'
theorem HasBasis.inf_basis_neBot_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃i'⦄, p' i' → (s i ∩ s' i').Nonempty :=
(hl.inf' hl').neBot_iff.trans <| by simp [@forall_swap _ ι']
theorem HasBasis.inf_neBot_iff (hl : l.HasBasis p s) :
NeBot (l ⊓ l') ↔ ∀ ⦃i⦄, p i → ∀ ⦃s'⦄, s' ∈ l' → (s i ∩ s').Nonempty :=
hl.inf_basis_neBot_iff l'.basis_sets
theorem HasBasis.inf_principal_neBot_iff (hl : l.HasBasis p s) {t : Set α} :
NeBot (l ⊓ 𝓟 t) ↔ ∀ ⦃i⦄, p i → (s i ∩ t).Nonempty :=
(hl.inf_principal t).neBot_iff
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff (hl : l.HasBasis p s) (hl' : l'.HasBasis p' s') :
Disjoint l l' ↔ ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
not_iff_not.mp <| by simp only [_root_.disjoint_iff, ← Ne.eq_def, ← neBot_iff, inf_eq_inter,
hl.inf_basis_neBot_iff hl', not_exists, not_and, bot_eq_empty, ← nonempty_iff_ne_empty]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem _root_.Disjoint.exists_mem_filter_basis (h : Disjoint l l') (hl : l.HasBasis p s)
(hl' : l'.HasBasis p' s') : ∃ i, p i ∧ ∃ i', p' i' ∧ Disjoint (s i) (s' i') :=
(hl.disjoint_iff hl').1 h
theorem _root_.Pairwise.exists_mem_filter_basis_of_disjoint {I} [Finite I] {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} (hd : Pairwise (Disjoint on l))
(h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ Pairwise (Disjoint on fun i => s i (ind i)) := by
rcases hd.exists_mem_filter_of_disjoint with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono fun i j hij => hij.mono (ht _) (ht _)⟩
theorem _root_.Set.PairwiseDisjoint.exists_mem_filter_basis {I : Type*} {l : I → Filter α}
{ι : I → Sort*} {p : ∀ i, ι i → Prop} {s : ∀ i, ι i → Set α} {S : Set I}
(hd : S.PairwiseDisjoint l) (hS : S.Finite) (h : ∀ i, (l i).HasBasis (p i) (s i)) :
∃ ind : ∀ i, ι i, (∀ i, p i (ind i)) ∧ S.PairwiseDisjoint fun i => s i (ind i) := by
rcases hd.exists_mem_filter hS with ⟨t, htl, hd⟩
choose ind hp ht using fun i => (h i).mem_iff.1 (htl i)
exact ⟨ind, hp, hd.mono ht⟩
theorem inf_neBot_iff :
NeBot (l ⊓ l') ↔ ∀ ⦃s : Set α⦄, s ∈ l → ∀ ⦃s'⦄, s' ∈ l' → (s ∩ s').Nonempty :=
l.basis_sets.inf_neBot_iff
theorem inf_principal_neBot_iff {s : Set α} : NeBot (l ⊓ 𝓟 s) ↔ ∀ U ∈ l, (U ∩ s).Nonempty :=
l.basis_sets.inf_principal_neBot_iff
theorem mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∈ f ↔ f ⊓ 𝓟 sᶜ = ⊥ := by
refine not_iff_not.1 ((inf_principal_neBot_iff.trans ?_).symm.trans neBot_iff)
exact
⟨fun h hs => by simpa [Set.not_nonempty_empty] using h s hs, fun hs t ht =>
inter_compl_nonempty_iff.2 fun hts => hs <| mem_of_superset ht hts⟩
theorem not_mem_iff_inf_principal_compl {f : Filter α} {s : Set α} : s ∉ f ↔ NeBot (f ⊓ 𝓟 sᶜ) :=
(not_congr mem_iff_inf_principal_compl).trans neBot_iff.symm
@[simp]
theorem disjoint_principal_right {f : Filter α} {s : Set α} : Disjoint f (𝓟 s) ↔ sᶜ ∈ f := by
rw [mem_iff_inf_principal_compl, compl_compl, disjoint_iff]
@[simp]
theorem disjoint_principal_left {f : Filter α} {s : Set α} : Disjoint (𝓟 s) f ↔ sᶜ ∈ f := by
rw [disjoint_comm, disjoint_principal_right]
@[simp 1100] -- Porting note: higher priority for linter
theorem disjoint_principal_principal {s t : Set α} : Disjoint (𝓟 s) (𝓟 t) ↔ Disjoint s t := by
rw [← subset_compl_iff_disjoint_left, disjoint_principal_left, mem_principal]
alias ⟨_, _root_.Disjoint.filter_principal⟩ := disjoint_principal_principal
@[simp]
theorem disjoint_pure_pure {x y : α} : Disjoint (pure x : Filter α) (pure y) ↔ x ≠ y := by
simp only [← principal_singleton, disjoint_principal_principal, disjoint_singleton]
@[simp]
theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by
simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_left (h : l.HasBasis p s) :
Disjoint l l' ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' := by
simp only [h.disjoint_iff l'.basis_sets, id, ← disjoint_principal_left,
(hasBasis_principal _).disjoint_iff l'.basis_sets, true_and, Unique.exists_iff]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.disjoint_iff_right (h : l.HasBasis p s) :
Disjoint l' l ↔ ∃ i, p i ∧ (s i)ᶜ ∈ l' :=
disjoint_comm.trans h.disjoint_iff_left
theorem le_iff_forall_inf_principal_compl {f g : Filter α} : f ≤ g ↔ ∀ V ∈ g, f ⊓ 𝓟 Vᶜ = ⊥ :=
forall₂_congr fun _ _ => mem_iff_inf_principal_compl
theorem inf_neBot_iff_frequently_left {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in f, p x) → ∃ᶠ x in g, p x := by
simp only [inf_neBot_iff, frequently_iff, and_comm]; rfl
theorem inf_neBot_iff_frequently_right {f g : Filter α} :
NeBot (f ⊓ g) ↔ ∀ {p : α → Prop}, (∀ᶠ x in g, p x) → ∃ᶠ x in f, p x := by
rw [inf_comm]
exact inf_neBot_iff_frequently_left
theorem HasBasis.eq_biInf (h : l.HasBasis p s) : l = ⨅ (i) (_ : p i), 𝓟 (s i) :=
eq_biInf_of_mem_iff_exists_mem fun {_} => by simp only [h.mem_iff, mem_principal, exists_prop]
theorem HasBasis.eq_iInf (h : l.HasBasis (fun _ => True) s) : l = ⨅ i, 𝓟 (s i) := by
simpa only [iInf_true] using h.eq_biInf
theorem hasBasis_iInf_principal {s : ι → Set α} (h : Directed (· ≥ ·) s) [Nonempty ι] :
(⨅ i, 𝓟 (s i)).HasBasis (fun _ => True) s :=
⟨fun t => by
simpa only [true_and] using mem_iInf_of_directed (h.mono_comp monotone_principal.dual) t⟩
/-- If `s : ι → Set α` is an indexed family of sets, then finite intersections of `s i` form a basis
of `⨅ i, 𝓟 (s i)`. -/
theorem hasBasis_iInf_principal_finite {ι : Type*} (s : ι → Set α) :
(⨅ i, 𝓟 (s i)).HasBasis (fun t : Set ι => t.Finite) fun t => ⋂ i ∈ t, s i := by
refine ⟨fun U => (mem_iInf_finite _).trans ?_⟩
simp only [iInf_principal_finset, mem_iUnion, mem_principal, exists_prop,
exists_finite_iff_finset, Finset.set_biInter_coe]
theorem hasBasis_biInf_principal {s : β → Set α} {S : Set β} (h : DirectedOn (s ⁻¹'o (· ≥ ·)) S)
(ne : S.Nonempty) : (⨅ i ∈ S, 𝓟 (s i)).HasBasis (fun i => i ∈ S) s :=
⟨fun t => by
refine mem_biInf_of_directed ?_ ne
rw [directedOn_iff_directed, ← directed_comp] at h ⊢
refine h.mono_comp ?_
exact fun _ _ => principal_mono.2⟩
theorem hasBasis_biInf_principal' {ι : Type*} {p : ι → Prop} {s : ι → Set α}
(h : ∀ i, p i → ∀ j, p j → ∃ k, p k ∧ s k ⊆ s i ∧ s k ⊆ s j) (ne : ∃ i, p i) :
(⨅ (i) (_ : p i), 𝓟 (s i)).HasBasis p s :=
Filter.hasBasis_biInf_principal h ne
theorem HasBasis.map (f : α → β) (hl : l.HasBasis p s) : (l.map f).HasBasis p fun i => f '' s i :=
⟨fun t => by simp only [mem_map, image_subset_iff, hl.mem_iff, preimage]⟩
theorem HasBasis.comap (f : β → α) (hl : l.HasBasis p s) :
(l.comap f).HasBasis p fun i => f ⁻¹' s i :=
⟨fun t => by
simp only [mem_comap', hl.mem_iff]
refine exists_congr (fun i => Iff.rfl.and ?_)
exact ⟨fun h x hx => h hx rfl, fun h y hy x hx => h <| by rwa [mem_preimage, hx]⟩⟩
theorem comap_hasBasis (f : α → β) (l : Filter β) :
HasBasis (comap f l) (fun s : Set β => s ∈ l) fun s => f ⁻¹' s :=
⟨fun _ => mem_comap⟩
theorem HasBasis.forall_mem_mem (h : HasBasis l p s) {x : α} :
(∀ t ∈ l, x ∈ t) ↔ ∀ i, p i → x ∈ s i := by
simp only [h.mem_iff, exists_imp, and_imp]
exact ⟨fun h i hi => h (s i) i hi Subset.rfl, fun h t i hi ht => ht (h i hi)⟩
protected theorem HasBasis.biInf_mem [CompleteLattice β] {f : Set α → β} (h : HasBasis l p s)
(hf : Monotone f) : ⨅ t ∈ l, f t = ⨅ (i) (_ : p i), f (s i) :=
le_antisymm (le_iInf₂ fun i hi => iInf₂_le (s i) (h.mem_of_mem hi)) <|
le_iInf₂ fun _t ht =>
let ⟨i, hpi, hi⟩ := h.mem_iff.1 ht
iInf₂_le_of_le i hpi (hf hi)
protected theorem HasBasis.biInter_mem {f : Set α → Set β} (h : HasBasis l p s) (hf : Monotone f) :
⋂ t ∈ l, f t = ⋂ (i) (_ : p i), f (s i) :=
h.biInf_mem hf
protected theorem HasBasis.ker (h : HasBasis l p s) : l.ker = ⋂ (i) (_ : p i), s i :=
l.ker_def.trans <| h.biInter_mem monotone_id
variable {ι'' : Type*} [Preorder ι''] (l) (s'' : ι'' → Set α)
/-- `IsAntitoneBasis s` means the image of `s` is a filter basis such that `s` is decreasing. -/
structure IsAntitoneBasis extends IsBasis (fun _ => True) s'' : Prop where
/-- The sequence of sets is antitone. -/
protected antitone : Antitone s''
/-- We say that a filter `l` has an antitone basis `s : ι → Set α`, if `t ∈ l` if and only if `t`
includes `s i` for some `i`, and `s` is decreasing. -/
structure HasAntitoneBasis (l : Filter α) (s : ι'' → Set α)
extends HasBasis l (fun _ => True) s : Prop where
/-- The sequence of sets is antitone. -/
protected antitone : Antitone s
protected theorem HasAntitoneBasis.map {l : Filter α} {s : ι'' → Set α}
(hf : HasAntitoneBasis l s) (m : α → β) : HasAntitoneBasis (map m l) (m '' s ·) :=
⟨HasBasis.map _ hf.toHasBasis, fun _ _ h => image_subset _ <| hf.2 h⟩
protected theorem HasAntitoneBasis.comap {l : Filter α} {s : ι'' → Set α}
(hf : HasAntitoneBasis l s) (m : β → α) : HasAntitoneBasis (comap m l) (m ⁻¹' s ·) :=
⟨hf.1.comap _, fun _ _ h ↦ preimage_mono (hf.2 h)⟩
lemma HasAntitoneBasis.iInf_principal {ι : Type*} [Preorder ι] [Nonempty ι] [IsDirected ι (· ≤ ·)]
{s : ι → Set α} (hs : Antitone s) : (⨅ i, 𝓟 (s i)).HasAntitoneBasis s :=
⟨hasBasis_iInf_principal hs.directed_ge, hs⟩
end SameType
section TwoTypes
variable {la : Filter α} {pa : ι → Prop} {sa : ι → Set α} {lb : Filter β} {pb : ι' → Prop}
{sb : ι' → Set β} {f : α → β}
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.tendsto_left_iff (hla : la.HasBasis pa sa) :
Tendsto f la lb ↔ ∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t := by
simp only [Tendsto, (hla.map f).le_iff, image_subset_iff]
rfl
theorem HasBasis.tendsto_right_iff (hlb : lb.HasBasis pb sb) :
Tendsto f la lb ↔ ∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i := by
simp only [Tendsto, hlb.ge_iff, mem_map', Filter.Eventually]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem HasBasis.tendsto_iff (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
Tendsto f la lb ↔ ∀ ib, pb ib → ∃ ia, pa ia ∧ ∀ x ∈ sa ia, f x ∈ sb ib := by
simp [hlb.tendsto_right_iff, hla.eventually_iff]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem Tendsto.basis_left (H : Tendsto f la lb) (hla : la.HasBasis pa sa) :
∀ t ∈ lb, ∃ i, pa i ∧ MapsTo f (sa i) t :=
hla.tendsto_left_iff.1 H
theorem Tendsto.basis_right (H : Tendsto f la lb) (hlb : lb.HasBasis pb sb) :
∀ i, pb i → ∀ᶠ x in la, f x ∈ sb i :=
hlb.tendsto_right_iff.1 H
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`.
theorem Tendsto.basis_both (H : Tendsto f la lb) (hla : la.HasBasis pa sa)
(hlb : lb.HasBasis pb sb) :
∀ ib, pb ib → ∃ ia, pa ia ∧ MapsTo f (sa ia) (sb ib) :=
(hla.tendsto_iff hlb).1 H
theorem HasBasis.prod_pprod (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la ×ˢ lb).HasBasis (fun i : PProd ι ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 :=
(hla.comap Prod.fst).inf' (hlb.comap Prod.snd)
theorem HasBasis.prod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop}
{sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la ×ˢ lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i => sa i.1 ×ˢ sb i.2 :=
(hla.comap Prod.fst).inf (hlb.comap Prod.snd)
theorem HasBasis.prod_same_index {p : ι → Prop} {sb : ι → Set β} (hla : la.HasBasis p sa)
(hlb : lb.HasBasis p sb) (h_dir : ∀ {i j}, p i → p j → ∃ k, p k ∧ sa k ⊆ sa i ∧ sb k ⊆ sb j) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i := by
simp only [hasBasis_iff, (hla.prod_pprod hlb).mem_iff]
refine fun t => ⟨?_, ?_⟩
· rintro ⟨⟨i, j⟩, ⟨hi, hj⟩, hsub : sa i ×ˢ sb j ⊆ t⟩
rcases h_dir hi hj with ⟨k, hk, ki, kj⟩
exact ⟨k, hk, (Set.prod_mono ki kj).trans hsub⟩
· rintro ⟨i, hi, h⟩
exact ⟨⟨i, i⟩, ⟨hi, hi⟩, h⟩
theorem HasBasis.prod_same_index_mono {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α}
{sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb)
(hsa : MonotoneOn sa { i | p i }) (hsb : MonotoneOn sb { i | p i }) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i :=
hla.prod_same_index hlb fun {i j} hi hj =>
have : p (min i j) := min_rec' _ hi hj
⟨min i j, this, hsa this hi <| min_le_left _ _, hsb this hj <| min_le_right _ _⟩
theorem HasBasis.prod_same_index_anti {ι : Type*} [LinearOrder ι] {p : ι → Prop} {sa : ι → Set α}
{sb : ι → Set β} (hla : la.HasBasis p sa) (hlb : lb.HasBasis p sb)
(hsa : AntitoneOn sa { i | p i }) (hsb : AntitoneOn sb { i | p i }) :
(la ×ˢ lb).HasBasis p fun i => sa i ×ˢ sb i :=
@HasBasis.prod_same_index_mono _ _ _ _ ιᵒᵈ _ _ _ _ hla hlb hsa.dual_left hsb.dual_left
theorem HasBasis.prod_self (hl : la.HasBasis pa sa) :
(la ×ˢ la).HasBasis pa fun i => sa i ×ˢ sa i :=
hl.prod_same_index hl fun {i j} hi hj => by
simpa only [exists_prop, subset_inter_iff] using
hl.mem_iff.1 (inter_mem (hl.mem_of_mem hi) (hl.mem_of_mem hj))
theorem mem_prod_self_iff {s} : s ∈ la ×ˢ la ↔ ∃ t ∈ la, t ×ˢ t ⊆ s :=
la.basis_sets.prod_self.mem_iff
lemma eventually_prod_self_iff {r : α → α → Prop} :
(∀ᶠ x in la ×ˢ la, r x.1 x.2) ↔ ∃ t ∈ la, ∀ x ∈ t, ∀ y ∈ t, r x y :=
mem_prod_self_iff.trans <| by simp only [prod_subset_iff, mem_setOf_eq]
theorem HasAntitoneBasis.prod {ι : Type*} [LinearOrder ι] {f : Filter α} {g : Filter β}
{s : ι → Set α} {t : ι → Set β} (hf : HasAntitoneBasis f s) (hg : HasAntitoneBasis g t) :
HasAntitoneBasis (f ×ˢ g) fun n => s n ×ˢ t n :=
⟨hf.1.prod_same_index_anti hg.1 (hf.2.antitoneOn _) (hg.2.antitoneOn _), hf.2.set_prod hg.2⟩
theorem HasBasis.coprod {ι ι' : Type*} {pa : ι → Prop} {sa : ι → Set α} {pb : ι' → Prop}
{sb : ι' → Set β} (hla : la.HasBasis pa sa) (hlb : lb.HasBasis pb sb) :
(la.coprod lb).HasBasis (fun i : ι × ι' => pa i.1 ∧ pb i.2) fun i =>
Prod.fst ⁻¹' sa i.1 ∪ Prod.snd ⁻¹' sb i.2 :=
(hla.comap Prod.fst).sup (hlb.comap Prod.snd)
end TwoTypes
theorem map_sigma_mk_comap {π : α → Type*} {π' : β → Type*} {f : α → β}
(hf : Function.Injective f) (g : ∀ a, π a → π' (f a)) (a : α) (l : Filter (π' (f a))) :
map (Sigma.mk a) (comap (g a) l) = comap (Sigma.map f g) (map (Sigma.mk (f a)) l) := by
refine (((basis_sets _).comap _).map _).eq_of_same_basis ?_
convert ((basis_sets l).map (Sigma.mk (f a))).comap (Sigma.map f g)
apply image_sigmaMk_preimage_sigmaMap hf
end Filter
end sort
namespace Filter
variable {α β γ ι : Type*} {ι' : Sort*}
/-- `IsCountablyGenerated f` means `f = generate s` for some countable `s`. -/
class IsCountablyGenerated (f : Filter α) : Prop where
/-- There exists a countable set that generates the filter. -/
out : ∃ s : Set (Set α), s.Countable ∧ f = generate s
/-- `IsCountableBasis p s` means the image of `s` bounded by `p` is a countable filter basis. -/
structure IsCountableBasis (p : ι → Prop) (s : ι → Set α) extends IsBasis p s : Prop where
/-- The set of `i` that satisfy the predicate `p` is countable. -/
countable : (setOf p).Countable
/-- We say that a filter `l` has a countable basis `s : ι → Set α` bounded by `p : ι → Prop`,
if `t ∈ l` if and only if `t` includes `s i` for some `i` such that `p i`, and the set
defined by `p` is countable. -/
structure HasCountableBasis (l : Filter α) (p : ι → Prop) (s : ι → Set α)
extends HasBasis l p s : Prop where
/-- The set of `i` that satisfy the predicate `p` is countable. -/
countable : (setOf p).Countable
/-- A countable filter basis `B` on a type `α` is a nonempty countable collection of sets of `α`
such that the intersection of two elements of this collection contains some element
of the collection. -/
structure CountableFilterBasis (α : Type*) extends FilterBasis α where
/-- The set of sets of the filter basis is countable. -/
countable : sets.Countable
-- For illustration purposes, the countable filter basis defining `(atTop : Filter ℕ)`
instance Nat.inhabitedCountableFilterBasis : Inhabited (CountableFilterBasis ℕ) :=
⟨⟨default, countable_range fun n => Ici n⟩⟩
theorem HasCountableBasis.isCountablyGenerated {f : Filter α} {p : ι → Prop} {s : ι → Set α}
(h : f.HasCountableBasis p s) : f.IsCountablyGenerated :=
⟨⟨{ t | ∃ i, p i ∧ s i = t }, h.countable.image s, h.toHasBasis.eq_generate⟩⟩
theorem HasBasis.isCountablyGenerated [Countable ι] {f : Filter α} {p : ι → Prop} {s : ι → Set α}
(h : f.HasBasis p s) : f.IsCountablyGenerated :=
HasCountableBasis.isCountablyGenerated ⟨h, to_countable _⟩
theorem antitone_seq_of_seq (s : ℕ → Set α) :
∃ t : ℕ → Set α, Antitone t ∧ ⨅ i, 𝓟 (s i) = ⨅ i, 𝓟 (t i) := by
use fun n => ⋂ m ≤ n, s m; constructor
· exact fun i j hij => biInter_mono (Iic_subset_Iic.2 hij) fun n _ => Subset.rfl
apply le_antisymm <;> rw [le_iInf_iff] <;> intro i
· rw [le_principal_iff]
refine (biInter_mem (finite_le_nat _)).2 fun j _ => ?_
exact mem_iInf_of_mem j (mem_principal_self _)
· refine iInf_le_of_le i (principal_mono.2 <| iInter₂_subset i ?_)
rfl
theorem countable_biInf_eq_iInf_seq [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable)
(Bne : B.Nonempty) (f : ι → α) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) :=
let ⟨g, hg⟩ := Bcbl.exists_eq_range Bne
⟨g, hg.symm ▸ iInf_range⟩
theorem countable_biInf_eq_iInf_seq' [CompleteLattice α] {B : Set ι} (Bcbl : B.Countable)
(f : ι → α) {i₀ : ι} (h : f i₀ = ⊤) : ∃ x : ℕ → ι, ⨅ t ∈ B, f t = ⨅ i, f (x i) := by
rcases B.eq_empty_or_nonempty with hB | Bnonempty
· rw [hB, iInf_emptyset]
use fun _ => i₀
simp [h]
· exact countable_biInf_eq_iInf_seq Bcbl Bnonempty f
theorem countable_biInf_principal_eq_seq_iInf {B : Set (Set α)} (Bcbl : B.Countable) :
∃ x : ℕ → Set α, ⨅ t ∈ B, 𝓟 t = ⨅ i, 𝓟 (x i) :=
countable_biInf_eq_iInf_seq' Bcbl 𝓟 principal_univ
section IsCountablyGenerated
protected theorem HasAntitoneBasis.mem_iff [Preorder ι] {l : Filter α} {s : ι → Set α}
(hs : l.HasAntitoneBasis s) {t : Set α} : t ∈ l ↔ ∃ i, s i ⊆ t :=
hs.toHasBasis.mem_iff.trans <| by simp only [exists_prop, true_and]
protected theorem HasAntitoneBasis.mem [Preorder ι] {l : Filter α} {s : ι → Set α}
(hs : l.HasAntitoneBasis s) (i : ι) : s i ∈ l :=
hs.toHasBasis.mem_of_mem trivial
theorem HasAntitoneBasis.hasBasis_ge [Preorder ι] [IsDirected ι (· ≤ ·)] {l : Filter α}
{s : ι → Set α} (hs : l.HasAntitoneBasis s) (i : ι) : l.HasBasis (fun j => i ≤ j) s :=
hs.1.to_hasBasis (fun j _ => (exists_ge_ge i j).imp fun _k hk => ⟨hk.1, hs.2 hk.2⟩) fun j _ =>
⟨j, trivial, Subset.rfl⟩
/-- If `f` is countably generated and `f.HasBasis p s`, then `f` admits a decreasing basis
enumerated by natural numbers such that all sets have the form `s i`. More precisely, there is a
sequence `i n` such that `p (i n)` for all `n` and `s (i n)` is a decreasing sequence of sets which
forms a basis of `f`-/
theorem HasBasis.exists_antitone_subbasis {f : Filter α} [h : f.IsCountablyGenerated]
{p : ι' → Prop} {s : ι' → Set α} (hs : f.HasBasis p s) :
∃ x : ℕ → ι', (∀ i, p (x i)) ∧ f.HasAntitoneBasis fun i => s (x i) := by
obtain ⟨x', hx'⟩ : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i) := by
rcases h with ⟨s, hsc, rfl⟩
rw [generate_eq_biInf]
exact countable_biInf_principal_eq_seq_iInf hsc
have : ∀ i, x' i ∈ f := fun i => hx'.symm ▸ (iInf_le (fun i => 𝓟 (x' i)) i) (mem_principal_self _)
let x : ℕ → { i : ι' // p i } := fun n =>
Nat.recOn n (hs.index _ <| this 0) fun n xn =>
hs.index _ <| inter_mem (this <| n + 1) (hs.mem_of_mem xn.2)
have x_anti : Antitone fun i => s (x i).1 :=
antitone_nat_of_succ_le fun i => (hs.set_index_subset _).trans inter_subset_right
have x_subset : ∀ i, s (x i).1 ⊆ x' i := by
rintro (_ | i)
exacts [hs.set_index_subset _, (hs.set_index_subset _).trans inter_subset_left]
refine ⟨fun i => (x i).1, fun i => (x i).2, ?_⟩
have : (⨅ i, 𝓟 (s (x i).1)).HasAntitoneBasis fun i => s (x i).1 := .iInf_principal x_anti
convert this
exact
le_antisymm (le_iInf fun i => le_principal_iff.2 <| by cases i <;> apply hs.set_index_mem)
(hx'.symm ▸
le_iInf fun i => le_principal_iff.2 <| this.1.mem_iff.2 ⟨i, trivial, x_subset i⟩)
/-- A countably generated filter admits a basis formed by an antitone sequence of sets. -/
theorem exists_antitone_basis (f : Filter α) [f.IsCountablyGenerated] :
∃ x : ℕ → Set α, f.HasAntitoneBasis x :=
let ⟨x, _, hx⟩ := f.basis_sets.exists_antitone_subbasis
⟨x, hx⟩
theorem exists_antitone_seq (f : Filter α) [f.IsCountablyGenerated] :
∃ x : ℕ → Set α, Antitone x ∧ ∀ {s}, s ∈ f ↔ ∃ i, x i ⊆ s :=
let ⟨x, hx⟩ := f.exists_antitone_basis
⟨x, hx.antitone, by simp [hx.1.mem_iff]⟩
instance Inf.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f]
[IsCountablyGenerated g] : IsCountablyGenerated (f ⊓ g) := by
rcases f.exists_antitone_basis with ⟨s, hs⟩
rcases g.exists_antitone_basis with ⟨t, ht⟩
exact HasCountableBasis.isCountablyGenerated ⟨hs.1.inf ht.1, Set.to_countable _⟩
instance map.isCountablyGenerated (l : Filter α) [l.IsCountablyGenerated] (f : α → β) :
(map f l).IsCountablyGenerated :=
let ⟨_x, hxl⟩ := l.exists_antitone_basis
(hxl.map _).isCountablyGenerated
instance comap.isCountablyGenerated (l : Filter β) [l.IsCountablyGenerated] (f : α → β) :
(comap f l).IsCountablyGenerated :=
let ⟨_x, hxl⟩ := l.exists_antitone_basis
(hxl.comap _).isCountablyGenerated
instance Sup.isCountablyGenerated (f g : Filter α) [IsCountablyGenerated f]
[IsCountablyGenerated g] : IsCountablyGenerated (f ⊔ g) := by
rcases f.exists_antitone_basis with ⟨s, hs⟩
rcases g.exists_antitone_basis with ⟨t, ht⟩
exact HasCountableBasis.isCountablyGenerated ⟨hs.1.sup ht.1, Set.to_countable _⟩
instance prod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la]
[IsCountablyGenerated lb] : IsCountablyGenerated (la ×ˢ lb) :=
Filter.Inf.isCountablyGenerated _ _
instance coprod.isCountablyGenerated (la : Filter α) (lb : Filter β) [IsCountablyGenerated la]
[IsCountablyGenerated lb] : IsCountablyGenerated (la.coprod lb) :=
Filter.Sup.isCountablyGenerated _ _
end IsCountablyGenerated
theorem isCountablyGenerated_seq [Countable ι'] (x : ι' → Set α) :
IsCountablyGenerated (⨅ i, 𝓟 (x i)) := by
use range x, countable_range x
rw [generate_eq_biInf, iInf_range]
theorem isCountablyGenerated_of_seq {f : Filter α} (h : ∃ x : ℕ → Set α, f = ⨅ i, 𝓟 (x i)) :
f.IsCountablyGenerated := by
rcases h with ⟨x, rfl⟩
apply isCountablyGenerated_seq
theorem isCountablyGenerated_biInf_principal {B : Set (Set α)} (h : B.Countable) :
IsCountablyGenerated (⨅ s ∈ B, 𝓟 s) :=
isCountablyGenerated_of_seq (countable_biInf_principal_eq_seq_iInf h)
theorem isCountablyGenerated_iff_exists_antitone_basis {f : Filter α} :
IsCountablyGenerated f ↔ ∃ x : ℕ → Set α, f.HasAntitoneBasis x := by
constructor
· intro h
exact f.exists_antitone_basis
· rintro ⟨x, h⟩
rw [h.1.eq_iInf]
exact isCountablyGenerated_seq x
@[instance]
theorem isCountablyGenerated_principal (s : Set α) : IsCountablyGenerated (𝓟 s) :=
isCountablyGenerated_of_seq ⟨fun _ => s, iInf_const.symm⟩
@[instance]
theorem isCountablyGenerated_pure (a : α) : IsCountablyGenerated (pure a) := by
rw [← principal_singleton]
exact isCountablyGenerated_principal _
@[instance]
theorem isCountablyGenerated_bot : IsCountablyGenerated (⊥ : Filter α) :=
@principal_empty α ▸ isCountablyGenerated_principal _
@[instance]
theorem isCountablyGenerated_top : IsCountablyGenerated (⊤ : Filter α) :=
@principal_univ α ▸ isCountablyGenerated_principal _
-- Porting note: without explicit `Sort u` and `Type v`, Lean 4 uses `ι : Prop`
universe u v
instance iInf.isCountablyGenerated {ι : Sort u} {α : Type v} [Countable ι] (f : ι → Filter α)
[∀ i, IsCountablyGenerated (f i)] : IsCountablyGenerated (⨅ i, f i) := by
choose s hs using fun i => exists_antitone_basis (f i)
rw [← PLift.down_surjective.iInf_comp]
refine HasCountableBasis.isCountablyGenerated ⟨hasBasis_iInf fun n => (hs _).1, ?_⟩
refine (countable_range <| Sigma.map ((↑) : Finset (PLift ι) → Set (PLift ι)) fun _ => id).mono ?_
rintro ⟨I, f⟩ ⟨hI, -⟩
lift I to Finset (PLift ι) using hI
exact ⟨⟨I, f⟩, rfl⟩
end Filter
|
Order\Filter\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Data.Set.Finite
/-!
# Theory of filters on sets
## Main definitions
* `Filter` : filters on a set;
* `Filter.principal` : filter of all sets containing a given set;
* `Filter.map`, `Filter.comap` : operations on filters;
* `Filter.Tendsto` : limit with respect to filters;
* `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`;
* `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`;
* `filter_upwards [h₁, ..., hₙ]` :
a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`,
and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`;
* `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter.
Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to
abstract two related kinds of ideas:
* *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions
at a point or at infinity, etc...
* *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough
a point `x`, or for close enough pairs of points, or things happening almost everywhere in the
sense of measure theory. Dually, filters can also express the idea of *things happening often*:
for arbitrarily large `n`, or at a point in any neighborhood of given a point etc...
In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice
structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois
insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to
the smallest filter containing it in the other direction.
We also prove `Filter` is a monadic functor, with a push-forward operation
`Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the
order on filters.
The examples of filters appearing in the description of the two motivating ideas are:
* `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N`
* `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic)
* `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces
defined in `Mathlib/Topology/UniformSpace/Basic.lean`)
* `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ`
(defined in `Mathlib/MeasureTheory/OuterMeasure/AE`)
The general notion of limit of a map with respect to filters on the source and target types
is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation.
The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is
`Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come
rather late in this file in order to immediately relate them to the lattice structure).
For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to
some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of
`M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`,
which is a special case of `mem_closure_of_tendsto` from Topology.Basic.
## Notations
* `∀ᶠ x in f, p x` : `f.Eventually p`;
* `∃ᶠ x in f, p x` : `f.Frequently p`;
* `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`;
* `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`;
* `𝓟 s` : `Filter.Principal s`, localized in `Filter`.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which
we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element
`⊥` for its lattice structure, at the cost of including the assumption
`[NeBot f]` in a number of lemmas and definitions.
-/
assert_not_exists OrderedSemiring
open Function Set Order
open scoped symmDiff
universe u v w x y
/-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`,
is upwards-closed, and is stable under intersection. We do not forbid this collection to be
all sets of `α`. -/
structure Filter (α : Type*) where
/-- The set of sets that belong to the filter. -/
sets : Set (Set α)
/-- The set `Set.univ` belongs to any filter. -/
univ_sets : Set.univ ∈ sets
/-- If a set belongs to a filter, then its superset belongs to the filter as well. -/
sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets
/-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/
inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets
/-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/
instance {α : Type*} : Membership (Set α) (Filter α) :=
⟨fun U F => U ∈ F.sets⟩
namespace Filter
variable {α : Type u} {f g : Filter α} {s t : Set α}
@[simp]
protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t :=
Iff.rfl
@[simp]
protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f :=
Iff.rfl
instance inhabitedMem : Inhabited { s : Set α // s ∈ f } :=
⟨⟨univ, f.univ_sets⟩⟩
theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
theorem filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
@[ext]
protected theorem ext (h : ∀ s, s ∈ f ↔ s ∈ g) : f = g := by
simpa [filter_eq_iff, Set.ext_iff, Filter.mem_sets]
/-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g.,
`Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/
protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g :=
Filter.ext <| compl_surjective.forall.2 h
@[simp]
theorem univ_mem : univ ∈ f :=
f.univ_sets
theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f :=
f.sets_of_superset hx hxy
instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where
trans h₁ h₂ := mem_of_superset h₂ h₁
theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f :=
f.inter_sets hs ht
@[simp]
theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f :=
⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩,
and_imp.2 inter_mem⟩
theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f :=
inter_mem hs ht
theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f :=
mem_of_superset univ_mem fun x _ => h x
theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f :=
mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁
theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f :=
⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs =>
mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩
/-- Override `sets` field of a filter to provide better definitional equality. -/
protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where
sets := S
univ_sets := (hmem _).2 univ_mem
sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub
inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂)
lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem
@[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl
@[simp]
theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f :=
Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs]
@[simp]
theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f :=
biInter_mem is.finite_toSet
alias _root_.Finset.iInter_mem_sets := biInter_finset_mem
-- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work
@[simp]
theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by
rw [sInter_eq_biInter, biInter_mem hfin]
@[simp]
theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f :=
(sInter_mem (finite_range _)).trans forall_mem_range
theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩
theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h =>
mem_of_superset h hst
theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P)
(hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by
constructor
· rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩
exact
⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩
· rintro ⟨u, huf, hPu, hQu⟩
exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩
theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} :
(∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b :=
Set.forall_in_swap
end Filter
namespace Mathlib.Tactic
open Lean Meta Elab Tactic
/--
`filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms
`h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`.
The list is an optional parameter, `[]` being its default value.
`filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for
`{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`.
`filter_upwards [h₁, ⋯, hₙ] using e` is a short form for
`{ filter_upwards [h1, ⋯, hn], exact e }`.
Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`.
Note that in this case, the `aᵢ` terms can be used in `e`.
-/
syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")?
(" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic
elab_rules : tactic
| `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do
let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly}
for e in args.getD #[] |>.reverse do
let goal ← getMainGoal
replaceMainGoal <| ← goal.withContext <| runTermElab do
let m ← mkFreshExprMVar none
let lem ← Term.elabTermEnsuringType
(← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType)
goal.assign lem
return [m.mvarId!]
liftMetaTactic fun goal => do
goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config
evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq])
if let some l := wth then
evalTactic <|← `(tactic| intro $[$l]*)
if let some e := usingArg then
evalTactic <|← `(tactic| exact $e)
end Mathlib.Tactic
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x}
section Principal
/-- The principal filter of `s` is the collection of all supersets of `s`. -/
def principal (s : Set α) : Filter α where
sets := { t | s ⊆ t }
univ_sets := subset_univ s
sets_of_superset hx := Subset.trans hx
inter_sets := subset_inter
@[inherit_doc]
scoped notation "𝓟" => Filter.principal
@[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl
theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl
end Principal
open Filter
section Join
/-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/
def join (f : Filter (Filter α)) : Filter α where
sets := { s | { t : Filter α | s ∈ t } ∈ f }
univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true]
sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy
inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂
@[simp]
theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f :=
Iff.rfl
end Join
section Lattice
variable {f g : Filter α} {s t : Set α}
instance : PartialOrder (Filter α) where
le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f
le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁
le_refl a := Subset.rfl
le_trans a b c h₁ h₂ := Subset.trans h₂ h₁
theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f :=
Iff.rfl
protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop]
/-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/
inductive GenerateSets (g : Set (Set α)) : Set α → Prop
| basic {s : Set α} : s ∈ g → GenerateSets g s
| univ : GenerateSets g univ
| superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t
| inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t)
/-- `generate g` is the largest filter containing the sets `g`. -/
def generate (g : Set (Set α)) : Filter α where
sets := {s | GenerateSets g s}
univ_sets := GenerateSets.univ
sets_of_superset := GenerateSets.superset
inter_sets := GenerateSets.inter
lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) :
U ∈ generate s := GenerateSets.basic h
theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets :=
Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu =>
hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy =>
inter_mem hx hy
theorem mem_generate_iff {s : Set <| Set α} {U : Set α} :
U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by
constructor <;> intro h
· induction h with
| @basic V V_in =>
exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩
| univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩
| superset _ hVW hV =>
rcases hV with ⟨t, hts, ht, htV⟩
exact ⟨t, hts, ht, htV.trans hVW⟩
| inter _ _ hV hW =>
rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩
exact
⟨t ∪ u, union_subset hts hus, ht.union hu,
(sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩
· rcases h with ⟨t, hts, tfin, h⟩
exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h
@[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s :=
le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <|
le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl
/-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly
`s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/
protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where
sets := s
univ_sets := hs ▸ univ_mem
sets_of_superset := hs ▸ mem_of_superset
inter_sets := hs ▸ inter_mem
theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} :
Filter.mkOfClosure s hs = generate s :=
Filter.ext fun u =>
show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl
/-- Galois insertion from sets of sets into filters. -/
def giGenerate (α : Type*) :
@GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where
gc _ _ := le_generate_iff
le_l_u _ _ h := GenerateSets.basic h
choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
/-- The infimum of filters is the filter generated by intersections
of elements of the two filters. -/
instance : Inf (Filter α) :=
⟨fun f g : Filter α =>
{ sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b }
univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩
sets_of_superset := by
rintro x y ⟨a, ha, b, hb, rfl⟩ xy
refine
⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y,
mem_of_superset hb subset_union_left, ?_⟩
rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy]
inter_sets := by
rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩
refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩
ac_rfl }⟩
theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ :=
Iff.rfl
theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem, (inter_univ s).symm⟩
theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem, s, h, (univ_inter s).symm⟩
theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) :
s ∩ t ∈ f ⊓ g :=
⟨s, hs, t, ht, rfl⟩
theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g)
(h : s ∩ t ⊆ u) : u ∈ f ⊓ g :=
mem_of_superset (inter_mem_inf hs ht) h
theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} :
s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s :=
⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ =>
mem_inf_of_inter h₁ h₂ sub⟩
instance : Top (Filter α) :=
⟨{ sets := { s | ∀ x, x ∈ s }
univ_sets := fun x => mem_univ x
sets_of_superset := fun hx hxy a => hxy (hx a)
inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩
theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s :=
Iff.rfl
@[simp]
theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by
rw [mem_top_iff_forall, eq_univ_iff_forall]
section CompleteLattice
/- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately,
we want to have different definitional equalities for some lattice operations. So we define them
upfront and change the lattice operations for the complete lattice instance. -/
instance instCompleteLatticeFilter : CompleteLattice (Filter α) :=
{ @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with
le := (· ≤ ·)
top := ⊤
le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => mem_inf_of_left
inf_le_right := fun _ _ _ => mem_inf_of_right
le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb)
sSup := join ∘ 𝓟
le_sSup := fun _ _f hf _s hs => hs hf
sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs }
instance : Inhabited (Filter α) := ⟨⊥⟩
end CompleteLattice
/-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to
the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a
`CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/
class NeBot (f : Filter α) : Prop where
/-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/
ne' : f ≠ ⊥
theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne'
@[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left
theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g :=
⟨ne_bot_of_le_ne_bot hf.1 hg⟩
theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g :=
hf.mono hg
@[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by
simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff]
theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff]
theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl
/-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot`
as the second alternative, to be used as an instance. -/
theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk
theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(giGenerate α).gc.u_inf
theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets :=
(giGenerate α).gc.u_sInf
theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets :=
(giGenerate α).gc.u_iInf
theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) :=
(giGenerate α).gc.l_bot
theorem generate_univ : Filter.generate univ = (⊥ : Filter α) :=
bot_unique fun _ _ => GenerateSets.basic (mem_univ _)
theorem generate_union {s t : Set (Set α)} :
Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t :=
(giGenerate α).gc.l_sup
theorem generate_iUnion {s : ι → Set (Set α)} :
Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) :=
(giGenerate α).gc.l_iSup
@[simp]
theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) :=
trivial
@[simp]
theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
Iff.rfl
theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g :=
⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩
@[simp]
theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) :=
Iff.rfl
@[simp]
theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by
simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter]
@[simp]
theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by
simp [neBot_iff]
theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) :=
show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm
theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i :=
iInf_le f i hs
theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite)
{V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by
haveI := I_fin.fintype
refine mem_of_superset (iInter_mem.2 fun i => ?_) hU
exact mem_iInf_of_mem (i : ι) (hV _)
theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} :
(U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by
constructor
· rw [iInf_eq_generate, mem_generate_iff]
rintro ⟨t, tsub, tfin, tinter⟩
rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩
rw [sInter_iUnion] at tinter
set V := fun i => U ∪ ⋂₀ σ i with hV
have V_in : ∀ i, V i ∈ s i := by
rintro i
have : ⋂₀ σ i ∈ s i := by
rw [sInter_mem (σfin _)]
apply σsub
exact mem_of_superset this subset_union_right
refine ⟨I, Ifin, V, V_in, ?_⟩
rwa [hV, ← union_iInter, union_eq_self_of_subset_right]
· rintro ⟨I, Ifin, V, V_in, rfl⟩
exact mem_iInf_of_iInter Ifin V_in Subset.rfl
theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} :
(U ∈ ⨅ i, s i) ↔
∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧
(∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by
classical
simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter]
refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩
rintro ⟨I, If, V, hV, rfl⟩
refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩
· dsimp only
split_ifs
exacts [hV _, univ_mem]
· exact dif_neg hi
· simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta,
iInter_univ, inter_univ, eq_self_iff_true, true_and_iff]
theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s}
(hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i :=
let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩
theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) :
(s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by
refine ⟨exists_iInter_of_mem_iInf, ?_⟩
rintro ⟨t, ht, rfl⟩
exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i)
@[simp]
theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f :=
⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩
theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } :=
Set.ext fun _ => le_principal_iff
theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by
simp only [le_principal_iff, iff_self_iff, mem_principal]
@[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono
@[mono]
theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2
@[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by
simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl
@[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl
@[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ :=
top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true]
@[simp]
theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ :=
bot_unique fun _ _ => empty_subset _
theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s :=
eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def]
/-! ### Lattice equations -/
theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩
theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id
theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty :=
@Filter.nonempty_of_mem α f hf s hs
@[simp]
theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl
theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α :=
nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f)
theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc =>
(nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s
theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ :=
empty_mem_iff_bot.mp <| univ_mem' isEmptyElim
protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by
simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty,
@eq_comm _ ∅]
theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f)
(ht : t ∈ g) : Disjoint f g :=
Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩
theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h =>
not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩
theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by
simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α}
(hd : Pairwise (Disjoint on l)) :
∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by
have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by
simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd
choose! s t hst using this
refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩
exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2,
(hst hij).mono ((iInter_subset _ j).trans inter_subset_left)
((iInter_subset _ i).trans inter_subset_right)]
theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι}
(hd : t.PairwiseDisjoint l) (ht : t.Finite) :
∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by
haveI := ht.to_subtype
rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩
lift s to (i : t) → {s // s ∈ l i} using hsl
rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩
exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩
/-- There is exactly one filter on an empty type. -/
instance unique [IsEmpty α] : Unique (Filter α) where
default := ⊥
uniq := filter_eq_bot_of_isEmpty
theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α :=
not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _)
/-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are
equal. -/
theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by
refine top_unique fun s hs => ?_
obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
exact univ_mem
theorem forall_mem_nonempty_iff_neBot {f : Filter α} :
(∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f :=
⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩
instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) :=
⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1
fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩
theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α :=
⟨fun _ =>
by_contra fun h' =>
haveI := not_nonempty_iff.1 h'
not_subsingleton (Filter α) inferInstance,
@Filter.instNontrivialFilter α⟩
theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S :=
le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩)
fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs
theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f :=
eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm
theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by
rw [iInf_subtype']
exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop]
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] :
(iInf f).sets = ⋃ i, (f i).sets :=
let ⟨i⟩ := ne
let u :=
{ sets := ⋃ i, (f i).sets
univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩
sets_of_superset := by
simp only [mem_iUnion, exists_imp]
exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩
inter_sets := by
simp only [mem_iUnion, exists_imp]
intro x y a hx b hy
rcases h a b with ⟨c, ha, hb⟩
exact ⟨c, inter_mem (ha hx) (hb hy)⟩ }
have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion
-- Porting note: it was just `congr_arg filter.sets this.symm`
(congr_arg Filter.sets this.symm).trans <| by simp only
theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) :
s ∈ iInf f ↔ ∃ i, s ∈ f i := by
simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by
haveI := ne.to_subtype
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets :=
ext fun t => by simp [mem_biInf_of_directed h ne]
theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) :
(⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by
rw [iInf_eq_iInf_finset, iInf_sets_eq]
exact directed_of_isDirected_le fun _ _ => biInf_mono
theorem iInf_sets_eq_finite' (f : ι → Filter α) :
(⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by
rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply]
theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) :
s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i :=
(Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion
theorem mem_iInf_finite' {f : ι → Filter α} (s) :
s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) :=
(Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion
@[simp]
theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) :=
Filter.ext fun x => by simp only [mem_sup, mem_join]
@[simp]
theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) :=
Filter.ext fun x => by simp only [mem_iSup, mem_join]
instance : DistribLattice (Filter α) :=
{ Filter.instCompleteLatticeFilter with
le_sup_inf := by
intro x y z s
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
rintro hs t₁ ht₁ t₂ ht₂ rfl
exact
⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂,
x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ }
/-- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/
def coframeMinimalAxioms : Coframe.MinimalAxioms (Filter α) :=
{ Filter.instCompleteLatticeFilter with
iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by
classical
rw [iInf_subtype']
rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at h₂
obtain ⟨u, hu⟩ := h₂
rw [← Finset.inf_eq_iInf] at hu
suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩
refine Finset.induction_on u (le_sup_of_le_right le_top) ?_
rintro ⟨i⟩ u _ ih
rw [Finset.inf_insert, sup_inf_left]
exact le_inf (iInf_le _ _) ih }
instance instCoframe : Coframe (Filter α) := .ofMinimalAxioms coframeMinimalAxioms
theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} :
(t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by
classical
simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype']
refine ⟨fun h => ?_, ?_⟩
· rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩
refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ,
fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩
refine iInter_congr_of_surjective id surjective_id ?_
rintro ⟨a, ha⟩
simp [ha]
· rintro ⟨p, hpf, rfl⟩
exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2)
/-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/
theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
(∀ i, NeBot (f i)) → NeBot (iInf f) :=
not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot,
mem_iInf_of_directed hd] using id
/-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/
theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f)
(hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by
cases isEmpty_or_nonempty ι
· constructor
simp [iInf_of_empty f, top_ne_bot]
· exact iInf_neBot_of_directed' hd hb
theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
@iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ =>
⟨ne_of_mem_of_not_mem hf hbot⟩
theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩
theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩
theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩
@[elab_as_elim]
theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop}
(uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by
classical
rw [mem_iInf_finite'] at hs
simp only [← Finset.inf_eq_iInf] at hs
rcases hs with ⟨is, his⟩
induction is using Finset.induction_on generalizing s with
| empty => rwa [mem_top.1 his]
| insert _ ih =>
rw [Finset.inf_insert, mem_inf_iff] at his
rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩
exact ins hs₁ (ih hs₂)
/-! #### `principal` equations -/
@[simp]
theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) :=
le_antisymm
(by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp]
theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) :=
Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal]
@[simp]
theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) :=
Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff]
@[simp]
theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ :=
empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff
@[simp]
theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty :=
neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm
alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff
theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) :=
IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by
rw [sup_principal, union_compl_self, principal_univ]
theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by
simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal,
← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl]
lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by
simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq]
lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by
ext
simp only [mem_iSup, mem_inf_principal]
theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by
rw [← empty_mem_iff_bot, mem_inf_principal]
simp only [mem_empty_iff_false, imp_false, compl_def]
theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by
rwa [inf_principal_eq_bot, compl_compl] at h
theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) :
s \ t ∈ f ⊓ 𝓟 tᶜ :=
inter_mem_inf hs <| mem_principal_self tᶜ
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
@[simp]
theorem iInf_principal_finset {ι : Type w} (s : Finset ι) (f : ι → Set α) :
⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by
classical
induction' s using Finset.induction_on with i s _ hs
· simp
· rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal]
theorem iInf_principal {ι : Sort w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := by
cases nonempty_fintype (PLift ι)
rw [← iInf_plift_down, ← iInter_plift_down]
simpa using iInf_principal_finset Finset.univ (f <| PLift.down ·)
/-- A special case of `iInf_principal` that is safe to mark `simp`. -/
@[simp]
theorem iInf_principal' {ι : Type w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) :=
iInf_principal _
theorem iInf_principal_finite {ι : Type w} {s : Set ι} (hs : s.Finite) (f : ι → Set α) :
⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by
lift s to Finset ι using hs
exact mod_cast iInf_principal_finset s f
end Lattice
@[mono, gcongr]
theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs
/-! ### Eventually -/
/-- `f.Eventually p` or `∀ᶠ x in f, p x` mean that `{x | p x} ∈ f`. E.g., `∀ᶠ x in atTop, p x`
means that `p` holds true for sufficiently large `x`. -/
protected def Eventually (p : α → Prop) (f : Filter α) : Prop :=
{ x | p x } ∈ f
@[inherit_doc Filter.Eventually]
notation3 "∀ᶠ "(...)" in "f", "r:(scoped p => Filter.Eventually p f) => r
theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f :=
Iff.rfl
@[simp]
theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l :=
Iff.rfl
protected theorem ext' {f₁ f₂ : Filter α}
(h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ :=
Filter.ext h
theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop}
(hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x :=
h hp
theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f)
(h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x :=
mem_of_superset hU h
protected theorem Eventually.and {p q : α → Prop} {f : Filter α} :
f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x :=
inter_mem
@[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem
theorem eventually_of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x :=
univ_mem' hp
@[simp]
theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ :=
empty_mem_iff_bot
@[simp]
theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by
by_cases h : p <;> simp [h, t.ne]
theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y :=
exists_mem_subset_iff.symm
theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) :
∃ v ∈ f, ∀ y ∈ v, p y :=
eventually_iff_exists_mem.1 hp
theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x :=
mp_mem hp hq
theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x :=
hp.mp (eventually_of_forall hq)
theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop}
(h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y :=
fun y => h.mono fun _ h => h y
@[simp]
theorem eventually_and {p q : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x :=
inter_mem_iff
theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x)
(h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x :=
h'.mp (h.mono fun _ hx => hx.mp)
theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) :
(∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x :=
⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩
@[simp]
theorem eventually_all {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i, p i x) ↔ ∀ i, ∀ᶠ x in l, p i x := by
simpa only [Filter.Eventually, setOf_forall] using iInter_mem
@[simp]
theorem eventually_all_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := by
simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI
alias _root_.Set.Finite.eventually_all := eventually_all_finite
-- attribute [protected] Set.Finite.eventually_all
@[simp] theorem eventually_all_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} :
(∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x :=
I.finite_toSet.eventually_all
alias _root_.Finset.eventually_all := eventually_all_finset
-- attribute [protected] Finset.eventually_all
@[simp]
theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x :=
by_cases (fun h : p => by simp [h]) fun h => by simp [h]
@[simp]
theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by
simp only [@or_comm _ q, eventually_or_distrib_left]
theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x :=
eventually_all
@[simp]
theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x :=
⟨⟩
@[simp]
theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x :=
Iff.rfl
@[simp]
theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x :=
Iff.rfl
@[simp]
theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x :=
Iff.rfl
@[simp]
theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} :
(∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x :=
mem_iSup
@[simp]
theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x :=
Iff.rfl
theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop}
(hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x :=
Filter.eventually_principal.mp (hP.filter_mono hf)
theorem eventually_inf {f g : Filter α} {p : α → Prop} :
(∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x :=
mem_inf_iff_superset
theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} :
(∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x :=
mem_inf_principal
/-! ### Frequently -/
/-- `f.Frequently p` or `∃ᶠ x in f, p x` mean that `{x | ¬p x} ∉ f`. E.g., `∃ᶠ x in atTop, p x`
means that there exist arbitrarily large `x` for which `p` holds true. -/
protected def Frequently (p : α → Prop) (f : Filter α) : Prop :=
¬∀ᶠ x in f, ¬p x
@[inherit_doc Filter.Frequently]
notation3 "∃ᶠ "(...)" in "f", "r:(scoped p => Filter.Frequently p f) => r
theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) :
∃ᶠ x in f, p x :=
compl_not_mem h
theorem frequently_of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) :
∃ᶠ x in f, p x :=
Eventually.frequently (eventually_of_forall h)
theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x :=
mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h
theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) :
∃ᶠ x in g, p x :=
mt (fun h' => h'.filter_mono hle) h
theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x :=
h.mp (eventually_of_forall hpq)
theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x)
(hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
refine mt (fun h => hq.mp <| h.mono ?_) hp
exact fun x hpq hq hp => hpq ⟨hp, hq⟩
theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
simpa only [and_comm] using hq.and_eventually hp
theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by
by_contra H
replace H : ∀ᶠ x in f, ¬p x := eventually_of_forall (not_exists.1 H)
exact hp H
theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) :
∃ x, p x :=
hp.frequently.exists
lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} :
(∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by
rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl
lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) :=
frequently_iff_neBot
theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} :
(∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x :=
⟨fun hp q hq => (hp.and_eventually hq).exists, fun H hp => by
simpa only [and_not_self_iff, exists_false] using H hp⟩
theorem frequently_iff {f : Filter α} {P : α → Prop} :
(∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by
simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)]
rfl
@[simp]
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
@[simp]
theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by
simp only [Filter.Frequently, not_not]
@[simp]
theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by
simp [frequently_iff_neBot]
@[simp]
theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp
@[simp]
theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by
by_cases p <;> simp [*]
@[simp]
theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and]
theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp
theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp
theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by
simp [imp_iff_not_or]
theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib]
theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by
set_option tactic.skipAssignedInstances false in simp [frequently_imp_distrib]
theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
@[simp]
theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp]
@[simp]
theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by
simp only [@and_comm _ q, frequently_and_distrib_left]
@[simp]
theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp
@[simp]
theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently]
@[simp]
theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by
simp [Filter.Frequently, not_forall]
theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by
simp only [Filter.Frequently, eventually_inf_principal, not_and]
alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal
theorem frequently_sup {p : α → Prop} {f g : Filter α} :
(∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by
simp only [Filter.Frequently, eventually_sup, not_and_or]
@[simp]
theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by
simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop]
@[simp]
theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} :
(∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by
simp only [Filter.Frequently, eventually_iSup, not_forall]
theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) :
∃ f : α → β, ∀ᶠ x in l, r x (f x) := by
haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty
choose! f hf using fun x (hx : ∃ y, r x y) => hx
exact ⟨f, h.mono hf⟩
/-!
### Relation “eventually equal”
-/
/-- Two functions `f` and `g` are *eventually equal* along a filter `l` if the set of `x` such that
`f x = g x` belongs to `l`. -/
def EventuallyEq (l : Filter α) (f g : α → β) : Prop :=
∀ᶠ x in l, f x = g x
@[inherit_doc]
notation:50 f " =ᶠ[" l:50 "] " g:50 => EventuallyEq l f g
theorem EventuallyEq.eventually {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∀ᶠ x in l, f x = g x :=
h
theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop)
(hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) :=
hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl
theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t :=
eventually_congr <| eventually_of_forall fun _ ↦ eq_iff_iff
alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set
@[simp]
theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by
simp [eventuallyEq_set]
theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∃ s ∈ l, EqOn f g s :=
Eventually.exists_mem h
theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) :
f =ᶠ[l] g :=
eventually_of_mem hs h
theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s :=
eventually_iff_exists_mem
theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) :
f =ᶠ[l'] g :=
h₂ h₁
@[refl, simp]
theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f :=
eventually_of_forall fun _ => rfl
protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f :=
EventuallyEq.refl l f
@[symm]
theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f :=
H.mono fun _ => Eq.symm
@[trans]
theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) :
f =ᶠ[l] h :=
H₂.rw (fun x y => f x = y) H₁
theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) :
f =ᶠ[l] h ↔ g =ᶠ[l] h :=
⟨H.symm.trans, H.trans⟩
theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) :
f =ᶠ[l] g ↔ f =ᶠ[l] h :=
⟨(·.trans H), (·.trans H.symm)⟩
instance {l : Filter α} :
Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where
trans := EventuallyEq.trans
theorem EventuallyEq.prod_mk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') :
(fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) :=
hf.mp <|
hg.mono <| by
intros
simp only [*]
-- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t.
-- composition on the right.
theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) :
h ∘ f =ᶠ[l] h ∘ g :=
H.mono fun _ hx => congr_arg h hx
theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ)
(Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) :=
(Hf.prod_mk Hg).fun_comp (uncurry h)
@[to_additive]
theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x :=
h.comp₂ (· * ·) h'
@[to_additive const_smul]
theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) :
(fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c :=
h.fun_comp (· ^ c)
@[to_additive]
theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
(fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ :=
h.fun_comp Inv.inv
@[to_additive]
theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x :=
h.comp₂ (· / ·) h'
attribute [to_additive] EventuallyEq.const_smul
@[to_additive]
theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β}
(hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x :=
hf.comp₂ (· • ·) hg
theorem EventuallyEq.sup [Sup β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x :=
hf.comp₂ (· ⊔ ·) hg
theorem EventuallyEq.inf [Inf β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x :=
hf.comp₂ (· ⊓ ·) hg
theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) :
f ⁻¹' s =ᶠ[l] g ⁻¹' s :=
h.fun_comp s
theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) :=
h.comp₂ (· ∧ ·) h'
theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) :=
h.comp₂ (· ∨ ·) h'
theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) :
(sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) :=
h.fun_comp Not
theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α}
(h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) :=
(h.diff h').union (h'.diff h)
theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s :=
eventuallyEq_set.trans <| by simp
theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by
simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp]
theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by
rw [inter_comm, inter_eventuallyEq_left]
@[simp]
theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s :=
Iff.rfl
theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} :
f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x :=
eventually_inf_principal
theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm
theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 :=
⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩
section LE
variable [LE β] {l : Filter α}
/-- A function `f` is eventually less than or equal to a function `g` at a filter `l`. -/
def EventuallyLE (l : Filter α) (f g : α → β) : Prop :=
∀ᶠ x in l, f x ≤ g x
@[inherit_doc]
notation:50 f " ≤ᶠ[" l:50 "] " g:50 => EventuallyLE l f g
theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f' ≤ᶠ[l] g' :=
H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H
theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' :=
⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩
end LE
section Preorder
variable [Preorder β] {l : Filter α} {f g h : α → β}
theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g :=
h.mono fun _ => le_of_eq
@[refl]
theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f :=
EventuallyEq.rfl.le
theorem EventuallyLE.rfl : f ≤ᶠ[l] f :=
EventuallyLE.refl l f
@[trans]
theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₂.mp <| H₁.mono fun _ => le_trans
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans
@[trans]
theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.le.trans H₂
instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyEq.trans_le
@[trans]
theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.trans H₂.le
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans_eq
end Preorder
variable {l : Filter α}
theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g)
(h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g :=
h₂.mp <| h₁.mono fun _ => le_antisymm
theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by
simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and]
theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) :
g ≤ᶠ[l] f ↔ g =ᶠ[l] f :=
⟨fun h' => h'.antisymm h, EventuallyEq.le⟩
theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) :
∀ᶠ x in l, f x ≠ g x :=
h.mono fun _ hx => hx.ne
theorem Eventually.ne_top_of_lt [PartialOrder β] [OrderTop β] {l : Filter α} {f g : α → β}
(h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ :=
h.mono fun _ hx => hx.ne_top
theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β}
(h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ :=
h.mono fun _ hx => hx.lt_top
theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} :
(∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ :=
⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩
@[mono]
theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) :=
h'.mp <| h.mono fun _ => And.imp
@[mono]
theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) :=
h'.mp <| h.mono fun _ => Or.imp
protected lemma EventuallyLE.iUnion [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i ≤ᶠ[l] t i) : (⋃ i, s i) ≤ᶠ[l] ⋃ i, t i :=
(eventually_all.2 h).mono fun _x hx hx' ↦
let ⟨i, hi⟩ := mem_iUnion.1 hx'; mem_iUnion.2 ⟨i, hx i hi⟩
protected lemma EventuallyEq.iUnion [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i =ᶠ[l] t i) : (⋃ i, s i) =ᶠ[l] ⋃ i, t i :=
(EventuallyLE.iUnion fun i ↦ (h i).le).antisymm <| .iUnion fun i ↦ (h i).symm.le
protected lemma EventuallyLE.iInter [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i ≤ᶠ[l] t i) : (⋂ i, s i) ≤ᶠ[l] ⋂ i, t i :=
(eventually_all.2 h).mono fun _x hx hx' ↦ mem_iInter.2 fun i ↦ hx i (mem_iInter.1 hx' i)
protected lemma EventuallyEq.iInter [Finite ι] {s t : ι → Set α}
(h : ∀ i, s i =ᶠ[l] t i) : (⋂ i, s i) =ᶠ[l] ⋂ i, t i :=
(EventuallyLE.iInter fun i ↦ (h i).le).antisymm <| .iInter fun i ↦ (h i).symm.le
lemma _root_.Set.Finite.eventuallyLE_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) := by
have := hs.to_subtype
rw [biUnion_eq_iUnion, biUnion_eq_iUnion]
exact .iUnion fun i ↦ hle i.1 i.2
alias EventuallyLE.biUnion := Set.Finite.eventuallyLE_iUnion
lemma _root_.Set.Finite.eventuallyEq_iUnion {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) :=
(EventuallyLE.biUnion hs fun i hi ↦ (heq i hi).le).antisymm <|
.biUnion hs fun i hi ↦ (heq i hi).symm.le
alias EventuallyEq.biUnion := Set.Finite.eventuallyEq_iUnion
lemma _root_.Set.Finite.eventuallyLE_iInter {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) := by
have := hs.to_subtype
rw [biInter_eq_iInter, biInter_eq_iInter]
exact .iInter fun i ↦ hle i.1 i.2
alias EventuallyLE.biInter := Set.Finite.eventuallyLE_iInter
lemma _root_.Set.Finite.eventuallyEq_iInter {ι : Type*} {s : Set ι} (hs : s.Finite)
{f g : ι → Set α} (heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) :=
(EventuallyLE.biInter hs fun i hi ↦ (heq i hi).le).antisymm <|
.biInter hs fun i hi ↦ (heq i hi).symm.le
alias EventuallyEq.biInter := Set.Finite.eventuallyEq_iInter
lemma _root_.Finset.eventuallyLE_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋃ i ∈ s, f i) ≤ᶠ[l] (⋃ i ∈ s, g i) :=
.biUnion s.finite_toSet hle
lemma _root_.Finset.eventuallyEq_iUnion {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋃ i ∈ s, f i) =ᶠ[l] (⋃ i ∈ s, g i) :=
.biUnion s.finite_toSet heq
lemma _root_.Finset.eventuallyLE_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(hle : ∀ i ∈ s, f i ≤ᶠ[l] g i) : (⋂ i ∈ s, f i) ≤ᶠ[l] (⋂ i ∈ s, g i) :=
.biInter s.finite_toSet hle
lemma _root_.Finset.eventuallyEq_iInter {ι : Type*} (s : Finset ι) {f g : ι → Set α}
(heq : ∀ i ∈ s, f i =ᶠ[l] g i) : (⋂ i ∈ s, f i) =ᶠ[l] (⋂ i ∈ s, g i) :=
.biInter s.finite_toSet heq
@[mono]
theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) :
(tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) :=
h.mono fun _ => mt
@[mono]
theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') :
(s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s :=
eventually_inf_principal.symm
theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t :=
set_eventuallyLE_iff_mem_inf_principal.trans <| by
simp only [le_inf_iff, inf_le_left, true_and_iff, le_principal_iff]
theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} :
s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by
simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le]
theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂)
(hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by
filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx
theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h)
(hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by
filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx
theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g :=
hf.mono fun _ => _root_.le_sup_of_le_left
theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g :=
hg.mono fun _ => _root_.le_sup_of_le_right
theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l :=
fun _ hs => h.mono fun _ hm => hm hs
/-! ### Push-forwards, pull-backs, and the monad structure -/
section Map
/-- The forward map of a filter -/
def map (m : α → β) (f : Filter α) : Filter β where
sets := preimage m ⁻¹' f.sets
univ_sets := univ_mem
sets_of_superset hs st := mem_of_superset hs <| preimage_mono st
inter_sets hs ht := inter_mem hs ht
@[simp]
theorem map_principal {s : Set α} {f : α → β} : map f (𝓟 s) = 𝓟 (Set.image f s) :=
Filter.ext fun _ => image_subset_iff.symm
variable {f : Filter α} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β}
@[simp]
theorem eventually_map {P : β → Prop} : (∀ᶠ b in map m f, P b) ↔ ∀ᶠ a in f, P (m a) :=
Iff.rfl
@[simp]
theorem frequently_map {P : β → Prop} : (∃ᶠ b in map m f, P b) ↔ ∃ᶠ a in f, P (m a) :=
Iff.rfl
@[simp]
theorem mem_map : t ∈ map m f ↔ m ⁻¹' t ∈ f :=
Iff.rfl
theorem mem_map' : t ∈ map m f ↔ { x | m x ∈ t } ∈ f :=
Iff.rfl
theorem image_mem_map (hs : s ∈ f) : m '' s ∈ map m f :=
f.sets_of_superset hs <| subset_preimage_image m s
-- The simpNF linter says that the LHS can be simplified via `Filter.mem_map`.
-- However this is a higher priority lemma.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem image_mem_map_iff (hf : Injective m) : m '' s ∈ map m f ↔ s ∈ f :=
⟨fun h => by rwa [← preimage_image_eq s hf], image_mem_map⟩
theorem range_mem_map : range m ∈ map m f := by
rw [← image_univ]
exact image_mem_map univ_mem
theorem mem_map_iff_exists_image : t ∈ map m f ↔ ∃ s ∈ f, m '' s ⊆ t :=
⟨fun ht => ⟨m ⁻¹' t, ht, image_preimage_subset _ _⟩, fun ⟨_, hs, ht⟩ =>
mem_of_superset (image_mem_map hs) ht⟩
@[simp]
theorem map_id : Filter.map id f = f :=
filter_eq <| rfl
@[simp]
theorem map_id' : Filter.map (fun x => x) f = f :=
map_id
@[simp]
theorem map_compose : Filter.map m' ∘ Filter.map m = Filter.map (m' ∘ m) :=
funext fun _ => filter_eq <| rfl
@[simp]
theorem map_map : Filter.map m' (Filter.map m f) = Filter.map (m' ∘ m) f :=
congr_fun Filter.map_compose f
/-- If functions `m₁` and `m₂` are eventually equal at a filter `f`, then
they map this filter to the same filter. -/
theorem map_congr {m₁ m₂ : α → β} {f : Filter α} (h : m₁ =ᶠ[f] m₂) : map m₁ f = map m₂ f :=
Filter.ext' fun _ => eventually_congr (h.mono fun _ hx => hx ▸ Iff.rfl)
end Map
section Comap
/-- The inverse map of a filter. A set `s` belongs to `Filter.comap m f` if either of the following
equivalent conditions hold.
1. There exists a set `t ∈ f` such that `m ⁻¹' t ⊆ s`. This is used as a definition.
2. The set `kernImage m s = {y | ∀ x, m x = y → x ∈ s}` belongs to `f`, see `Filter.mem_comap'`.
3. The set `(m '' sᶜ)ᶜ` belongs to `f`, see `Filter.mem_comap_iff_compl` and
`Filter.compl_mem_comap`. -/
def comap (m : α → β) (f : Filter β) : Filter α where
sets := { s | ∃ t ∈ f, m ⁻¹' t ⊆ s }
univ_sets := ⟨univ, univ_mem, by simp only [subset_univ, preimage_univ]⟩
sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩
inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ =>
⟨a' ∩ b', inter_mem ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩
variable {f : α → β} {l : Filter β} {p : α → Prop} {s : Set α}
theorem mem_comap' : s ∈ comap f l ↔ { y | ∀ ⦃x⦄, f x = y → x ∈ s } ∈ l :=
⟨fun ⟨t, ht, hts⟩ => mem_of_superset ht fun y hy x hx => hts <| mem_preimage.2 <| by rwa [hx],
fun h => ⟨_, h, fun x hx => hx rfl⟩⟩
-- TODO: it would be nice to use `kernImage` much more to take advantage of common name and API,
-- and then this would become `mem_comap'`
theorem mem_comap'' : s ∈ comap f l ↔ kernImage f s ∈ l :=
mem_comap'
/-- RHS form is used, e.g., in the definition of `UniformSpace`. -/
lemma mem_comap_prod_mk {x : α} {s : Set β} {F : Filter (α × β)} :
s ∈ comap (Prod.mk x) F ↔ {p : α × β | p.fst = x → p.snd ∈ s} ∈ F := by
simp_rw [mem_comap', Prod.ext_iff, and_imp, @forall_swap β (_ = _), forall_eq, eq_comm]
@[simp]
theorem eventually_comap : (∀ᶠ a in comap f l, p a) ↔ ∀ᶠ b in l, ∀ a, f a = b → p a :=
mem_comap'
@[simp]
theorem frequently_comap : (∃ᶠ a in comap f l, p a) ↔ ∃ᶠ b in l, ∃ a, f a = b ∧ p a := by
simp only [Filter.Frequently, eventually_comap, not_exists, _root_.not_and]
theorem mem_comap_iff_compl : s ∈ comap f l ↔ (f '' sᶜ)ᶜ ∈ l := by
simp only [mem_comap'', kernImage_eq_compl]
theorem compl_mem_comap : sᶜ ∈ comap f l ↔ (f '' s)ᶜ ∈ l := by rw [mem_comap_iff_compl, compl_compl]
end Comap
section KernMap
/-- The analog of `kernImage` for filters. A set `s` belongs to `Filter.kernMap m f` if either of
the following equivalent conditions hold.
1. There exists a set `t ∈ f` such that `s = kernImage m t`. This is used as a definition.
2. There exists a set `t` such that `tᶜ ∈ f` and `sᶜ = m '' t`, see `Filter.mem_kernMap_iff_compl`
and `Filter.compl_mem_kernMap`.
This definition because it gives a right adjoint to `Filter.comap`, and because it has a nice
interpretation when working with `co-` filters (`Filter.cocompact`, `Filter.cofinite`, ...).
For example, `kernMap m (cocompact α)` is the filter generated by the complements of the sets
`m '' K` where `K` is a compact subset of `α`. -/
def kernMap (m : α → β) (f : Filter α) : Filter β where
sets := (kernImage m) '' f.sets
univ_sets := ⟨univ, f.univ_sets, by simp [kernImage_eq_compl]⟩
sets_of_superset := by
rintro _ t ⟨s, hs, rfl⟩ hst
refine ⟨s ∪ m ⁻¹' t, mem_of_superset hs subset_union_left, ?_⟩
rw [kernImage_union_preimage, union_eq_right.mpr hst]
inter_sets := by
rintro _ _ ⟨s₁, h₁, rfl⟩ ⟨s₂, h₂, rfl⟩
exact ⟨s₁ ∩ s₂, f.inter_sets h₁ h₂, Set.preimage_kernImage.u_inf⟩
variable {m : α → β} {f : Filter α}
theorem mem_kernMap {s : Set β} : s ∈ kernMap m f ↔ ∃ t ∈ f, kernImage m t = s :=
Iff.rfl
theorem mem_kernMap_iff_compl {s : Set β} : s ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = sᶜ := by
rw [mem_kernMap, compl_surjective.exists]
refine exists_congr (fun x ↦ and_congr_right fun _ ↦ ?_)
rw [kernImage_compl, compl_eq_comm, eq_comm]
theorem compl_mem_kernMap {s : Set β} : sᶜ ∈ kernMap m f ↔ ∃ t, tᶜ ∈ f ∧ m '' t = s := by
simp_rw [mem_kernMap_iff_compl, compl_compl]
end KernMap
/-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`.
Unfortunately, this `bind` does not result in the expected applicative. See `Filter.seq` for the
applicative instance. -/
def bind (f : Filter α) (m : α → Filter β) : Filter β :=
join (map m f)
/-- The applicative sequentiation operation. This is not induced by the bind operation. -/
def seq (f : Filter (α → β)) (g : Filter α) : Filter β where
sets := { s | ∃ u ∈ f, ∃ t ∈ g, ∀ m ∈ u, ∀ x ∈ t, (m : α → β) x ∈ s }
univ_sets := ⟨univ, univ_mem, univ, univ_mem, fun _ _ _ _ => trivial⟩
sets_of_superset := fun ⟨t₀, t₁, h₀, h₁, h⟩ hst =>
⟨t₀, t₁, h₀, h₁, fun _ hx _ hy => hst <| h _ hx _ hy⟩
inter_sets := fun ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩ =>
⟨t₀ ∩ u₀, inter_mem ht₀ hu₀, t₁ ∩ u₁, inter_mem ht₁ hu₁, fun _ ⟨hx₀, hx₁⟩ _ ⟨hy₀, hy₁⟩ =>
⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩
/-- `pure x` is the set of sets that contain `x`. It is equal to `𝓟 {x}` but
with this definition we have `s ∈ pure a` defeq `a ∈ s`. -/
instance : Pure Filter :=
⟨fun x =>
{ sets := { s | x ∈ s }
inter_sets := And.intro
sets_of_superset := fun hs hst => hst hs
univ_sets := trivial }⟩
instance : Bind Filter :=
⟨@Filter.bind⟩
instance : Functor Filter where map := @Filter.map
instance : LawfulFunctor (Filter : Type u → Type u) where
id_map _ := map_id
comp_map _ _ _ := map_map.symm
map_const := rfl
theorem pure_sets (a : α) : (pure a : Filter α).sets = { s | a ∈ s } :=
rfl
@[simp]
theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Filter α) ↔ a ∈ s :=
Iff.rfl
@[simp]
theorem eventually_pure {a : α} {p : α → Prop} : (∀ᶠ x in pure a, p x) ↔ p a :=
Iff.rfl
@[simp]
theorem principal_singleton (a : α) : 𝓟 {a} = pure a :=
Filter.ext fun s => by simp only [mem_pure, mem_principal, singleton_subset_iff]
@[simp]
theorem map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) :=
rfl
theorem pure_le_principal {s : Set α} (a : α) : pure a ≤ 𝓟 s ↔ a ∈ s := by
simp
@[simp] theorem join_pure (f : Filter α) : join (pure f) = f := rfl
@[simp]
theorem pure_bind (a : α) (m : α → Filter β) : bind (pure a) m = m a := by
simp only [Bind.bind, bind, map_pure, join_pure]
theorem map_bind {α β} (m : β → γ) (f : Filter α) (g : α → Filter β) :
map m (bind f g) = bind f (map m ∘ g) :=
rfl
theorem bind_map {α β} (m : α → β) (f : Filter α) (g : β → Filter γ) :
(bind (map m f) g) = bind f (g ∘ m) :=
rfl
/-!
### `Filter` as a `Monad`
In this section we define `Filter.monad`, a `Monad` structure on `Filter`s. This definition is not
an instance because its `Seq` projection is not equal to the `Filter.seq` function we use in the
`Applicative` instance on `Filter`.
-/
section
/-- The monad structure on filters. -/
protected def monad : Monad Filter where map := @Filter.map
attribute [local instance] Filter.monad
protected theorem lawfulMonad : LawfulMonad Filter where
map_const := rfl
id_map _ := rfl
seqLeft_eq _ _ := rfl
seqRight_eq _ _ := rfl
pure_seq _ _ := rfl
bind_pure_comp _ _ := rfl
bind_map _ _ := rfl
pure_bind _ _ := rfl
bind_assoc _ _ _ := rfl
end
instance : Alternative Filter where
seq := fun x y => x.seq (y ())
failure := ⊥
orElse x y := x ⊔ y ()
@[simp]
theorem map_def {α β} (m : α → β) (f : Filter α) : m <$> f = map m f :=
rfl
@[simp]
theorem bind_def {α β} (f : Filter α) (m : α → Filter β) : f >>= m = bind f m :=
rfl
/-! #### `map` and `comap` equations -/
section Map
variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Filter β} {m : α → β} {m' : β → γ} {s : Set α} {t : Set β}
@[simp] theorem mem_comap : s ∈ comap m g ↔ ∃ t ∈ g, m ⁻¹' t ⊆ s := Iff.rfl
theorem preimage_mem_comap (ht : t ∈ g) : m ⁻¹' t ∈ comap m g :=
⟨t, ht, Subset.rfl⟩
theorem Eventually.comap {p : β → Prop} (hf : ∀ᶠ b in g, p b) (f : α → β) :
∀ᶠ a in comap f g, p (f a) :=
preimage_mem_comap hf
theorem comap_id : comap id f = f :=
le_antisymm (fun _ => preimage_mem_comap) fun _ ⟨_, ht, hst⟩ => mem_of_superset ht hst
theorem comap_id' : comap (fun x => x) f = f := comap_id
theorem comap_const_of_not_mem {x : β} (ht : t ∈ g) (hx : x ∉ t) : comap (fun _ : α => x) g = ⊥ :=
empty_mem_iff_bot.1 <| mem_comap'.2 <| mem_of_superset ht fun _ hx' _ h => hx <| h.symm ▸ hx'
theorem comap_const_of_mem {x : β} (h : ∀ t ∈ g, x ∈ t) : comap (fun _ : α => x) g = ⊤ :=
top_unique fun _ hs => univ_mem' fun _ => h _ (mem_comap'.1 hs) rfl
theorem map_const [NeBot f] {c : β} : (f.map fun _ => c) = pure c := by
ext s
by_cases h : c ∈ s <;> simp [h]
theorem comap_comap {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f :=
Filter.coext fun s => by simp only [compl_mem_comap, image_image, (· ∘ ·)]
section comm
/-!
The variables in the following lemmas are used as in this diagram:
```
φ
α → β
θ ↓ ↓ ψ
γ → δ
ρ
```
-/
variable {φ : α → β} {θ : α → γ} {ψ : β → δ} {ρ : γ → δ}
theorem map_comm (H : ψ ∘ φ = ρ ∘ θ) (F : Filter α) :
map ψ (map φ F) = map ρ (map θ F) := by
rw [Filter.map_map, H, ← Filter.map_map]
theorem comap_comm (H : ψ ∘ φ = ρ ∘ θ) (G : Filter δ) :
comap φ (comap ψ G) = comap θ (comap ρ G) := by
rw [Filter.comap_comap, H, ← Filter.comap_comap]
end comm
theorem _root_.Function.Semiconj.filter_map {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) :=
map_comm h.comp_eq
theorem _root_.Function.Commute.filter_map {f g : α → α} (h : Function.Commute f g) :
Function.Commute (map f) (map g) :=
h.semiconj.filter_map
theorem _root_.Function.Semiconj.filter_comap {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (comap f) (comap gb) (comap ga) :=
comap_comm h.comp_eq.symm
theorem _root_.Function.Commute.filter_comap {f g : α → α} (h : Function.Commute f g) :
Function.Commute (comap f) (comap g) :=
h.semiconj.filter_comap
section
open Filter
theorem _root_.Function.LeftInverse.filter_map {f : α → β} {g : β → α} (hfg : LeftInverse g f) :
LeftInverse (map g) (map f) := fun F ↦ by
rw [map_map, hfg.comp_eq_id, map_id]
theorem _root_.Function.LeftInverse.filter_comap {f : α → β} {g : β → α} (hfg : LeftInverse g f) :
RightInverse (comap g) (comap f) := fun F ↦ by
rw [comap_comap, hfg.comp_eq_id, comap_id]
nonrec theorem _root_.Function.RightInverse.filter_map {f : α → β} {g : β → α}
(hfg : RightInverse g f) : RightInverse (map g) (map f) :=
hfg.filter_map
nonrec theorem _root_.Function.RightInverse.filter_comap {f : α → β} {g : β → α}
(hfg : RightInverse g f) : LeftInverse (comap g) (comap f) :=
hfg.filter_comap
theorem _root_.Set.LeftInvOn.filter_map_Iic {f : α → β} {g : β → α} (hfg : LeftInvOn g f s) :
LeftInvOn (map g) (map f) (Iic <| 𝓟 s) := fun F (hF : F ≤ 𝓟 s) ↦ by
have : (g ∘ f) =ᶠ[𝓟 s] id := by simpa only [eventuallyEq_principal] using hfg
rw [map_map, map_congr (this.filter_mono hF), map_id]
nonrec theorem _root_.Set.RightInvOn.filter_map_Iic {f : α → β} {g : β → α}
(hfg : RightInvOn g f t) : RightInvOn (map g) (map f) (Iic <| 𝓟 t) :=
hfg.filter_map_Iic
end
@[simp]
theorem comap_principal {t : Set β} : comap m (𝓟 t) = 𝓟 (m ⁻¹' t) :=
Filter.ext fun _ => ⟨fun ⟨_u, hu, b⟩ => (preimage_mono hu).trans b,
fun h => ⟨t, Subset.rfl, h⟩⟩
theorem principal_subtype {α : Type*} (s : Set α) (t : Set s) :
𝓟 t = comap (↑) (𝓟 (((↑) : s → α) '' t)) := by
rw [comap_principal, preimage_image_eq _ Subtype.coe_injective]
@[simp]
theorem comap_pure {b : β} : comap m (pure b) = 𝓟 (m ⁻¹' {b}) := by
rw [← principal_singleton, comap_principal]
theorem map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g :=
⟨fun h _ ⟨_, ht, hts⟩ => mem_of_superset (h ht) hts, fun h _ ht => h ⟨_, ht, Subset.rfl⟩⟩
theorem gc_map_comap (m : α → β) : GaloisConnection (map m) (comap m) :=
fun _ _ => map_le_iff_le_comap
theorem comap_le_iff_le_kernMap : comap m g ≤ f ↔ g ≤ kernMap m f := by
simp [Filter.le_def, mem_comap'', mem_kernMap, -mem_comap]
theorem gc_comap_kernMap (m : α → β) : GaloisConnection (comap m) (kernMap m) :=
fun _ _ ↦ comap_le_iff_le_kernMap
theorem kernMap_principal {s : Set α} : kernMap m (𝓟 s) = 𝓟 (kernImage m s) := by
refine eq_of_forall_le_iff (fun g ↦ ?_)
rw [← comap_le_iff_le_kernMap, le_principal_iff, le_principal_iff, mem_comap'']
@[mono]
theorem map_mono : Monotone (map m) :=
(gc_map_comap m).monotone_l
@[mono]
theorem comap_mono : Monotone (comap m) :=
(gc_map_comap m).monotone_u
/-- Temporary lemma that we can tag with `gcongr` -/
@[gcongr] theorem _root_.GCongr.Filter.map_le_map {F G : Filter α} (h : F ≤ G) :
map m F ≤ map m G := map_mono h
/-- Temporary lemma that we can tag with `gcongr` -/
@[gcongr]
theorem _root_.GCongr.Filter.comap_le_comap {F G : Filter β} (h : F ≤ G) :
comap m F ≤ comap m G := comap_mono h
@[simp] theorem map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot
@[simp] theorem map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup
@[simp]
theorem map_iSup {f : ι → Filter α} : map m (⨆ i, f i) = ⨆ i, map m (f i) :=
(gc_map_comap m).l_iSup
@[simp]
theorem map_top (f : α → β) : map f ⊤ = 𝓟 (range f) := by
rw [← principal_univ, map_principal, image_univ]
@[simp] theorem comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top
@[simp] theorem comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf
@[simp]
theorem comap_iInf {f : ι → Filter β} : comap m (⨅ i, f i) = ⨅ i, comap m (f i) :=
(gc_map_comap m).u_iInf
theorem le_comap_top (f : α → β) (l : Filter α) : l ≤ comap f ⊤ := by
rw [comap_top]
exact le_top
theorem map_comap_le : map m (comap m g) ≤ g :=
(gc_map_comap m).l_u_le _
theorem le_comap_map : f ≤ comap m (map m f) :=
(gc_map_comap m).le_u_l _
@[simp]
theorem comap_bot : comap m ⊥ = ⊥ :=
bot_unique fun s _ => ⟨∅, mem_bot, by simp only [empty_subset, preimage_empty]⟩
theorem neBot_of_comap (h : (comap m g).NeBot) : g.NeBot := by
rw [neBot_iff] at *
contrapose! h
rw [h]
exact comap_bot
theorem comap_inf_principal_range : comap m (g ⊓ 𝓟 (range m)) = comap m g := by
simp
theorem disjoint_comap (h : Disjoint g₁ g₂) : Disjoint (comap m g₁) (comap m g₂) := by
simp only [disjoint_iff, ← comap_inf, h.eq_bot, comap_bot]
theorem comap_iSup {ι} {f : ι → Filter β} {m : α → β} : comap m (iSup f) = ⨆ i, comap m (f i) :=
(gc_comap_kernMap m).l_iSup
theorem comap_sSup {s : Set (Filter β)} {m : α → β} : comap m (sSup s) = ⨆ f ∈ s, comap m f := by
simp only [sSup_eq_iSup, comap_iSup, eq_self_iff_true]
theorem comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := by
rw [sup_eq_iSup, comap_iSup, iSup_bool_eq, Bool.cond_true, Bool.cond_false]
theorem map_comap (f : Filter β) (m : α → β) : (f.comap m).map m = f ⊓ 𝓟 (range m) := by
refine le_antisymm (le_inf map_comap_le <| le_principal_iff.2 range_mem_map) ?_
rintro t' ⟨t, ht, sub⟩
refine mem_inf_principal.2 (mem_of_superset ht ?_)
rintro _ hxt ⟨x, rfl⟩
exact sub hxt
theorem map_comap_setCoe_val (f : Filter β) (s : Set β) :
(f.comap ((↑) : s → β)).map (↑) = f ⊓ 𝓟 s := by
rw [map_comap, Subtype.range_val]
theorem map_comap_of_mem {f : Filter β} {m : α → β} (hf : range m ∈ f) : (f.comap m).map m = f := by
rw [map_comap, inf_eq_left.2 (le_principal_iff.2 hf)]
instance canLift (c) (p) [CanLift α β c p] :
CanLift (Filter α) (Filter β) (map c) fun f => ∀ᶠ x : α in f, p x where
prf f hf := ⟨comap c f, map_comap_of_mem <| hf.mono CanLift.prf⟩
theorem comap_le_comap_iff {f g : Filter β} {m : α → β} (hf : range m ∈ f) :
comap m f ≤ comap m g ↔ f ≤ g :=
⟨fun h => map_comap_of_mem hf ▸ (map_mono h).trans map_comap_le, fun h => comap_mono h⟩
theorem map_comap_of_surjective {f : α → β} (hf : Surjective f) (l : Filter β) :
map f (comap f l) = l :=
map_comap_of_mem <| by simp only [hf.range_eq, univ_mem]
theorem comap_injective {f : α → β} (hf : Surjective f) : Injective (comap f) :=
LeftInverse.injective <| map_comap_of_surjective hf
theorem _root_.Function.Surjective.filter_map_top {f : α → β} (hf : Surjective f) : map f ⊤ = ⊤ :=
(congr_arg _ comap_top).symm.trans <| map_comap_of_surjective hf ⊤
theorem subtype_coe_map_comap (s : Set α) (f : Filter α) :
map ((↑) : s → α) (comap ((↑) : s → α) f) = f ⊓ 𝓟 s := by rw [map_comap, Subtype.range_coe]
theorem image_mem_of_mem_comap {f : Filter α} {c : β → α} (h : range c ∈ f) {W : Set β}
(W_in : W ∈ comap c f) : c '' W ∈ f := by
rw [← map_comap_of_mem h]
exact image_mem_map W_in
theorem image_coe_mem_of_mem_comap {f : Filter α} {U : Set α} (h : U ∈ f) {W : Set U}
(W_in : W ∈ comap ((↑) : U → α) f) : (↑) '' W ∈ f :=
image_mem_of_mem_comap (by simp [h]) W_in
theorem comap_map {f : Filter α} {m : α → β} (h : Injective m) : comap m (map m f) = f :=
le_antisymm
(fun s hs =>
mem_of_superset (preimage_mem_comap <| image_mem_map hs) <| by
simp only [preimage_image_eq s h, Subset.rfl])
le_comap_map
theorem mem_comap_iff {f : Filter β} {m : α → β} (inj : Injective m) (large : Set.range m ∈ f)
{S : Set α} : S ∈ comap m f ↔ m '' S ∈ f := by
rw [← image_mem_map_iff inj, map_comap_of_mem large]
theorem map_le_map_iff_of_injOn {l₁ l₂ : Filter α} {f : α → β} {s : Set α} (h₁ : s ∈ l₁)
(h₂ : s ∈ l₂) (hinj : InjOn f s) : map f l₁ ≤ map f l₂ ↔ l₁ ≤ l₂ :=
⟨fun h _t ht =>
mp_mem h₁ <|
mem_of_superset (h <| image_mem_map (inter_mem h₂ ht)) fun _y ⟨_x, ⟨hxs, hxt⟩, hxy⟩ hys =>
hinj hxs hys hxy ▸ hxt,
fun h => map_mono h⟩
theorem map_le_map_iff {f g : Filter α} {m : α → β} (hm : Injective m) :
map m f ≤ map m g ↔ f ≤ g := by rw [map_le_iff_le_comap, comap_map hm]
theorem map_eq_map_iff_of_injOn {f g : Filter α} {m : α → β} {s : Set α} (hsf : s ∈ f) (hsg : s ∈ g)
(hm : InjOn m s) : map m f = map m g ↔ f = g := by
simp only [le_antisymm_iff, map_le_map_iff_of_injOn hsf hsg hm,
map_le_map_iff_of_injOn hsg hsf hm]
theorem map_inj {f g : Filter α} {m : α → β} (hm : Injective m) : map m f = map m g ↔ f = g :=
map_eq_map_iff_of_injOn univ_mem univ_mem hm.injOn
theorem map_injective {m : α → β} (hm : Injective m) : Injective (map m) := fun _ _ =>
(map_inj hm).1
theorem comap_neBot_iff {f : Filter β} {m : α → β} : NeBot (comap m f) ↔ ∀ t ∈ f, ∃ a, m a ∈ t := by
simp only [← forall_mem_nonempty_iff_neBot, mem_comap, forall_exists_index, and_imp]
exact ⟨fun h t t_in => h (m ⁻¹' t) t t_in Subset.rfl, fun h s t ht hst => (h t ht).imp hst⟩
theorem comap_neBot {f : Filter β} {m : α → β} (hm : ∀ t ∈ f, ∃ a, m a ∈ t) : NeBot (comap m f) :=
comap_neBot_iff.mpr hm
theorem comap_neBot_iff_frequently {f : Filter β} {m : α → β} :
NeBot (comap m f) ↔ ∃ᶠ y in f, y ∈ range m := by
simp only [comap_neBot_iff, frequently_iff, mem_range, @and_comm (_ ∈ _), exists_exists_eq_and]
theorem comap_neBot_iff_compl_range {f : Filter β} {m : α → β} :
NeBot (comap m f) ↔ (range m)ᶜ ∉ f :=
comap_neBot_iff_frequently
theorem comap_eq_bot_iff_compl_range {f : Filter β} {m : α → β} : comap m f = ⊥ ↔ (range m)ᶜ ∈ f :=
not_iff_not.mp <| neBot_iff.symm.trans comap_neBot_iff_compl_range
theorem comap_surjective_eq_bot {f : Filter β} {m : α → β} (hm : Surjective m) :
comap m f = ⊥ ↔ f = ⊥ := by
rw [comap_eq_bot_iff_compl_range, hm.range_eq, compl_univ, empty_mem_iff_bot]
theorem disjoint_comap_iff (h : Surjective m) :
Disjoint (comap m g₁) (comap m g₂) ↔ Disjoint g₁ g₂ := by
rw [disjoint_iff, disjoint_iff, ← comap_inf, comap_surjective_eq_bot h]
theorem NeBot.comap_of_range_mem {f : Filter β} {m : α → β} (_ : NeBot f) (hm : range m ∈ f) :
NeBot (comap m f) :=
comap_neBot_iff_frequently.2 <| Eventually.frequently hm
@[simp]
theorem comap_fst_neBot_iff {f : Filter α} :
(f.comap (Prod.fst : α × β → α)).NeBot ↔ f.NeBot ∧ Nonempty β := by
cases isEmpty_or_nonempty β
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp [*]
· simp [comap_neBot_iff_frequently, *]
@[instance]
theorem comap_fst_neBot [Nonempty β] {f : Filter α} [NeBot f] :
(f.comap (Prod.fst : α × β → α)).NeBot :=
comap_fst_neBot_iff.2 ⟨‹_›, ‹_›⟩
@[simp]
theorem comap_snd_neBot_iff {f : Filter β} :
(f.comap (Prod.snd : α × β → β)).NeBot ↔ Nonempty α ∧ f.NeBot := by
cases' isEmpty_or_nonempty α with hα hα
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]; simp
· simp [comap_neBot_iff_frequently, hα]
@[instance]
theorem comap_snd_neBot [Nonempty α] {f : Filter β} [NeBot f] :
(f.comap (Prod.snd : α × β → β)).NeBot :=
comap_snd_neBot_iff.2 ⟨‹_›, ‹_›⟩
theorem comap_eval_neBot_iff' {ι : Type*} {α : ι → Type*} {i : ι} {f : Filter (α i)} :
(comap (eval i) f).NeBot ↔ (∀ j, Nonempty (α j)) ∧ NeBot f := by
cases' isEmpty_or_nonempty (∀ j, α j) with H H
· rw [filter_eq_bot_of_isEmpty (f.comap _), ← not_iff_not]
simp [← Classical.nonempty_pi]
· have : ∀ j, Nonempty (α j) := Classical.nonempty_pi.1 H
simp [comap_neBot_iff_frequently, *]
@[simp]
theorem comap_eval_neBot_iff {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] {i : ι}
{f : Filter (α i)} : (comap (eval i) f).NeBot ↔ NeBot f := by simp [comap_eval_neBot_iff', *]
@[instance]
theorem comap_eval_neBot {ι : Type*} {α : ι → Type*} [∀ j, Nonempty (α j)] (i : ι)
(f : Filter (α i)) [NeBot f] : (comap (eval i) f).NeBot :=
comap_eval_neBot_iff.2 ‹_›
theorem comap_inf_principal_neBot_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α}
(hs : m '' s ∈ f) : NeBot (comap m f ⊓ 𝓟 s) := by
refine ⟨compl_compl s ▸ mt mem_of_eq_bot ?_⟩
rintro ⟨t, ht, hts⟩
rcases hf.nonempty_of_mem (inter_mem hs ht) with ⟨_, ⟨x, hxs, rfl⟩, hxt⟩
exact absurd hxs (hts hxt)
theorem comap_coe_neBot_of_le_principal {s : Set γ} {l : Filter γ} [h : NeBot l] (h' : l ≤ 𝓟 s) :
NeBot (comap ((↑) : s → γ) l) :=
h.comap_of_range_mem <| (@Subtype.range_coe γ s).symm ▸ h' (mem_principal_self s)
theorem NeBot.comap_of_surj {f : Filter β} {m : α → β} (hf : NeBot f) (hm : Surjective m) :
NeBot (comap m f) :=
hf.comap_of_range_mem <| univ_mem' hm
theorem NeBot.comap_of_image_mem {f : Filter β} {m : α → β} (hf : NeBot f) {s : Set α}
(hs : m '' s ∈ f) : NeBot (comap m f) :=
hf.comap_of_range_mem <| mem_of_superset hs (image_subset_range _ _)
@[simp]
theorem map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ :=
⟨by
rw [← empty_mem_iff_bot, ← empty_mem_iff_bot]
exact id, fun h => by simp only [h, map_bot]⟩
theorem map_neBot_iff (f : α → β) {F : Filter α} : NeBot (map f F) ↔ NeBot F := by
simp only [neBot_iff, Ne, map_eq_bot_iff]
theorem NeBot.map (hf : NeBot f) (m : α → β) : NeBot (map m f) :=
(map_neBot_iff m).2 hf
theorem NeBot.of_map : NeBot (f.map m) → NeBot f :=
(map_neBot_iff m).1
instance map_neBot [hf : NeBot f] : NeBot (f.map m) :=
hf.map m
theorem sInter_comap_sets (f : α → β) (F : Filter β) : ⋂₀ (comap f F).sets = ⋂ U ∈ F, f ⁻¹' U := by
ext x
suffices (∀ (A : Set α) (B : Set β), B ∈ F → f ⁻¹' B ⊆ A → x ∈ A) ↔
∀ B : Set β, B ∈ F → f x ∈ B by
simp only [mem_sInter, mem_iInter, Filter.mem_sets, mem_comap, this, and_imp, exists_prop,
mem_preimage, exists_imp]
constructor
· intro h U U_in
simpa only [Subset.rfl, forall_prop_of_true, mem_preimage] using h (f ⁻¹' U) U U_in
· intro h V U U_in f_U_V
exact f_U_V (h U U_in)
end Map
-- this is a generic rule for monotone functions:
theorem map_iInf_le {f : ι → Filter α} {m : α → β} : map m (iInf f) ≤ ⨅ i, map m (f i) :=
le_iInf fun _ => map_mono <| iInf_le _ _
theorem map_iInf_eq {f : ι → Filter α} {m : α → β} (hf : Directed (· ≥ ·) f) [Nonempty ι] :
map m (iInf f) = ⨅ i, map m (f i) :=
map_iInf_le.antisymm fun s (hs : m ⁻¹' s ∈ iInf f) =>
let ⟨i, hi⟩ := (mem_iInf_of_directed hf _).1 hs
have : ⨅ i, map m (f i) ≤ 𝓟 s :=
iInf_le_of_le i <| by simpa only [le_principal_iff, mem_map]
Filter.le_principal_iff.1 this
theorem map_biInf_eq {ι : Type w} {f : ι → Filter α} {m : α → β} {p : ι → Prop}
(h : DirectedOn (f ⁻¹'o (· ≥ ·)) { x | p x }) (ne : ∃ i, p i) :
map m (⨅ (i) (_ : p i), f i) = ⨅ (i) (_ : p i), map m (f i) := by
haveI := nonempty_subtype.2 ne
simp only [iInf_subtype']
exact map_iInf_eq h.directed_val
theorem map_inf_le {f g : Filter α} {m : α → β} : map m (f ⊓ g) ≤ map m f ⊓ map m g :=
(@map_mono _ _ m).map_inf_le f g
theorem map_inf {f g : Filter α} {m : α → β} (h : Injective m) :
map m (f ⊓ g) = map m f ⊓ map m g := by
refine map_inf_le.antisymm ?_
rintro t ⟨s₁, hs₁, s₂, hs₂, ht : m ⁻¹' t = s₁ ∩ s₂⟩
refine mem_inf_of_inter (image_mem_map hs₁) (image_mem_map hs₂) ?_
rw [← image_inter h, image_subset_iff, ht]
theorem map_inf' {f g : Filter α} {m : α → β} {t : Set α} (htf : t ∈ f) (htg : t ∈ g)
(h : InjOn m t) : map m (f ⊓ g) = map m f ⊓ map m g := by
lift f to Filter t using htf; lift g to Filter t using htg
replace h : Injective (m ∘ ((↑) : t → α)) := h.injective
simp only [map_map, ← map_inf Subtype.coe_injective, map_inf h]
lemma disjoint_of_map {α β : Type*} {F G : Filter α} {f : α → β}
(h : Disjoint (map f F) (map f G)) : Disjoint F G :=
disjoint_iff.mpr <| map_eq_bot_iff.mp <| le_bot_iff.mp <| trans map_inf_le (disjoint_iff.mp h)
theorem disjoint_map {m : α → β} (hm : Injective m) {f₁ f₂ : Filter α} :
Disjoint (map m f₁) (map m f₂) ↔ Disjoint f₁ f₂ := by
simp only [disjoint_iff, ← map_inf hm, map_eq_bot_iff]
theorem map_equiv_symm (e : α ≃ β) (f : Filter β) : map e.symm f = comap e f :=
map_injective e.injective <| by
rw [map_map, e.self_comp_symm, map_id, map_comap_of_surjective e.surjective]
theorem map_eq_comap_of_inverse {f : Filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id)
(h₂ : n ∘ m = id) : map m f = comap n f :=
map_equiv_symm ⟨n, m, congr_fun h₁, congr_fun h₂⟩ f
theorem comap_equiv_symm (e : α ≃ β) (f : Filter α) : comap e.symm f = map e f :=
(map_eq_comap_of_inverse e.self_comp_symm e.symm_comp_self).symm
theorem map_swap_eq_comap_swap {f : Filter (α × β)} : Prod.swap <$> f = comap Prod.swap f :=
map_eq_comap_of_inverse Prod.swap_swap_eq Prod.swap_swap_eq
/-- A useful lemma when dealing with uniformities. -/
theorem map_swap4_eq_comap {f : Filter ((α × β) × γ × δ)} :
map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f =
comap (fun p : (α × γ) × β × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) f :=
map_eq_comap_of_inverse (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl) (funext fun ⟨⟨_, _⟩, ⟨_, _⟩⟩ => rfl)
theorem le_map {f : Filter α} {m : α → β} {g : Filter β} (h : ∀ s ∈ f, m '' s ∈ g) : g ≤ f.map m :=
fun _ hs => mem_of_superset (h _ hs) <| image_preimage_subset _ _
theorem le_map_iff {f : Filter α} {m : α → β} {g : Filter β} : g ≤ f.map m ↔ ∀ s ∈ f, m '' s ∈ g :=
⟨fun h _ hs => h (image_mem_map hs), le_map⟩
protected theorem push_pull (f : α → β) (F : Filter α) (G : Filter β) :
map f (F ⊓ comap f G) = map f F ⊓ G := by
apply le_antisymm
· calc
map f (F ⊓ comap f G) ≤ map f F ⊓ (map f <| comap f G) := map_inf_le
_ ≤ map f F ⊓ G := inf_le_inf_left (map f F) map_comap_le
· rintro U ⟨V, V_in, W, ⟨Z, Z_in, hZ⟩, h⟩
apply mem_inf_of_inter (image_mem_map V_in) Z_in
calc
f '' V ∩ Z = f '' (V ∩ f ⁻¹' Z) := by rw [image_inter_preimage]
_ ⊆ f '' (V ∩ W) := image_subset _ (inter_subset_inter_right _ ‹_›)
_ = f '' (f ⁻¹' U) := by rw [h]
_ ⊆ U := image_preimage_subset f U
protected theorem push_pull' (f : α → β) (F : Filter α) (G : Filter β) :
map f (comap f G ⊓ F) = G ⊓ map f F := by simp only [Filter.push_pull, inf_comm]
theorem principal_eq_map_coe_top (s : Set α) : 𝓟 s = map ((↑) : s → α) ⊤ := by simp
theorem inf_principal_eq_bot_iff_comap {F : Filter α} {s : Set α} :
F ⊓ 𝓟 s = ⊥ ↔ comap ((↑) : s → α) F = ⊥ := by
rw [principal_eq_map_coe_top s, ← Filter.push_pull', inf_top_eq, map_eq_bot_iff]
section Applicative
theorem singleton_mem_pure {a : α} : {a} ∈ (pure a : Filter α) :=
mem_singleton a
theorem pure_injective : Injective (pure : α → Filter α) := fun a _ hab =>
(Filter.ext_iff.1 hab { x | a = x }).1 rfl
instance pure_neBot {α : Type u} {a : α} : NeBot (pure a) :=
⟨mt empty_mem_iff_bot.2 <| not_mem_empty a⟩
@[simp]
theorem le_pure_iff {f : Filter α} {a : α} : f ≤ pure a ↔ {a} ∈ f := by
rw [← principal_singleton, le_principal_iff]
theorem mem_seq_def {f : Filter (α → β)} {g : Filter α} {s : Set β} :
s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, ∀ x ∈ u, ∀ y ∈ t, (x : α → β) y ∈ s :=
Iff.rfl
theorem mem_seq_iff {f : Filter (α → β)} {g : Filter α} {s : Set β} :
s ∈ f.seq g ↔ ∃ u ∈ f, ∃ t ∈ g, Set.seq u t ⊆ s := by
simp only [mem_seq_def, seq_subset, exists_prop, iff_self_iff]
theorem mem_map_seq_iff {f : Filter α} {g : Filter β} {m : α → β → γ} {s : Set γ} :
s ∈ (f.map m).seq g ↔ ∃ t u, t ∈ g ∧ u ∈ f ∧ ∀ x ∈ u, ∀ y ∈ t, m x y ∈ s :=
Iff.intro (fun ⟨t, ht, s, hs, hts⟩ => ⟨s, m ⁻¹' t, hs, ht, fun _ => hts _⟩)
fun ⟨t, s, ht, hs, hts⟩ =>
⟨m '' s, image_mem_map hs, t, ht, fun _ ⟨_, has, Eq⟩ => Eq ▸ hts _ has⟩
theorem seq_mem_seq {f : Filter (α → β)} {g : Filter α} {s : Set (α → β)} {t : Set α} (hs : s ∈ f)
(ht : t ∈ g) : s.seq t ∈ f.seq g :=
⟨s, hs, t, ht, fun f hf a ha => ⟨f, hf, a, ha, rfl⟩⟩
theorem le_seq {f : Filter (α → β)} {g : Filter α} {h : Filter β}
(hh : ∀ t ∈ f, ∀ u ∈ g, Set.seq t u ∈ h) : h ≤ seq f g := fun _ ⟨_, ht, _, hu, hs⟩ =>
mem_of_superset (hh _ ht _ hu) fun _ ⟨_, hm, _, ha, eq⟩ => eq ▸ hs _ hm _ ha
@[mono]
theorem seq_mono {f₁ f₂ : Filter (α → β)} {g₁ g₂ : Filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁.seq g₁ ≤ f₂.seq g₂ :=
le_seq fun _ hs _ ht => seq_mem_seq (hf hs) (hg ht)
@[simp]
theorem pure_seq_eq_map (g : α → β) (f : Filter α) : seq (pure g) f = f.map g := by
refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_)
· rw [← singleton_seq]
apply seq_mem_seq _ hs
exact singleton_mem_pure
· refine sets_of_superset (map g f) (image_mem_map ht) ?_
rintro b ⟨a, ha, rfl⟩
exact ⟨g, hs, a, ha, rfl⟩
@[simp]
theorem seq_pure (f : Filter (α → β)) (a : α) : seq f (pure a) = map (fun g : α → β => g a) f := by
refine le_antisymm (le_map fun s hs => ?_) (le_seq fun s hs t ht => ?_)
· rw [← seq_singleton]
exact seq_mem_seq hs singleton_mem_pure
· refine sets_of_superset (map (fun g : α → β => g a) f) (image_mem_map hs) ?_
rintro b ⟨g, hg, rfl⟩
exact ⟨g, hg, a, ht, rfl⟩
@[simp]
theorem seq_assoc (x : Filter α) (g : Filter (α → β)) (h : Filter (β → γ)) :
seq h (seq g x) = seq (seq (map (· ∘ ·) h) g) x := by
refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_)
· rcases mem_seq_iff.1 hs with ⟨u, hu, v, hv, hs⟩
rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hu⟩
refine mem_of_superset ?_ (Set.seq_mono ((Set.seq_mono hu Subset.rfl).trans hs) Subset.rfl)
rw [← Set.seq_seq]
exact seq_mem_seq hw (seq_mem_seq hv ht)
· rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩
refine mem_of_superset ?_ (Set.seq_mono Subset.rfl ht)
rw [Set.seq_seq]
exact seq_mem_seq (seq_mem_seq (image_mem_map hs) hu) hv
theorem prod_map_seq_comm (f : Filter α) (g : Filter β) :
(map Prod.mk f).seq g = seq (map (fun b a => (a, b)) g) f := by
refine le_antisymm (le_seq fun s hs t ht => ?_) (le_seq fun s hs t ht => ?_)
· rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩
refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl)
rw [← Set.prod_image_seq_comm]
exact seq_mem_seq (image_mem_map ht) hu
· rcases mem_map_iff_exists_image.1 hs with ⟨u, hu, hs⟩
refine mem_of_superset ?_ (Set.seq_mono hs Subset.rfl)
rw [Set.prod_image_seq_comm]
exact seq_mem_seq (image_mem_map ht) hu
theorem seq_eq_filter_seq {α β : Type u} (f : Filter (α → β)) (g : Filter α) :
f <*> g = seq f g :=
rfl
instance : LawfulApplicative (Filter : Type u → Type u) where
map_pure := map_pure
seqLeft_eq _ _ := rfl
seqRight_eq _ _ := rfl
seq_pure := seq_pure
pure_seq := pure_seq_eq_map
seq_assoc := seq_assoc
instance : CommApplicative (Filter : Type u → Type u) :=
⟨fun f g => prod_map_seq_comm f g⟩
end Applicative
/-! #### `bind` equations -/
section Bind
@[simp]
theorem eventually_bind {f : Filter α} {m : α → Filter β} {p : β → Prop} :
(∀ᶠ y in bind f m, p y) ↔ ∀ᶠ x in f, ∀ᶠ y in m x, p y :=
Iff.rfl
@[simp]
theorem eventuallyEq_bind {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} :
g₁ =ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ =ᶠ[m x] g₂ :=
Iff.rfl
@[simp]
theorem eventuallyLE_bind [LE γ] {f : Filter α} {m : α → Filter β} {g₁ g₂ : β → γ} :
g₁ ≤ᶠ[bind f m] g₂ ↔ ∀ᶠ x in f, g₁ ≤ᶠ[m x] g₂ :=
Iff.rfl
theorem mem_bind' {s : Set β} {f : Filter α} {m : α → Filter β} :
s ∈ bind f m ↔ { a | s ∈ m a } ∈ f :=
Iff.rfl
@[simp]
theorem mem_bind {s : Set β} {f : Filter α} {m : α → Filter β} :
s ∈ bind f m ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x :=
calc
s ∈ bind f m ↔ { a | s ∈ m a } ∈ f := Iff.rfl
_ ↔ ∃ t ∈ f, t ⊆ { a | s ∈ m a } := exists_mem_subset_iff.symm
_ ↔ ∃ t ∈ f, ∀ x ∈ t, s ∈ m x := Iff.rfl
theorem bind_le {f : Filter α} {g : α → Filter β} {l : Filter β} (h : ∀ᶠ x in f, g x ≤ l) :
f.bind g ≤ l :=
join_le <| eventually_map.2 h
@[mono]
theorem bind_mono {f₁ f₂ : Filter α} {g₁ g₂ : α → Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ᶠ[f₁] g₂) :
bind f₁ g₁ ≤ bind f₂ g₂ := by
refine le_trans (fun s hs => ?_) (join_mono <| map_mono hf)
simp only [mem_join, mem_bind', mem_map] at hs ⊢
filter_upwards [hg, hs] with _ hx hs using hx hs
theorem bind_inf_principal {f : Filter α} {g : α → Filter β} {s : Set β} :
(f.bind fun x => g x ⊓ 𝓟 s) = f.bind g ⊓ 𝓟 s :=
Filter.ext fun s => by simp only [mem_bind, mem_inf_principal]
theorem sup_bind {f g : Filter α} {h : α → Filter β} : bind (f ⊔ g) h = bind f h ⊔ bind g h := rfl
theorem principal_bind {s : Set α} {f : α → Filter β} : bind (𝓟 s) f = ⨆ x ∈ s, f x :=
show join (map f (𝓟 s)) = ⨆ x ∈ s, f x by
simp only [sSup_image, join_principal_eq_sSup, map_principal, eq_self_iff_true]
end Bind
/-! ### Limits -/
/-- `Filter.Tendsto` is the generic "limit of a function" predicate.
`Tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`,
the `f`-preimage of `a` is an `l₁` neighborhood. -/
def Tendsto (f : α → β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁.map f ≤ l₂
theorem tendsto_def {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f ⁻¹' s ∈ l₁ :=
Iff.rfl
theorem tendsto_iff_eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ ⦃p : β → Prop⦄, (∀ᶠ y in l₂, p y) → ∀ᶠ x in l₁, p (f x) :=
Iff.rfl
theorem tendsto_iff_forall_eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, ∀ᶠ x in l₁, f x ∈ s :=
Iff.rfl
lemma Tendsto.eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {s : Set β}
(hf : Tendsto f l₁ l₂) (h : s ∈ l₂) : ∀ᶠ x in l₁, f x ∈ s :=
hf h
theorem Tendsto.eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∀ᶠ y in l₂, p y) : ∀ᶠ x in l₁, p (f x) :=
hf h
theorem not_tendsto_iff_exists_frequently_nmem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
¬Tendsto f l₁ l₂ ↔ ∃ s ∈ l₂, ∃ᶠ x in l₁, f x ∉ s := by
simp only [tendsto_iff_forall_eventually_mem, not_forall, exists_prop, not_eventually]
theorem Tendsto.frequently {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∃ᶠ x in l₁, p (f x)) : ∃ᶠ y in l₂, p y :=
mt hf.eventually h
theorem Tendsto.frequently_map {l₁ : Filter α} {l₂ : Filter β} {p : α → Prop} {q : β → Prop}
(f : α → β) (c : Filter.Tendsto f l₁ l₂) (w : ∀ x, p x → q (f x)) (h : ∃ᶠ x in l₁, p x) :
∃ᶠ y in l₂, q y :=
c.frequently (h.mono w)
@[simp]
theorem tendsto_bot {f : α → β} {l : Filter β} : Tendsto f ⊥ l := by simp [Tendsto]
@[simp] theorem tendsto_top {f : α → β} {l : Filter α} : Tendsto f l ⊤ := le_top
theorem le_map_of_right_inverse {mab : α → β} {mba : β → α} {f : Filter α} {g : Filter β}
(h₁ : mab ∘ mba =ᶠ[g] id) (h₂ : Tendsto mba g f) : g ≤ map mab f := by
rw [← @map_id _ g, ← map_congr h₁, ← map_map]
exact map_mono h₂
theorem tendsto_of_isEmpty [IsEmpty α] {f : α → β} {la : Filter α} {lb : Filter β} :
Tendsto f la lb := by simp only [filter_eq_bot_of_isEmpty la, tendsto_bot]
theorem eventuallyEq_of_left_inv_of_right_inv {f : α → β} {g₁ g₂ : β → α} {fa : Filter α}
{fb : Filter β} (hleft : ∀ᶠ x in fa, g₁ (f x) = x) (hright : ∀ᶠ y in fb, f (g₂ y) = y)
(htendsto : Tendsto g₂ fb fa) : g₁ =ᶠ[fb] g₂ :=
(htendsto.eventually hleft).mp <| hright.mono fun _ hr hl => (congr_arg g₁ hr.symm).trans hl
theorem tendsto_iff_comap {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f :=
map_le_iff_le_comap
alias ⟨Tendsto.le_comap, _⟩ := tendsto_iff_comap
protected theorem Tendsto.disjoint {f : α → β} {la₁ la₂ : Filter α} {lb₁ lb₂ : Filter β}
(h₁ : Tendsto f la₁ lb₁) (hd : Disjoint lb₁ lb₂) (h₂ : Tendsto f la₂ lb₂) : Disjoint la₁ la₂ :=
(disjoint_comap hd).mono h₁.le_comap h₂.le_comap
theorem tendsto_congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ := by rw [Tendsto, Tendsto, map_congr hl]
theorem Tendsto.congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂)
(h : Tendsto f₁ l₁ l₂) : Tendsto f₂ l₁ l₂ :=
(tendsto_congr' hl).1 h
theorem tendsto_congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ :=
tendsto_congr' (univ_mem' h)
theorem Tendsto.congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ → Tendsto f₂ l₁ l₂ :=
(tendsto_congr h).1
theorem tendsto_id' {x y : Filter α} : Tendsto id x y ↔ x ≤ y :=
Iff.rfl
theorem tendsto_id {x : Filter α} : Tendsto id x x :=
le_refl x
theorem Tendsto.comp {f : α → β} {g : β → γ} {x : Filter α} {y : Filter β} {z : Filter γ}
(hg : Tendsto g y z) (hf : Tendsto f x y) : Tendsto (g ∘ f) x z := fun _ hs => hf (hg hs)
protected theorem Tendsto.iterate {f : α → α} {l : Filter α} (h : Tendsto f l l) :
∀ n, Tendsto (f^[n]) l l
| 0 => tendsto_id
| (n + 1) => (h.iterate n).comp h
theorem Tendsto.mono_left {f : α → β} {x y : Filter α} {z : Filter β} (hx : Tendsto f x z)
(h : y ≤ x) : Tendsto f y z :=
(map_mono h).trans hx
theorem Tendsto.mono_right {f : α → β} {x : Filter α} {y z : Filter β} (hy : Tendsto f x y)
(hz : y ≤ z) : Tendsto f x z :=
le_trans hy hz
theorem Tendsto.neBot {f : α → β} {x : Filter α} {y : Filter β} (h : Tendsto f x y) [hx : NeBot x] :
NeBot y :=
(hx.map _).mono h
theorem tendsto_map {f : α → β} {x : Filter α} : Tendsto f x (map f x) :=
le_refl (map f x)
@[simp]
theorem tendsto_map'_iff {f : β → γ} {g : α → β} {x : Filter α} {y : Filter γ} :
Tendsto f (map g x) y ↔ Tendsto (f ∘ g) x y := by
rw [Tendsto, Tendsto, map_map]
alias ⟨_, tendsto_map'⟩ := tendsto_map'_iff
theorem tendsto_comap {f : α → β} {x : Filter β} : Tendsto f (comap f x) x :=
map_comap_le
@[simp]
theorem tendsto_comap_iff {f : α → β} {g : β → γ} {a : Filter α} {c : Filter γ} :
Tendsto f a (c.comap g) ↔ Tendsto (g ∘ f) a c :=
⟨fun h => tendsto_comap.comp h, fun h => map_le_iff_le_comap.mp <| by rwa [map_map]⟩
theorem tendsto_comap'_iff {m : α → β} {f : Filter α} {g : Filter β} {i : γ → α} (h : range i ∈ f) :
Tendsto (m ∘ i) (comap i f) g ↔ Tendsto m f g := by
rw [Tendsto, ← map_compose]
simp only [(· ∘ ·), map_comap_of_mem h, Tendsto]
theorem Tendsto.of_tendsto_comp {f : α → β} {g : β → γ} {a : Filter α} {b : Filter β} {c : Filter γ}
(hfg : Tendsto (g ∘ f) a c) (hg : comap g c ≤ b) : Tendsto f a b := by
rw [tendsto_iff_comap] at hfg ⊢
calc
a ≤ comap (g ∘ f) c := hfg
_ ≤ comap f b := by simpa [comap_comap] using comap_mono hg
theorem comap_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : ψ ∘ φ = id)
(hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : comap φ g = f := by
refine ((comap_mono <| map_le_iff_le_comap.1 hψ).trans ?_).antisymm (map_le_iff_le_comap.1 hφ)
rw [comap_comap, eq, comap_id]
theorem map_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : φ ∘ ψ = id)
(hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : map φ f = g := by
refine le_antisymm hφ (le_trans ?_ (map_mono hψ))
rw [map_map, eq, map_id]
theorem tendsto_inf {f : α → β} {x : Filter α} {y₁ y₂ : Filter β} :
Tendsto f x (y₁ ⊓ y₂) ↔ Tendsto f x y₁ ∧ Tendsto f x y₂ := by
simp only [Tendsto, le_inf_iff, iff_self_iff]
theorem tendsto_inf_left {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₁ y) :
Tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_left) h
theorem tendsto_inf_right {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₂ y) :
Tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_right) h
theorem Tendsto.inf {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β} (h₁ : Tendsto f x₁ y₁)
(h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊓ x₂) (y₁ ⊓ y₂) :=
tendsto_inf.2 ⟨tendsto_inf_left h₁, tendsto_inf_right h₂⟩
@[simp]
theorem tendsto_iInf {f : α → β} {x : Filter α} {y : ι → Filter β} :
Tendsto f x (⨅ i, y i) ↔ ∀ i, Tendsto f x (y i) := by
simp only [Tendsto, iff_self_iff, le_iInf_iff]
theorem tendsto_iInf' {f : α → β} {x : ι → Filter α} {y : Filter β} (i : ι)
(hi : Tendsto f (x i) y) : Tendsto f (⨅ i, x i) y :=
hi.mono_left <| iInf_le _ _
theorem tendsto_iInf_iInf {f : α → β} {x : ι → Filter α} {y : ι → Filter β}
(h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iInf x) (iInf y) :=
tendsto_iInf.2 fun i => tendsto_iInf' i (h i)
@[simp]
theorem tendsto_sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} :
Tendsto f (x₁ ⊔ x₂) y ↔ Tendsto f x₁ y ∧ Tendsto f x₂ y := by
simp only [Tendsto, map_sup, sup_le_iff]
theorem Tendsto.sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} :
Tendsto f x₁ y → Tendsto f x₂ y → Tendsto f (x₁ ⊔ x₂) y := fun h₁ h₂ => tendsto_sup.mpr ⟨h₁, h₂⟩
theorem Tendsto.sup_sup {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β}
(h₁ : Tendsto f x₁ y₁) (h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊔ x₂) (y₁ ⊔ y₂) :=
tendsto_sup.mpr ⟨h₁.mono_right le_sup_left, h₂.mono_right le_sup_right⟩
@[simp]
theorem tendsto_iSup {f : α → β} {x : ι → Filter α} {y : Filter β} :
Tendsto f (⨆ i, x i) y ↔ ∀ i, Tendsto f (x i) y := by simp only [Tendsto, map_iSup, iSup_le_iff]
theorem tendsto_iSup_iSup {f : α → β} {x : ι → Filter α} {y : ι → Filter β}
(h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iSup x) (iSup y) :=
tendsto_iSup.2 fun i => (h i).mono_right <| le_iSup _ _
@[simp] theorem tendsto_principal {f : α → β} {l : Filter α} {s : Set β} :
Tendsto f l (𝓟 s) ↔ ∀ᶠ a in l, f a ∈ s := by
simp only [Tendsto, le_principal_iff, mem_map', Filter.Eventually]
-- Porting note: was a `simp` lemma
theorem tendsto_principal_principal {f : α → β} {s : Set α} {t : Set β} :
Tendsto f (𝓟 s) (𝓟 t) ↔ ∀ a ∈ s, f a ∈ t := by
simp only [tendsto_principal, eventually_principal]
@[simp] theorem tendsto_pure {f : α → β} {a : Filter α} {b : β} :
Tendsto f a (pure b) ↔ ∀ᶠ x in a, f x = b := by
simp only [Tendsto, le_pure_iff, mem_map', mem_singleton_iff, Filter.Eventually]
theorem tendsto_pure_pure (f : α → β) (a : α) : Tendsto f (pure a) (pure (f a)) :=
tendsto_pure.2 rfl
theorem tendsto_const_pure {a : Filter α} {b : β} : Tendsto (fun _ => b) a (pure b) :=
tendsto_pure.2 <| univ_mem' fun _ => rfl
theorem pure_le_iff {a : α} {l : Filter α} : pure a ≤ l ↔ ∀ s ∈ l, a ∈ s :=
Iff.rfl
theorem tendsto_pure_left {f : α → β} {a : α} {l : Filter β} :
Tendsto f (pure a) l ↔ ∀ s ∈ l, f a ∈ s :=
Iff.rfl
@[simp]
theorem map_inf_principal_preimage {f : α → β} {s : Set β} {l : Filter α} :
map f (l ⊓ 𝓟 (f ⁻¹' s)) = map f l ⊓ 𝓟 s :=
Filter.ext fun t => by simp only [mem_map', mem_inf_principal, mem_setOf_eq, mem_preimage]
/-- If two filters are disjoint, then a function cannot tend to both of them along a non-trivial
filter. -/
theorem Tendsto.not_tendsto {f : α → β} {a : Filter α} {b₁ b₂ : Filter β} (hf : Tendsto f a b₁)
[NeBot a] (hb : Disjoint b₁ b₂) : ¬Tendsto f a b₂ := fun hf' =>
(tendsto_inf.2 ⟨hf, hf'⟩).neBot.ne hb.eq_bot
protected theorem Tendsto.if {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {p : α → Prop}
[∀ x, Decidable (p x)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 { x | p x }) l₂)
(h₁ : Tendsto g (l₁ ⊓ 𝓟 { x | ¬p x }) l₂) :
Tendsto (fun x => if p x then f x else g x) l₁ l₂ := by
simp only [tendsto_def, mem_inf_principal] at *
intro s hs
filter_upwards [h₀ s hs, h₁ s hs] with x hp₀ hp₁
rw [mem_preimage]
split_ifs with h
exacts [hp₀ h, hp₁ h]
protected theorem Tendsto.if' {α β : Type*} {l₁ : Filter α} {l₂ : Filter β} {f g : α → β}
{p : α → Prop} [DecidablePred p] (hf : Tendsto f l₁ l₂) (hg : Tendsto g l₁ l₂) :
Tendsto (fun a => if p a then f a else g a) l₁ l₂ :=
(tendsto_inf_left hf).if (tendsto_inf_left hg)
protected theorem Tendsto.piecewise {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {s : Set α}
[∀ x, Decidable (x ∈ s)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 s) l₂) (h₁ : Tendsto g (l₁ ⊓ 𝓟 sᶜ) l₂) :
Tendsto (piecewise s f g) l₁ l₂ :=
Tendsto.if h₀ h₁
end Filter
open Filter
theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g :=
h
theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s)
(hl : s ∈ l) : f =ᶠ[l] g :=
h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl
theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t :=
Filter.eventually_of_forall h
theorem Set.MapsTo.tendsto {α β} {s : Set α} {t : Set β} {f : α → β} (h : MapsTo f s t) :
Filter.Tendsto f (𝓟 s) (𝓟 t) :=
Filter.tendsto_principal_principal.2 h
theorem Filter.EventuallyEq.comp_tendsto {α β γ : Type*} {l : Filter α} {f : α → β} {f' : α → β}
(H : f =ᶠ[l] f') {g : γ → α} {lc : Filter γ} (hg : Tendsto g lc l) :
f ∘ g =ᶠ[lc] f' ∘ g :=
hg.eventually H
variable {α β : Type*} {F : Filter α} {G : Filter β}
theorem Filter.map_mapsTo_Iic_iff_tendsto {m : α → β} :
MapsTo (map m) (Iic F) (Iic G) ↔ Tendsto m F G :=
⟨fun hm ↦ hm right_mem_Iic, fun hm _ ↦ hm.mono_left⟩
alias ⟨_, Filter.Tendsto.map_mapsTo_Iic⟩ := Filter.map_mapsTo_Iic_iff_tendsto
theorem Filter.map_mapsTo_Iic_iff_mapsTo {s : Set α} {t : Set β} {m : α → β} :
MapsTo (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ MapsTo m s t := by
rw [map_mapsTo_Iic_iff_tendsto, tendsto_principal_principal, MapsTo]
alias ⟨_, Set.MapsTo.filter_map_Iic⟩ := Filter.map_mapsTo_Iic_iff_mapsTo
-- TODO(Anatole): unify with the global case
theorem Filter.map_surjOn_Iic_iff_le_map {m : α → β} :
SurjOn (map m) (Iic F) (Iic G) ↔ G ≤ map m F := by
refine ⟨fun hm ↦ ?_, fun hm ↦ ?_⟩
· rcases hm right_mem_Iic with ⟨H, (hHF : H ≤ F), rfl⟩
exact map_mono hHF
· have : RightInvOn (F ⊓ comap m ·) (map m) (Iic G) :=
fun H (hHG : H ≤ G) ↦ by simpa [Filter.push_pull] using hHG.trans hm
exact this.surjOn fun H _ ↦ mem_Iic.mpr inf_le_left
theorem Filter.map_surjOn_Iic_iff_surjOn {s : Set α} {t : Set β} {m : α → β} :
SurjOn (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ SurjOn m s t := by
rw [map_surjOn_Iic_iff_le_map, map_principal, principal_mono, SurjOn]
alias ⟨_, Set.SurjOn.filter_map_Iic⟩ := Filter.map_surjOn_Iic_iff_surjOn
theorem Filter.filter_injOn_Iic_iff_injOn {s : Set α} {m : α → β} :
InjOn (map m) (Iic <| 𝓟 s) ↔ InjOn m s := by
refine ⟨fun hm x hx y hy hxy ↦ ?_, fun hm F hF G hG ↦ ?_⟩
· rwa [← pure_injective.eq_iff, ← map_pure, ← map_pure, hm.eq_iff, pure_injective.eq_iff]
at hxy <;> rwa [mem_Iic, pure_le_principal]
· simp [map_eq_map_iff_of_injOn (le_principal_iff.mp hF) (le_principal_iff.mp hG) hm]
alias ⟨_, Set.InjOn.filter_map_Iic⟩ := Filter.filter_injOn_Iic_iff_injOn
namespace Filter
/-- Construct a filter from a property that is stable under finite unions.
A set `s` belongs to `Filter.comk p _ _ _` iff its complement satisfies the predicate `p`.
This constructor is useful to define filters like `Filter.cofinite`. -/
def comk (p : Set α → Prop) (he : p ∅) (hmono : ∀ t, p t → ∀ s ⊆ t, p s)
(hunion : ∀ s, p s → ∀ t, p t → p (s ∪ t)) : Filter α where
sets := {t | p tᶜ}
univ_sets := by simpa
sets_of_superset := fun ht₁ ht => hmono _ ht₁ _ (compl_subset_compl.2 ht)
inter_sets := fun ht₁ ht₂ => by simp [compl_inter, hunion _ ht₁ _ ht₂]
@[simp]
lemma mem_comk {p : Set α → Prop} {he hmono hunion s} :
s ∈ comk p he hmono hunion ↔ p sᶜ :=
.rfl
lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} :
sᶜ ∈ comk p he hmono hunion ↔ p s := by
simp
end Filter
|
Order\Filter\CardinalInter.lean | /-
Copyright (c) 2024 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Order.Filter.CountableInter
import Mathlib.SetTheory.Cardinal.Ordinal
import Mathlib.SetTheory.Cardinal.Cofinality
/-!
# Filters with a cardinal intersection property
In this file we define `CardinalInterFilter l c` to be the class of filters with the following
property: for any collection of sets `s ∈ l` with cardinality strictly less than `c`,
their intersection belongs to `l` as well.
# Main results
* `Filter.cardinalInterFilter_aleph0` establishes that every filter `l` is a
`CardinalInterFilter l aleph0`
* `CardinalInterFilter.toCountableInterFilter` establishes that every `CardinalInterFilter l c` with
`c > aleph0` is a `CountableInterFilter`.
* `CountableInterFilter.toCardinalInterFilter` establishes that every `CountableInterFilter l` is a
`CardinalInterFilter l aleph1`.
* `CardinalInterFilter.of_CardinalInterFilter_of_lt` establishes that we have
`CardinalInterFilter l c` → `CardinalInterFilter l a` for all `a < c`.
## Tags
filter, cardinal
-/
open Set Filter Cardinal
universe u
variable {ι : Type u} {α β : Type u} {c : Cardinal.{u}}
/-- A filter `l` has the cardinal `c` intersection property if for any collection
of less than `c` sets `s ∈ l`, their intersection belongs to `l` as well. -/
class CardinalInterFilter (l : Filter α) (c : Cardinal.{u}) : Prop where
/-- For a collection of sets `s ∈ l` with cardinality below c,
their intersection belongs to `l` as well. -/
cardinal_sInter_mem : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l
variable {l : Filter α}
theorem cardinal_sInter_mem {S : Set (Set α)} [CardinalInterFilter l c] (hSc : #S < c) :
⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs),
CardinalInterFilter.cardinal_sInter_mem _ hSc⟩
/-- Every filter is a CardinalInterFilter with c = aleph0 -/
theorem _root_.Filter.cardinalInterFilter_aleph0 (l : Filter α) : CardinalInterFilter l aleph0 where
cardinal_sInter_mem := by
simp_all only [aleph_zero, lt_aleph0_iff_subtype_finite, setOf_mem_eq, sInter_mem,
implies_true, forall_const]
/-- Every CardinalInterFilter with c > aleph0 is a CountableInterFilter -/
theorem CardinalInterFilter.toCountableInterFilter (l : Filter α) [CardinalInterFilter l c]
(hc : aleph0 < c) : CountableInterFilter l where
countable_sInter_mem S hS a :=
CardinalInterFilter.cardinal_sInter_mem S (lt_of_le_of_lt (Set.Countable.le_aleph0 hS) hc) a
/-- Every CountableInterFilter is a CardinalInterFilter with c = aleph 1-/
instance CountableInterFilter.toCardinalInterFilter (l : Filter α) [CountableInterFilter l] :
CardinalInterFilter l (aleph 1) where
cardinal_sInter_mem S hS a :=
CountableInterFilter.countable_sInter_mem S ((countable_iff_lt_aleph_one S).mpr hS) a
theorem cardinalInterFilter_aleph_one_iff :
CardinalInterFilter l (aleph 1) ↔ CountableInterFilter l :=
⟨fun _ ↦ ⟨fun S h a ↦
CardinalInterFilter.cardinal_sInter_mem S ((countable_iff_lt_aleph_one S).1 h) a⟩,
fun _ ↦ CountableInterFilter.toCardinalInterFilter l⟩
/-- Every CardinalInterFilter for some c also is a CardinalInterFilter for some a ≤ c -/
theorem CardinalInterFilter.of_cardinalInterFilter_of_le (l : Filter α) [CardinalInterFilter l c]
{a : Cardinal.{u}} (hac : a ≤ c) :
CardinalInterFilter l a where
cardinal_sInter_mem S hS a :=
CardinalInterFilter.cardinal_sInter_mem S (lt_of_lt_of_le hS hac) a
theorem CardinalInterFilter.of_cardinalInterFilter_of_lt (l : Filter α) [CardinalInterFilter l c]
{a : Cardinal.{u}} (hac : a < c) : CardinalInterFilter l a :=
CardinalInterFilter.of_cardinalInterFilter_of_le l (hac.le)
namespace Filter
variable [CardinalInterFilter l c]
theorem cardinal_iInter_mem {s : ι → Set α} (hic : #ι < c) :
(⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := by
rw [← sInter_range _]
apply (cardinal_sInter_mem (lt_of_le_of_lt Cardinal.mk_range_le hic)).trans
exact forall_mem_range
theorem cardinal_bInter_mem {S : Set ι} (hS : #S < c)
{s : ∀ i ∈ S, Set α} :
(⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by
rw [biInter_eq_iInter]
exact (cardinal_iInter_mem hS).trans Subtype.forall
theorem eventually_cardinal_forall {p : α → ι → Prop} (hic : #ι < c) :
(∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by
simp only [Filter.Eventually, setOf_forall]
exact cardinal_iInter_mem hic
theorem eventually_cardinal_ball {S : Set ι} (hS : #S < c)
{p : α → ∀ i ∈ S, Prop} :
(∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by
simp only [Filter.Eventually, setOf_forall]
exact cardinal_bInter_mem hS
theorem EventuallyLE.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c)
(h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i :=
((eventually_cardinal_forall hic).2 h).mono fun _ hst hs => mem_iUnion.2 <|
(mem_iUnion.1 hs).imp hst
theorem EventuallyEq.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c)
(h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i :=
(EventuallyLE.cardinal_iUnion hic fun i => (h i).le).antisymm
(EventuallyLE.cardinal_iUnion hic fun i => (h i).symm.le)
theorem EventuallyLE.cardinal_bUnion {S : Set ι} (hS : #S < c)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) :
⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by
simp only [biUnion_eq_iUnion]
exact EventuallyLE.cardinal_iUnion hS fun i => h i i.2
theorem EventuallyEq.cardinal_bUnion {S : Set ι} (hS : #S < c)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) :
⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› :=
(EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).le).antisymm
(EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).symm.le)
theorem EventuallyLE.cardinal_iInter {s t : ι → Set α} (hic : #ι < c)
(h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i :=
((eventually_cardinal_forall hic).2 h).mono fun _ hst hs =>
mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i)
theorem EventuallyEq.cardinal_iInter {s t : ι → Set α} (hic : #ι < c)
(h : ∀ i, s i =ᶠ[l] t i) : ⋂ i, s i =ᶠ[l] ⋂ i, t i :=
(EventuallyLE.cardinal_iInter hic fun i => (h i).le).antisymm
(EventuallyLE.cardinal_iInter hic fun i => (h i).symm.le)
theorem EventuallyLE.cardinal_bInter {S : Set ι} (hS : #S < c)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) :
⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by
simp only [biInter_eq_iInter]
exact EventuallyLE.cardinal_iInter hS fun i => h i i.2
theorem EventuallyEq.cardinal_bInter {S : Set ι} (hS : #S < c)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) :
⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› :=
(EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).le).antisymm
(EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).symm.le)
/-- Construct a filter with cardinal `c` intersection property. This constructor deduces
`Filter.univ_sets` and `Filter.inter_sets` from the cardinal `c` intersection property. -/
def ofCardinalInter (l : Set (Set α)) (hc : 2 < c)
(hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l)
(h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where
sets := l
univ_sets :=
sInter_empty ▸ hl ∅ (mk_eq_zero (∅ : Set (Set α)) ▸ lt_trans zero_lt_two hc) (empty_subset _)
sets_of_superset := h_mono _ _
inter_sets {s t} hs ht := sInter_pair s t ▸ by
apply hl _ (?_) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩)
have : #({s, t} : Set (Set α)) ≤ 2 := by
calc
_ ≤ #({t} : Set (Set α)) + 1 := Cardinal.mk_insert_le
_ = 2 := by norm_num
exact lt_of_le_of_lt this hc
instance cardinalInter_ofCardinalInter (l : Set (Set α)) (hc : 2 < c)
(hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l)
(h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) :
CardinalInterFilter (Filter.ofCardinalInter l hc hl h_mono) c :=
⟨hl⟩
@[simp]
theorem mem_ofCardinalInter {l : Set (Set α)} (hc : 2 < c)
(hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l)
{s : Set α} : s ∈ Filter.ofCardinalInter l hc hl h_mono ↔ s ∈ l :=
Iff.rfl
/-- Construct a filter with cardinal `c` intersection property.
Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property.
Similarly to `Filter.ofCardinalInter`,
this constructor deduces some properties from the cardinal `c` intersection property
which becomes the cardinal `c` union property because we take complements of all sets. -/
def ofCardinalUnion (l : Set (Set α)) (hc : 2 < c)
(hUnion : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l)
(hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by
refine .ofCardinalInter {s | sᶜ ∈ l} hc (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_
· rw [mem_setOf_eq, compl_sInter]
apply hUnion (compl '' S) (lt_of_le_of_lt mk_image_le hSc)
intro s hs
rw [mem_image] at hs
rcases hs with ⟨t, ht, rfl⟩
apply hSp ht
· rw [mem_setOf_eq]
rw [← compl_subset_compl] at hsub
exact hmono sᶜ ht tᶜ hsub
instance cardinalInter_ofCardinalUnion (l : Set (Set α)) (hc : 2 < c) (h₁ h₂) :
CardinalInterFilter (Filter.ofCardinalUnion l hc h₁ h₂) c :=
cardinalInter_ofCardinalInter ..
@[simp]
theorem mem_ofCardinalUnion {l : Set (Set α)} (hc : 2 < c) {hunion hmono s} :
s ∈ ofCardinalUnion l hc hunion hmono ↔ l sᶜ :=
Iff.rfl
instance cardinalInterFilter_principal (s : Set α) : CardinalInterFilter (𝓟 s) c :=
⟨fun _ _ hS => subset_sInter hS⟩
instance cardinalInterFilter_bot : CardinalInterFilter (⊥ : Filter α) c := by
rw [← principal_empty]
apply cardinalInterFilter_principal
instance cardinalInterFilter_top : CardinalInterFilter (⊤ : Filter α) c := by
rw [← principal_univ]
apply cardinalInterFilter_principal
instance (l : Filter β) [CardinalInterFilter l c] (f : α → β) :
CardinalInterFilter (comap f l) c := by
refine ⟨fun S hSc hS => ?_⟩
choose! t htl ht using hS
refine ⟨_, (cardinal_bInter_mem hSc).2 htl, ?_⟩
simpa [preimage_iInter] using iInter₂_mono ht
instance (l : Filter α) [CardinalInterFilter l c] (f : α → β) :
CardinalInterFilter (map f l) c := by
refine ⟨fun S hSc hS => ?_⟩
simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢
exact (cardinal_bInter_mem hSc).2 hS
/-- Infimum of two `CardinalInterFilter`s is a `CardinalInterFilter`. This is useful, e.g.,
to automatically get an instance for `residual α ⊓ 𝓟 s`. -/
instance cardinalInterFilter_inf_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c]
[CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊓ l₂) c := by
refine ⟨fun S hSc hS => ?_⟩
choose s hs t ht hst using hS
replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (cardinal_bInter_mem hSc).2 hs
replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (cardinal_bInter_mem hSc).2 ht
refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_)
rw [hst i hi]
apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _)
instance cardinalInterFilter_inf (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}}
[CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] : CardinalInterFilter (l₁ ⊓ l₂)
(c₁ ⊓ c₂) := by
have : CardinalInterFilter l₁ (c₁ ⊓ c₂) :=
CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left
have : CardinalInterFilter l₂ (c₁ ⊓ c₂) :=
CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right
exact cardinalInterFilter_inf_eq _ _
/-- Supremum of two `CardinalInterFilter`s is a `CardinalInterFilter`. -/
instance cardinalInterFilter_sup_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c]
[CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊔ l₂) c := by
refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (cardinal_sInter_mem hSc).2 fun s hs => ?_
exacts [(hS s hs).1, (hS s hs).2]
instance cardinalInterFilter_sup (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}}
[CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] :
CardinalInterFilter (l₁ ⊔ l₂) (c₁ ⊓ c₂) := by
have : CardinalInterFilter l₁ (c₁ ⊓ c₂) :=
CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left
have : CardinalInterFilter l₂ (c₁ ⊓ c₂) :=
CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right
exact cardinalInterFilter_sup_eq _ _
variable (g : Set (Set α))
/-- `Filter.CardinalGenerateSets c g` is the (sets of the)
greatest `cardinalInterFilter c` containing `g`. -/
inductive CardinalGenerateSets : Set α → Prop
| basic {s : Set α} : s ∈ g → CardinalGenerateSets s
| univ : CardinalGenerateSets univ
| superset {s t : Set α} : CardinalGenerateSets s → s ⊆ t → CardinalGenerateSets t
| sInter {S : Set (Set α)} :
(#S < c) → (∀ s ∈ S, CardinalGenerateSets s) → CardinalGenerateSets (⋂₀ S)
/-- `Filter.cardinalGenerate c g` is the greatest `cardinalInterFilter c` containing `g`. -/
def cardinalGenerate (hc : 2 < c) : Filter α :=
ofCardinalInter (CardinalGenerateSets g) hc (fun _ => CardinalGenerateSets.sInter) fun _ _ =>
CardinalGenerateSets.superset
lemma cardinalInter_ofCardinalGenerate (hc : 2 < c) :
CardinalInterFilter (cardinalGenerate g hc) c := by
delta cardinalGenerate
apply cardinalInter_ofCardinalInter _ _ _
variable {g}
/-- A set is in the `cardinalInterFilter` generated by `g` if and only if
it contains an intersection of `c` elements of `g`. -/
theorem mem_cardinaleGenerate_iff {s : Set α} {hreg : c.IsRegular} :
s ∈ cardinalGenerate g (IsRegular.nat_lt hreg 2) ↔
∃ S : Set (Set α), S ⊆ g ∧ (#S < c) ∧ ⋂₀ S ⊆ s := by
constructor <;> intro h
· induction' h with s hs s t _ st ih S Sct _ ih
· refine ⟨{s}, singleton_subset_iff.mpr hs, ?_⟩
simpa [subset_refl] using IsRegular.nat_lt hreg 1
· exact ⟨∅, ⟨empty_subset g, mk_eq_zero (∅ : Set <| Set α) ▸ IsRegular.nat_lt hreg 0, by simp⟩⟩
· exact Exists.imp (by tauto) ih
choose T Tg Tct hT using ih
refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa,
(Cardinal.card_biUnion_lt_iff_forall_of_isRegular hreg Sct).2 Tct, ?_⟩
apply subset_sInter
apply fun s H => subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H)
rcases h with ⟨S, Sg, Sct, hS⟩
have : CardinalInterFilter (cardinalGenerate g (IsRegular.nat_lt hreg 2)) c :=
cardinalInter_ofCardinalGenerate _ _
exact mem_of_superset ((cardinal_sInter_mem Sct).mpr
(fun s H => CardinalGenerateSets.basic (Sg H))) hS
theorem le_cardinalGenerate_iff_of_cardinalInterFilter {f : Filter α} [CardinalInterFilter f c]
(hc : 2 < c) : f ≤ cardinalGenerate g hc ↔ g ⊆ f.sets := by
constructor <;> intro h
· exact subset_trans (fun s => CardinalGenerateSets.basic) h
intro s hs
induction hs with
| basic hs => exact h hs
| univ => exact univ_mem
| superset _ st ih => exact mem_of_superset ih st
| sInter Sct _ ih => exact (cardinal_sInter_mem Sct).mpr ih
/-- `cardinalGenerate g hc` is the greatest `cardinalInterFilter c` containing `g`. -/
theorem cardinalGenerate_isGreatest (hc : 2 < c) :
IsGreatest { f : Filter α | CardinalInterFilter f c ∧ g ⊆ f.sets } (cardinalGenerate g hc) := by
refine ⟨⟨cardinalInter_ofCardinalGenerate _ _, fun s => CardinalGenerateSets.basic⟩, ?_⟩
rintro f ⟨fct, hf⟩
rwa [le_cardinalGenerate_iff_of_cardinalInterFilter]
end Filter
|
Order\Filter\Cocardinal.lean | /-
Copyright (c) 2024 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Filter.CountableInter
import Mathlib.Order.Filter.CardinalInter
import Mathlib.SetTheory.Cardinal.Ordinal
import Mathlib.SetTheory.Cardinal.Cofinality
import Mathlib.Order.Filter.Bases
/-!
# The cocardinal filter
In this file we define `Filter.cocardinal hc`: the filter of sets with cardinality less than
a regular cardinal `c` that satisfies `Cardinal.aleph0 < c`.
Such filters are `CardinalInterFilter` with cardinality `c`.
-/
open Set Filter Cardinal
universe u
variable {ι : Type u} {α β : Type u}
variable {c : Cardinal.{u}} {hreg : c.IsRegular}
variable {l : Filter α}
namespace Filter
variable (α) in
/-- The filter defined by all sets that have a complement with at most cardinality `c`. For a union
of `c` sets of `c` elements to have `c` elements, we need that `c` is a regular cardinal. -/
def cocardinal (hreg : c.IsRegular) : Filter α := by
apply ofCardinalUnion {s | Cardinal.mk s < c} (lt_of_lt_of_le (nat_lt_aleph0 2) hreg.aleph0_le)
· refine fun s hS hSc ↦ lt_of_le_of_lt (mk_sUnion_le _) <| mul_lt_of_lt hreg.aleph0_le hS ?_
exact iSup_lt_of_isRegular hreg hS fun i ↦ hSc i i.property
· exact fun _ hSc _ ht ↦ lt_of_le_of_lt (mk_le_mk_of_subset ht) hSc
@[simp]
theorem mem_cocardinal {s : Set α} :
s ∈ cocardinal α hreg ↔ Cardinal.mk (sᶜ : Set α) < c := Iff.rfl
@[simp] lemma cocardinal_aleph0_eq_cofinite :
cocardinal (α := α) isRegular_aleph0 = cofinite := by
aesop
instance instCardinalInterFilter_cocardinal : CardinalInterFilter (cocardinal (α := α) hreg) c where
cardinal_sInter_mem S hS hSs := by
rw [mem_cocardinal, Set.compl_sInter]
apply lt_of_le_of_lt (mk_sUnion_le _)
apply mul_lt_of_lt hreg.aleph0_le (lt_of_le_of_lt mk_image_le hS)
apply iSup_lt_of_isRegular hreg <| lt_of_le_of_lt mk_image_le hS
aesop
@[simp]
theorem eventually_cocardinal {p : α → Prop} :
(∀ᶠ x in cocardinal α hreg, p x) ↔ #{ x | ¬p x } < c := Iff.rfl
theorem hasBasis_cocardinal : HasBasis (cocardinal α hreg) {s : Set α | #s < c} compl :=
⟨fun s =>
⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ => by
have : #↑sᶜ < c := by
apply lt_of_le_of_lt _ htf
rw [compl_subset_comm] at hts
apply Cardinal.mk_le_mk_of_subset hts
simp_all only [mem_cocardinal] ⟩⟩
theorem frequently_cocardinal {p : α → Prop} :
(∃ᶠ x in cocardinal α hreg, p x) ↔ c ≤ # { x | p x } := by
simp only [Filter.Frequently, eventually_cocardinal, not_not,coe_setOf, not_lt]
lemma frequently_cocardinal_mem {s : Set α} :
(∃ᶠ x in cocardinal α hreg, x ∈ s) ↔ c ≤ #s := frequently_cocardinal
@[simp]
lemma cocardinal_inf_principal_neBot_iff {s : Set α} :
(cocardinal α hreg ⊓ 𝓟 s).NeBot ↔ c ≤ #s :=
frequently_mem_iff_neBot.symm.trans frequently_cocardinal
theorem compl_mem_cocardinal_of_card_lt {s : Set α} (hs : #s < c) :
sᶜ ∈ cocardinal α hreg :=
mem_cocardinal.2 <| (compl_compl s).symm ▸ hs
theorem _root_.Set.Finite.compl_mem_cocardinal {s : Set α} (hs : s.Finite) :
sᶜ ∈ cocardinal α hreg :=
compl_mem_cocardinal_of_card_lt <| lt_of_lt_of_le (Finite.lt_aleph0 hs) (hreg.aleph0_le)
theorem eventually_cocardinal_nmem_of_card_lt {s : Set α} (hs : #s < c) :
∀ᶠ x in cocardinal α hreg, x ∉ s :=
compl_mem_cocardinal_of_card_lt hs
theorem _root_.Finset.eventually_cocardinal_nmem (s : Finset α) :
∀ᶠ x in cocardinal α hreg, x ∉ s :=
eventually_cocardinal_nmem_of_card_lt <| lt_of_lt_of_le (finset_card_lt_aleph0 s) (hreg.aleph0_le)
theorem eventually_cocardinal_ne (x : α) : ∀ᶠ a in cocardinal α hreg, a ≠ x := by
simpa [Set.finite_singleton x] using hreg.nat_lt 1
/-- The filter defined by all sets that have countable complements. -/
abbrev cocountable : Filter α := cocardinal α Cardinal.isRegular_aleph_one
theorem mem_cocountable {s : Set α} :
s ∈ cocountable ↔ (sᶜ : Set α).Countable := by
rw [Cardinal.countable_iff_lt_aleph_one, mem_cocardinal]
end Filter
|
Order\Filter\Cofinite.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov
-/
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Order.Filter.Pi
/-!
# The cofinite filter
In this file we define
`Filter.cofinite`: the filter of sets with finite complement
and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `Filter.atTop`.
## TODO
Define filters for other cardinalities of the complement.
-/
open Set Function
variable {ι α β : Type*} {l : Filter α}
namespace Filter
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : Filter α :=
comk Set.Finite finite_empty (fun _t ht _s hsub ↦ ht.subset hsub) fun _ h _ ↦ h.union
@[simp]
theorem mem_cofinite {s : Set α} : s ∈ @cofinite α ↔ sᶜ.Finite :=
Iff.rfl
@[simp]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in cofinite, p x) ↔ { x | ¬p x }.Finite :=
Iff.rfl
theorem hasBasis_cofinite : HasBasis cofinite (fun s : Set α => s.Finite) compl :=
⟨fun s =>
⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ =>
htf.subset <| compl_subset_comm.2 hts⟩⟩
instance cofinite_neBot [Infinite α] : NeBot (@cofinite α) :=
hasBasis_cofinite.neBot_iff.2 fun hs => hs.infinite_compl.nonempty
@[simp]
theorem cofinite_eq_bot_iff : @cofinite α = ⊥ ↔ Finite α := by
simp [← empty_mem_iff_bot, finite_univ_iff]
@[simp]
theorem cofinite_eq_bot [Finite α] : @cofinite α = ⊥ := cofinite_eq_bot_iff.2 ‹_›
theorem frequently_cofinite_iff_infinite {p : α → Prop} :
(∃ᶠ x in cofinite, p x) ↔ Set.Infinite { x | p x } := by
simp only [Filter.Frequently, eventually_cofinite, not_not, Set.Infinite]
lemma frequently_cofinite_mem_iff_infinite {s : Set α} : (∃ᶠ x in cofinite, x ∈ s) ↔ s.Infinite :=
frequently_cofinite_iff_infinite
alias ⟨_, _root_.Set.Infinite.frequently_cofinite⟩ := frequently_cofinite_mem_iff_infinite
@[simp]
lemma cofinite_inf_principal_neBot_iff {s : Set α} : (cofinite ⊓ 𝓟 s).NeBot ↔ s.Infinite :=
frequently_mem_iff_neBot.symm.trans frequently_cofinite_mem_iff_infinite
alias ⟨_, _root_.Set.Infinite.cofinite_inf_principal_neBot⟩ := cofinite_inf_principal_neBot_iff
theorem _root_.Set.Finite.compl_mem_cofinite {s : Set α} (hs : s.Finite) : sᶜ ∈ @cofinite α :=
mem_cofinite.2 <| (compl_compl s).symm ▸ hs
theorem _root_.Set.Finite.eventually_cofinite_nmem {s : Set α} (hs : s.Finite) :
∀ᶠ x in cofinite, x ∉ s :=
hs.compl_mem_cofinite
theorem _root_.Finset.eventually_cofinite_nmem (s : Finset α) : ∀ᶠ x in cofinite, x ∉ s :=
s.finite_toSet.eventually_cofinite_nmem
theorem _root_.Set.infinite_iff_frequently_cofinite {s : Set α} :
Set.Infinite s ↔ ∃ᶠ x in cofinite, x ∈ s :=
frequently_cofinite_iff_infinite.symm
theorem eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x :=
(Set.finite_singleton x).eventually_cofinite_nmem
theorem le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l := by
refine ⟨fun h x => h (finite_singleton x).compl_mem_cofinite, fun h s (hs : sᶜ.Finite) => ?_⟩
rw [← compl_compl s, ← biUnion_of_singleton sᶜ, compl_iUnion₂, Filter.biInter_mem hs]
exact fun x _ => h x
theorem le_cofinite_iff_eventually_ne : l ≤ cofinite ↔ ∀ x, ∀ᶠ y in l, y ≠ x :=
le_cofinite_iff_compl_singleton_mem
/-- If `α` is a preorder with no maximal element, then `atTop ≤ cofinite`. -/
theorem atTop_le_cofinite [Preorder α] [NoMaxOrder α] : (atTop : Filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_atTop
theorem comap_cofinite_le (f : α → β) : comap f cofinite ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr fun x =>
mem_comap.2 ⟨{f x}ᶜ, (finite_singleton _).compl_mem_cofinite, fun _ => ne_of_apply_ne f⟩
/-- The coproduct of the cofinite filters on two types is the cofinite filter on their product. -/
theorem coprod_cofinite : (cofinite : Filter α).coprod (cofinite : Filter β) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprod, mem_cofinite, compl_compl, finite_image_fst_and_snd_iff]
theorem coprodᵢ_cofinite {α : ι → Type*} [Finite ι] :
(Filter.coprodᵢ fun i => (cofinite : Filter (α i))) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprodᵢ, mem_cofinite, compl_compl, forall_finite_image_eval_iff]
theorem disjoint_cofinite_left : Disjoint cofinite l ↔ ∃ s ∈ l, Set.Finite s := by
simp [l.basis_sets.disjoint_iff_right]
theorem disjoint_cofinite_right : Disjoint l cofinite ↔ ∃ s ∈ l, Set.Finite s :=
disjoint_comm.trans disjoint_cofinite_left
/-- If `l ≥ Filter.cofinite` is a countably generated filter, then `l.ker` is cocountable. -/
theorem countable_compl_ker [l.IsCountablyGenerated] (h : cofinite ≤ l) : Set.Countable l.kerᶜ := by
rcases exists_antitone_basis l with ⟨s, hs⟩
simp only [hs.ker, iInter_true, compl_iInter]
exact countable_iUnion fun n ↦ Set.Finite.countable <| h <| hs.mem _
/-- If `f` tends to a countably generated filter `l` along `Filter.cofinite`,
then for all but countably many elements, `f x ∈ l.ker`. -/
theorem Tendsto.countable_compl_preimage_ker {f : α → β}
{l : Filter β} [l.IsCountablyGenerated] (h : Tendsto f cofinite l) :
Set.Countable (f ⁻¹' l.ker)ᶜ := by rw [← ker_comap]; exact countable_compl_ker h.le_comap
end Filter
open Filter
lemma Set.Finite.cofinite_inf_principal_compl {s : Set α} (hs : s.Finite) :
cofinite ⊓ 𝓟 sᶜ = cofinite := by
simpa using hs.compl_mem_cofinite
lemma Set.Finite.cofinite_inf_principal_diff {s t : Set α} (ht : t.Finite) :
cofinite ⊓ 𝓟 (s \ t) = cofinite ⊓ 𝓟 s := by
rw [diff_eq, ← inf_principal, ← inf_assoc, inf_right_comm, ht.cofinite_inf_principal_compl]
/-- For natural numbers the filters `Filter.cofinite` and `Filter.atTop` coincide. -/
theorem Nat.cofinite_eq_atTop : @cofinite ℕ = atTop := by
refine le_antisymm ?_ atTop_le_cofinite
refine atTop_basis.ge_iff.2 fun N _ => ?_
simpa only [mem_cofinite, compl_Ici] using finite_lt_nat N
theorem Nat.frequently_atTop_iff_infinite {p : ℕ → Prop} :
(∃ᶠ n in atTop, p n) ↔ Set.Infinite { n | p n } := by
rw [← Nat.cofinite_eq_atTop, frequently_cofinite_iff_infinite]
lemma Nat.eventually_pos : ∀ᶠ (k : ℕ) in Filter.atTop, 0 < k :=
Filter.eventually_of_mem (Filter.mem_atTop_sets.mpr ⟨1, fun _ hx ↦ hx⟩) (fun _ hx ↦ hx)
theorem Filter.Tendsto.exists_within_forall_le {α β : Type*} [LinearOrder β] {s : Set α}
(hs : s.Nonempty) {f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atTop) :
∃ a₀ ∈ s, ∀ a ∈ s, f a₀ ≤ f a := by
rcases em (∃ y ∈ s, ∃ x, f y < x) with (⟨y, hys, x, hx⟩ | not_all_top)
· -- the set of points `{y | f y < x}` is nonempty and finite, so we take `min` over this set
have : { y | ¬x ≤ f y }.Finite := Filter.eventually_cofinite.mp (tendsto_atTop.1 hf x)
simp only [not_le] at this
obtain ⟨a₀, ⟨ha₀ : f a₀ < x, ha₀s⟩, others_bigger⟩ :=
exists_min_image _ f (this.inter_of_left s) ⟨y, hx, hys⟩
refine ⟨a₀, ha₀s, fun a has => (lt_or_le (f a) x).elim ?_ (le_trans ha₀.le)⟩
exact fun h => others_bigger a ⟨h, has⟩
· -- in this case, f is constant because all values are at top
push_neg at not_all_top
obtain ⟨a₀, ha₀s⟩ := hs
exact ⟨a₀, ha₀s, fun a ha => not_all_top a ha (f a₀)⟩
theorem Filter.Tendsto.exists_forall_le [Nonempty α] [LinearOrder β] {f : α → β}
(hf : Tendsto f cofinite atTop) : ∃ a₀, ∀ a, f a₀ ≤ f a :=
let ⟨a₀, _, ha₀⟩ := hf.exists_within_forall_le univ_nonempty
⟨a₀, fun a => ha₀ a (mem_univ _)⟩
theorem Filter.Tendsto.exists_within_forall_ge [LinearOrder β] {s : Set α} (hs : s.Nonempty)
{f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atBot) :
∃ a₀ ∈ s, ∀ a ∈ s, f a ≤ f a₀ :=
@Filter.Tendsto.exists_within_forall_le _ βᵒᵈ _ _ hs _ hf
theorem Filter.Tendsto.exists_forall_ge [Nonempty α] [LinearOrder β] {f : α → β}
(hf : Tendsto f cofinite atBot) : ∃ a₀, ∀ a, f a ≤ f a₀ :=
@Filter.Tendsto.exists_forall_le _ βᵒᵈ _ _ _ hf
theorem Function.Surjective.le_map_cofinite {f : α → β} (hf : Surjective f) :
cofinite ≤ map f cofinite := fun _ h => .of_preimage h hf
/-- For an injective function `f`, inverse images of finite sets are finite. See also
`Filter.comap_cofinite_le` and `Function.Injective.comap_cofinite_eq`. -/
theorem Function.Injective.tendsto_cofinite {f : α → β} (hf : Injective f) :
Tendsto f cofinite cofinite := fun _ h => h.preimage hf.injOn
/-- The pullback of the `Filter.cofinite` under an injective function is equal to `Filter.cofinite`.
See also `Filter.comap_cofinite_le` and `Function.Injective.tendsto_cofinite`. -/
theorem Function.Injective.comap_cofinite_eq {f : α → β} (hf : Injective f) :
comap f cofinite = cofinite :=
(comap_cofinite_le f).antisymm hf.tendsto_cofinite.le_comap
/-- An injective sequence `f : ℕ → ℕ` tends to infinity at infinity. -/
theorem Function.Injective.nat_tendsto_atTop {f : ℕ → ℕ} (hf : Injective f) :
Tendsto f atTop atTop :=
Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite
|
Order\Filter\CountableInter.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Order.Filter.Curry
import Mathlib.Data.Set.Countable
/-!
# Filters with countable intersection property
In this file we define `CountableInterFilter` to be the class of filters with the following
property: for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well.
Two main examples are the `residual` filter defined in `Mathlib.Topology.GDelta` and
the `MeasureTheory.ae` filter defined in `Mathlib/MeasureTheory.OuterMeasure/AE`.
We reformulate the definition in terms of indexed intersection and in terms of `Filter.Eventually`
and provide instances for some basic constructions (`⊥`, `⊤`, `Filter.principal`, `Filter.map`,
`Filter.comap`, `Inf.inf`). We also provide a custom constructor `Filter.ofCountableInter`
that deduces two axioms of a `Filter` from the countable intersection property.
Note that there also exists a typeclass `CardinalInterFilter`, and thus an alternative spelling of
`CountableInterFilter` as `CardinalInterFilter l (aleph 1)`. The former (defined here) is the
preferred spelling; it has the advantage of not requiring the user to import the theory ordinals.
## Tags
filter, countable
-/
open Set Filter
open Filter
variable {ι : Sort*} {α β : Type*}
/-- A filter `l` has the countable intersection property if for any countable collection
of sets `s ∈ l` their intersection belongs to `l` as well. -/
class CountableInterFilter (l : Filter α) : Prop where
/-- For a countable collection of sets `s ∈ l`, their intersection belongs to `l` as well. -/
countable_sInter_mem : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l
variable {l : Filter α} [CountableInterFilter l]
theorem countable_sInter_mem {S : Set (Set α)} (hSc : S.Countable) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l :=
⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs),
CountableInterFilter.countable_sInter_mem _ hSc⟩
theorem countable_iInter_mem [Countable ι] {s : ι → Set α} : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l :=
sInter_range s ▸ (countable_sInter_mem (countable_range _)).trans forall_mem_range
theorem countable_bInter_mem {ι : Type*} {S : Set ι} (hS : S.Countable) {s : ∀ i ∈ S, Set α} :
(⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by
rw [biInter_eq_iInter]
haveI := hS.toEncodable
exact countable_iInter_mem.trans Subtype.forall
theorem eventually_countable_forall [Countable ι] {p : α → ι → Prop} :
(∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by
simpa only [Filter.Eventually, setOf_forall] using
@countable_iInter_mem _ _ l _ _ fun i => { x | p x i }
theorem eventually_countable_ball {ι : Type*} {S : Set ι} (hS : S.Countable)
{p : α → ∀ i ∈ S, Prop} :
(∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by
simpa only [Filter.Eventually, setOf_forall] using
@countable_bInter_mem _ l _ _ _ hS fun i hi => { x | p x i hi }
theorem EventuallyLE.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) :
⋃ i, s i ≤ᶠ[l] ⋃ i, t i :=
(eventually_countable_forall.2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst
theorem EventuallyEq.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) :
⋃ i, s i =ᶠ[l] ⋃ i, t i :=
(EventuallyLE.countable_iUnion fun i => (h i).le).antisymm
(EventuallyLE.countable_iUnion fun i => (h i).symm.le)
theorem EventuallyLE.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) :
⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by
simp only [biUnion_eq_iUnion]
haveI := hS.toEncodable
exact EventuallyLE.countable_iUnion fun i => h i i.2
theorem EventuallyEq.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) :
⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› :=
(EventuallyLE.countable_bUnion hS fun i hi => (h i hi).le).antisymm
(EventuallyLE.countable_bUnion hS fun i hi => (h i hi).symm.le)
theorem EventuallyLE.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) :
⋂ i, s i ≤ᶠ[l] ⋂ i, t i :=
(eventually_countable_forall.2 h).mono fun _ hst hs =>
mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i)
theorem EventuallyEq.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) :
⋂ i, s i =ᶠ[l] ⋂ i, t i :=
(EventuallyLE.countable_iInter fun i => (h i).le).antisymm
(EventuallyLE.countable_iInter fun i => (h i).symm.le)
theorem EventuallyLE.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) :
⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by
simp only [biInter_eq_iInter]
haveI := hS.toEncodable
exact EventuallyLE.countable_iInter fun i => h i i.2
theorem EventuallyEq.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable)
{s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) :
⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› :=
(EventuallyLE.countable_bInter hS fun i hi => (h i hi).le).antisymm
(EventuallyLE.countable_bInter hS fun i hi => (h i hi).symm.le)
/-- Construct a filter with countable intersection property. This constructor deduces
`Filter.univ_sets` and `Filter.inter_sets` from the countable intersection property. -/
def Filter.ofCountableInter (l : Set (Set α))
(hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l)
(h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where
sets := l
univ_sets := @sInter_empty α ▸ hl _ countable_empty (empty_subset _)
sets_of_superset := h_mono _ _
inter_sets {s t} hs ht := sInter_pair s t ▸
hl _ ((countable_singleton _).insert _) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩)
instance Filter.countableInter_ofCountableInter (l : Set (Set α))
(hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l)
(h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) :
CountableInterFilter (Filter.ofCountableInter l hl h_mono) :=
⟨hl⟩
@[simp]
theorem Filter.mem_ofCountableInter {l : Set (Set α)}
(hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l)
{s : Set α} : s ∈ Filter.ofCountableInter l hl h_mono ↔ s ∈ l :=
Iff.rfl
/-- Construct a filter with countable intersection property.
Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property.
Similarly to `Filter.ofCountableInter`,
this constructor deduces some properties from the countable intersection property
which becomes the countable union property because we take complements of all sets. -/
def Filter.ofCountableUnion (l : Set (Set α))
(hUnion : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l)
(hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by
refine .ofCountableInter {s | sᶜ ∈ l} (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_
· rw [mem_setOf_eq, compl_sInter]
apply hUnion (compl '' S) (hSc.image _)
intro s hs
rw [mem_image] at hs
rcases hs with ⟨t, ht, rfl⟩
apply hSp ht
· rw [mem_setOf_eq]
rw [← compl_subset_compl] at hsub
exact hmono sᶜ ht tᶜ hsub
instance Filter.countableInter_ofCountableUnion (l : Set (Set α)) (h₁ h₂) :
CountableInterFilter (Filter.ofCountableUnion l h₁ h₂) :=
countableInter_ofCountableInter ..
@[simp]
theorem Filter.mem_ofCountableUnion {l : Set (Set α)} {hunion hmono s} :
s ∈ ofCountableUnion l hunion hmono ↔ l sᶜ :=
Iff.rfl
instance countableInterFilter_principal (s : Set α) : CountableInterFilter (𝓟 s) :=
⟨fun _ _ hS => subset_sInter hS⟩
instance countableInterFilter_bot : CountableInterFilter (⊥ : Filter α) := by
rw [← principal_empty]
apply countableInterFilter_principal
instance countableInterFilter_top : CountableInterFilter (⊤ : Filter α) := by
rw [← principal_univ]
apply countableInterFilter_principal
instance (l : Filter β) [CountableInterFilter l] (f : α → β) :
CountableInterFilter (comap f l) := by
refine ⟨fun S hSc hS => ?_⟩
choose! t htl ht using hS
have : (⋂ s ∈ S, t s) ∈ l := (countable_bInter_mem hSc).2 htl
refine ⟨_, this, ?_⟩
simpa [preimage_iInter] using iInter₂_mono ht
instance (l : Filter α) [CountableInterFilter l] (f : α → β) : CountableInterFilter (map f l) := by
refine ⟨fun S hSc hS => ?_⟩
simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢
exact (countable_bInter_mem hSc).2 hS
/-- Infimum of two `CountableInterFilter`s is a `CountableInterFilter`. This is useful, e.g.,
to automatically get an instance for `residual α ⊓ 𝓟 s`. -/
instance countableInterFilter_inf (l₁ l₂ : Filter α) [CountableInterFilter l₁]
[CountableInterFilter l₂] : CountableInterFilter (l₁ ⊓ l₂) := by
refine ⟨fun S hSc hS => ?_⟩
choose s hs t ht hst using hS
replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (countable_bInter_mem hSc).2 hs
replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (countable_bInter_mem hSc).2 ht
refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_)
rw [hst i hi]
apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _)
/-- Supremum of two `CountableInterFilter`s is a `CountableInterFilter`. -/
instance countableInterFilter_sup (l₁ l₂ : Filter α) [CountableInterFilter l₁]
[CountableInterFilter l₂] : CountableInterFilter (l₁ ⊔ l₂) := by
refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (countable_sInter_mem hSc).2 fun s hs => ?_
exacts [(hS s hs).1, (hS s hs).2]
instance CountableInterFilter.curry {α β : Type*} {l : Filter α} {m : Filter β}
[CountableInterFilter l] [CountableInterFilter m] : CountableInterFilter (l.curry m) := ⟨by
intro S Sct hS
simp_rw [mem_curry_iff, mem_sInter, eventually_countable_ball (p := fun _ _ _ => (_ ,_) ∈ _) Sct,
eventually_countable_ball (p := fun _ _ _ => ∀ᶠ (_ : β) in m, _) Sct, ← mem_curry_iff]
exact hS⟩
namespace Filter
variable (g : Set (Set α))
/-- `Filter.CountableGenerateSets g` is the (sets of the)
greatest `countableInterFilter` containing `g`. -/
inductive CountableGenerateSets : Set α → Prop
| basic {s : Set α} : s ∈ g → CountableGenerateSets s
| univ : CountableGenerateSets univ
| superset {s t : Set α} : CountableGenerateSets s → s ⊆ t → CountableGenerateSets t
| sInter {S : Set (Set α)} :
S.Countable → (∀ s ∈ S, CountableGenerateSets s) → CountableGenerateSets (⋂₀ S)
/-- `Filter.countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/
def countableGenerate : Filter α :=
ofCountableInter (CountableGenerateSets g) (fun _ => CountableGenerateSets.sInter) fun _ _ =>
CountableGenerateSets.superset
--deriving CountableInterFilter
-- Porting note: could not de derived
instance : CountableInterFilter (countableGenerate g) := by
delta countableGenerate; infer_instance
variable {g}
/-- A set is in the `countableInterFilter` generated by `g` if and only if
it contains a countable intersection of elements of `g`. -/
theorem mem_countableGenerate_iff {s : Set α} :
s ∈ countableGenerate g ↔ ∃ S : Set (Set α), S ⊆ g ∧ S.Countable ∧ ⋂₀ S ⊆ s := by
constructor <;> intro h
· induction' h with s hs s t _ st ih S Sct _ ih
· exact ⟨{s}, by simp [hs, subset_refl]⟩
· exact ⟨∅, by simp⟩
· refine Exists.imp (fun S => ?_) ih
tauto
choose T Tg Tct hT using ih
refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa, Sct.biUnion Tct, ?_⟩
apply subset_sInter
intro s H
exact subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H)
rcases h with ⟨S, Sg, Sct, hS⟩
refine mem_of_superset ((countable_sInter_mem Sct).mpr ?_) hS
intro s H
exact CountableGenerateSets.basic (Sg H)
theorem le_countableGenerate_iff_of_countableInterFilter {f : Filter α} [CountableInterFilter f] :
f ≤ countableGenerate g ↔ g ⊆ f.sets := by
constructor <;> intro h
· exact subset_trans (fun s => CountableGenerateSets.basic) h
intro s hs
induction' hs with s hs s t _ st ih S Sct _ ih
· exact h hs
· exact univ_mem
· exact mem_of_superset ih st
exact (countable_sInter_mem Sct).mpr ih
variable (g)
/-- `countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/
theorem countableGenerate_isGreatest :
IsGreatest { f : Filter α | CountableInterFilter f ∧ g ⊆ f.sets } (countableGenerate g) := by
refine ⟨⟨inferInstance, fun s => CountableGenerateSets.basic⟩, ?_⟩
rintro f ⟨fct, hf⟩
rwa [@le_countableGenerate_iff_of_countableInterFilter _ _ _ fct]
end Filter
|
Order\Filter\CountableSeparatingOn.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Filter.CountableInter
/-!
# Filters with countable intersections and countable separating families
In this file we prove some facts about a filter with countable intersections property on a type with
a countable family of sets that separates points of the space. The main use case is the
`MeasureTheory.ae` filter and a space with countably generated σ-algebra but lemmas apply,
e.g., to the `residual` filter and a T₀ topological space with second countable topology.
To avoid repetition of lemmas for different families of separating sets (measurable sets, open sets,
closed sets), all theorems in this file take a predicate `p : Set α → Prop` as an argument and prove
existence of a countable separating family satisfying this predicate by searching for a
`HasCountableSeparatingOn` typeclass instance.
## Main definitions
- `HasCountableSeparatingOn α p t`: a typeclass saying that there exists a countable set family
`S : Set (Set α)` such that all `s ∈ S` satisfy the predicate `p` and any two distinct points
`x y ∈ t`, `x ≠ y`, can be separated by a set `s ∈ S`. For technical reasons, we formulate the
latter property as "for all `x y ∈ t`, if `x ∈ s ↔ y ∈ s` for all `s ∈ S`, then `x = y`".
This typeclass is used in all lemmas in this file to avoid repeating them for open sets, closed
sets, and measurable sets.
### Main results
#### Filters supported on a (sub)singleton
Let `l : Filter α` be a filter with countable intersections property. Let `p : Set α → Prop` be a
property such that there exists a countable family of sets satisfying `p` and separating points of
`α`. Then `l` is supported on a subsingleton: there exists a subsingleton `t` such that
`t ∈ l`.
We formalize various versions of this theorem in
`Filter.exists_subset_subsingleton_mem_of_forall_separating`,
`Filter.exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating`,
`Filter.exists_singleton_mem_of_mem_of_forall_separating`,
`Filter.exists_subsingleton_mem_of_forall_separating`, and
`Filter.exists_singleton_mem_of_forall_separating`.
#### Eventually constant functions
Consider a function `f : α → β`, a filter `l` with countable intersections property, and a countable
separating family of sets of `β`. Suppose that for every `U` from the family, either
`∀ᶠ x in l, f x ∈ U` or `∀ᶠ x in l, f x ∉ U`. Then `f` is eventually constant along `l`.
We formalize three versions of this theorem in
`Filter.exists_mem_eventuallyEq_const_of_eventually_mem_of_forall_separating`,
`Filter.exists_eventuallyEq_const_of_eventually_mem_of_forall_separating`, and
`Filer.exists_eventuallyEq_const_of_forall_separating`.
#### Eventually equal functions
Two functions are equal along a filter with countable intersections property if the preimages of all
sets from a countable separating family of sets are equal along the filter.
We formalize several versions of this theorem in
`Filter.of_eventually_mem_of_forall_separating_mem_iff`, `Filter.of_forall_separating_mem_iff`,
`Filter.of_eventually_mem_of_forall_separating_preimage`, and
`Filter.of_forall_separating_preimage`.
## Keywords
filter, countable
-/
open Function Set Filter
/-- We say that a type `α` has a *countable separating family of sets* satisfying a predicate
`p : Set α → Prop` on a set `t` if there exists a countable family of sets `S : Set (Set α)` such
that all sets `s ∈ S` satisfy `p` and any two distinct points `x y ∈ t`, `x ≠ y`, can be separated
by `s ∈ S`: there exists `s ∈ S` such that exactly one of `x` and `y` belongs to `s`.
E.g., if `α` is a `T₀` topological space with second countable topology, then it has a countable
separating family of open sets and a countable separating family of closed sets.
-/
class HasCountableSeparatingOn (α : Type*) (p : Set α → Prop) (t : Set α) : Prop where
exists_countable_separating : ∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧
∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y
theorem exists_countable_separating (α : Type*) (p : Set α → Prop) (t : Set α)
[h : HasCountableSeparatingOn α p t] :
∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧
∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y :=
h.1
theorem exists_nonempty_countable_separating (α : Type*) {p : Set α → Prop} {s₀} (hp : p s₀)
(t : Set α) [HasCountableSeparatingOn α p t] :
∃ S : Set (Set α), S.Nonempty ∧ S.Countable ∧ (∀ s ∈ S, p s) ∧
∀ x ∈ t, ∀ y ∈ t, (∀ s ∈ S, x ∈ s ↔ y ∈ s) → x = y :=
let ⟨S, hSc, hSp, hSt⟩ := exists_countable_separating α p t
⟨insert s₀ S, insert_nonempty _ _, hSc.insert _, forall_insert_of_forall hSp hp,
fun x hx y hy hxy ↦ hSt x hx y hy <| forall_of_forall_insert hxy⟩
theorem exists_seq_separating (α : Type*) {p : Set α → Prop} {s₀} (hp : p s₀) (t : Set α)
[HasCountableSeparatingOn α p t] :
∃ S : ℕ → Set α, (∀ n, p (S n)) ∧ ∀ x ∈ t, ∀ y ∈ t, (∀ n, x ∈ S n ↔ y ∈ S n) → x = y := by
rcases exists_nonempty_countable_separating α hp t with ⟨S, hSne, hSc, hS⟩
rcases hSc.exists_eq_range hSne with ⟨S, rfl⟩
use S
simpa only [forall_mem_range] using hS
theorem HasCountableSeparatingOn.mono {α} {p₁ p₂ : Set α → Prop} {t₁ t₂ : Set α}
[h : HasCountableSeparatingOn α p₁ t₁] (hp : ∀ s, p₁ s → p₂ s) (ht : t₂ ⊆ t₁) :
HasCountableSeparatingOn α p₂ t₂ where
exists_countable_separating :=
let ⟨S, hSc, hSp, hSt⟩ := h.1
⟨S, hSc, fun s hs ↦ hp s (hSp s hs), fun x hx y hy ↦ hSt x (ht hx) y (ht hy)⟩
theorem HasCountableSeparatingOn.of_subtype {α : Type*} {p : Set α → Prop} {t : Set α}
{q : Set t → Prop} [h : HasCountableSeparatingOn t q univ]
(hpq : ∀ U, q U → ∃ V, p V ∧ (↑) ⁻¹' V = U) : HasCountableSeparatingOn α p t := by
rcases h.1 with ⟨S, hSc, hSq, hS⟩
choose! V hpV hV using fun s hs ↦ hpq s (hSq s hs)
refine ⟨⟨V '' S, hSc.image _, forall_mem_image.2 hpV, fun x hx y hy h ↦ ?_⟩⟩
refine congr_arg Subtype.val (hS ⟨x, hx⟩ trivial ⟨y, hy⟩ trivial fun U hU ↦ ?_)
rw [← hV U hU]
exact h _ (mem_image_of_mem _ hU)
theorem HasCountableSeparatingOn.subtype_iff {α : Type*} {p : Set α → Prop} {t : Set α} :
HasCountableSeparatingOn t (fun u ↦ ∃ v, p v ∧ (↑) ⁻¹' v = u) univ ↔
HasCountableSeparatingOn α p t := by
constructor <;> intro h
· exact h.of_subtype $ fun s ↦ id
rcases h with ⟨S, Sct, Sp, hS⟩
use {Subtype.val ⁻¹' s | s ∈ S}, Sct.image _, ?_, ?_
· rintro u ⟨t, tS, rfl⟩
exact ⟨t, Sp _ tS, rfl⟩
rintro x - y - hxy
exact Subtype.val_injective $ hS _ (Subtype.coe_prop _) _ (Subtype.coe_prop _)
fun s hs ↦ hxy (Subtype.val ⁻¹' s) ⟨s, hs, rfl⟩
namespace Filter
variable {α β : Type*} {l : Filter α} [CountableInterFilter l] {f g : α → β}
/-!
### Filters supported on a (sub)singleton
In this section we prove several versions of the following theorem. Let `l : Filter α` be a filter
with countable intersections property. Let `p : Set α → Prop` be a property such that there exists a
countable family of sets satisfying `p` and separating points of `α`. Then `l` is supported on
a subsingleton: there exists a subsingleton `t` such that `t ∈ l`.
With extra `Nonempty`/`Set.Nonempty` assumptions one can ensure that `t` is a singleton `{x}`.
If `s ∈ l`, then it suffices to assume that the countable family separates only points of `s`.
-/
theorem exists_subset_subsingleton_mem_of_forall_separating (p : Set α → Prop)
{s : Set α} [h : HasCountableSeparatingOn α p s] (hs : s ∈ l)
(hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ t, t ⊆ s ∧ t.Subsingleton ∧ t ∈ l := by
rcases h.1 with ⟨S, hSc, hSp, hS⟩
refine ⟨s ∩ ⋂₀ (S ∩ l.sets) ∩ ⋂ (U ∈ S) (_ : Uᶜ ∈ l), Uᶜ, ?_, ?_, ?_⟩
· exact fun _ h ↦ h.1.1
· intro x hx y hy
simp only [mem_sInter, mem_inter_iff, mem_iInter, mem_compl_iff] at hx hy
refine hS x hx.1.1 y hy.1.1 (fun s hsS ↦ ?_)
cases hl s (hSp s hsS) with
| inl hsl => simp only [hx.1.2 s ⟨hsS, hsl⟩, hy.1.2 s ⟨hsS, hsl⟩]
| inr hsl => simp only [hx.2 s hsS hsl, hy.2 s hsS hsl]
· exact inter_mem
(inter_mem hs ((countable_sInter_mem (hSc.mono inter_subset_left)).2 fun _ h ↦ h.2))
((countable_bInter_mem hSc).2 fun U hU ↦ iInter_mem.2 id)
theorem exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating (p : Set α → Prop)
{s : Set α} [HasCountableSeparatingOn α p s] (hs : s ∈ l) (hne : s.Nonempty)
(hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) : ∃ a ∈ s, {a} ∈ l := by
rcases exists_subset_subsingleton_mem_of_forall_separating p hs hl with ⟨t, hts, ht, htl⟩
rcases ht.eq_empty_or_singleton with rfl | ⟨x, rfl⟩
· exact hne.imp fun a ha ↦ ⟨ha, mem_of_superset htl (empty_subset _)⟩
· exact ⟨x, hts rfl, htl⟩
theorem exists_singleton_mem_of_mem_of_forall_separating [Nonempty α] (p : Set α → Prop)
{s : Set α} [HasCountableSeparatingOn α p s] (hs : s ∈ l) (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) :
∃ a, {a} ∈ l := by
rcases s.eq_empty_or_nonempty with rfl | hne
· exact ‹Nonempty α›.elim fun a ↦ ⟨a, mem_of_superset hs (empty_subset _)⟩
· exact (exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating p hs hne hl).imp fun _ ↦
And.right
theorem exists_subsingleton_mem_of_forall_separating (p : Set α → Prop)
[HasCountableSeparatingOn α p univ] (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) :
∃ s : Set α, s.Subsingleton ∧ s ∈ l :=
let ⟨t, _, hts, htl⟩ := exists_subset_subsingleton_mem_of_forall_separating p univ_mem hl
⟨t, hts, htl⟩
theorem exists_singleton_mem_of_forall_separating [Nonempty α] (p : Set α → Prop)
[HasCountableSeparatingOn α p univ] (hl : ∀ U, p U → U ∈ l ∨ Uᶜ ∈ l) :
∃ x : α, {x} ∈ l :=
exists_singleton_mem_of_mem_of_forall_separating p univ_mem hl
/-!
### Eventually constant functions
In this section we apply theorems from the previous section to the filter `Filter.map f l` to show
that `f : α → β` is eventually constant along `l` if for every `U` from the separating family,
either `∀ᶠ x in l, f x ∈ U` or `∀ᶠ x in l, f x ∉ U`.
-/
theorem exists_mem_eventuallyEq_const_of_eventually_mem_of_forall_separating (p : Set β → Prop)
{s : Set β} [HasCountableSeparatingOn β p s] (hs : ∀ᶠ x in l, f x ∈ s) (hne : s.Nonempty)
(h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) :
∃ a ∈ s, f =ᶠ[l] const α a :=
exists_mem_singleton_mem_of_mem_of_nonempty_of_forall_separating p (l := map f l) hs hne h
theorem exists_eventuallyEq_const_of_eventually_mem_of_forall_separating [Nonempty β]
(p : Set β → Prop) {s : Set β} [HasCountableSeparatingOn β p s] (hs : ∀ᶠ x in l, f x ∈ s)
(h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) :
∃ a, f =ᶠ[l] const α a :=
exists_singleton_mem_of_mem_of_forall_separating (l := map f l) p hs h
theorem exists_eventuallyEq_const_of_forall_separating [Nonempty β] (p : Set β → Prop)
[HasCountableSeparatingOn β p univ]
(h : ∀ U, p U → (∀ᶠ x in l, f x ∈ U) ∨ (∀ᶠ x in l, f x ∉ U)) :
∃ a, f =ᶠ[l] const α a :=
exists_singleton_mem_of_forall_separating (l := map f l) p h
namespace EventuallyEq
/-!
### Eventually equal functions
In this section we show that two functions are equal along a filter with countable intersections
property if the preimages of all sets from a countable separating family of sets are equal along
the filter.
-/
theorem of_eventually_mem_of_forall_separating_mem_iff (p : Set β → Prop) {s : Set β}
[h' : HasCountableSeparatingOn β p s] (hf : ∀ᶠ x in l, f x ∈ s) (hg : ∀ᶠ x in l, g x ∈ s)
(h : ∀ U : Set β, p U → ∀ᶠ x in l, f x ∈ U ↔ g x ∈ U) : f =ᶠ[l] g := by
rcases h'.1 with ⟨S, hSc, hSp, hS⟩
have H : ∀ᶠ x in l, ∀ s ∈ S, f x ∈ s ↔ g x ∈ s :=
(eventually_countable_ball hSc).2 fun s hs ↦ (h _ (hSp _ hs))
filter_upwards [H, hf, hg] with x hx hxf hxg using hS _ hxf _ hxg hx
theorem of_forall_separating_mem_iff (p : Set β → Prop)
[HasCountableSeparatingOn β p univ] (h : ∀ U : Set β, p U → ∀ᶠ x in l, f x ∈ U ↔ g x ∈ U) :
f =ᶠ[l] g :=
of_eventually_mem_of_forall_separating_mem_iff p (s := univ) univ_mem univ_mem h
theorem of_eventually_mem_of_forall_separating_preimage (p : Set β → Prop) {s : Set β}
[HasCountableSeparatingOn β p s] (hf : ∀ᶠ x in l, f x ∈ s) (hg : ∀ᶠ x in l, g x ∈ s)
(h : ∀ U : Set β, p U → f ⁻¹' U =ᶠ[l] g ⁻¹' U) : f =ᶠ[l] g :=
of_eventually_mem_of_forall_separating_mem_iff p hf hg fun U hU ↦ (h U hU).mem_iff
theorem of_forall_separating_preimage (p : Set β → Prop) [HasCountableSeparatingOn β p univ]
(h : ∀ U : Set β, p U → f ⁻¹' U =ᶠ[l] g ⁻¹' U) : f =ᶠ[l] g :=
of_eventually_mem_of_forall_separating_preimage p (s := univ) univ_mem univ_mem h
end EventuallyEq
end Filter
|
Order\Filter\Curry.lean | /-
Copyright (c) 2022 Kevin H. Wilson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin H. Wilson
-/
import Mathlib.Order.Filter.Prod
/-!
# Curried Filters
This file provides an operation (`Filter.curry`) on filters which provides the equivalence
`∀ᶠ a in l, ∀ᶠ b in l', p (a, b) ↔ ∀ᶠ c in (l.curry l'), p c` (see `Filter.eventually_curry_iff`).
To understand when this operation might arise, it is helpful to think of `∀ᶠ` as a combination of
the quantifiers `∃ ∀`. For instance, `∀ᶠ n in atTop, p n ↔ ∃ N, ∀ n ≥ N, p n`. A curried filter
yields the quantifier order `∃ ∀ ∃ ∀`. For instance,
`∀ᶠ n in atTop.curry atTop, p n ↔ ∃ M, ∀ m ≥ M, ∃ N, ∀ n ≥ N, p (m, n)`.
This is different from a product filter, which instead yields a quantifier order `∃ ∃ ∀ ∀`. For
instance, `∀ᶠ n in atTop ×ˢ atTop, p n ↔ ∃ M, ∃ N, ∀ m ≥ M, ∀ n ≥ N, p (m, n)`. This makes it
clear that if something eventually occurs on the product filter, it eventually occurs on the curried
filter (see `Filter.curry_le_prod` and `Filter.Eventually.curry`), but the converse is not true.
Another way to think about the curried versus the product filter is that tending to some limit on
the product filter is a version of uniform convergence (see `tendsto_prod_filter_iff`) whereas
tending to some limit on a curried filter is just iterated limits (see `Filter.Tendsto.curry`).
In the "generalized set" intuition, `Filter.prod` and `Filter.curry` correspond to two ways of
describing the product of two sets, namely `s ×ˢ t = fst ⁻¹' s ∩ snd ⁻¹' t` and
`s ×ˢ t = ⋃ x ∈ s, (x, ·) '' t`.
## Main definitions
* `Filter.curry`: A binary operation on filters which represents iterated limits
## Main statements
* `Filter.eventually_curry_iff`: An alternative definition of a curried filter
* `Filter.curry_le_prod`: Something that is eventually true on the a product filter is eventually
true on the curried filter
## Tags
uniform convergence, curried filters, product filters
-/
namespace Filter
variable {α β γ : Type*}
/-- This filter is characterized by `Filter.eventually_curry_iff`:
`(∀ᶠ (x : α × β) in f.curry g, p x) ↔ ∀ᶠ (x : α) in f, ∀ᶠ (y : β) in g, p (x, y)`. Useful
in adding quantifiers to the middle of `Tendsto`s. See
`hasFDerivAt_of_tendstoUniformlyOnFilter`. -/
def curry (f : Filter α) (g : Filter β) : Filter (α × β) :=
bind f fun a ↦ map (a, ·) g
theorem eventually_curry_iff {f : Filter α} {g : Filter β} {p : α × β → Prop} :
(∀ᶠ x : α × β in f.curry g, p x) ↔ ∀ᶠ x : α in f, ∀ᶠ y : β in g, p (x, y) :=
Iff.rfl
theorem frequently_curry_iff {α β : Type*} {l : Filter α} {m : Filter β}
(p : (α × β) → Prop) : (∃ᶠ x in l.curry m, p x) ↔ ∃ᶠ x in l, ∃ᶠ y in m, p (x, y) := by
simp_rw [Filter.Frequently, not_iff_not, not_not, eventually_curry_iff]
theorem mem_curry_iff {f : Filter α} {g : Filter β} {s : Set (α × β)} :
s ∈ f.curry g ↔ ∀ᶠ x : α in f, ∀ᶠ y : β in g, (x, y) ∈ s := Iff.rfl
theorem curry_le_prod {f : Filter α} {g : Filter β} : f.curry g ≤ f.prod g :=
fun _ => Eventually.curry
theorem Tendsto.curry {f : α → β → γ} {la : Filter α} {lb : Filter β} {lc : Filter γ}
(h : ∀ᶠ a in la, Tendsto (fun b : β => f a b) lb lc) : Tendsto (↿f) (la.curry lb) lc :=
fun _s hs => h.mono fun _a ha => ha hs
theorem frequently_curry_prod_iff {α β : Type*} {l : Filter α} {m : Filter β}
(s : Set α) (t : Set β) : (∃ᶠ x in l.curry m, x ∈ s ×ˢ t) ↔ sᶜ ∉ l ∧ tᶜ ∉ m := by
refine ⟨fun h => ?_, fun ⟨hs, ht⟩ => ?_⟩
· exact frequently_prod_and.mp (Frequently.filter_mono h curry_le_prod)
rw [frequently_curry_iff]
exact Frequently.mono hs $ fun x hx => Frequently.mono ht (by simp[hx])
theorem prod_mem_curry {α β : Type*} {l : Filter α} {m : Filter β} {s : Set α} {t : Set β}
(hs : s ∈ l) (ht : t ∈ m) : s ×ˢ t ∈ l.curry m :=
curry_le_prod $ prod_mem_prod hs ht
theorem eventually_curry_prod_iff {α β : Type*} {l : Filter α} {m : Filter β}
[NeBot l] [NeBot m] (s : Set α) (t : Set β) :
(∀ᶠ x in l.curry m, x ∈ s ×ˢ t) ↔ s ∈ l ∧ t ∈ m := by
refine ⟨fun h => ⟨?_, ?_⟩, fun ⟨hs, ht⟩ => prod_mem_curry hs ht⟩ <;>
rw [eventually_curry_iff] at h
· apply mem_of_superset h
simp
rcases h.exists with ⟨_, hx⟩
apply mem_of_superset hx
exact fun _ hy => hy.2
end Filter
|
Order\Filter\ENNReal.lean | /-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Topology.Instances.ENNReal
/-!
# Order properties of extended non-negative reals
This file compiles filter-related results about `ℝ≥0∞` (see Data/Real/ENNReal.lean).
-/
open Filter ENNReal
namespace ENNReal
variable {α : Type*} {f : Filter α}
theorem eventually_le_limsup [CountableInterFilter f] (u : α → ℝ≥0∞) :
∀ᶠ y in f, u y ≤ f.limsup u :=
_root_.eventually_le_limsup
theorem limsup_eq_zero_iff [CountableInterFilter f] {u : α → ℝ≥0∞} :
f.limsup u = 0 ↔ u =ᶠ[f] 0 :=
limsup_eq_bot
theorem limsup_const_mul_of_ne_top {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha_top : a ≠ ⊤) :
(f.limsup fun x : α => a * u x) = a * f.limsup u := by
by_cases ha_zero : a = 0
· simp_rw [ha_zero, zero_mul, ← ENNReal.bot_eq_zero]
exact limsup_const_bot
let g := fun x : ℝ≥0∞ => a * x
have hg_bij : Function.Bijective g :=
Function.bijective_iff_has_inverse.mpr
⟨fun x => a⁻¹ * x,
⟨fun x => by simp [g, ← mul_assoc, ENNReal.inv_mul_cancel ha_zero ha_top], fun x => by
simp [g, ← mul_assoc, ENNReal.mul_inv_cancel ha_zero ha_top]⟩⟩
have hg_mono : StrictMono g :=
Monotone.strictMono_of_injective (fun _ _ _ => by rwa [mul_le_mul_left ha_zero ha_top]) hg_bij.1
let g_iso := StrictMono.orderIsoOfSurjective g hg_mono hg_bij.2
exact (OrderIso.limsup_apply g_iso).symm
theorem limsup_const_mul [CountableInterFilter f] {u : α → ℝ≥0∞} {a : ℝ≥0∞} :
f.limsup (a * u ·) = a * f.limsup u := by
by_cases ha_top : a ≠ ⊤
· exact limsup_const_mul_of_ne_top ha_top
push_neg at ha_top
by_cases hu : u =ᶠ[f] 0
· have hau : (a * u ·) =ᶠ[f] 0 := hu.mono fun x hx => by simp [hx]
simp only [limsup_congr hu, limsup_congr hau, Pi.zero_def, ← ENNReal.bot_eq_zero,
limsup_const_bot]
simp
· have hu_mul : ∃ᶠ x : α in f, ⊤ ≤ ite (u x = 0) (0 : ℝ≥0∞) ⊤ := by
rw [EventuallyEq, not_eventually] at hu
refine hu.mono fun x hx => ?_
rw [Pi.zero_apply] at hx
simp [hx]
have h_top_le : (f.limsup fun x : α => ite (u x = 0) (0 : ℝ≥0∞) ⊤) = ⊤ :=
eq_top_iff.mpr (le_limsup_of_frequently_le hu_mul)
have hfu : f.limsup u ≠ 0 := mt limsup_eq_zero_iff.1 hu
simp only [ha_top, top_mul', h_top_le, hfu, ite_false]
theorem limsup_mul_le [CountableInterFilter f] (u v : α → ℝ≥0∞) :
f.limsup (u * v) ≤ f.limsup u * f.limsup v :=
calc
f.limsup (u * v) ≤ f.limsup fun x => f.limsup u * v x := by
refine limsup_le_limsup ?_
filter_upwards [@eventually_le_limsup _ f _ u] with x hx using mul_le_mul' hx le_rfl
_ = f.limsup u * f.limsup v := limsup_const_mul
theorem limsup_add_le [CountableInterFilter f] (u v : α → ℝ≥0∞) :
f.limsup (u + v) ≤ f.limsup u + f.limsup v :=
sInf_le ((eventually_le_limsup u).mp
((eventually_le_limsup v).mono fun _ hxg hxf => add_le_add hxf hxg))
theorem limsup_liminf_le_liminf_limsup {β} [Countable β] {f : Filter α} [CountableInterFilter f]
{g : Filter β} (u : α → β → ℝ≥0∞) :
(f.limsup fun a : α => g.liminf fun b : β => u a b) ≤
g.liminf fun b => f.limsup fun a => u a b :=
have h1 : ∀ᶠ a in f, ∀ b, u a b ≤ f.limsup fun a' => u a' b := by
rw [eventually_countable_forall]
exact fun b => ENNReal.eventually_le_limsup fun a => u a b
sInf_le <| h1.mono fun x hx => Filter.liminf_le_liminf (Filter.eventually_of_forall hx)
end ENNReal
|
Order\Filter\EventuallyConst.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Floris van Doorn
-/
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Order.Filter.Subsingleton
/-!
# Functions that are eventually constant along a filter
In this file we define a predicate `Filter.EventuallyConst f l` saying that a function `f : α → β`
is eventually equal to a constant along a filter `l`. We also prove some basic properties of these
functions.
## Implementation notes
A naive definition of `Filter.EventuallyConst f l` is `∃ y, ∀ᶠ x in l, f x = y`.
However, this proposition is false for empty `α`, `β`.
Instead, we say that `Filter.map f l` is supported on a subsingleton.
This allows us to drop `[Nonempty _]` assumptions here and there.
-/
open Set
variable {α β γ δ : Type*} {l : Filter α} {f : α → β}
namespace Filter
/-- The proposition that a function is eventually constant along a filter on the domain. -/
def EventuallyConst (f : α → β) (l : Filter α) : Prop := (map f l).Subsingleton
theorem HasBasis.eventuallyConst_iff {ι : Sort*} {p : ι → Prop} {s : ι → Set α}
(h : l.HasBasis p s) : EventuallyConst f l ↔ ∃ i, p i ∧ ∀ x ∈ s i, ∀ y ∈ s i, f x = f y :=
(h.map f).subsingleton_iff.trans <| by simp only [Set.Subsingleton, forall_mem_image]
theorem HasBasis.eventuallyConst_iff' {ι : Sort*} {p : ι → Prop} {s : ι → Set α}
{x : ι → α} (h : l.HasBasis p s) (hx : ∀ i, p i → x i ∈ s i) :
EventuallyConst f l ↔ ∃ i, p i ∧ ∀ y ∈ s i, f y = f (x i) :=
h.eventuallyConst_iff.trans <| exists_congr fun i ↦ and_congr_right fun hi ↦
⟨fun h ↦ (h · · (x i) (hx i hi)), fun h a ha b hb ↦ h a ha ▸ (h b hb).symm⟩
lemma eventuallyConst_iff_tendsto [Nonempty β] :
EventuallyConst f l ↔ ∃ x, Tendsto f l (pure x) :=
subsingleton_iff_exists_le_pure
alias ⟨EventuallyConst.exists_tendsto, _⟩ := eventuallyConst_iff_tendsto
theorem EventuallyConst.of_tendsto {x : β} (h : Tendsto f l (pure x)) : EventuallyConst f l :=
have : Nonempty β := ⟨x⟩; eventuallyConst_iff_tendsto.2 ⟨x, h⟩
theorem eventuallyConst_iff_exists_eventuallyEq [Nonempty β] :
EventuallyConst f l ↔ ∃ c, f =ᶠ[l] fun _ ↦ c :=
subsingleton_iff_exists_singleton_mem
alias ⟨EventuallyConst.eventuallyEq_const, _⟩ := eventuallyConst_iff_exists_eventuallyEq
theorem eventuallyConst_pred' {p : α → Prop} :
EventuallyConst p l ↔ (p =ᶠ[l] fun _ ↦ False) ∨ (p =ᶠ[l] fun _ ↦ True) := by
simp only [eventuallyConst_iff_exists_eventuallyEq, Prop.exists_iff]
theorem eventuallyConst_pred {p : α → Prop} :
EventuallyConst p l ↔ (∀ᶠ x in l, p x) ∨ (∀ᶠ x in l, ¬p x) := by
simp [eventuallyConst_pred', or_comm, EventuallyEq]
theorem eventuallyConst_set' {s : Set α} :
EventuallyConst s l ↔ (s =ᶠ[l] (∅ : Set α)) ∨ s =ᶠ[l] univ :=
eventuallyConst_pred'
theorem eventuallyConst_set {s : Set α} :
EventuallyConst s l ↔ (∀ᶠ x in l, x ∈ s) ∨ (∀ᶠ x in l, x ∉ s) :=
eventuallyConst_pred
theorem eventuallyConst_preimage {s : Set β} {f : α → β} :
EventuallyConst (f ⁻¹' s) l ↔ EventuallyConst s (map f l) :=
.rfl
theorem EventuallyEq.eventuallyConst_iff {g : α → β} (h : f =ᶠ[l] g) :
EventuallyConst f l ↔ EventuallyConst g l := by
simp only [EventuallyConst, map_congr h]
@[simp] theorem eventuallyConst_id : EventuallyConst id l ↔ l.Subsingleton := Iff.rfl
namespace EventuallyConst
@[simp] protected lemma bot : EventuallyConst f ⊥ := subsingleton_bot
@[simp]
protected lemma const (c : β) : EventuallyConst (fun _ ↦ c) l :=
.of_tendsto tendsto_const_pure
protected lemma congr {g} (h : EventuallyConst f l) (hg : f =ᶠ[l] g) : EventuallyConst g l :=
hg.eventuallyConst_iff.1 h
@[nontriviality]
lemma of_subsingleton_right [Subsingleton β] : EventuallyConst f l := .of_subsingleton
nonrec lemma anti {l'} (h : EventuallyConst f l) (hl' : l' ≤ l) : EventuallyConst f l' :=
h.anti (map_mono hl')
@[nontriviality]
lemma of_subsingleton_left [Subsingleton α] : EventuallyConst f l :=
.map .of_subsingleton f
lemma comp (h : EventuallyConst f l) (g : β → γ) : EventuallyConst (g ∘ f) l := h.map g
@[to_additive]
protected lemma inv [Inv β] (h : EventuallyConst f l) : EventuallyConst (f⁻¹) l := h.comp Inv.inv
lemma comp_tendsto {lb : Filter β} {g : β → γ} (hg : EventuallyConst g lb)
(hf : Tendsto f l lb) : EventuallyConst (g ∘ f) l :=
hg.anti hf
lemma apply {ι : Type*} {p : ι → Type*} {g : α → ∀ x, p x}
(h : EventuallyConst g l) (i : ι) : EventuallyConst (g · i) l :=
h.comp <| Function.eval i
lemma comp₂ {g : α → γ} (hf : EventuallyConst f l) (op : β → γ → δ) (hg : EventuallyConst g l) :
EventuallyConst (fun x ↦ op (f x) (g x)) l :=
((hf.prod hg).map op.uncurry).anti <|
(tendsto_map (f := op.uncurry)).comp (tendsto_map.prod_mk tendsto_map)
lemma prod_mk {g : α → γ} (hf : EventuallyConst f l) (hg : EventuallyConst g l) :
EventuallyConst (fun x ↦ (f x, g x)) l :=
hf.comp₂ Prod.mk hg
@[to_additive]
lemma mul [Mul β] {g : α → β} (hf : EventuallyConst f l) (hg : EventuallyConst g l) :
EventuallyConst (f * g) l :=
hf.comp₂ (· * ·) hg
variable [One β] {s : Set α} {c : β}
@[to_additive]
lemma of_mulIndicator_const (h : EventuallyConst (s.mulIndicator fun _ ↦ c) l) (hc : c ≠ 1) :
EventuallyConst s l := by
simpa [(· ∘ ·), hc, imp_false] using h.comp (· = c)
@[to_additive]
theorem mulIndicator_const (h : EventuallyConst s l) (c : β) :
EventuallyConst (s.mulIndicator fun _ ↦ c) l := by
classical exact h.comp (if · then c else 1)
@[to_additive]
theorem mulIndicator_const_iff_of_ne (hc : c ≠ 1) :
EventuallyConst (s.mulIndicator fun _ ↦ c) l ↔ EventuallyConst s l :=
⟨(of_mulIndicator_const · hc), (mulIndicator_const · c)⟩
@[to_additive (attr := simp)]
theorem mulIndicator_const_iff :
EventuallyConst (s.mulIndicator fun _ ↦ c) l ↔ c = 1 ∨ EventuallyConst s l := by
rcases eq_or_ne c 1 with rfl | hc <;> simp [mulIndicator_const_iff_of_ne, *]
end EventuallyConst
lemma eventuallyConst_atTop [SemilatticeSup α] [Nonempty α] :
EventuallyConst f atTop ↔ (∃ i, ∀ j, i ≤ j → f j = f i) :=
(atTop_basis.eventuallyConst_iff' fun i _ ↦ left_mem_Ici).trans <| by
simp only [true_and, mem_Ici]
lemma eventuallyConst_atTop_nat {f : ℕ → α} :
EventuallyConst f atTop ↔ ∃ n, ∀ m, n ≤ m → f (m + 1) = f m := by
rw [eventuallyConst_atTop]
refine exists_congr fun n ↦ ⟨fun h m hm ↦ ?_, fun h m hm ↦ ?_⟩
· exact (h (m + 1) (hm.trans m.le_succ)).trans (h m hm).symm
· induction m, hm using Nat.le_induction with
| base => rfl
| succ m hm ihm => exact (h m hm).trans ihm
end Filter
|
Order\Filter\Extr.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Algebra.Order.Group.Defs
/-!
# Minimum and maximum w.r.t. a filter and on a set
## Main Definitions
This file defines six predicates of the form `isAB`, where `A` is `Min`, `Max`, or `Extr`,
and `B` is `Filter` or `On`.
* `isMinFilter f l a` means that `f a ≤ f x` in some `l`-neighborhood of `a`;
* `isMaxFilter f l a` means that `f x ≤ f a` in some `l`-neighborhood of `a`;
* `isExtrFilter f l a` means `isMinFilter f l a` or `isMaxFilter f l a`.
Similar predicates with `on` suffix are particular cases for `l = 𝓟 s`.
## Main statements
### Change of the filter (set) argument
* `is*Filter.filter_mono` : replace the filter with a smaller one;
* `is*Filter.filter_inf` : replace a filter `l` with `l ⊓ l'`;
* `is*On.on_subset` : restrict to a smaller set;
* `is*Pn.inter` : replace a set `s` with `s ∩ t`.
### Composition
* `is**.comp_mono` : if `x` is an extremum for `f` and `g` is a monotone function,
then `x` is an extremum for `g ∘ f`;
* `is**.comp_antitone` : similarly for the case of antitone `g`;
* `is**.bicomp_mono` : if `x` is an extremum of the same type for `f` and `g`
and a binary operation `op` is monotone in both arguments, then `x` is an extremum
of the same type for `fun x => op (f x) (g x)`.
* `is*Filter.comp_tendsto` : if `g x` is an extremum for `f` w.r.t. `l'` and `Tendsto g l l'`,
then `x` is an extremum for `f ∘ g` w.r.t. `l`.
* `is*On.on_preimage` : if `g x` is an extremum for `f` on `s`, then `x` is an extremum
for `f ∘ g` on `g ⁻¹' s`.
### Algebraic operations
* `is**.add` : if `x` is an extremum of the same type for two functions,
then it is an extremum of the same type for their sum;
* `is**.neg` : if `x` is an extremum for `f`, then it is an extremum
of the opposite type for `-f`;
* `is**.sub` : if `x` is a minimum for `f` and a maximum for `g`,
then it is a minimum for `f - g` and a maximum for `g - f`;
* `is**.max`, `is**.min`, `is**.sup`, `is**.inf` : similarly for `is**.add`
for pointwise `max`, `min`, `sup`, `inf`, respectively.
### Miscellaneous definitions
* `is**_const` : any point is both a minimum and maximum for a constant function;
* `isMin/Max*.isExt` : any minimum/maximum point is an extremum;
* `is**.dual`, `is**.undual`: conversion between codomains `α` and `dual α`;
## Missing features (TODO)
* Multiplication and division;
* `is**.bicompl` : if `x` is a minimum for `f`, `y` is a minimum for `g`, and `op` is a monotone
binary operation, then `(x, y)` is a minimum for `uncurry (bicompl op f g)`. From this point
of view, `is**.bicomp` is a composition
* It would be nice to have a tactic that specializes `comp_(anti)mono` or `bicomp_mono`
based on a proof of monotonicity of a given (binary) function. The tactic should maintain a `meta`
list of known (anti)monotone (binary) functions with their names, as well as a list of special
types of filters, and define the missing lemmas once one of these two lists grows.
-/
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
open Set Filter
open Filter
section Preorder
variable [Preorder β] [Preorder γ]
variable (f : α → β) (s : Set α) (l : Filter α) (a : α)
/-! ### Definitions -/
/-- `IsMinFilter f l a` means that `f a ≤ f x` for all `x` in some `l`-neighborhood of `a` -/
def IsMinFilter : Prop :=
∀ᶠ x in l, f a ≤ f x
/-- `is_maxFilter f l a` means that `f x ≤ f a` for all `x` in some `l`-neighborhood of `a` -/
def IsMaxFilter : Prop :=
∀ᶠ x in l, f x ≤ f a
/-- `IsExtrFilter f l a` means `IsMinFilter f l a` or `IsMaxFilter f l a` -/
def IsExtrFilter : Prop :=
IsMinFilter f l a ∨ IsMaxFilter f l a
/-- `IsMinOn f s a` means that `f a ≤ f x` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/
def IsMinOn :=
IsMinFilter f (𝓟 s) a
/-- `IsMaxOn f s a` means that `f x ≤ f a` for all `x ∈ s`. Note that we do not assume `a ∈ s`. -/
def IsMaxOn :=
IsMaxFilter f (𝓟 s) a
/-- `IsExtrOn f s a` means `IsMinOn f s a` or `IsMaxOn f s a` -/
def IsExtrOn : Prop :=
IsExtrFilter f (𝓟 s) a
variable {f s a l} {t : Set α} {l' : Filter α}
theorem IsExtrOn.elim {p : Prop} : IsExtrOn f s a → (IsMinOn f s a → p) → (IsMaxOn f s a → p) → p :=
Or.elim
theorem isMinOn_iff : IsMinOn f s a ↔ ∀ x ∈ s, f a ≤ f x :=
Iff.rfl
theorem isMaxOn_iff : IsMaxOn f s a ↔ ∀ x ∈ s, f x ≤ f a :=
Iff.rfl
theorem isMinOn_univ_iff : IsMinOn f univ a ↔ ∀ x, f a ≤ f x :=
univ_subset_iff.trans eq_univ_iff_forall
theorem isMaxOn_univ_iff : IsMaxOn f univ a ↔ ∀ x, f x ≤ f a :=
univ_subset_iff.trans eq_univ_iff_forall
theorem IsMinFilter.tendsto_principal_Ici (h : IsMinFilter f l a) : Tendsto f l (𝓟 <| Ici (f a)) :=
tendsto_principal.2 h
theorem IsMaxFilter.tendsto_principal_Iic (h : IsMaxFilter f l a) : Tendsto f l (𝓟 <| Iic (f a)) :=
tendsto_principal.2 h
/-! ### Conversion to `IsExtr*` -/
theorem IsMinFilter.isExtr : IsMinFilter f l a → IsExtrFilter f l a :=
Or.inl
theorem IsMaxFilter.isExtr : IsMaxFilter f l a → IsExtrFilter f l a :=
Or.inr
theorem IsMinOn.isExtr (h : IsMinOn f s a) : IsExtrOn f s a :=
IsMinFilter.isExtr h
theorem IsMaxOn.isExtr (h : IsMaxOn f s a) : IsExtrOn f s a :=
IsMaxFilter.isExtr h
/-! ### Constant function -/
theorem isMinFilter_const {b : β} : IsMinFilter (fun _ => b) l a :=
univ_mem' fun _ => le_rfl
theorem isMaxFilter_const {b : β} : IsMaxFilter (fun _ => b) l a :=
univ_mem' fun _ => le_rfl
theorem isExtrFilter_const {b : β} : IsExtrFilter (fun _ => b) l a :=
isMinFilter_const.isExtr
theorem isMinOn_const {b : β} : IsMinOn (fun _ => b) s a :=
isMinFilter_const
theorem isMaxOn_const {b : β} : IsMaxOn (fun _ => b) s a :=
isMaxFilter_const
theorem isExtrOn_const {b : β} : IsExtrOn (fun _ => b) s a :=
isExtrFilter_const
/-! ### Order dual -/
open OrderDual (toDual)
theorem isMinFilter_dual_iff : IsMinFilter (toDual ∘ f) l a ↔ IsMaxFilter f l a :=
Iff.rfl
theorem isMaxFilter_dual_iff : IsMaxFilter (toDual ∘ f) l a ↔ IsMinFilter f l a :=
Iff.rfl
theorem isExtrFilter_dual_iff : IsExtrFilter (toDual ∘ f) l a ↔ IsExtrFilter f l a :=
or_comm
alias ⟨IsMinFilter.undual, IsMaxFilter.dual⟩ := isMinFilter_dual_iff
alias ⟨IsMaxFilter.undual, IsMinFilter.dual⟩ := isMaxFilter_dual_iff
alias ⟨IsExtrFilter.undual, IsExtrFilter.dual⟩ := isExtrFilter_dual_iff
theorem isMinOn_dual_iff : IsMinOn (toDual ∘ f) s a ↔ IsMaxOn f s a :=
Iff.rfl
theorem isMaxOn_dual_iff : IsMaxOn (toDual ∘ f) s a ↔ IsMinOn f s a :=
Iff.rfl
theorem isExtrOn_dual_iff : IsExtrOn (toDual ∘ f) s a ↔ IsExtrOn f s a :=
or_comm
alias ⟨IsMinOn.undual, IsMaxOn.dual⟩ := isMinOn_dual_iff
alias ⟨IsMaxOn.undual, IsMinOn.dual⟩ := isMaxOn_dual_iff
alias ⟨IsExtrOn.undual, IsExtrOn.dual⟩ := isExtrOn_dual_iff
/-! ### Operations on the filter/set -/
theorem IsMinFilter.filter_mono (h : IsMinFilter f l a) (hl : l' ≤ l) : IsMinFilter f l' a :=
hl h
theorem IsMaxFilter.filter_mono (h : IsMaxFilter f l a) (hl : l' ≤ l) : IsMaxFilter f l' a :=
hl h
theorem IsExtrFilter.filter_mono (h : IsExtrFilter f l a) (hl : l' ≤ l) : IsExtrFilter f l' a :=
h.elim (fun h => (h.filter_mono hl).isExtr) fun h => (h.filter_mono hl).isExtr
theorem IsMinFilter.filter_inf (h : IsMinFilter f l a) (l') : IsMinFilter f (l ⊓ l') a :=
h.filter_mono inf_le_left
theorem IsMaxFilter.filter_inf (h : IsMaxFilter f l a) (l') : IsMaxFilter f (l ⊓ l') a :=
h.filter_mono inf_le_left
theorem IsExtrFilter.filter_inf (h : IsExtrFilter f l a) (l') : IsExtrFilter f (l ⊓ l') a :=
h.filter_mono inf_le_left
theorem IsMinOn.on_subset (hf : IsMinOn f t a) (h : s ⊆ t) : IsMinOn f s a :=
hf.filter_mono <| principal_mono.2 h
theorem IsMaxOn.on_subset (hf : IsMaxOn f t a) (h : s ⊆ t) : IsMaxOn f s a :=
hf.filter_mono <| principal_mono.2 h
theorem IsExtrOn.on_subset (hf : IsExtrOn f t a) (h : s ⊆ t) : IsExtrOn f s a :=
hf.filter_mono <| principal_mono.2 h
theorem IsMinOn.inter (hf : IsMinOn f s a) (t) : IsMinOn f (s ∩ t) a :=
hf.on_subset inter_subset_left
theorem IsMaxOn.inter (hf : IsMaxOn f s a) (t) : IsMaxOn f (s ∩ t) a :=
hf.on_subset inter_subset_left
theorem IsExtrOn.inter (hf : IsExtrOn f s a) (t) : IsExtrOn f (s ∩ t) a :=
hf.on_subset inter_subset_left
/-! ### Composition with (anti)monotone functions -/
theorem IsMinFilter.comp_mono (hf : IsMinFilter f l a) {g : β → γ} (hg : Monotone g) :
IsMinFilter (g ∘ f) l a :=
mem_of_superset hf fun _x hx => hg hx
theorem IsMaxFilter.comp_mono (hf : IsMaxFilter f l a) {g : β → γ} (hg : Monotone g) :
IsMaxFilter (g ∘ f) l a :=
mem_of_superset hf fun _x hx => hg hx
theorem IsExtrFilter.comp_mono (hf : IsExtrFilter f l a) {g : β → γ} (hg : Monotone g) :
IsExtrFilter (g ∘ f) l a :=
hf.elim (fun hf => (hf.comp_mono hg).isExtr) fun hf => (hf.comp_mono hg).isExtr
theorem IsMinFilter.comp_antitone (hf : IsMinFilter f l a) {g : β → γ} (hg : Antitone g) :
IsMaxFilter (g ∘ f) l a :=
hf.dual.comp_mono fun _ _ h => hg h
theorem IsMaxFilter.comp_antitone (hf : IsMaxFilter f l a) {g : β → γ} (hg : Antitone g) :
IsMinFilter (g ∘ f) l a :=
hf.dual.comp_mono fun _ _ h => hg h
theorem IsExtrFilter.comp_antitone (hf : IsExtrFilter f l a) {g : β → γ} (hg : Antitone g) :
IsExtrFilter (g ∘ f) l a :=
hf.dual.comp_mono fun _ _ h => hg h
theorem IsMinOn.comp_mono (hf : IsMinOn f s a) {g : β → γ} (hg : Monotone g) :
IsMinOn (g ∘ f) s a :=
IsMinFilter.comp_mono hf hg
theorem IsMaxOn.comp_mono (hf : IsMaxOn f s a) {g : β → γ} (hg : Monotone g) :
IsMaxOn (g ∘ f) s a :=
IsMaxFilter.comp_mono hf hg
theorem IsExtrOn.comp_mono (hf : IsExtrOn f s a) {g : β → γ} (hg : Monotone g) :
IsExtrOn (g ∘ f) s a :=
IsExtrFilter.comp_mono hf hg
theorem IsMinOn.comp_antitone (hf : IsMinOn f s a) {g : β → γ} (hg : Antitone g) :
IsMaxOn (g ∘ f) s a :=
IsMinFilter.comp_antitone hf hg
theorem IsMaxOn.comp_antitone (hf : IsMaxOn f s a) {g : β → γ} (hg : Antitone g) :
IsMinOn (g ∘ f) s a :=
IsMaxFilter.comp_antitone hf hg
theorem IsExtrOn.comp_antitone (hf : IsExtrOn f s a) {g : β → γ} (hg : Antitone g) :
IsExtrOn (g ∘ f) s a :=
IsExtrFilter.comp_antitone hf hg
theorem IsMinFilter.bicomp_mono [Preorder δ] {op : β → γ → δ}
(hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinFilter f l a) {g : α → γ}
(hg : IsMinFilter g l a) : IsMinFilter (fun x => op (f x) (g x)) l a :=
mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx
theorem IsMaxFilter.bicomp_mono [Preorder δ] {op : β → γ → δ}
(hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxFilter f l a) {g : α → γ}
(hg : IsMaxFilter g l a) : IsMaxFilter (fun x => op (f x) (g x)) l a :=
mem_of_superset (inter_mem hf hg) fun _x ⟨hfx, hgx⟩ => hop hfx hgx
-- No `Extr` version because we need `hf` and `hg` to be of the same kind
theorem IsMinOn.bicomp_mono [Preorder δ] {op : β → γ → δ}
(hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMinOn f s a) {g : α → γ}
(hg : IsMinOn g s a) : IsMinOn (fun x => op (f x) (g x)) s a :=
IsMinFilter.bicomp_mono hop hf hg
theorem IsMaxOn.bicomp_mono [Preorder δ] {op : β → γ → δ}
(hop : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) op op) (hf : IsMaxOn f s a) {g : α → γ}
(hg : IsMaxOn g s a) : IsMaxOn (fun x => op (f x) (g x)) s a :=
IsMaxFilter.bicomp_mono hop hf hg
/-! ### Composition with `Tendsto` -/
theorem IsMinFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMinFilter f l (g b))
(hg : Tendsto g l' l) : IsMinFilter (f ∘ g) l' b :=
hg hf
theorem IsMaxFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsMaxFilter f l (g b))
(hg : Tendsto g l' l) : IsMaxFilter (f ∘ g) l' b :=
hg hf
theorem IsExtrFilter.comp_tendsto {g : δ → α} {l' : Filter δ} {b : δ} (hf : IsExtrFilter f l (g b))
(hg : Tendsto g l' l) : IsExtrFilter (f ∘ g) l' b :=
hf.elim (fun hf => (hf.comp_tendsto hg).isExtr) fun hf => (hf.comp_tendsto hg).isExtr
theorem IsMinOn.on_preimage (g : δ → α) {b : δ} (hf : IsMinOn f s (g b)) :
IsMinOn (f ∘ g) (g ⁻¹' s) b :=
hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _)
theorem IsMaxOn.on_preimage (g : δ → α) {b : δ} (hf : IsMaxOn f s (g b)) :
IsMaxOn (f ∘ g) (g ⁻¹' s) b :=
hf.comp_tendsto (tendsto_principal_principal.mpr <| Subset.refl _)
theorem IsExtrOn.on_preimage (g : δ → α) {b : δ} (hf : IsExtrOn f s (g b)) :
IsExtrOn (f ∘ g) (g ⁻¹' s) b :=
hf.elim (fun hf => (hf.on_preimage g).isExtr) fun hf => (hf.on_preimage g).isExtr
theorem IsMinOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMinOn f s a) (hg : MapsTo g t s)
(ha : g b = a) : IsMinOn (f ∘ g) t b := fun y hy => by
simpa only [ha, (· ∘ ·)] using hf (hg hy)
theorem IsMaxOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsMaxOn f s a) (hg : MapsTo g t s)
(ha : g b = a) : IsMaxOn (f ∘ g) t b :=
hf.dual.comp_mapsTo hg ha
theorem IsExtrOn.comp_mapsTo {t : Set δ} {g : δ → α} {b : δ} (hf : IsExtrOn f s a)
(hg : MapsTo g t s) (ha : g b = a) : IsExtrOn (f ∘ g) t b :=
hf.elim (fun h => Or.inl <| h.comp_mapsTo hg ha) fun h => Or.inr <| h.comp_mapsTo hg ha
end Preorder
/-! ### Pointwise addition -/
section OrderedAddCommMonoid
variable [OrderedAddCommMonoid β] {f g : α → β} {a : α} {s : Set α} {l : Filter α}
theorem IsMinFilter.add (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) :
IsMinFilter (fun x => f x + g x) l a :=
show IsMinFilter (fun x => f x + g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg
theorem IsMaxFilter.add (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) :
IsMaxFilter (fun x => f x + g x) l a :=
show IsMaxFilter (fun x => f x + g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => add_le_add hx hy) hg
theorem IsMinOn.add (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x + g x) s a :=
IsMinFilter.add hf hg
theorem IsMaxOn.add (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x + g x) s a :=
IsMaxFilter.add hf hg
end OrderedAddCommMonoid
/-! ### Pointwise negation and subtraction -/
section OrderedAddCommGroup
variable [OrderedAddCommGroup β] {f g : α → β} {a : α} {s : Set α} {l : Filter α}
theorem IsMinFilter.neg (hf : IsMinFilter f l a) : IsMaxFilter (fun x => -f x) l a :=
hf.comp_antitone fun _x _y hx => neg_le_neg hx
theorem IsMaxFilter.neg (hf : IsMaxFilter f l a) : IsMinFilter (fun x => -f x) l a :=
hf.comp_antitone fun _x _y hx => neg_le_neg hx
theorem IsExtrFilter.neg (hf : IsExtrFilter f l a) : IsExtrFilter (fun x => -f x) l a :=
hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr
theorem IsMinOn.neg (hf : IsMinOn f s a) : IsMaxOn (fun x => -f x) s a :=
hf.comp_antitone fun _x _y hx => neg_le_neg hx
theorem IsMaxOn.neg (hf : IsMaxOn f s a) : IsMinOn (fun x => -f x) s a :=
hf.comp_antitone fun _x _y hx => neg_le_neg hx
theorem IsExtrOn.neg (hf : IsExtrOn f s a) : IsExtrOn (fun x => -f x) s a :=
hf.elim (fun hf => hf.neg.isExtr) fun hf => hf.neg.isExtr
theorem IsMinFilter.sub (hf : IsMinFilter f l a) (hg : IsMaxFilter g l a) :
IsMinFilter (fun x => f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem IsMaxFilter.sub (hf : IsMaxFilter f l a) (hg : IsMinFilter g l a) :
IsMaxFilter (fun x => f x - g x) l a := by simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem IsMinOn.sub (hf : IsMinOn f s a) (hg : IsMaxOn g s a) :
IsMinOn (fun x => f x - g x) s a := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem IsMaxOn.sub (hf : IsMaxOn f s a) (hg : IsMinOn g s a) :
IsMaxOn (fun x => f x - g x) s a := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
end OrderedAddCommGroup
/-! ### Pointwise `sup`/`inf` -/
section SemilatticeSup
variable [SemilatticeSup β] {f g : α → β} {a : α} {s : Set α} {l : Filter α}
theorem IsMinFilter.sup (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) :
IsMinFilter (fun x => f x ⊔ g x) l a :=
show IsMinFilter (fun x => f x ⊔ g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => sup_le_sup hx hy) hg
theorem IsMaxFilter.sup (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) :
IsMaxFilter (fun x => f x ⊔ g x) l a :=
show IsMaxFilter (fun x => f x ⊔ g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => sup_le_sup hx hy) hg
theorem IsMinOn.sup (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x ⊔ g x) s a :=
IsMinFilter.sup hf hg
theorem IsMaxOn.sup (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x ⊔ g x) s a :=
IsMaxFilter.sup hf hg
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf β] {f g : α → β} {a : α} {s : Set α} {l : Filter α}
theorem IsMinFilter.inf (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) :
IsMinFilter (fun x => f x ⊓ g x) l a :=
show IsMinFilter (fun x => f x ⊓ g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => inf_le_inf hx hy) hg
theorem IsMaxFilter.inf (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) :
IsMaxFilter (fun x => f x ⊓ g x) l a :=
show IsMaxFilter (fun x => f x ⊓ g x) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => inf_le_inf hx hy) hg
theorem IsMinOn.inf (hf : IsMinOn f s a) (hg : IsMinOn g s a) : IsMinOn (fun x => f x ⊓ g x) s a :=
IsMinFilter.inf hf hg
theorem IsMaxOn.inf (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) : IsMaxOn (fun x => f x ⊓ g x) s a :=
IsMaxFilter.inf hf hg
end SemilatticeInf
/-! ### Pointwise `min`/`max` -/
section LinearOrder
variable [LinearOrder β] {f g : α → β} {a : α} {s : Set α} {l : Filter α}
theorem IsMinFilter.min (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) :
IsMinFilter (fun x => min (f x) (g x)) l a :=
show IsMinFilter (fun x => Min.min (f x) (g x)) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => min_le_min hx hy) hg
theorem IsMaxFilter.min (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) :
IsMaxFilter (fun x => min (f x) (g x)) l a :=
show IsMaxFilter (fun x => Min.min (f x) (g x)) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => min_le_min hx hy) hg
theorem IsMinOn.min (hf : IsMinOn f s a) (hg : IsMinOn g s a) :
IsMinOn (fun x => min (f x) (g x)) s a :=
IsMinFilter.min hf hg
theorem IsMaxOn.min (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) :
IsMaxOn (fun x => min (f x) (g x)) s a :=
IsMaxFilter.min hf hg
theorem IsMinFilter.max (hf : IsMinFilter f l a) (hg : IsMinFilter g l a) :
IsMinFilter (fun x => max (f x) (g x)) l a :=
show IsMinFilter (fun x => Max.max (f x) (g x)) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => max_le_max hx hy) hg
theorem IsMaxFilter.max (hf : IsMaxFilter f l a) (hg : IsMaxFilter g l a) :
IsMaxFilter (fun x => max (f x) (g x)) l a :=
show IsMaxFilter (fun x => Max.max (f x) (g x)) l a from
hf.bicomp_mono (fun _x _x' hx _y _y' hy => max_le_max hx hy) hg
theorem IsMinOn.max (hf : IsMinOn f s a) (hg : IsMinOn g s a) :
IsMinOn (fun x => max (f x) (g x)) s a :=
IsMinFilter.max hf hg
theorem IsMaxOn.max (hf : IsMaxOn f s a) (hg : IsMaxOn g s a) :
IsMaxOn (fun x => max (f x) (g x)) s a :=
IsMaxFilter.max hf hg
end LinearOrder
section Eventually
/-! ### Relation with `eventually` comparisons of two functions -/
theorem Filter.EventuallyLE.isMaxFilter {α β : Type*} [Preorder β] {f g : α → β} {a : α}
{l : Filter α} (hle : g ≤ᶠ[l] f) (hfga : f a = g a) (h : IsMaxFilter f l a) :
IsMaxFilter g l a := by
refine hle.mp (h.mono fun x hf hgf => ?_)
rw [← hfga]
exact le_trans hgf hf
theorem IsMaxFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α}
(h : IsMaxFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMaxFilter g l a :=
heq.symm.le.isMaxFilter hfga h
theorem Filter.EventuallyEq.isMaxFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α}
{l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMaxFilter f l a ↔ IsMaxFilter g l a :=
⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩
theorem Filter.EventuallyLE.isMinFilter {α β : Type*} [Preorder β] {f g : α → β} {a : α}
{l : Filter α} (hle : f ≤ᶠ[l] g) (hfga : f a = g a) (h : IsMinFilter f l a) :
IsMinFilter g l a :=
@Filter.EventuallyLE.isMaxFilter _ βᵒᵈ _ _ _ _ _ hle hfga h
theorem IsMinFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α}
(h : IsMinFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMinFilter g l a :=
heq.le.isMinFilter hfga h
theorem Filter.EventuallyEq.isMinFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α}
{l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsMinFilter f l a ↔ IsMinFilter g l a :=
⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩
theorem IsExtrFilter.congr {α β : Type*} [Preorder β] {f g : α → β} {a : α} {l : Filter α}
(h : IsExtrFilter f l a) (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsExtrFilter g l a := by
rw [IsExtrFilter] at *
rwa [← heq.isMaxFilter_iff hfga, ← heq.isMinFilter_iff hfga]
theorem Filter.EventuallyEq.isExtrFilter_iff {α β : Type*} [Preorder β] {f g : α → β} {a : α}
{l : Filter α} (heq : f =ᶠ[l] g) (hfga : f a = g a) : IsExtrFilter f l a ↔ IsExtrFilter g l a :=
⟨fun h => h.congr heq hfga, fun h => h.congr heq.symm hfga.symm⟩
end Eventually
/-! ### `isMaxOn`/`isMinOn` imply `ciSup`/`ciInf` -/
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] {f : β → α} {s : Set β} {x₀ : β}
theorem IsMaxOn.iSup_eq (hx₀ : x₀ ∈ s) (h : IsMaxOn f s x₀) : ⨆ x : s, f x = f x₀ :=
haveI : Nonempty s := ⟨⟨x₀, hx₀⟩⟩
ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun x => h x.2) fun _w hw => ⟨⟨x₀, hx₀⟩, hw⟩
theorem IsMinOn.iInf_eq (hx₀ : x₀ ∈ s) (h : IsMinOn f s x₀) : ⨅ x : s, f x = f x₀ :=
@IsMaxOn.iSup_eq αᵒᵈ β _ _ _ _ hx₀ h
end ConditionallyCompleteLinearOrder
|
Order\Filter\FilterProduct.lean | /-
Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Abhimanyu Pallavi Sudhir, Yury Kudryashov
-/
import Mathlib.Order.Filter.Ultrafilter
import Mathlib.Order.Filter.Ring
/-!
# Ultraproducts
If `φ` is an ultrafilter, then the space of germs of functions `f : α → β` at `φ` is called
the *ultraproduct*. In this file we prove properties of ultraproducts that rely on `φ` being an
ultrafilter. Definitions and properties that work for any filter should go to `Order.Filter.Germ`.
## Tags
ultrafilter, ultraproduct
-/
universe u v
variable {α : Type u} {β : Type v} {φ : Ultrafilter α}
namespace Filter
local notation3 "∀* "(...)", "r:(scoped p => Filter.Eventually p (Ultrafilter.toFilter φ)) => r
namespace Germ
open Ultrafilter
local notation "β*" => Germ (φ : Filter α) β
instance instGroupWithZero [GroupWithZero β] : GroupWithZero β* where
__ := instDivInvMonoid
__ := instMonoidWithZero
mul_inv_cancel f := inductionOn f fun f hf ↦ coe_eq.2 <| (φ.em fun y ↦ f y = 0).elim
(fun H ↦ (hf <| coe_eq.2 H).elim) fun H ↦ H.mono fun x ↦ mul_inv_cancel
inv_zero := coe_eq.2 <| by simp only [Function.comp, inv_zero, EventuallyEq.rfl]
instance instDivisionSemiring [DivisionSemiring β] : DivisionSemiring β* where
toSemiring := instSemiring
__ := instGroupWithZero
nnqsmul := _
nnqsmul_def := fun q a => rfl
instance instDivisionRing [DivisionRing β] : DivisionRing β* where
__ := instRing
__ := instDivisionSemiring
qsmul := _
qsmul_def := fun q a => rfl
instance instSemifield [Semifield β] : Semifield β* where
__ := instCommSemiring
__ := instDivisionSemiring
instance instField [Field β] : Field β* where
__ := instCommRing
__ := instDivisionRing
theorem coe_lt [Preorder β] {f g : α → β} : (f : β*) < g ↔ ∀* x, f x < g x := by
simp only [lt_iff_le_not_le, eventually_and, coe_le, eventually_not, EventuallyLE]
theorem coe_pos [Preorder β] [Zero β] {f : α → β} : 0 < (f : β*) ↔ ∀* x, 0 < f x :=
coe_lt
theorem const_lt [Preorder β] {x y : β} : x < y → (↑x : β*) < ↑y :=
coe_lt.mpr ∘ liftRel_const
@[simp, norm_cast]
theorem const_lt_iff [Preorder β] {x y : β} : (↑x : β*) < ↑y ↔ x < y :=
coe_lt.trans liftRel_const_iff
theorem lt_def [Preorder β] : ((· < ·) : β* → β* → Prop) = LiftRel (· < ·) := by
ext ⟨f⟩ ⟨g⟩
exact coe_lt
instance isTotal [LE β] [IsTotal β (· ≤ ·)] : IsTotal β* (· ≤ ·) :=
⟨fun f g =>
inductionOn₂ f g fun _f _g => eventually_or.1 <| eventually_of_forall fun _x => total_of _ _ _⟩
open Classical in
/-- If `φ` is an ultrafilter then the ultraproduct is a linear order. -/
noncomputable instance instLinearOrder [LinearOrder β] : LinearOrder β* :=
Lattice.toLinearOrder _
@[to_additive]
noncomputable instance linearOrderedCommGroup [LinearOrderedCommGroup β] :
LinearOrderedCommGroup β* where
__ := instOrderedCommGroup
__ := instLinearOrder
instance instStrictOrderedSemiring [StrictOrderedSemiring β] : StrictOrderedSemiring β* where
__ := instOrderedSemiring
__ := instOrderedAddCancelCommMonoid
mul_lt_mul_of_pos_left x y z := inductionOn₃ x y z fun _f _g _h hfg hh ↦
coe_lt.2 <| (coe_lt.1 hh).mp <| (coe_lt.1 hfg).mono fun _a ↦ mul_lt_mul_of_pos_left
mul_lt_mul_of_pos_right x y z := inductionOn₃ x y z fun _f _g _h hfg hh ↦
coe_lt.2 <| (coe_lt.1 hh).mp <| (coe_lt.1 hfg).mono fun _a ↦ mul_lt_mul_of_pos_right
instance instStrictOrderedCommSemiring [StrictOrderedCommSemiring β] :
StrictOrderedCommSemiring β* where
__ := instStrictOrderedSemiring
__ := instOrderedCommSemiring
instance instStrictOrderedRing [StrictOrderedRing β] : StrictOrderedRing β* where
__ := instRing
__ := instStrictOrderedSemiring
zero_le_one := const_le zero_le_one
mul_pos x y := inductionOn₂ x y fun _f _g hf hg ↦
coe_pos.2 <| (coe_pos.1 hg).mp <| (coe_pos.1 hf).mono fun _x ↦ mul_pos
instance instStrictOrderedCommRing [StrictOrderedCommRing β] : StrictOrderedCommRing β* where
__ := instStrictOrderedRing
__ := instOrderedCommRing
noncomputable instance instLinearOrderedRing [LinearOrderedRing β] : LinearOrderedRing β* where
__ := instStrictOrderedRing
__ := instLinearOrder
noncomputable instance instLinearOrderedField [LinearOrderedField β] : LinearOrderedField β* where
__ := instLinearOrderedRing
__ := instField
noncomputable instance instLinearOrderedCommRing [LinearOrderedCommRing β] :
LinearOrderedCommRing β* where
__ := instLinearOrderedRing
__ := instCommMonoid
theorem max_def [LinearOrder β] (x y : β*) : max x y = map₂ max x y :=
inductionOn₂ x y fun a b => by
rcases le_total (a : β*) b with h | h
· rw [max_eq_right h, map₂_coe, coe_eq]
exact h.mono fun i hi => (max_eq_right hi).symm
· rw [max_eq_left h, map₂_coe, coe_eq]
exact h.mono fun i hi => (max_eq_left hi).symm
theorem min_def [K : LinearOrder β] (x y : β*) : min x y = map₂ min x y :=
inductionOn₂ x y fun a b => by
rcases le_total (a : β*) b with h | h
· rw [min_eq_left h, map₂_coe, coe_eq]
exact h.mono fun i hi => (min_eq_left hi).symm
· rw [min_eq_right h, map₂_coe, coe_eq]
exact h.mono fun i hi => (min_eq_right hi).symm
theorem abs_def [LinearOrderedAddCommGroup β] (x : β*) : |x| = map abs x :=
inductionOn x fun _a => rfl
@[simp]
theorem const_max [LinearOrder β] (x y : β) : (↑(max x y : β) : β*) = max ↑x ↑y := by
rw [max_def, map₂_const]
@[simp]
theorem const_min [LinearOrder β] (x y : β) : (↑(min x y : β) : β*) = min ↑x ↑y := by
rw [min_def, map₂_const]
@[simp]
theorem const_abs [LinearOrderedAddCommGroup β] (x : β) : (↑|x| : β*) = |↑x| := by
rw [abs_def, map_const]
end Germ
end Filter
|
Order\Filter\IndicatorFunction.lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import Mathlib.Order.Filter.AtTopBot
/-!
# Indicator function and filters
Properties of additive and multiplicative indicator functions involving `=ᶠ` and `≤ᶠ`.
## Tags
indicator, characteristic, filter
-/
variable {α β M E : Type*}
open Set Filter
section One
variable [One M] {s t : Set α} {f g : α → M} {a : α} {l : Filter α}
@[to_additive]
theorem mulIndicator_eventuallyEq (hf : f =ᶠ[l ⊓ 𝓟 s] g) (hs : s =ᶠ[l] t) :
mulIndicator s f =ᶠ[l] mulIndicator t g :=
(eventually_inf_principal.1 hf).mp <| hs.mem_iff.mono fun x hst hfg =>
by_cases
(fun hxs : x ∈ s => by simp only [*, hst.1 hxs, mulIndicator_of_mem])
(fun hxs => by simp only [mulIndicator_of_not_mem, hxs, mt hst.2 hxs, not_false_eq_true])
end One
section Monoid
variable [Monoid M] {s t : Set α} {f g : α → M} {a : α} {l : Filter α}
@[to_additive]
theorem mulIndicator_union_eventuallyEq (h : ∀ᶠ a in l, a ∉ s ∩ t) :
mulIndicator (s ∪ t) f =ᶠ[l] mulIndicator s f * mulIndicator t f :=
h.mono fun _a ha => mulIndicator_union_of_not_mem_inter ha _
end Monoid
section Order
variable [One β] [Preorder β] {s t : Set α} {f g : α → β} {a : α} {l : Filter α}
@[to_additive]
theorem mulIndicator_eventuallyLE_mulIndicator (h : f ≤ᶠ[l ⊓ 𝓟 s] g) :
mulIndicator s f ≤ᶠ[l] mulIndicator s g :=
(eventually_inf_principal.1 h).mono fun _ => mulIndicator_rel_mulIndicator le_rfl
end Order
@[to_additive]
theorem Monotone.mulIndicator_eventuallyEq_iUnion {ι} [Preorder ι] [One β] (s : ι → Set α)
(hs : Monotone s) (f : α → β) (a : α) :
(fun i => mulIndicator (s i) f a) =ᶠ[atTop] fun _ ↦ mulIndicator (⋃ i, s i) f a := by
classical exact hs.piecewise_eventually_eq_iUnion f 1 a
@[to_additive]
theorem Monotone.tendsto_mulIndicator {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Monotone s)
(f : α → β) (a : α) :
Tendsto (fun i => mulIndicator (s i) f a) atTop (pure <| mulIndicator (⋃ i, s i) f a) :=
tendsto_pure.2 <| hs.mulIndicator_eventuallyEq_iUnion s f a
@[to_additive]
theorem Antitone.mulIndicator_eventuallyEq_iInter {ι} [Preorder ι] [One β] (s : ι → Set α)
(hs : Antitone s) (f : α → β) (a : α) :
(fun i => mulIndicator (s i) f a) =ᶠ[atTop] fun _ ↦ mulIndicator (⋂ i, s i) f a := by
classical exact hs.piecewise_eventually_eq_iInter f 1 a
@[to_additive]
theorem Antitone.tendsto_mulIndicator {ι} [Preorder ι] [One β] (s : ι → Set α) (hs : Antitone s)
(f : α → β) (a : α) :
Tendsto (fun i => mulIndicator (s i) f a) atTop (pure <| mulIndicator (⋂ i, s i) f a) :=
tendsto_pure.2 <| hs.mulIndicator_eventuallyEq_iInter s f a
@[to_additive]
theorem mulIndicator_biUnion_finset_eventuallyEq {ι} [One β] (s : ι → Set α) (f : α → β) (a : α) :
(fun n : Finset ι => mulIndicator (⋃ i ∈ n, s i) f a) =ᶠ[atTop]
fun _ ↦ mulIndicator (iUnion s) f a := by
rw [iUnion_eq_iUnion_finset s]
apply Monotone.mulIndicator_eventuallyEq_iUnion
exact fun _ _ ↦ biUnion_subset_biUnion_left
@[to_additive]
theorem tendsto_mulIndicator_biUnion_finset {ι} [One β] (s : ι → Set α) (f : α → β) (a : α) :
Tendsto (fun n : Finset ι => mulIndicator (⋃ i ∈ n, s i) f a) atTop
(pure <| mulIndicator (iUnion s) f a) :=
tendsto_pure.2 <| mulIndicator_biUnion_finset_eventuallyEq s f a
@[to_additive]
protected theorem Filter.EventuallyEq.mulSupport [One β] {f g : α → β} {l : Filter α}
(h : f =ᶠ[l] g) :
Function.mulSupport f =ᶠ[l] Function.mulSupport g :=
h.preimage ({1}ᶜ : Set β)
@[to_additive]
protected theorem Filter.EventuallyEq.mulIndicator [One β] {l : Filter α} {f g : α → β} {s : Set α}
(hfg : f =ᶠ[l] g) : s.mulIndicator f =ᶠ[l] s.mulIndicator g :=
mulIndicator_eventuallyEq (hfg.filter_mono inf_le_left) EventuallyEq.rfl
@[to_additive]
theorem Filter.EventuallyEq.mulIndicator_one [One β] {l : Filter α} {f : α → β} {s : Set α}
(hf : f =ᶠ[l] 1) : s.mulIndicator f =ᶠ[l] 1 :=
hf.mulIndicator.trans <| by rw [mulIndicator_one']
@[to_additive]
theorem Filter.EventuallyEq.of_mulIndicator [One β] {l : Filter α} {f : α → β}
(hf : ∀ᶠ x in l, f x ≠ 1) {s t : Set α} (h : s.mulIndicator f =ᶠ[l] t.mulIndicator f) :
s =ᶠ[l] t := by
have : ∀ {s : Set α}, Function.mulSupport (s.mulIndicator f) =ᶠ[l] s := fun {s} ↦ by
rw [mulSupport_mulIndicator]
exact (hf.mono fun x hx ↦ and_iff_left hx).set_eq
exact this.symm.trans <| h.mulSupport.trans this
@[to_additive]
theorem Filter.EventuallyEq.of_mulIndicator_const [One β] {l : Filter α} {c : β} (hc : c ≠ 1)
{s t : Set α} (h : s.mulIndicator (fun _ ↦ c) =ᶠ[l] t.mulIndicator fun _ ↦ c) : s =ᶠ[l] t :=
.of_mulIndicator (eventually_of_forall fun _ ↦ hc) h
@[to_additive]
theorem Filter.mulIndicator_const_eventuallyEq [One β] {l : Filter α} {c : β} (hc : c ≠ 1)
{s t : Set α} : s.mulIndicator (fun _ ↦ c) =ᶠ[l] t.mulIndicator (fun _ ↦ c) ↔ s =ᶠ[l] t :=
⟨.of_mulIndicator_const hc, mulIndicator_eventuallyEq .rfl⟩
|
Order\Filter\Interval.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Order.Filter.SmallSets
import Mathlib.Order.Filter.AtTopBot
/-!
# Convergence of intervals
## Motivation
If a function tends to infinity somewhere, then its derivative is not integrable around this place.
One should be careful about this statement: "somewhere" could mean a point, but also convergence
from the left or from the right, or it could also be infinity, and "around this place" will refer
to these directed neighborhoods. Therefore, the above theorem has many variants. Instead of stating
all these variants, one can look for the common abstraction and have a single version. One has to
be careful: if one considers convergence along a sequence, then the function may tend to infinity
but have a derivative which is small along the sequence (with big jumps inbetween), so in the end
the derivative may be integrable on a neighborhood of the sequence. What really matters for such
calculus issues in terms of derivatives is that whole intervals are included in the sets we
consider.
The right common abstraction is provided in this file, as the `TendstoIxxClass` typeclass.
It takes as parameters a class of bounded intervals and two real filters `l₁` and `l₂`.
An instance `TendstoIxxClass Icc l₁ l₂` registers that, if `aₙ` and `bₙ` are converging towards
the filter `l₁`, then the intervals `Icc aₙ bₙ` are eventually contained in any given set
belonging to `l₂`. For instance, for `l₁ = 𝓝[>] x` and `l₂ = 𝓝[≥] x`, the strict and large right
neighborhoods of `x` respectively, then given any large right neighborhood `s ∈ 𝓝[≥] x` and any two
sequences `xₙ` and `yₙ` converging strictly to the right of `x`,
then the interval `[xₙ, yₙ]` is eventually contained in `s`. Therefore, the instance
`TendstoIxxClass Icc (𝓝[>] x) (𝓝[≥] x)` holds. Note that one could have taken as
well `l₂ = 𝓝[>] x`, but that `l₁ = 𝓝[≥] x` and `l₂ = 𝓝[>] x` wouldn't work.
With this formalism, the above theorem would read: if `TendstoIxxClass Icc l l` and `f` tends
to infinity along `l`, then its derivative is not integrable on any element of `l`.
Beyond this simple example, this typeclass plays a prominent role in generic formulations of
the fundamental theorem of calculus.
## Main definition
If both `a` and `b` tend to some filter `l₁`, sometimes this implies that `Ixx a b` tends to
`l₂.smallSets`, i.e., for any `s ∈ l₂` eventually `Ixx a b` becomes a subset of `s`. Here and below
`Ixx` is one of `Set.Icc`, `Set.Ico`, `Set.Ioc`, and `Set.Ioo`.
We define `Filter.TendstoIxxClass Ixx l₁ l₂` to be a typeclass representing this property.
The instances provide the best `l₂` for a given `l₁`. In many cases `l₁ = l₂` but sometimes we can
drop an endpoint from an interval: e.g., we prove
`Filter.TendstoIxxClass Set.Ico (𝓟 (Set.Iic a)) (𝓟 (Set.Iio a))`, i.e., if `u₁ n` and `u₂ n` belong
eventually to `Set.Iic a`, then the interval `Set.Ico (u₁ n) (u₂ n)` is eventually included in
`Set.Iio a`.
The next table shows “output” filters `l₂` for different values of `Ixx` and `l₁`. The instances
that need topology are defined in `Mathlib/Topology/Algebra/Ordered`.
| Input filter | `Ixx = Set.Icc` | `Ixx = Set.Ico` | `Ixx = Set.Ioc` | `Ixx = Set.Ioo` |
|-----------------:|:----------------:|:----------------:|:----------------:|:----------------:|
| `Filter.atTop` | `Filter.atTop` | `Filter.atTop` | `Filter.atTop` | `Filter.atTop` |
| `Filter.atBot` | `Filter.atBot` | `Filter.atBot` | `Filter.atBot` | `Filter.atBot` |
| `pure a` | `pure a` | `⊥` | `⊥` | `⊥` |
| `𝓟 (Set.Iic a)` | `𝓟 (Set.Iic a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iic a)` | `𝓟 (Set.Iio a)` |
| `𝓟 (Set.Ici a)` | `𝓟 (Set.Ici a)` | `𝓟 (Set.Ici a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` |
| `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` | `𝓟 (Set.Ioi a)` |
| `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` | `𝓟 (Set.Iio a)` |
| `𝓝 a` | `𝓝 a` | `𝓝 a` | `𝓝 a` | `𝓝 a` |
| `𝓝[Set.Iic a] b` | `𝓝[Set.Iic a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iic a] b` | `𝓝[Set.Iio a] b` |
| `𝓝[Set.Ici a] b` | `𝓝[Set.Ici a] b` | `𝓝[Set.Ici a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` |
| `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` | `𝓝[Set.Ioi a] b` |
| `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` | `𝓝[Set.Iio a] b` |
-/
variable {α β : Type*}
open Filter Set Function
namespace Filter
section Preorder
/-- A pair of filters `l₁`, `l₂` has `TendstoIxxClass Ixx` property if `Ixx a b` tends to
`l₂.small_sets` as `a` and `b` tend to `l₁`. In all instances `Ixx` is one of `Set.Icc`, `Set.Ico`,
`Set.Ioc`, or `Set.Ioo`. The instances provide the best `l₂` for a given `l₁`. In many cases
`l₁ = l₂` but sometimes we can drop an endpoint from an interval: e.g., we prove
`TendstoIxxClass Set.Ico (𝓟 (Set.Iic a)) (𝓟 (Set.Iio a))`, i.e., if `u₁ n` and `u₂ n` belong
eventually to `Set.Iic a`, then the interval `Set.Ico (u₁ n) (u₂ n)` is eventually included in
`Set.Iio a`.
We mark `l₂` as an `outParam` so that Lean can automatically find an appropriate `l₂` based on
`Ixx` and `l₁`. This way, e.g., `tendsto.Ico h₁ h₂` works without specifying explicitly `l₂`. -/
class TendstoIxxClass (Ixx : α → α → Set α) (l₁ : Filter α) (l₂ : outParam <| Filter α) : Prop where
/-- `Function.uncurry Ixx` tends to `l₂.smallSets` along `l₁ ×ˢ l₁`. In other words, for any
`s ∈ l₂` there exists `t ∈ l₁` such that `Ixx x y ⊆ s` whenever `x ∈ t` and `y ∈ t`.
Use lemmas like `Filter.Tendsto.Icc` instead. -/
tendsto_Ixx : Tendsto (fun p : α × α => Ixx p.1 p.2) (l₁ ×ˢ l₁) l₂.smallSets
theorem tendstoIxxClass_principal {s t : Set α} {Ixx : α → α → Set α} :
TendstoIxxClass Ixx (𝓟 s) (𝓟 t) ↔ ∀ᵉ (x ∈ s) (y ∈ s), Ixx x y ⊆ t :=
Iff.trans ⟨fun h => h.1, fun h => ⟨h⟩⟩ <| by
simp only [smallSets_principal, prod_principal_principal, tendsto_principal_principal,
forall_prod_set, mem_powerset_iff, mem_principal]
theorem tendstoIxxClass_inf {l₁ l₁' l₂ l₂' : Filter α} {Ixx} [h : TendstoIxxClass Ixx l₁ l₂]
[h' : TendstoIxxClass Ixx l₁' l₂'] : TendstoIxxClass Ixx (l₁ ⊓ l₁') (l₂ ⊓ l₂') :=
⟨by simpa only [prod_inf_prod, smallSets_inf] using h.1.inf h'.1⟩
theorem tendstoIxxClass_of_subset {l₁ l₂ : Filter α} {Ixx Ixx' : α → α → Set α}
(h : ∀ a b, Ixx a b ⊆ Ixx' a b) [h' : TendstoIxxClass Ixx' l₁ l₂] : TendstoIxxClass Ixx l₁ l₂ :=
⟨h'.1.smallSets_mono <| eventually_of_forall <| Prod.forall.2 h⟩
theorem HasBasis.tendstoIxxClass {ι : Type*} {p : ι → Prop} {s} {l : Filter α}
(hl : l.HasBasis p s) {Ixx : α → α → Set α}
(H : ∀ i, p i → ∀ x ∈ s i, ∀ y ∈ s i, Ixx x y ⊆ s i) : TendstoIxxClass Ixx l l :=
⟨(hl.prod_self.tendsto_iff hl.smallSets).2 fun i hi => ⟨i, hi, fun _ h => H i hi _ h.1 _ h.2⟩⟩
variable [Preorder α]
protected theorem Tendsto.Icc {l₁ l₂ : Filter α} [TendstoIxxClass Icc l₁ l₂] {lb : Filter β}
{u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) :
Tendsto (fun x => Icc (u₁ x) (u₂ x)) lb l₂.smallSets :=
(@TendstoIxxClass.tendsto_Ixx α Set.Icc _ _ _).comp <| h₁.prod_mk h₂
protected theorem Tendsto.Ioc {l₁ l₂ : Filter α} [TendstoIxxClass Ioc l₁ l₂] {lb : Filter β}
{u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) :
Tendsto (fun x => Ioc (u₁ x) (u₂ x)) lb l₂.smallSets :=
(@TendstoIxxClass.tendsto_Ixx α Set.Ioc _ _ _).comp <| h₁.prod_mk h₂
protected theorem Tendsto.Ico {l₁ l₂ : Filter α} [TendstoIxxClass Ico l₁ l₂] {lb : Filter β}
{u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) :
Tendsto (fun x => Ico (u₁ x) (u₂ x)) lb l₂.smallSets :=
(@TendstoIxxClass.tendsto_Ixx α Set.Ico _ _ _).comp <| h₁.prod_mk h₂
protected theorem Tendsto.Ioo {l₁ l₂ : Filter α} [TendstoIxxClass Ioo l₁ l₂] {lb : Filter β}
{u₁ u₂ : β → α} (h₁ : Tendsto u₁ lb l₁) (h₂ : Tendsto u₂ lb l₁) :
Tendsto (fun x => Ioo (u₁ x) (u₂ x)) lb l₂.smallSets :=
(@TendstoIxxClass.tendsto_Ixx α Set.Ioo _ _ _).comp <| h₁.prod_mk h₂
instance tendsto_Icc_atTop_atTop : TendstoIxxClass Icc (atTop : Filter α) atTop :=
(hasBasis_iInf_principal_finite _).tendstoIxxClass fun _ _ =>
Set.OrdConnected.out <| ordConnected_biInter fun _ _ => ordConnected_Ici
instance tendsto_Ico_atTop_atTop : TendstoIxxClass Ico (atTop : Filter α) atTop :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendsto_Ioc_atTop_atTop : TendstoIxxClass Ioc (atTop : Filter α) atTop :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendsto_Ioo_atTop_atTop : TendstoIxxClass Ioo (atTop : Filter α) atTop :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self
instance tendsto_Icc_atBot_atBot : TendstoIxxClass Icc (atBot : Filter α) atBot :=
(hasBasis_iInf_principal_finite _).tendstoIxxClass fun _ _ =>
Set.OrdConnected.out <| ordConnected_biInter fun _ _ => ordConnected_Iic
instance tendsto_Ico_atBot_atBot : TendstoIxxClass Ico (atBot : Filter α) atBot :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendsto_Ioc_atBot_atBot : TendstoIxxClass Ioc (atBot : Filter α) atBot :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendsto_Ioo_atBot_atBot : TendstoIxxClass Ioo (atBot : Filter α) atBot :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self
instance OrdConnected.tendsto_Icc {s : Set α} [hs : OrdConnected s] :
TendstoIxxClass Icc (𝓟 s) (𝓟 s) :=
tendstoIxxClass_principal.2 hs.out
instance tendsto_Ico_Ici_Ici {a : α} : TendstoIxxClass Ico (𝓟 (Ici a)) (𝓟 (Ici a)) :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendsto_Ico_Ioi_Ioi {a : α} : TendstoIxxClass Ico (𝓟 (Ioi a)) (𝓟 (Ioi a)) :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendsto_Ico_Iic_Iio {a : α} : TendstoIxxClass Ico (𝓟 (Iic a)) (𝓟 (Iio a)) :=
tendstoIxxClass_principal.2 fun _ _ _ h₁ _ h₂ => lt_of_lt_of_le h₂.2 h₁
instance tendsto_Ico_Iio_Iio {a : α} : TendstoIxxClass Ico (𝓟 (Iio a)) (𝓟 (Iio a)) :=
tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self
instance tendsto_Ioc_Ici_Ioi {a : α} : TendstoIxxClass Ioc (𝓟 (Ici a)) (𝓟 (Ioi a)) :=
tendstoIxxClass_principal.2 fun _ h₁ _ _ _ h₂ => lt_of_le_of_lt h₁ h₂.1
instance tendsto_Ioc_Iic_Iic {a : α} : TendstoIxxClass Ioc (𝓟 (Iic a)) (𝓟 (Iic a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendsto_Ioc_Iio_Iio {a : α} : TendstoIxxClass Ioc (𝓟 (Iio a)) (𝓟 (Iio a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendsto_Ioc_Ioi_Ioi {a : α} : TendstoIxxClass Ioc (𝓟 (Ioi a)) (𝓟 (Ioi a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
instance tendsto_Ioo_Ici_Ioi {a : α} : TendstoIxxClass Ioo (𝓟 (Ici a)) (𝓟 (Ioi a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self
instance tendsto_Ioo_Iic_Iio {a : α} : TendstoIxxClass Ioo (𝓟 (Iic a)) (𝓟 (Iio a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ico_self
instance tendsto_Ioo_Ioi_Ioi {a : α} : TendstoIxxClass Ioo (𝓟 (Ioi a)) (𝓟 (Ioi a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self
instance tendsto_Ioo_Iio_Iio {a : α} : TendstoIxxClass Ioo (𝓟 (Iio a)) (𝓟 (Iio a)) :=
tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Ioc_self
instance tendsto_Icc_Icc_Icc {a b : α} : TendstoIxxClass Icc (𝓟 (Icc a b)) (𝓟 (Icc a b)) :=
tendstoIxxClass_principal.mpr fun _x hx _y hy => Icc_subset_Icc hx.1 hy.2
instance tendsto_Ioc_Icc_Icc {a b : α} : TendstoIxxClass Ioc (𝓟 (Icc a b)) (𝓟 (Icc a b)) :=
tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self
end Preorder
section PartialOrder
variable [PartialOrder α]
instance tendsto_Icc_pure_pure {a : α} : TendstoIxxClass Icc (pure a) (pure a : Filter α) := by
rw [← principal_singleton]
exact tendstoIxxClass_principal.2 ordConnected_singleton.out
instance tendsto_Ico_pure_bot {a : α} : TendstoIxxClass Ico (pure a) ⊥ :=
⟨by simp⟩
instance tendsto_Ioc_pure_bot {a : α} : TendstoIxxClass Ioc (pure a) ⊥ :=
⟨by simp⟩
instance tendsto_Ioo_pure_bot {a : α} : TendstoIxxClass Ioo (pure a) ⊥ :=
⟨by simp⟩
end PartialOrder
section LinearOrder
open Interval
variable [LinearOrder α]
instance tendsto_Icc_uIcc_uIcc {a b : α} : TendstoIxxClass Icc (𝓟 [[a, b]]) (𝓟 [[a, b]]) :=
Filter.tendsto_Icc_Icc_Icc
instance tendsto_Ioc_uIcc_uIcc {a b : α} : TendstoIxxClass Ioc (𝓟 [[a, b]]) (𝓟 [[a, b]]) :=
Filter.tendsto_Ioc_Icc_Icc
instance tendsto_uIcc_of_Icc {l : Filter α} [TendstoIxxClass Icc l l] :
TendstoIxxClass uIcc l l := by
refine ⟨fun s hs => mem_map.2 <| mem_prod_self_iff.2 ?_⟩
obtain ⟨t, htl, hts⟩ : ∃ t ∈ l, ∀ p ∈ (t : Set α) ×ˢ t, Icc (p : α × α).1 p.2 ∈ s :=
mem_prod_self_iff.1 (mem_map.1 (tendsto_fst.Icc tendsto_snd hs))
refine ⟨t, htl, fun p hp => ?_⟩
rcases le_total p.1 p.2 with h | h
· rw [mem_preimage, uIcc_of_le h]
exact hts p hp
· rw [mem_preimage, uIcc_of_ge h]
exact hts ⟨p.2, p.1⟩ ⟨hp.2, hp.1⟩
protected theorem Tendsto.uIcc {l : Filter α} [TendstoIxxClass Icc l l] {f g : β → α}
{lb : Filter β} (hf : Tendsto f lb l) (hg : Tendsto g lb l) :
Tendsto (fun x => [[f x, g x]]) lb l.smallSets :=
(@TendstoIxxClass.tendsto_Ixx α Set.uIcc _ _ _).comp <| hf.prod_mk hg
end LinearOrder
end Filter
|
Order\Filter\Ker.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Filter.Basic
/-!
# Kernel of a filter
In this file we define the *kernel* `Filter.ker f` of a filter `f`
to be the intersection of all its sets.
We also prove that `Filter.principal` and `Filter.ker` form a Galois coinsertion
and prove other basic theorems about `Filter.ker`.
-/
open Function Set
namespace Filter
variable {ι : Sort*} {α β : Type*} {f g : Filter α} {s : Set α} {a : α}
/-- The *kernel* of a filter is the intersection of all its sets. -/
def ker (f : Filter α) : Set α := ⋂₀ f.sets
lemma ker_def (f : Filter α) : f.ker = ⋂ s ∈ f, s := sInter_eq_biInter
@[simp] lemma mem_ker : a ∈ f.ker ↔ ∀ s ∈ f, a ∈ s := mem_sInter
@[simp] lemma subset_ker : s ⊆ f.ker ↔ ∀ t ∈ f, s ⊆ t := subset_sInter_iff
/-- `Filter.principal` forms a Galois coinsertion with `Filter.ker`. -/
def gi_principal_ker : GaloisCoinsertion (𝓟 : Set α → Filter α) ker :=
GaloisConnection.toGaloisCoinsertion (fun s f ↦ by simp [principal_le_iff]) <| by
simp only [le_iff_subset, subset_def, mem_ker, mem_principal]; aesop
lemma ker_mono : Monotone (ker : Filter α → Set α) := gi_principal_ker.gc.monotone_u
lemma ker_surjective : Surjective (ker : Filter α → Set α) := gi_principal_ker.u_surjective
@[simp] lemma ker_bot : ker (⊥ : Filter α) = ∅ := sInter_eq_empty_iff.2 fun _ ↦ ⟨∅, trivial, id⟩
@[simp] lemma ker_top : ker (⊤ : Filter α) = univ := gi_principal_ker.gc.u_top
@[simp] lemma ker_eq_univ : ker f = univ ↔ f = ⊤ := gi_principal_ker.gc.u_eq_top.trans <| by simp
@[simp] lemma ker_inf (f g : Filter α) : ker (f ⊓ g) = ker f ∩ ker g := gi_principal_ker.gc.u_inf
@[simp] lemma ker_iInf (f : ι → Filter α) : ker (⨅ i, f i) = ⨅ i, ker (f i) :=
gi_principal_ker.gc.u_iInf
@[simp] lemma ker_sInf (S : Set (Filter α)) : ker (sInf S) = ⨅ f ∈ S, ker f :=
gi_principal_ker.gc.u_sInf
@[simp] lemma ker_principal (s : Set α) : ker (𝓟 s) = s := gi_principal_ker.u_l_eq _
@[simp] lemma ker_pure (a : α) : ker (pure a) = {a} := by rw [← principal_singleton, ker_principal]
@[simp] lemma ker_comap (m : α → β) (f : Filter β) : ker (comap m f) = m ⁻¹' ker f := by
ext a
simp only [mem_ker, mem_comap, forall_exists_index, and_imp, @forall_swap (Set α), mem_preimage]
exact forall₂_congr fun s _ ↦ ⟨fun h ↦ h _ Subset.rfl, fun ha t ht ↦ ht ha⟩
end Filter
|
Order\Filter\Lift.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Filter.Bases
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Lift filters along filter and set functions
-/
open Set Filter Function
namespace Filter
variable {α β γ : Type*} {ι : Sort*}
section lift
/-- A variant on `bind` using a function `g` taking a set instead of a member of `α`.
This is essentially a push-forward along a function mapping each set to a filter. -/
protected def lift (f : Filter α) (g : Set α → Filter β) :=
⨅ s ∈ f, g s
variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Set α → Filter β}
@[simp]
theorem lift_top (g : Set α → Filter β) : (⊤ : Filter α).lift g = g univ := by simp [Filter.lift]
-- Porting note: use `∃ i, p i ∧ _` instead of `∃ i (hi : p i), _`
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis
of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`Filter.HasBasis` one has to use `Σ i, β i` as the index type, see `Filter.HasBasis.lift`.
This lemma states the corresponding `mem_iff` statement without using a sigma type. -/
theorem HasBasis.mem_lift_iff {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ}
{g : Set α → Filter γ} (hg : ∀ i, (g <| s i).HasBasis (pg i) (sg i)) (gm : Monotone g)
{s : Set γ} : s ∈ f.lift g ↔ ∃ i, p i ∧ ∃ x, pg i x ∧ sg i x ⊆ s := by
refine (mem_biInf_of_directed ?_ ⟨univ, univ_sets _⟩).trans ?_
· intro t₁ ht₁ t₂ ht₂
exact ⟨t₁ ∩ t₂, inter_mem ht₁ ht₂, gm inter_subset_left, gm inter_subset_right⟩
· simp only [← (hg _).mem_iff]
exact hf.exists_iff fun t₁ t₂ ht H => gm ht H
/-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function
`Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis
of the filter `g (s i)`, then
`(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)`
is a basis of the filter `f.lift g`.
This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using
`has_basis` one has to use `Σ i, β i` as the index type. See also `Filter.HasBasis.mem_lift_iff`
for the corresponding `mem_iff` statement formulated without using a sigma type. -/
theorem HasBasis.lift {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s)
{β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ}
(hg : ∀ i, (g (s i)).HasBasis (pg i) (sg i)) (gm : Monotone g) :
(f.lift g).HasBasis (fun i : Σi, β i => p i.1 ∧ pg i.1 i.2) fun i : Σi, β i => sg i.1 i.2 := by
refine ⟨fun t => (hf.mem_lift_iff hg gm).trans ?_⟩
simp [Sigma.exists, and_assoc, exists_and_left]
theorem mem_lift_sets (hg : Monotone g) {s : Set β} : s ∈ f.lift g ↔ ∃ t ∈ f, s ∈ g t :=
(f.basis_sets.mem_lift_iff (fun s => (g s).basis_sets) hg).trans <| by
simp only [id, exists_mem_subset_iff]
theorem sInter_lift_sets (hg : Monotone g) :
⋂₀ { s | s ∈ f.lift g } = ⋂ s ∈ f, ⋂₀ { t | t ∈ g s } := by
simp only [sInter_eq_biInter, mem_setOf_eq, Filter.mem_sets, mem_lift_sets hg, iInter_exists,
iInter_and, @iInter_comm _ (Set β)]
theorem mem_lift {s : Set β} {t : Set α} (ht : t ∈ f) (hs : s ∈ g t) : s ∈ f.lift g :=
le_principal_iff.mp <|
show f.lift g ≤ 𝓟 s from iInf_le_of_le t <| iInf_le_of_le ht <| le_principal_iff.mpr hs
theorem lift_le {f : Filter α} {g : Set α → Filter β} {h : Filter β} {s : Set α} (hs : s ∈ f)
(hg : g s ≤ h) : f.lift g ≤ h :=
iInf₂_le_of_le s hs hg
theorem le_lift {f : Filter α} {g : Set α → Filter β} {h : Filter β} :
h ≤ f.lift g ↔ ∀ s ∈ f, h ≤ g s :=
le_iInf₂_iff
theorem lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ :=
iInf_mono fun s => iInf_mono' fun hs => ⟨hf hs, hg s⟩
theorem lift_mono' (hg : ∀ s ∈ f, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := iInf₂_mono hg
theorem tendsto_lift {m : γ → β} {l : Filter γ} :
Tendsto m l (f.lift g) ↔ ∀ s ∈ f, Tendsto m l (g s) := by
simp only [Filter.lift, tendsto_iInf]
theorem map_lift_eq {m : β → γ} (hg : Monotone g) : map m (f.lift g) = f.lift (map m ∘ g) :=
have : Monotone (map m ∘ g) := map_mono.comp hg
Filter.ext fun s => by
simp only [mem_lift_sets hg, mem_lift_sets this, exists_prop, mem_map, Function.comp_apply]
theorem comap_lift_eq {m : γ → β} : comap m (f.lift g) = f.lift (comap m ∘ g) := by
simp only [Filter.lift, comap_iInf]; rfl
theorem comap_lift_eq2 {m : β → α} {g : Set β → Filter γ} (hg : Monotone g) :
(comap m f).lift g = f.lift (g ∘ preimage m) :=
le_antisymm (le_iInf₂ fun s hs => iInf₂_le (m ⁻¹' s) ⟨s, hs, Subset.rfl⟩)
(le_iInf₂ fun _s ⟨s', hs', h_sub⟩ => iInf₂_le_of_le s' hs' <| hg h_sub)
theorem lift_map_le {g : Set β → Filter γ} {m : α → β} : (map m f).lift g ≤ f.lift (g ∘ image m) :=
le_lift.2 fun _s hs => lift_le (image_mem_map hs) le_rfl
theorem map_lift_eq2 {g : Set β → Filter γ} {m : α → β} (hg : Monotone g) :
(map m f).lift g = f.lift (g ∘ image m) :=
lift_map_le.antisymm <| le_lift.2 fun _s hs => lift_le hs <| hg <| image_preimage_subset _ _
theorem lift_comm {g : Filter β} {h : Set α → Set β → Filter γ} :
(f.lift fun s => g.lift (h s)) = g.lift fun t => f.lift fun s => h s t :=
le_antisymm
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi)
(le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj =>
iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi)
theorem lift_assoc {h : Set β → Filter γ} (hg : Monotone g) :
(f.lift g).lift h = f.lift fun s => (g s).lift h :=
le_antisymm
(le_iInf₂ fun _s hs => le_iInf₂ fun t ht =>
iInf_le_of_le t <| iInf_le _ <| (mem_lift_sets hg).mpr ⟨_, hs, ht⟩)
(le_iInf₂ fun t ht =>
let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht
iInf_le_of_le s <| iInf_le_of_le hs <| iInf_le_of_le t <| iInf_le _ h')
theorem lift_lift_same_le_lift {g : Set α → Set α → Filter β} :
(f.lift fun s => f.lift (g s)) ≤ f.lift fun s => g s s :=
le_lift.2 fun _s hs => lift_le hs <| lift_le hs le_rfl
theorem lift_lift_same_eq_lift {g : Set α → Set α → Filter β} (hg₁ : ∀ s, Monotone fun t => g s t)
(hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift (g s)) = f.lift fun s => g s s :=
lift_lift_same_le_lift.antisymm <|
le_lift.2 fun s hs => le_lift.2 fun t ht => lift_le (inter_mem hs ht) <|
calc
g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) := hg₂ (s ∩ t) inter_subset_left
_ ≤ g s t := hg₁ s inter_subset_right
theorem lift_principal {s : Set α} (hg : Monotone g) : (𝓟 s).lift g = g s :=
(lift_le (mem_principal_self _) le_rfl).antisymm (le_lift.2 fun _t ht => hg ht)
theorem monotone_lift [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Filter β} (hf : Monotone f)
(hg : Monotone g) : Monotone fun c => (f c).lift (g c) := fun _ _ h => lift_mono (hf h) (hg h)
theorem lift_neBot_iff (hm : Monotone g) : (NeBot (f.lift g)) ↔ ∀ s ∈ f, NeBot (g s) := by
simp only [neBot_iff, Ne, ← empty_mem_iff_bot, mem_lift_sets hm, not_exists, not_and]
@[simp]
theorem lift_const {f : Filter α} {g : Filter β} : (f.lift fun _ => g) = g :=
iInf_subtype'.trans iInf_const
@[simp]
theorem lift_inf {f : Filter α} {g h : Set α → Filter β} :
(f.lift fun x => g x ⊓ h x) = f.lift g ⊓ f.lift h := by simp only [Filter.lift, iInf_inf_eq]
@[simp]
theorem lift_principal2 {f : Filter α} : f.lift 𝓟 = f :=
le_antisymm (fun s hs => mem_lift hs (mem_principal_self s))
(le_iInf fun s => le_iInf fun hs => by simp only [hs, le_principal_iff])
theorem lift_iInf_le {f : ι → Filter α} {g : Set α → Filter β} :
(iInf f).lift g ≤ ⨅ i, (f i).lift g :=
le_iInf fun _ => lift_mono (iInf_le _ _) le_rfl
theorem lift_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β}
(hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) : (iInf f).lift g = ⨅ i, (f i).lift g := by
refine lift_iInf_le.antisymm fun s => ?_
have H : ∀ t ∈ iInf f, ⨅ i, (f i).lift g ≤ g t := by
intro t ht
refine iInf_sets_induct ht ?_ fun hs ht => ?_
· inhabit ι
exact iInf₂_le_of_le default univ (iInf_le _ univ_mem)
· rw [hg]
exact le_inf (iInf₂_le_of_le _ _ <| iInf_le _ hs) ht
simp only [mem_lift_sets (Monotone.of_map_inf hg), exists_imp, and_imp]
exact fun t ht hs => H t ht hs
theorem lift_iInf_of_directed [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β}
(hf : Directed (· ≥ ·) f) (hg : Monotone g) : (iInf f).lift g = ⨅ i, (f i).lift g :=
lift_iInf_le.antisymm fun s => by
simp only [mem_lift_sets hg, exists_imp, and_imp, mem_iInf_of_directed hf]
exact fun t i ht hs => mem_iInf_of_mem i <| mem_lift ht hs
theorem lift_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Filter β}
(hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) (hg' : g univ = ⊤) :
(iInf f).lift g = ⨅ i, (f i).lift g := by
cases isEmpty_or_nonempty ι
· simp [iInf_of_empty, hg']
· exact lift_iInf hg
end lift
section Lift'
/-- Specialize `lift` to functions `Set α → Set β`. This can be viewed as a generalization of `map`.
This is essentially a push-forward along a function mapping each set to a set. -/
protected def lift' (f : Filter α) (h : Set α → Set β) :=
f.lift (𝓟 ∘ h)
variable {f f₁ f₂ : Filter α} {h h₁ h₂ : Set α → Set β}
@[simp]
theorem lift'_top (h : Set α → Set β) : (⊤ : Filter α).lift' h = 𝓟 (h univ) :=
lift_top _
theorem mem_lift' {t : Set α} (ht : t ∈ f) : h t ∈ f.lift' h :=
le_principal_iff.mp <| show f.lift' h ≤ 𝓟 (h t) from iInf_le_of_le t <| iInf_le_of_le ht <| le_rfl
theorem tendsto_lift' {m : γ → β} {l : Filter γ} :
Tendsto m l (f.lift' h) ↔ ∀ s ∈ f, ∀ᶠ a in l, m a ∈ h s := by
simp only [Filter.lift', tendsto_lift, tendsto_principal, comp]
theorem HasBasis.lift' {ι} {p : ι → Prop} {s} (hf : f.HasBasis p s) (hh : Monotone h) :
(f.lift' h).HasBasis p (h ∘ s) :=
⟨fun t => (hf.mem_lift_iff (fun i => hasBasis_principal (h (s i)))
(monotone_principal.comp hh)).trans <| by simp only [exists_const, true_and, comp]⟩
theorem mem_lift'_sets (hh : Monotone h) {s : Set β} : s ∈ f.lift' h ↔ ∃ t ∈ f, h t ⊆ s :=
mem_lift_sets <| monotone_principal.comp hh
theorem eventually_lift'_iff (hh : Monotone h) {p : β → Prop} :
(∀ᶠ y in f.lift' h, p y) ↔ ∃ t ∈ f, ∀ y ∈ h t, p y :=
mem_lift'_sets hh
theorem sInter_lift'_sets (hh : Monotone h) : ⋂₀ { s | s ∈ f.lift' h } = ⋂ s ∈ f, h s :=
(sInter_lift_sets (monotone_principal.comp hh)).trans <| iInter₂_congr fun _ _ => csInf_Ici
theorem lift'_le {f : Filter α} {g : Set α → Set β} {h : Filter β} {s : Set α} (hs : s ∈ f)
(hg : 𝓟 (g s) ≤ h) : f.lift' g ≤ h :=
lift_le hs hg
theorem lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ :=
lift_mono hf fun s => principal_mono.mpr <| hh s
theorem lift'_mono' (hh : ∀ s ∈ f, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ :=
iInf₂_mono fun s hs => principal_mono.mpr <| hh s hs
theorem lift'_cong (hh : ∀ s ∈ f, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ :=
le_antisymm (lift'_mono' fun s hs => le_of_eq <| hh s hs)
(lift'_mono' fun s hs => le_of_eq <| (hh s hs).symm)
theorem map_lift'_eq {m : β → γ} (hh : Monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) :=
calc
map m (f.lift' h) = f.lift (map m ∘ 𝓟 ∘ h) := map_lift_eq <| monotone_principal.comp hh
_ = f.lift' (image m ∘ h) := by simp only [comp, Filter.lift', map_principal]
theorem lift'_map_le {g : Set β → Set γ} {m : α → β} : (map m f).lift' g ≤ f.lift' (g ∘ image m) :=
lift_map_le
theorem map_lift'_eq2 {g : Set β → Set γ} {m : α → β} (hg : Monotone g) :
(map m f).lift' g = f.lift' (g ∘ image m) :=
map_lift_eq2 <| monotone_principal.comp hg
theorem comap_lift'_eq {m : γ → β} : comap m (f.lift' h) = f.lift' (preimage m ∘ h) := by
simp only [Filter.lift', comap_lift_eq, (· ∘ ·), comap_principal]
theorem comap_lift'_eq2 {m : β → α} {g : Set β → Set γ} (hg : Monotone g) :
(comap m f).lift' g = f.lift' (g ∘ preimage m) :=
comap_lift_eq2 <| monotone_principal.comp hg
theorem lift'_principal {s : Set α} (hh : Monotone h) : (𝓟 s).lift' h = 𝓟 (h s) :=
lift_principal <| monotone_principal.comp hh
theorem lift'_pure {a : α} (hh : Monotone h) : (pure a : Filter α).lift' h = 𝓟 (h {a}) := by
rw [← principal_singleton, lift'_principal hh]
theorem lift'_bot (hh : Monotone h) : (⊥ : Filter α).lift' h = 𝓟 (h ∅) := by
rw [← principal_empty, lift'_principal hh]
theorem le_lift' {f : Filter α} {h : Set α → Set β} {g : Filter β} :
g ≤ f.lift' h ↔ ∀ s ∈ f, h s ∈ g :=
le_lift.trans <| forall₂_congr fun _ _ => le_principal_iff
theorem principal_le_lift' {t : Set β} : 𝓟 t ≤ f.lift' h ↔ ∀ s ∈ f, t ⊆ h s :=
le_lift'
theorem monotone_lift' [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Set β} (hf : Monotone f)
(hg : Monotone g) : Monotone fun c => (f c).lift' (g c) := fun _ _ h => lift'_mono (hf h) (hg h)
theorem lift_lift'_assoc {g : Set α → Set β} {h : Set β → Filter γ} (hg : Monotone g)
(hh : Monotone h) : (f.lift' g).lift h = f.lift fun s => h (g s) :=
calc
(f.lift' g).lift h = f.lift fun s => (𝓟 (g s)).lift h := lift_assoc (monotone_principal.comp hg)
_ = f.lift fun s => h (g s) := by simp only [lift_principal, hh, eq_self_iff_true]
theorem lift'_lift'_assoc {g : Set α → Set β} {h : Set β → Set γ} (hg : Monotone g)
(hh : Monotone h) : (f.lift' g).lift' h = f.lift' fun s => h (g s) :=
lift_lift'_assoc hg (monotone_principal.comp hh)
theorem lift'_lift_assoc {g : Set α → Filter β} {h : Set β → Set γ} (hg : Monotone g) :
(f.lift g).lift' h = f.lift fun s => (g s).lift' h :=
lift_assoc hg
theorem lift_lift'_same_le_lift' {g : Set α → Set α → Set β} :
(f.lift fun s => f.lift' (g s)) ≤ f.lift' fun s => g s s :=
lift_lift_same_le_lift
theorem lift_lift'_same_eq_lift' {g : Set α → Set α → Set β} (hg₁ : ∀ s, Monotone fun t => g s t)
(hg₂ : ∀ t, Monotone fun s => g s t) :
(f.lift fun s => f.lift' (g s)) = f.lift' fun s => g s s :=
lift_lift_same_eq_lift (fun s => monotone_principal.comp (hg₁ s)) fun t =>
monotone_principal.comp (hg₂ t)
theorem lift'_inf_principal_eq {h : Set α → Set β} {s : Set β} :
f.lift' h ⊓ 𝓟 s = f.lift' fun t => h t ∩ s := by
simp only [Filter.lift', Filter.lift, (· ∘ ·), ← inf_principal, iInf_subtype', ← iInf_inf]
theorem lift'_neBot_iff (hh : Monotone h) : NeBot (f.lift' h) ↔ ∀ s ∈ f, (h s).Nonempty :=
calc
NeBot (f.lift' h) ↔ ∀ s ∈ f, NeBot (𝓟 (h s)) := lift_neBot_iff (monotone_principal.comp hh)
_ ↔ ∀ s ∈ f, (h s).Nonempty := by simp only [principal_neBot_iff]
@[simp]
theorem lift'_id {f : Filter α} : f.lift' id = f :=
lift_principal2
theorem lift'_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Set β}
(hg : ∀ s t, g (s ∩ t) = g s ∩ g t) : (iInf f).lift' g = ⨅ i, (f i).lift' g :=
lift_iInf fun s t => by simp only [inf_principal, comp, hg]
theorem lift'_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Set β}
(hg : ∀ {s t}, g (s ∩ t) = g s ∩ g t) (hg' : g univ = univ) :
(iInf f).lift' g = ⨅ i, (f i).lift' g :=
lift_iInf_of_map_univ (fun s t => by simp only [inf_principal, comp, hg])
(by rw [Function.comp_apply, hg', principal_univ])
theorem lift'_inf (f g : Filter α) {s : Set α → Set β} (hs : ∀ t₁ t₂, s (t₁ ∩ t₂) = s t₁ ∩ s t₂) :
(f ⊓ g).lift' s = f.lift' s ⊓ g.lift' s := by
rw [inf_eq_iInf, inf_eq_iInf, lift'_iInf hs]
refine iInf_congr ?_
rintro (_|_) <;> rfl
theorem lift'_inf_le (f g : Filter α) (s : Set α → Set β) :
(f ⊓ g).lift' s ≤ f.lift' s ⊓ g.lift' s :=
le_inf (lift'_mono inf_le_left le_rfl) (lift'_mono inf_le_right le_rfl)
theorem comap_eq_lift' {f : Filter β} {m : α → β} : comap m f = f.lift' (preimage m) :=
Filter.ext fun _ => (mem_lift'_sets monotone_preimage).symm
end Lift'
section Prod
variable {f : Filter α}
theorem prod_def {f : Filter α} {g : Filter β} :
f ×ˢ g = f.lift fun s => g.lift' fun t => s ×ˢ t := by
simpa only [Filter.lift', Filter.lift, (f.basis_sets.prod g.basis_sets).eq_biInf,
iInf_prod, iInf_and] using iInf_congr fun i => iInf_comm
alias mem_prod_same_iff := mem_prod_self_iff
theorem prod_same_eq : f ×ˢ f = f.lift' fun t : Set α => t ×ˢ t :=
f.basis_sets.prod_self.eq_biInf
theorem tendsto_prod_self_iff {f : α × α → β} {x : Filter α} {y : Filter β} :
Filter.Tendsto f (x ×ˢ x) y ↔ ∀ W ∈ y, ∃ U ∈ x, ∀ x x' : α, x ∈ U → x' ∈ U → f (x, x') ∈ W := by
simp only [tendsto_def, mem_prod_same_iff, prod_sub_preimage_iff, exists_prop, iff_self_iff]
variable {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*}
theorem prod_lift_lift {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Filter β₁}
{g₂ : Set α₂ → Filter β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) :
f₁.lift g₁ ×ˢ f₂.lift g₂ = f₁.lift fun s => f₂.lift fun t => g₁ s ×ˢ g₂ t := by
simp only [prod_def, lift_assoc hg₁]
apply congr_arg; funext x
rw [lift_comm]
apply congr_arg; funext y
apply lift'_lift_assoc hg₂
theorem prod_lift'_lift' {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Set β₁}
{g₂ : Set α₂ → Set β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) :
f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift' fun t => g₁ s ×ˢ g₂ t :=
calc
f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s) ×ˢ 𝓟 (g₂ t) :=
prod_lift_lift (monotone_principal.comp hg₁) (monotone_principal.comp hg₂)
_ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s ×ˢ g₂ t) := by
{ simp only [prod_principal_principal] }
end Prod
end Filter
|
Order\Filter\ListTraverse.lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Control.Traversable.Instances
import Mathlib.Order.Filter.Basic
/-!
# Properties of `Traversable.traverse` on `List`s and `Filter`s
In this file we prove basic properties (monotonicity, membership)
for `Traversable.traverse f l`, where `f : β → Filter α` and `l : List β`.
-/
open Set List
namespace Filter
universe u
variable {α β γ : Type u} {f : β → Filter α} {s : γ → Set α}
theorem sequence_mono : ∀ as bs : List (Filter α), Forall₂ (· ≤ ·) as bs → sequence as ≤ sequence bs
| [], [], Forall₂.nil => le_rfl
| _::as, _::bs, Forall₂.cons h hs => seq_mono (map_mono h) (sequence_mono as bs hs)
theorem mem_traverse :
∀ (fs : List β) (us : List γ),
Forall₂ (fun b c => s c ∈ f b) fs us → traverse s us ∈ traverse f fs
| [], [], Forall₂.nil => mem_pure.2 <| mem_singleton _
| _::fs, _::us, Forall₂.cons h hs => seq_mem_seq (image_mem_map h) (mem_traverse fs us hs)
-- TODO: add a `Filter.HasBasis` statement
theorem mem_traverse_iff (fs : List β) (t : Set (List α)) :
t ∈ traverse f fs ↔
∃ us : List (Set α), Forall₂ (fun b (s : Set α) => s ∈ f b) fs us ∧ sequence us ⊆ t := by
constructor
· induction fs generalizing t with
| nil =>
simp only [sequence, mem_pure, imp_self, forall₂_nil_left_iff, exists_eq_left, Set.pure_def,
singleton_subset_iff, traverse_nil]
| cons b fs ih =>
intro ht
rcases mem_seq_iff.1 ht with ⟨u, hu, v, hv, ht⟩
rcases mem_map_iff_exists_image.1 hu with ⟨w, hw, hwu⟩
rcases ih v hv with ⟨us, hus, hu⟩
exact ⟨w::us, Forall₂.cons hw hus, (Set.seq_mono hwu hu).trans ht⟩
· rintro ⟨us, hus, hs⟩
exact mem_of_superset (mem_traverse _ _ hus) hs
end Filter
|
Order\Filter\ModEq.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Nat.ModEq
import Mathlib.Order.Filter.AtTopBot
/-!
# Numbers are frequently ModEq to fixed numbers
In this file we prove that `m ≡ d [MOD n]` frequently as `m → ∞`.
-/
open Filter
namespace Nat
/-- Infinitely many natural numbers are equal to `d` mod `n`. -/
theorem frequently_modEq {n : ℕ} (h : n ≠ 0) (d : ℕ) : ∃ᶠ m in atTop, m ≡ d [MOD n] :=
((tendsto_add_atTop_nat d).comp (tendsto_id.nsmul_atTop h.bot_lt)).frequently <|
frequently_of_forall fun m => by simp [Nat.modEq_iff_dvd, ← sub_sub]
theorem frequently_mod_eq {d n : ℕ} (h : d < n) : ∃ᶠ m in atTop, m % n = d := by
simpa only [Nat.ModEq, mod_eq_of_lt h] using frequently_modEq h.ne_bot d
theorem frequently_even : ∃ᶠ m : ℕ in atTop, Even m := by
simpa only [even_iff] using frequently_mod_eq zero_lt_two
theorem frequently_odd : ∃ᶠ m : ℕ in atTop, Odd m := by
simpa only [odd_iff] using frequently_mod_eq one_lt_two
end Nat
theorem Filter.nonneg_of_eventually_pow_nonneg {α : Type*} [LinearOrderedRing α] {a : α}
(h : ∀ᶠ n in atTop, 0 ≤ a ^ (n : ℕ)) : 0 ≤ a :=
let ⟨_n, ho, hn⟩ := (Nat.frequently_odd.and_eventually h).exists
ho.pow_nonneg_iff.1 hn
|
Order\Filter\NAry.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Filter.Prod
/-!
# N-ary maps of filter
This file defines the binary and ternary maps of filters. This is mostly useful to define pointwise
operations on filters.
## Main declarations
* `Filter.map₂`: Binary map of filters.
## Notes
This file is very similar to `Data.Set.NAry`, `Data.Finset.NAry` and `Data.Option.NAry`. Please
keep them in sync.
-/
open Function Set
open Filter
namespace Filter
variable {α α' β β' γ γ' δ δ' ε ε' : Type*} {m : α → β → γ} {f f₁ f₂ : Filter α}
{g g₁ g₂ : Filter β} {h h₁ h₂ : Filter γ} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {u : Set γ}
{v : Set δ} {a : α} {b : β} {c : γ}
/-- The image of a binary function `m : α → β → γ` as a function `Filter α → Filter β → Filter γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) : Filter γ :=
((f ×ˢ g).map (uncurry m)).copy { s | ∃ u ∈ f, ∃ v ∈ g, image2 m u v ⊆ s } fun _ ↦ by
simp only [mem_map, mem_prod_iff, image2_subset_iff, prod_subset_iff]; rfl
@[simp 900]
theorem mem_map₂_iff : u ∈ map₂ m f g ↔ ∃ s ∈ f, ∃ t ∈ g, image2 m s t ⊆ u :=
Iff.rfl
theorem image2_mem_map₂ (hs : s ∈ f) (ht : t ∈ g) : image2 m s t ∈ map₂ m f g :=
⟨_, hs, _, ht, Subset.rfl⟩
theorem map_prod_eq_map₂ (m : α → β → γ) (f : Filter α) (g : Filter β) :
Filter.map (fun p : α × β => m p.1 p.2) (f ×ˢ g) = map₂ m f g := by
rw [map₂, copy_eq, uncurry_def]
theorem map_prod_eq_map₂' (m : α × β → γ) (f : Filter α) (g : Filter β) :
Filter.map m (f ×ˢ g) = map₂ (fun a b => m (a, b)) f g :=
map_prod_eq_map₂ (curry m) f g
@[simp]
theorem map₂_mk_eq_prod (f : Filter α) (g : Filter β) : map₂ Prod.mk f g = f ×ˢ g := by
simp only [← map_prod_eq_map₂, map_id']
-- lemma image2_mem_map₂_iff (hm : injective2 m) : image2 m s t ∈ map₂ m f g ↔ s ∈ f ∧ t ∈ g :=
-- ⟨by { rintro ⟨u, v, hu, hv, h⟩, rw image2_subset_image2_iff hm at h,
-- exact ⟨mem_of_superset hu h.1, mem_of_superset hv h.2⟩ }, λ h, image2_mem_map₂ h.1 h.2⟩
theorem map₂_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : map₂ m f₁ g₁ ≤ map₂ m f₂ g₂ :=
fun _ ⟨s, hs, t, ht, hst⟩ => ⟨s, hf hs, t, hg ht, hst⟩
theorem map₂_mono_left (h : g₁ ≤ g₂) : map₂ m f g₁ ≤ map₂ m f g₂ :=
map₂_mono Subset.rfl h
theorem map₂_mono_right (h : f₁ ≤ f₂) : map₂ m f₁ g ≤ map₂ m f₂ g :=
map₂_mono h Subset.rfl
@[simp]
theorem le_map₂_iff {h : Filter γ} :
h ≤ map₂ m f g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → image2 m s t ∈ h :=
⟨fun H _ hs _ ht => H <| image2_mem_map₂ hs ht, fun H _ ⟨_, hs, _, ht, hu⟩ =>
mem_of_superset (H hs ht) hu⟩
@[simp]
theorem map₂_eq_bot_iff : map₂ m f g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp [← map_prod_eq_map₂]
@[simp]
theorem map₂_bot_left : map₂ m ⊥ g = ⊥ := map₂_eq_bot_iff.2 <| .inl rfl
@[simp]
theorem map₂_bot_right : map₂ m f ⊥ = ⊥ := map₂_eq_bot_iff.2 <| .inr rfl
@[simp]
theorem map₂_neBot_iff : (map₂ m f g).NeBot ↔ f.NeBot ∧ g.NeBot := by simp [neBot_iff, not_or]
protected theorem NeBot.map₂ (hf : f.NeBot) (hg : g.NeBot) : (map₂ m f g).NeBot :=
map₂_neBot_iff.2 ⟨hf, hg⟩
instance map₂.neBot [NeBot f] [NeBot g] : NeBot (map₂ m f g) := .map₂ ‹_› ‹_›
theorem NeBot.of_map₂_left (h : (map₂ m f g).NeBot) : f.NeBot :=
(map₂_neBot_iff.1 h).1
theorem NeBot.of_map₂_right (h : (map₂ m f g).NeBot) : g.NeBot :=
(map₂_neBot_iff.1 h).2
theorem map₂_sup_left : map₂ m (f₁ ⊔ f₂) g = map₂ m f₁ g ⊔ map₂ m f₂ g := by
simp_rw [← map_prod_eq_map₂, sup_prod, map_sup]
theorem map₂_sup_right : map₂ m f (g₁ ⊔ g₂) = map₂ m f g₁ ⊔ map₂ m f g₂ := by
simp_rw [← map_prod_eq_map₂, prod_sup, map_sup]
theorem map₂_inf_subset_left : map₂ m (f₁ ⊓ f₂) g ≤ map₂ m f₁ g ⊓ map₂ m f₂ g :=
Monotone.map_inf_le (fun _ _ ↦ map₂_mono_right) f₁ f₂
theorem map₂_inf_subset_right : map₂ m f (g₁ ⊓ g₂) ≤ map₂ m f g₁ ⊓ map₂ m f g₂ :=
Monotone.map_inf_le (fun _ _ ↦ map₂_mono_left) g₁ g₂
@[simp]
theorem map₂_pure_left : map₂ m (pure a) g = g.map (m a) := by
rw [← map_prod_eq_map₂, pure_prod, map_map]; rfl
@[simp]
theorem map₂_pure_right : map₂ m f (pure b) = f.map (m · b) := by
rw [← map_prod_eq_map₂, prod_pure, map_map]; rfl
theorem map₂_pure : map₂ m (pure a) (pure b) = pure (m a b) := by rw [map₂_pure_right, map_pure]
theorem map₂_swap (m : α → β → γ) (f : Filter α) (g : Filter β) :
map₂ m f g = map₂ (fun a b => m b a) g f := by
rw [← map_prod_eq_map₂, prod_comm, map_map, ← map_prod_eq_map₂, Function.comp_def]
@[simp]
theorem map₂_left [NeBot g] : map₂ (fun x _ => x) f g = f := by
rw [← map_prod_eq_map₂, map_fst_prod]
@[simp]
theorem map₂_right [NeBot f] : map₂ (fun _ y => y) f g = g := by rw [map₂_swap, map₂_left]
theorem map_map₂ (m : α → β → γ) (n : γ → δ) :
(map₂ m f g).map n = map₂ (fun a b => n (m a b)) f g := by
rw [← map_prod_eq_map₂, ← map_prod_eq_map₂, map_map]; rfl
theorem map₂_map_left (m : γ → β → δ) (n : α → γ) :
map₂ m (f.map n) g = map₂ (fun a b => m (n a) b) f g := by
rw [← map_prod_eq_map₂, ← map_prod_eq_map₂, ← @map_id _ g, prod_map_map_eq, map_map, map_id]; rfl
theorem map₂_map_right (m : α → γ → δ) (n : β → γ) :
map₂ m f (g.map n) = map₂ (fun a b => m a (n b)) f g := by
rw [map₂_swap, map₂_map_left, map₂_swap]
@[simp]
theorem map₂_curry (m : α × β → γ) (f : Filter α) (g : Filter β) :
map₂ (curry m) f g = (f ×ˢ g).map m :=
(map_prod_eq_map₂' _ _ _).symm
@[simp]
theorem map_uncurry_prod (m : α → β → γ) (f : Filter α) (g : Filter β) :
(f ×ˢ g).map (uncurry m) = map₂ m f g :=
(map₂_curry (uncurry m) f g).symm
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `Filter.map₂` of those operations.
The proof pattern is `map₂_lemma operation_lemma`. For example, `map₂_comm mul_comm` proves that
`map₂ (*) f g = map₂ (*) g f` in a `CommSemigroup`.
-/
theorem map₂_assoc {m : δ → γ → ε} {n : α → β → δ} {m' : α → ε' → ε} {n' : β → γ → ε'}
{h : Filter γ} (h_assoc : ∀ a b c, m (n a b) c = m' a (n' b c)) :
map₂ m (map₂ n f g) h = map₂ m' f (map₂ n' g h) := by
rw [← map_prod_eq_map₂ n, ← map_prod_eq_map₂ n', map₂_map_left, map₂_map_right,
← map_prod_eq_map₂, ← map_prod_eq_map₂, ← prod_assoc, map_map]
simp only [h_assoc, Function.comp, Equiv.prodAssoc_apply]
theorem map₂_comm {n : β → α → γ} (h_comm : ∀ a b, m a b = n b a) : map₂ m f g = map₂ n g f :=
(map₂_swap _ _ _).trans <| by simp_rw [h_comm]
theorem map₂_left_comm {m : α → δ → ε} {n : β → γ → δ} {m' : α → γ → δ'} {n' : β → δ' → ε}
(h_left_comm : ∀ a b c, m a (n b c) = n' b (m' a c)) :
map₂ m f (map₂ n g h) = map₂ n' g (map₂ m' f h) := by
rw [map₂_swap m', map₂_swap m]
exact map₂_assoc fun _ _ _ => h_left_comm _ _ _
theorem map₂_right_comm {m : δ → γ → ε} {n : α → β → δ} {m' : α → γ → δ'} {n' : δ' → β → ε}
(h_right_comm : ∀ a b c, m (n a b) c = n' (m' a c) b) :
map₂ m (map₂ n f g) h = map₂ n' (map₂ m' f h) g := by
rw [map₂_swap n, map₂_swap n']
exact map₂_assoc fun _ _ _ => h_right_comm _ _ _
theorem map_map₂_distrib {n : γ → δ} {m' : α' → β' → δ} {n₁ : α → α'} {n₂ : β → β'}
(h_distrib : ∀ a b, n (m a b) = m' (n₁ a) (n₂ b)) :
(map₂ m f g).map n = map₂ m' (f.map n₁) (g.map n₂) := by
simp_rw [map_map₂, map₂_map_left, map₂_map_right, h_distrib]
/-- Symmetric statement to `Filter.map₂_map_left_comm`. -/
theorem map_map₂_distrib_left {n : γ → δ} {m' : α' → β → δ} {n' : α → α'}
(h_distrib : ∀ a b, n (m a b) = m' (n' a) b) : (map₂ m f g).map n = map₂ m' (f.map n') g :=
map_map₂_distrib h_distrib
/-- Symmetric statement to `Filter.map_map₂_right_comm`. -/
theorem map_map₂_distrib_right {n : γ → δ} {m' : α → β' → δ} {n' : β → β'}
(h_distrib : ∀ a b, n (m a b) = m' a (n' b)) : (map₂ m f g).map n = map₂ m' f (g.map n') :=
map_map₂_distrib h_distrib
/-- Symmetric statement to `Filter.map_map₂_distrib_left`. -/
theorem map₂_map_left_comm {m : α' → β → γ} {n : α → α'} {m' : α → β → δ} {n' : δ → γ}
(h_left_comm : ∀ a b, m (n a) b = n' (m' a b)) : map₂ m (f.map n) g = (map₂ m' f g).map n' :=
(map_map₂_distrib_left fun a b => (h_left_comm a b).symm).symm
/-- Symmetric statement to `Filter.map_map₂_distrib_right`. -/
theorem map_map₂_right_comm {m : α → β' → γ} {n : β → β'} {m' : α → β → δ} {n' : δ → γ}
(h_right_comm : ∀ a b, m a (n b) = n' (m' a b)) : map₂ m f (g.map n) = (map₂ m' f g).map n' :=
(map_map₂_distrib_right fun a b => (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `f-f` cross terms on the RHS. -/
theorem map₂_distrib_le_left {m : α → δ → ε} {n : β → γ → δ} {m₁ : α → β → β'} {m₂ : α → γ → γ'}
{n' : β' → γ' → ε} (h_distrib : ∀ a b c, m a (n b c) = n' (m₁ a b) (m₂ a c)) :
map₂ m f (map₂ n g h) ≤ map₂ n' (map₂ m₁ f g) (map₂ m₂ f h) := by
rintro s ⟨t₁, ⟨u₁, hu₁, v, hv, ht₁⟩, t₂, ⟨u₂, hu₂, w, hw, ht₂⟩, hs⟩
refine ⟨u₁ ∩ u₂, inter_mem hu₁ hu₂, _, image2_mem_map₂ hv hw, ?_⟩
refine (image2_distrib_subset_left h_distrib).trans ((image2_subset ?_ ?_).trans hs)
· exact (image2_subset_right inter_subset_left).trans ht₁
· exact (image2_subset_right inter_subset_right).trans ht₂
/-- The other direction does not hold because of the `h`-`h` cross terms on the RHS. -/
theorem map₂_distrib_le_right {m : δ → γ → ε} {n : α → β → δ} {m₁ : α → γ → α'} {m₂ : β → γ → β'}
{n' : α' → β' → ε} (h_distrib : ∀ a b c, m (n a b) c = n' (m₁ a c) (m₂ b c)) :
map₂ m (map₂ n f g) h ≤ map₂ n' (map₂ m₁ f h) (map₂ m₂ g h) := by
rintro s ⟨t₁, ⟨u, hu, w₁, hw₁, ht₁⟩, t₂, ⟨v, hv, w₂, hw₂, ht₂⟩, hs⟩
refine ⟨_, image2_mem_map₂ hu hv, w₁ ∩ w₂, inter_mem hw₁ hw₂, ?_⟩
refine (image2_distrib_subset_right h_distrib).trans ((image2_subset ?_ ?_).trans hs)
· exact (image2_subset_left inter_subset_left).trans ht₁
· exact (image2_subset_left inter_subset_right).trans ht₂
theorem map_map₂_antidistrib {n : γ → δ} {m' : β' → α' → δ} {n₁ : β → β'} {n₂ : α → α'}
(h_antidistrib : ∀ a b, n (m a b) = m' (n₁ b) (n₂ a)) :
(map₂ m f g).map n = map₂ m' (g.map n₁) (f.map n₂) := by
rw [map₂_swap m]
exact map_map₂_distrib fun _ _ => h_antidistrib _ _
/-- Symmetric statement to `Filter.map₂_map_left_anticomm`. -/
theorem map_map₂_antidistrib_left {n : γ → δ} {m' : β' → α → δ} {n' : β → β'}
(h_antidistrib : ∀ a b, n (m a b) = m' (n' b) a) : (map₂ m f g).map n = map₂ m' (g.map n') f :=
map_map₂_antidistrib h_antidistrib
/-- Symmetric statement to `Filter.map_map₂_right_anticomm`. -/
theorem map_map₂_antidistrib_right {n : γ → δ} {m' : β → α' → δ} {n' : α → α'}
(h_antidistrib : ∀ a b, n (m a b) = m' b (n' a)) : (map₂ m f g).map n = map₂ m' g (f.map n') :=
map_map₂_antidistrib h_antidistrib
/-- Symmetric statement to `Filter.map_map₂_antidistrib_left`. -/
theorem map₂_map_left_anticomm {m : α' → β → γ} {n : α → α'} {m' : β → α → δ} {n' : δ → γ}
(h_left_anticomm : ∀ a b, m (n a) b = n' (m' b a)) :
map₂ m (f.map n) g = (map₂ m' g f).map n' :=
(map_map₂_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `Filter.map_map₂_antidistrib_right`. -/
theorem map_map₂_right_anticomm {m : α → β' → γ} {n : β → β'} {m' : β → α → δ} {n' : δ → γ}
(h_right_anticomm : ∀ a b, m a (n b) = n' (m' b a)) :
map₂ m f (g.map n) = (map₂ m' g f).map n' :=
(map_map₂_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm
/-- If `a` is a left identity for `f : α → β → β`, then `pure a` is a left identity for
`Filter.map₂ f`. -/
theorem map₂_left_identity {f : α → β → β} {a : α} (h : ∀ b, f a b = b) (l : Filter β) :
map₂ f (pure a) l = l := by rw [map₂_pure_left, show f a = id from funext h, map_id]
/-- If `b` is a right identity for `f : α → β → α`, then `pure b` is a right identity for
`Filter.map₂ f`. -/
theorem map₂_right_identity {f : α → β → α} {b : β} (h : ∀ a, f a b = a) (l : Filter α) :
map₂ f l (pure b) = l := by rw [map₂_pure_right, funext h, map_id']
end Filter
|
Order\Filter\Partial.lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Data.PFun
/-!
# `Tendsto` for relations and partial functions
This file generalizes `Filter` definitions from functions to partial functions and relations.
## Considering functions and partial functions as relations
A function `f : α → β` can be considered as the relation `Rel α β` which relates `x` and `f x` for
all `x`, and nothing else. This relation is called `Function.Graph f`.
A partial function `f : α →. β` can be considered as the relation `Rel α β` which relates `x` and
`f x` for all `x` for which `f x` exists, and nothing else. This relation is called
`PFun.Graph' f`.
In this regard, a function is a relation for which every element in `α` is related to exactly one
element in `β` and a partial function is a relation for which every element in `α` is related to at
most one element in `β`.
This file leverages this analogy to generalize `Filter` definitions from functions to partial
functions and relations.
## Notes
`Set.preimage` can be generalized to relations in two ways:
* `Rel.preimage` returns the image of the set under the inverse relation.
* `Rel.core` returns the set of elements that are only related to those in the set.
Both generalizations are sensible in the context of filters, so `Filter.comap` and `Filter.Tendsto`
get two generalizations each.
We first take care of relations. Then the definitions for partial functions are taken as special
cases of the definitions for relations.
-/
universe u v w
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w}
open Filter
/-! ### Relations -/
/-- The forward map of a filter under a relation. Generalization of `Filter.map` to relations. Note
that `Rel.core` generalizes `Set.preimage`. -/
def rmap (r : Rel α β) (l : Filter α) : Filter β where
sets := { s | r.core s ∈ l }
univ_sets := by simp
sets_of_superset hs st := mem_of_superset hs (Rel.core_mono _ st)
inter_sets hs ht := by
simp only [Set.mem_setOf_eq]
convert inter_mem hs ht
rw [← Rel.core_inter]
theorem rmap_sets (r : Rel α β) (l : Filter α) : (l.rmap r).sets = r.core ⁻¹' l.sets :=
rfl
@[simp]
theorem mem_rmap (r : Rel α β) (l : Filter α) (s : Set β) : s ∈ l.rmap r ↔ r.core s ∈ l :=
Iff.rfl
@[simp]
theorem rmap_rmap (r : Rel α β) (s : Rel β γ) (l : Filter α) :
rmap s (rmap r l) = rmap (r.comp s) l :=
filter_eq <| by simp [rmap_sets, Set.preimage, Rel.core_comp]
@[simp]
theorem rmap_compose (r : Rel α β) (s : Rel β γ) : rmap s ∘ rmap r = rmap (r.comp s) :=
funext <| rmap_rmap _ _
/-- Generic "limit of a relation" predicate. `RTendsto r l₁ l₂` asserts that for every
`l₂`-neighborhood `a`, the `r`-core of `a` is an `l₁`-neighborhood. One generalization of
`Filter.Tendsto` to relations. -/
def RTendsto (r : Rel α β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁.rmap r ≤ l₂
theorem rtendsto_def (r : Rel α β) (l₁ : Filter α) (l₂ : Filter β) :
RTendsto r l₁ l₂ ↔ ∀ s ∈ l₂, r.core s ∈ l₁ :=
Iff.rfl
/-- One way of taking the inverse map of a filter under a relation. One generalization of
`Filter.comap` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/
def rcomap (r : Rel α β) (f : Filter β) : Filter α where
sets := Rel.image (fun s t => r.core s ⊆ t) f.sets
univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩
sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩
inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ =>
⟨a' ∩ b', inter_mem ha₁ hb₁, (r.core_inter a' b').subset.trans (Set.inter_subset_inter ha₂ hb₂)⟩
theorem rcomap_sets (r : Rel α β) (f : Filter β) :
(rcomap r f).sets = Rel.image (fun s t => r.core s ⊆ t) f.sets :=
rfl
theorem rcomap_rcomap (r : Rel α β) (s : Rel β γ) (l : Filter γ) :
rcomap r (rcomap s l) = rcomap (r.comp s) l :=
filter_eq <| by
ext t; simp only [rcomap_sets, Rel.image, Filter.mem_sets, Set.mem_setOf_eq, Rel.core_comp]
constructor
· rintro ⟨u, ⟨v, vsets, hv⟩, h⟩
exact ⟨v, vsets, Set.Subset.trans (Rel.core_mono _ hv) h⟩
rintro ⟨t, tsets, ht⟩
exact ⟨Rel.core s t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩
@[simp]
theorem rcomap_compose (r : Rel α β) (s : Rel β γ) : rcomap r ∘ rcomap s = rcomap (r.comp s) :=
funext <| rcomap_rcomap _ _
theorem rtendsto_iff_le_rcomap (r : Rel α β) (l₁ : Filter α) (l₂ : Filter β) :
RTendsto r l₁ l₂ ↔ l₁ ≤ l₂.rcomap r := by
rw [rtendsto_def]
simp_rw [← l₂.mem_sets]
constructor
· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h s t tl₂ => mem_of_superset (h t tl₂)
· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h t tl₂ => h _ t tl₂ Set.Subset.rfl
-- Interestingly, there does not seem to be a way to express this relation using a forward map.
-- Given a filter `f` on `α`, we want a filter `f'` on `β` such that `r.preimage s ∈ f` if
-- and only if `s ∈ f'`. But the intersection of two sets satisfying the lhs may be empty.
/-- One way of taking the inverse map of a filter under a relation. Generalization of `Filter.comap`
to relations. -/
def rcomap' (r : Rel α β) (f : Filter β) : Filter α where
sets := Rel.image (fun s t => r.preimage s ⊆ t) f.sets
univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩
sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩
inter_sets := fun ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩ =>
⟨a' ∩ b', inter_mem ha₁ hb₁,
(@Rel.preimage_inter _ _ r _ _).trans (Set.inter_subset_inter ha₂ hb₂)⟩
@[simp]
theorem mem_rcomap' (r : Rel α β) (l : Filter β) (s : Set α) :
s ∈ l.rcomap' r ↔ ∃ t ∈ l, r.preimage t ⊆ s :=
Iff.rfl
theorem rcomap'_sets (r : Rel α β) (f : Filter β) :
(rcomap' r f).sets = Rel.image (fun s t => r.preimage s ⊆ t) f.sets :=
rfl
@[simp]
theorem rcomap'_rcomap' (r : Rel α β) (s : Rel β γ) (l : Filter γ) :
rcomap' r (rcomap' s l) = rcomap' (r.comp s) l :=
Filter.ext fun t => by
simp only [mem_rcomap', Rel.preimage_comp]
constructor
· rintro ⟨u, ⟨v, vsets, hv⟩, h⟩
exact ⟨v, vsets, (Rel.preimage_mono _ hv).trans h⟩
rintro ⟨t, tsets, ht⟩
exact ⟨s.preimage t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩
@[simp]
theorem rcomap'_compose (r : Rel α β) (s : Rel β γ) : rcomap' r ∘ rcomap' s = rcomap' (r.comp s) :=
funext <| rcomap'_rcomap' _ _
/-- Generic "limit of a relation" predicate. `RTendsto' r l₁ l₂` asserts that for every
`l₂`-neighborhood `a`, the `r`-preimage of `a` is an `l₁`-neighborhood. One generalization of
`Filter.Tendsto` to relations. -/
def RTendsto' (r : Rel α β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁ ≤ l₂.rcomap' r
theorem rtendsto'_def (r : Rel α β) (l₁ : Filter α) (l₂ : Filter β) :
RTendsto' r l₁ l₂ ↔ ∀ s ∈ l₂, r.preimage s ∈ l₁ := by
unfold RTendsto' rcomap'; constructor
· simpa [le_def, Rel.mem_image] using fun h s hs => h _ _ hs Set.Subset.rfl
· simpa [le_def, Rel.mem_image] using fun h s t ht => mem_of_superset (h t ht)
theorem tendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α → β) :
Tendsto f l₁ l₂ ↔ RTendsto (Function.graph f) l₁ l₂ := by
simp [tendsto_def, Function.graph, rtendsto_def, Rel.core, Set.preimage]
theorem tendsto_iff_rtendsto' (l₁ : Filter α) (l₂ : Filter β) (f : α → β) :
Tendsto f l₁ l₂ ↔ RTendsto' (Function.graph f) l₁ l₂ := by
simp [tendsto_def, Function.graph, rtendsto'_def, Rel.preimage_def, Set.preimage]
/-! ### Partial functions -/
/-- The forward map of a filter under a partial function. Generalization of `Filter.map` to partial
functions. -/
def pmap (f : α →. β) (l : Filter α) : Filter β :=
Filter.rmap f.graph' l
@[simp]
theorem mem_pmap (f : α →. β) (l : Filter α) (s : Set β) : s ∈ l.pmap f ↔ f.core s ∈ l :=
Iff.rfl
/-- Generic "limit of a partial function" predicate. `PTendsto r l₁ l₂` asserts that for every
`l₂`-neighborhood `a`, the `p`-core of `a` is an `l₁`-neighborhood. One generalization of
`Filter.Tendsto` to partial function. -/
def PTendsto (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁.pmap f ≤ l₂
theorem ptendsto_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) :
PTendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f.core s ∈ l₁ :=
Iff.rfl
theorem ptendsto_iff_rtendsto (l₁ : Filter α) (l₂ : Filter β) (f : α →. β) :
PTendsto f l₁ l₂ ↔ RTendsto f.graph' l₁ l₂ :=
Iff.rfl
theorem pmap_res (l : Filter α) (s : Set α) (f : α → β) :
pmap (PFun.res f s) l = map f (l ⊓ 𝓟 s) := by
ext t
simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or]
rfl
theorem tendsto_iff_ptendsto (l₁ : Filter α) (l₂ : Filter β) (s : Set α) (f : α → β) :
Tendsto f (l₁ ⊓ 𝓟 s) l₂ ↔ PTendsto (PFun.res f s) l₁ l₂ := by
simp only [Tendsto, PTendsto, pmap_res]
theorem tendsto_iff_ptendsto_univ (l₁ : Filter α) (l₂ : Filter β) (f : α → β) :
Tendsto f l₁ l₂ ↔ PTendsto (PFun.res f Set.univ) l₁ l₂ := by
rw [← tendsto_iff_ptendsto]
simp [principal_univ]
/-- Inverse map of a filter under a partial function. One generalization of `Filter.comap` to
partial functions. -/
def pcomap' (f : α →. β) (l : Filter β) : Filter α :=
Filter.rcomap' f.graph' l
/-- Generic "limit of a partial function" predicate. `PTendsto' r l₁ l₂` asserts that for every
`l₂`-neighborhood `a`, the `p`-preimage of `a` is an `l₁`-neighborhood. One generalization of
`Filter.Tendsto` to partial functions. -/
def PTendsto' (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) :=
l₁ ≤ l₂.rcomap' f.graph'
theorem ptendsto'_def (f : α →. β) (l₁ : Filter α) (l₂ : Filter β) :
PTendsto' f l₁ l₂ ↔ ∀ s ∈ l₂, f.preimage s ∈ l₁ :=
rtendsto'_def _ _ _
theorem ptendsto_of_ptendsto' {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} :
PTendsto' f l₁ l₂ → PTendsto f l₁ l₂ := by
rw [ptendsto_def, ptendsto'_def]
exact fun h s sl₂ => mem_of_superset (h s sl₂) (PFun.preimage_subset_core _ _)
theorem ptendsto'_of_ptendsto {f : α →. β} {l₁ : Filter α} {l₂ : Filter β} (h : f.Dom ∈ l₁) :
PTendsto f l₁ l₂ → PTendsto' f l₁ l₂ := by
rw [ptendsto_def, ptendsto'_def]
intro h' s sl₂
rw [PFun.preimage_eq]
exact inter_mem (h' s sl₂) h
end Filter
|
Order\Filter\Pi.lean | /-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Alex Kontorovich
-/
import Mathlib.Order.Filter.Bases
/-!
# (Co)product of a family of filters
In this file we define two filters on `Π i, α i` and prove some basic properties of these filters.
* `Filter.pi (f : Π i, Filter (α i))` to be the maximal filter on `Π i, α i` such that
`∀ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as
`Π i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed
products.
* `Filter.coprodᵢ (f : Π i, Filter (α i))`: a generalization of `Filter.coprod`; it is the supremum
of `comap (eval i) (f i)`.
-/
open Set Function Filter
namespace Filter
variable {ι : Type*} {α : ι → Type*} {f f₁ f₂ : (i : ι) → Filter (α i)} {s : (i : ι) → Set (α i)}
{p : ∀ i, α i → Prop}
section Pi
/-- The product of an indexed family of filters. -/
def pi (f : ∀ i, Filter (α i)) : Filter (∀ i, α i) :=
⨅ i, comap (eval i) (f i)
instance pi.isCountablyGenerated [Countable ι] [∀ i, IsCountablyGenerated (f i)] :
IsCountablyGenerated (pi f) :=
iInf.isCountablyGenerated _
theorem tendsto_eval_pi (f : ∀ i, Filter (α i)) (i : ι) : Tendsto (eval i) (pi f) (f i) :=
tendsto_iInf' i tendsto_comap
theorem tendsto_pi {β : Type*} {m : β → ∀ i, α i} {l : Filter β} :
Tendsto m l (pi f) ↔ ∀ i, Tendsto (fun x => m x i) l (f i) := by
simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl
/-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to
`f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a
product of topological spaces. -/
alias ⟨Tendsto.apply, _⟩ := tendsto_pi
theorem le_pi {g : Filter (∀ i, α i)} : g ≤ pi f ↔ ∀ i, Tendsto (eval i) g (f i) :=
tendsto_pi
@[mono]
theorem pi_mono (h : ∀ i, f₁ i ≤ f₂ i) : pi f₁ ≤ pi f₂ :=
iInf_mono fun i => comap_mono <| h i
theorem mem_pi_of_mem (i : ι) {s : Set (α i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f :=
mem_iInf_of_mem i <| preimage_mem_comap hs
theorem pi_mem_pi {I : Set ι} (hI : I.Finite) (h : ∀ i ∈ I, s i ∈ f i) : I.pi s ∈ pi f := by
rw [pi_def, biInter_eq_iInter]
refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl
exact preimage_mem_comap (h i i.2)
theorem mem_pi {s : Set (∀ i, α i)} :
s ∈ pi f ↔ ∃ I : Set ι, I.Finite ∧ ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ I.pi t ⊆ s := by
constructor
· simp only [pi, mem_iInf', mem_comap, pi_def]
rintro ⟨I, If, V, hVf, -, rfl, -⟩
choose t htf htV using hVf
exact ⟨I, If, t, htf, iInter₂_mono fun i _ => htV i⟩
· rintro ⟨I, If, t, htf, hts⟩
exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts
theorem mem_pi' {s : Set (∀ i, α i)} :
s ∈ pi f ↔ ∃ I : Finset ι, ∃ t : ∀ i, Set (α i), (∀ i, t i ∈ f i) ∧ Set.pi (↑I) t ⊆ s :=
mem_pi.trans exists_finite_iff_finset
theorem mem_of_pi_mem_pi [∀ i, NeBot (f i)] {I : Set ι} (h : I.pi s ∈ pi f) {i : ι} (hi : i ∈ I) :
s i ∈ f i := by
classical
rcases mem_pi.1 h with ⟨I', -, t, htf, hts⟩
refine mem_of_superset (htf i) fun x hx => ?_
have : ∀ i, (t i).Nonempty := fun i => nonempty_of_mem (htf i)
choose g hg using this
have : update g i x ∈ I'.pi t := fun j _ => by
rcases eq_or_ne j i with (rfl | hne) <;> simp [*]
simpa using hts this i hi
@[simp]
theorem pi_mem_pi_iff [∀ i, NeBot (f i)] {I : Set ι} (hI : I.Finite) :
I.pi s ∈ pi f ↔ ∀ i ∈ I, s i ∈ f i :=
⟨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩
theorem Eventually.eval_pi {i : ι} (hf : ∀ᶠ x : α i in f i, p i x) :
∀ᶠ x : ∀ i : ι, α i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf
theorem eventually_pi [Finite ι] (hf : ∀ i, ∀ᶠ x in f i, p i x) :
∀ᶠ x : ∀ i, α i in pi f, ∀ i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi
theorem hasBasis_pi {ι' : ι → Type} {s : ∀ i, ι' i → Set (α i)} {p : ∀ i, ι' i → Prop}
(h : ∀ i, (f i).HasBasis (p i) (s i)) :
(pi f).HasBasis (fun If : Set ι × ∀ i, ι' i => If.1.Finite ∧ ∀ i ∈ If.1, p i (If.2 i))
fun If : Set ι × ∀ i, ι' i => If.1.pi fun i => s i <| If.2 i := by
simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (∀ j, α j) → α i)
theorem le_pi_principal (s : (i : ι) → Set (α i)) :
𝓟 (univ.pi s) ≤ pi fun i ↦ 𝓟 (s i) :=
le_pi.2 fun i ↦ tendsto_principal_principal.2 fun _f hf ↦ hf i trivial
@[simp]
theorem pi_principal [Finite ι] (s : (i : ι) → Set (α i)) :
pi (fun i ↦ 𝓟 (s i)) = 𝓟 (univ.pi s) := by
simp [Filter.pi, Set.pi_def]
@[simp]
theorem pi_pure [Finite ι] (f : (i : ι) → α i) : pi (pure <| f ·) = pure f := by
simp only [← principal_singleton, pi_principal, univ_pi_singleton]
@[simp]
theorem pi_inf_principal_univ_pi_eq_bot :
pi f ⊓ 𝓟 (Set.pi univ s) = ⊥ ↔ ∃ i, f i ⊓ 𝓟 (s i) = ⊥ := by
constructor
· simp only [inf_principal_eq_bot, mem_pi]
contrapose!
rintro (hsf : ∀ i, ∃ᶠ x in f i, x ∈ s i) I - t htf hts
have : ∀ i, (s i ∩ t i).Nonempty := fun i => ((hsf i).and_eventually (htf i)).exists
choose x hxs hxt using this
exact hts (fun i _ => hxt i) (mem_univ_pi.2 hxs)
· simp only [inf_principal_eq_bot]
rintro ⟨i, hi⟩
filter_upwards [mem_pi_of_mem i hi] with x using mt fun h => h i trivial
@[simp]
theorem pi_inf_principal_pi_eq_bot [∀ i, NeBot (f i)] {I : Set ι} :
pi f ⊓ 𝓟 (Set.pi I s) = ⊥ ↔ ∃ i ∈ I, f i ⊓ 𝓟 (s i) = ⊥ := by
classical
rw [← univ_pi_piecewise_univ I, pi_inf_principal_univ_pi_eq_bot]
refine exists_congr fun i => ?_
by_cases hi : i ∈ I <;> simp [hi, NeBot.ne']
@[simp]
theorem pi_inf_principal_univ_pi_neBot :
NeBot (pi f ⊓ 𝓟 (Set.pi univ s)) ↔ ∀ i, NeBot (f i ⊓ 𝓟 (s i)) := by simp [neBot_iff]
@[simp]
theorem pi_inf_principal_pi_neBot [∀ i, NeBot (f i)] {I : Set ι} :
NeBot (pi f ⊓ 𝓟 (I.pi s)) ↔ ∀ i ∈ I, NeBot (f i ⊓ 𝓟 (s i)) := by simp [neBot_iff]
instance PiInfPrincipalPi.neBot [h : ∀ i, NeBot (f i ⊓ 𝓟 (s i))] {I : Set ι} :
NeBot (pi f ⊓ 𝓟 (I.pi s)) :=
(pi_inf_principal_univ_pi_neBot.2 ‹_›).mono <|
inf_le_inf_left _ <| principal_mono.2 fun x hx i _ => hx i trivial
@[simp]
theorem pi_eq_bot : pi f = ⊥ ↔ ∃ i, f i = ⊥ := by
simpa using @pi_inf_principal_univ_pi_eq_bot ι α f fun _ => univ
@[simp]
theorem pi_neBot : NeBot (pi f) ↔ ∀ i, NeBot (f i) := by simp [neBot_iff]
instance [∀ i, NeBot (f i)] : NeBot (pi f) :=
pi_neBot.2 ‹_›
@[simp]
theorem map_eval_pi (f : ∀ i, Filter (α i)) [∀ i, NeBot (f i)] (i : ι) :
map (eval i) (pi f) = f i := by
refine le_antisymm (tendsto_eval_pi f i) fun s hs => ?_
rcases mem_pi.1 (mem_map.1 hs) with ⟨I, hIf, t, htf, hI⟩
rw [← image_subset_iff] at hI
refine mem_of_superset (htf i) ((subset_eval_image_pi ?_ _).trans hI)
exact nonempty_of_mem (pi_mem_pi hIf fun i _ => htf i)
@[simp]
theorem pi_le_pi [∀ i, NeBot (f₁ i)] : pi f₁ ≤ pi f₂ ↔ ∀ i, f₁ i ≤ f₂ i :=
⟨fun h i => map_eval_pi f₁ i ▸ (tendsto_eval_pi _ _).mono_left h, pi_mono⟩
@[simp]
theorem pi_inj [∀ i, NeBot (f₁ i)] : pi f₁ = pi f₂ ↔ f₁ = f₂ := by
refine ⟨fun h => ?_, congr_arg pi⟩
have hle : f₁ ≤ f₂ := pi_le_pi.1 h.le
haveI : ∀ i, NeBot (f₂ i) := fun i => neBot_of_le (hle i)
exact hle.antisymm (pi_le_pi.1 h.ge)
end Pi
/-! ### `n`-ary coproducts of filters -/
section CoprodCat
-- for "Coprod"
/-- Coproduct of filters. -/
protected def coprodᵢ (f : ∀ i, Filter (α i)) : Filter (∀ i, α i) :=
⨆ i : ι, comap (eval i) (f i)
theorem mem_coprodᵢ_iff {s : Set (∀ i, α i)} :
s ∈ Filter.coprodᵢ f ↔ ∀ i : ι, ∃ t₁ ∈ f i, eval i ⁻¹' t₁ ⊆ s := by simp [Filter.coprodᵢ]
theorem compl_mem_coprodᵢ {s : Set (∀ i, α i)} :
sᶜ ∈ Filter.coprodᵢ f ↔ ∀ i, (eval i '' s)ᶜ ∈ f i := by
simp only [Filter.coprodᵢ, mem_iSup, compl_mem_comap]
theorem coprodᵢ_neBot_iff' :
NeBot (Filter.coprodᵢ f) ↔ (∀ i, Nonempty (α i)) ∧ ∃ d, NeBot (f d) := by
simp only [Filter.coprodᵢ, iSup_neBot, ← exists_and_left, ← comap_eval_neBot_iff']
@[simp]
theorem coprodᵢ_neBot_iff [∀ i, Nonempty (α i)] : NeBot (Filter.coprodᵢ f) ↔ ∃ d, NeBot (f d) := by
simp [coprodᵢ_neBot_iff', *]
theorem coprodᵢ_eq_bot_iff' : Filter.coprodᵢ f = ⊥ ↔ (∃ i, IsEmpty (α i)) ∨ f = ⊥ := by
simpa only [not_neBot, not_and_or, funext_iff, not_forall, not_exists, not_nonempty_iff]
using coprodᵢ_neBot_iff'.not
@[simp]
theorem coprodᵢ_eq_bot_iff [∀ i, Nonempty (α i)] : Filter.coprodᵢ f = ⊥ ↔ f = ⊥ := by
simpa [funext_iff] using coprodᵢ_neBot_iff.not
@[simp] theorem coprodᵢ_bot' : Filter.coprodᵢ (⊥ : ∀ i, Filter (α i)) = ⊥ :=
coprodᵢ_eq_bot_iff'.2 (Or.inr rfl)
@[simp]
theorem coprodᵢ_bot : Filter.coprodᵢ (fun _ => ⊥ : ∀ i, Filter (α i)) = ⊥ :=
coprodᵢ_bot'
theorem NeBot.coprodᵢ [∀ i, Nonempty (α i)] {i : ι} (h : NeBot (f i)) : NeBot (Filter.coprodᵢ f) :=
coprodᵢ_neBot_iff.2 ⟨i, h⟩
@[instance]
theorem coprodᵢ_neBot [∀ i, Nonempty (α i)] [Nonempty ι] (f : ∀ i, Filter (α i))
[H : ∀ i, NeBot (f i)] : NeBot (Filter.coprodᵢ f) :=
(H (Classical.arbitrary ι)).coprodᵢ
@[mono]
theorem coprodᵢ_mono (hf : ∀ i, f₁ i ≤ f₂ i) : Filter.coprodᵢ f₁ ≤ Filter.coprodᵢ f₂ :=
iSup_mono fun i => comap_mono (hf i)
variable {β : ι → Type*} {m : ∀ i, α i → β i}
theorem map_pi_map_coprodᵢ_le :
map (fun k : ∀ i, α i => fun i => m i (k i)) (Filter.coprodᵢ f) ≤
Filter.coprodᵢ fun i => map (m i) (f i) := by
simp only [le_def, mem_map, mem_coprodᵢ_iff]
intro s h i
obtain ⟨t, H, hH⟩ := h i
exact ⟨{ x : α i | m i x ∈ t }, H, fun x hx => hH hx⟩
theorem Tendsto.pi_map_coprodᵢ {g : ∀ i, Filter (β i)} (h : ∀ i, Tendsto (m i) (f i) (g i)) :
Tendsto (fun k : ∀ i, α i => fun i => m i (k i)) (Filter.coprodᵢ f) (Filter.coprodᵢ g) :=
map_pi_map_coprodᵢ_le.trans (coprodᵢ_mono h)
end CoprodCat
end Filter
|
Order\Filter\Pointwise.lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yaël Dillies
-/
import Mathlib.Data.Set.Pointwise.SMul
import Mathlib.Order.Filter.NAry
import Mathlib.Order.Filter.Ultrafilter
/-!
# Pointwise operations on filters
This file defines pointwise operations on filters. This is useful because usual algebraic operations
distribute over pointwise operations. For example,
* `(f₁ * f₂).map m = f₁.map m * f₂.map m`
* `𝓝 (x * y) = 𝓝 x * 𝓝 y`
## Main declarations
* `0` (`Filter.instZero`): Pure filter at `0 : α`, or alternatively principal filter at `0 : Set α`.
* `1` (`Filter.instOne`): Pure filter at `1 : α`, or alternatively principal filter at `1 : Set α`.
* `f + g` (`Filter.instAdd`): Addition, filter generated by all `s + t` where `s ∈ f` and `t ∈ g`.
* `f * g` (`Filter.instMul`): Multiplication, filter generated by all `s * t` where `s ∈ f` and
`t ∈ g`.
* `-f` (`Filter.instNeg`): Negation, filter of all `-s` where `s ∈ f`.
* `f⁻¹` (`Filter.instInv`): Inversion, filter of all `s⁻¹` where `s ∈ f`.
* `f - g` (`Filter.instSub`): Subtraction, filter generated by all `s - t` where `s ∈ f` and
`t ∈ g`.
* `f / g` (`Filter.instDiv`): Division, filter generated by all `s / t` where `s ∈ f` and `t ∈ g`.
* `f +ᵥ g` (`Filter.instVAdd`): Scalar addition, filter generated by all `s +ᵥ t` where `s ∈ f` and
`t ∈ g`.
* `f -ᵥ g` (`Filter.instVSub`): Scalar subtraction, filter generated by all `s -ᵥ t` where `s ∈ f`
and `t ∈ g`.
* `f • g` (`Filter.instSMul`): Scalar multiplication, filter generated by all `s • t` where
`s ∈ f` and `t ∈ g`.
* `a +ᵥ f` (`Filter.instVAddFilter`): Translation, filter of all `a +ᵥ s` where `s ∈ f`.
* `a • f` (`Filter.instSMulFilter`): Scaling, filter of all `a • s` where `s ∈ f`.
For `α` a semigroup/monoid, `Filter α` is a semigroup/monoid.
As an unfortunate side effect, this means that `n • f`, where `n : ℕ`, is ambiguous between
pointwise scaling and repeated pointwise addition. See note [pointwise nat action].
## Implementation notes
We put all instances in the locale `Pointwise`, so that these instances are not available by
default. Note that we do not mark them as reducible (as argued by note [reducible non-instances])
since we expect the locale to be open whenever the instances are actually used (and making the
instances reducible changes the behavior of `simp`).
## Tags
filter multiplication, filter addition, pointwise addition, pointwise multiplication,
-/
open Function Set Filter Pointwise
variable {F α β γ δ ε : Type*}
namespace Filter
/-! ### `0`/`1` as filters -/
section One
variable [One α] {f : Filter α} {s : Set α}
/-- `1 : Filter α` is defined as the filter of sets containing `1 : α` in locale `Pointwise`. -/
@[to_additive
"`0 : Filter α` is defined as the filter of sets containing `0 : α` in locale `Pointwise`."]
protected def instOne : One (Filter α) :=
⟨pure 1⟩
scoped[Pointwise] attribute [instance] Filter.instOne Filter.instZero
@[to_additive (attr := simp)]
theorem mem_one : s ∈ (1 : Filter α) ↔ (1 : α) ∈ s :=
mem_pure
@[to_additive]
theorem one_mem_one : (1 : Set α) ∈ (1 : Filter α) :=
mem_pure.2 Set.one_mem_one
@[to_additive (attr := simp)]
theorem pure_one : pure 1 = (1 : Filter α) :=
rfl
@[to_additive (attr := simp)]
theorem principal_one : 𝓟 1 = (1 : Filter α) :=
principal_singleton _
@[to_additive]
theorem one_neBot : (1 : Filter α).NeBot :=
Filter.pure_neBot
scoped[Pointwise] attribute [instance] one_neBot zero_neBot
@[to_additive (attr := simp)]
protected theorem map_one' (f : α → β) : (1 : Filter α).map f = pure (f 1) :=
rfl
@[to_additive (attr := simp)]
theorem le_one_iff : f ≤ 1 ↔ (1 : Set α) ∈ f :=
le_pure_iff
@[to_additive]
protected theorem NeBot.le_one_iff (h : f.NeBot) : f ≤ 1 ↔ f = 1 :=
h.le_pure_iff
@[to_additive (attr := simp)]
theorem eventually_one {p : α → Prop} : (∀ᶠ x in 1, p x) ↔ p 1 :=
eventually_pure
@[to_additive (attr := simp)]
theorem tendsto_one {a : Filter β} {f : β → α} : Tendsto f a 1 ↔ ∀ᶠ x in a, f x = 1 :=
tendsto_pure
@[to_additive (attr := simp)]
theorem one_prod_one [One β] : (1 : Filter α) ×ˢ (1 : Filter β) = 1 :=
prod_pure_pure
/-- `pure` as a `OneHom`. -/
@[to_additive "`pure` as a `ZeroHom`."]
def pureOneHom : OneHom α (Filter α) where
toFun := pure; map_one' := pure_one
@[to_additive (attr := simp)]
theorem coe_pureOneHom : (pureOneHom : α → Filter α) = pure :=
rfl
@[to_additive (attr := simp)]
theorem pureOneHom_apply (a : α) : pureOneHom a = pure a :=
rfl
variable [One β]
@[to_additive]
-- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it.
protected theorem map_one [FunLike F α β] [OneHomClass F α β] (φ : F) : map φ 1 = 1 := by
rw [Filter.map_one', map_one, pure_one]
end One
/-! ### Filter negation/inversion -/
section Inv
variable [Inv α] {f g : Filter α} {s : Set α} {a : α}
/-- The inverse of a filter is the pointwise preimage under `⁻¹` of its sets. -/
@[to_additive "The negation of a filter is the pointwise preimage under `-` of its sets."]
instance instInv : Inv (Filter α) :=
⟨map Inv.inv⟩
@[to_additive (attr := simp)]
protected theorem map_inv : f.map Inv.inv = f⁻¹ :=
rfl
@[to_additive]
theorem mem_inv : s ∈ f⁻¹ ↔ Inv.inv ⁻¹' s ∈ f :=
Iff.rfl
@[to_additive]
protected theorem inv_le_inv (hf : f ≤ g) : f⁻¹ ≤ g⁻¹ :=
map_mono hf
@[to_additive (attr := simp)]
theorem inv_pure : (pure a : Filter α)⁻¹ = pure a⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem inv_eq_bot_iff : f⁻¹ = ⊥ ↔ f = ⊥ :=
map_eq_bot_iff
@[to_additive (attr := simp)]
theorem neBot_inv_iff : f⁻¹.NeBot ↔ NeBot f :=
map_neBot_iff _
@[to_additive]
protected theorem NeBot.inv : f.NeBot → f⁻¹.NeBot := fun h => h.map _
@[to_additive neg.instNeBot]
lemma inv.instNeBot [NeBot f] : NeBot f⁻¹ := .inv ‹_›
scoped[Pointwise] attribute [instance] inv.instNeBot neg.instNeBot
end Inv
section InvolutiveInv
variable [InvolutiveInv α] {f g : Filter α} {s : Set α}
@[to_additive (attr := simp)]
protected lemma comap_inv : comap Inv.inv f = f⁻¹ :=
.symm <| map_eq_comap_of_inverse (inv_comp_inv _) (inv_comp_inv _)
@[to_additive]
theorem inv_mem_inv (hs : s ∈ f) : s⁻¹ ∈ f⁻¹ := by rwa [mem_inv, inv_preimage, inv_inv]
/-- Inversion is involutive on `Filter α` if it is on `α`. -/
@[to_additive "Negation is involutive on `Filter α` if it is on `α`."]
protected def instInvolutiveInv : InvolutiveInv (Filter α) :=
{ Filter.instInv with
inv_inv := fun f => map_map.trans <| by rw [inv_involutive.comp_self, map_id] }
scoped[Pointwise] attribute [instance] Filter.instInvolutiveInv Filter.instInvolutiveNeg
@[to_additive (attr := simp)]
protected theorem inv_le_inv_iff : f⁻¹ ≤ g⁻¹ ↔ f ≤ g :=
⟨fun h => inv_inv f ▸ inv_inv g ▸ Filter.inv_le_inv h, Filter.inv_le_inv⟩
@[to_additive]
theorem inv_le_iff_le_inv : f⁻¹ ≤ g ↔ f ≤ g⁻¹ := by rw [← Filter.inv_le_inv_iff, inv_inv]
@[to_additive (attr := simp)]
theorem inv_le_self : f⁻¹ ≤ f ↔ f⁻¹ = f :=
⟨fun h => h.antisymm <| inv_le_iff_le_inv.1 h, Eq.le⟩
end InvolutiveInv
@[to_additive (attr := simp)]
lemma inv_atTop {G : Type*} [OrderedCommGroup G] : (atTop : Filter G)⁻¹ = atBot :=
(OrderIso.inv G).map_atTop
/-! ### Filter addition/multiplication -/
section Mul
variable [Mul α] [Mul β] {f f₁ f₂ g g₁ g₂ h : Filter α} {s t : Set α} {a b : α}
/-- The filter `f * g` is generated by `{s * t | s ∈ f, t ∈ g}` in locale `Pointwise`. -/
@[to_additive "The filter `f + g` is generated by `{s + t | s ∈ f, t ∈ g}` in locale `Pointwise`."]
protected def instMul : Mul (Filter α) :=
⟨/- This is defeq to `map₂ (· * ·) f g`, but the hypothesis unfolds to `t₁ * t₂ ⊆ s` rather
than all the way to `Set.image2 (· * ·) t₁ t₂ ⊆ s`. -/
fun f g => { map₂ (· * ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ * t₂ ⊆ s } }⟩
scoped[Pointwise] attribute [instance] Filter.instMul Filter.instAdd
@[to_additive (attr := simp)]
theorem map₂_mul : map₂ (· * ·) f g = f * g :=
rfl
@[to_additive]
theorem mem_mul : s ∈ f * g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ * t₂ ⊆ s :=
Iff.rfl
@[to_additive]
theorem mul_mem_mul : s ∈ f → t ∈ g → s * t ∈ f * g :=
image2_mem_map₂
@[to_additive (attr := simp)]
theorem bot_mul : ⊥ * g = ⊥ :=
map₂_bot_left
@[to_additive (attr := simp)]
theorem mul_bot : f * ⊥ = ⊥ :=
map₂_bot_right
@[to_additive (attr := simp)]
theorem mul_eq_bot_iff : f * g = ⊥ ↔ f = ⊥ ∨ g = ⊥ :=
map₂_eq_bot_iff
@[to_additive (attr := simp)] -- TODO: make this a scoped instance in the `Pointwise` namespace
lemma mul_neBot_iff : (f * g).NeBot ↔ f.NeBot ∧ g.NeBot :=
map₂_neBot_iff
@[to_additive]
protected theorem NeBot.mul : NeBot f → NeBot g → NeBot (f * g) :=
NeBot.map₂
@[to_additive]
theorem NeBot.of_mul_left : (f * g).NeBot → f.NeBot :=
NeBot.of_map₂_left
@[to_additive]
theorem NeBot.of_mul_right : (f * g).NeBot → g.NeBot :=
NeBot.of_map₂_right
@[to_additive add.instNeBot]
protected lemma mul.instNeBot [NeBot f] [NeBot g] : NeBot (f * g) := .mul ‹_› ‹_›
scoped[Pointwise] attribute [instance] mul.instNeBot add.instNeBot
@[to_additive (attr := simp)]
theorem pure_mul : pure a * g = g.map (a * ·) :=
map₂_pure_left
@[to_additive (attr := simp)]
theorem mul_pure : f * pure b = f.map (· * b) :=
map₂_pure_right
@[to_additive]
-- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it.
theorem pure_mul_pure : (pure a : Filter α) * pure b = pure (a * b) :=
map₂_pure
@[to_additive (attr := simp)]
theorem le_mul_iff : h ≤ f * g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s * t ∈ h :=
le_map₂_iff
@[to_additive]
instance covariant_mul : CovariantClass (Filter α) (Filter α) (· * ·) (· ≤ ·) :=
⟨fun _ _ _ => map₂_mono_left⟩
@[to_additive]
instance covariant_swap_mul : CovariantClass (Filter α) (Filter α) (swap (· * ·)) (· ≤ ·) :=
⟨fun _ _ _ => map₂_mono_right⟩
@[to_additive]
protected theorem map_mul [FunLike F α β] [MulHomClass F α β] (m : F) :
(f₁ * f₂).map m = f₁.map m * f₂.map m :=
map_map₂_distrib <| map_mul m
/-- `pure` operation as a `MulHom`. -/
@[to_additive "The singleton operation as an `AddHom`."]
def pureMulHom : α →ₙ* Filter α where
toFun := pure; map_mul' _ _ := pure_mul_pure.symm
@[to_additive (attr := simp)]
theorem coe_pureMulHom : (pureMulHom : α → Filter α) = pure :=
rfl
@[to_additive (attr := simp)]
theorem pureMulHom_apply (a : α) : pureMulHom a = pure a :=
rfl
end Mul
/-! ### Filter subtraction/division -/
section Div
variable [Div α] {f f₁ f₂ g g₁ g₂ h : Filter α} {s t : Set α} {a b : α}
/-- The filter `f / g` is generated by `{s / t | s ∈ f, t ∈ g}` in locale `Pointwise`. -/
@[to_additive "The filter `f - g` is generated by `{s - t | s ∈ f, t ∈ g}` in locale `Pointwise`."]
protected def instDiv : Div (Filter α) :=
⟨/- This is defeq to `map₂ (· / ·) f g`, but the hypothesis unfolds to `t₁ / t₂ ⊆ s`
rather than all the way to `Set.image2 (· / ·) t₁ t₂ ⊆ s`. -/
fun f g => { map₂ (· / ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ / t₂ ⊆ s } }⟩
scoped[Pointwise] attribute [instance] Filter.instDiv Filter.instSub
@[to_additive (attr := simp)]
theorem map₂_div : map₂ (· / ·) f g = f / g :=
rfl
@[to_additive]
theorem mem_div : s ∈ f / g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ / t₂ ⊆ s :=
Iff.rfl
@[to_additive]
theorem div_mem_div : s ∈ f → t ∈ g → s / t ∈ f / g :=
image2_mem_map₂
@[to_additive (attr := simp)]
theorem bot_div : ⊥ / g = ⊥ :=
map₂_bot_left
@[to_additive (attr := simp)]
theorem div_bot : f / ⊥ = ⊥ :=
map₂_bot_right
@[to_additive (attr := simp)]
theorem div_eq_bot_iff : f / g = ⊥ ↔ f = ⊥ ∨ g = ⊥ :=
map₂_eq_bot_iff
@[to_additive (attr := simp)]
theorem div_neBot_iff : (f / g).NeBot ↔ f.NeBot ∧ g.NeBot :=
map₂_neBot_iff
@[to_additive]
protected theorem NeBot.div : NeBot f → NeBot g → NeBot (f / g) :=
NeBot.map₂
@[to_additive]
theorem NeBot.of_div_left : (f / g).NeBot → f.NeBot :=
NeBot.of_map₂_left
@[to_additive]
theorem NeBot.of_div_right : (f / g).NeBot → g.NeBot :=
NeBot.of_map₂_right
@[to_additive sub.instNeBot]
lemma div.instNeBot [NeBot f] [NeBot g] : NeBot (f / g) := .div ‹_› ‹_›
scoped[Pointwise] attribute [instance] div.instNeBot sub.instNeBot
@[to_additive (attr := simp)]
theorem pure_div : pure a / g = g.map (a / ·) :=
map₂_pure_left
@[to_additive (attr := simp)]
theorem div_pure : f / pure b = f.map (· / b) :=
map₂_pure_right
@[to_additive]
-- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it.
theorem pure_div_pure : (pure a : Filter α) / pure b = pure (a / b) :=
map₂_pure
@[to_additive]
protected theorem div_le_div : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ / g₁ ≤ f₂ / g₂ :=
map₂_mono
@[to_additive]
protected theorem div_le_div_left : g₁ ≤ g₂ → f / g₁ ≤ f / g₂ :=
map₂_mono_left
@[to_additive]
protected theorem div_le_div_right : f₁ ≤ f₂ → f₁ / g ≤ f₂ / g :=
map₂_mono_right
@[to_additive (attr := simp)]
protected theorem le_div_iff : h ≤ f / g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s / t ∈ h :=
le_map₂_iff
@[to_additive]
instance covariant_div : CovariantClass (Filter α) (Filter α) (· / ·) (· ≤ ·) :=
⟨fun _ _ _ => map₂_mono_left⟩
@[to_additive]
instance covariant_swap_div : CovariantClass (Filter α) (Filter α) (swap (· / ·)) (· ≤ ·) :=
⟨fun _ _ _ => map₂_mono_right⟩
end Div
open Pointwise
/-- Repeated pointwise addition (not the same as pointwise repeated addition!) of a `Filter`. See
Note [pointwise nat action]. -/
protected def instNSMul [Zero α] [Add α] : SMul ℕ (Filter α) :=
⟨nsmulRec⟩
/-- Repeated pointwise multiplication (not the same as pointwise repeated multiplication!) of a
`Filter`. See Note [pointwise nat action]. -/
@[to_additive existing]
protected def instNPow [One α] [Mul α] : Pow (Filter α) ℕ :=
⟨fun s n => npowRec n s⟩
/-- Repeated pointwise addition/subtraction (not the same as pointwise repeated
addition/subtraction!) of a `Filter`. See Note [pointwise nat action]. -/
protected def instZSMul [Zero α] [Add α] [Neg α] : SMul ℤ (Filter α) :=
⟨zsmulRec⟩
/-- Repeated pointwise multiplication/division (not the same as pointwise repeated
multiplication/division!) of a `Filter`. See Note [pointwise nat action]. -/
@[to_additive existing]
protected def instZPow [One α] [Mul α] [Inv α] : Pow (Filter α) ℤ :=
⟨fun s n => zpowRec npowRec n s⟩
scoped[Pointwise] attribute [instance] Filter.instNSMul Filter.instNPow
Filter.instZSMul Filter.instZPow
/-- `Filter α` is a `Semigroup` under pointwise operations if `α` is. -/
@[to_additive "`Filter α` is an `AddSemigroup` under pointwise operations if `α` is."]
protected def semigroup [Semigroup α] : Semigroup (Filter α) where
mul := (· * ·)
mul_assoc _ _ _ := map₂_assoc mul_assoc
/-- `Filter α` is a `CommSemigroup` under pointwise operations if `α` is. -/
@[to_additive "`Filter α` is an `AddCommSemigroup` under pointwise operations if `α` is."]
protected def commSemigroup [CommSemigroup α] : CommSemigroup (Filter α) :=
{ Filter.semigroup with mul_comm := fun _ _ => map₂_comm mul_comm }
section MulOneClass
variable [MulOneClass α] [MulOneClass β]
/-- `Filter α` is a `MulOneClass` under pointwise operations if `α` is. -/
@[to_additive "`Filter α` is an `AddZeroClass` under pointwise operations if `α` is."]
protected def mulOneClass : MulOneClass (Filter α) where
one := 1
mul := (· * ·)
one_mul := map₂_left_identity one_mul
mul_one := map₂_right_identity mul_one
scoped[Pointwise] attribute [instance] Filter.semigroup Filter.addSemigroup
Filter.commSemigroup Filter.addCommSemigroup Filter.mulOneClass Filter.addZeroClass
variable [FunLike F α β]
/-- If `φ : α →* β` then `mapMonoidHom φ` is the monoid homomorphism
`Filter α →* Filter β` induced by `map φ`. -/
@[to_additive "If `φ : α →+ β` then `mapAddMonoidHom φ` is the monoid homomorphism
`Filter α →+ Filter β` induced by `map φ`."]
def mapMonoidHom [MonoidHomClass F α β] (φ : F) : Filter α →* Filter β where
toFun := map φ
map_one' := Filter.map_one φ
map_mul' _ _ := Filter.map_mul φ
-- The other direction does not hold in general
@[to_additive]
theorem comap_mul_comap_le [MulHomClass F α β] (m : F) {f g : Filter β} :
f.comap m * g.comap m ≤ (f * g).comap m := fun _ ⟨_, ⟨t₁, ht₁, t₂, ht₂, t₁t₂⟩, mt⟩ =>
⟨m ⁻¹' t₁, ⟨t₁, ht₁, Subset.rfl⟩, m ⁻¹' t₂, ⟨t₂, ht₂, Subset.rfl⟩,
(preimage_mul_preimage_subset _).trans <| (preimage_mono t₁t₂).trans mt⟩
@[to_additive]
theorem Tendsto.mul_mul [MulHomClass F α β] (m : F) {f₁ g₁ : Filter α} {f₂ g₂ : Filter β} :
Tendsto m f₁ f₂ → Tendsto m g₁ g₂ → Tendsto m (f₁ * g₁) (f₂ * g₂) := fun hf hg =>
(Filter.map_mul m).trans_le <| mul_le_mul' hf hg
/-- `pure` as a `MonoidHom`. -/
@[to_additive "`pure` as an `AddMonoidHom`."]
def pureMonoidHom : α →* Filter α :=
{ pureMulHom, pureOneHom with }
@[to_additive (attr := simp)]
theorem coe_pureMonoidHom : (pureMonoidHom : α → Filter α) = pure :=
rfl
@[to_additive (attr := simp)]
theorem pureMonoidHom_apply (a : α) : pureMonoidHom a = pure a :=
rfl
end MulOneClass
section Monoid
variable [Monoid α] {f g : Filter α} {s : Set α} {a : α} {m n : ℕ}
/-- `Filter α` is a `Monoid` under pointwise operations if `α` is. -/
@[to_additive "`Filter α` is an `AddMonoid` under pointwise operations if `α` is."]
protected def monoid : Monoid (Filter α) :=
{ Filter.mulOneClass, Filter.semigroup, @Filter.instNPow α _ _ with }
scoped[Pointwise] attribute [instance] Filter.monoid Filter.addMonoid
@[to_additive]
theorem pow_mem_pow (hs : s ∈ f) : ∀ n : ℕ, s ^ n ∈ f ^ n
| 0 => by
rw [pow_zero]
exact one_mem_one
| n + 1 => by
rw [pow_succ]
exact mul_mem_mul (pow_mem_pow hs n) hs
@[to_additive (attr := simp) nsmul_bot]
theorem bot_pow {n : ℕ} (hn : n ≠ 0) : (⊥ : Filter α) ^ n = ⊥ := by
rw [← tsub_add_cancel_of_le (Nat.succ_le_of_lt <| Nat.pos_of_ne_zero hn), pow_succ', bot_mul]
@[to_additive]
theorem mul_top_of_one_le (hf : 1 ≤ f) : f * ⊤ = ⊤ := by
refine top_le_iff.1 fun s => ?_
simp only [mem_mul, mem_top, exists_and_left, exists_eq_left]
rintro ⟨t, ht, hs⟩
rwa [mul_univ_of_one_mem (mem_one.1 <| hf ht), univ_subset_iff] at hs
@[to_additive]
theorem top_mul_of_one_le (hf : 1 ≤ f) : ⊤ * f = ⊤ := by
refine top_le_iff.1 fun s => ?_
simp only [mem_mul, mem_top, exists_and_left, exists_eq_left]
rintro ⟨t, ht, hs⟩
rwa [univ_mul_of_one_mem (mem_one.1 <| hf ht), univ_subset_iff] at hs
@[to_additive (attr := simp)]
theorem top_mul_top : (⊤ : Filter α) * ⊤ = ⊤ :=
mul_top_of_one_le le_top
@[to_additive nsmul_top]
theorem top_pow : ∀ {n : ℕ}, n ≠ 0 → (⊤ : Filter α) ^ n = ⊤
| 0 => fun h => (h rfl).elim
| 1 => fun _ => pow_one _
| n + 2 => fun _ => by rw [pow_succ, top_pow n.succ_ne_zero, top_mul_top]
@[to_additive]
protected theorem _root_.IsUnit.filter : IsUnit a → IsUnit (pure a : Filter α) :=
IsUnit.map (pureMonoidHom : α →* Filter α)
end Monoid
/-- `Filter α` is a `CommMonoid` under pointwise operations if `α` is. -/
@[to_additive "`Filter α` is an `AddCommMonoid` under pointwise operations if `α` is."]
protected def commMonoid [CommMonoid α] : CommMonoid (Filter α) :=
{ Filter.mulOneClass, Filter.commSemigroup with }
open Pointwise
section DivisionMonoid
variable [DivisionMonoid α] {f g : Filter α}
@[to_additive]
protected theorem mul_eq_one_iff : f * g = 1 ↔ ∃ a b, f = pure a ∧ g = pure b ∧ a * b = 1 := by
refine ⟨fun hfg => ?_, ?_⟩
· obtain ⟨t₁, h₁, t₂, h₂, h⟩ : (1 : Set α) ∈ f * g := hfg.symm.subst one_mem_one
have hfg : (f * g).NeBot := hfg.symm.subst one_neBot
rw [(hfg.nonempty_of_mem <| mul_mem_mul h₁ h₂).subset_one_iff, Set.mul_eq_one_iff] at h
obtain ⟨a, b, rfl, rfl, h⟩ := h
refine ⟨a, b, ?_, ?_, h⟩
· rwa [← hfg.of_mul_left.le_pure_iff, le_pure_iff]
· rwa [← hfg.of_mul_right.le_pure_iff, le_pure_iff]
· rintro ⟨a, b, rfl, rfl, h⟩
rw [pure_mul_pure, h, pure_one]
/-- `Filter α` is a division monoid under pointwise operations if `α` is. -/
@[to_additive subtractionMonoid "`Filter α` is a subtraction monoid under pointwise operations if
`α` is."]
-- Porting note: `to_additive` guessed `divisionAddMonoid`
protected def divisionMonoid : DivisionMonoid (Filter α) :=
{ Filter.monoid, Filter.instInvolutiveInv, Filter.instDiv, Filter.instZPow (α := α) with
mul_inv_rev := fun s t => map_map₂_antidistrib mul_inv_rev
inv_eq_of_mul := fun s t h => by
obtain ⟨a, b, rfl, rfl, hab⟩ := Filter.mul_eq_one_iff.1 h
rw [inv_pure, inv_eq_of_mul_eq_one_right hab]
div_eq_mul_inv := fun f g => map_map₂_distrib_right div_eq_mul_inv }
@[to_additive]
theorem isUnit_iff : IsUnit f ↔ ∃ a, f = pure a ∧ IsUnit a := by
constructor
· rintro ⟨u, rfl⟩
obtain ⟨a, b, ha, hb, h⟩ := Filter.mul_eq_one_iff.1 u.mul_inv
refine ⟨a, ha, ⟨a, b, h, pure_injective ?_⟩, rfl⟩
rw [← pure_mul_pure, ← ha, ← hb]
exact u.inv_mul
· rintro ⟨a, rfl, ha⟩
exact ha.filter
end DivisionMonoid
/-- `Filter α` is a commutative division monoid under pointwise operations if `α` is. -/
@[to_additive subtractionCommMonoid
"`Filter α` is a commutative subtraction monoid under pointwise operations if `α` is."]
protected def divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (Filter α) :=
{ Filter.divisionMonoid, Filter.commSemigroup with }
/-- `Filter α` has distributive negation if `α` has. -/
protected def instDistribNeg [Mul α] [HasDistribNeg α] : HasDistribNeg (Filter α) :=
{ Filter.instInvolutiveNeg with
neg_mul := fun _ _ => map₂_map_left_comm neg_mul
mul_neg := fun _ _ => map_map₂_right_comm mul_neg }
scoped[Pointwise] attribute [instance] Filter.commMonoid Filter.addCommMonoid Filter.divisionMonoid
Filter.subtractionMonoid Filter.divisionCommMonoid Filter.subtractionCommMonoid
Filter.instDistribNeg
section Distrib
variable [Distrib α] {f g h : Filter α}
/-!
Note that `Filter α` is not a `Distrib` because `f * g + f * h` has cross terms that `f * (g + h)`
lacks.
-/
theorem mul_add_subset : f * (g + h) ≤ f * g + f * h :=
map₂_distrib_le_left mul_add
theorem add_mul_subset : (f + g) * h ≤ f * h + g * h :=
map₂_distrib_le_right add_mul
end Distrib
section MulZeroClass
variable [MulZeroClass α] {f g : Filter α}
/-! Note that `Filter` is not a `MulZeroClass` because `0 * ⊥ ≠ 0`. -/
theorem NeBot.mul_zero_nonneg (hf : f.NeBot) : 0 ≤ f * 0 :=
le_mul_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, ha⟩ := hf.nonempty_of_mem h₁
⟨_, ha, _, h₂, mul_zero _⟩
theorem NeBot.zero_mul_nonneg (hg : g.NeBot) : 0 ≤ 0 * g :=
le_mul_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, hb⟩ := hg.nonempty_of_mem h₂
⟨_, h₁, _, hb, zero_mul _⟩
end MulZeroClass
section Group
variable [Group α] [DivisionMonoid β] [FunLike F α β] [MonoidHomClass F α β]
(m : F) {f g f₁ g₁ : Filter α} {f₂ g₂ : Filter β}
/-! Note that `Filter α` is not a group because `f / f ≠ 1` in general -/
-- Porting note: increase priority to appease `simpNF` so left-hand side doesn't simplify
@[to_additive (attr := simp 1100)]
protected theorem one_le_div_iff : 1 ≤ f / g ↔ ¬Disjoint f g := by
refine ⟨fun h hfg => ?_, ?_⟩
· obtain ⟨s, hs, t, ht, hst⟩ := hfg.le_bot (mem_bot : ∅ ∈ ⊥)
exact Set.one_mem_div_iff.1 (h <| div_mem_div hs ht) (disjoint_iff.2 hst.symm)
· rintro h s ⟨t₁, h₁, t₂, h₂, hs⟩
exact hs (Set.one_mem_div_iff.2 fun ht => h <| disjoint_of_disjoint_of_mem ht h₁ h₂)
@[to_additive]
theorem not_one_le_div_iff : ¬1 ≤ f / g ↔ Disjoint f g :=
Filter.one_le_div_iff.not_left
@[to_additive]
theorem NeBot.one_le_div (h : f.NeBot) : 1 ≤ f / f := by
rintro s ⟨t₁, h₁, t₂, h₂, hs⟩
obtain ⟨a, ha₁, ha₂⟩ := Set.not_disjoint_iff.1 (h.not_disjoint h₁ h₂)
rw [mem_one, ← div_self' a]
exact hs (Set.div_mem_div ha₁ ha₂)
@[to_additive]
theorem isUnit_pure (a : α) : IsUnit (pure a : Filter α) :=
(Group.isUnit a).filter
@[simp]
theorem isUnit_iff_singleton : IsUnit f ↔ ∃ a, f = pure a := by
simp only [isUnit_iff, Group.isUnit, and_true_iff]
@[to_additive]
theorem map_inv' : f⁻¹.map m = (f.map m)⁻¹ :=
Semiconj.filter_map (map_inv m) f
@[to_additive]
protected theorem Tendsto.inv_inv : Tendsto m f₁ f₂ → Tendsto m f₁⁻¹ f₂⁻¹ := fun hf =>
(Filter.map_inv' m).trans_le <| Filter.inv_le_inv hf
@[to_additive]
protected theorem map_div : (f / g).map m = f.map m / g.map m :=
map_map₂_distrib <| map_div m
@[to_additive]
protected theorem Tendsto.div_div (hf : Tendsto m f₁ f₂) (hg : Tendsto m g₁ g₂) :
Tendsto m (f₁ / g₁) (f₂ / g₂) :=
(Filter.map_div m).trans_le <| Filter.div_le_div hf hg
end Group
open Pointwise
section GroupWithZero
variable [GroupWithZero α] {f g : Filter α}
theorem NeBot.div_zero_nonneg (hf : f.NeBot) : 0 ≤ f / 0 :=
Filter.le_div_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, ha⟩ := hf.nonempty_of_mem h₁
⟨_, ha, _, h₂, div_zero _⟩
theorem NeBot.zero_div_nonneg (hg : g.NeBot) : 0 ≤ 0 / g :=
Filter.le_div_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, hb⟩ := hg.nonempty_of_mem h₂
⟨_, h₁, _, hb, zero_div _⟩
end GroupWithZero
/-! ### Scalar addition/multiplication of filters -/
section SMul
variable [SMul α β] {f f₁ f₂ : Filter α} {g g₁ g₂ h : Filter β} {s : Set α} {t : Set β} {a : α}
{b : β}
/-- The filter `f • g` is generated by `{s • t | s ∈ f, t ∈ g}` in locale `Pointwise`. -/
@[to_additive "The filter `f +ᵥ g` is generated by `{s +ᵥ t | s ∈ f, t ∈ g}` in locale
`Pointwise`."]
protected def instSMul : SMul (Filter α) (Filter β) :=
⟨/- This is defeq to `map₂ (· • ·) f g`, but the hypothesis unfolds to `t₁ • t₂ ⊆ s`
rather than all the way to `Set.image2 (· • ·) t₁ t₂ ⊆ s`. -/
fun f g => { map₂ (· • ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ • t₂ ⊆ s } }⟩
scoped[Pointwise] attribute [instance] Filter.instSMul Filter.instVAdd
@[to_additive (attr := simp)]
theorem map₂_smul : map₂ (· • ·) f g = f • g :=
rfl
@[to_additive]
theorem mem_smul : t ∈ f • g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ • t₂ ⊆ t :=
Iff.rfl
@[to_additive]
theorem smul_mem_smul : s ∈ f → t ∈ g → s • t ∈ f • g :=
image2_mem_map₂
@[to_additive (attr := simp)]
theorem bot_smul : (⊥ : Filter α) • g = ⊥ :=
map₂_bot_left
@[to_additive (attr := simp)]
theorem smul_bot : f • (⊥ : Filter β) = ⊥ :=
map₂_bot_right
@[to_additive (attr := simp)]
theorem smul_eq_bot_iff : f • g = ⊥ ↔ f = ⊥ ∨ g = ⊥ :=
map₂_eq_bot_iff
@[to_additive (attr := simp)]
theorem smul_neBot_iff : (f • g).NeBot ↔ f.NeBot ∧ g.NeBot :=
map₂_neBot_iff
@[to_additive]
protected theorem NeBot.smul : NeBot f → NeBot g → NeBot (f • g) :=
NeBot.map₂
@[to_additive]
theorem NeBot.of_smul_left : (f • g).NeBot → f.NeBot :=
NeBot.of_map₂_left
@[to_additive]
theorem NeBot.of_smul_right : (f • g).NeBot → g.NeBot :=
NeBot.of_map₂_right
@[to_additive vadd.instNeBot]
lemma smul.instNeBot [NeBot f] [NeBot g] : NeBot (f • g) := .smul ‹_› ‹_›
scoped[Pointwise] attribute [instance] smul.instNeBot vadd.instNeBot
@[to_additive (attr := simp)]
theorem pure_smul : (pure a : Filter α) • g = g.map (a • ·) :=
map₂_pure_left
@[to_additive (attr := simp)]
theorem smul_pure : f • pure b = f.map (· • b) :=
map₂_pure_right
@[to_additive]
-- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it.
theorem pure_smul_pure : (pure a : Filter α) • (pure b : Filter β) = pure (a • b) :=
map₂_pure
@[to_additive]
theorem smul_le_smul : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ • g₁ ≤ f₂ • g₂ :=
map₂_mono
@[to_additive]
theorem smul_le_smul_left : g₁ ≤ g₂ → f • g₁ ≤ f • g₂ :=
map₂_mono_left
@[to_additive]
theorem smul_le_smul_right : f₁ ≤ f₂ → f₁ • g ≤ f₂ • g :=
map₂_mono_right
@[to_additive (attr := simp)]
theorem le_smul_iff : h ≤ f • g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s • t ∈ h :=
le_map₂_iff
@[to_additive]
instance covariant_smul : CovariantClass (Filter α) (Filter β) (· • ·) (· ≤ ·) :=
⟨fun _ _ _ => map₂_mono_left⟩
end SMul
/-! ### Scalar subtraction of filters -/
section Vsub
variable [VSub α β] {f f₁ f₂ g g₁ g₂ : Filter β} {h : Filter α} {s t : Set β} {a b : β}
/-- The filter `f -ᵥ g` is generated by `{s -ᵥ t | s ∈ f, t ∈ g}` in locale `Pointwise`. -/
protected def instVSub : VSub (Filter α) (Filter β) :=
⟨/- This is defeq to `map₂ (-ᵥ) f g`, but the hypothesis unfolds to `t₁ -ᵥ t₂ ⊆ s` rather than all
the way to `Set.image2 (-ᵥ) t₁ t₂ ⊆ s`. -/
fun f g => { map₂ (· -ᵥ ·) f g with sets := { s | ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ -ᵥ t₂ ⊆ s } }⟩
scoped[Pointwise] attribute [instance] Filter.instVSub
@[simp]
theorem map₂_vsub : map₂ (· -ᵥ ·) f g = f -ᵥ g :=
rfl
theorem mem_vsub {s : Set α} : s ∈ f -ᵥ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ -ᵥ t₂ ⊆ s :=
Iff.rfl
theorem vsub_mem_vsub : s ∈ f → t ∈ g → s -ᵥ t ∈ f -ᵥ g :=
image2_mem_map₂
@[simp]
theorem bot_vsub : (⊥ : Filter β) -ᵥ g = ⊥ :=
map₂_bot_left
@[simp]
theorem vsub_bot : f -ᵥ (⊥ : Filter β) = ⊥ :=
map₂_bot_right
@[simp]
theorem vsub_eq_bot_iff : f -ᵥ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ :=
map₂_eq_bot_iff
@[simp]
theorem vsub_neBot_iff : (f -ᵥ g : Filter α).NeBot ↔ f.NeBot ∧ g.NeBot :=
map₂_neBot_iff
protected theorem NeBot.vsub : NeBot f → NeBot g → NeBot (f -ᵥ g) :=
NeBot.map₂
theorem NeBot.of_vsub_left : (f -ᵥ g : Filter α).NeBot → f.NeBot :=
NeBot.of_map₂_left
theorem NeBot.of_vsub_right : (f -ᵥ g : Filter α).NeBot → g.NeBot :=
NeBot.of_map₂_right
lemma vsub.instNeBot [NeBot f] [NeBot g] : NeBot (f -ᵥ g) := .vsub ‹_› ‹_›
scoped[Pointwise] attribute [instance] vsub.instNeBot
@[simp]
theorem pure_vsub : (pure a : Filter β) -ᵥ g = g.map (a -ᵥ ·) :=
map₂_pure_left
@[simp]
theorem vsub_pure : f -ᵥ pure b = f.map (· -ᵥ b) :=
map₂_pure_right
-- Porting note (#11119): removed `simp` attribute because `simpNF` says it can prove it.
theorem pure_vsub_pure : (pure a : Filter β) -ᵥ pure b = (pure (a -ᵥ b) : Filter α) :=
map₂_pure
theorem vsub_le_vsub : f₁ ≤ f₂ → g₁ ≤ g₂ → f₁ -ᵥ g₁ ≤ f₂ -ᵥ g₂ :=
map₂_mono
theorem vsub_le_vsub_left : g₁ ≤ g₂ → f -ᵥ g₁ ≤ f -ᵥ g₂ :=
map₂_mono_left
theorem vsub_le_vsub_right : f₁ ≤ f₂ → f₁ -ᵥ g ≤ f₂ -ᵥ g :=
map₂_mono_right
@[simp]
theorem le_vsub_iff : h ≤ f -ᵥ g ↔ ∀ ⦃s⦄, s ∈ f → ∀ ⦃t⦄, t ∈ g → s -ᵥ t ∈ h :=
le_map₂_iff
end Vsub
/-! ### Translation/scaling of filters -/
section SMul
variable [SMul α β] {f f₁ f₂ : Filter β} {s : Set β} {a : α}
/-- `a • f` is the map of `f` under `a •` in locale `Pointwise`. -/
@[to_additive "`a +ᵥ f` is the map of `f` under `a +ᵥ` in locale `Pointwise`."]
protected def instSMulFilter : SMul α (Filter β) :=
⟨fun a => map (a • ·)⟩
scoped[Pointwise] attribute [instance] Filter.instSMulFilter Filter.instVAddFilter
@[to_additive (attr := simp)]
protected theorem map_smul : map (fun b => a • b) f = a • f :=
rfl
@[to_additive]
theorem mem_smul_filter : s ∈ a • f ↔ (a • ·) ⁻¹' s ∈ f := Iff.rfl
@[to_additive]
theorem smul_set_mem_smul_filter : s ∈ f → a • s ∈ a • f :=
image_mem_map
@[to_additive (attr := simp)]
theorem smul_filter_bot : a • (⊥ : Filter β) = ⊥ :=
map_bot
@[to_additive (attr := simp)]
theorem smul_filter_eq_bot_iff : a • f = ⊥ ↔ f = ⊥ :=
map_eq_bot_iff
@[to_additive (attr := simp)]
theorem smul_filter_neBot_iff : (a • f).NeBot ↔ f.NeBot :=
map_neBot_iff _
@[to_additive]
theorem NeBot.smul_filter : f.NeBot → (a • f).NeBot := fun h => h.map _
@[to_additive]
theorem NeBot.of_smul_filter : (a • f).NeBot → f.NeBot :=
NeBot.of_map
@[to_additive vadd_filter.instNeBot]
lemma smul_filter.instNeBot [NeBot f] : NeBot (a • f) := .smul_filter ‹_›
scoped[Pointwise] attribute [instance] smul_filter.instNeBot vadd_filter.instNeBot
@[to_additive]
theorem smul_filter_le_smul_filter (hf : f₁ ≤ f₂) : a • f₁ ≤ a • f₂ :=
map_mono hf
@[to_additive]
instance covariant_smul_filter : CovariantClass α (Filter β) (· • ·) (· ≤ ·) :=
⟨fun _ => @map_mono β β _⟩
end SMul
open Pointwise
@[to_additive]
instance smulCommClass_filter [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α β (Filter γ) :=
⟨fun _ _ _ => map_comm (funext <| smul_comm _ _) _⟩
@[to_additive]
instance smulCommClass_filter' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass α (Filter β) (Filter γ) :=
⟨fun a _ _ => map_map₂_distrib_right <| smul_comm a⟩
@[to_additive]
instance smulCommClass_filter'' [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Filter α) β (Filter γ) :=
haveI := SMulCommClass.symm α β γ
SMulCommClass.symm _ _ _
@[to_additive]
instance smulCommClass [SMul α γ] [SMul β γ] [SMulCommClass α β γ] :
SMulCommClass (Filter α) (Filter β) (Filter γ) :=
⟨fun _ _ _ => map₂_left_comm smul_comm⟩
@[to_additive vaddAssocClass]
instance isScalarTower [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α β (Filter γ) :=
⟨fun a b f => by simp only [← Filter.map_smul, map_map, smul_assoc]; rfl⟩
@[to_additive vaddAssocClass']
instance isScalarTower' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower α (Filter β) (Filter γ) :=
⟨fun a f g => by
refine (map_map₂_distrib_left fun _ _ => ?_).symm
exact (smul_assoc a _ _).symm⟩
@[to_additive vaddAssocClass'']
instance isScalarTower'' [SMul α β] [SMul α γ] [SMul β γ] [IsScalarTower α β γ] :
IsScalarTower (Filter α) (Filter β) (Filter γ) :=
⟨fun _ _ _ => map₂_assoc smul_assoc⟩
@[to_additive]
instance isCentralScalar [SMul α β] [SMul αᵐᵒᵖ β] [IsCentralScalar α β] :
IsCentralScalar α (Filter β) :=
⟨fun _ f => (congr_arg fun m => map m f) <| funext fun _ => op_smul_eq_smul _ _⟩
/-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of
`Filter α` on `Filter β`. -/
@[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action
of `Filter α` on `Filter β`"]
protected def mulAction [Monoid α] [MulAction α β] : MulAction (Filter α) (Filter β) where
one_smul f := map₂_pure_left.trans <| by simp_rw [one_smul, map_id']
mul_smul f g h := map₂_assoc mul_smul
/-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `Filter β`.
-/
@[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on
`Filter β`."]
protected def mulActionFilter [Monoid α] [MulAction α β] : MulAction α (Filter β) where
mul_smul a b f := by simp only [← Filter.map_smul, map_map, Function.comp, ← mul_smul]
one_smul f := by simp only [← Filter.map_smul, one_smul, map_id']
scoped[Pointwise] attribute [instance] Filter.mulAction Filter.addAction Filter.mulActionFilter
Filter.addActionFilter
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
multiplicative action on `Filter β`. -/
protected def distribMulActionFilter [Monoid α] [AddMonoid β] [DistribMulAction α β] :
DistribMulAction α (Filter β) where
smul_add _ _ _ := map_map₂_distrib <| smul_add _
smul_zero _ := (map_pure _ _).trans <| by rw [smul_zero, pure_zero]
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/
protected def mulDistribMulActionFilter [Monoid α] [Monoid β] [MulDistribMulAction α β] :
MulDistribMulAction α (Set β) where
smul_mul _ _ _ := image_image2_distrib <| smul_mul' _
smul_one _ := image_singleton.trans <| by rw [smul_one, singleton_one]
scoped[Pointwise]
attribute [instance] Filter.distribMulActionFilter Filter.mulDistribMulActionFilter
section SMulWithZero
variable [Zero α] [Zero β] [SMulWithZero α β] {f : Filter α} {g : Filter β}
/-!
Note that we have neither `SMulWithZero α (Filter β)` nor `SMulWithZero (Filter α) (Filter β)`
because `0 * ⊥ ≠ 0`.
-/
theorem NeBot.smul_zero_nonneg (hf : f.NeBot) : 0 ≤ f • (0 : Filter β) :=
le_smul_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, ha⟩ := hf.nonempty_of_mem h₁
⟨_, ha, _, h₂, smul_zero _⟩
theorem NeBot.zero_smul_nonneg (hg : g.NeBot) : 0 ≤ (0 : Filter α) • g :=
le_smul_iff.2 fun _ h₁ _ h₂ =>
let ⟨_, hb⟩ := hg.nonempty_of_mem h₂
⟨_, h₁, _, hb, zero_smul _ _⟩
theorem zero_smul_filter_nonpos : (0 : α) • g ≤ 0 := by
refine fun s hs => mem_smul_filter.2 ?_
convert @univ_mem _ g
refine eq_univ_iff_forall.2 fun a => ?_
rwa [mem_preimage, zero_smul]
theorem zero_smul_filter (hg : g.NeBot) : (0 : α) • g = 0 :=
zero_smul_filter_nonpos.antisymm <|
le_map_iff.2 fun s hs => by
simp_rw [zero_smul, (hg.nonempty_of_mem hs).image_const]
exact zero_mem_zero
end SMulWithZero
end Filter
|
Order\Filter\Prod.lean | /-
Copyright (c) 2022 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johanes Hölzl, Patrick Massot, Yury Kudryashov, Kevin Wilson, Heather Macbeth
-/
import Mathlib.Order.Filter.Basic
/-!
# Product and coproduct filters
In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product
of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and
`Filter.Tendsto Prod.snd l g`.
## Implementation details
The product filter cannot be defined using the monad structure on filters. For example:
```lean
F := do {x ← seq, y ← top, return (x, y)}
G := do {y ← top, x ← seq, return (x, y)}
```
hence:
```lean
s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s
s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s
```
Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`.
As product filter we want to have `F` as result.
## Notations
* `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`.
-/
open Set
open Filter
namespace Filter
variable {α β γ δ : Type*} {ι : Sort*}
section Prod
variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β}
/-- Product of filters. This is the filter generated by cartesian products
of elements of the component filters. -/
protected def prod (f : Filter α) (g : Filter β) : Filter (α × β) :=
f.comap Prod.fst ⊓ g.comap Prod.snd
instance instSProd : SProd (Filter α) (Filter β) (Filter (α × β)) where
sprod := Filter.prod
theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g :=
inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht)
theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by
simp only [SProd.sprod, Filter.prod]
constructor
· rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩
exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩
· rintro ⟨t₁, ht₁, t₂, ht₂, h⟩
exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h
@[simp]
theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g :=
⟨fun h =>
let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h
(prod_subset_prod_iff.1 H).elim
(fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h =>
h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e =>
absurd ht'e (nonempty_of_mem ht').ne_empty,
fun h => prod_mem_prod h.1 h.2⟩
theorem mem_prod_principal {s : Set (α × β)} :
s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by
rw [← @exists_mem_subset_iff _ f, mem_prod_iff]
refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩
· rintro ⟨v, v_in, hv⟩ a a_in b b_in
exact hv (mk_mem_prod a_in <| v_in b_in)
· rintro ⟨x, y⟩ ⟨hx, hy⟩
exact h hx y hy
theorem mem_prod_top {s : Set (α × β)} :
s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by
rw [← principal_univ, mem_prod_principal]
simp only [mem_univ, forall_true_left]
theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} :
(∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by
rw [eventually_iff, eventually_iff, mem_prod_principal]
simp only [mem_setOf_eq]
theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) :
comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by
erw [comap_inf, Filter.comap_comap, Filter.comap_comap]
theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_top, inf_top_eq]
theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_top, top_inf_eq]
theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_sup, inf_sup_right, ← Filter.prod, ← Filter.prod]
theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_sup, inf_sup_left, ← Filter.prod, ← Filter.prod]
theorem eventually_prod_iff {p : α × β → Prop} :
(∀ᶠ x in f ×ˢ g, p x) ↔
∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧
∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by
simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g
theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f :=
tendsto_inf_left tendsto_comap
theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g :=
tendsto_inf_right tendsto_comap
/-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to
`g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).1) f g :=
tendsto_fst.comp H
/-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to
`h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).2) f h :=
tendsto_snd.comp H
theorem Tendsto.prod_mk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ}
(h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) :=
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) :=
tendsto_snd.prod_mk tendsto_fst
theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).1 :=
tendsto_fst.eventually h
theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).2 :=
tendsto_snd.eventually h
theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β}
{pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl lb).and (hb.prod_inr la)
theorem EventuallyEq.prod_map {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) :
Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb :=
(Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2
theorem EventuallyLE.prod_map {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) :
Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb :=
Eventually.prod_mk ha hb
theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop}
(h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by
rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩
exact ha.mono fun a ha => hb.mono fun b hb => h ha hb
protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop}
(h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 :=
mt (fun h ↦ by simpa only [not_frequently] using h.curry) h
/-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about
all diagonal pairs `(i, i)` -/
theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) :
∀ᶠ i in f, p (i, i) := by
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
apply (ht.and hs).mono fun x hx => hst hx.1 hx.2
theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} :
(∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} :
(∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) :=
tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod
theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} :
(⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_iInf, iInf_inf]
simp only [Filter.prod, eq_self_iff_true]
theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} :
(f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by
dsimp only [SProd.sprod]
rw [Filter.prod, comap_iInf, inf_iInf]
simp only [Filter.prod, eq_self_iff_true]
@[mono, gcongr]
theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ :=
inf_le_inf (comap_mono hf) (comap_mono hg)
@[gcongr]
theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g :=
Filter.prod_mono hf rfl.le
@[gcongr]
theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ :=
Filter.prod_mono rfl.le hf
theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by
simp only [SProd.sprod, Filter.prod, comap_comap, comap_inf, (· ∘ ·)]
theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by
simp only [SProd.sprod, Filter.prod, comap_comap, (· ∘ ·), inf_comm, Prod.swap, comap_inf]
theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by
rw [prod_comm', ← map_swap_eq_comap_swap]
rfl
theorem mem_prod_iff_left {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by
simp only [mem_prod_iff, prod_subset_iff]
refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff
exact exists_congr fun _ => Iff.rfl.and forall₂_swap
theorem mem_prod_iff_right {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by
rw [prod_comm, mem_map, mem_prod_iff_left]; rfl
@[simp]
theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by
ext s
simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def,
exists_mem_subset_iff]
@[simp]
theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by
rw [prod_comm, map_map]; apply map_fst_prod
@[simp]
theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ :=
⟨fun h =>
⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩,
fun h => prod_mono h.1 h.2⟩
@[simp]
theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by
refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩
have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le
haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2
exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩
theorem eventually_swap_iff {p : α × β → Prop} :
(∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by
rw [prod_comm]; rfl
theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by
simp_rw [← comap_equiv_symm, SProd.sprod, Filter.prod, comap_inf, comap_comap, inf_assoc, (· ∘ ·),
Equiv.prodAssoc_symm_apply]
theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by
simp_rw [map_equiv_symm, SProd.sprod, Filter.prod, comap_inf, comap_comap, inf_assoc,
Function.comp, Equiv.prodAssoc_apply]
theorem tendsto_prodAssoc {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) :=
(prod_assoc f g h).le
theorem tendsto_prodAssoc_symm {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) :=
(prod_assoc_symm f g h).le
/-- A useful lemma when dealing with uniformities. -/
theorem map_swap4_prod {h : Filter γ} {k : Filter δ} :
map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) =
(f ×ˢ h) ×ˢ (g ×ˢ k) := by
simp_rw [map_swap4_eq_comap, SProd.sprod, Filter.prod, comap_inf, comap_comap]; ac_rfl
theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} :
Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k))
((f ×ˢ h) ×ˢ (g ×ˢ k)) :=
map_swap4_prod.le
theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) :=
le_antisymm
(fun s hs =>
let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs
mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <|
by rwa [prod_image_image_eq, image_subset_iff])
((tendsto_map.comp tendsto_fst).prod_mk (tendsto_map.comp tendsto_snd))
theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂)
(g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) :
map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) :=
prod_map_map_eq
theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) :
map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by
rw [← prod_map_map_eq', map_id]
theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) :
F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by
rw [← prod_map_map_eq', map_id]
theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≤ map Prod.fst f ×ˢ map Prod.snd f :=
le_inf le_comap_map le_comap_map
theorem Tendsto.prod_map {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β}
{c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) :
Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by
erw [Tendsto, ← prod_map_map_eq]
exact Filter.prod_mono hf hg
protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) :
map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by
simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left]
intro s
constructor
· exact fun ⟨t, ht, s, hs, h⟩ => ⟨s, hs, t, ht, fun x hx y hy => @h ⟨x, y⟩ ⟨hx, hy⟩⟩
· exact fun ⟨s, hs, t, ht, h⟩ => ⟨t, ht, s, hs, fun ⟨x, y⟩ ⟨hx, hy⟩ => h x hx y hy⟩
theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g
theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} :
(f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by
simp only [SProd.sprod, Filter.prod, comap_inf, inf_comm, inf_assoc, inf_left_comm]
theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by
rw [prod_inf_prod, inf_idem]
theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by
rw [prod_inf_prod, inf_idem]
@[simp]
theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by
simp only [SProd.sprod, Filter.prod, comap_principal, principal_eq_iff_eq, comap_principal,
inf_principal]; rfl
@[simp]
theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by
rw [prod_eq, map_pure, pure_seq_eq_map]
theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) :
map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by
rw [Filter.pure_prod]; rfl
@[simp]
theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by
rw [prod_eq, seq_pure, map_map]; rfl
theorem prod_pure_pure {a : α} {b : β} :
(pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp
@[simp]
theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by
simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop,
Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right]
@[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl
@[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl
theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by
simp only [neBot_iff, Ne, prod_eq_bot, not_or]
protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟨hf, hg⟩
instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg
@[simp]
lemma disjoint_prod {f' : Filter α} {g' : Filter β} :
Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' ∨ Disjoint g g' := by
simp only [disjoint_iff, prod_inf_prod, prod_eq_bot]
/-- `p ∧ q` occurs frequently along the product of two filters
iff both `p` and `q` occur frequently along the corresponding filters. -/
theorem frequently_prod_and {p : α → Prop} {q : β → Prop} :
(∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by
simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal]
rfl
theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} :
Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by
simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop, iff_self_iff]
theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} :
Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by
dsimp only [SProd.sprod]
unfold Filter.prod
simp only [tendsto_inf, tendsto_comap_iff, (· ∘ ·)]
theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} :
(f ≤ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' :=
tendsto_prod_iff'
end Prod
/-! ### Coproducts of filters -/
section Coprod
variable {f : Filter α} {g : Filter β}
/-- Coproduct of filters. -/
protected def coprod (f : Filter α) (g : Filter β) : Filter (α × β) :=
f.comap Prod.fst ⊔ g.comap Prod.snd
theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) :
Filter.coprod f g = f ×ˢ ⊤ ⊔ ⊤ ×ˢ g := by
rw [prod_top, top_prod]
rfl
theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by
simp [Filter.coprod]
@[simp]
theorem bot_coprod (l : Filter β) : (⊥ : Filter α).coprod l = comap Prod.snd l := by
simp [Filter.coprod]
@[simp]
theorem coprod_bot (l : Filter α) : l.coprod (⊥ : Filter β) = comap Prod.fst l := by
simp [Filter.coprod]
theorem bot_coprod_bot : (⊥ : Filter α).coprod (⊥ : Filter β) = ⊥ := by simp
theorem compl_mem_coprod {s : Set (α × β)} {la : Filter α} {lb : Filter β} :
sᶜ ∈ la.coprod lb ↔ (Prod.fst '' s)ᶜ ∈ la ∧ (Prod.snd '' s)ᶜ ∈ lb := by
simp only [Filter.coprod, mem_sup, compl_mem_comap]
@[mono]
theorem coprod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁.coprod g₁ ≤ f₂.coprod g₂ :=
sup_le_sup (comap_mono hf) (comap_mono hg)
theorem coprod_neBot_iff : (f.coprod g).NeBot ↔ f.NeBot ∧ Nonempty β ∨ Nonempty α ∧ g.NeBot := by
simp [Filter.coprod]
@[instance]
theorem coprod_neBot_left [NeBot f] [Nonempty β] : (f.coprod g).NeBot :=
coprod_neBot_iff.2 (Or.inl ⟨‹_›, ‹_›⟩)
@[instance]
theorem coprod_neBot_right [NeBot g] [Nonempty α] : (f.coprod g).NeBot :=
coprod_neBot_iff.2 (Or.inr ⟨‹_›, ‹_›⟩)
theorem principal_coprod_principal (s : Set α) (t : Set β) :
(𝓟 s).coprod (𝓟 t) = 𝓟 (sᶜ ×ˢ tᶜ)ᶜ := by
rw [Filter.coprod, comap_principal, comap_principal, sup_principal, Set.prod_eq, compl_inter,
preimage_compl, preimage_compl, compl_compl, compl_compl]
-- this inequality can be strict; see `map_const_principal_coprod_map_id_principal` and
-- `map_prod_map_const_id_principal_coprod_principal` below.
theorem map_prod_map_coprod_le.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} :
map (Prod.map m₁ m₂) (f₁.coprod f₂) ≤ (map m₁ f₁).coprod (map m₂ f₂) := by
intro s
simp only [mem_map, mem_coprod_iff]
rintro ⟨⟨u₁, hu₁, h₁⟩, u₂, hu₂, h₂⟩
refine ⟨⟨m₁ ⁻¹' u₁, hu₁, fun _ hx => h₁ ?_⟩, ⟨m₂ ⁻¹' u₂, hu₂, fun _ hx => h₂ ?_⟩⟩ <;> convert hx
/-- Characterization of the coproduct of the `Filter.map`s of two principal filters `𝓟 {a}` and
`𝓟 {i}`, the first under the constant function `fun a => b` and the second under the identity
function. Together with the next lemma, `map_prod_map_const_id_principal_coprod_principal`, this
provides an example showing that the inequality in the lemma `map_prod_map_coprod_le` can be strict.
-/
theorem map_const_principal_coprod_map_id_principal {α β ι : Type*} (a : α) (b : β) (i : ι) :
(map (fun _ => b) (𝓟 {a})).coprod (map id (𝓟 {i})) =
𝓟 ((({b} : Set β) ×ˢ univ) ∪ (univ ×ˢ ({i} : Set ι))) := by
simp only [map_principal, Filter.coprod, comap_principal, sup_principal, image_singleton,
image_id, prod_univ, univ_prod, id]
/-- Characterization of the `Filter.map` of the coproduct of two principal filters `𝓟 {a}` and
`𝓟 {i}`, under the `Prod.map` of two functions, respectively the constant function `fun a => b` and
the identity function. Together with the previous lemma,
`map_const_principal_coprod_map_id_principal`, this provides an example showing that the inequality
in the lemma `map_prod_map_coprod_le` can be strict. -/
theorem map_prod_map_const_id_principal_coprod_principal {α β ι : Type*} (a : α) (b : β) (i : ι) :
map (Prod.map (fun _ : α => b) id) ((𝓟 {a}).coprod (𝓟 {i})) =
𝓟 (({b} : Set β) ×ˢ (univ : Set ι)) := by
rw [principal_coprod_principal, map_principal]
congr
ext ⟨b', i'⟩
constructor
· rintro ⟨⟨a'', i''⟩, _, h₂, h₃⟩
simp
· rintro ⟨h₁, _⟩
use (a, i')
simpa using h₁.symm
theorem Tendsto.prod_map_coprod {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β}
{c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) :
Tendsto (Prod.map f g) (a.coprod b) (c.coprod d) :=
map_prod_map_coprod_le.trans (coprod_mono hf hg)
end Coprod
end Filter
|
Order\Filter\Ring.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Order.Filter.Germ.OrderedMonoid
import Mathlib.Algebra.Order.Ring.Defs
/-!
# Lemmas about filters and ordered rings.
-/
namespace Filter
open Function Filter
universe u v
variable {α : Type u} {β : Type v}
theorem EventuallyLE.mul_le_mul [MulZeroClass β] [PartialOrder β] [PosMulMono β] [MulPosMono β]
{l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) (hg₀ : 0 ≤ᶠ[l] g₁)
(hf₀ : 0 ≤ᶠ[l] f₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg, hg₀, hf₀] with x using _root_.mul_le_mul
@[to_additive EventuallyLE.add_le_add]
theorem EventuallyLE.mul_le_mul' [Mul β] [Preorder β] [CovariantClass β β (· * ·) (· ≤ ·)]
[CovariantClass β β (swap (· * ·)) (· ≤ ·)] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β}
(hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx
theorem EventuallyLE.mul_nonneg [OrderedSemiring β] {l : Filter α} {f g : α → β} (hf : 0 ≤ᶠ[l] f)
(hg : 0 ≤ᶠ[l] g) : 0 ≤ᶠ[l] f * g := by filter_upwards [hf, hg] with x using _root_.mul_nonneg
theorem eventually_sub_nonneg [OrderedRing β] {l : Filter α} {f g : α → β} :
0 ≤ᶠ[l] g - f ↔ f ≤ᶠ[l] g :=
eventually_congr <| eventually_of_forall fun _ => sub_nonneg
namespace Germ
variable {l : Filter α}
@[to_additive]
instance instOrderedCommGroup [OrderedCommGroup β] : OrderedCommGroup (Germ l β) where
__ := instOrderedCancelCommMonoid
__ := instCommGroup
instance instOrderedSemiring [OrderedSemiring β] : OrderedSemiring (Germ l β) where
__ := instSemiring
__ := instOrderedAddCommMonoid
zero_le_one := const_le zero_le_one
mul_le_mul_of_nonneg_left x y z := inductionOn₃ x y z fun _f _g _h hfg hh ↦ hh.mp <| hfg.mono
fun _a ↦ mul_le_mul_of_nonneg_left
mul_le_mul_of_nonneg_right x y z := inductionOn₃ x y z fun _f _g _h hfg hh ↦ hh.mp <| hfg.mono
fun _a ↦ mul_le_mul_of_nonneg_right
instance instOrderedCommSemiring [OrderedCommSemiring β] : OrderedCommSemiring (Germ l β) where
__ := instOrderedSemiring
__ := instCommSemiring
instance instOrderedRing [OrderedRing β] : OrderedRing (Germ l β) where
__ := instRing
__ := instOrderedAddCommGroup
__ := instOrderedSemiring
mul_nonneg x y := inductionOn₂ x y fun _f _g hf hg ↦ hg.mp <| hf.mono fun _a ↦ mul_nonneg
instance instOrderedCommRing [OrderedCommRing β] : OrderedCommRing (Germ l β) where
__ := instOrderedRing
__ := instOrderedCommSemiring
end Germ
end Filter
|
Order\Filter\SmallSets.lean | /-
Copyright (c) 2022 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Order.Filter.Lift
import Mathlib.Order.Filter.AtTopBot
/-!
# The filter of small sets
This file defines the filter of small sets w.r.t. a filter `f`, which is the largest filter
containing all powersets of members of `f`.
`g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`.
An example usage is that if `f : ι → E → ℝ` is a family of nonnegative functions with integral 1,
then saying that `fun i ↦ support (f i)` tendsto `(𝓝 0).smallSets` is a way of saying that
`f` tends to the Dirac delta distribution.
-/
open Filter
open Filter Set
variable {α β : Type*} {ι : Sort*}
namespace Filter
variable {l l' la : Filter α} {lb : Filter β}
/-- The filter `l.smallSets` is the largest filter containing all powersets of members of `l`. -/
def smallSets (l : Filter α) : Filter (Set α) :=
l.lift' powerset
theorem smallSets_eq_generate {f : Filter α} : f.smallSets = generate (powerset '' f.sets) := by
simp_rw [generate_eq_biInf, smallSets, iInf_image, Filter.lift', Filter.lift, Function.comp_apply,
Filter.mem_sets]
-- TODO: get more properties from the adjunction?
-- TODO: is there a general way to get a lower adjoint for the lift of an upper adjoint?
theorem bind_smallSets_gc :
GaloisConnection (fun L : Filter (Set α) ↦ L.bind principal) smallSets := by
intro L l
simp_rw [smallSets_eq_generate, le_generate_iff, image_subset_iff]
rfl
protected theorem HasBasis.smallSets {p : ι → Prop} {s : ι → Set α} (h : HasBasis l p s) :
HasBasis l.smallSets p fun i => 𝒫 s i :=
h.lift' monotone_powerset
theorem hasBasis_smallSets (l : Filter α) :
HasBasis l.smallSets (fun t : Set α => t ∈ l) powerset :=
l.basis_sets.smallSets
/-- `g` converges to `f.smallSets` if for all `s ∈ f`, eventually we have `g x ⊆ s`. -/
theorem tendsto_smallSets_iff {f : α → Set β} :
Tendsto f la lb.smallSets ↔ ∀ t ∈ lb, ∀ᶠ x in la, f x ⊆ t :=
(hasBasis_smallSets lb).tendsto_right_iff
theorem eventually_smallSets {p : Set α → Prop} :
(∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, ∀ t, t ⊆ s → p t :=
eventually_lift'_iff monotone_powerset
theorem eventually_smallSets' {p : Set α → Prop} (hp : ∀ ⦃s t⦄, s ⊆ t → p t → p s) :
(∀ᶠ s in l.smallSets, p s) ↔ ∃ s ∈ l, p s :=
eventually_smallSets.trans <|
exists_congr fun s => Iff.rfl.and ⟨fun H => H s Subset.rfl, fun hs _t ht => hp ht hs⟩
theorem frequently_smallSets {p : Set α → Prop} :
(∃ᶠ s in l.smallSets, p s) ↔ ∀ t ∈ l, ∃ s, s ⊆ t ∧ p s :=
l.hasBasis_smallSets.frequently_iff
theorem frequently_smallSets_mem (l : Filter α) : ∃ᶠ s in l.smallSets, s ∈ l :=
frequently_smallSets.2 fun t ht => ⟨t, Subset.rfl, ht⟩
@[simp]
lemma tendsto_image_smallSets {f : α → β} :
Tendsto (f '' ·) la.smallSets lb.smallSets ↔ Tendsto f la lb := by
rw [tendsto_smallSets_iff]
refine forall₂_congr fun u hu ↦ ?_
rw [eventually_smallSets' fun s t hst ht ↦ (image_subset _ hst).trans ht]
simp only [image_subset_iff, exists_mem_subset_iff, mem_map]
alias ⟨_, Tendsto.image_smallSets⟩ := tendsto_image_smallSets
theorem HasAntitoneBasis.tendsto_smallSets {ι} [Preorder ι] {s : ι → Set α}
(hl : l.HasAntitoneBasis s) : Tendsto s atTop l.smallSets :=
tendsto_smallSets_iff.2 fun _t ht => hl.eventually_subset ht
@[mono]
theorem monotone_smallSets : Monotone (@smallSets α) :=
monotone_lift' monotone_id monotone_const
@[simp]
theorem smallSets_bot : (⊥ : Filter α).smallSets = pure ∅ := by
rw [smallSets, lift'_bot, powerset_empty, principal_singleton]
exact monotone_powerset
@[simp]
theorem smallSets_top : (⊤ : Filter α).smallSets = ⊤ := by
rw [smallSets, lift'_top, powerset_univ, principal_univ]
@[simp]
theorem smallSets_principal (s : Set α) : (𝓟 s).smallSets = 𝓟 (𝒫 s) :=
lift'_principal monotone_powerset
theorem smallSets_comap_eq_comap_image (l : Filter β) (f : α → β) :
(comap f l).smallSets = comap (image f) l.smallSets := by
refine (gc_map_comap _).u_comm_of_l_comm (gc_map_comap _) bind_smallSets_gc bind_smallSets_gc ?_
simp [Function.comp, map_bind, bind_map]
theorem smallSets_comap (l : Filter β) (f : α → β) :
(comap f l).smallSets = l.lift' (powerset ∘ preimage f) :=
comap_lift'_eq2 monotone_powerset
theorem comap_smallSets (l : Filter β) (f : α → Set β) :
comap f l.smallSets = l.lift' (preimage f ∘ powerset) :=
comap_lift'_eq
theorem smallSets_iInf {f : ι → Filter α} : (iInf f).smallSets = ⨅ i, (f i).smallSets :=
lift'_iInf_of_map_univ (powerset_inter _ _) powerset_univ
theorem smallSets_inf (l₁ l₂ : Filter α) : (l₁ ⊓ l₂).smallSets = l₁.smallSets ⊓ l₂.smallSets :=
lift'_inf _ _ powerset_inter
instance smallSets_neBot (l : Filter α) : NeBot l.smallSets := by
refine (lift'_neBot_iff ?_).2 fun _ _ => powerset_nonempty
exact monotone_powerset
theorem Tendsto.smallSets_mono {s t : α → Set β} (ht : Tendsto t la lb.smallSets)
(hst : ∀ᶠ x in la, s x ⊆ t x) : Tendsto s la lb.smallSets := by
rw [tendsto_smallSets_iff] at ht ⊢
exact fun u hu => (ht u hu).mp (hst.mono fun _ hst ht => hst.trans ht)
/-- Generalized **squeeze theorem** (also known as **sandwich theorem**). If `s : α → Set β` is a
family of sets that tends to `Filter.smallSets lb` along `la` and `f : α → β` is a function such
that `f x ∈ s x` eventually along `la`, then `f` tends to `lb` along `la`.
If `s x` is the closed interval `[g x, h x]` for some functions `g`, `h` that tend to the same limit
`𝓝 y`, then we obtain the standard squeeze theorem, see
`tendsto_of_tendsto_of_tendsto_of_le_of_le'`. -/
theorem Tendsto.of_smallSets {s : α → Set β} {f : α → β} (hs : Tendsto s la lb.smallSets)
(hf : ∀ᶠ x in la, f x ∈ s x) : Tendsto f la lb := fun t ht =>
hf.mp <| (tendsto_smallSets_iff.mp hs t ht).mono fun _ h₁ h₂ => h₁ h₂
@[simp]
theorem eventually_smallSets_eventually {p : α → Prop} :
(∀ᶠ s in l.smallSets, ∀ᶠ x in l', x ∈ s → p x) ↔ ∀ᶠ x in l ⊓ l', p x :=
calc
_ ↔ ∃ s ∈ l, ∀ᶠ x in l', x ∈ s → p x :=
eventually_smallSets' fun s t hst ht => ht.mono fun x hx hs => hx (hst hs)
_ ↔ ∃ s ∈ l, ∃ t ∈ l', ∀ x, x ∈ t → x ∈ s → p x := by simp only [eventually_iff_exists_mem]
_ ↔ ∀ᶠ x in l ⊓ l', p x := by simp only [eventually_inf, and_comm, mem_inter_iff, ← and_imp]
@[simp]
theorem eventually_smallSets_forall {p : α → Prop} :
(∀ᶠ s in l.smallSets, ∀ x ∈ s, p x) ↔ ∀ᶠ x in l, p x := by
simpa only [inf_top_eq, eventually_top] using @eventually_smallSets_eventually α l ⊤ p
alias ⟨Eventually.of_smallSets, Eventually.smallSets⟩ := eventually_smallSets_forall
@[simp]
theorem eventually_smallSets_subset {s : Set α} : (∀ᶠ t in l.smallSets, t ⊆ s) ↔ s ∈ l :=
eventually_smallSets_forall
end Filter
|
Order\Filter\Subsingleton.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Filter.Bases
import Mathlib.Order.Filter.Ultrafilter
/-!
# Subsingleton filters
We say that a filter `l` is a *subsingleton* if there exists a subsingleton set `s ∈ l`.
Equivalently, `l` is either `⊥` or `pure a` for some `a`.
-/
open Set
variable {α β : Type*} {l : Filter α}
namespace Filter
/-- We say that a filter is a *subsingleton* if there exists a subsingleton set
that belongs to the filter. -/
protected def Subsingleton (l : Filter α) : Prop := ∃ s ∈ l, Set.Subsingleton s
theorem HasBasis.subsingleton_iff {ι : Sort*} {p : ι → Prop} {s : ι → Set α} (h : l.HasBasis p s) :
l.Subsingleton ↔ ∃ i, p i ∧ (s i).Subsingleton :=
h.exists_iff fun _ _ hsub h ↦ h.anti hsub
theorem Subsingleton.anti {l'} (hl : l.Subsingleton) (hl' : l' ≤ l) : l'.Subsingleton :=
let ⟨s, hsl, hs⟩ := hl; ⟨s, hl' hsl, hs⟩
@[nontriviality]
theorem Subsingleton.of_subsingleton [Subsingleton α] : l.Subsingleton :=
⟨univ, univ_mem, subsingleton_univ⟩
theorem Subsingleton.map (hl : l.Subsingleton) (f : α → β) : (map f l).Subsingleton :=
let ⟨s, hsl, hs⟩ := hl; ⟨f '' s, image_mem_map hsl, hs.image f⟩
theorem Subsingleton.prod (hl : l.Subsingleton) {l' : Filter β} (hl' : l'.Subsingleton) :
(l ×ˢ l').Subsingleton :=
let ⟨s, hsl, hs⟩ := hl; let ⟨t, htl', ht⟩ := hl'; ⟨s ×ˢ t, prod_mem_prod hsl htl', hs.prod ht⟩
@[simp]
theorem subsingleton_pure {a : α} : Filter.Subsingleton (pure a) :=
⟨{a}, rfl, subsingleton_singleton⟩
@[simp]
theorem subsingleton_bot : Filter.Subsingleton (⊥ : Filter α) :=
⟨∅, trivial, subsingleton_empty⟩
/-- A nontrivial subsingleton filter is equal to `pure a` for some `a`. -/
theorem Subsingleton.exists_eq_pure [l.NeBot] (hl : l.Subsingleton) : ∃ a, l = pure a := by
rcases hl with ⟨s, hsl, hs⟩
rcases exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨nonempty_of_mem hsl, hs⟩ with ⟨a, rfl⟩
refine ⟨a, (NeBot.le_pure_iff ‹_›).1 ?_⟩
rwa [le_pure_iff]
/-- A filter is a subsingleton iff it is equal to `⊥` or to `pure a` for some `a`. -/
theorem subsingleton_iff_bot_or_pure : l.Subsingleton ↔ l = ⊥ ∨ ∃ a, l = pure a := by
refine ⟨fun hl ↦ ?_, ?_⟩
· exact (eq_or_neBot l).imp_right (@Subsingleton.exists_eq_pure _ _ · hl)
· rintro (rfl | ⟨a, rfl⟩) <;> simp
/-- In a nonempty type, a filter is a subsingleton iff
it is less than or equal to a pure filter. -/
theorem subsingleton_iff_exists_le_pure [Nonempty α] : l.Subsingleton ↔ ∃ a, l ≤ pure a := by
rcases eq_or_neBot l with rfl | hbot
· simp
· simp [subsingleton_iff_bot_or_pure, ← hbot.le_pure_iff, hbot.ne]
theorem subsingleton_iff_exists_singleton_mem [Nonempty α] : l.Subsingleton ↔ ∃ a, {a} ∈ l := by
simp only [subsingleton_iff_exists_le_pure, le_pure_iff]
/-- A subsingleton filter on a nonempty type is less than or equal to `pure a` for some `a`. -/
alias ⟨Subsingleton.exists_le_pure, _⟩ := subsingleton_iff_exists_le_pure
lemma Subsingleton.isCountablyGenerated (hl : l.Subsingleton) : IsCountablyGenerated l := by
rcases subsingleton_iff_bot_or_pure.1 hl with rfl|⟨x, rfl⟩
· exact isCountablyGenerated_bot
· exact isCountablyGenerated_pure x
end Filter
|
Order\Filter\Ultrafilter.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov
-/
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.ZornAtoms
/-!
# Ultrafilters
An ultrafilter is a minimal (maximal in the set order) proper filter.
In this file we define
* `Ultrafilter.of`: an ultrafilter that is less than or equal to a given filter;
* `Ultrafilter`: subtype of ultrafilters;
* `pure x : Ultrafilter α`: `pure x` as an `Ultrafilter`;
* `Ultrafilter.map`, `Ultrafilter.bind`, `Ultrafilter.comap` : operations on ultrafilters;
* `hyperfilter`: the ultrafilter extending the cofinite filter.
-/
universe u v
variable {α : Type u} {β : Type v} {γ : Type*}
open Set Filter Function
open scoped Classical
open Filter
/-- `Filter α` is an atomic type: for every filter there exists an ultrafilter that is less than or
equal to this filter. -/
instance : IsAtomic (Filter α) :=
IsAtomic.of_isChain_bounded fun c hc hne hb =>
⟨sInf c, (sInf_neBot_of_directed' hne (show IsChain (· ≥ ·) c from hc.symm).directedOn hb).ne,
fun _ hx => sInf_le hx⟩
/-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/
structure Ultrafilter (α : Type*) extends Filter α where
/-- An ultrafilter is nontrivial. -/
protected neBot' : NeBot toFilter
/-- If `g` is a nontrivial filter that is less than or equal to an ultrafilter, then it is greater
than or equal to the ultrafilter. -/
protected le_of_le : ∀ g, Filter.NeBot g → g ≤ toFilter → toFilter ≤ g
namespace Ultrafilter
variable {f g : Ultrafilter α} {s t : Set α} {p q : α → Prop}
attribute [coe] Ultrafilter.toFilter
instance : CoeTC (Ultrafilter α) (Filter α) :=
⟨Ultrafilter.toFilter⟩
instance : Membership (Set α) (Ultrafilter α) :=
⟨fun s f => s ∈ (f : Filter α)⟩
theorem unique (f : Ultrafilter α) {g : Filter α} (h : g ≤ f) (hne : NeBot g := by infer_instance) :
g = f :=
le_antisymm h <| f.le_of_le g hne h
instance neBot (f : Ultrafilter α) : NeBot (f : Filter α) :=
f.neBot'
protected theorem isAtom (f : Ultrafilter α) : IsAtom (f : Filter α) :=
⟨f.neBot.ne, fun _ hgf => by_contra fun hg => hgf.ne <| f.unique hgf.le ⟨hg⟩⟩
@[simp, norm_cast]
theorem mem_coe : s ∈ (f : Filter α) ↔ s ∈ f :=
Iff.rfl
theorem coe_injective : Injective ((↑) : Ultrafilter α → Filter α)
| ⟨f, h₁, h₂⟩, ⟨g, _, _⟩, _ => by congr
theorem eq_of_le {f g : Ultrafilter α} (h : (f : Filter α) ≤ g) : f = g :=
coe_injective (g.unique h)
@[simp, norm_cast]
theorem coe_le_coe {f g : Ultrafilter α} : (f : Filter α) ≤ g ↔ f = g :=
⟨fun h => eq_of_le h, fun h => h ▸ le_rfl⟩
@[simp, norm_cast]
theorem coe_inj : (f : Filter α) = g ↔ f = g :=
coe_injective.eq_iff
@[ext]
theorem ext ⦃f g : Ultrafilter α⦄ (h : ∀ s, s ∈ f ↔ s ∈ g) : f = g :=
coe_injective <| Filter.ext h
theorem le_of_inf_neBot (f : Ultrafilter α) {g : Filter α} (hg : NeBot (↑f ⊓ g)) : ↑f ≤ g :=
le_of_inf_eq (f.unique inf_le_left hg)
theorem le_of_inf_neBot' (f : Ultrafilter α) {g : Filter α} (hg : NeBot (g ⊓ f)) : ↑f ≤ g :=
f.le_of_inf_neBot <| by rwa [inf_comm]
theorem inf_neBot_iff {f : Ultrafilter α} {g : Filter α} : NeBot (↑f ⊓ g) ↔ ↑f ≤ g :=
⟨le_of_inf_neBot f, fun h => (inf_of_le_left h).symm ▸ f.neBot⟩
theorem disjoint_iff_not_le {f : Ultrafilter α} {g : Filter α} : Disjoint (↑f) g ↔ ¬↑f ≤ g := by
rw [← inf_neBot_iff, neBot_iff, Ne, not_not, disjoint_iff]
@[simp]
theorem compl_not_mem_iff : sᶜ ∉ f ↔ s ∈ f :=
⟨fun hsc =>
le_principal_iff.1 <|
f.le_of_inf_neBot ⟨fun h => hsc <| mem_of_eq_bot <| by rwa [compl_compl]⟩,
compl_not_mem⟩
@[simp]
theorem frequently_iff_eventually : (∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, p x :=
compl_not_mem_iff
alias ⟨_root_.Filter.Frequently.eventually, _⟩ := frequently_iff_eventually
theorem compl_mem_iff_not_mem : sᶜ ∈ f ↔ s ∉ f := by rw [← compl_not_mem_iff, compl_compl]
theorem diff_mem_iff (f : Ultrafilter α) : s \ t ∈ f ↔ s ∈ f ∧ t ∉ f :=
inter_mem_iff.trans <| and_congr Iff.rfl compl_mem_iff_not_mem
/-- If `sᶜ ∉ f ↔ s ∈ f`, then `f` is an ultrafilter. The other implication is given by
`Ultrafilter.compl_not_mem_iff`. -/
def ofComplNotMemIff (f : Filter α) (h : ∀ s, sᶜ ∉ f ↔ s ∈ f) : Ultrafilter α where
toFilter := f
neBot' := ⟨fun hf => by simp [hf] at h⟩
le_of_le g hg hgf s hs := (h s).1 fun hsc => compl_not_mem hs (hgf hsc)
/-- If `f : Filter α` is an atom, then it is an ultrafilter. -/
def ofAtom (f : Filter α) (hf : IsAtom f) : Ultrafilter α where
toFilter := f
neBot' := ⟨hf.1⟩
le_of_le g hg := (isAtom_iff_le_of_ge.1 hf).2 g hg.ne
theorem nonempty_of_mem (hs : s ∈ f) : s.Nonempty :=
Filter.nonempty_of_mem hs
theorem ne_empty_of_mem (hs : s ∈ f) : s ≠ ∅ :=
(nonempty_of_mem hs).ne_empty
@[simp]
theorem empty_not_mem : ∅ ∉ f :=
Filter.empty_not_mem (f : Filter α)
@[simp]
theorem le_sup_iff {u : Ultrafilter α} {f g : Filter α} : ↑u ≤ f ⊔ g ↔ ↑u ≤ f ∨ ↑u ≤ g :=
not_iff_not.1 <| by simp only [← disjoint_iff_not_le, not_or, disjoint_sup_right]
@[simp]
theorem union_mem_iff : s ∪ t ∈ f ↔ s ∈ f ∨ t ∈ f := by
simp only [← mem_coe, ← le_principal_iff, ← sup_principal, le_sup_iff]
theorem mem_or_compl_mem (f : Ultrafilter α) (s : Set α) : s ∈ f ∨ sᶜ ∈ f :=
or_iff_not_imp_left.2 compl_mem_iff_not_mem.2
protected theorem em (f : Ultrafilter α) (p : α → Prop) : (∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, ¬p x :=
f.mem_or_compl_mem { x | p x }
theorem eventually_or : (∀ᶠ x in f, p x ∨ q x) ↔ (∀ᶠ x in f, p x) ∨ ∀ᶠ x in f, q x :=
union_mem_iff
theorem eventually_not : (∀ᶠ x in f, ¬p x) ↔ ¬∀ᶠ x in f, p x :=
compl_mem_iff_not_mem
theorem eventually_imp : (∀ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∀ᶠ x in f, q x := by
simp only [imp_iff_not_or, eventually_or, eventually_not]
theorem finite_sUnion_mem_iff {s : Set (Set α)} (hs : s.Finite) : ⋃₀ s ∈ f ↔ ∃ t ∈ s, t ∈ f :=
Finite.induction_on hs (by simp) fun _ _ his => by
simp [union_mem_iff, his, or_and_right, exists_or]
theorem finite_biUnion_mem_iff {is : Set β} {s : β → Set α} (his : is.Finite) :
(⋃ i ∈ is, s i) ∈ f ↔ ∃ i ∈ is, s i ∈ f := by
simp only [← sUnion_image, finite_sUnion_mem_iff (his.image s), exists_mem_image]
/-- Pushforward for ultrafilters. -/
nonrec def map (m : α → β) (f : Ultrafilter α) : Ultrafilter β :=
ofComplNotMemIff (map m f) fun s => @compl_not_mem_iff _ f (m ⁻¹' s)
@[simp, norm_cast]
theorem coe_map (m : α → β) (f : Ultrafilter α) : (map m f : Filter β) = Filter.map m ↑f :=
rfl
@[simp]
theorem mem_map {m : α → β} {f : Ultrafilter α} {s : Set β} : s ∈ map m f ↔ m ⁻¹' s ∈ f :=
Iff.rfl
@[simp]
nonrec theorem map_id (f : Ultrafilter α) : f.map id = f :=
coe_injective map_id
@[simp]
theorem map_id' (f : Ultrafilter α) : (f.map fun x => x) = f :=
map_id _
@[simp]
nonrec theorem map_map (f : Ultrafilter α) (m : α → β) (n : β → γ) :
(f.map m).map n = f.map (n ∘ m) :=
coe_injective map_map
/-- The pullback of an ultrafilter along an injection whose range is large with respect to the given
ultrafilter. -/
nonrec def comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u) :
Ultrafilter α where
toFilter := comap m u
neBot' := u.neBot'.comap_of_range_mem large
le_of_le g hg hgu := by
simp only [← u.unique (map_le_iff_le_comap.2 hgu), comap_map inj, le_rfl]
@[simp]
theorem mem_comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u)
{s : Set α} : s ∈ u.comap inj large ↔ m '' s ∈ u :=
mem_comap_iff inj large
@[simp, norm_cast]
theorem coe_comap {m : α → β} (u : Ultrafilter β) (inj : Injective m) (large : Set.range m ∈ u) :
(u.comap inj large : Filter α) = Filter.comap m u :=
rfl
@[simp]
nonrec theorem comap_id (f : Ultrafilter α) (h₀ : Injective (id : α → α) := injective_id)
(h₁ : range id ∈ f := (by rw [range_id]; exact univ_mem)) :
f.comap h₀ h₁ = f :=
coe_injective comap_id
@[simp]
nonrec theorem comap_comap (f : Ultrafilter γ) {m : α → β} {n : β → γ} (inj₀ : Injective n)
(large₀ : range n ∈ f) (inj₁ : Injective m) (large₁ : range m ∈ f.comap inj₀ large₀)
(inj₂ : Injective (n ∘ m) := inj₀.comp inj₁)
(large₂ : range (n ∘ m) ∈ f :=
(by rw [range_comp]; exact image_mem_of_mem_comap large₀ large₁)) :
(f.comap inj₀ large₀).comap inj₁ large₁ = f.comap inj₂ large₂ :=
coe_injective comap_comap
/-- The principal ultrafilter associated to a point `x`. -/
instance : Pure Ultrafilter :=
⟨fun a => ofComplNotMemIff (pure a) fun s => by simp⟩
@[simp]
theorem mem_pure {a : α} {s : Set α} : s ∈ (pure a : Ultrafilter α) ↔ a ∈ s :=
Iff.rfl
@[simp]
theorem coe_pure (a : α) : ↑(pure a : Ultrafilter α) = (pure a : Filter α) :=
rfl
@[simp]
theorem map_pure (m : α → β) (a : α) : map m (pure a) = pure (m a) :=
rfl
@[simp]
theorem comap_pure {m : α → β} (a : α) (inj : Injective m) (large) :
comap (pure <| m a) inj large = pure a :=
coe_injective <|
Filter.comap_pure.trans <| by
rw [coe_pure, ← principal_singleton, ← image_singleton, preimage_image_eq _ inj]
theorem pure_injective : Injective (pure : α → Ultrafilter α) := fun _ _ h =>
Filter.pure_injective (congr_arg Ultrafilter.toFilter h : _)
instance [Inhabited α] : Inhabited (Ultrafilter α) :=
⟨pure default⟩
instance [Nonempty α] : Nonempty (Ultrafilter α) :=
Nonempty.map pure inferInstance
theorem eq_pure_of_finite_mem (h : s.Finite) (h' : s ∈ f) : ∃ x ∈ s, f = pure x := by
rw [← biUnion_of_singleton s] at h'
rcases (Ultrafilter.finite_biUnion_mem_iff h).mp h' with ⟨a, has, haf⟩
exact ⟨a, has, eq_of_le (Filter.le_pure_iff.2 haf)⟩
theorem eq_pure_of_finite [Finite α] (f : Ultrafilter α) : ∃ a, f = pure a :=
(eq_pure_of_finite_mem finite_univ univ_mem).imp fun _ ⟨_, ha⟩ => ha
theorem le_cofinite_or_eq_pure (f : Ultrafilter α) : (f : Filter α) ≤ cofinite ∨ ∃ a, f = pure a :=
or_iff_not_imp_left.2 fun h =>
let ⟨_, hs, hfin⟩ := Filter.disjoint_cofinite_right.1 (disjoint_iff_not_le.2 h)
let ⟨a, _, hf⟩ := eq_pure_of_finite_mem hfin hs
⟨a, hf⟩
/-- Monadic bind for ultrafilters, coming from the one on filters
defined in terms of map and join. -/
def bind (f : Ultrafilter α) (m : α → Ultrafilter β) : Ultrafilter β :=
ofComplNotMemIff (Filter.bind ↑f fun x => ↑(m x)) fun s => by
simp only [mem_bind', mem_coe, ← compl_mem_iff_not_mem, compl_setOf, compl_compl]
instance instBind : Bind Ultrafilter :=
⟨@Ultrafilter.bind⟩
instance functor : Functor Ultrafilter where map := @Ultrafilter.map
instance monad : Monad Ultrafilter where map := @Ultrafilter.map
section
attribute [local instance] Filter.monad Filter.lawfulMonad
instance lawfulMonad : LawfulMonad Ultrafilter where
id_map f := coe_injective (id_map f.toFilter)
pure_bind a f := coe_injective (Filter.pure_bind a ((Ultrafilter.toFilter) ∘ f))
bind_assoc _ _ _ := coe_injective (filter_eq rfl)
bind_pure_comp f x := coe_injective (bind_pure_comp f x.1)
map_const := rfl
seqLeft_eq _ _ := rfl
seqRight_eq _ _ := rfl
pure_seq _ _ := rfl
bind_map _ _ := rfl
end
/-- The ultrafilter lemma: Any proper filter is contained in an ultrafilter. -/
theorem exists_le (f : Filter α) [h : NeBot f] : ∃ u : Ultrafilter α, ↑u ≤ f :=
let ⟨u, hu, huf⟩ := (eq_bot_or_exists_atom_le f).resolve_left h.ne
⟨ofAtom u hu, huf⟩
alias _root_.Filter.exists_ultrafilter_le := exists_le
/-- Construct an ultrafilter extending a given filter.
The ultrafilter lemma is the assertion that such a filter exists;
we use the axiom of choice to pick one. -/
noncomputable def of (f : Filter α) [NeBot f] : Ultrafilter α :=
Classical.choose (exists_le f)
theorem of_le (f : Filter α) [NeBot f] : ↑(of f) ≤ f :=
Classical.choose_spec (exists_le f)
theorem of_coe (f : Ultrafilter α) : of ↑f = f :=
coe_inj.1 <| f.unique (of_le f.toFilter)
theorem exists_ultrafilter_of_finite_inter_nonempty (S : Set (Set α))
(cond : ∀ T : Finset (Set α), (↑T : Set (Set α)) ⊆ S → (⋂₀ (↑T : Set (Set α))).Nonempty) :
∃ F : Ultrafilter α, S ⊆ F.sets :=
haveI : NeBot (generate S) :=
generate_neBot_iff.2 fun _ hts ht =>
ht.coe_toFinset ▸ cond ht.toFinset (ht.coe_toFinset.symm ▸ hts)
⟨of (generate S), fun _ ht => (of_le <| generate S) <| GenerateSets.basic ht⟩
end Ultrafilter
namespace Filter
variable {f : Filter α} {s : Set α} {a : α}
open Ultrafilter
theorem isAtom_pure : IsAtom (pure a : Filter α) :=
(pure a : Ultrafilter α).isAtom
protected theorem NeBot.le_pure_iff (hf : f.NeBot) : f ≤ pure a ↔ f = pure a :=
⟨Ultrafilter.unique (pure a), le_of_eq⟩
protected theorem NeBot.eq_pure_iff (hf : f.NeBot) {x : α} :
f = pure x ↔ {x} ∈ f := by
rw [← hf.le_pure_iff, le_pure_iff]
lemma atTop_eq_pure_of_isTop [LinearOrder α] {x : α} (hx : IsTop x) :
(atTop : Filter α) = pure x := by
have : Nonempty α := ⟨x⟩
apply atTop_neBot.eq_pure_iff.2
convert Ici_mem_atTop x using 1
exact (Ici_eq_singleton_iff_isTop.2 hx).symm
lemma atBot_eq_pure_of_isBot [LinearOrder α] {x : α} (hx : IsBot x) :
(atBot : Filter α) = pure x :=
@atTop_eq_pure_of_isTop αᵒᵈ _ _ hx
@[simp]
theorem lt_pure_iff : f < pure a ↔ f = ⊥ :=
isAtom_pure.lt_iff
theorem le_pure_iff' : f ≤ pure a ↔ f = ⊥ ∨ f = pure a :=
isAtom_pure.le_iff
@[simp]
theorem Iic_pure (a : α) : Iic (pure a : Filter α) = {⊥, pure a} :=
isAtom_pure.Iic_eq
theorem mem_iff_ultrafilter : s ∈ f ↔ ∀ g : Ultrafilter α, ↑g ≤ f → s ∈ g := by
refine ⟨fun hf g hg => hg hf, fun H => by_contra fun hf => ?_⟩
set g : Filter (sᶜ : Set α) := comap (↑) f
haveI : NeBot g := comap_neBot_iff_compl_range.2 (by simpa [compl_setOf] )
simpa using H ((of g).map (↑)) (map_le_iff_le_comap.mpr (of_le g))
theorem le_iff_ultrafilter {f₁ f₂ : Filter α} : f₁ ≤ f₂ ↔ ∀ g : Ultrafilter α, ↑g ≤ f₁ → ↑g ≤ f₂ :=
⟨fun h _ h₁ => h₁.trans h, fun h _ hs => mem_iff_ultrafilter.2 fun g hg => h g hg hs⟩
/-- A filter equals the intersection of all the ultrafilters which contain it. -/
theorem iSup_ultrafilter_le_eq (f : Filter α) :
⨆ (g : Ultrafilter α) (_ : g ≤ f), (g : Filter α) = f :=
eq_of_forall_ge_iff fun f' => by simp only [iSup_le_iff, ← le_iff_ultrafilter]
/-- The `tendsto` relation can be checked on ultrafilters. -/
theorem tendsto_iff_ultrafilter (f : α → β) (l₁ : Filter α) (l₂ : Filter β) :
Tendsto f l₁ l₂ ↔ ∀ g : Ultrafilter α, ↑g ≤ l₁ → Tendsto f g l₂ := by
simpa only [tendsto_iff_comap] using le_iff_ultrafilter
theorem exists_ultrafilter_iff {f : Filter α} : (∃ u : Ultrafilter α, ↑u ≤ f) ↔ NeBot f :=
⟨fun ⟨_, uf⟩ => neBot_of_le uf, fun h => @exists_ultrafilter_le _ _ h⟩
theorem forall_neBot_le_iff {g : Filter α} {p : Filter α → Prop} (hp : Monotone p) :
(∀ f : Filter α, NeBot f → f ≤ g → p f) ↔ ∀ f : Ultrafilter α, ↑f ≤ g → p f := by
refine ⟨fun H f hf => H f f.neBot hf, ?_⟩
intro H f hf hfg
exact hp (of_le f) (H _ ((of_le f).trans hfg))
section Hyperfilter
variable (α) [Infinite α]
/-- The ultrafilter extending the cofinite filter. -/
noncomputable def hyperfilter : Ultrafilter α :=
Ultrafilter.of cofinite
variable {α}
theorem hyperfilter_le_cofinite : ↑(hyperfilter α) ≤ @cofinite α :=
Ultrafilter.of_le cofinite
theorem _root_.Nat.hyperfilter_le_atTop : (hyperfilter ℕ).toFilter ≤ atTop :=
hyperfilter_le_cofinite.trans_eq Nat.cofinite_eq_atTop
@[simp]
theorem bot_ne_hyperfilter : (⊥ : Filter α) ≠ hyperfilter α :=
(NeBot.ne inferInstance).symm
theorem nmem_hyperfilter_of_finite {s : Set α} (hf : s.Finite) : s ∉ hyperfilter α := fun hy =>
compl_not_mem hy <| hyperfilter_le_cofinite hf.compl_mem_cofinite
alias _root_.Set.Finite.nmem_hyperfilter := nmem_hyperfilter_of_finite
theorem compl_mem_hyperfilter_of_finite {s : Set α} (hf : Set.Finite s) : sᶜ ∈ hyperfilter α :=
compl_mem_iff_not_mem.2 hf.nmem_hyperfilter
alias _root_.Set.Finite.compl_mem_hyperfilter := compl_mem_hyperfilter_of_finite
theorem mem_hyperfilter_of_finite_compl {s : Set α} (hf : Set.Finite sᶜ) : s ∈ hyperfilter α :=
compl_compl s ▸ hf.compl_mem_hyperfilter
end Hyperfilter
end Filter
namespace Ultrafilter
open Filter
variable {m : α → β} {s : Set α} {g : Ultrafilter β}
theorem comap_inf_principal_neBot_of_image_mem (h : m '' s ∈ g) : (Filter.comap m g ⊓ 𝓟 s).NeBot :=
Filter.comap_inf_principal_neBot_of_image_mem g.neBot h
/-- Ultrafilter extending the inf of a comapped ultrafilter and a principal ultrafilter. -/
noncomputable def ofComapInfPrincipal (h : m '' s ∈ g) : Ultrafilter α :=
@of _ (Filter.comap m g ⊓ 𝓟 s) (comap_inf_principal_neBot_of_image_mem h)
theorem ofComapInfPrincipal_mem (h : m '' s ∈ g) : s ∈ ofComapInfPrincipal h := by
let f := Filter.comap m g ⊓ 𝓟 s
haveI : f.NeBot := comap_inf_principal_neBot_of_image_mem h
have : s ∈ f := mem_inf_of_right (mem_principal_self s)
exact le_def.mp (of_le _) s this
theorem ofComapInfPrincipal_eq_of_map (h : m '' s ∈ g) : (ofComapInfPrincipal h).map m = g := by
let f := Filter.comap m g ⊓ 𝓟 s
haveI : f.NeBot := comap_inf_principal_neBot_of_image_mem h
apply eq_of_le
calc
Filter.map m (of f) ≤ Filter.map m f := map_mono (of_le _)
_ ≤ (Filter.map m <| Filter.comap m g) ⊓ Filter.map m (𝓟 s) := map_inf_le
_ = (Filter.map m <| Filter.comap m g) ⊓ (𝓟 <| m '' s) := by rw [map_principal]
_ ≤ ↑g ⊓ (𝓟 <| m '' s) := inf_le_inf_right _ map_comap_le
_ = ↑g := inf_of_le_left (le_principal_iff.mpr h)
end Ultrafilter
|
Order\Filter\ZeroAndBoundedAtFilter.lean | /-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck, David Loeffler
-/
import Mathlib.Algebra.Module.Submodule.Basic
import Mathlib.Topology.Algebra.Monoid
import Mathlib.Analysis.Asymptotics.Asymptotics
import Mathlib.Algebra.Algebra.Pi
/-!
# Zero and Bounded at filter
Given a filter `l` we define the notion of a function being `ZeroAtFilter` as well as being
`BoundedAtFilter`. Alongside this we construct the `Submodule`, `AddSubmonoid` of functions
that are `ZeroAtFilter`. Similarly, we construct the `Submodule` and `Subalgebra` of functions
that are `BoundedAtFilter`.
-/
namespace Filter
variable {𝕜 α β : Type*}
open Topology
/-- If `l` is a filter on `α`, then a function `f : α → β` is `ZeroAtFilter l`
if it tends to zero along `l`. -/
def ZeroAtFilter [Zero β] [TopologicalSpace β] (l : Filter α) (f : α → β) : Prop :=
Filter.Tendsto f l (𝓝 0)
theorem zero_zeroAtFilter [Zero β] [TopologicalSpace β] (l : Filter α) :
ZeroAtFilter l (0 : α → β) :=
tendsto_const_nhds
nonrec theorem ZeroAtFilter.add [TopologicalSpace β] [AddZeroClass β] [ContinuousAdd β]
{l : Filter α} {f g : α → β} (hf : ZeroAtFilter l f) (hg : ZeroAtFilter l g) :
ZeroAtFilter l (f + g) := by
simpa using hf.add hg
nonrec theorem ZeroAtFilter.neg [TopologicalSpace β] [AddGroup β] [ContinuousNeg β] {l : Filter α}
{f : α → β} (hf : ZeroAtFilter l f) : ZeroAtFilter l (-f) := by simpa using hf.neg
theorem ZeroAtFilter.smul [TopologicalSpace β] [Zero 𝕜] [Zero β]
[SMulWithZero 𝕜 β] [ContinuousConstSMul 𝕜 β] {l : Filter α} {f : α → β} (c : 𝕜)
(hf : ZeroAtFilter l f) : ZeroAtFilter l (c • f) := by simpa using hf.const_smul c
variable (𝕜) in
/-- `zeroAtFilterSubmodule l` is the submodule of `f : α → β` which
tend to zero along `l`. -/
def zeroAtFilterSubmodule
[TopologicalSpace β] [Semiring 𝕜] [AddCommMonoid β] [Module 𝕜 β]
[ContinuousAdd β] [ContinuousConstSMul 𝕜 β]
(l : Filter α) : Submodule 𝕜 (α → β) where
carrier := ZeroAtFilter l
zero_mem' := zero_zeroAtFilter l
add_mem' ha hb := ha.add hb
smul_mem' c _ hf := hf.smul c
/-- `zeroAtFilterAddSubmonoid l` is the additive submonoid of `f : α → β`
which tend to zero along `l`. -/
def zeroAtFilterAddSubmonoid [TopologicalSpace β] [AddZeroClass β] [ContinuousAdd β]
(l : Filter α) : AddSubmonoid (α → β) where
carrier := ZeroAtFilter l
add_mem' ha hb := ha.add hb
zero_mem' := zero_zeroAtFilter l
/-- If `l` is a filter on `α`, then a function `f: α → β` is `BoundedAtFilter l`
if `f =O[l] 1`. -/
def BoundedAtFilter [Norm β] (l : Filter α) (f : α → β) : Prop :=
Asymptotics.IsBigO l f (1 : α → ℝ)
theorem ZeroAtFilter.boundedAtFilter [NormedAddCommGroup β] {l : Filter α} {f : α → β}
(hf : ZeroAtFilter l f) : BoundedAtFilter l f := by
rw [ZeroAtFilter, ← Asymptotics.isLittleO_const_iff (one_ne_zero' ℝ)] at hf
exact hf.isBigO
theorem const_boundedAtFilter [Norm β] (l : Filter α) (c : β) :
BoundedAtFilter l (Function.const α c : α → β) :=
Asymptotics.isBigO_const_const c one_ne_zero l
nonrec theorem BoundedAtFilter.add [SeminormedAddCommGroup β] {l : Filter α} {f g : α → β}
(hf : BoundedAtFilter l f) (hg : BoundedAtFilter l g) : BoundedAtFilter l (f + g) := by
simpa using hf.add hg
theorem BoundedAtFilter.neg [SeminormedAddCommGroup β] {l : Filter α} {f : α → β}
(hf : BoundedAtFilter l f) : BoundedAtFilter l (-f) :=
hf.neg_left
theorem BoundedAtFilter.smul
[SeminormedRing 𝕜] [SeminormedAddCommGroup β] [Module 𝕜 β] [BoundedSMul 𝕜 β]
{l : Filter α} {f : α → β} (c : 𝕜) (hf : BoundedAtFilter l f) : BoundedAtFilter l (c • f) :=
hf.const_smul_left c
nonrec theorem BoundedAtFilter.mul [SeminormedRing β] {l : Filter α} {f g : α → β}
(hf : BoundedAtFilter l f) (hg : BoundedAtFilter l g) : BoundedAtFilter l (f * g) := by
refine (hf.mul hg).trans ?_
convert Asymptotics.isBigO_refl (E := ℝ) _ l
simp
variable (𝕜) in
/-- The submodule of functions that are bounded along a filter `l`. -/
def boundedFilterSubmodule
[SeminormedRing 𝕜] [SeminormedAddCommGroup β] [Module 𝕜 β] [BoundedSMul 𝕜 β] (l : Filter α) :
Submodule 𝕜 (α → β) where
carrier := BoundedAtFilter l
zero_mem' := const_boundedAtFilter l 0
add_mem' hf hg := hf.add hg
smul_mem' c _ hf := hf.smul c
variable (𝕜) in
/-- The subalgebra of functions that are bounded along a filter `l`. -/
def boundedFilterSubalgebra
[SeminormedCommRing 𝕜] [SeminormedRing β] [Algebra 𝕜 β] [BoundedSMul 𝕜 β] (l : Filter α) :
Subalgebra 𝕜 (α → β) :=
Submodule.toSubalgebra
(boundedFilterSubmodule 𝕜 l)
(const_boundedAtFilter l (1 : β))
(fun f g hf hg ↦ by simpa only [Pi.one_apply, mul_one, norm_mul] using hf.mul hg)
end Filter
|
Order\Filter\Germ\Basic.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Algebra.Module.Pi
/-!
# Germ of a function at a filter
The germ of a function `f : α → β` at a filter `l : Filter α` is the equivalence class of `f`
with respect to the equivalence relation `EventuallyEq l`: `f ≈ g` means `∀ᶠ x in l, f x = g x`.
## Main definitions
We define
* `Filter.Germ l β` to be the space of germs of functions `α → β` at a filter `l : Filter α`;
* coercion from `α → β` to `Germ l β`: `(f : Germ l β)` is the germ of `f : α → β`
at `l : Filter α`; this coercion is declared as `CoeTC`;
* `(const l c : Germ l β)` is the germ of the constant function `fun x : α ↦ c` at a filter `l`;
* coercion from `β` to `Germ l β`: `(↑c : Germ l β)` is the germ of the constant function
`fun x : α ↦ c` at a filter `l`; this coercion is declared as `CoeTC`;
* `map (F : β → γ) (f : Germ l β)` to be the composition of a function `F` and a germ `f`;
* `map₂ (F : β → γ → δ) (f : Germ l β) (g : Germ l γ)` to be the germ of `fun x ↦ F (f x) (g x)`
at `l`;
* `f.Tendsto lb`: we say that a germ `f : Germ l β` tends to a filter `lb` if its representatives
tend to `lb` along `l`;
* `f.compTendsto g hg` and `f.compTendsto' g hg`: given `f : Germ l β` and a function
`g : γ → α` (resp., a germ `g : Germ lc α`), if `g` tends to `l` along `lc`, then the composition
`f ∘ g` is a well-defined germ at `lc`;
* `Germ.liftPred`, `Germ.liftRel`: lift a predicate or a relation to the space of germs:
`(f : Germ l β).liftPred p` means `∀ᶠ x in l, p (f x)`, and similarly for a relation.
We also define `map (F : β → γ) : Germ l β → Germ l γ` sending each germ `f` to `F ∘ f`.
For each of the following structures we prove that if `β` has this structure, then so does
`Germ l β`:
* one-operation algebraic structures up to `CommGroup`;
* `MulZeroClass`, `Distrib`, `Semiring`, `CommSemiring`, `Ring`, `CommRing`;
* `MulAction`, `DistribMulAction`, `Module`;
* `Preorder`, `PartialOrder`, and `Lattice` structures, as well as `BoundedOrder`;
## Tags
filter, germ
-/
assert_not_exists OrderedSemiring
namespace Filter
variable {α β γ δ : Type*} {l : Filter α} {f g h : α → β}
theorem const_eventuallyEq' [NeBot l] {a b : β} : (∀ᶠ _ in l, a = b) ↔ a = b :=
eventually_const
theorem const_eventuallyEq [NeBot l] {a b : β} : ((fun _ => a) =ᶠ[l] fun _ => b) ↔ a = b :=
@const_eventuallyEq' _ _ _ _ a b
/-- Setoid used to define the space of germs. -/
def germSetoid (l : Filter α) (β : Type*) : Setoid (α → β) where
r := EventuallyEq l
iseqv := ⟨EventuallyEq.refl _, EventuallyEq.symm, EventuallyEq.trans⟩
/-- The space of germs of functions `α → β` at a filter `l`. -/
def Germ (l : Filter α) (β : Type*) : Type _ :=
Quotient (germSetoid l β)
/-- Setoid used to define the filter product. This is a dependent version of
`Filter.germSetoid`. -/
def productSetoid (l : Filter α) (ε : α → Type*) : Setoid ((a : _) → ε a) where
r f g := ∀ᶠ a in l, f a = g a
iseqv :=
⟨fun _ => eventually_of_forall fun _ => rfl, fun h => h.mono fun _ => Eq.symm,
fun h1 h2 => h1.congr (h2.mono fun _ hx => hx ▸ Iff.rfl)⟩
/-- The filter product `(a : α) → ε a` at a filter `l`. This is a dependent version of
`Filter.Germ`. -/
-- Porting note: removed @[protected]
def Product (l : Filter α) (ε : α → Type*) : Type _ :=
Quotient (productSetoid l ε)
namespace Product
variable {ε : α → Type*}
instance coeTC : CoeTC ((a : _) → ε a) (l.Product ε) :=
⟨@Quotient.mk' _ (productSetoid _ ε)⟩
instance instInhabited [(a : _) → Inhabited (ε a)] : Inhabited (l.Product ε) :=
⟨(↑fun a => (default : ε a) : l.Product ε)⟩
end Product
namespace Germ
-- Porting note: added
@[coe]
def ofFun : (α → β) → (Germ l β) := @Quotient.mk' _ (germSetoid _ _)
instance : CoeTC (α → β) (Germ l β) :=
⟨ofFun⟩
@[coe] -- Porting note: removed `HasLiftT` instance
def const {l : Filter α} (b : β) : (Germ l β) := ofFun fun _ => b
instance coeTC : CoeTC β (Germ l β) :=
⟨const⟩
/-- A germ `P` of functions `α → β` is constant w.r.t. `l`. -/
def IsConstant {l : Filter α} (P : Germ l β) : Prop :=
P.liftOn (fun f ↦ ∃ b : β, f =ᶠ[l] (fun _ ↦ b)) <| by
suffices ∀ f g : α → β, ∀ b : β, f =ᶠ[l] g → (f =ᶠ[l] fun _ ↦ b) → (g =ᶠ[l] fun _ ↦ b) from
fun f g h ↦ propext ⟨fun ⟨b, hb⟩ ↦ ⟨b, this f g b h hb⟩, fun ⟨b, hb⟩ ↦ ⟨b, h.trans hb⟩⟩
exact fun f g b hfg hf ↦ (hfg.symm).trans hf
theorem isConstant_coe {l : Filter α} {b} (h : ∀ x', f x' = b) : (↑f : Germ l β).IsConstant :=
⟨b, eventually_of_forall (fun x ↦ h x)⟩
@[simp]
theorem isConstant_coe_const {l : Filter α} {b : β} : (fun _ : α ↦ b : Germ l β).IsConstant := by
use b
/-- If `f : α → β` is constant w.r.t. `l` and `g : β → γ`, then `g ∘ f : α → γ` also is. -/
lemma isConstant_comp {l : Filter α} {f : α → β} {g : β → γ}
(h : (f : Germ l β).IsConstant) : ((g ∘ f) : Germ l γ).IsConstant := by
obtain ⟨b, hb⟩ := h
exact ⟨g b, hb.fun_comp g⟩
@[simp]
theorem quot_mk_eq_coe (l : Filter α) (f : α → β) : Quot.mk _ f = (f : Germ l β) :=
rfl
@[simp]
theorem mk'_eq_coe (l : Filter α) (f : α → β) :
@Quotient.mk' _ (germSetoid _ _) f = (f : Germ l β) :=
rfl
@[elab_as_elim]
theorem inductionOn (f : Germ l β) {p : Germ l β → Prop} (h : ∀ f : α → β, p f) : p f :=
Quotient.inductionOn' f h
@[elab_as_elim]
theorem inductionOn₂ (f : Germ l β) (g : Germ l γ) {p : Germ l β → Germ l γ → Prop}
(h : ∀ (f : α → β) (g : α → γ), p f g) : p f g :=
Quotient.inductionOn₂' f g h
@[elab_as_elim]
theorem inductionOn₃ (f : Germ l β) (g : Germ l γ) (h : Germ l δ)
{p : Germ l β → Germ l γ → Germ l δ → Prop}
(H : ∀ (f : α → β) (g : α → γ) (h : α → δ), p f g h) : p f g h :=
Quotient.inductionOn₃' f g h H
/-- Given a map `F : (α → β) → (γ → δ)` that sends functions eventually equal at `l` to functions
eventually equal at `lc`, returns a map from `Germ l β` to `Germ lc δ`. -/
def map' {lc : Filter γ} (F : (α → β) → γ → δ) (hF : (l.EventuallyEq ⇒ lc.EventuallyEq) F F) :
Germ l β → Germ lc δ :=
Quotient.map' F hF
/-- Given a germ `f : Germ l β` and a function `F : (α → β) → γ` sending eventually equal functions
to the same value, returns the value `F` takes on functions having germ `f` at `l`. -/
def liftOn {γ : Sort*} (f : Germ l β) (F : (α → β) → γ) (hF : (l.EventuallyEq ⇒ (· = ·)) F F) :
γ :=
Quotient.liftOn' f F hF
@[simp]
theorem map'_coe {lc : Filter γ} (F : (α → β) → γ → δ) (hF : (l.EventuallyEq ⇒ lc.EventuallyEq) F F)
(f : α → β) : map' F hF f = F f :=
rfl
@[simp, norm_cast]
theorem coe_eq : (f : Germ l β) = g ↔ f =ᶠ[l] g :=
Quotient.eq''
alias ⟨_, _root_.Filter.EventuallyEq.germ_eq⟩ := coe_eq
/-- Lift a function `β → γ` to a function `Germ l β → Germ l γ`. -/
def map (op : β → γ) : Germ l β → Germ l γ :=
map' (op ∘ ·) fun _ _ H => H.mono fun _ H => congr_arg op H
@[simp]
theorem map_coe (op : β → γ) (f : α → β) : map op (f : Germ l β) = op ∘ f :=
rfl
@[simp]
theorem map_id : map id = (id : Germ l β → Germ l β) := by
ext ⟨f⟩
rfl
theorem map_map (op₁ : γ → δ) (op₂ : β → γ) (f : Germ l β) :
map op₁ (map op₂ f) = map (op₁ ∘ op₂) f :=
inductionOn f fun _ => rfl
/-- Lift a binary function `β → γ → δ` to a function `Germ l β → Germ l γ → Germ l δ`. -/
def map₂ (op : β → γ → δ) : Germ l β → Germ l γ → Germ l δ :=
Quotient.map₂' (fun f g x => op (f x) (g x)) fun f f' Hf g g' Hg =>
Hg.mp <| Hf.mono fun x Hf Hg => by simp only [Hf, Hg]
@[simp]
theorem map₂_coe (op : β → γ → δ) (f : α → β) (g : α → γ) :
map₂ op (f : Germ l β) g = fun x => op (f x) (g x) :=
rfl
/-- A germ at `l` of maps from `α` to `β` tends to `lb : Filter β` if it is represented by a map
which tends to `lb` along `l`. -/
protected def Tendsto (f : Germ l β) (lb : Filter β) : Prop :=
liftOn f (fun f => Tendsto f l lb) fun _f _g H => propext (tendsto_congr' H)
@[simp, norm_cast]
theorem coe_tendsto {f : α → β} {lb : Filter β} : (f : Germ l β).Tendsto lb ↔ Tendsto f l lb :=
Iff.rfl
alias ⟨_, _root_.Filter.Tendsto.germ_tendsto⟩ := coe_tendsto
/-- Given two germs `f : Germ l β`, and `g : Germ lc α`, where `l : Filter α`, if `g` tends to `l`,
then the composition `f ∘ g` is well-defined as a germ at `lc`. -/
def compTendsto' (f : Germ l β) {lc : Filter γ} (g : Germ lc α) (hg : g.Tendsto l) : Germ lc β :=
liftOn f (fun f => g.map f) fun _f₁ _f₂ hF =>
inductionOn g (fun _g hg => coe_eq.2 <| hg.eventually hF) hg
@[simp]
theorem coe_compTendsto' (f : α → β) {lc : Filter γ} {g : Germ lc α} (hg : g.Tendsto l) :
(f : Germ l β).compTendsto' g hg = g.map f :=
rfl
/-- Given a germ `f : Germ l β` and a function `g : γ → α`, where `l : Filter α`, if `g` tends
to `l` along `lc : Filter γ`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/
def compTendsto (f : Germ l β) {lc : Filter γ} (g : γ → α) (hg : Tendsto g lc l) : Germ lc β :=
f.compTendsto' _ hg.germ_tendsto
@[simp]
theorem coe_compTendsto (f : α → β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) :
(f : Germ l β).compTendsto g hg = f ∘ g :=
rfl
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem compTendsto'_coe (f : Germ l β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) :
f.compTendsto' _ hg.germ_tendsto = f.compTendsto g hg :=
rfl
theorem Filter.Tendsto.congr_germ {f g : β → γ} {l : Filter α} {l' : Filter β} (h : f =ᶠ[l'] g)
{φ : α → β} (hφ : Tendsto φ l l') : (f ∘ φ : Germ l γ) = g ∘ φ :=
EventuallyEq.germ_eq (h.comp_tendsto hφ)
lemma isConstant_comp_tendsto {lc : Filter γ} {g : γ → α}
(hf : (f : Germ l β).IsConstant) (hg : Tendsto g lc l) : IsConstant (f ∘ g : Germ lc β) := by
rcases hf with ⟨b, hb⟩
exact ⟨b, hb.comp_tendsto hg⟩
/-- If a germ `f : Germ l β` is constant, where `l : Filter α`,
and a function `g : γ → α` tends to `l` along `lc : Filter γ`,
the germ of the composition `f ∘ g` is also constant. -/
lemma isConstant_compTendsto {f : Germ l β} {lc : Filter γ} {g : γ → α}
(hf : f.IsConstant) (hg : Tendsto g lc l) : (f.compTendsto g hg).IsConstant := by
induction f using Quotient.inductionOn with | _ f => ?_
exact isConstant_comp_tendsto hf hg
@[simp, norm_cast]
theorem const_inj [NeBot l] {a b : β} : (↑a : Germ l β) = ↑b ↔ a = b :=
coe_eq.trans const_eventuallyEq
@[simp]
theorem map_const (l : Filter α) (a : β) (f : β → γ) : (↑a : Germ l β).map f = ↑(f a) :=
rfl
@[simp]
theorem map₂_const (l : Filter α) (b : β) (c : γ) (f : β → γ → δ) :
map₂ f (↑b : Germ l β) ↑c = ↑(f b c) :=
rfl
@[simp]
theorem const_compTendsto {l : Filter α} (b : β) {lc : Filter γ} {g : γ → α} (hg : Tendsto g lc l) :
(↑b : Germ l β).compTendsto g hg = ↑b :=
rfl
@[simp]
theorem const_compTendsto' {l : Filter α} (b : β) {lc : Filter γ} {g : Germ lc α}
(hg : g.Tendsto l) : (↑b : Germ l β).compTendsto' g hg = ↑b :=
inductionOn g (fun _ _ => rfl) hg
/-- Lift a predicate on `β` to `Germ l β`. -/
def LiftPred (p : β → Prop) (f : Germ l β) : Prop :=
liftOn f (fun f => ∀ᶠ x in l, p (f x)) fun _f _g H =>
propext <| eventually_congr <| H.mono fun _x hx => hx ▸ Iff.rfl
@[simp]
theorem liftPred_coe {p : β → Prop} {f : α → β} : LiftPred p (f : Germ l β) ↔ ∀ᶠ x in l, p (f x) :=
Iff.rfl
theorem liftPred_const {p : β → Prop} {x : β} (hx : p x) : LiftPred p (↑x : Germ l β) :=
eventually_of_forall fun _y => hx
@[simp]
theorem liftPred_const_iff [NeBot l] {p : β → Prop} {x : β} : LiftPred p (↑x : Germ l β) ↔ p x :=
@eventually_const _ _ _ (p x)
/-- Lift a relation `r : β → γ → Prop` to `Germ l β → Germ l γ → Prop`. -/
def LiftRel (r : β → γ → Prop) (f : Germ l β) (g : Germ l γ) : Prop :=
Quotient.liftOn₂' f g (fun f g => ∀ᶠ x in l, r (f x) (g x)) fun _f _g _f' _g' Hf Hg =>
propext <| eventually_congr <| Hg.mp <| Hf.mono fun _x hf hg => hf ▸ hg ▸ Iff.rfl
@[simp]
theorem liftRel_coe {r : β → γ → Prop} {f : α → β} {g : α → γ} :
LiftRel r (f : Germ l β) g ↔ ∀ᶠ x in l, r (f x) (g x) :=
Iff.rfl
theorem liftRel_const {r : β → γ → Prop} {x : β} {y : γ} (h : r x y) :
LiftRel r (↑x : Germ l β) ↑y :=
eventually_of_forall fun _ => h
@[simp]
theorem liftRel_const_iff [NeBot l] {r : β → γ → Prop} {x : β} {y : γ} :
LiftRel r (↑x : Germ l β) ↑y ↔ r x y :=
@eventually_const _ _ _ (r x y)
instance instInhabited [Inhabited β] : Inhabited (Germ l β) := ⟨↑(default : β)⟩
section Monoid
variable {M : Type*} {G : Type*}
@[to_additive] instance instMul [Mul M] : Mul (Germ l M) := ⟨map₂ (· * ·)⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul [Mul M] (f g : α → M) : ↑(f * g) = (f * g : Germ l M) :=
rfl
@[to_additive] instance instOne [One M] : One (Germ l M) := ⟨↑(1 : M)⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_one [One M] : ↑(1 : α → M) = (1 : Germ l M) :=
rfl
@[to_additive]
instance instSemigroup [Semigroup M] : Semigroup (Germ l M) :=
{ mul_assoc := fun a b c => Quotient.inductionOn₃' a b c
fun _ _ _ => congrArg ofFun <| mul_assoc .. }
@[to_additive]
instance instCommSemigroup [CommSemigroup M] : CommSemigroup (Germ l M) :=
{ mul_comm := Quotient.ind₂' fun _ _ => congrArg ofFun <| mul_comm .. }
@[to_additive]
instance instIsLeftCancelMul [Mul M] [IsLeftCancelMul M] : IsLeftCancelMul (Germ l M) where
mul_left_cancel f₁ f₂ f₃ :=
inductionOn₃ f₁ f₂ f₃ fun _f₁ _f₂ _f₃ H =>
coe_eq.2 ((coe_eq.1 H).mono fun _x => mul_left_cancel)
@[to_additive]
instance instIsRightCancelMul [Mul M] [IsRightCancelMul M] : IsRightCancelMul (Germ l M) where
mul_right_cancel f₁ f₂ f₃ :=
inductionOn₃ f₁ f₂ f₃ fun _f₁ _f₂ _f₃ H =>
coe_eq.2 <| (coe_eq.1 H).mono fun _x => mul_right_cancel
@[to_additive]
instance instIsCancelMul [Mul M] [IsCancelMul M] : IsCancelMul (Germ l M) where
@[to_additive]
instance instLeftCancelSemigroup [LeftCancelSemigroup M] : LeftCancelSemigroup (Germ l M) where
mul_left_cancel _ _ _ := mul_left_cancel
@[to_additive]
instance instRightCancelSemigroup [RightCancelSemigroup M] : RightCancelSemigroup (Germ l M) where
mul_right_cancel _ _ _ := mul_right_cancel
@[to_additive]
instance instMulOneClass [MulOneClass M] : MulOneClass (Germ l M) :=
{ one_mul := Quotient.ind' fun _ => congrArg ofFun <| one_mul _
mul_one := Quotient.ind' fun _ => congrArg ofFun <| mul_one _ }
@[to_additive]
instance instSMul [SMul M G] : SMul M (Germ l G) where smul n := map (n • ·)
@[to_additive existing instSMul]
instance instPow [Pow G M] : Pow (Germ l G) M where pow f n := map (· ^ n) f
@[to_additive (attr := simp, norm_cast)]
theorem coe_smul [SMul M G] (n : M) (f : α → G) : ↑(n • f) = n • (f : Germ l G) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem const_smul [SMul M G] (n : M) (a : G) : (↑(n • a) : Germ l G) = n • (↑a : Germ l G) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow [Pow G M] (f : α → G) (n : M) : ↑(f ^ n) = (f : Germ l G) ^ n :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem const_pow [Pow G M] (a : G) (n : M) : (↑(a ^ n) : Germ l G) = (↑a : Germ l G) ^ n :=
rfl
-- TODO: #7432
@[to_additive]
instance instMonoid [Monoid M] : Monoid (Germ l M) :=
{ Function.Surjective.monoid ofFun (surjective_quot_mk _) (by rfl)
(fun _ _ => by rfl) fun _ _ => by rfl with
toSemigroup := instSemigroup
toOne := instOne
npow := fun n a => a ^ n }
/-- Coercion from functions to germs as a monoid homomorphism. -/
@[to_additive "Coercion from functions to germs as an additive monoid homomorphism."]
def coeMulHom [Monoid M] (l : Filter α) : (α → M) →* Germ l M where
toFun := ofFun; map_one' := rfl; map_mul' _ _ := rfl
@[to_additive (attr := simp)]
theorem coe_coeMulHom [Monoid M] : (coeMulHom l : (α → M) → Germ l M) = ofFun :=
rfl
@[to_additive]
instance instCommMonoid [CommMonoid M] : CommMonoid (Germ l M) :=
{ mul_comm := mul_comm }
instance instNatCast [NatCast M] : NatCast (Germ l M) where natCast n := (n : α → M)
@[simp]
theorem natCast_def [NatCast M] (n : ℕ) : ((fun _ ↦ n : α → M) : Germ l M) = n := rfl
@[simp, norm_cast]
theorem const_nat [NatCast M] (n : ℕ) : ((n : M) : Germ l M) = n := rfl
-- See note [no_index around OfNat.ofNat]
@[simp, norm_cast]
theorem coe_ofNat [NatCast M] (n : ℕ) [n.AtLeastTwo] :
((no_index (OfNat.ofNat n : α → M)) : Germ l M) = OfNat.ofNat n :=
rfl
-- See note [no_index around OfNat.ofNat]
@[simp, norm_cast]
theorem const_ofNat [NatCast M] (n : ℕ) [n.AtLeastTwo] :
((no_index (OfNat.ofNat n : M)) : Germ l M) = OfNat.ofNat n :=
rfl
instance instIntCast [IntCast M] : IntCast (Germ l M) where intCast n := (n : α → M)
@[simp]
theorem intCast_def [IntCast M] (n : ℤ) : ((fun _ ↦ n : α → M) : Germ l M) = n := rfl
@[deprecated (since := "2024-04-05")] alias coe_nat := natCast_def
@[deprecated (since := "2024-04-05")] alias coe_int := intCast_def
instance instAddMonoidWithOne [AddMonoidWithOne M] : AddMonoidWithOne (Germ l M) where
natCast_zero := congrArg ofFun <| by simp; rfl
natCast_succ _ := congrArg ofFun <| by simp [Function.comp]; rfl
instance instAddCommMonoidWithOne [AddCommMonoidWithOne M] : AddCommMonoidWithOne (Germ l M) :=
{ add_comm := add_comm }
@[to_additive] instance instInv [Inv G] : Inv (Germ l G) := ⟨map Inv.inv⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv G] (f : α → G) : ↑f⁻¹ = (f⁻¹ : Germ l G) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem const_inv [Inv G] (a : G) : (↑(a⁻¹) : Germ l G) = (↑a)⁻¹ :=
rfl
@[to_additive] instance instDiv [Div M] : Div (Germ l M) := ⟨map₂ (· / ·)⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_div [Div M] (f g : α → M) : ↑(f / g) = (f / g : Germ l M) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem const_div [Div M] (a b : M) : (↑(a / b) : Germ l M) = ↑a / ↑b :=
rfl
@[to_additive]
instance instInvolutiveInv [InvolutiveInv G] : InvolutiveInv (Germ l G) :=
{ inv_inv := Quotient.ind' fun _ => congrArg ofFun<| inv_inv _ }
instance instHasDistribNeg [Mul G] [HasDistribNeg G] : HasDistribNeg (Germ l G) :=
{ neg_mul := Quotient.ind₂' fun _ _ => congrArg ofFun <| neg_mul ..
mul_neg := Quotient.ind₂' fun _ _ => congrArg ofFun <| mul_neg .. }
@[to_additive]
instance instInvOneClass [InvOneClass G] : InvOneClass (Germ l G) :=
⟨congr_arg ofFun inv_one⟩
@[to_additive subNegMonoid]
instance instDivInvMonoid [DivInvMonoid G] : DivInvMonoid (Germ l G) where
zpow z f := f ^ z
zpow_zero' := Quotient.ind' fun _ => congrArg ofFun <|
funext fun _ => DivInvMonoid.zpow_zero' _
zpow_succ' _ := Quotient.ind' fun _ => congrArg ofFun <|
funext fun _ => DivInvMonoid.zpow_succ' ..
zpow_neg' _ := Quotient.ind' fun _ => congrArg ofFun <|
funext fun _ => DivInvMonoid.zpow_neg' ..
div_eq_mul_inv := Quotient.ind₂' fun _ _ ↦ congrArg ofFun <| div_eq_mul_inv ..
@[to_additive]
instance instDivisionMonoid [DivisionMonoid G] : DivisionMonoid (Germ l G) where
inv_inv := inv_inv
mul_inv_rev x y := inductionOn₂ x y fun _ _ ↦ congr_arg ofFun <| mul_inv_rev _ _
inv_eq_of_mul x y := inductionOn₂ x y fun _ _ h ↦ coe_eq.2 <| (coe_eq.1 h).mono fun _ ↦
DivisionMonoid.inv_eq_of_mul _ _
@[to_additive]
instance instGroup [Group G] : Group (Germ l G) :=
{ mul_left_inv := Quotient.ind' fun _ => congrArg ofFun <| mul_left_inv _ }
@[to_additive]
instance instCommGroup [CommGroup G] : CommGroup (Germ l G) :=
{ mul_comm := mul_comm }
instance instAddGroupWithOne [AddGroupWithOne G] : AddGroupWithOne (Germ l G) where
__ := instAddMonoidWithOne
__ := instAddGroup
intCast_ofNat _ := congrArg ofFun <| by simp
intCast_negSucc _ := congrArg ofFun <| by simp [Function.comp]; rfl
end Monoid
section Ring
variable {R : Type*}
instance instNontrivial [Nontrivial R] [NeBot l] : Nontrivial (Germ l R) :=
let ⟨x, y, h⟩ := exists_pair_ne R
⟨⟨↑x, ↑y, mt const_inj.1 h⟩⟩
instance instMulZeroClass [MulZeroClass R] : MulZeroClass (Germ l R) :=
{ zero_mul := Quotient.ind' fun _ => congrArg ofFun <| zero_mul _
mul_zero := Quotient.ind' fun _ => congrArg ofFun <| mul_zero _ }
instance instMulZeroOneClass [MulZeroOneClass R] : MulZeroOneClass (Germ l R) where
__ := instMulZeroClass
__ := instMulOneClass
instance instMonoidWithZero [MonoidWithZero R] : MonoidWithZero (Germ l R) where
__ := instMonoid
__ := instMulZeroClass
instance instDistrib [Distrib R] : Distrib (Germ l R) where
left_distrib a b c := Quotient.inductionOn₃' a b c fun _ _ _ ↦ congrArg ofFun <| left_distrib ..
right_distrib a b c := Quotient.inductionOn₃' a b c fun _ _ _ ↦ congrArg ofFun <| right_distrib ..
instance instNonUnitalNonAssocSemiring [NonUnitalNonAssocSemiring R] :
NonUnitalNonAssocSemiring (Germ l R) where
__ := instAddCommMonoid
__ := instDistrib
__ := instMulZeroClass
instance instNonUnitalSemiring [NonUnitalSemiring R] : NonUnitalSemiring (Germ l R) :=
{ mul_assoc := mul_assoc }
instance instNonAssocSemiring [NonAssocSemiring R] : NonAssocSemiring (Germ l R) where
__ := instNonUnitalNonAssocSemiring
__ := instMulZeroOneClass
__ := instAddMonoidWithOne
instance instNonUnitalNonAssocRing [NonUnitalNonAssocRing R] :
NonUnitalNonAssocRing (Germ l R) where
__ := instAddCommGroup
__ := instNonUnitalNonAssocSemiring
instance instNonUnitalRing [NonUnitalRing R] : NonUnitalRing (Germ l R) :=
{ mul_assoc := mul_assoc }
instance instNonAssocRing [NonAssocRing R] : NonAssocRing (Germ l R) where
__ := instNonUnitalNonAssocRing
__ := instNonAssocSemiring
__ := instAddGroupWithOne
instance instSemiring [Semiring R] : Semiring (Germ l R) where
__ := instNonUnitalSemiring
__ := instNonAssocSemiring
__ := instMonoidWithZero
instance instRing [Ring R] : Ring (Germ l R) where
__ := instSemiring
__ := instAddCommGroup
__ := instNonAssocRing
instance instNonUnitalCommSemiring [NonUnitalCommSemiring R] :
NonUnitalCommSemiring (Germ l R) :=
{ mul_comm := mul_comm }
instance instCommSemiring [CommSemiring R] : CommSemiring (Germ l R) :=
{ mul_comm := mul_comm }
instance instNonUnitalCommRing [NonUnitalCommRing R] : NonUnitalCommRing (Germ l R) where
__ := instNonUnitalRing
__ := instCommSemigroup
instance instCommRing [CommRing R] : CommRing (Germ l R) :=
{ mul_comm := mul_comm }
/-- Coercion `(α → R) → Germ l R` as a `RingHom`. -/
def coeRingHom [Semiring R] (l : Filter α) : (α → R) →+* Germ l R :=
{ (coeMulHom l : _ →* Germ l R), (coeAddHom l : _ →+ Germ l R) with toFun := ofFun }
@[simp]
theorem coe_coeRingHom [Semiring R] : (coeRingHom l : (α → R) → Germ l R) = ofFun :=
rfl
end Ring
section Module
variable {M N R : Type*}
@[to_additive]
instance instSMul' [SMul M β] : SMul (Germ l M) (Germ l β) :=
⟨map₂ (· • ·)⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_smul' [SMul M β] (c : α → M) (f : α → β) : ↑(c • f) = (c : Germ l M) • (f : Germ l β) :=
rfl
@[to_additive]
instance instMulAction [Monoid M] [MulAction M β] : MulAction M (Germ l β) where
one_smul f :=
inductionOn f fun f => by
norm_cast
simp [one_smul]
mul_smul c₁ c₂ f :=
inductionOn f fun f => by
norm_cast
simp [mul_smul]
@[to_additive]
instance instMulAction' [Monoid M] [MulAction M β] : MulAction (Germ l M) (Germ l β) where
one_smul f := inductionOn f fun f => by simp only [← coe_one, ← coe_smul', one_smul]
mul_smul c₁ c₂ f :=
inductionOn₃ c₁ c₂ f fun c₁ c₂ f => by
norm_cast
simp [mul_smul]
instance instDistribMulAction [Monoid M] [AddMonoid N] [DistribMulAction M N] :
DistribMulAction M (Germ l N) where
smul_add c f g :=
inductionOn₂ f g fun f g => by
norm_cast
simp [smul_add]
smul_zero c := by simp only [← coe_zero, ← coe_smul, smul_zero]
instance instDistribMulAction' [Monoid M] [AddMonoid N] [DistribMulAction M N] :
DistribMulAction (Germ l M) (Germ l N) where
smul_add c f g :=
inductionOn₃ c f g fun c f g => by
norm_cast
simp [smul_add]
smul_zero c := inductionOn c fun c => by simp only [← coe_zero, ← coe_smul', smul_zero]
instance instModule [Semiring R] [AddCommMonoid M] [Module R M] : Module R (Germ l M) where
add_smul c₁ c₂ f :=
inductionOn f fun f => by
norm_cast
simp [add_smul]
zero_smul f :=
inductionOn f fun f => by
norm_cast
simp [zero_smul, coe_zero]
instance instModule' [Semiring R] [AddCommMonoid M] [Module R M] :
Module (Germ l R) (Germ l M) where
add_smul c₁ c₂ f :=
inductionOn₃ c₁ c₂ f fun c₁ c₂ f => by
norm_cast
simp [add_smul]
zero_smul f := inductionOn f fun f => by simp only [← coe_zero, ← coe_smul', zero_smul]
end Module
instance instLE [LE β] : LE (Germ l β) := ⟨LiftRel (· ≤ ·)⟩
theorem le_def [LE β] : ((· ≤ ·) : Germ l β → Germ l β → Prop) = LiftRel (· ≤ ·) :=
rfl
@[simp]
theorem coe_le [LE β] : (f : Germ l β) ≤ g ↔ f ≤ᶠ[l] g :=
Iff.rfl
theorem coe_nonneg [LE β] [Zero β] {f : α → β} : 0 ≤ (f : Germ l β) ↔ ∀ᶠ x in l, 0 ≤ f x :=
Iff.rfl
theorem const_le [LE β] {x y : β} : x ≤ y → (↑x : Germ l β) ≤ ↑y :=
liftRel_const
@[simp, norm_cast]
theorem const_le_iff [LE β] [NeBot l] {x y : β} : (↑x : Germ l β) ≤ ↑y ↔ x ≤ y :=
liftRel_const_iff
instance instPreorder [Preorder β] : Preorder (Germ l β) where
le := (· ≤ ·)
le_refl f := inductionOn f <| EventuallyLE.refl l
le_trans f₁ f₂ f₃ := inductionOn₃ f₁ f₂ f₃ fun f₁ f₂ f₃ => EventuallyLE.trans
instance instPartialOrder [PartialOrder β] : PartialOrder (Germ l β) where
le_antisymm f g := inductionOn₂ f g fun _ _ h₁ h₂ ↦ (EventuallyLE.antisymm h₁ h₂).germ_eq
instance instBot [Bot β] : Bot (Germ l β) := ⟨↑(⊥ : β)⟩
instance instTop [Top β] : Top (Germ l β) := ⟨↑(⊤ : β)⟩
@[simp, norm_cast]
theorem const_bot [Bot β] : (↑(⊥ : β) : Germ l β) = ⊥ :=
rfl
@[simp, norm_cast]
theorem const_top [Top β] : (↑(⊤ : β) : Germ l β) = ⊤ :=
rfl
instance instOrderBot [LE β] [OrderBot β] : OrderBot (Germ l β) where
bot_le f := inductionOn f fun _ => eventually_of_forall fun _ => bot_le
instance instOrderTop [LE β] [OrderTop β] : OrderTop (Germ l β) where
le_top f := inductionOn f fun _ => eventually_of_forall fun _ => le_top
instance instBoundedOrder [LE β] [BoundedOrder β] : BoundedOrder (Germ l β) where
__ := instOrderBot
__ := instOrderTop
instance instSup [Sup β] : Sup (Germ l β) := ⟨map₂ (· ⊔ ·)⟩
instance instInf [Inf β] : Inf (Germ l β) := ⟨map₂ (· ⊓ ·)⟩
@[simp, norm_cast]
theorem const_sup [Sup β] (a b : β) : ↑(a ⊔ b) = (↑a ⊔ ↑b : Germ l β) :=
rfl
@[simp, norm_cast]
theorem const_inf [Inf β] (a b : β) : ↑(a ⊓ b) = (↑a ⊓ ↑b : Germ l β) :=
rfl
instance instSemilatticeSup [SemilatticeSup β] : SemilatticeSup (Germ l β) where
le_sup_left f g := inductionOn₂ f g fun _f _g => eventually_of_forall fun _x ↦ le_sup_left
le_sup_right f g := inductionOn₂ f g fun _f _g ↦ eventually_of_forall fun _x ↦ le_sup_right
sup_le f₁ f₂ g := inductionOn₃ f₁ f₂ g fun _f₁ _f₂ _g h₁ h₂ ↦ h₂.mp <| h₁.mono fun _x ↦ sup_le
instance instSemilatticeInf [SemilatticeInf β] : SemilatticeInf (Germ l β) where
inf_le_left f g := inductionOn₂ f g fun _f _g ↦ eventually_of_forall fun _x ↦ inf_le_left
inf_le_right f g := inductionOn₂ f g fun _f _g ↦ eventually_of_forall fun _x ↦ inf_le_right
le_inf f₁ f₂ g := inductionOn₃ f₁ f₂ g fun _f₁ _f₂ _g h₁ h₂ ↦ h₂.mp <| h₁.mono fun _x ↦ le_inf
instance instLattice [Lattice β] : Lattice (Germ l β) where
__ := instSemilatticeSup
__ := instSemilatticeInf
instance instDistribLattice [DistribLattice β] : DistribLattice (Germ l β) where
le_sup_inf f g h := inductionOn₃ f g h fun _f _g _h ↦ eventually_of_forall fun _ ↦ le_sup_inf
@[to_additive]
instance instExistsMulOfLE [Mul β] [LE β] [ExistsMulOfLE β] : ExistsMulOfLE (Germ l β) where
exists_mul_of_le {x y} := inductionOn₂ x y fun f g (h : f ≤ᶠ[l] g) ↦ by
classical
choose c hc using fun x (hx : f x ≤ g x) ↦ exists_mul_of_le hx
refine ⟨ofFun fun x ↦ if hx : f x ≤ g x then c x hx else f x, coe_eq.2 ?_⟩
filter_upwards [h] with x hx
rw [dif_pos hx, hc]
end Germ
end Filter
|
Order\Filter\Germ\OrderedMonoid.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.Module.Pi
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Order.Filter.Germ.Basic
/-!
# Ordered monoid instances on the space of germs of a function at a filter
For each of the following structures we prove that if `β` has this structure, then so does
`Germ l β`:
* `OrderedCancelCommMonoid` and `OrderedCancelAddCommMonoid`.
## Tags
filter, germ
-/
namespace Filter.Germ
variable {α : Type*} {β : Type*} {l : Filter α}
@[to_additive]
instance instOrderedCommMonoid [OrderedCommMonoid β] : OrderedCommMonoid (Germ l β) where
mul_le_mul_left f g := inductionOn₂ f g fun _ _ H h ↦ inductionOn h fun _ ↦ H.mono
fun _ H ↦ mul_le_mul_left' H _
@[to_additive]
instance instOrderedCancelCommMonoid [OrderedCancelCommMonoid β] :
OrderedCancelCommMonoid (Germ l β) where
le_of_mul_le_mul_left f g h := inductionOn₃ f g h fun _ _ _ H ↦ H.mono
fun _ ↦ le_of_mul_le_mul_left'
@[to_additive]
instance instCanonicallyOrderedCommMonoid [CanonicallyOrderedCommMonoid β] :
CanonicallyOrderedCommMonoid (Germ l β) where
__ := instExistsMulOfLE
le_self_mul x y := inductionOn₂ x y fun _ _ ↦ eventually_of_forall fun _ ↦ le_self_mul
end Filter.Germ
|
Order\Fin\Basic.lean | /-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import Mathlib.Data.Fin.Basic
import Mathlib.Order.Hom.Set
/-!
# `Fin n` forms a bounded linear order
This file contains the linear ordered instance on `Fin n`.
`Fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
* `Fin.orderIsoSubtype` : coercion to `{i // i < n}` as an `OrderIso`;
* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;
* `Fin.valOrderEmb` : coercion to natural numbers as an `OrderEmbedding`;
* `Fin.succOrderEmb` : `Fin.succ` as an `OrderEmbedding`;
* `Fin.castLEOrderEmb h` : `Fin.castLE` as an `OrderEmbedding`, embed `Fin n` into `Fin m` when
`h : n ≤ m`;
* `Fin.castOrderIso` : `Fin.cast` as an `OrderIso`, order isomorphism between `Fin n` and `Fin m`
provided that `n = m`, see also `Equiv.finCongr`;
* `Fin.castAddOrderEmb m` : `Fin.castAdd` as an `OrderEmbedding`, embed `Fin n` into `Fin (n+m)`;
* `Fin.castSuccOrderEmb` : `Fin.castSucc` as an `OrderEmbedding`, embed `Fin n` into `Fin (n+1)`;
* `Fin.addNatOrderEmb m i` : `Fin.addNat` as an `OrderEmbedding`, add `m` on `i` on the right,
generalizes `Fin.succ`;
* `Fin.natAddOrderEmb n i` : `Fin.natAdd` as an `OrderEmbedding`, adds `n` on `i` on the left;
* `Fin.revOrderIso`: `Fin.rev` as an `OrderIso`, the antitone involution given by `i ↦ n-(i+1)`
-/
assert_not_exists Monoid
open Function Nat Set
namespace Fin
variable {m n : ℕ}
/-! ### Instances -/
instance instLinearOrder : LinearOrder (Fin n) :=
@LinearOrder.liftWithOrd (Fin n) _ _ ⟨fun x y => ⟨max x y, max_rec' (· < n) x.2 y.2⟩⟩
⟨fun x y => ⟨min x y, min_rec' (· < n) x.2 y.2⟩⟩ _ Fin.val Fin.val_injective (fun _ _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance instBoundedOrder [NeZero n] : BoundedOrder (Fin n) where
top := rev 0
le_top i := Nat.le_pred_of_lt i.is_lt
bot := 0
bot_le := Fin.zero_le'
/- There is a slight asymmetry here, in the sense that `0` is of type `Fin n` when we have
`[NeZero n]` whereas `last n` is of type `Fin (n + 1)`. To address this properly would
require a change to std4, defining `NeZero n` and thus re-defining `last n`
(and possibly make its argument implicit) as `rev 0`, of type `Fin n`. As we can see from these
lemmas, this would be equivalent to the existing definition. -/
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances being used to construct these instances non-computably.
-/
instance instPartialOrder : PartialOrder (Fin n) := inferInstance
instance instLattice : Lattice (Fin n) := inferInstance
/-! ### Miscellaneous lemmas -/
lemma top_eq_last (n : ℕ) : ⊤ = Fin.last n := rfl
lemma bot_eq_zero (n : ℕ) : ⊥ = (0 : Fin (n + 1)) := rfl
@[simp] theorem rev_bot [NeZero n] : rev (⊥ : Fin n) = ⊤ := rfl
@[simp] theorem rev_top [NeZero n] : rev (⊤ : Fin n) = ⊥ := rev_rev _
theorem rev_zero_eq_top (n : ℕ) [NeZero n] : rev (0 : Fin n) = ⊤ := rfl
theorem rev_last_eq_bot (n : ℕ) : rev (last n) = ⊥ := by rw [rev_last, bot_eq_zero]
section ToFin
variable {α : Type*} [Preorder α] {f : α → Fin (n + 1)}
lemma strictMono_pred_comp (hf : ∀ a, f a ≠ 0) (hf₂ : StrictMono f) :
StrictMono (fun a => pred (f a) (hf a)) := fun _ _ h => pred_lt_pred_iff.2 (hf₂ h)
lemma monotone_pred_comp (hf : ∀ a, f a ≠ 0) (hf₂ : Monotone f) :
Monotone (fun a => pred (f a) (hf a)) := fun _ _ h => pred_le_pred_iff.2 (hf₂ h)
lemma strictMono_castPred_comp (hf : ∀ a, f a ≠ last n) (hf₂ : StrictMono f) :
StrictMono (fun a => castPred (f a) (hf a)) := fun _ _ h => castPred_lt_castPred_iff.2 (hf₂ h)
lemma monotone_castPred_comp (hf : ∀ a, f a ≠ last n) (hf₂ : Monotone f) :
Monotone (fun a => castPred (f a) (hf a)) := fun _ _ h => castPred_le_castPred_iff.2 (hf₂ h)
end ToFin
section FromFin
variable {α : Type*} [Preorder α] {f : Fin (n + 1) → α}
/-- A function `f` on `Fin (n + 1)` is strictly monotone if and only if `f i < f (i + 1)`
for all `i`. -/
lemma strictMono_iff_lt_succ : StrictMono f ↔ ∀ i : Fin n, f (castSucc i) < f i.succ :=
liftFun_iff_succ (· < ·)
/-- A function `f` on `Fin (n + 1)` is monotone if and only if `f i ≤ f (i + 1)` for all `i`. -/
lemma monotone_iff_le_succ : Monotone f ↔ ∀ i : Fin n, f (castSucc i) ≤ f i.succ :=
monotone_iff_forall_lt.trans <| liftFun_iff_succ (· ≤ ·)
/-- A function `f` on `Fin (n + 1)` is strictly antitone if and only if `f (i + 1) < f i`
for all `i`. -/
lemma strictAnti_iff_succ_lt : StrictAnti f ↔ ∀ i : Fin n, f i.succ < f (castSucc i) :=
liftFun_iff_succ (· > ·)
/-- A function `f` on `Fin (n + 1)` is antitone if and only if `f (i + 1) ≤ f i` for all `i`. -/
lemma antitone_iff_succ_le : Antitone f ↔ ∀ i : Fin n, f i.succ ≤ f (castSucc i) :=
antitone_iff_forall_lt.trans <| liftFun_iff_succ (· ≥ ·)
end FromFin
/-! #### Monotonicity -/
lemma val_strictMono : StrictMono (val : Fin n → ℕ) := fun _ _ ↦ id
lemma strictMono_succ : StrictMono (succ : Fin n → Fin (n + 1)) := fun _ _ ↦ succ_lt_succ
lemma strictMono_castLE (h : n ≤ m) : StrictMono (castLE h : Fin n → Fin m) := fun _ _ ↦ id
lemma strictMono_castAdd (m) : StrictMono (castAdd m : Fin n → Fin (n + m)) := strictMono_castLE _
lemma strictMono_castSucc : StrictMono (castSucc : Fin n → Fin (n + 1)) := strictMono_castAdd _
lemma strictMono_natAdd (n) : StrictMono (natAdd n : Fin m → Fin (n + m)) :=
fun i j h ↦ Nat.add_lt_add_left (show i.val < j.val from h) _
lemma strictMono_addNat (m) : StrictMono ((addNat · m) : Fin n → Fin (n + m)) :=
fun i j h ↦ Nat.add_lt_add_right (show i.val < j.val from h) _
lemma strictMono_succAbove (p : Fin (n + 1)) : StrictMono (succAbove p) :=
strictMono_castSucc.ite strictMono_succ
(fun _ _ hij hj => (castSucc_lt_castSucc_iff.mpr hij).trans hj) fun i =>
(castSucc_lt_succ i).le
variable {p : Fin (n + 1)} {i j : Fin n}
lemma succAbove_lt_succAbove_iff : succAbove p i < succAbove p j ↔ i < j :=
(strictMono_succAbove p).lt_iff_lt
lemma succAbove_le_succAbove_iff : succAbove p i ≤ succAbove p j ↔ i ≤ j :=
(strictMono_succAbove p).le_iff_le
lemma predAbove_right_monotone (p : Fin n) : Monotone p.predAbove := fun a b H => by
dsimp [predAbove]
split_ifs with ha hb hb
all_goals simp only [le_iff_val_le_val, coe_pred]
· exact pred_le_pred H
· calc
_ ≤ _ := Nat.pred_le _
_ ≤ _ := H
· exact le_pred_of_lt ((not_lt.mp ha).trans_lt hb)
· exact H
lemma predAbove_left_monotone (i : Fin (n + 1)) : Monotone fun p ↦ predAbove p i := fun a b H ↦ by
dsimp [predAbove]
split_ifs with ha hb hb
· rfl
· exact pred_le _
· have : b < a := castSucc_lt_castSucc_iff.mpr (hb.trans_le (le_of_not_gt ha))
exact absurd H this.not_le
· rfl
/-- `Fin.predAbove p` as an `OrderHom`. -/
@[simps!] def predAboveOrderHom (p : Fin n) : Fin (n + 1) →o Fin n :=
⟨p.predAbove, p.predAbove_right_monotone⟩
/-! #### Order isomorphisms -/
/-- The equivalence `Fin n ≃ {i // i < n}` is an order isomorphism. -/
@[simps! apply symm_apply]
def orderIsoSubtype : Fin n ≃o {i // i < n} :=
equivSubtype.toOrderIso (by simp [Monotone]) (by simp [Monotone])
/-- `Fin.cast` as an `OrderIso`.
`castOrderIso eq i` embeds `i` into an equal `Fin` type. -/
@[simps]
def castOrderIso (eq : n = m) : Fin n ≃o Fin m where
toEquiv := ⟨cast eq, cast eq.symm, leftInverse_cast eq, rightInverse_cast eq⟩
map_rel_iff' := cast_le_cast eq
@[deprecated (since := "2024-05-23")] alias castIso := castOrderIso
@[simp]
lemma symm_castOrderIso (h : n = m) : (castOrderIso h).symm = castOrderIso h.symm := by subst h; rfl
@[deprecated (since := "2024-05-23")] alias symm_castIso := symm_castOrderIso
@[simp]
lemma castOrderIso_refl (h : n = n := rfl) : castOrderIso h = OrderIso.refl (Fin n) := by ext; simp
@[deprecated (since := "2024-05-23")] alias castIso_refl := castOrderIso_refl
/-- While in many cases `Fin.castOrderIso` is better than `Equiv.cast`/`cast`, sometimes we want to
apply a generic lemma about `cast`. -/
lemma castOrderIso_toEquiv (h : n = m) : (castOrderIso h).toEquiv = Equiv.cast (h ▸ rfl) := by
subst h; rfl
@[deprecated (since := "2024-05-23")] alias castIso_to_equiv := castOrderIso_toEquiv
/-- `Fin.rev n` as an order-reversing isomorphism. -/
@[simps! apply toEquiv]
def revOrderIso : (Fin n)ᵒᵈ ≃o Fin n := ⟨OrderDual.ofDual.trans revPerm, rev_le_rev⟩
@[simp]
lemma revOrderIso_symm_apply (i : Fin n) : revOrderIso.symm i = OrderDual.toDual (rev i) := rfl
/-! #### Order embeddings -/
/-- The inclusion map `Fin n → ℕ` is an order embedding. -/
@[simps! apply]
def valOrderEmb (n) : Fin n ↪o ℕ := ⟨valEmbedding, Iff.rfl⟩
/-- The ordering on `Fin n` is a well order. -/
instance Lt.isWellOrder (n) : IsWellOrder (Fin n) (· < ·) := (valOrderEmb n).isWellOrder
/-- `Fin.succ` as an `OrderEmbedding` -/
def succOrderEmb (n : ℕ) : Fin n ↪o Fin (n + 1) := .ofStrictMono succ strictMono_succ
@[simp, norm_cast] lemma coe_succOrderEmb : ⇑(succOrderEmb n) = Fin.succ := rfl
/-- `Fin.castLE` as an `OrderEmbedding`.
`castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps! apply toEmbedding]
def castLEOrderEmb (h : n ≤ m) : Fin n ↪o Fin m := .ofStrictMono (castLE h) (strictMono_castLE h)
/-- `Fin.castAdd` as an `OrderEmbedding`.
`castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
@[simps! apply toEmbedding]
def castAddOrderEmb (m) : Fin n ↪o Fin (n + m) := .ofStrictMono (castAdd m) (strictMono_castAdd m)
/-- `Fin.castSucc` as an `OrderEmbedding`.
`castSuccOrderEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
@[simps! apply toEmbedding]
def castSuccOrderEmb : Fin n ↪o Fin (n + 1) := .ofStrictMono castSucc strictMono_castSucc
/-- `Fin.addNat` as an `OrderEmbedding`.
`addNatOrderEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/
@[simps! apply toEmbedding]
def addNatOrderEmb (m) : Fin n ↪o Fin (n + m) := .ofStrictMono (addNat · m) (strictMono_addNat m)
/-- `Fin.natAdd` as an `OrderEmbedding`.
`natAddOrderEmb n i` adds `n` to `i` "on the left". -/
@[simps! apply toEmbedding]
def natAddOrderEmb (n) : Fin m ↪o Fin (n + m) := .ofStrictMono (natAdd n) (strictMono_natAdd n)
/-- `Fin.succAbove p` as an `OrderEmbedding`. -/
@[simps! apply toEmbedding]
def succAboveOrderEmb (p : Fin (n + 1)) : Fin n ↪o Fin (n + 1) :=
OrderEmbedding.ofStrictMono (succAbove p) (strictMono_succAbove p)
/-! ### Uniqueness of order isomorphisms -/
variable {α : Type*} [Preorder α]
/-- If `e` is an `orderIso` between `Fin n` and `Fin m`, then `n = m` and `e` is the identity
map. In this lemma we state that for each `i : Fin n` we have `(e i : ℕ) = (i : ℕ)`. -/
@[simp] lemma coe_orderIso_apply (e : Fin n ≃o Fin m) (i : Fin n) : (e i : ℕ) = i := by
rcases i with ⟨i, hi⟩
dsimp only
induction' i using Nat.strong_induction_on with i h
refine le_antisymm (forall_lt_iff_le.1 fun j hj => ?_) (forall_lt_iff_le.1 fun j hj => ?_)
· have := e.symm.lt_iff_lt.2 (mk_lt_of_lt_val hj)
rw [e.symm_apply_apply] at this
-- Porting note: convert was abusing definitional equality
have : _ < i := this
convert this
simpa using h _ this (e.symm _).is_lt
· rwa [← h j hj (hj.trans hi), ← lt_iff_val_lt_val, e.lt_iff_lt]
instance orderIso_subsingleton : Subsingleton (Fin n ≃o α) :=
⟨fun e e' => by
ext i
rw [← e.symm.apply_eq_iff_eq, e.symm_apply_apply, ← e'.trans_apply, Fin.ext_iff,
coe_orderIso_apply]⟩
instance orderIso_subsingleton' : Subsingleton (α ≃o Fin n) := OrderIso.symm_injective.subsingleton
instance orderIsoUnique : Unique (Fin n ≃o Fin n) := Unique.mk' _
/-- Two strictly monotone functions from `Fin n` are equal provided that their ranges
are equal. -/
lemma strictMono_unique {f g : Fin n → α} (hf : StrictMono f) (hg : StrictMono g)
(h : range f = range g) : f = g :=
have : (hf.orderIso f).trans (OrderIso.setCongr _ _ h) = hg.orderIso g := Subsingleton.elim _ _
congr_arg (Function.comp (Subtype.val : range g → α)) (funext <| RelIso.ext_iff.1 this)
/-- Two order embeddings of `Fin n` are equal provided that their ranges are equal. -/
lemma orderEmbedding_eq {f g : Fin n ↪o α} (h : range f = range g) : f = g :=
RelEmbedding.ext <| funext_iff.1 <| strictMono_unique f.strictMono g.strictMono h
end Fin
|
Order\Fin\Tuple.lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes
-/
import Mathlib.Data.Fin.VecNotation
import Mathlib.Logic.Equiv.Fin
import Mathlib.Order.Fin.Basic
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.PiLex
/-!
# Order properties on tuples
-/
assert_not_exists Monoid
open Function Set
namespace Fin
variable {m n : ℕ} {α : Fin (n + 1) → Type*} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ)
(i : Fin n) (y : α i.succ) (z : α 0)
lemma pi_lex_lt_cons_cons {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ}
(s : ∀ {i : Fin n.succ}, α i → α i → Prop) :
Pi.Lex (· < ·) (@s) (Fin.cons x₀ x) (Fin.cons y₀ y) ↔
s x₀ y₀ ∨ x₀ = y₀ ∧ Pi.Lex (· < ·) (@fun i : Fin n ↦ @s i.succ) x y := by
simp_rw [Pi.Lex, Fin.exists_fin_succ, Fin.cons_succ, Fin.cons_zero, Fin.forall_fin_succ]
simp [and_assoc, exists_and_left]
variable [∀ i, Preorder (α i)]
lemma insertNth_mem_Icc {i : Fin (n + 1)} {x : α i} {p : ∀ j, α (i.succAbove j)}
{q₁ q₂ : ∀ j, α j} :
i.insertNth x p ∈ Icc q₁ q₂ ↔
x ∈ Icc (q₁ i) (q₂ i) ∧ p ∈ Icc (fun j ↦ q₁ (i.succAbove j)) fun j ↦ q₂ (i.succAbove j) := by
simp only [mem_Icc, insertNth_le_iff, le_insertNth_iff, and_assoc, @and_left_comm (x ≤ q₂ i)]
lemma preimage_insertNth_Icc_of_mem {i : Fin (n + 1)} {x : α i} {q₁ q₂ : ∀ j, α j}
(hx : x ∈ Icc (q₁ i) (q₂ i)) :
i.insertNth x ⁻¹' Icc q₁ q₂ = Icc (fun j ↦ q₁ (i.succAbove j)) fun j ↦ q₂ (i.succAbove j) :=
Set.ext fun p ↦ by simp only [mem_preimage, insertNth_mem_Icc, hx, true_and_iff]
lemma preimage_insertNth_Icc_of_not_mem {i : Fin (n + 1)} {x : α i} {q₁ q₂ : ∀ j, α j}
(hx : x ∉ Icc (q₁ i) (q₂ i)) : i.insertNth x ⁻¹' Icc q₁ q₂ = ∅ :=
Set.ext fun p ↦ by
simp only [mem_preimage, insertNth_mem_Icc, hx, false_and_iff, mem_empty_iff_false]
end Fin
open Set Fin Matrix Function
variable {α : Type*}
lemma liftFun_vecCons {n : ℕ} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} {a : α} :
((· < ·) ⇒ r) (vecCons a f) (vecCons a f) ↔ r a (f 0) ∧ ((· < ·) ⇒ r) f f := by
simp only [liftFun_iff_succ r, forall_fin_succ, cons_val_succ, cons_val_zero, ← succ_castSucc,
castSucc_zero]
variable [Preorder α] {n : ℕ} {f : Fin (n + 1) → α} {a : α}
@[simp] lemma strictMono_vecCons : StrictMono (vecCons a f) ↔ a < f 0 ∧ StrictMono f :=
liftFun_vecCons (· < ·)
@[simp]
lemma monotone_vecCons : Monotone (vecCons a f) ↔ a ≤ f 0 ∧ Monotone f := by
simpa only [monotone_iff_forall_lt] using @liftFun_vecCons α n (· ≤ ·) _ f a
@[simp] lemma monotone_vecEmpty : Monotone ![a]
| ⟨0, _⟩, ⟨0, _⟩, _ => le_refl _
@[simp] lemma strictMono_vecEmpty : StrictMono ![a]
| ⟨0, _⟩, ⟨0, _⟩, h => (irrefl _ h).elim
@[simp] lemma strictAnti_vecCons : StrictAnti (vecCons a f) ↔ f 0 < a ∧ StrictAnti f :=
liftFun_vecCons (· > ·)
@[simp] lemma antitone_vecCons : Antitone (vecCons a f) ↔ f 0 ≤ a ∧ Antitone f :=
monotone_vecCons (α := αᵒᵈ)
@[simp] lemma antitone_vecEmpty : Antitone (vecCons a vecEmpty)
| ⟨0, _⟩, ⟨0, _⟩, _ => le_rfl
@[simp] lemma strictAnti_vecEmpty : StrictAnti (vecCons a vecEmpty)
| ⟨0, _⟩, ⟨0, _⟩, h => (irrefl _ h).elim
lemma StrictMono.vecCons (hf : StrictMono f) (ha : a < f 0) : StrictMono (vecCons a f) :=
strictMono_vecCons.2 ⟨ha, hf⟩
lemma StrictAnti.vecCons (hf : StrictAnti f) (ha : f 0 < a) : StrictAnti (vecCons a f) :=
strictAnti_vecCons.2 ⟨ha, hf⟩
lemma Monotone.vecCons (hf : Monotone f) (ha : a ≤ f 0) : Monotone (vecCons a f) :=
monotone_vecCons.2 ⟨ha, hf⟩
lemma Antitone.vecCons (hf : Antitone f) (ha : f 0 ≤ a) : Antitone (vecCons a f) :=
antitone_vecCons.2 ⟨ha, hf⟩
example : Monotone ![1, 2, 2, 3] := by decide
variable {n : ℕ}
/-- `Π i : Fin 2, α i` is order equivalent to `α 0 × α 1`. See also `OrderIso.finTwoArrowEquiv`
for a non-dependent version. -/
def OrderIso.piFinTwoIso (α : Fin 2 → Type*) [∀ i, Preorder (α i)] : (∀ i, α i) ≃o α 0 × α 1 where
toEquiv := piFinTwoEquiv α
map_rel_iff' := Iff.symm Fin.forall_fin_two
/-- The space of functions `Fin 2 → α` is order equivalent to `α × α`. See also
`OrderIso.piFinTwoIso`. -/
def OrderIso.finTwoArrowIso (α : Type*) [Preorder α] : (Fin 2 → α) ≃o α × α :=
{ OrderIso.piFinTwoIso fun _ => α with toEquiv := finTwoArrowEquiv α }
/-- Order isomorphism between `Π j : Fin (n + 1), α j` and
`α i × Π j : Fin n, α (Fin.succAbove i j)`. -/
def OrderIso.piFinSuccAboveIso (α : Fin (n + 1) → Type*) [∀ i, LE (α i)]
(i : Fin (n + 1)) : (∀ j, α j) ≃o α i × ∀ j, α (i.succAbove j) where
toEquiv := Equiv.piFinSuccAbove α i
map_rel_iff' := Iff.symm i.forall_iff_succAbove
/-- `Fin.succAbove` as an order isomorphism between `Fin n` and `{x : Fin (n + 1) // x ≠ p}`. -/
def finSuccAboveOrderIso (p : Fin (n + 1)) : Fin n ≃o { x : Fin (n + 1) // x ≠ p } where
__ := finSuccAboveEquiv p
map_rel_iff' := p.succAboveOrderEmb.map_rel_iff'
lemma finSuccAboveOrderIso_apply (p : Fin (n + 1)) (i : Fin n) :
finSuccAboveOrderIso p i = ⟨p.succAbove i, p.succAbove_ne i⟩ := rfl
lemma finSuccAboveOrderIso_symm_apply_last (x : { x : Fin (n + 1) // x ≠ Fin.last n }) :
(finSuccAboveOrderIso (Fin.last n)).symm x = Fin.castLT x.1 (Fin.val_lt_last x.2) := by
rw [← Option.some_inj]
simpa [finSuccAboveOrderIso, finSuccAboveEquiv, OrderIso.symm]
using finSuccEquiv'_last_apply x.property
lemma finSuccAboveOrderIso_symm_apply_ne_last {p : Fin (n + 1)} (h : p ≠ Fin.last n)
(x : { x : Fin (n + 1) // x ≠ p }) :
(finSuccAboveEquiv p).symm x = (p.castLT (Fin.val_lt_last h)).predAbove x := by
rw [← Option.some_inj]
simpa [finSuccAboveEquiv, OrderIso.symm] using finSuccEquiv'_ne_last_apply h x.property
/-- Promote a `Fin n` into a larger `Fin m`, as a subtype where the underlying
values are retained. This is the `OrderIso` version of `Fin.castLE`. -/
@[simps apply symm_apply]
def Fin.castLEOrderIso {n m : ℕ} (h : n ≤ m) : Fin n ≃o { i : Fin m // (i : ℕ) < n } where
toFun i := ⟨Fin.castLE h i, by simp⟩
invFun i := ⟨i, i.prop⟩
left_inv _ := by simp
right_inv _ := by simp
map_rel_iff' := by simp [(strictMono_castLE h).le_iff_le]
|
Order\Heyting\Basic.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.PropInstances
/-!
# Heyting algebras
This file defines Heyting, co-Heyting and bi-Heyting algebras.
A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that
`a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`.
Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬`
such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`.
Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras.
From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean
algebras model classical logic.
Heyting algebras are the order theoretic equivalent of cartesian-closed categories.
## Main declarations
* `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation).
* `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement).
* `HeytingAlgebra`: Heyting algebra.
* `CoheytingAlgebra`: Co-Heyting algebra.
* `BiheytingAlgebra`: bi-Heyting algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
## Tags
Heyting, Brouwer, algebra, implication, negation, intuitionistic
-/
open Function OrderDual
universe u
variable {ι α β : Type*}
/-! ### Notation -/
section
variable (α β)
instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) :=
⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩
instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) :=
⟨fun a => (¬a.1, ¬a.2)⟩
instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) :=
⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩
instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) :=
⟨fun a => (a.1ᶜ, a.2ᶜ)⟩
end
@[simp]
theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 :=
rfl
@[simp]
theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 :=
rfl
@[simp]
theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 :=
rfl
@[simp]
theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 :=
rfl
@[simp]
theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 :=
rfl
@[simp]
theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 :=
rfl
@[simp]
theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ :=
rfl
@[simp]
theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ :=
rfl
namespace Pi
variable {π : ι → Type*}
instance [∀ i, HImp (π i)] : HImp (∀ i, π i) :=
⟨fun a b i => a i ⇨ b i⟩
instance [∀ i, HNot (π i)] : HNot (∀ i, π i) :=
⟨fun a i => ¬a i⟩
theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i :=
rfl
theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i :=
rfl
@[simp]
theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i :=
rfl
@[simp]
theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i :=
rfl
end Pi
/-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called
Heyting implication such that `a ⇨` is right adjoint to `a ⊓`.
This generalizes `HeytingAlgebra` by not requiring a bottom element. -/
class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c
/-- A generalized co-Heyting algebra is a lattice with an additional binary
difference operation `\` such that `\ a` is right adjoint to `⊔ a`.
This generalizes `CoheytingAlgebra` by not requiring a top element. -/
class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting
implication such that `a ⇨` is right adjoint to `a ⊓`. -/
class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where
/-- `a ⇨` is right adjoint to `a ⊓` -/
himp_bot (a : α) : a ⇨ ⊥ = aᶜ
/-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\`
such that `\ a` is right adjoint to `⊔ a`. -/
class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where
/-- `\ a` is right adjoint to `⊔ a` -/
sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a
-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot
-- See note [lower instance priority]
instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α :=
{ bot_le := ‹HeytingAlgebra α›.bot_le }
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α :=
{ ‹CoheytingAlgebra α› with }
-- See note [lower instance priority]
instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] :
CoheytingAlgebra α :=
{ ‹BiheytingAlgebra α› with }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
himp,
compl := fun a => himp a ⊥,
le_himp_iff,
himp_bot := fun a => rfl }
-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α)
(le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where
himp := (compl · ⊔ ·)
compl := compl
le_himp_iff := le_himp_iff
himp_bot _ := sup_bot_eq _
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/
abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α)
(sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
sdiff,
hnot := fun a => sdiff ⊤ a,
sdiff_le_iff,
top_sdiff := fun a => rfl }
-- See note [reducible non-instances]
/-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/
abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α)
(sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where
sdiff a b := a ⊓ hnot b
hnot := hnot
sdiff_le_iff := sdiff_le_iff
top_sdiff _ := top_inf_eq _
/-! In this section, we'll give interpretations of these results in the Heyting algebra model of
intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and",
`⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are
the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] {a b c d : α}
/-- `p → q → r ↔ p ∧ q → r` -/
@[simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _
/-- `p → q → r ↔ q ∧ p → r` -/
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
/-- `p → q → r ↔ q → p → r` -/
theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff']
/-- `p → q → p` -/
theorem le_himp : a ≤ b ⇨ a :=
le_himp_iff.2 inf_le_left
/-- `p → p → q ↔ p → q` -/
theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem]
/-- `p → p` -/
@[simp]
theorem himp_self : a ⇨ a = ⊤ :=
top_le_iff.1 <| le_himp_iff.2 inf_le_right
/-- `(p → q) ∧ p → q` -/
theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b :=
le_himp_iff.1 le_rfl
/-- `p ∧ (p → q) → q` -/
theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff]
/-- `p ∧ (p → q) ↔ p ∧ q` -/
@[simp]
theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b :=
le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp
/-- `(p → q) ∧ p ↔ q ∧ p` -/
@[simp]
theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm]
/-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic:
an implication holds iff the conclusion follows from the hypothesis. -/
@[simp]
theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq]
/-- `p → true`, `true → p ↔ p` -/
@[simp]
theorem himp_top : a ⇨ ⊤ = ⊤ :=
himp_eq_top_iff.2 le_top
@[simp]
theorem top_himp : ⊤ ⇨ a = a :=
eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq]
/-- `p → q → r ↔ p ∧ q → r` -/
theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc]
/-- `(q → r) → (p → q) → q → r` -/
theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by
rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc]
exact inf_le_left
@[simp]
theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by
simpa using @himp_le_himp_himp_himp
/-- `p → q → r ↔ q → p → r` -/
theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm]
@[simp]
theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem]
theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) :=
eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff]
theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) :=
eq_of_forall_le_iff fun d => by
rw [le_inf_iff, le_himp_comm, sup_le_iff]
simp_rw [le_himp_comm]
theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b :=
le_himp_iff.2 <| himp_inf_le.trans h
theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c :=
le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le
theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d :=
(himp_le_himp_right hab).trans <| himp_le_himp_left hcd
@[simp]
theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by
rw [sup_himp_distrib, himp_self, top_inf_eq]
@[simp]
theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by
rw [sup_himp_distrib, himp_self, inf_top_eq]
theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by
conv_rhs => rw [← @top_himp _ _ a]
rw [← h.eq_top, sup_himp_self_left]
theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b :=
h.symm.himp_eq_right
theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by
rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left]
theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by
rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right]
/-- See `himp_le` for a stronger version in Boolean algebras. -/
theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a :=
(himp_le_himp_left hba).trans_eq hac.himp_eq_right
theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b :=
le_himp_iff.2 inf_himp_le
@[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff]
lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not
theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by
rw [le_himp_iff, inf_right_comm, ← le_himp_iff]
exact himp_inf_le.trans le_himp_himp
theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c :=
(himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba)
-- See note [lower instance priority]
instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α :=
DistribLattice.ofInfSupLe fun a b c => by
simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl
instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where
sdiff a b := toDual (ofDual b ⇨ ofDual a)
sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff
instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] :
GeneralizedHeytingAlgebra (α × β) where
le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff
instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] :
GeneralizedHeytingAlgebra (∀ i, α i) where
le_himp_iff i := by simp [le_def]
end GeneralizedHeytingAlgebra
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] {a b c d : α}
@[simp]
theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c :=
GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _
theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm]
theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff']
theorem sdiff_le : a \ b ≤ a :=
sdiff_le_iff.2 le_sup_right
theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b :=
h.mono_left sdiff_le
theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) :=
h.mono_right sdiff_le
theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem]
@[simp]
theorem sdiff_self : a \ a = ⊥ :=
le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left
theorem le_sup_sdiff : a ≤ b ⊔ a \ b :=
sdiff_le_iff.1 le_rfl
theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff]
theorem sup_sdiff_left : a ⊔ a \ b = a :=
sup_of_le_left sdiff_le
theorem sup_sdiff_right : a \ b ⊔ a = a :=
sup_of_le_right sdiff_le
theorem inf_sdiff_left : a \ b ⊓ a = a \ b :=
inf_of_le_left sdiff_le
theorem inf_sdiff_right : a ⊓ a \ b = a \ b :=
inf_of_le_right sdiff_le
@[simp]
theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b :=
le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff)
@[simp]
theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm]
alias sup_sdiff_self_left := sdiff_sup_self
alias sup_sdiff_self_right := sup_sdiff_self
theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b :=
sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _
-- cf. `Set.union_diff_cancel'`
theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by
rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc]
theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b :=
sup_sdiff_cancel' le_rfl h
theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h]
theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c :=
sup_le hac <| h.trans sdiff_le
theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c :=
sup_le (h.trans sdiff_le) hbc
@[simp]
theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq]
@[simp]
theorem sdiff_bot : a \ ⊥ = a :=
eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq]
@[simp]
theorem bot_sdiff : ⊥ \ a = ⊥ :=
sdiff_eq_bot_iff.2 bot_le
theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by
rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self,
sup_left_comm]
exact le_sup_left
@[simp]
theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by
simpa using @sdiff_sdiff_sdiff_le_sdiff
theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) :=
eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc]
theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) :=
sdiff_sdiff _ _ _
theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by
simp_rw [sdiff_sdiff, sup_comm]
theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b :=
sdiff_right_comm _ _ _
@[simp]
theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem]
@[simp]
theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff]
theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c :=
eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff]
theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c :=
eq_of_forall_ge_iff fun d => by
rw [sup_le_iff, sdiff_le_comm, le_inf_iff]
simp_rw [sdiff_le_comm]
theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c :=
sup_sdiff_distrib _ _ _
@[simp]
theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by rw [sup_sdiff, sdiff_self, sup_bot_eq]
@[simp]
theorem sup_sdiff_left_self : (a ⊔ b) \ a = b \ a := by rw [sup_comm, sup_sdiff_right_self]
@[gcongr]
theorem sdiff_le_sdiff_right (h : a ≤ b) : a \ c ≤ b \ c :=
sdiff_le_iff.2 <| h.trans <| le_sup_sdiff
@[gcongr]
theorem sdiff_le_sdiff_left (h : a ≤ b) : c \ b ≤ c \ a :=
sdiff_le_iff.2 <| le_sup_sdiff.trans <| sup_le_sup_right h _
@[gcongr]
theorem sdiff_le_sdiff (hab : a ≤ b) (hcd : c ≤ d) : a \ d ≤ b \ c :=
(sdiff_le_sdiff_right hab).trans <| sdiff_le_sdiff_left hcd
-- cf. `IsCompl.inf_sup`
theorem sdiff_inf : a \ (b ⊓ c) = a \ b ⊔ a \ c :=
sdiff_inf_distrib _ _ _
@[simp]
theorem sdiff_inf_self_left (a b : α) : a \ (a ⊓ b) = a \ b := by
rw [sdiff_inf, sdiff_self, bot_sup_eq]
@[simp]
theorem sdiff_inf_self_right (a b : α) : b \ (a ⊓ b) = b \ a := by
rw [sdiff_inf, sdiff_self, sup_bot_eq]
theorem Disjoint.sdiff_eq_left (h : Disjoint a b) : a \ b = a := by
conv_rhs => rw [← @sdiff_bot _ _ a]
rw [← h.eq_bot, sdiff_inf_self_left]
theorem Disjoint.sdiff_eq_right (h : Disjoint a b) : b \ a = b :=
h.symm.sdiff_eq_left
theorem Disjoint.sup_sdiff_cancel_left (h : Disjoint a b) : (a ⊔ b) \ a = b := by
rw [sup_sdiff, sdiff_self, bot_sup_eq, h.sdiff_eq_right]
theorem Disjoint.sup_sdiff_cancel_right (h : Disjoint a b) : (a ⊔ b) \ b = a := by
rw [sup_sdiff, sdiff_self, sup_bot_eq, h.sdiff_eq_left]
/-- See `le_sdiff` for a stronger version in generalised Boolean algebras. -/
theorem Disjoint.le_sdiff_of_le_left (hac : Disjoint a c) (hab : a ≤ b) : a ≤ b \ c :=
hac.sdiff_eq_left.ge.trans <| sdiff_le_sdiff_right hab
theorem sdiff_sdiff_le : a \ (a \ b) ≤ b :=
sdiff_le_iff.2 le_sdiff_sup
@[simp] lemma sdiff_eq_sdiff_iff : a \ b = b \ a ↔ a = b := by simp [le_antisymm_iff]
lemma sdiff_ne_sdiff_iff : a \ b ≠ b \ a ↔ a ≠ b := sdiff_eq_sdiff_iff.not
theorem sdiff_triangle (a b c : α) : a \ c ≤ a \ b ⊔ b \ c := by
rw [sdiff_le_iff, sup_left_comm, ← sdiff_le_iff]
exact sdiff_sdiff_le.trans le_sup_sdiff
theorem sdiff_sup_sdiff_cancel (hba : b ≤ a) (hcb : c ≤ b) : a \ b ⊔ b \ c = a \ c :=
(sdiff_triangle _ _ _).antisymm' <| sup_le (sdiff_le_sdiff_left hcb) (sdiff_le_sdiff_right hba)
theorem sdiff_le_sdiff_of_sup_le_sup_left (h : c ⊔ a ≤ c ⊔ b) : a \ c ≤ b \ c := by
rw [← sup_sdiff_left_self, ← @sup_sdiff_left_self _ _ _ b]
exact sdiff_le_sdiff_right h
theorem sdiff_le_sdiff_of_sup_le_sup_right (h : a ⊔ c ≤ b ⊔ c) : a \ c ≤ b \ c := by
rw [← sup_sdiff_right_self, ← @sup_sdiff_right_self _ _ b]
exact sdiff_le_sdiff_right h
@[simp]
theorem inf_sdiff_sup_left : a \ c ⊓ (a ⊔ b) = a \ c :=
inf_of_le_left <| sdiff_le.trans le_sup_left
@[simp]
theorem inf_sdiff_sup_right : a \ c ⊓ (b ⊔ a) = a \ c :=
inf_of_le_left <| sdiff_le.trans le_sup_right
-- See note [lower instance priority]
instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : DistribLattice α :=
{ ‹GeneralizedCoheytingAlgebra α› with
le_sup_inf :=
fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl }
instance OrderDual.instGeneralizedHeytingAlgebra : GeneralizedHeytingAlgebra αᵒᵈ where
himp := fun a b => toDual (ofDual b \ ofDual a)
le_himp_iff := fun a b c => by rw [inf_comm]; exact sdiff_le_iff
instance Prod.instGeneralizedCoheytingAlgebra [GeneralizedCoheytingAlgebra β] :
GeneralizedCoheytingAlgebra (α × β) where
sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff
instance Pi.instGeneralizedCoheytingAlgebra {α : ι → Type*}
[∀ i, GeneralizedCoheytingAlgebra (α i)] : GeneralizedCoheytingAlgebra (∀ i, α i) where
sdiff_le_iff i := by simp [le_def]
end GeneralizedCoheytingAlgebra
section HeytingAlgebra
variable [HeytingAlgebra α] {a b c : α}
@[simp]
theorem himp_bot (a : α) : a ⇨ ⊥ = aᶜ :=
HeytingAlgebra.himp_bot _
@[simp]
theorem bot_himp (a : α) : ⊥ ⇨ a = ⊤ :=
himp_eq_top_iff.2 bot_le
theorem compl_sup_distrib (a b : α) : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := by
simp_rw [← himp_bot, sup_himp_distrib]
@[simp]
theorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ :=
compl_sup_distrib _ _
theorem compl_le_himp : aᶜ ≤ a ⇨ b :=
(himp_bot _).ge.trans <| himp_le_himp_left bot_le
theorem compl_sup_le_himp : aᶜ ⊔ b ≤ a ⇨ b :=
sup_le compl_le_himp le_himp
theorem sup_compl_le_himp : b ⊔ aᶜ ≤ a ⇨ b :=
sup_le le_himp compl_le_himp
-- `p → ¬ p ↔ ¬ p`
@[simp]
theorem himp_compl (a : α) : a ⇨ aᶜ = aᶜ := by rw [← himp_bot, himp_himp, inf_idem]
-- `p → ¬ q ↔ q → ¬ p`
theorem himp_compl_comm (a b : α) : a ⇨ bᶜ = b ⇨ aᶜ := by simp_rw [← himp_bot, himp_left_comm]
theorem le_compl_iff_disjoint_right : a ≤ bᶜ ↔ Disjoint a b := by
rw [← himp_bot, le_himp_iff, disjoint_iff_inf_le]
theorem le_compl_iff_disjoint_left : a ≤ bᶜ ↔ Disjoint b a :=
le_compl_iff_disjoint_right.trans disjoint_comm
theorem le_compl_comm : a ≤ bᶜ ↔ b ≤ aᶜ := by
rw [le_compl_iff_disjoint_right, le_compl_iff_disjoint_left]
alias ⟨_, Disjoint.le_compl_right⟩ := le_compl_iff_disjoint_right
alias ⟨_, Disjoint.le_compl_left⟩ := le_compl_iff_disjoint_left
alias le_compl_iff_le_compl := le_compl_comm
alias ⟨le_compl_of_le_compl, _⟩ := le_compl_comm
theorem disjoint_compl_left : Disjoint aᶜ a :=
disjoint_iff_inf_le.mpr <| le_himp_iff.1 (himp_bot _).ge
theorem disjoint_compl_right : Disjoint a aᶜ :=
disjoint_compl_left.symm
theorem LE.le.disjoint_compl_left (h : b ≤ a) : Disjoint aᶜ b :=
_root_.disjoint_compl_left.mono_right h
theorem LE.le.disjoint_compl_right (h : a ≤ b) : Disjoint a bᶜ :=
_root_.disjoint_compl_right.mono_left h
theorem IsCompl.compl_eq (h : IsCompl a b) : aᶜ = b :=
h.1.le_compl_left.antisymm' <| Disjoint.le_of_codisjoint disjoint_compl_left h.2
theorem IsCompl.eq_compl (h : IsCompl a b) : a = bᶜ :=
h.1.le_compl_right.antisymm <| Disjoint.le_of_codisjoint disjoint_compl_left h.2.symm
theorem compl_unique (h₀ : a ⊓ b = ⊥) (h₁ : a ⊔ b = ⊤) : aᶜ = b :=
(IsCompl.of_eq h₀ h₁).compl_eq
@[simp]
theorem inf_compl_self (a : α) : a ⊓ aᶜ = ⊥ :=
disjoint_compl_right.eq_bot
@[simp]
theorem compl_inf_self (a : α) : aᶜ ⊓ a = ⊥ :=
disjoint_compl_left.eq_bot
theorem inf_compl_eq_bot : a ⊓ aᶜ = ⊥ :=
inf_compl_self _
theorem compl_inf_eq_bot : aᶜ ⊓ a = ⊥ :=
compl_inf_self _
@[simp]
theorem compl_top : (⊤ : α)ᶜ = ⊥ :=
eq_of_forall_le_iff fun a => by rw [le_compl_iff_disjoint_right, disjoint_top, le_bot_iff]
@[simp]
theorem compl_bot : (⊥ : α)ᶜ = ⊤ := by rw [← himp_bot, himp_self]
@[simp] theorem le_compl_self : a ≤ aᶜ ↔ a = ⊥ := by
rw [le_compl_iff_disjoint_left, disjoint_self]
@[simp] theorem ne_compl_self [Nontrivial α] : a ≠ aᶜ := by
intro h
cases le_compl_self.1 (le_of_eq h)
simp at h
@[simp] theorem compl_ne_self [Nontrivial α] : aᶜ ≠ a :=
ne_comm.1 ne_compl_self
@[simp] theorem lt_compl_self [Nontrivial α] : a < aᶜ ↔ a = ⊥ := by
rw [lt_iff_le_and_ne]; simp
theorem le_compl_compl : a ≤ aᶜᶜ :=
disjoint_compl_right.le_compl_right
theorem compl_anti : Antitone (compl : α → α) := fun _ _ h =>
le_compl_comm.1 <| h.trans le_compl_compl
@[gcongr]
theorem compl_le_compl (h : a ≤ b) : bᶜ ≤ aᶜ :=
compl_anti h
@[simp]
theorem compl_compl_compl (a : α) : aᶜᶜᶜ = aᶜ :=
(compl_anti le_compl_compl).antisymm le_compl_compl
@[simp]
theorem disjoint_compl_compl_left_iff : Disjoint aᶜᶜ b ↔ Disjoint a b := by
simp_rw [← le_compl_iff_disjoint_left, compl_compl_compl]
@[simp]
theorem disjoint_compl_compl_right_iff : Disjoint a bᶜᶜ ↔ Disjoint a b := by
simp_rw [← le_compl_iff_disjoint_right, compl_compl_compl]
theorem compl_sup_compl_le : aᶜ ⊔ bᶜ ≤ (a ⊓ b)ᶜ :=
sup_le (compl_anti inf_le_left) <| compl_anti inf_le_right
theorem compl_compl_inf_distrib (a b : α) : (a ⊓ b)ᶜᶜ = aᶜᶜ ⊓ bᶜᶜ := by
refine ((compl_anti compl_sup_compl_le).trans (compl_sup_distrib _ _).le).antisymm ?_
rw [le_compl_iff_disjoint_right, disjoint_assoc, disjoint_compl_compl_left_iff,
disjoint_left_comm, disjoint_compl_compl_left_iff, ← disjoint_assoc, inf_comm]
exact disjoint_compl_right
theorem compl_compl_himp_distrib (a b : α) : (a ⇨ b)ᶜᶜ = aᶜᶜ ⇨ bᶜᶜ := by
apply le_antisymm
· rw [le_himp_iff, ← compl_compl_inf_distrib]
exact compl_anti (compl_anti himp_inf_le)
· refine le_compl_comm.1 ((compl_anti compl_sup_le_himp).trans ?_)
rw [compl_sup_distrib, le_compl_iff_disjoint_right, disjoint_right_comm, ←
le_compl_iff_disjoint_right]
exact inf_himp_le
instance OrderDual.instCoheytingAlgebra : CoheytingAlgebra αᵒᵈ where
hnot := toDual ∘ compl ∘ ofDual
sdiff a b := toDual (ofDual b ⇨ ofDual a)
sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff
top_sdiff := @himp_bot α _
@[simp]
theorem ofDual_hnot (a : αᵒᵈ) : ofDual (¬a) = (ofDual a)ᶜ :=
rfl
@[simp]
theorem toDual_compl (a : α) : toDual aᶜ = ¬toDual a :=
rfl
instance Prod.instHeytingAlgebra [HeytingAlgebra β] : HeytingAlgebra (α × β) where
himp_bot a := Prod.ext_iff.2 ⟨himp_bot a.1, himp_bot a.2⟩
instance Pi.instHeytingAlgebra {α : ι → Type*} [∀ i, HeytingAlgebra (α i)] :
HeytingAlgebra (∀ i, α i) where
himp_bot f := funext fun i ↦ himp_bot (f i)
end HeytingAlgebra
section CoheytingAlgebra
variable [CoheytingAlgebra α] {a b c : α}
@[simp]
theorem top_sdiff' (a : α) : ⊤ \ a = ¬a :=
CoheytingAlgebra.top_sdiff _
@[simp]
theorem sdiff_top (a : α) : a \ ⊤ = ⊥ :=
sdiff_eq_bot_iff.2 le_top
theorem hnot_inf_distrib (a b : α) : ¬(a ⊓ b) = ¬a ⊔ ¬b := by
simp_rw [← top_sdiff', sdiff_inf_distrib]
theorem sdiff_le_hnot : a \ b ≤ ¬b :=
(sdiff_le_sdiff_right le_top).trans_eq <| top_sdiff' _
theorem sdiff_le_inf_hnot : a \ b ≤ a ⊓ ¬b :=
le_inf sdiff_le sdiff_le_hnot
-- See note [lower instance priority]
instance (priority := 100) CoheytingAlgebra.toDistribLattice : DistribLattice α :=
{ ‹CoheytingAlgebra α› with
le_sup_inf :=
fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl }
@[simp]
theorem hnot_sdiff (a : α) : ¬a \ a = ¬a := by rw [← top_sdiff', sdiff_sdiff, sup_idem]
theorem hnot_sdiff_comm (a b : α) : ¬a \ b = ¬b \ a := by simp_rw [← top_sdiff', sdiff_right_comm]
theorem hnot_le_iff_codisjoint_right : ¬a ≤ b ↔ Codisjoint a b := by
rw [← top_sdiff', sdiff_le_iff, codisjoint_iff_le_sup]
theorem hnot_le_iff_codisjoint_left : ¬a ≤ b ↔ Codisjoint b a :=
hnot_le_iff_codisjoint_right.trans Codisjoint_comm
theorem hnot_le_comm : ¬a ≤ b ↔ ¬b ≤ a := by
rw [hnot_le_iff_codisjoint_right, hnot_le_iff_codisjoint_left]
alias ⟨_, Codisjoint.hnot_le_right⟩ := hnot_le_iff_codisjoint_right
alias ⟨_, Codisjoint.hnot_le_left⟩ := hnot_le_iff_codisjoint_left
theorem codisjoint_hnot_right : Codisjoint a (¬a) :=
codisjoint_iff_le_sup.2 <| sdiff_le_iff.1 (top_sdiff' _).le
theorem codisjoint_hnot_left : Codisjoint (¬a) a :=
codisjoint_hnot_right.symm
theorem LE.le.codisjoint_hnot_left (h : a ≤ b) : Codisjoint (¬a) b :=
_root_.codisjoint_hnot_left.mono_right h
theorem LE.le.codisjoint_hnot_right (h : b ≤ a) : Codisjoint a (¬b) :=
_root_.codisjoint_hnot_right.mono_left h
theorem IsCompl.hnot_eq (h : IsCompl a b) : ¬a = b :=
h.2.hnot_le_right.antisymm <| Disjoint.le_of_codisjoint h.1.symm codisjoint_hnot_right
theorem IsCompl.eq_hnot (h : IsCompl a b) : a = ¬b :=
h.2.hnot_le_left.antisymm' <| Disjoint.le_of_codisjoint h.1 codisjoint_hnot_right
@[simp]
theorem sup_hnot_self (a : α) : a ⊔ ¬a = ⊤ :=
Codisjoint.eq_top codisjoint_hnot_right
@[simp]
theorem hnot_sup_self (a : α) : ¬a ⊔ a = ⊤ :=
Codisjoint.eq_top codisjoint_hnot_left
@[simp]
theorem hnot_bot : ¬(⊥ : α) = ⊤ :=
eq_of_forall_ge_iff fun a => by rw [hnot_le_iff_codisjoint_left, codisjoint_bot, top_le_iff]
@[simp]
theorem hnot_top : ¬(⊤ : α) = ⊥ := by rw [← top_sdiff', sdiff_self]
theorem hnot_hnot_le : ¬¬a ≤ a :=
codisjoint_hnot_right.hnot_le_left
theorem hnot_anti : Antitone (hnot : α → α) := fun _ _ h => hnot_le_comm.1 <| hnot_hnot_le.trans h
theorem hnot_le_hnot (h : a ≤ b) : ¬b ≤ ¬a :=
hnot_anti h
@[simp]
theorem hnot_hnot_hnot (a : α) : ¬¬¬a = ¬a :=
hnot_hnot_le.antisymm <| hnot_anti hnot_hnot_le
@[simp]
theorem codisjoint_hnot_hnot_left_iff : Codisjoint (¬¬a) b ↔ Codisjoint a b := by
simp_rw [← hnot_le_iff_codisjoint_right, hnot_hnot_hnot]
@[simp]
theorem codisjoint_hnot_hnot_right_iff : Codisjoint a (¬¬b) ↔ Codisjoint a b := by
simp_rw [← hnot_le_iff_codisjoint_left, hnot_hnot_hnot]
theorem le_hnot_inf_hnot : ¬(a ⊔ b) ≤ ¬a ⊓ ¬b :=
le_inf (hnot_anti le_sup_left) <| hnot_anti le_sup_right
theorem hnot_hnot_sup_distrib (a b : α) : ¬¬(a ⊔ b) = ¬¬a ⊔ ¬¬b := by
refine ((hnot_inf_distrib _ _).ge.trans <| hnot_anti le_hnot_inf_hnot).antisymm' ?_
rw [hnot_le_iff_codisjoint_left, codisjoint_assoc, codisjoint_hnot_hnot_left_iff,
codisjoint_left_comm, codisjoint_hnot_hnot_left_iff, ← codisjoint_assoc, sup_comm]
exact codisjoint_hnot_right
theorem hnot_hnot_sdiff_distrib (a b : α) : ¬¬(a \ b) = ¬¬a \ ¬¬b := by
apply le_antisymm
· refine hnot_le_comm.1 ((hnot_anti sdiff_le_inf_hnot).trans' ?_)
rw [hnot_inf_distrib, hnot_le_iff_codisjoint_right, codisjoint_left_comm, ←
hnot_le_iff_codisjoint_right]
exact le_sdiff_sup
· rw [sdiff_le_iff, ← hnot_hnot_sup_distrib]
exact hnot_anti (hnot_anti le_sup_sdiff)
instance OrderDual.instHeytingAlgebra : HeytingAlgebra αᵒᵈ where
compl := toDual ∘ hnot ∘ ofDual
himp a b := toDual (ofDual b \ ofDual a)
le_himp_iff a b c := by rw [inf_comm]; exact sdiff_le_iff
himp_bot := @top_sdiff' α _
@[simp]
theorem ofDual_compl (a : αᵒᵈ) : ofDual aᶜ = ¬ofDual a :=
rfl
@[simp]
theorem ofDual_himp (a b : αᵒᵈ) : ofDual (a ⇨ b) = ofDual b \ ofDual a :=
rfl
@[simp]
theorem toDual_hnot (a : α) : toDual (¬a) = (toDual a)ᶜ :=
rfl
@[simp]
theorem toDual_sdiff (a b : α) : toDual (a \ b) = toDual b ⇨ toDual a :=
rfl
instance Prod.instCoheytingAlgebra [CoheytingAlgebra β] : CoheytingAlgebra (α × β) where
sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff
top_sdiff a := Prod.ext_iff.2 ⟨top_sdiff' a.1, top_sdiff' a.2⟩
instance Pi.instCoheytingAlgebra {α : ι → Type*} [∀ i, CoheytingAlgebra (α i)] :
CoheytingAlgebra (∀ i, α i) where
top_sdiff f := funext fun i ↦ top_sdiff' (f i)
end CoheytingAlgebra
section BiheytingAlgebra
variable [BiheytingAlgebra α] {a : α}
theorem compl_le_hnot : aᶜ ≤ ¬a :=
(disjoint_compl_left : Disjoint _ a).le_of_codisjoint codisjoint_hnot_right
end BiheytingAlgebra
/-- Propositions form a Heyting algebra with implication as Heyting implication and negation as
complement. -/
instance Prop.instHeytingAlgebra : HeytingAlgebra Prop :=
{ Prop.instDistribLattice, Prop.instBoundedOrder with
himp := (· → ·),
le_himp_iff := fun _ _ _ => and_imp.symm, himp_bot := fun _ => rfl }
@[simp]
theorem himp_iff_imp (p q : Prop) : p ⇨ q ↔ p → q :=
Iff.rfl
@[simp]
theorem compl_iff_not (p : Prop) : pᶜ ↔ ¬p :=
Iff.rfl
-- See note [reducible non-instances]
/-- A bounded linear order is a bi-Heyting algebra by setting
* `a ⇨ b = ⊤` if `a ≤ b` and `a ⇨ b = b` otherwise.
* `a \ b = ⊥` if `a ≤ b` and `a \ b = a` otherwise. -/
abbrev LinearOrder.toBiheytingAlgebra [LinearOrder α] [BoundedOrder α] : BiheytingAlgebra α :=
{ LinearOrder.toLattice, ‹BoundedOrder α› with
himp := fun a b => if a ≤ b then ⊤ else b,
compl := fun a => if a = ⊥ then ⊤ else ⊥,
le_himp_iff := fun a b c => by
change _ ≤ ite _ _ _ ↔ _
split_ifs with h
· exact iff_of_true le_top (inf_le_of_right_le h)
· rw [inf_le_iff, or_iff_left h],
himp_bot := fun a => if_congr le_bot_iff rfl rfl, sdiff := fun a b => if a ≤ b then ⊥ else a,
hnot := fun a => if a = ⊤ then ⊥ else ⊤,
sdiff_le_iff := fun a b c => by
change ite _ _ _ ≤ _ ↔ _
split_ifs with h
· exact iff_of_true bot_le (le_sup_of_le_left h)
· rw [le_sup_iff, or_iff_right h],
top_sdiff := fun a => if_congr top_le_iff rfl rfl }
instance OrderDual.instBiheytingAlgebra [BiheytingAlgebra α] : BiheytingAlgebra αᵒᵈ where
__ := instHeytingAlgebra
__ := instCoheytingAlgebra
instance Prod.instBiheytingAlgebra [BiheytingAlgebra α] [BiheytingAlgebra β] :
BiheytingAlgebra (α × β) where
__ := instHeytingAlgebra
__ := instCoheytingAlgebra
instance Pi.instBiheytingAlgebra {α : ι → Type*} [∀ i, BiheytingAlgebra (α i)] :
BiheytingAlgebra (∀ i, α i) where
__ := instHeytingAlgebra
__ := instCoheytingAlgebra
section lift
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedHeytingAlgebra` along an injection. -/
protected abbrev Function.Injective.generalizedHeytingAlgebra [Sup α] [Inf α] [Top α]
[HImp α] [GeneralizedHeytingAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_top : f ⊤ = ⊤) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : GeneralizedHeytingAlgebra α :=
{ __ := hf.lattice f map_sup map_inf
__ := ‹Top α›
__ := ‹HImp α›
le_top := fun a => by
change f _ ≤ _
rw [map_top]
exact le_top,
le_himp_iff := fun a b c => by
change f _ ≤ _ ↔ f _ ≤ _
erw [map_himp, map_inf, le_himp_iff] }
-- See note [reducible non-instances]
/-- Pullback a `GeneralizedCoheytingAlgebra` along an injection. -/
protected abbrev Function.Injective.generalizedCoheytingAlgebra [Sup α] [Inf α] [Bot α]
[SDiff α] [GeneralizedCoheytingAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_bot : f ⊥ = ⊥) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
GeneralizedCoheytingAlgebra α :=
{ __ := hf.lattice f map_sup map_inf
__ := ‹Bot α›
__ := ‹SDiff α›
bot_le := fun a => by
change f _ ≤ _
rw [map_bot]
exact bot_le,
sdiff_le_iff := fun a b c => by
change f _ ≤ _ ↔ f _ ≤ _
erw [map_sdiff, map_sup, sdiff_le_iff] }
-- See note [reducible non-instances]
/-- Pullback a `HeytingAlgebra` along an injection. -/
protected abbrev Function.Injective.heytingAlgebra [Sup α] [Inf α] [Top α] [Bot α]
[HasCompl α] [HImp α] [HeytingAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_compl : ∀ a, f aᶜ = (f a)ᶜ)
(map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : HeytingAlgebra α :=
{ __ := hf.generalizedHeytingAlgebra f map_sup map_inf map_top map_himp
__ := ‹Bot α›
__ := ‹HasCompl α›
bot_le := fun a => by
change f _ ≤ _
rw [map_bot]
exact bot_le,
himp_bot := fun a => hf <| by erw [map_himp, map_compl, map_bot, himp_bot] }
-- See note [reducible non-instances]
/-- Pullback a `CoheytingAlgebra` along an injection. -/
protected abbrev Function.Injective.coheytingAlgebra [Sup α] [Inf α] [Top α] [Bot α]
[HNot α] [SDiff α] [CoheytingAlgebra β] (f : α → β) (hf : Injective f)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b)
(map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) (map_hnot : ∀ a, f (¬a) = ¬f a)
(map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : CoheytingAlgebra α :=
{ __ := hf.generalizedCoheytingAlgebra f map_sup map_inf map_bot map_sdiff
__ := ‹Top α›
__ := ‹HNot α›
le_top := fun a => by
change f _ ≤ _
rw [map_top]
exact le_top,
top_sdiff := fun a => hf <| by erw [map_sdiff, map_hnot, map_top, top_sdiff'] }
-- See note [reducible non-instances]
/-- Pullback a `BiheytingAlgebra` along an injection. -/
protected abbrev Function.Injective.biheytingAlgebra [Sup α] [Inf α] [Top α] [Bot α]
[HasCompl α] [HNot α] [HImp α] [SDiff α] [BiheytingAlgebra β] (f : α → β)
(hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b)
(map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥)
(map_compl : ∀ a, f aᶜ = (f a)ᶜ) (map_hnot : ∀ a, f (¬a) = ¬f a)
(map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) :
BiheytingAlgebra α :=
{ hf.heytingAlgebra f map_sup map_inf map_top map_bot map_compl map_himp,
hf.coheytingAlgebra f map_sup map_inf map_top map_bot map_hnot map_sdiff with }
end lift
namespace PUnit
variable (a b : PUnit.{u + 1})
instance instBiheytingAlgebra : BiheytingAlgebra PUnit.{u+1} :=
{ PUnit.instLinearOrder.{u} with
top := unit,
bot := unit,
sup := fun _ _ => unit,
inf := fun _ _ => unit,
compl := fun _ => unit,
sdiff := fun _ _ => unit,
hnot := fun _ => unit,
himp := fun _ _ => unit,
le_top := fun _ => trivial,
le_sup_left := fun _ _ => trivial,
le_sup_right := fun _ _ => trivial,
sup_le := fun _ _ _ _ _ => trivial,
inf_le_left := fun _ _ => trivial,
inf_le_right := fun _ _ => trivial,
le_inf := fun _ _ _ _ _ => trivial,
bot_le := fun _ => trivial,
le_himp_iff := fun _ _ _ => Iff.rfl,
himp_bot := fun _ => rfl,
top_sdiff := fun _ => rfl,
sdiff_le_iff := fun _ _ _ => Iff.rfl }
@[simp]
theorem top_eq : (⊤ : PUnit) = unit :=
rfl
@[simp]
theorem bot_eq : (⊥ : PUnit) = unit :=
rfl
@[simp, nolint simpNF]
theorem sup_eq : a ⊔ b = unit :=
rfl
@[simp, nolint simpNF]
theorem inf_eq : a ⊓ b = unit :=
rfl
@[simp]
theorem compl_eq : aᶜ = unit :=
rfl
@[simp, nolint simpNF]
theorem sdiff_eq : a \ b = unit :=
rfl
@[simp, nolint simpNF]
theorem hnot_eq : ¬a = unit :=
rfl
-- eligible for `dsimp`
@[simp, nolint simpNF]
theorem himp_eq : a ⇨ b = unit :=
rfl
end PUnit
|
Order\Heyting\Boundary.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Common
/-!
# Co-Heyting boundary
The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation with
itself. The boundary in the co-Heyting algebra of closed sets coincides with the topological
boundary.
## Main declarations
* `Coheyting.boundary`: Co-Heyting boundary. `Coheyting.boundary a = a ⊓ ¬a`
## Notation
`∂ a` is notation for `Coheyting.boundary a` in locale `Heyting`.
-/
variable {α : Type*}
namespace Coheyting
variable [CoheytingAlgebra α] {a b : α}
/-- The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation
with itself. Note that this is always `⊥` for a boolean algebra. -/
def boundary (a : α) : α :=
a ⊓ ¬a
/-- The boundary of an element of a co-Heyting algebra. -/
scoped[Heyting] prefix:120 "∂ " => Coheyting.boundary
-- Porting note: Should the notation be automatically included in the current scope?
open Heyting
-- Porting note: Should hnot be named hNot?
theorem inf_hnot_self (a : α) : a ⊓ ¬a = ∂ a :=
rfl
theorem boundary_le : ∂ a ≤ a :=
inf_le_left
theorem boundary_le_hnot : ∂ a ≤ ¬a :=
inf_le_right
@[simp]
theorem boundary_bot : ∂ (⊥ : α) = ⊥ := bot_inf_eq _
@[simp]
theorem boundary_top : ∂ (⊤ : α) = ⊥ := by rw [boundary, hnot_top, inf_bot_eq]
theorem boundary_hnot_le (a : α) : ∂ (¬a) ≤ ∂ a :=
(inf_comm _ _).trans_le <| inf_le_inf_right _ hnot_hnot_le
@[simp]
theorem boundary_hnot_hnot (a : α) : ∂ (¬¬a) = ∂ (¬a) := by
simp_rw [boundary, hnot_hnot_hnot, inf_comm]
@[simp]
theorem hnot_boundary (a : α) : ¬∂ a = ⊤ := by rw [boundary, hnot_inf_distrib, sup_hnot_self]
/-- **Leibniz rule** for the co-Heyting boundary. -/
theorem boundary_inf (a b : α) : ∂ (a ⊓ b) = ∂ a ⊓ b ⊔ a ⊓ ∂ b := by
unfold boundary
rw [hnot_inf_distrib, inf_sup_left, inf_right_comm, ← inf_assoc]
theorem boundary_inf_le : ∂ (a ⊓ b) ≤ ∂ a ⊔ ∂ b :=
(boundary_inf _ _).trans_le <| sup_le_sup inf_le_left inf_le_right
theorem boundary_sup_le : ∂ (a ⊔ b) ≤ ∂ a ⊔ ∂ b := by
rw [boundary, inf_sup_right]
exact
sup_le_sup (inf_le_inf_left _ <| hnot_anti le_sup_left)
(inf_le_inf_left _ <| hnot_anti le_sup_right)
/- The intuitionistic version of `Coheyting.boundary_le_boundary_sup_sup_boundary_inf_left`. Either
proof can be obtained from the other using the equivalence of Heyting algebras and intuitionistic
logic and duality between Heyting and co-Heyting algebras. It is crucial that the following proof be
intuitionistic. -/
example (a b : Prop) : (a ∧ b ∨ ¬(a ∧ b)) ∧ ((a ∨ b) ∨ ¬(a ∨ b)) → a ∨ ¬a := by
rintro ⟨⟨ha, _⟩ | hnab, (ha | hb) | hnab⟩ <;> try exact Or.inl ha
· exact Or.inr fun ha => hnab ⟨ha, hb⟩
· exact Or.inr fun ha => hnab <| Or.inl ha
theorem boundary_le_boundary_sup_sup_boundary_inf_left : ∂ a ≤ ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) := by
-- Porting note: the following simp generates the same term as mathlib3 if you remove
-- sup_inf_right from both. With sup_inf_right included, mathlib4 and mathlib3 generate
-- different terms
simp only [boundary, sup_inf_left, sup_inf_right, sup_right_idem, le_inf_iff, sup_assoc,
sup_comm _ a]
refine ⟨⟨⟨?_, ?_⟩, ⟨?_, ?_⟩⟩, ?_, ?_⟩ <;> try { exact le_sup_of_le_left inf_le_left } <;>
refine inf_le_of_right_le ?_
· rw [hnot_le_iff_codisjoint_right, codisjoint_left_comm]
exact codisjoint_hnot_left
· refine le_sup_of_le_right ?_
rw [hnot_le_iff_codisjoint_right]
exact codisjoint_hnot_right.mono_right (hnot_anti inf_le_left)
theorem boundary_le_boundary_sup_sup_boundary_inf_right : ∂ b ≤ ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) := by
rw [sup_comm a, inf_comm]
exact boundary_le_boundary_sup_sup_boundary_inf_left
theorem boundary_sup_sup_boundary_inf (a b : α) : ∂ (a ⊔ b) ⊔ ∂ (a ⊓ b) = ∂ a ⊔ ∂ b :=
le_antisymm (sup_le boundary_sup_le boundary_inf_le) <|
sup_le boundary_le_boundary_sup_sup_boundary_inf_left
boundary_le_boundary_sup_sup_boundary_inf_right
@[simp]
theorem boundary_idem (a : α) : ∂ ∂ a = ∂ a := by rw [boundary, hnot_boundary, inf_top_eq]
theorem hnot_hnot_sup_boundary (a : α) : ¬¬a ⊔ ∂ a = a := by
rw [boundary, sup_inf_left, hnot_sup_self, inf_top_eq, sup_eq_right]
exact hnot_hnot_le
theorem hnot_eq_top_iff_exists_boundary : ¬a = ⊤ ↔ ∃ b, ∂ b = a :=
⟨fun h => ⟨a, by rw [boundary, h, inf_top_eq]⟩, by
rintro ⟨b, rfl⟩
exact hnot_boundary _⟩
end Coheyting
open Heyting
section BooleanAlgebra
variable [BooleanAlgebra α]
@[simp]
theorem Coheyting.boundary_eq_bot (a : α) : ∂ a = ⊥ :=
inf_compl_eq_bot
end BooleanAlgebra
|
Order\Heyting\Hom.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Lattice
/-!
# Heyting algebra morphisms
A Heyting homomorphism between two Heyting algebras is a bounded lattice homomorphism that preserves
Heyting implication.
We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `HeytingHom`: Heyting homomorphisms.
* `CoheytingHom`: Co-Heyting homomorphisms.
* `BiheytingHom`: Bi-Heyting homomorphisms.
## Typeclasses
* `HeytingHomClass`
* `CoheytingHomClass`
* `BiheytingHomClass`
-/
open Function
variable {F α β γ δ : Type*}
/-- The type of Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that preserve
Heyting implication. -/
structure HeytingHom (α β : Type*) [HeytingAlgebra α] [HeytingAlgebra β] extends
LatticeHom α β where
/-- The proposition that a Heyting homomorphism preserves the bottom element. -/
protected map_bot' : toFun ⊥ = ⊥
/-- The proposition that a Heyting homomorphism preserves the Heyting implication. -/
protected map_himp' : ∀ a b, toFun (a ⇨ b) = toFun a ⇨ toFun b
/-- The type of co-Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that
preserve difference. -/
structure CoheytingHom (α β : Type*) [CoheytingAlgebra α] [CoheytingAlgebra β] extends
LatticeHom α β where
/-- The proposition that a co-Heyting homomorphism preserves the top element. -/
protected map_top' : toFun ⊤ = ⊤
/-- The proposition that a co-Heyting homomorphism preserves the difference operation. -/
protected map_sdiff' : ∀ a b, toFun (a \ b) = toFun a \ toFun b
/-- The type of bi-Heyting homomorphisms from `α` to `β`. Bounded lattice homomorphisms that
preserve Heyting implication and difference. -/
structure BiheytingHom (α β : Type*) [BiheytingAlgebra α] [BiheytingAlgebra β] extends
LatticeHom α β where
/-- The proposition that a bi-Heyting homomorphism preserves the Heyting implication. -/
protected map_himp' : ∀ a b, toFun (a ⇨ b) = toFun a ⇨ toFun b
/-- The proposition that a bi-Heyting homomorphism preserves the difference operation. -/
protected map_sdiff' : ∀ a b, toFun (a \ b) = toFun a \ toFun b
/-- `HeytingHomClass F α β` states that `F` is a type of Heyting homomorphisms.
You should extend this class when you extend `HeytingHom`. -/
class HeytingHomClass (F α β : Type*) [HeytingAlgebra α] [HeytingAlgebra β] [FunLike F α β]
extends LatticeHomClass F α β : Prop where
/-- The proposition that a Heyting homomorphism preserves the bottom element. -/
map_bot (f : F) : f ⊥ = ⊥
/-- The proposition that a Heyting homomorphism preserves the Heyting implication. -/
map_himp (f : F) : ∀ a b, f (a ⇨ b) = f a ⇨ f b
/-- `CoheytingHomClass F α β` states that `F` is a type of co-Heyting homomorphisms.
You should extend this class when you extend `CoheytingHom`. -/
class CoheytingHomClass (F α β : Type*) [CoheytingAlgebra α] [CoheytingAlgebra β] [FunLike F α β]
extends LatticeHomClass F α β : Prop where
/-- The proposition that a co-Heyting homomorphism preserves the top element. -/
map_top (f : F) : f ⊤ = ⊤
/-- The proposition that a co-Heyting homomorphism preserves the difference operation. -/
map_sdiff (f : F) : ∀ a b, f (a \ b) = f a \ f b
/-- `BiheytingHomClass F α β` states that `F` is a type of bi-Heyting homomorphisms.
You should extend this class when you extend `BiheytingHom`. -/
class BiheytingHomClass (F α β : Type*) [BiheytingAlgebra α] [BiheytingAlgebra β] [FunLike F α β]
extends LatticeHomClass F α β : Prop where
/-- The proposition that a bi-Heyting homomorphism preserves the Heyting implication. -/
map_himp (f : F) : ∀ a b, f (a ⇨ b) = f a ⇨ f b
/-- The proposition that a bi-Heyting homomorphism preserves the difference operation. -/
map_sdiff (f : F) : ∀ a b, f (a \ b) = f a \ f b
export HeytingHomClass (map_himp)
export CoheytingHomClass (map_sdiff)
attribute [simp] map_himp map_sdiff
section Hom
variable [FunLike F α β]
/- Porting note: `[HeytingAlgebra α, β]` -> `{ _ : HeytingAlgebra α, β}` as a dangerous instance fix
similar for Coheyting & Biheyting instances -/
-- See note [lower instance priority]
instance (priority := 100) HeytingHomClass.toBoundedLatticeHomClass [HeytingAlgebra α]
{ _ : HeytingAlgebra β} [HeytingHomClass F α β] : BoundedLatticeHomClass F α β :=
{ ‹HeytingHomClass F α β› with
map_top := fun f => by rw [← @himp_self α _ ⊥, ← himp_self, map_himp] }
-- See note [lower instance priority]
instance (priority := 100) CoheytingHomClass.toBoundedLatticeHomClass [CoheytingAlgebra α]
{ _ : CoheytingAlgebra β} [CoheytingHomClass F α β] : BoundedLatticeHomClass F α β :=
{ ‹CoheytingHomClass F α β› with
map_bot := fun f => by rw [← @sdiff_self α _ ⊤, ← sdiff_self, map_sdiff] }
-- See note [lower instance priority]
instance (priority := 100) BiheytingHomClass.toHeytingHomClass [BiheytingAlgebra α]
{ _ : BiheytingAlgebra β} [BiheytingHomClass F α β] : HeytingHomClass F α β :=
{ ‹BiheytingHomClass F α β› with
map_bot := fun f => by rw [← @sdiff_self α _ ⊤, ← sdiff_self, BiheytingHomClass.map_sdiff] }
-- See note [lower instance priority]
instance (priority := 100) BiheytingHomClass.toCoheytingHomClass [BiheytingAlgebra α]
{ _ : BiheytingAlgebra β} [BiheytingHomClass F α β] : CoheytingHomClass F α β :=
{ ‹BiheytingHomClass F α β› with
map_top := fun f => by rw [← @himp_self α _ ⊥, ← himp_self, map_himp] }
end Hom
section Equiv
variable [EquivLike F α β]
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toHeytingHomClass [HeytingAlgebra α]
{ _ : HeytingAlgebra β} [OrderIsoClass F α β] : HeytingHomClass F α β :=
{ OrderIsoClass.toBoundedLatticeHomClass with
map_himp := fun f a b =>
eq_of_forall_le_iff fun c => by
simp only [← map_inv_le_iff, le_himp_iff]
rw [← OrderIsoClass.map_le_map_iff f]
simp }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toCoheytingHomClass [CoheytingAlgebra α]
{ _ : CoheytingAlgebra β} [OrderIsoClass F α β] : CoheytingHomClass F α β :=
{ OrderIsoClass.toBoundedLatticeHomClass with
map_sdiff := fun f a b =>
eq_of_forall_ge_iff fun c => by
simp only [← le_map_inv_iff, sdiff_le_iff]
rw [← OrderIsoClass.map_le_map_iff f]
simp }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toBiheytingHomClass [BiheytingAlgebra α]
{ _ : BiheytingAlgebra β} [OrderIsoClass F α β] : BiheytingHomClass F α β :=
{ OrderIsoClass.toLatticeHomClass with
map_himp := fun f a b =>
eq_of_forall_le_iff fun c => by
simp only [← map_inv_le_iff, le_himp_iff]
rw [← OrderIsoClass.map_le_map_iff f]
simp
map_sdiff := fun f a b =>
eq_of_forall_ge_iff fun c => by
simp only [← le_map_inv_iff, sdiff_le_iff]
rw [← OrderIsoClass.map_le_map_iff f]
simp }
end Equiv
variable [FunLike F α β]
-- Porting note: Revisit this issue to see if it works in Lean 4.
/-- This can't be an instance because of typeclass loops. -/
lemma BoundedLatticeHomClass.toBiheytingHomClass [BooleanAlgebra α] [BooleanAlgebra β]
[BoundedLatticeHomClass F α β] : BiheytingHomClass F α β :=
{ ‹BoundedLatticeHomClass F α β› with
map_himp := fun f a b => by rw [himp_eq, himp_eq, map_sup, (isCompl_compl.map _).compl_eq]
map_sdiff := fun f a b => by rw [sdiff_eq, sdiff_eq, map_inf, (isCompl_compl.map _).compl_eq] }
section HeytingAlgebra
open scoped symmDiff
variable [HeytingAlgebra α] [HeytingAlgebra β] [HeytingHomClass F α β] (f : F)
@[simp]
theorem map_compl (a : α) : f aᶜ = (f a)ᶜ := by rw [← himp_bot, ← himp_bot, map_himp, map_bot]
@[simp]
theorem map_bihimp (a b : α) : f (a ⇔ b) = f a ⇔ f b := by simp_rw [bihimp, map_inf, map_himp]
-- TODO: `map_bihimp`
end HeytingAlgebra
section CoheytingAlgebra
open scoped symmDiff
variable [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingHomClass F α β] (f : F)
@[simp]
theorem map_hnot (a : α) : f (¬a) = ¬f a := by rw [← top_sdiff', ← top_sdiff', map_sdiff, map_top]
@[simp]
theorem map_symmDiff (a b : α) : f (a ∆ b) = f a ∆ f b := by simp_rw [symmDiff, map_sup, map_sdiff]
end CoheytingAlgebra
instance [HeytingAlgebra α] [HeytingAlgebra β] [HeytingHomClass F α β] : CoeTC F (HeytingHom α β) :=
⟨fun f =>
{ toFun := f
map_sup' := map_sup f
map_inf' := map_inf f
map_bot' := map_bot f
map_himp' := map_himp f }⟩
instance [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingHomClass F α β] :
CoeTC F (CoheytingHom α β) :=
⟨fun f =>
{ toFun := f
map_sup' := map_sup f
map_inf' := map_inf f
map_top' := map_top f
map_sdiff' := map_sdiff f }⟩
instance [BiheytingAlgebra α] [BiheytingAlgebra β] [BiheytingHomClass F α β] :
CoeTC F (BiheytingHom α β) :=
⟨fun f =>
{ toFun := f
map_sup' := map_sup f
map_inf' := map_inf f
map_himp' := map_himp f
map_sdiff' := map_sdiff f }⟩
namespace HeytingHom
variable [HeytingAlgebra α] [HeytingAlgebra β] [HeytingAlgebra γ] [HeytingAlgebra δ]
instance instFunLike : FunLike (HeytingHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr
instance instHeytingHomClass : HeytingHomClass (HeytingHom α β) α β where
map_sup f := f.map_sup'
map_inf f := f.map_inf'
map_bot f := f.map_bot'
map_himp := HeytingHom.map_himp'
-- Porting note: CoeFun undesired here in lean 4
-- /-- Helper instance for when there's too many metavariables to apply `DFunLike.CoeFun`
-- directly. -/
-- instance : CoeFun (HeytingHom α β) fun _ => α → β :=
-- DFunLike.hasCoeToFun
-- @[simp] -- Porting note: not in simp-nf, simp can simplify lhs. Added aux simp lemma
theorem toFun_eq_coe {f : HeytingHom α β} : f.toFun = ⇑f :=
rfl
@[simp]
theorem toFun_eq_coe_aux {f : HeytingHom α β} : (↑f.toLatticeHom) = ⇑f :=
rfl
@[ext]
theorem ext {f g : HeytingHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `HeytingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : HeytingHom α β) (f' : α → β) (h : f' = f) : HeytingHom α β where
toFun := f'
map_sup' := by simpa only [h] using map_sup f
map_inf' := by simpa only [h] using map_inf f
map_bot' := by simpa only [h] using map_bot f
map_himp' := by simpa only [h] using map_himp f
@[simp]
theorem coe_copy (f : HeytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : HeytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `HeytingHom`. -/
protected def id : HeytingHom α α :=
{ BotHom.id _ with
toLatticeHom := LatticeHom.id _
map_himp' := fun _ _ => rfl }
@[simp]
theorem coe_id : ⇑(HeytingHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : HeytingHom.id α a = a :=
rfl
instance : Inhabited (HeytingHom α α) :=
⟨HeytingHom.id _⟩
instance : PartialOrder (HeytingHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
/-- Composition of `HeytingHom`s as a `HeytingHom`. -/
def comp (f : HeytingHom β γ) (g : HeytingHom α β) : HeytingHom α γ :=
{ f.toLatticeHom.comp g.toLatticeHom with
toFun := f ∘ g
map_bot' := by simp
map_himp' := fun a b => by simp }
variable {f f₁ f₂ : HeytingHom α β} {g g₁ g₂ : HeytingHom β γ}
@[simp]
theorem coe_comp (f : HeytingHom β γ) (g : HeytingHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : HeytingHom β γ) (g : HeytingHom α β) (a : α) : f.comp g a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : HeytingHom γ δ) (g : HeytingHom β γ) (h : HeytingHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : HeytingHom α β) : f.comp (HeytingHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : HeytingHom α β) : (HeytingHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => HeytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end HeytingHom
namespace CoheytingHom
variable [CoheytingAlgebra α] [CoheytingAlgebra β] [CoheytingAlgebra γ] [CoheytingAlgebra δ]
instance : FunLike (CoheytingHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr
instance : CoheytingHomClass (CoheytingHom α β) α β where
map_sup f := f.map_sup'
map_inf f := f.map_inf'
map_top f := f.map_top'
map_sdiff := CoheytingHom.map_sdiff'
-- @[simp] -- Porting note: not in simp-nf, simp can simplify lhs. Added aux simp lemma
theorem toFun_eq_coe {f : CoheytingHom α β} : f.toFun = (f : α → β) :=
rfl
@[simp]
theorem toFun_eq_coe_aux {f : CoheytingHom α β} : (↑f.toLatticeHom) = ⇑f :=
rfl
@[ext]
theorem ext {f g : CoheytingHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `CoheytingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : CoheytingHom α β where
toFun := f'
map_sup' := by simpa only [h] using map_sup f
map_inf' := by simpa only [h] using map_inf f
map_top' := by simpa only [h] using map_top f
map_sdiff' := by simpa only [h] using map_sdiff f
@[simp]
theorem coe_copy (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : CoheytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `CoheytingHom`. -/
protected def id : CoheytingHom α α :=
{ TopHom.id _ with
toLatticeHom := LatticeHom.id _
map_sdiff' := fun _ _ => rfl }
@[simp]
theorem coe_id : ⇑(CoheytingHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : CoheytingHom.id α a = a :=
rfl
instance : Inhabited (CoheytingHom α α) :=
⟨CoheytingHom.id _⟩
instance : PartialOrder (CoheytingHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
/-- Composition of `CoheytingHom`s as a `CoheytingHom`. -/
def comp (f : CoheytingHom β γ) (g : CoheytingHom α β) : CoheytingHom α γ :=
{ f.toLatticeHom.comp g.toLatticeHom with
toFun := f ∘ g
map_top' := by simp
map_sdiff' := fun a b => by simp }
variable {f f₁ f₂ : CoheytingHom α β} {g g₁ g₂ : CoheytingHom β γ}
@[simp]
theorem coe_comp (f : CoheytingHom β γ) (g : CoheytingHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : CoheytingHom β γ) (g : CoheytingHom α β) (a : α) : f.comp g a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : CoheytingHom γ δ) (g : CoheytingHom β γ) (h : CoheytingHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : CoheytingHom α β) : f.comp (CoheytingHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : CoheytingHom α β) : (CoheytingHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => CoheytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end CoheytingHom
namespace BiheytingHom
variable [BiheytingAlgebra α] [BiheytingAlgebra β] [BiheytingAlgebra γ] [BiheytingAlgebra δ]
instance : FunLike (BiheytingHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr
instance : BiheytingHomClass (BiheytingHom α β) α β where
map_sup f := f.map_sup'
map_inf f := f.map_inf'
map_himp f := f.map_himp'
map_sdiff f := f.map_sdiff'
-- @[simp] -- Porting note: not in simp-nf, simp can simplify lhs. Added aux simp lemma
theorem toFun_eq_coe {f : BiheytingHom α β} : f.toFun = (f : α → β) :=
rfl
@[simp]
theorem toFun_eq_coe_aux {f : BiheytingHom α β} : (↑f.toLatticeHom) = ⇑f :=
rfl
@[ext]
theorem ext {f g : BiheytingHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `BiheytingHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : BiheytingHom α β where
toFun := f'
map_sup' := by simpa only [h] using map_sup f
map_inf' := by simpa only [h] using map_inf f
map_himp' := by simpa only [h] using map_himp f
map_sdiff' := by simpa only [h] using map_sdiff f
@[simp]
theorem coe_copy (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : BiheytingHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `BiheytingHom`. -/
protected def id : BiheytingHom α α :=
{ HeytingHom.id _, CoheytingHom.id _ with toLatticeHom := LatticeHom.id _ }
@[simp]
theorem coe_id : ⇑(BiheytingHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : BiheytingHom.id α a = a :=
rfl
instance : Inhabited (BiheytingHom α α) :=
⟨BiheytingHom.id _⟩
instance : PartialOrder (BiheytingHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
/-- Composition of `BiheytingHom`s as a `BiheytingHom`. -/
def comp (f : BiheytingHom β γ) (g : BiheytingHom α β) : BiheytingHom α γ :=
{ f.toLatticeHom.comp g.toLatticeHom with
toFun := f ∘ g
map_himp' := fun a b => by simp
map_sdiff' := fun a b => by simp }
variable {f f₁ f₂ : BiheytingHom α β} {g g₁ g₂ : BiheytingHom β γ}
@[simp]
theorem coe_comp (f : BiheytingHom β γ) (g : BiheytingHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : BiheytingHom β γ) (g : BiheytingHom α β) (a : α) : f.comp g a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : BiheytingHom γ δ) (g : BiheytingHom β γ) (h : BiheytingHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : BiheytingHom α β) : f.comp (BiheytingHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : BiheytingHom α β) : (BiheytingHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => BiheytingHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end BiheytingHom
|
Order\Heyting\Regular.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.GaloisConnection
/-!
# Heyting regular elements
This file defines Heyting regular elements, elements of a Heyting algebra that are their own double
complement, and proves that they form a boolean algebra.
From a logic standpoint, this means that we can perform classical logic within intuitionistic logic
by simply double-negating all propositions. This is practical for synthetic computability theory.
## Main declarations
* `IsRegular`: `a` is Heyting-regular if `aᶜᶜ = a`.
* `Regular`: The subtype of Heyting-regular elements.
* `Regular.BooleanAlgebra`: Heyting-regular elements form a boolean algebra.
## References
* [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3]
-/
open Function
variable {α : Type*}
namespace Heyting
section HasCompl
variable [HasCompl α] {a : α}
/-- An element of a Heyting algebra is regular if its double complement is itself. -/
def IsRegular (a : α) : Prop :=
aᶜᶜ = a
protected theorem IsRegular.eq : IsRegular a → aᶜᶜ = a :=
id
instance IsRegular.decidablePred [DecidableEq α] : @DecidablePred α IsRegular := fun _ =>
‹DecidableEq α› _ _
end HasCompl
section HeytingAlgebra
variable [HeytingAlgebra α] {a b : α}
theorem isRegular_bot : IsRegular (⊥ : α) := by rw [IsRegular, compl_bot, compl_top]
theorem isRegular_top : IsRegular (⊤ : α) := by rw [IsRegular, compl_top, compl_bot]
theorem IsRegular.inf (ha : IsRegular a) (hb : IsRegular b) : IsRegular (a ⊓ b) := by
rw [IsRegular, compl_compl_inf_distrib, ha.eq, hb.eq]
theorem IsRegular.himp (ha : IsRegular a) (hb : IsRegular b) : IsRegular (a ⇨ b) := by
rw [IsRegular, compl_compl_himp_distrib, ha.eq, hb.eq]
theorem isRegular_compl (a : α) : IsRegular aᶜ :=
compl_compl_compl _
protected theorem IsRegular.disjoint_compl_left_iff (ha : IsRegular a) :
Disjoint aᶜ b ↔ b ≤ a := by rw [← le_compl_iff_disjoint_left, ha.eq]
protected theorem IsRegular.disjoint_compl_right_iff (hb : IsRegular b) :
Disjoint a bᶜ ↔ a ≤ b := by rw [← le_compl_iff_disjoint_right, hb.eq]
-- See note [reducible non-instances]
/-- A Heyting algebra with regular excluded middle is a boolean algebra. -/
abbrev _root_.BooleanAlgebra.ofRegular (h : ∀ a : α, IsRegular (a ⊔ aᶜ)) : BooleanAlgebra α :=
have : ∀ a : α, IsCompl a aᶜ := fun a =>
⟨disjoint_compl_right,
codisjoint_iff.2 <| by erw [← (h a), compl_sup, inf_compl_eq_bot, compl_bot]⟩
{ ‹HeytingAlgebra α›,
GeneralizedHeytingAlgebra.toDistribLattice with
himp_eq := fun a b =>
eq_of_forall_le_iff fun _ => le_himp_iff.trans (this _).le_sup_right_iff_inf_left_le.symm
inf_compl_le_bot := fun a => (this _).1.le_bot
top_le_sup_compl := fun a => (this _).2.top_le }
variable (α)
/-- The boolean algebra of Heyting regular elements. -/
def Regular : Type _ :=
{ a : α // IsRegular a }
variable {α}
namespace Regular
-- Porting note: `val` and `prop` are new
/-- The coercion `Regular α → α` -/
@[coe] def val : Regular α → α :=
Subtype.val
theorem prop : ∀ a : Regular α, IsRegular a.val := Subtype.prop
instance : CoeOut (Regular α) α := ⟨Regular.val⟩
theorem coe_injective : Injective ((↑) : Regular α → α) :=
Subtype.coe_injective
@[simp]
theorem coe_inj {a b : Regular α} : (a : α) = b ↔ a = b :=
Subtype.coe_inj
instance top : Top (Regular α) :=
⟨⟨⊤, isRegular_top⟩⟩
instance bot : Bot (Regular α) :=
⟨⟨⊥, isRegular_bot⟩⟩
instance inf : Inf (Regular α) :=
⟨fun a b => ⟨a ⊓ b, a.2.inf b.2⟩⟩
instance himp : HImp (Regular α) :=
⟨fun a b => ⟨a ⇨ b, a.2.himp b.2⟩⟩
instance hasCompl : HasCompl (Regular α) :=
⟨fun a => ⟨aᶜ, isRegular_compl _⟩⟩
@[simp, norm_cast]
theorem coe_top : ((⊤ : Regular α) : α) = ⊤ :=
rfl
@[simp, norm_cast]
theorem coe_bot : ((⊥ : Regular α) : α) = ⊥ :=
rfl
@[simp, norm_cast]
theorem coe_inf (a b : Regular α) : (↑(a ⊓ b) : α) = (a : α) ⊓ b :=
rfl
@[simp, norm_cast]
theorem coe_himp (a b : Regular α) : (↑(a ⇨ b) : α) = (a : α) ⇨ b :=
rfl
@[simp, norm_cast]
theorem coe_compl (a : Regular α) : (↑aᶜ : α) = (a : α)ᶜ :=
rfl
instance : Inhabited (Regular α) :=
⟨⊥⟩
instance : SemilatticeInf (Regular α) :=
coe_injective.semilatticeInf _ coe_inf
instance boundedOrder : BoundedOrder (Regular α) :=
BoundedOrder.lift ((↑) : Regular α → α) (fun _ _ => id) coe_top coe_bot
@[simp, norm_cast]
theorem coe_le_coe {a b : Regular α} : (a : α) ≤ b ↔ a ≤ b :=
Iff.rfl
@[simp, norm_cast]
theorem coe_lt_coe {a b : Regular α} : (a : α) < b ↔ a < b :=
Iff.rfl
/-- **Regularization** of `a`. The smallest regular element greater than `a`. -/
def toRegular : α →o Regular α :=
⟨fun a => ⟨aᶜᶜ, isRegular_compl _⟩, fun _ _ h =>
coe_le_coe.1 <| compl_le_compl <| compl_le_compl h⟩
@[simp, norm_cast]
theorem coe_toRegular (a : α) : (toRegular a : α) = aᶜᶜ :=
rfl
@[simp]
theorem toRegular_coe (a : Regular α) : toRegular (a : α) = a :=
coe_injective a.2
/-- The Galois insertion between `Regular.toRegular` and `coe`. -/
def gi : GaloisInsertion toRegular ((↑) : Regular α → α) where
choice a ha := ⟨a, ha.antisymm le_compl_compl⟩
gc _ b :=
coe_le_coe.symm.trans <|
⟨le_compl_compl.trans, fun h => (compl_anti <| compl_anti h).trans_eq b.2⟩
le_l_u _ := le_compl_compl
choice_eq _ ha := coe_injective <| le_compl_compl.antisymm ha
instance lattice : Lattice (Regular α) :=
gi.liftLattice
@[simp, norm_cast]
theorem coe_sup (a b : Regular α) : (↑(a ⊔ b) : α) = ((a : α) ⊔ b)ᶜᶜ :=
rfl
instance : BooleanAlgebra (Regular α) :=
{ Regular.lattice, Regular.boundedOrder, Regular.himp,
Regular.hasCompl with
le_sup_inf := fun a b c =>
coe_le_coe.1 <| by
dsimp
rw [sup_inf_left, compl_compl_inf_distrib]
inf_compl_le_bot := fun a => coe_le_coe.1 <| disjoint_iff_inf_le.1 disjoint_compl_right
top_le_sup_compl := fun a =>
coe_le_coe.1 <| by
dsimp
rw [compl_sup, inf_compl_eq_bot, compl_bot]
himp_eq := fun a b =>
coe_injective
(by
dsimp
rw [compl_sup, a.prop.eq]
refine eq_of_forall_le_iff fun c => le_himp_iff.trans ?_
rw [le_compl_iff_disjoint_right, disjoint_left_comm]
rw [b.prop.disjoint_compl_left_iff]) }
@[simp, norm_cast]
theorem coe_sdiff (a b : Regular α) : (↑(a \ b) : α) = (a : α) ⊓ bᶜ :=
rfl
end Regular
end HeytingAlgebra
variable [BooleanAlgebra α]
theorem isRegular_of_boolean : ∀ a : α, IsRegular a :=
compl_compl
/-- A decidable proposition is intuitionistically Heyting-regular. -/
-- Porting note: removed @[nolint decidable_classical]
theorem isRegular_of_decidable (p : Prop) [Decidable p] : IsRegular p :=
propext <| Decidable.not_not
end Heyting
|
Order\Hom\Basic.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Logic.Equiv.Option
import Mathlib.Order.RelIso.Basic
import Mathlib.Order.Disjoint
import Mathlib.Order.WithBot
import Mathlib.Tactic.Monotonicity.Attr
import Mathlib.Util.AssertExists
/-!
# Order homomorphisms
This file defines order homomorphisms, which are bundled monotone functions. A preorder
homomorphism `f : α →o β` is a function `α → β` along with a proof that `∀ x y, x ≤ y → f x ≤ f y`.
## Main definitions
In this file we define the following bundled monotone maps:
* `OrderHom α β` a.k.a. `α →o β`: Preorder homomorphism.
An `OrderHom α β` is a function `f : α → β` such that `a₁ ≤ a₂ → f a₁ ≤ f a₂`
* `OrderEmbedding α β` a.k.a. `α ↪o β`: Relation embedding.
An `OrderEmbedding α β` is an embedding `f : α ↪ β` such that `a ≤ b ↔ f a ≤ f b`.
Defined as an abbreviation of `@RelEmbedding α β (≤) (≤)`.
* `OrderIso`: Relation isomorphism.
An `OrderIso α β` is an equivalence `f : α ≃ β` such that `a ≤ b ↔ f a ≤ f b`.
Defined as an abbreviation of `@RelIso α β (≤) (≤)`.
We also define many `OrderHom`s. In some cases we define two versions, one with `ₘ` suffix and
one without it (e.g., `OrderHom.compₘ` and `OrderHom.comp`). This means that the former
function is a "more bundled" version of the latter. We can't just drop the "less bundled" version
because the more bundled version usually does not work with dot notation.
* `OrderHom.id`: identity map as `α →o α`;
* `OrderHom.curry`: an order isomorphism between `α × β →o γ` and `α →o β →o γ`;
* `OrderHom.comp`: composition of two bundled monotone maps;
* `OrderHom.compₘ`: composition of bundled monotone maps as a bundled monotone map;
* `OrderHom.const`: constant function as a bundled monotone map;
* `OrderHom.prod`: combine `α →o β` and `α →o γ` into `α →o β × γ`;
* `OrderHom.prodₘ`: a more bundled version of `OrderHom.prod`;
* `OrderHom.prodIso`: order isomorphism between `α →o β × γ` and `(α →o β) × (α →o γ)`;
* `OrderHom.diag`: diagonal embedding of `α` into `α × α` as a bundled monotone map;
* `OrderHom.onDiag`: restrict a monotone map `α →o α →o β` to the diagonal;
* `OrderHom.fst`: projection `Prod.fst : α × β → α` as a bundled monotone map;
* `OrderHom.snd`: projection `Prod.snd : α × β → β` as a bundled monotone map;
* `OrderHom.prodMap`: `prod.map f g` as a bundled monotone map;
* `Pi.evalOrderHom`: evaluation of a function at a point `Function.eval i` as a bundled
monotone map;
* `OrderHom.coeFnHom`: coercion to function as a bundled monotone map;
* `OrderHom.apply`: application of an `OrderHom` at a point as a bundled monotone map;
* `OrderHom.pi`: combine a family of monotone maps `f i : α →o π i` into a monotone map
`α →o Π i, π i`;
* `OrderHom.piIso`: order isomorphism between `α →o Π i, π i` and `Π i, α →o π i`;
* `OrderHom.subtype.val`: embedding `Subtype.val : Subtype p → α` as a bundled monotone map;
* `OrderHom.dual`: reinterpret a monotone map `α →o β` as a monotone map `αᵒᵈ →o βᵒᵈ`;
* `OrderHom.dualIso`: order isomorphism between `α →o β` and `(αᵒᵈ →o βᵒᵈ)ᵒᵈ`;
* `OrderHom.compl`: order isomorphism `α ≃o αᵒᵈ` given by taking complements in a
boolean algebra;
We also define two functions to convert other bundled maps to `α →o β`:
* `OrderEmbedding.toOrderHom`: convert `α ↪o β` to `α →o β`;
* `RelHom.toOrderHom`: convert a `RelHom` between strict orders to an `OrderHom`.
## Tags
monotone map, bundled morphism
-/
open OrderDual
variable {F α β γ δ : Type*}
/-- Bundled monotone (aka, increasing) function -/
structure OrderHom (α β : Type*) [Preorder α] [Preorder β] where
/-- The underlying function of an `OrderHom`. -/
toFun : α → β
/-- The underlying function of an `OrderHom` is monotone. -/
monotone' : Monotone toFun
/-- Notation for an `OrderHom`. -/
infixr:25 " →o " => OrderHom
/-- An order embedding is an embedding `f : α ↪ β` such that `a ≤ b ↔ (f a) ≤ (f b)`.
This definition is an abbreviation of `RelEmbedding (≤) (≤)`. -/
abbrev OrderEmbedding (α β : Type*) [LE α] [LE β] :=
@RelEmbedding α β (· ≤ ·) (· ≤ ·)
/-- Notation for an `OrderEmbedding`. -/
infixl:25 " ↪o " => OrderEmbedding
/-- An order isomorphism is an equivalence such that `a ≤ b ↔ (f a) ≤ (f b)`.
This definition is an abbreviation of `RelIso (≤) (≤)`. -/
abbrev OrderIso (α β : Type*) [LE α] [LE β] :=
@RelIso α β (· ≤ ·) (· ≤ ·)
/-- Notation for an `OrderIso`. -/
infixl:25 " ≃o " => OrderIso
section
/-- `OrderHomClass F α b` asserts that `F` is a type of `≤`-preserving morphisms. -/
abbrev OrderHomClass (F : Type*) (α β : outParam Type*) [LE α] [LE β] [FunLike F α β] :=
RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop)
/-- `OrderIsoClass F α β` states that `F` is a type of order isomorphisms.
You should extend this class when you extend `OrderIso`. -/
class OrderIsoClass (F α β : Type*) [LE α] [LE β] [EquivLike F α β] : Prop where
/-- An order isomorphism respects `≤`. -/
map_le_map_iff (f : F) {a b : α} : f a ≤ f b ↔ a ≤ b
end
export OrderIsoClass (map_le_map_iff)
attribute [simp] map_le_map_iff
/-- Turn an element of a type `F` satisfying `OrderIsoClass F α β` into an actual
`OrderIso`. This is declared as the default coercion from `F` to `α ≃o β`. -/
@[coe]
def OrderIsoClass.toOrderIso [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] (f : F) :
α ≃o β :=
{ EquivLike.toEquiv f with map_rel_iff' := map_le_map_iff f }
/-- Any type satisfying `OrderIsoClass` can be cast into `OrderIso` via
`OrderIsoClass.toOrderIso`. -/
instance [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β] : CoeTC F (α ≃o β) :=
⟨OrderIsoClass.toOrderIso⟩
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toOrderHomClass [LE α] [LE β]
[EquivLike F α β] [OrderIsoClass F α β] : OrderHomClass F α β :=
{ EquivLike.toEmbeddingLike (E := F) with
map_rel := fun f _ _ => (map_le_map_iff f).2 }
namespace OrderHomClass
variable [Preorder α] [Preorder β] [FunLike F α β] [OrderHomClass F α β]
protected theorem monotone (f : F) : Monotone f := fun _ _ => map_rel f
protected theorem mono (f : F) : Monotone f := fun _ _ => map_rel f
/-- Turn an element of a type `F` satisfying `OrderHomClass F α β` into an actual
`OrderHom`. This is declared as the default coercion from `F` to `α →o β`. -/
@[coe]
def toOrderHom (f : F) : α →o β where
toFun := f
monotone' := OrderHomClass.monotone f
/-- Any type satisfying `OrderHomClass` can be cast into `OrderHom` via
`OrderHomClass.toOrderHom`. -/
instance : CoeTC F (α →o β) :=
⟨toOrderHom⟩
end OrderHomClass
section OrderIsoClass
section LE
variable [LE α] [LE β] [EquivLike F α β] [OrderIsoClass F α β]
-- Porting note: needed to add explicit arguments to map_le_map_iff
@[simp]
theorem map_inv_le_iff (f : F) {a : α} {b : β} : EquivLike.inv f b ≤ a ↔ b ≤ f a := by
convert (map_le_map_iff f (a := EquivLike.inv f b) (b := a)).symm
exact (EquivLike.right_inv f _).symm
-- Porting note: needed to add explicit arguments to map_le_map_iff
@[simp]
theorem le_map_inv_iff (f : F) {a : α} {b : β} : a ≤ EquivLike.inv f b ↔ f a ≤ b := by
convert (map_le_map_iff f (a := a) (b := EquivLike.inv f b)).symm
exact (EquivLike.right_inv _ _).symm
end LE
variable [Preorder α] [Preorder β] [EquivLike F α β] [OrderIsoClass F α β]
theorem map_lt_map_iff (f : F) {a b : α} : f a < f b ↔ a < b :=
lt_iff_lt_of_le_iff_le' (map_le_map_iff f) (map_le_map_iff f)
@[simp]
theorem map_inv_lt_iff (f : F) {a : α} {b : β} : EquivLike.inv f b < a ↔ b < f a := by
rw [← map_lt_map_iff f]
simp only [EquivLike.apply_inv_apply]
@[simp]
theorem lt_map_inv_iff (f : F) {a : α} {b : β} : a < EquivLike.inv f b ↔ f a < b := by
rw [← map_lt_map_iff f]
simp only [EquivLike.apply_inv_apply]
end OrderIsoClass
namespace OrderHom
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ]
instance : FunLike (α →o β) α β where
coe := toFun
coe_injective' f g h := by cases f; cases g; congr
instance : OrderHomClass (α →o β) α β where
map_rel f _ _ h := f.monotone' h
@[simp] theorem coe_mk (f : α → β) (hf : Monotone f) : ⇑(mk f hf) = f := rfl
protected theorem monotone (f : α →o β) : Monotone f :=
f.monotone'
protected theorem mono (f : α →o β) : Monotone f :=
f.monotone
/-- See Note [custom simps projection]. We give this manually so that we use `toFun` as the
projection directly instead. -/
def Simps.coe (f : α →o β) : α → β := f
/- Porting note (#11215): TODO: all other DFunLike classes use `apply` instead of `coe`
for the projection names. Maybe we should change this. -/
initialize_simps_projections OrderHom (toFun → coe)
@[simp] theorem toFun_eq_coe (f : α →o β) : f.toFun = f := rfl
-- See library note [partially-applied ext lemmas]
@[ext]
theorem ext (f g : α →o β) (h : (f : α → β) = g) : f = g :=
DFunLike.coe_injective h
@[simp] theorem coe_eq (f : α →o β) : OrderHomClass.toOrderHom f = f := rfl
@[simp] theorem _root_.OrderHomClass.coe_coe {F} [FunLike F α β] [OrderHomClass F α β] (f : F) :
⇑(f : α →o β) = f :=
rfl
/-- One can lift an unbundled monotone function to a bundled one. -/
protected instance canLift : CanLift (α → β) (α →o β) (↑) Monotone where
prf f h := ⟨⟨f, h⟩, rfl⟩
/-- Copy of an `OrderHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : α →o β) (f' : α → β) (h : f' = f) : α →o β :=
⟨f', h.symm.subst f.monotone'⟩
@[simp]
theorem coe_copy (f : α →o β) (f' : α → β) (h : f' = f) : (f.copy f' h) = f' :=
rfl
theorem copy_eq (f : α →o β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
/-- The identity function as bundled monotone function. -/
@[simps (config := .asFn)]
def id : α →o α :=
⟨_root_.id, monotone_id⟩
instance : Inhabited (α →o α) :=
⟨id⟩
/-- The preorder structure of `α →o β` is pointwise inequality: `f ≤ g ↔ ∀ a, f a ≤ g a`. -/
instance : Preorder (α →o β) :=
@Preorder.lift (α →o β) (α → β) _ toFun
instance {β : Type*} [PartialOrder β] : PartialOrder (α →o β) :=
@PartialOrder.lift (α →o β) (α → β) _ toFun ext
theorem le_def {f g : α →o β} : f ≤ g ↔ ∀ x, f x ≤ g x :=
Iff.rfl
@[simp, norm_cast]
theorem coe_le_coe {f g : α →o β} : (f : α → β) ≤ g ↔ f ≤ g :=
Iff.rfl
@[simp]
theorem mk_le_mk {f g : α → β} {hf hg} : mk f hf ≤ mk g hg ↔ f ≤ g :=
Iff.rfl
@[mono]
theorem apply_mono {f g : α →o β} {x y : α} (h₁ : f ≤ g) (h₂ : x ≤ y) : f x ≤ g y :=
(h₁ x).trans <| g.mono h₂
/-- Curry/uncurry as an order isomorphism between `α × β →o γ` and `α →o β →o γ`. -/
def curry : (α × β →o γ) ≃o (α →o β →o γ) where
toFun f := ⟨fun x ↦ ⟨Function.curry f x, fun _ _ h ↦ f.mono ⟨le_rfl, h⟩⟩, fun _ _ h _ =>
f.mono ⟨h, le_rfl⟩⟩
invFun f := ⟨Function.uncurry fun x ↦ f x, fun x y h ↦ (f.mono h.1 x.2).trans ((f y.1).mono h.2)⟩
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := by simp [le_def]
@[simp]
theorem curry_apply (f : α × β →o γ) (x : α) (y : β) : curry f x y = f (x, y) :=
rfl
@[simp]
theorem curry_symm_apply (f : α →o β →o γ) (x : α × β) : curry.symm f x = f x.1 x.2 :=
rfl
/-- The composition of two bundled monotone functions. -/
@[simps (config := .asFn)]
def comp (g : β →o γ) (f : α →o β) : α →o γ :=
⟨g ∘ f, g.mono.comp f.mono⟩
@[mono]
theorem comp_mono ⦃g₁ g₂ : β →o γ⦄ (hg : g₁ ≤ g₂) ⦃f₁ f₂ : α →o β⦄ (hf : f₁ ≤ f₂) :
g₁.comp f₁ ≤ g₂.comp f₂ := fun _ => (hg _).trans (g₂.mono <| hf _)
@[simp] lemma mk_comp_mk (g : β → γ) (f : α → β) (hg hf) :
comp ⟨g, hg⟩ ⟨f, hf⟩ = ⟨g ∘ f, hg.comp hf⟩ := rfl
/-- The composition of two bundled monotone functions, a fully bundled version. -/
@[simps! (config := .asFn)]
def compₘ : (β →o γ) →o (α →o β) →o α →o γ :=
curry ⟨fun f : (β →o γ) × (α →o β) => f.1.comp f.2, fun _ _ h => comp_mono h.1 h.2⟩
@[simp]
theorem comp_id (f : α →o β) : comp f id = f := by
ext
rfl
@[simp]
theorem id_comp (f : α →o β) : comp id f = f := by
ext
rfl
/-- Constant function bundled as an `OrderHom`. -/
@[simps (config := .asFn)]
def const (α : Type*) [Preorder α] {β : Type*} [Preorder β] : β →o α →o β where
toFun b := ⟨Function.const α b, fun _ _ _ => le_rfl⟩
monotone' _ _ h _ := h
@[simp]
theorem const_comp (f : α →o β) (c : γ) : (const β c).comp f = const α c :=
rfl
@[simp]
theorem comp_const (γ : Type*) [Preorder γ] (f : α →o β) (c : α) :
f.comp (const γ c) = const γ (f c) :=
rfl
/-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a
`OrderHom`. -/
@[simps]
protected def prod (f : α →o β) (g : α →o γ) : α →o β × γ :=
⟨fun x => (f x, g x), fun _ _ h => ⟨f.mono h, g.mono h⟩⟩
@[mono]
theorem prod_mono {f₁ f₂ : α →o β} (hf : f₁ ≤ f₂) {g₁ g₂ : α →o γ} (hg : g₁ ≤ g₂) :
f₁.prod g₁ ≤ f₂.prod g₂ := fun _ => Prod.le_def.2 ⟨hf _, hg _⟩
theorem comp_prod_comp_same (f₁ f₂ : β →o γ) (g : α →o β) :
(f₁.comp g).prod (f₂.comp g) = (f₁.prod f₂).comp g :=
rfl
/-- Given two bundled monotone maps `f`, `g`, `f.prod g` is the map `x ↦ (f x, g x)` bundled as a
`OrderHom`. This is a fully bundled version. -/
@[simps!]
def prodₘ : (α →o β) →o (α →o γ) →o α →o β × γ :=
curry ⟨fun f : (α →o β) × (α →o γ) => f.1.prod f.2, fun _ _ h => prod_mono h.1 h.2⟩
/-- Diagonal embedding of `α` into `α × α` as an `OrderHom`. -/
@[simps!]
def diag : α →o α × α :=
id.prod id
/-- Restriction of `f : α →o α →o β` to the diagonal. -/
@[simps! (config := { simpRhs := true })]
def onDiag (f : α →o α →o β) : α →o β :=
(curry.symm f).comp diag
/-- `Prod.fst` as an `OrderHom`. -/
@[simps]
def fst : α × β →o α :=
⟨Prod.fst, fun _ _ h => h.1⟩
/-- `Prod.snd` as an `OrderHom`. -/
@[simps]
def snd : α × β →o β :=
⟨Prod.snd, fun _ _ h => h.2⟩
@[simp]
theorem fst_prod_snd : (fst : α × β →o α).prod snd = id := by
ext ⟨x, y⟩ : 2
rfl
@[simp]
theorem fst_comp_prod (f : α →o β) (g : α →o γ) : fst.comp (f.prod g) = f :=
ext _ _ rfl
@[simp]
theorem snd_comp_prod (f : α →o β) (g : α →o γ) : snd.comp (f.prod g) = g :=
ext _ _ rfl
/-- Order isomorphism between the space of monotone maps to `β × γ` and the product of the spaces
of monotone maps to `β` and `γ`. -/
@[simps]
def prodIso : (α →o β × γ) ≃o (α →o β) × (α →o γ) where
toFun f := (fst.comp f, snd.comp f)
invFun f := f.1.prod f.2
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := forall_and.symm
/-- `Prod.map` of two `OrderHom`s as an `OrderHom`. -/
@[simps]
def prodMap (f : α →o β) (g : γ →o δ) : α × γ →o β × δ :=
⟨Prod.map f g, fun _ _ h => ⟨f.mono h.1, g.mono h.2⟩⟩
variable {ι : Type*} {π : ι → Type*} [∀ i, Preorder (π i)]
/-- Evaluation of an unbundled function at a point (`Function.eval`) as an `OrderHom`. -/
@[simps (config := .asFn)]
def _root_.Pi.evalOrderHom (i : ι) : (∀ j, π j) →o π i :=
⟨Function.eval i, Function.monotone_eval i⟩
/-- The "forgetful functor" from `α →o β` to `α → β` that takes the underlying function,
is monotone. -/
@[simps (config := .asFn)]
def coeFnHom : (α →o β) →o α → β where
toFun f := f
monotone' _ _ h := h
/-- Function application `fun f => f a` (for fixed `a`) is a monotone function from the
monotone function space `α →o β` to `β`. See also `Pi.evalOrderHom`. -/
@[simps! (config := .asFn)]
def apply (x : α) : (α →o β) →o β :=
(Pi.evalOrderHom x).comp coeFnHom
/-- Construct a bundled monotone map `α →o Π i, π i` from a family of monotone maps
`f i : α →o π i`. -/
@[simps]
def pi (f : ∀ i, α →o π i) : α →o ∀ i, π i :=
⟨fun x i => f i x, fun _ _ h i => (f i).mono h⟩
/-- Order isomorphism between bundled monotone maps `α →o Π i, π i` and families of bundled monotone
maps `Π i, α →o π i`. -/
@[simps]
def piIso : (α →o ∀ i, π i) ≃o ∀ i, α →o π i where
toFun f i := (Pi.evalOrderHom i).comp f
invFun := pi
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := forall_swap
/-- `Subtype.val` as a bundled monotone function. -/
@[simps (config := .asFn)]
def Subtype.val (p : α → Prop) : Subtype p →o α :=
⟨_root_.Subtype.val, fun _ _ h => h⟩
/-- `Subtype.impEmbedding` as an order embedding. -/
@[simps!]
def _root_.Subtype.orderEmbedding {p q : α → Prop} (h : ∀ a, p a → q a) :
{x // p x} ↪o {x // q x} :=
{ Subtype.impEmbedding _ _ h with
map_rel_iff' := by aesop }
/-- There is a unique monotone map from a subsingleton to itself. -/
instance unique [Subsingleton α] : Unique (α →o α) where
default := OrderHom.id
uniq _ := ext _ _ (Subsingleton.elim _ _)
theorem orderHom_eq_id [Subsingleton α] (g : α →o α) : g = OrderHom.id :=
Subsingleton.elim _ _
/-- Reinterpret a bundled monotone function as a monotone function between dual orders. -/
@[simps]
protected def dual : (α →o β) ≃ (αᵒᵈ →o βᵒᵈ) where
toFun f := ⟨(OrderDual.toDual : β → βᵒᵈ) ∘ (f : α → β) ∘
(OrderDual.ofDual : αᵒᵈ → α), f.mono.dual⟩
invFun f := ⟨OrderDual.ofDual ∘ f ∘ OrderDual.toDual, f.mono.dual⟩
left_inv _ := rfl
right_inv _ := rfl
-- Porting note: We used to be able to write `(OrderHom.id : α →o α).dual` here rather than
-- `OrderHom.dual (OrderHom.id : α →o α)`.
-- See https://github.com/leanprover/lean4/issues/1910
@[simp]
theorem dual_id : OrderHom.dual (OrderHom.id : α →o α) = OrderHom.id :=
rfl
@[simp]
theorem dual_comp (g : β →o γ) (f : α →o β) :
OrderHom.dual (g.comp f) = (OrderHom.dual g).comp (OrderHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : OrderHom.dual.symm OrderHom.id = (OrderHom.id : α →o α) :=
rfl
@[simp]
theorem symm_dual_comp (g : βᵒᵈ →o γᵒᵈ) (f : αᵒᵈ →o βᵒᵈ) :
OrderHom.dual.symm (g.comp f) = (OrderHom.dual.symm g).comp (OrderHom.dual.symm f) :=
rfl
/-- `OrderHom.dual` as an order isomorphism. -/
def dualIso (α β : Type*) [Preorder α] [Preorder β] : (α →o β) ≃o (αᵒᵈ →o βᵒᵈ)ᵒᵈ where
toEquiv := OrderHom.dual.trans OrderDual.toDual
map_rel_iff' := Iff.rfl
/-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithBot α →o WithBot β`. -/
@[simps (config := .asFn)]
protected def withBotMap (f : α →o β) : WithBot α →o WithBot β :=
⟨WithBot.map f, f.mono.withBot_map⟩
/-- Lift an order homomorphism `f : α →o β` to an order homomorphism `WithTop α →o WithTop β`. -/
@[simps (config := .asFn)]
protected def withTopMap (f : α →o β) : WithTop α →o WithTop β :=
⟨WithTop.map f, f.mono.withTop_map⟩
end OrderHom
/-- Embeddings of partial orders that preserve `<` also preserve `≤`. -/
def RelEmbedding.orderEmbeddingOfLTEmbedding [PartialOrder α] [PartialOrder β]
(f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) : α ↪o β :=
{ f with
map_rel_iff' := by
intros
simp [le_iff_lt_or_eq, f.map_rel_iff, f.injective.eq_iff] }
@[simp]
theorem RelEmbedding.orderEmbeddingOfLTEmbedding_apply [PartialOrder α] [PartialOrder β]
{f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)} {x : α} :
RelEmbedding.orderEmbeddingOfLTEmbedding f x = f x :=
rfl
namespace OrderEmbedding
variable [Preorder α] [Preorder β] (f : α ↪o β)
/-- `<` is preserved by order embeddings of preorders. -/
def ltEmbedding : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop) :=
{ f with map_rel_iff' := by intros; simp [lt_iff_le_not_le, f.map_rel_iff] }
@[simp]
theorem ltEmbedding_apply (x : α) : f.ltEmbedding x = f x :=
rfl
@[simp]
theorem le_iff_le {a b} : f a ≤ f b ↔ a ≤ b :=
f.map_rel_iff
@[simp]
theorem lt_iff_lt {a b} : f a < f b ↔ a < b :=
f.ltEmbedding.map_rel_iff
theorem eq_iff_eq {a b} : f a = f b ↔ a = b :=
f.injective.eq_iff
protected theorem monotone : Monotone f :=
OrderHomClass.monotone f
protected theorem strictMono : StrictMono f := fun _ _ => f.lt_iff_lt.2
protected theorem acc (a : α) : Acc (· < ·) (f a) → Acc (· < ·) a :=
f.ltEmbedding.acc a
protected theorem wellFounded (f : α ↪o β) :
WellFounded ((· < ·) : β → β → Prop) → WellFounded ((· < ·) : α → α → Prop) :=
f.ltEmbedding.wellFounded
protected theorem isWellOrder [IsWellOrder β (· < ·)] (f : α ↪o β) : IsWellOrder α (· < ·) :=
f.ltEmbedding.isWellOrder
/-- An order embedding is also an order embedding between dual orders. -/
protected def dual : αᵒᵈ ↪o βᵒᵈ :=
⟨f.toEmbedding, f.map_rel_iff⟩
/-- A preorder which embeds into a well-founded preorder is itself well-founded. -/
protected theorem wellFoundedLT [WellFoundedLT β] (f : α ↪o β) : WellFoundedLT α where
wf := f.wellFounded IsWellFounded.wf
/-- A preorder which embeds into a preorder in which `(· > ·)` is well-founded
also has `(· > ·)` well-founded. -/
protected theorem wellFoundedGT [WellFoundedGT β] (f : α ↪o β) : WellFoundedGT α :=
@OrderEmbedding.wellFoundedLT αᵒᵈ _ _ _ _ f.dual
/-- A version of `WithBot.map` for order embeddings. -/
@[simps (config := .asFn)]
protected def withBotMap (f : α ↪o β) : WithBot α ↪o WithBot β :=
{ f.toEmbedding.optionMap with
toFun := WithBot.map f,
map_rel_iff' := @fun a b => WithBot.map_le_iff f f.map_rel_iff a b }
/-- A version of `WithTop.map` for order embeddings. -/
@[simps (config := .asFn)]
protected def withTopMap (f : α ↪o β) : WithTop α ↪o WithTop β :=
{ f.dual.withBotMap.dual with toFun := WithTop.map f }
/-- To define an order embedding from a partial order to a preorder it suffices to give a function
together with a proof that it satisfies `f a ≤ f b ↔ a ≤ b`.
-/
def ofMapLEIff {α β} [PartialOrder α] [Preorder β] (f : α → β) (hf : ∀ a b, f a ≤ f b ↔ a ≤ b) :
α ↪o β :=
RelEmbedding.ofMapRelIff f hf
@[simp]
theorem coe_ofMapLEIff {α β} [PartialOrder α] [Preorder β] {f : α → β} (h) :
⇑(ofMapLEIff f h) = f :=
rfl
/-- A strictly monotone map from a linear order is an order embedding. -/
def ofStrictMono {α β} [LinearOrder α] [Preorder β] (f : α → β) (h : StrictMono f) : α ↪o β :=
ofMapLEIff f fun _ _ => h.le_iff_le
@[simp]
theorem coe_ofStrictMono {α β} [LinearOrder α] [Preorder β] {f : α → β} (h : StrictMono f) :
⇑(ofStrictMono f h) = f :=
rfl
/-- Embedding of a subtype into the ambient type as an `OrderEmbedding`. -/
@[simps! (config := .asFn)]
def subtype (p : α → Prop) : Subtype p ↪o α :=
⟨Function.Embedding.subtype p, Iff.rfl⟩
/-- Convert an `OrderEmbedding` to an `OrderHom`. -/
@[simps (config := .asFn)]
def toOrderHom {X Y : Type*} [Preorder X] [Preorder Y] (f : X ↪o Y) : X →o Y where
toFun := f
monotone' := f.monotone
/-- The trivial embedding from an empty preorder to another preorder -/
@[simps] def ofIsEmpty [IsEmpty α] : α ↪o β where
toFun := isEmptyElim
inj' := isEmptyElim
map_rel_iff' {a} := isEmptyElim a
@[simp, norm_cast]
lemma coe_ofIsEmpty [IsEmpty α] : (ofIsEmpty : α ↪o β) = (isEmptyElim : α → β) := rfl
end OrderEmbedding
section Disjoint
variable [PartialOrder α] [PartialOrder β] (f : OrderEmbedding α β)
/-- If the images by an order embedding of two elements are disjoint,
then they are themselves disjoint. -/
lemma Disjoint.of_orderEmbedding [OrderBot α] [OrderBot β] {a₁ a₂ : α} :
Disjoint (f a₁) (f a₂) → Disjoint a₁ a₂ := by
intro h x h₁ h₂
rw [← f.le_iff_le] at h₁ h₂ ⊢
calc
f x ≤ ⊥ := h h₁ h₂
_ ≤ f ⊥ := bot_le
/-- If the images by an order embedding of two elements are codisjoint,
then they are themselves codisjoint. -/
lemma Codisjoint.of_orderEmbedding [OrderTop α] [OrderTop β] {a₁ a₂ : α} :
Codisjoint (f a₁) (f a₂) → Codisjoint a₁ a₂ :=
Disjoint.of_orderEmbedding (α := αᵒᵈ) (β := βᵒᵈ) f.dual
/-- If the images by an order embedding of two elements are complements,
then they are themselves complements. -/
lemma IsCompl.of_orderEmbedding [BoundedOrder α] [BoundedOrder β] {a₁ a₂ : α} :
IsCompl (f a₁) (f a₂) → IsCompl a₁ a₂ := fun ⟨hd, hcd⟩ ↦
⟨Disjoint.of_orderEmbedding f hd, Codisjoint.of_orderEmbedding f hcd⟩
end Disjoint
section RelHom
variable [PartialOrder α] [Preorder β]
namespace RelHom
variable (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop))
/-- A bundled expression of the fact that a map between partial orders that is strictly monotone
is weakly monotone. -/
@[simps (config := .asFn)]
def toOrderHom : α →o β where
toFun := f
monotone' := StrictMono.monotone fun _ _ => f.map_rel
end RelHom
theorem RelEmbedding.toOrderHom_injective
(f : ((· < ·) : α → α → Prop) ↪r ((· < ·) : β → β → Prop)) :
Function.Injective (f : ((· < ·) : α → α → Prop) →r ((· < ·) : β → β → Prop)).toOrderHom :=
fun _ _ h => f.injective h
end RelHom
namespace OrderIso
section LE
variable [LE α] [LE β] [LE γ]
instance : EquivLike (α ≃o β) α β where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
obtain ⟨⟨_, _⟩, _⟩ := f
obtain ⟨⟨_, _⟩, _⟩ := g
congr
instance : OrderIsoClass (α ≃o β) α β where
map_le_map_iff f _ _ := f.map_rel_iff'
@[simp]
theorem toFun_eq_coe {f : α ≃o β} : f.toFun = f :=
rfl
-- See note [partially-applied ext lemmas]
@[ext]
theorem ext {f g : α ≃o β} (h : (f : α → β) = g) : f = g :=
DFunLike.coe_injective h
/-- Reinterpret an order isomorphism as an order embedding. -/
def toOrderEmbedding (e : α ≃o β) : α ↪o β :=
e.toRelEmbedding
@[simp]
theorem coe_toOrderEmbedding (e : α ≃o β) : ⇑e.toOrderEmbedding = e :=
rfl
protected theorem bijective (e : α ≃o β) : Function.Bijective e :=
e.toEquiv.bijective
protected theorem injective (e : α ≃o β) : Function.Injective e :=
e.toEquiv.injective
protected theorem surjective (e : α ≃o β) : Function.Surjective e :=
e.toEquiv.surjective
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem apply_eq_iff_eq (e : α ≃o β) {x y : α} : e x = e y ↔ x = y :=
e.toEquiv.apply_eq_iff_eq
/-- Identity order isomorphism. -/
def refl (α : Type*) [LE α] : α ≃o α :=
RelIso.refl (· ≤ ·)
@[simp]
theorem coe_refl : ⇑(refl α) = id :=
rfl
@[simp]
theorem refl_apply (x : α) : refl α x = x :=
rfl
@[simp]
theorem refl_toEquiv : (refl α).toEquiv = Equiv.refl α :=
rfl
/-- Inverse of an order isomorphism. -/
def symm (e : α ≃o β) : β ≃o α := RelIso.symm e
@[simp]
theorem apply_symm_apply (e : α ≃o β) (x : β) : e (e.symm x) = x :=
e.toEquiv.apply_symm_apply x
@[simp]
theorem symm_apply_apply (e : α ≃o β) (x : α) : e.symm (e x) = x :=
e.toEquiv.symm_apply_apply x
@[simp]
theorem symm_refl (α : Type*) [LE α] : (refl α).symm = refl α :=
rfl
theorem apply_eq_iff_eq_symm_apply (e : α ≃o β) (x : α) (y : β) : e x = y ↔ x = e.symm y :=
e.toEquiv.apply_eq_iff_eq_symm_apply
theorem symm_apply_eq (e : α ≃o β) {x : α} {y : β} : e.symm y = x ↔ y = e x :=
e.toEquiv.symm_apply_eq
@[simp]
theorem symm_symm (e : α ≃o β) : e.symm.symm = e := by
ext
rfl
theorem symm_bijective : Function.Bijective (OrderIso.symm : (α ≃o β) → β ≃o α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
theorem symm_injective : Function.Injective (symm : α ≃o β → β ≃o α) :=
symm_bijective.injective
@[simp]
theorem toEquiv_symm (e : α ≃o β) : e.toEquiv.symm = e.symm.toEquiv :=
rfl
/-- Composition of two order isomorphisms is an order isomorphism. -/
@[trans]
def trans (e : α ≃o β) (e' : β ≃o γ) : α ≃o γ :=
RelIso.trans e e'
@[simp]
theorem coe_trans (e : α ≃o β) (e' : β ≃o γ) : ⇑(e.trans e') = e' ∘ e :=
rfl
@[simp]
theorem trans_apply (e : α ≃o β) (e' : β ≃o γ) (x : α) : e.trans e' x = e' (e x) :=
rfl
@[simp]
theorem refl_trans (e : α ≃o β) : (refl α).trans e = e := by
ext x
rfl
@[simp]
theorem trans_refl (e : α ≃o β) : e.trans (refl β) = e := by
ext x
rfl
@[simp]
theorem symm_trans_apply (e₁ : α ≃o β) (e₂ : β ≃o γ) (c : γ) :
(e₁.trans e₂).symm c = e₁.symm (e₂.symm c) :=
rfl
theorem symm_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) : (e₁.trans e₂).symm = e₂.symm.trans e₁.symm :=
rfl
@[simp]
theorem self_trans_symm (e : α ≃o β) : e.trans e.symm = OrderIso.refl α :=
RelIso.self_trans_symm e
@[simp]
theorem symm_trans_self (e : α ≃o β) : e.symm.trans e = OrderIso.refl β :=
RelIso.symm_trans_self e
/-- An order isomorphism between the domains and codomains of two prosets of
order homomorphisms gives an order isomorphism between the two function prosets. -/
@[simps apply symm_apply]
def arrowCongr {α β γ δ} [Preorder α] [Preorder β] [Preorder γ] [Preorder δ]
(f : α ≃o γ) (g : β ≃o δ) : (α →o β) ≃o (γ →o δ) where
toFun p := .comp g <| .comp p f.symm
invFun p := .comp g.symm <| .comp p f
left_inv p := DFunLike.coe_injective <| by
change (g.symm ∘ g) ∘ p ∘ (f.symm ∘ f) = p
simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp,
OrderIso.self_trans_symm, OrderIso.coe_refl, Function.comp_id]
right_inv p := DFunLike.coe_injective <| by
change (g ∘ g.symm) ∘ p ∘ (f ∘ f.symm) = p
simp only [← DFunLike.coe_eq_coe_fn, ← OrderIso.coe_trans, Function.id_comp,
OrderIso.symm_trans_self, OrderIso.coe_refl, Function.comp_id]
map_rel_iff' {p q} := by
simp only [Equiv.coe_fn_mk, OrderHom.le_def, OrderHom.comp_coe,
OrderHomClass.coe_coe, Function.comp_apply, map_le_map_iff]
exact Iff.symm f.forall_congr_left
/-- If `α` and `β` are order-isomorphic then the two orders of order-homomorphisms
from `α` and `β` to themselves are order-isomorphic. -/
@[simps! apply symm_apply]
def conj {α β} [Preorder α] [Preorder β] (f : α ≃o β) : (α →o α) ≃ (β →o β) :=
arrowCongr f f
/-- `Prod.swap` as an `OrderIso`. -/
def prodComm : α × β ≃o β × α where
toEquiv := Equiv.prodComm α β
map_rel_iff' := Prod.swap_le_swap
@[simp]
theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap :=
rfl
@[simp]
theorem prodComm_symm : (prodComm : α × β ≃o β × α).symm = prodComm :=
rfl
variable (α)
/-- The order isomorphism between a type and its double dual. -/
def dualDual : α ≃o αᵒᵈᵒᵈ :=
refl α
@[simp]
theorem coe_dualDual : ⇑(dualDual α) = toDual ∘ toDual :=
rfl
@[simp]
theorem coe_dualDual_symm : ⇑(dualDual α).symm = ofDual ∘ ofDual :=
rfl
variable {α}
@[simp]
theorem dualDual_apply (a : α) : dualDual α a = toDual (toDual a) :=
rfl
@[simp]
theorem dualDual_symm_apply (a : αᵒᵈᵒᵈ) : (dualDual α).symm a = ofDual (ofDual a) :=
rfl
end LE
open Set
section LE
variable [LE α] [LE β] [LE γ]
--@[simp] Porting note (#10618): simp can prove it
theorem le_iff_le (e : α ≃o β) {x y : α} : e x ≤ e y ↔ x ≤ y :=
e.map_rel_iff
theorem le_symm_apply (e : α ≃o β) {x : α} {y : β} : x ≤ e.symm y ↔ e x ≤ y :=
e.rel_symm_apply
theorem symm_apply_le (e : α ≃o β) {x : α} {y : β} : e.symm y ≤ x ↔ y ≤ e x :=
e.symm_apply_rel
end LE
variable [Preorder α] [Preorder β] [Preorder γ]
protected theorem monotone (e : α ≃o β) : Monotone e :=
e.toOrderEmbedding.monotone
protected theorem strictMono (e : α ≃o β) : StrictMono e :=
e.toOrderEmbedding.strictMono
@[simp]
theorem lt_iff_lt (e : α ≃o β) {x y : α} : e x < e y ↔ x < y :=
e.toOrderEmbedding.lt_iff_lt
/-- Converts an `OrderIso` into a `RelIso (<) (<)`. -/
def toRelIsoLT (e : α ≃o β) : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop) :=
⟨e.toEquiv, lt_iff_lt e⟩
@[simp]
theorem toRelIsoLT_apply (e : α ≃o β) (x : α) : e.toRelIsoLT x = e x :=
rfl
@[simp]
theorem toRelIsoLT_symm (e : α ≃o β) : e.toRelIsoLT.symm = e.symm.toRelIsoLT :=
rfl
/-- Converts a `RelIso (<) (<)` into an `OrderIso`. -/
def ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β]
(e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : α ≃o β :=
⟨e.toEquiv, by simp [le_iff_eq_or_lt, e.map_rel_iff, e.injective.eq_iff]⟩
@[simp]
theorem ofRelIsoLT_apply {α β} [PartialOrder α] [PartialOrder β]
(e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) (x : α) : ofRelIsoLT e x = e x :=
rfl
@[simp]
theorem ofRelIsoLT_symm {α β} [PartialOrder α] [PartialOrder β]
(e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) :
(ofRelIsoLT e).symm = ofRelIsoLT e.symm :=
rfl
@[simp]
theorem ofRelIsoLT_toRelIsoLT {α β} [PartialOrder α] [PartialOrder β] (e : α ≃o β) :
ofRelIsoLT (toRelIsoLT e) = e := by
ext
simp
@[simp]
theorem toRelIsoLT_ofRelIsoLT {α β} [PartialOrder α] [PartialOrder β]
(e : ((· < ·) : α → α → Prop) ≃r ((· < ·) : β → β → Prop)) : toRelIsoLT (ofRelIsoLT e) = e := by
ext
simp
/-- To show that `f : α → β`, `g : β → α` make up an order isomorphism of linear orders,
it suffices to prove `cmp a (g b) = cmp (f a) b`. -/
def ofCmpEqCmp {α β} [LinearOrder α] [LinearOrder β] (f : α → β) (g : β → α)
(h : ∀ (a : α) (b : β), cmp a (g b) = cmp (f a) b) : α ≃o β :=
have gf : ∀ a : α, a = g (f a) := by
intro
rw [← cmp_eq_eq_iff, h, cmp_self_eq_eq]
{ toFun := f, invFun := g, left_inv := fun a => (gf a).symm,
right_inv := by
intro
rw [← cmp_eq_eq_iff, ← h, cmp_self_eq_eq],
map_rel_iff' := by
intros a b
apply le_iff_le_of_cmp_eq_cmp
convert (h a (f b)).symm
apply gf }
/-- To show that `f : α →o β` and `g : β →o α` make up an order isomorphism it is enough to show
that `g` is the inverse of `f`-/
def ofHomInv {F G : Type*} [FunLike F α β] [OrderHomClass F α β] [FunLike G β α]
[OrderHomClass G β α] (f : F) (g : G)
(h₁ : (f : α →o β).comp (g : β →o α) = OrderHom.id)
(h₂ : (g : β →o α).comp (f : α →o β) = OrderHom.id) :
α ≃o β where
toFun := f
invFun := g
left_inv := DFunLike.congr_fun h₂
right_inv := DFunLike.congr_fun h₁
map_rel_iff' := @fun a b =>
⟨fun h => by
replace h := map_rel g h
rwa [Equiv.coe_fn_mk, show g (f a) = (g : β →o α).comp (f : α →o β) a from rfl,
show g (f b) = (g : β →o α).comp (f : α →o β) b from rfl, h₂] at h,
fun h => (f : α →o β).monotone h⟩
/-- Order isomorphism between `α → β` and `β`, where `α` has a unique element. -/
@[simps! toEquiv apply]
def funUnique (α β : Type*) [Unique α] [Preorder β] : (α → β) ≃o β where
toEquiv := Equiv.funUnique α β
map_rel_iff' := by simp [Pi.le_def, Unique.forall_iff]
@[simp]
theorem funUnique_symm_apply {α β : Type*} [Unique α] [Preorder β] :
((funUnique α β).symm : β → α → β) = Function.const α :=
rfl
end OrderIso
namespace Equiv
variable [Preorder α] [Preorder β]
/-- If `e` is an equivalence with monotone forward and inverse maps, then `e` is an
order isomorphism. -/
def toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) : α ≃o β :=
⟨e, ⟨fun h => by simpa only [e.symm_apply_apply] using h₂ h, fun h => h₁ h⟩⟩
@[simp]
theorem coe_toOrderIso (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) :
⇑(e.toOrderIso h₁ h₂) = e :=
rfl
@[simp]
theorem toOrderIso_toEquiv (e : α ≃ β) (h₁ : Monotone e) (h₂ : Monotone e.symm) :
(e.toOrderIso h₁ h₂).toEquiv = e :=
rfl
end Equiv
namespace StrictMono
variable [LinearOrder α] [Preorder β]
variable (f : α → β) (h_mono : StrictMono f) (h_surj : Function.Surjective f)
/-- A strictly monotone function with a right inverse is an order isomorphism. -/
@[simps (config := .asFn)]
def orderIsoOfRightInverse (g : β → α) (hg : Function.RightInverse g f) : α ≃o β :=
{ OrderEmbedding.ofStrictMono f h_mono with
toFun := f,
invFun := g,
left_inv := fun _ => h_mono.injective <| hg _,
right_inv := hg }
end StrictMono
/-- An order isomorphism is also an order isomorphism between dual orders. -/
protected def OrderIso.dual [LE α] [LE β] (f : α ≃o β) : αᵒᵈ ≃o βᵒᵈ :=
⟨f.toEquiv, f.map_rel_iff⟩
section LatticeIsos
theorem OrderIso.map_bot' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x ≤ x')
(hy : ∀ y', y ≤ y') : f x = y := by
refine le_antisymm ?_ (hy _)
rw [← f.apply_symm_apply y, f.map_rel_iff]
apply hx
theorem OrderIso.map_bot [LE α] [PartialOrder β] [OrderBot α] [OrderBot β] (f : α ≃o β) : f ⊥ = ⊥ :=
f.map_bot' (fun _ => bot_le) fun _ => bot_le
theorem OrderIso.map_top' [LE α] [PartialOrder β] (f : α ≃o β) {x : α} {y : β} (hx : ∀ x', x' ≤ x)
(hy : ∀ y', y' ≤ y) : f x = y :=
f.dual.map_bot' hx hy
theorem OrderIso.map_top [LE α] [PartialOrder β] [OrderTop α] [OrderTop β] (f : α ≃o β) : f ⊤ = ⊤ :=
f.dual.map_bot
theorem OrderEmbedding.map_inf_le [SemilatticeInf α] [SemilatticeInf β] (f : α ↪o β) (x y : α) :
f (x ⊓ y) ≤ f x ⊓ f y :=
f.monotone.map_inf_le x y
theorem OrderEmbedding.le_map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ↪o β) (x y : α) :
f x ⊔ f y ≤ f (x ⊔ y) :=
f.monotone.le_map_sup x y
theorem OrderIso.map_inf [SemilatticeInf α] [SemilatticeInf β] (f : α ≃o β) (x y : α) :
f (x ⊓ y) = f x ⊓ f y := by
refine (f.toOrderEmbedding.map_inf_le x y).antisymm ?_
apply f.symm.le_iff_le.1
simpa using f.symm.toOrderEmbedding.map_inf_le (f x) (f y)
theorem OrderIso.map_sup [SemilatticeSup α] [SemilatticeSup β] (f : α ≃o β) (x y : α) :
f (x ⊔ y) = f x ⊔ f y :=
f.dual.map_inf x y
/-- Note that this goal could also be stated `(Disjoint on f) a b` -/
theorem Disjoint.map_orderIso [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β]
{a b : α} (f : α ≃o β) (ha : Disjoint a b) : Disjoint (f a) (f b) := by
rw [disjoint_iff_inf_le, ← f.map_inf, ← f.map_bot]
exact f.monotone ha.le_bot
/-- Note that this goal could also be stated `(Codisjoint on f) a b` -/
theorem Codisjoint.map_orderIso [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β]
{a b : α} (f : α ≃o β) (ha : Codisjoint a b) : Codisjoint (f a) (f b) := by
rw [codisjoint_iff_le_sup, ← f.map_sup, ← f.map_top]
exact f.monotone ha.top_le
@[simp]
theorem disjoint_map_orderIso_iff [SemilatticeInf α] [OrderBot α] [SemilatticeInf β] [OrderBot β]
{a b : α} (f : α ≃o β) : Disjoint (f a) (f b) ↔ Disjoint a b :=
⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm,
fun h => h.map_orderIso f⟩
@[simp]
theorem codisjoint_map_orderIso_iff [SemilatticeSup α] [OrderTop α] [SemilatticeSup β] [OrderTop β]
{a b : α} (f : α ≃o β) : Codisjoint (f a) (f b) ↔ Codisjoint a b :=
⟨fun h => f.symm_apply_apply a ▸ f.symm_apply_apply b ▸ h.map_orderIso f.symm,
fun h => h.map_orderIso f⟩
namespace WithBot
/-- Taking the dual then adding `⊥` is the same as adding `⊤` then taking the dual.
This is the order iso form of `WithBot.ofDual`, as proven by `coe_toDualTopEquiv_eq`.
-/
protected def toDualTopEquiv [LE α] : WithBot αᵒᵈ ≃o (WithTop α)ᵒᵈ :=
OrderIso.refl _
@[simp]
theorem toDualTopEquiv_coe [LE α] (a : α) :
WithBot.toDualTopEquiv ↑(toDual a) = toDual (a : WithTop α) :=
rfl
@[simp]
theorem toDualTopEquiv_symm_coe [LE α] (a : α) :
WithBot.toDualTopEquiv.symm (toDual (a : WithTop α)) = ↑(toDual a) :=
rfl
@[simp]
theorem toDualTopEquiv_bot [LE α] : WithBot.toDualTopEquiv (⊥ : WithBot αᵒᵈ) = ⊥ :=
rfl
@[simp]
theorem toDualTopEquiv_symm_bot [LE α] : WithBot.toDualTopEquiv.symm (⊥ : (WithTop α)ᵒᵈ) = ⊥ :=
rfl
theorem coe_toDualTopEquiv_eq [LE α] :
(WithBot.toDualTopEquiv : WithBot αᵒᵈ → (WithTop α)ᵒᵈ) = toDual ∘ WithBot.ofDual :=
funext fun _ => rfl
end WithBot
namespace WithTop
/-- Taking the dual then adding `⊤` is the same as adding `⊥` then taking the dual.
This is the order iso form of `WithTop.ofDual`, as proven by `coe_toDualBotEquiv_eq`. -/
protected def toDualBotEquiv [LE α] : WithTop αᵒᵈ ≃o (WithBot α)ᵒᵈ :=
OrderIso.refl _
@[simp]
theorem toDualBotEquiv_coe [LE α] (a : α) :
WithTop.toDualBotEquiv ↑(toDual a) = toDual (a : WithBot α) :=
rfl
@[simp]
theorem toDualBotEquiv_symm_coe [LE α] (a : α) :
WithTop.toDualBotEquiv.symm (toDual (a : WithBot α)) = ↑(toDual a) :=
rfl
@[simp]
theorem toDualBotEquiv_top [LE α] : WithTop.toDualBotEquiv (⊤ : WithTop αᵒᵈ) = ⊤ :=
rfl
@[simp]
theorem toDualBotEquiv_symm_top [LE α] : WithTop.toDualBotEquiv.symm (⊤ : (WithBot α)ᵒᵈ) = ⊤ :=
rfl
theorem coe_toDualBotEquiv [LE α] :
(WithTop.toDualBotEquiv : WithTop αᵒᵈ → (WithBot α)ᵒᵈ) = toDual ∘ WithTop.ofDual :=
funext fun _ => rfl
end WithTop
namespace OrderIso
variable [PartialOrder α] [PartialOrder β] [PartialOrder γ]
/-- A version of `Equiv.optionCongr` for `WithTop`. -/
@[simps! apply]
def withTopCongr (e : α ≃o β) : WithTop α ≃o WithTop β :=
{ e.toOrderEmbedding.withTopMap with
toEquiv := e.toEquiv.optionCongr }
@[simp]
theorem withTopCongr_refl : (OrderIso.refl α).withTopCongr = OrderIso.refl _ :=
RelIso.toEquiv_injective Equiv.optionCongr_refl
@[simp]
theorem withTopCongr_symm (e : α ≃o β) : e.withTopCongr.symm = e.symm.withTopCongr :=
RelIso.toEquiv_injective e.toEquiv.optionCongr_symm
@[simp]
theorem withTopCongr_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) :
e₁.withTopCongr.trans e₂.withTopCongr = (e₁.trans e₂).withTopCongr :=
RelIso.toEquiv_injective <| e₁.toEquiv.optionCongr_trans e₂.toEquiv
/-- A version of `Equiv.optionCongr` for `WithBot`. -/
@[simps! apply]
def withBotCongr (e : α ≃o β) : WithBot α ≃o WithBot β :=
{ e.toOrderEmbedding.withBotMap with toEquiv := e.toEquiv.optionCongr }
@[simp]
theorem withBotCongr_refl : (OrderIso.refl α).withBotCongr = OrderIso.refl _ :=
RelIso.toEquiv_injective Equiv.optionCongr_refl
@[simp]
theorem withBotCongr_symm (e : α ≃o β) : e.withBotCongr.symm = e.symm.withBotCongr :=
RelIso.toEquiv_injective e.toEquiv.optionCongr_symm
@[simp]
theorem withBotCongr_trans (e₁ : α ≃o β) (e₂ : β ≃o γ) :
e₁.withBotCongr.trans e₂.withBotCongr = (e₁.trans e₂).withBotCongr :=
RelIso.toEquiv_injective <| e₁.toEquiv.optionCongr_trans e₂.toEquiv
end OrderIso
section BoundedOrder
variable [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] (f : α ≃o β)
theorem OrderIso.isCompl {x y : α} (h : IsCompl x y) : IsCompl (f x) (f y) :=
⟨h.1.map_orderIso _, h.2.map_orderIso _⟩
theorem OrderIso.isCompl_iff {x y : α} : IsCompl x y ↔ IsCompl (f x) (f y) :=
⟨f.isCompl, fun h => f.symm_apply_apply x ▸ f.symm_apply_apply y ▸ f.symm.isCompl h⟩
theorem OrderIso.complementedLattice [ComplementedLattice α] (f : α ≃o β) : ComplementedLattice β :=
⟨fun x => by
obtain ⟨y, hy⟩ := exists_isCompl (f.symm x)
rw [← f.symm_apply_apply y] at hy
exact ⟨f y, f.symm.isCompl_iff.2 hy⟩⟩
theorem OrderIso.complementedLattice_iff (f : α ≃o β) :
ComplementedLattice α ↔ ComplementedLattice β :=
⟨by intro; exact f.complementedLattice,
by intro; exact f.symm.complementedLattice⟩
end BoundedOrder
end LatticeIsos
-- Developments relating order homs and sets belong in `Order.Hom.Set` or later.
assert_not_exists Set.range
|
Order\Hom\Bounded.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Basic
import Mathlib.Order.BoundedOrder
/-!
# Bounded order homomorphisms
This file defines (bounded) order homomorphisms.
We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `TopHom`: Maps which preserve `⊤`.
* `BotHom`: Maps which preserve `⊥`.
* `BoundedOrderHom`: Bounded order homomorphisms. Monotone maps which preserve `⊤` and `⊥`.
## Typeclasses
* `TopHomClass`
* `BotHomClass`
* `BoundedOrderHomClass`
-/
open Function OrderDual
variable {F α β γ δ : Type*}
/-- The type of `⊤`-preserving functions from `α` to `β`. -/
structure TopHom (α β : Type*) [Top α] [Top β] where
/-- The underlying function. The preferred spelling is `DFunLike.coe`. -/
toFun : α → β
/-- The function preserves the top element. The preferred spelling is `map_top`. -/
map_top' : toFun ⊤ = ⊤
/-- The type of `⊥`-preserving functions from `α` to `β`. -/
structure BotHom (α β : Type*) [Bot α] [Bot β] where
/-- The underlying function. The preferred spelling is `DFunLike.coe`. -/
toFun : α → β
/-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/
map_bot' : toFun ⊥ = ⊥
/-- The type of bounded order homomorphisms from `α` to `β`. -/
structure BoundedOrderHom (α β : Type*) [Preorder α] [Preorder β] [BoundedOrder α]
[BoundedOrder β] extends OrderHom α β where
/-- The function preserves the top element. The preferred spelling is `map_top`. -/
map_top' : toFun ⊤ = ⊤
/-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/
map_bot' : toFun ⊥ = ⊥
section
/-- `TopHomClass F α β` states that `F` is a type of `⊤`-preserving morphisms.
You should extend this class when you extend `TopHom`. -/
class TopHomClass (F α β : Type*) [Top α] [Top β] [FunLike F α β] : Prop where
/-- A `TopHomClass` morphism preserves the top element. -/
map_top (f : F) : f ⊤ = ⊤
/-- `BotHomClass F α β` states that `F` is a type of `⊥`-preserving morphisms.
You should extend this class when you extend `BotHom`. -/
class BotHomClass (F α β : Type*) [Bot α] [Bot β] [FunLike F α β] : Prop where
/-- A `BotHomClass` morphism preserves the bottom element. -/
map_bot (f : F) : f ⊥ = ⊥
/-- `BoundedOrderHomClass F α β` states that `F` is a type of bounded order morphisms.
You should extend this class when you extend `BoundedOrderHom`. -/
class BoundedOrderHomClass (F α β : Type*) [LE α] [LE β]
[BoundedOrder α] [BoundedOrder β] [FunLike F α β]
extends RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) : Prop where
/-- Morphisms preserve the top element. The preferred spelling is `_root_.map_top`. -/
map_top (f : F) : f ⊤ = ⊤
/-- Morphisms preserve the bottom element. The preferred spelling is `_root_.map_bot`. -/
map_bot (f : F) : f ⊥ = ⊥
end
export TopHomClass (map_top)
export BotHomClass (map_bot)
attribute [simp] map_top map_bot
section Hom
variable [FunLike F α β]
-- See note [lower instance priority]
instance (priority := 100) BoundedOrderHomClass.toTopHomClass [LE α] [LE β]
[BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : TopHomClass F α β :=
{ ‹BoundedOrderHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) BoundedOrderHomClass.toBotHomClass [LE α] [LE β]
[BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : BotHomClass F α β :=
{ ‹BoundedOrderHomClass F α β› with }
end Hom
section Equiv
variable [EquivLike F α β]
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toTopHomClass [LE α] [OrderTop α]
[PartialOrder β] [OrderTop β] [OrderIsoClass F α β] : TopHomClass F α β :=
{ show OrderHomClass F α β from inferInstance with
map_top := fun f => top_le_iff.1 <| (map_inv_le_iff f).1 le_top }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toBotHomClass [LE α] [OrderBot α]
[PartialOrder β] [OrderBot β] [OrderIsoClass F α β] : BotHomClass F α β :=
{ map_bot := fun f => le_bot_iff.1 <| (le_map_inv_iff f).1 bot_le }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toBoundedOrderHomClass [LE α] [BoundedOrder α]
[PartialOrder β] [BoundedOrder β] [OrderIsoClass F α β] : BoundedOrderHomClass F α β :=
{ show OrderHomClass F α β from inferInstance, OrderIsoClass.toTopHomClass,
OrderIsoClass.toBotHomClass with }
-- Porting note: the `letI` is needed because we can't make the
-- `OrderTop` parameters instance implicit in `OrderIsoClass.toTopHomClass`,
-- and they apparently can't be figured out through unification.
@[simp]
theorem map_eq_top_iff [LE α] [OrderTop α] [PartialOrder β] [OrderTop β] [OrderIsoClass F α β]
(f : F) {a : α} : f a = ⊤ ↔ a = ⊤ := by
letI : TopHomClass F α β := OrderIsoClass.toTopHomClass
rw [← map_top f, (EquivLike.injective f).eq_iff]
-- Porting note: the `letI` is needed because we can't make the
-- `OrderBot` parameters instance implicit in `OrderIsoClass.toBotHomClass`,
-- and they apparently can't be figured out through unification.
@[simp]
theorem map_eq_bot_iff [LE α] [OrderBot α] [PartialOrder β] [OrderBot β] [OrderIsoClass F α β]
(f : F) {a : α} : f a = ⊥ ↔ a = ⊥ := by
letI : BotHomClass F α β := OrderIsoClass.toBotHomClass
rw [← map_bot f, (EquivLike.injective f).eq_iff]
end Equiv
variable [FunLike F α β]
/-- Turn an element of a type `F` satisfying `TopHomClass F α β` into an actual
`TopHom`. This is declared as the default coercion from `F` to `TopHom α β`. -/
@[coe]
def TopHomClass.toTopHom [Top α] [Top β] [TopHomClass F α β] (f : F) : TopHom α β :=
⟨f, map_top f⟩
instance [Top α] [Top β] [TopHomClass F α β] : CoeTC F (TopHom α β) :=
⟨TopHomClass.toTopHom⟩
/-- Turn an element of a type `F` satisfying `BotHomClass F α β` into an actual
`BotHom`. This is declared as the default coercion from `F` to `BotHom α β`. -/
@[coe]
def BotHomClass.toBotHom [Bot α] [Bot β] [BotHomClass F α β] (f : F) : BotHom α β :=
⟨f, map_bot f⟩
instance [Bot α] [Bot β] [BotHomClass F α β] : CoeTC F (BotHom α β) :=
⟨BotHomClass.toBotHom⟩
/-- Turn an element of a type `F` satisfying `BoundedOrderHomClass F α β` into an actual
`BoundedOrderHom`. This is declared as the default coercion from `F` to `BoundedOrderHom α β`. -/
@[coe]
def BoundedOrderHomClass.toBoundedOrderHom [Preorder α] [Preorder β] [BoundedOrder α]
[BoundedOrder β] [BoundedOrderHomClass F α β] (f : F) : BoundedOrderHom α β :=
{ (f : α →o β) with toFun := f, map_top' := map_top f, map_bot' := map_bot f }
instance [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] :
CoeTC F (BoundedOrderHom α β) :=
⟨BoundedOrderHomClass.toBoundedOrderHom⟩
/-! ### Top homomorphisms -/
namespace TopHom
variable [Top α]
section Top
variable [Top β] [Top γ] [Top δ]
instance : FunLike (TopHom α β) α β where
coe := TopHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : TopHomClass (TopHom α β) α β where
map_top := TopHom.map_top'
-- this must come after the coe_to_fun definition
initialize_simps_projections TopHom (toFun → apply)
@[ext]
theorem ext {f g : TopHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `TopHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : TopHom α β) (f' : α → β) (h : f' = f) :
TopHom α β where
toFun := f'
map_top' := h.symm ▸ f.map_top'
@[simp]
theorem coe_copy (f : TopHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : TopHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
instance : Inhabited (TopHom α β) :=
⟨⟨fun _ => ⊤, rfl⟩⟩
variable (α)
/-- `id` as a `TopHom`. -/
protected def id : TopHom α α :=
⟨id, rfl⟩
@[simp]
theorem coe_id : ⇑(TopHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : TopHom.id α a = a :=
rfl
/-- Composition of `TopHom`s as a `TopHom`. -/
def comp (f : TopHom β γ) (g : TopHom α β) :
TopHom α γ where
toFun := f ∘ g
map_top' := by rw [comp_apply, map_top, map_top]
@[simp]
theorem coe_comp (f : TopHom β γ) (g : TopHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : TopHom β γ) (g : TopHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : TopHom γ δ) (g : TopHom β γ) (h : TopHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : TopHom α β) : f.comp (TopHom.id α) = f :=
TopHom.ext fun _ => rfl
@[simp]
theorem id_comp (f : TopHom α β) : (TopHom.id β).comp f = f :=
TopHom.ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : TopHom β γ} {f : TopHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => TopHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun g => comp g f)⟩
@[simp]
theorem cancel_left {g : TopHom β γ} {f₁ f₂ : TopHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => TopHom.ext fun a => hg <| by rw [← TopHom.comp_apply, h, TopHom.comp_apply],
congr_arg _⟩
end Top
instance instLE [LE β] [Top β] : LE (TopHom α β) where
le f g := (f : α → β) ≤ g
instance [Preorder β] [Top β] : Preorder (TopHom α β) :=
Preorder.lift (DFunLike.coe : TopHom α β → α → β)
instance [PartialOrder β] [Top β] : PartialOrder (TopHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
section OrderTop
variable [LE β] [OrderTop β]
instance : OrderTop (TopHom α β) where
top := ⟨⊤, rfl⟩
le_top := fun _ => @le_top (α → β) _ _ _
@[simp]
theorem coe_top : ⇑(⊤ : TopHom α β) = ⊤ :=
rfl
@[simp]
theorem top_apply (a : α) : (⊤ : TopHom α β) a = ⊤ :=
rfl
end OrderTop
section SemilatticeInf
variable [SemilatticeInf β] [OrderTop β] (f g : TopHom α β)
instance : Inf (TopHom α β) :=
⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_top, map_top, inf_top_eq]⟩⟩
instance : SemilatticeInf (TopHom α β) :=
(DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl
@[simp]
theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
@[simp]
theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
end SemilatticeInf
section SemilatticeSup
variable [SemilatticeSup β] [OrderTop β] (f g : TopHom α β)
instance : Sup (TopHom α β) :=
⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_top, map_top, sup_top_eq]⟩⟩
instance : SemilatticeSup (TopHom α β) :=
(DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl
@[simp]
theorem coe_sup : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
@[simp]
theorem sup_apply (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
end SemilatticeSup
instance [Lattice β] [OrderTop β] : Lattice (TopHom α β) :=
DFunLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl
instance [DistribLattice β] [OrderTop β] : DistribLattice (TopHom α β) :=
DFunLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
end TopHom
/-! ### Bot homomorphisms -/
namespace BotHom
variable [Bot α]
section Bot
variable [Bot β] [Bot γ] [Bot δ]
instance : FunLike (BotHom α β) α β where
coe := BotHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : BotHomClass (BotHom α β) α β where
map_bot := BotHom.map_bot'
-- this must come after the coe_to_fun definition
initialize_simps_projections BotHom (toFun → apply)
@[ext]
theorem ext {f g : BotHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `BotHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : BotHom α β) (f' : α → β) (h : f' = f) :
BotHom α β where
toFun := f'
map_bot' := h.symm ▸ f.map_bot'
@[simp]
theorem coe_copy (f : BotHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : BotHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
instance : Inhabited (BotHom α β) :=
⟨⟨fun _ => ⊥, rfl⟩⟩
variable (α)
/-- `id` as a `BotHom`. -/
protected def id : BotHom α α :=
⟨id, rfl⟩
@[simp]
theorem coe_id : ⇑(BotHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : BotHom.id α a = a :=
rfl
/-- Composition of `BotHom`s as a `BotHom`. -/
def comp (f : BotHom β γ) (g : BotHom α β) :
BotHom α γ where
toFun := f ∘ g
map_bot' := by rw [comp_apply, map_bot, map_bot]
@[simp]
theorem coe_comp (f : BotHom β γ) (g : BotHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : BotHom β γ) (g : BotHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : BotHom γ δ) (g : BotHom β γ) (h : BotHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : BotHom α β) : f.comp (BotHom.id α) = f :=
BotHom.ext fun _ => rfl
@[simp]
theorem id_comp (f : BotHom α β) : (BotHom.id β).comp f = f :=
BotHom.ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : BotHom β γ} {f : BotHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => BotHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (comp · f)⟩
@[simp]
theorem cancel_left {g : BotHom β γ} {f₁ f₂ : BotHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => BotHom.ext fun a => hg <| by rw [← BotHom.comp_apply, h, BotHom.comp_apply],
congr_arg _⟩
end Bot
instance instLE [LE β] [Bot β] : LE (BotHom α β) where
le f g := (f : α → β) ≤ g
instance [Preorder β] [Bot β] : Preorder (BotHom α β) :=
Preorder.lift (DFunLike.coe : BotHom α β → α → β)
instance [PartialOrder β] [Bot β] : PartialOrder (BotHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
section OrderBot
variable [LE β] [OrderBot β]
instance : OrderBot (BotHom α β) where
bot := ⟨⊥, rfl⟩
bot_le := fun _ => @bot_le (α → β) _ _ _
@[simp]
theorem coe_bot : ⇑(⊥ : BotHom α β) = ⊥ :=
rfl
@[simp]
theorem bot_apply (a : α) : (⊥ : BotHom α β) a = ⊥ :=
rfl
end OrderBot
section SemilatticeInf
variable [SemilatticeInf β] [OrderBot β] (f g : BotHom α β)
instance : Inf (BotHom α β) :=
⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_bot, map_bot, inf_bot_eq]⟩⟩
instance : SemilatticeInf (BotHom α β) :=
(DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl
@[simp]
theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
@[simp]
theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
end SemilatticeInf
section SemilatticeSup
variable [SemilatticeSup β] [OrderBot β] (f g : BotHom α β)
instance : Sup (BotHom α β) :=
⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_bot, map_bot, sup_bot_eq]⟩⟩
instance : SemilatticeSup (BotHom α β) :=
(DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl
@[simp]
theorem coe_sup : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
@[simp]
theorem sup_apply (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
end SemilatticeSup
instance [Lattice β] [OrderBot β] : Lattice (BotHom α β) :=
DFunLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl
instance [DistribLattice β] [OrderBot β] : DistribLattice (BotHom α β) :=
DFunLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl
end BotHom
/-! ### Bounded order homomorphisms -/
-- Porting note (#11215): TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
initialize_simps_projections BoundedOrderHom (+toOrderHom, -toFun)
namespace BoundedOrderHom
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] [BoundedOrder α] [BoundedOrder β]
[BoundedOrder γ] [BoundedOrder δ]
/-- Reinterpret a `BoundedOrderHom` as a `TopHom`. -/
def toTopHom (f : BoundedOrderHom α β) : TopHom α β :=
{ f with }
/-- Reinterpret a `BoundedOrderHom` as a `BotHom`. -/
def toBotHom (f : BoundedOrderHom α β) : BotHom α β :=
{ f with }
instance : FunLike (BoundedOrderHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr
instance : BoundedOrderHomClass (BoundedOrderHom α β) α β where
map_rel f := @(f.monotone')
map_top f := f.map_top'
map_bot f := f.map_bot'
@[ext]
theorem ext {f g : BoundedOrderHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `BoundedOrderHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : BoundedOrderHom α β :=
{ f.toOrderHom.copy f' h, f.toTopHom.copy f' h, f.toBotHom.copy f' h with }
@[simp]
theorem coe_copy (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : BoundedOrderHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `BoundedOrderHom`. -/
protected def id : BoundedOrderHom α α :=
{ OrderHom.id, TopHom.id α, BotHom.id α with }
instance : Inhabited (BoundedOrderHom α α) :=
⟨BoundedOrderHom.id α⟩
@[simp]
theorem coe_id : ⇑(BoundedOrderHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : BoundedOrderHom.id α a = a :=
rfl
/-- Composition of `BoundedOrderHom`s as a `BoundedOrderHom`. -/
def comp (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : BoundedOrderHom α γ :=
{ f.toOrderHom.comp g.toOrderHom, f.toTopHom.comp g.toTopHom, f.toBotHom.comp g.toBotHom with }
@[simp]
theorem coe_comp (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) (a : α) :
(f.comp g) a = f (g a) :=
rfl
@[simp]
theorem coe_comp_orderHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) :
(f.comp g : OrderHom α γ) = (f : OrderHom β γ).comp g :=
rfl
@[simp]
theorem coe_comp_topHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) :
(f.comp g : TopHom α γ) = (f : TopHom β γ).comp g :=
rfl
@[simp]
theorem coe_comp_botHom (f : BoundedOrderHom β γ) (g : BoundedOrderHom α β) :
(f.comp g : BotHom α γ) = (f : BotHom β γ).comp g :=
rfl
@[simp]
theorem comp_assoc (f : BoundedOrderHom γ δ) (g : BoundedOrderHom β γ) (h : BoundedOrderHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : BoundedOrderHom α β) : f.comp (BoundedOrderHom.id α) = f :=
BoundedOrderHom.ext fun _ => rfl
@[simp]
theorem id_comp (f : BoundedOrderHom α β) : (BoundedOrderHom.id β).comp f = f :=
BoundedOrderHom.ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : BoundedOrderHom β γ} {f : BoundedOrderHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => BoundedOrderHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h,
congr_arg (fun g => comp g f)⟩
@[simp]
theorem cancel_left {g : BoundedOrderHom β γ} {f₁ f₂ : BoundedOrderHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h =>
BoundedOrderHom.ext fun a =>
hg <| by rw [← BoundedOrderHom.comp_apply, h, BoundedOrderHom.comp_apply],
congr_arg _⟩
end BoundedOrderHom
/-! ### Dual homs -/
namespace TopHom
variable [LE α] [OrderTop α] [LE β] [OrderTop β] [LE γ] [OrderTop γ]
/-- Reinterpret a top homomorphism as a bot homomorphism between the dual lattices. -/
@[simps]
protected def dual :
TopHom α β ≃ BotHom αᵒᵈ βᵒᵈ where
toFun f := ⟨f, f.map_top'⟩
invFun f := ⟨f, f.map_bot'⟩
left_inv _ := TopHom.ext fun _ => rfl
right_inv _ := BotHom.ext fun _ => rfl
@[simp]
theorem dual_id : TopHom.dual (TopHom.id α) = BotHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : TopHom β γ) (f : TopHom α β) :
TopHom.dual (g.comp f) = g.dual.comp (TopHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : TopHom.dual.symm (BotHom.id _) = TopHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : BotHom βᵒᵈ γᵒᵈ) (f : BotHom αᵒᵈ βᵒᵈ) :
TopHom.dual.symm (g.comp f) = (TopHom.dual.symm g).comp (TopHom.dual.symm f) :=
rfl
end TopHom
namespace BotHom
variable [LE α] [OrderBot α] [LE β] [OrderBot β] [LE γ] [OrderBot γ]
/-- Reinterpret a bot homomorphism as a top homomorphism between the dual lattices. -/
@[simps]
protected def dual :
BotHom α β ≃ TopHom αᵒᵈ βᵒᵈ where
toFun f := ⟨f, f.map_bot'⟩
invFun f := ⟨f, f.map_top'⟩
left_inv _ := BotHom.ext fun _ => rfl
right_inv _ := TopHom.ext fun _ => rfl
@[simp]
theorem dual_id : BotHom.dual (BotHom.id α) = TopHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : BotHom β γ) (f : BotHom α β) :
BotHom.dual (g.comp f) = g.dual.comp (BotHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : BotHom.dual.symm (TopHom.id _) = BotHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : TopHom βᵒᵈ γᵒᵈ) (f : TopHom αᵒᵈ βᵒᵈ) :
BotHom.dual.symm (g.comp f) = (BotHom.dual.symm g).comp (BotHom.dual.symm f) :=
rfl
end BotHom
namespace BoundedOrderHom
variable [Preorder α] [BoundedOrder α] [Preorder β] [BoundedOrder β] [Preorder γ] [BoundedOrder γ]
/-- Reinterpret a bounded order homomorphism as a bounded order homomorphism between the dual
orders. -/
@[simps]
protected def dual :
BoundedOrderHom α β ≃
BoundedOrderHom αᵒᵈ
βᵒᵈ where
toFun f := ⟨OrderHom.dual f.toOrderHom, f.map_bot', f.map_top'⟩
invFun f := ⟨OrderHom.dual.symm f.toOrderHom, f.map_bot', f.map_top'⟩
left_inv _ := ext fun _ => rfl
right_inv _ := ext fun _ => rfl
@[simp]
theorem dual_id : BoundedOrderHom.dual (BoundedOrderHom.id α) = BoundedOrderHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : BoundedOrderHom β γ) (f : BoundedOrderHom α β) :
BoundedOrderHom.dual (g.comp f) = g.dual.comp (BoundedOrderHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : BoundedOrderHom.dual.symm (BoundedOrderHom.id _) = BoundedOrderHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : BoundedOrderHom βᵒᵈ γᵒᵈ) (f : BoundedOrderHom αᵒᵈ βᵒᵈ) :
BoundedOrderHom.dual.symm (g.comp f) =
(BoundedOrderHom.dual.symm g).comp (BoundedOrderHom.dual.symm f) :=
rfl
end BoundedOrderHom
|
Order\Hom\CompleteLattice.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Hom.Lattice
/-!
# Complete lattice homomorphisms
This file defines frame homomorphisms and complete lattice homomorphisms.
We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `sSupHom`: Maps which preserve `⨆`.
* `sInfHom`: Maps which preserve `⨅`.
* `FrameHom`: Frame homomorphisms. Maps which preserve `⨆`, `⊓` and `⊤`.
* `CompleteLatticeHom`: Complete lattice homomorphisms. Maps which preserve `⨆` and `⨅`.
## Typeclasses
* `sSupHomClass`
* `sInfHomClass`
* `FrameHomClass`
* `CompleteLatticeHomClass`
## Concrete homs
* `CompleteLatticeHom.setPreimage`: `Set.preimage` as a complete lattice homomorphism.
## TODO
Frame homs are Heyting homs.
-/
open Function OrderDual Set
variable {F α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*}
-- Porting note: mathport made this & sInfHom into "SupHomCat" and "InfHomCat".
/-- The type of `⨆`-preserving functions from `α` to `β`. -/
structure sSupHom (α β : Type*) [SupSet α] [SupSet β] where
/-- The underlying function of a sSupHom. -/
toFun : α → β
/-- The proposition that a `sSupHom` commutes with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
/-- The type of `⨅`-preserving functions from `α` to `β`. -/
structure sInfHom (α β : Type*) [InfSet α] [InfSet β] where
/-- The underlying function of an `sInfHom`. -/
toFun : α → β
/-- The proposition that a `sInfHom` commutes with arbitrary infima/meets -/
map_sInf' (s : Set α) : toFun (sInf s) = sInf (toFun '' s)
/-- The type of frame homomorphisms from `α` to `β`. They preserve finite meets and arbitrary joins.
-/
structure FrameHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends
InfTopHom α β where
/-- The proposition that frame homomorphisms commute with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
/-- The type of complete lattice homomorphisms from `α` to `β`. -/
structure CompleteLatticeHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends
sInfHom α β where
/-- The proposition that complete lattice homomorphism commutes with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
section
-- Porting note: mathport made this & InfHomClass into "SupHomClassCat" and "InfHomClassCat".
/-- `sSupHomClass F α β` states that `F` is a type of `⨆`-preserving morphisms.
You should extend this class when you extend `sSupHom`. -/
class sSupHomClass (F α β : Type*) [SupSet α] [SupSet β] [FunLike F α β] : Prop where
/-- The proposition that members of `sSupHomClass`s commute with arbitrary suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
/-- `sInfHomClass F α β` states that `F` is a type of `⨅`-preserving morphisms.
You should extend this class when you extend `sInfHom`. -/
class sInfHomClass (F α β : Type*) [InfSet α] [InfSet β] [FunLike F α β] : Prop where
/-- The proposition that members of `sInfHomClass`s commute with arbitrary infima/meets. -/
map_sInf (f : F) (s : Set α) : f (sInf s) = sInf (f '' s)
/-- `FrameHomClass F α β` states that `F` is a type of frame morphisms. They preserve `⊓` and `⨆`.
You should extend this class when you extend `FrameHom`. -/
class FrameHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β] [FunLike F α β]
extends InfTopHomClass F α β : Prop where
/-- The proposition that members of `FrameHomClass` commute with arbitrary suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
/-- `CompleteLatticeHomClass F α β` states that `F` is a type of complete lattice morphisms.
You should extend this class when you extend `CompleteLatticeHom`. -/
class CompleteLatticeHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β]
[FunLike F α β] extends sInfHomClass F α β : Prop where
/-- The proposition that members of `CompleteLatticeHomClass` commute with arbitrary
suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
end
export sSupHomClass (map_sSup)
export sInfHomClass (map_sInf)
attribute [simp] map_sSup map_sInf
section Hom
variable [FunLike F α β]
@[simp] theorem map_iSup [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ι → α) :
f (⨆ i, g i) = ⨆ i, f (g i) := by simp [iSup, ← Set.range_comp, Function.comp]
theorem map_iSup₂ [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ∀ i, κ i → α) :
f (⨆ (i) (j), g i j) = ⨆ (i) (j), f (g i j) := by simp_rw [map_iSup]
@[simp] theorem map_iInf [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ι → α) :
f (⨅ i, g i) = ⨅ i, f (g i) := by simp [iInf, ← Set.range_comp, Function.comp]
theorem map_iInf₂ [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ∀ i, κ i → α) :
f (⨅ (i) (j), g i j) = ⨅ (i) (j), f (g i j) := by simp_rw [map_iInf]
-- See note [lower instance priority]
instance (priority := 100) sSupHomClass.toSupBotHomClass [CompleteLattice α]
[CompleteLattice β] [sSupHomClass F α β] : SupBotHomClass F α β :=
{ ‹sSupHomClass F α β› with
map_sup := fun f a b => by
rw [← sSup_pair, map_sSup]
simp only [Set.image_pair, sSup_insert, sSup_singleton]
map_bot := fun f => by
rw [← sSup_empty, map_sSup, Set.image_empty, sSup_empty] }
-- See note [lower instance priority]
instance (priority := 100) sInfHomClass.toInfTopHomClass [CompleteLattice α]
[CompleteLattice β] [sInfHomClass F α β] : InfTopHomClass F α β :=
{ ‹sInfHomClass F α β› with
map_inf := fun f a b => by
rw [← sInf_pair, map_sInf, Set.image_pair]
simp only [Set.image_pair, sInf_insert, sInf_singleton]
map_top := fun f => by
rw [← sInf_empty, map_sInf, Set.image_empty, sInf_empty] }
-- See note [lower instance priority]
instance (priority := 100) FrameHomClass.tosSupHomClass [CompleteLattice α]
[CompleteLattice β] [FrameHomClass F α β] : sSupHomClass F α β :=
{ ‹FrameHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) FrameHomClass.toBoundedLatticeHomClass [CompleteLattice α]
[CompleteLattice β] [FrameHomClass F α β] : BoundedLatticeHomClass F α β :=
{ ‹FrameHomClass F α β›, sSupHomClass.toSupBotHomClass with }
-- See note [lower instance priority]
instance (priority := 100) CompleteLatticeHomClass.toFrameHomClass [CompleteLattice α]
[CompleteLattice β] [CompleteLatticeHomClass F α β] : FrameHomClass F α β :=
{ ‹CompleteLatticeHomClass F α β›, sInfHomClass.toInfTopHomClass with }
-- See note [lower instance priority]
instance (priority := 100) CompleteLatticeHomClass.toBoundedLatticeHomClass [CompleteLattice α]
[CompleteLattice β] [CompleteLatticeHomClass F α β] : BoundedLatticeHomClass F α β :=
{ sSupHomClass.toSupBotHomClass, sInfHomClass.toInfTopHomClass with }
end Hom
section Equiv
variable [EquivLike F α β]
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.tosSupHomClass [CompleteLattice α]
[CompleteLattice β] [OrderIsoClass F α β] : sSupHomClass F α β :=
{ show OrderHomClass F α β from inferInstance with
map_sSup := fun f s =>
eq_of_forall_ge_iff fun c => by
simp only [← le_map_inv_iff, sSup_le_iff, Set.forall_mem_image] }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.tosInfHomClass [CompleteLattice α]
[CompleteLattice β] [OrderIsoClass F α β] : sInfHomClass F α β :=
{ show OrderHomClass F α β from inferInstance with
map_sInf := fun f s =>
eq_of_forall_le_iff fun c => by
simp only [← map_inv_le_iff, le_sInf_iff, Set.forall_mem_image] }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toCompleteLatticeHomClass [CompleteLattice α]
[CompleteLattice β] [OrderIsoClass F α β] : CompleteLatticeHomClass F α β :=
-- Porting note: Used to be:
-- { OrderIsoClass.tosSupHomClass, OrderIsoClass.toLatticeHomClass,
-- show sInfHomClass F α β from inferInstance with }
{ OrderIsoClass.tosSupHomClass, OrderIsoClass.tosInfHomClass with }
end Equiv
variable [FunLike F α β]
/-- Reinterpret an order isomorphism as a morphism of complete lattices. -/
@[simps] def OrderIso.toCompleteLatticeHom [CompleteLattice α] [CompleteLattice β]
(f : OrderIso α β) : CompleteLatticeHom α β where
toFun := f
map_sInf' := sInfHomClass.map_sInf f
map_sSup' := sSupHomClass.map_sSup f
instance [SupSet α] [SupSet β] [sSupHomClass F α β] : CoeTC F (sSupHom α β) :=
⟨fun f => ⟨f, map_sSup f⟩⟩
instance [InfSet α] [InfSet β] [sInfHomClass F α β] : CoeTC F (sInfHom α β) :=
⟨fun f => ⟨f, map_sInf f⟩⟩
instance [CompleteLattice α] [CompleteLattice β] [FrameHomClass F α β] : CoeTC F (FrameHom α β) :=
⟨fun f => ⟨f, map_sSup f⟩⟩
instance [CompleteLattice α] [CompleteLattice β] [CompleteLatticeHomClass F α β] :
CoeTC F (CompleteLatticeHom α β) :=
⟨fun f => ⟨f, map_sSup f⟩⟩
/-! ### Supremum homomorphisms -/
namespace sSupHom
variable [SupSet α]
section SupSet
variable [SupSet β] [SupSet γ] [SupSet δ]
instance : FunLike (sSupHom α β) α β where
coe := sSupHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : sSupHomClass (sSupHom α β) α β where
map_sSup := sSupHom.map_sSup'
@[simp] lemma toFun_eq_coe (f : sSupHom α β) : f.toFun = f := rfl
@[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : sSupHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `sSupHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : sSupHom α β) (f' : α → β) (h : f' = f) : sSupHom α β where
toFun := f'
map_sSup' := h.symm ▸ f.map_sSup'
@[simp]
theorem coe_copy (f : sSupHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : sSupHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `sSupHom`. -/
protected def id : sSupHom α α :=
⟨id, fun s => by rw [id, Set.image_id]⟩
instance : Inhabited (sSupHom α α) :=
⟨sSupHom.id α⟩
@[simp]
theorem coe_id : ⇑(sSupHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : sSupHom.id α a = a :=
rfl
/-- Composition of `sSupHom`s as a `sSupHom`. -/
def comp (f : sSupHom β γ) (g : sSupHom α β) : sSupHom α γ where
toFun := f ∘ g
map_sSup' s := by rw [comp_apply, map_sSup, map_sSup, Set.image_image]; simp only [Function.comp]
@[simp]
theorem coe_comp (f : sSupHom β γ) (g : sSupHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : sSupHom β γ) (g : sSupHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : sSupHom γ δ) (g : sSupHom β γ) (h : sSupHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : sSupHom α β) : f.comp (sSupHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : sSupHom α β) : (sSupHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : sSupHom β γ} {f : sSupHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left {g : sSupHom β γ} {f₁ f₂ : sSupHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end SupSet
variable {_ : CompleteLattice β}
instance : PartialOrder (sSupHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
instance : Bot (sSupHom α β) :=
⟨⟨fun _ => ⊥, fun s => by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [Set.image_empty, sSup_empty]
· rw [hs.image_const, sSup_singleton]⟩⟩
instance : OrderBot (sSupHom α β) where
bot := ⊥
bot_le := fun _ _ ↦ CompleteLattice.bot_le _
@[simp]
theorem coe_bot : ⇑(⊥ : sSupHom α β) = ⊥ :=
rfl
@[simp]
theorem bot_apply (a : α) : (⊥ : sSupHom α β) a = ⊥ :=
rfl
end sSupHom
/-! ### Infimum homomorphisms -/
namespace sInfHom
variable [InfSet α]
section InfSet
variable [InfSet β] [InfSet γ] [InfSet δ]
instance : FunLike (sInfHom α β) α β where
coe := sInfHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : sInfHomClass (sInfHom α β) α β where
map_sInf := sInfHom.map_sInf'
@[simp] lemma toFun_eq_coe (f : sInfHom α β) : f.toFun = f := rfl
@[simp] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : sInfHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `sInfHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : sInfHom α β) (f' : α → β) (h : f' = f) : sInfHom α β where
toFun := f'
map_sInf' := h.symm ▸ f.map_sInf'
@[simp]
theorem coe_copy (f : sInfHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : sInfHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as an `sInfHom`. -/
protected def id : sInfHom α α :=
⟨id, fun s => by rw [id, Set.image_id]⟩
instance : Inhabited (sInfHom α α) :=
⟨sInfHom.id α⟩
@[simp]
theorem coe_id : ⇑(sInfHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : sInfHom.id α a = a :=
rfl
/-- Composition of `sInfHom`s as a `sInfHom`. -/
def comp (f : sInfHom β γ) (g : sInfHom α β) : sInfHom α γ where
toFun := f ∘ g
map_sInf' s := by rw [comp_apply, map_sInf, map_sInf, Set.image_image]; simp only [Function.comp]
@[simp]
theorem coe_comp (f : sInfHom β γ) (g : sInfHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : sInfHom β γ) (g : sInfHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : sInfHom γ δ) (g : sInfHom β γ) (h : sInfHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : sInfHom α β) : f.comp (sInfHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : sInfHom α β) : (sInfHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : sInfHom β γ} {f : sInfHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left {g : sInfHom β γ} {f₁ f₂ : sInfHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end InfSet
variable [CompleteLattice β]
instance : PartialOrder (sInfHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
instance : Top (sInfHom α β) :=
⟨⟨fun _ => ⊤, fun s => by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [Set.image_empty, sInf_empty]
· rw [hs.image_const, sInf_singleton]⟩⟩
instance : OrderTop (sInfHom α β) where
top := ⊤
le_top := fun _ _ => CompleteLattice.le_top _
@[simp]
theorem coe_top : ⇑(⊤ : sInfHom α β) = ⊤ :=
rfl
@[simp]
theorem top_apply (a : α) : (⊤ : sInfHom α β) a = ⊤ :=
rfl
end sInfHom
/-! ### Frame homomorphisms -/
namespace FrameHom
variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] [CompleteLattice δ]
instance : FunLike (FrameHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f
obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g
congr
instance : FrameHomClass (FrameHom α β) α β where
map_sSup f := f.map_sSup'
map_inf f := f.map_inf'
map_top f := f.map_top'
/-- Reinterpret a `FrameHom` as a `LatticeHom`. -/
def toLatticeHom (f : FrameHom α β) : LatticeHom α β :=
f
lemma toFun_eq_coe (f : FrameHom α β) : f.toFun = f := rfl
@[simp] lemma coe_toInfTopHom (f : FrameHom α β) : ⇑f.toInfTopHom = f := rfl
@[simp] lemma coe_toLatticeHom (f : FrameHom α β) : ⇑f.toLatticeHom = f := rfl
@[simp] lemma coe_mk (f : InfTopHom α β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : FrameHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `FrameHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : FrameHom α β) (f' : α → β) (h : f' = f) : FrameHom α β :=
{ (f : sSupHom α β).copy f' h with toInfTopHom := f.toInfTopHom.copy f' h }
@[simp]
theorem coe_copy (f : FrameHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : FrameHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `FrameHom`. -/
protected def id : FrameHom α α :=
{ sSupHom.id α with toInfTopHom := InfTopHom.id α }
instance : Inhabited (FrameHom α α) :=
⟨FrameHom.id α⟩
@[simp]
theorem coe_id : ⇑(FrameHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : FrameHom.id α a = a :=
rfl
/-- Composition of `FrameHom`s as a `FrameHom`. -/
def comp (f : FrameHom β γ) (g : FrameHom α β) : FrameHom α γ :=
{ (f : sSupHom β γ).comp (g : sSupHom α β) with
toInfTopHom := f.toInfTopHom.comp g.toInfTopHom }
@[simp]
theorem coe_comp (f : FrameHom β γ) (g : FrameHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : FrameHom β γ) (g : FrameHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : FrameHom γ δ) (g : FrameHom β γ) (h : FrameHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : FrameHom α β) : f.comp (FrameHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : FrameHom α β) : (FrameHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : FrameHom β γ} {f : FrameHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left {g : FrameHom β γ} {f₁ f₂ : FrameHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
instance : PartialOrder (FrameHom α β) :=
PartialOrder.lift _ DFunLike.coe_injective
end FrameHom
/-! ### Complete lattice homomorphisms -/
namespace CompleteLatticeHom
variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ] [CompleteLattice δ]
instance : FunLike (CompleteLatticeHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr
instance : CompleteLatticeHomClass (CompleteLatticeHom α β) α β where
map_sSup f := f.map_sSup'
map_sInf f := f.map_sInf'
/-- Reinterpret a `CompleteLatticeHom` as a `sSupHom`. -/
def tosSupHom (f : CompleteLatticeHom α β) : sSupHom α β :=
f
/-- Reinterpret a `CompleteLatticeHom` as a `BoundedLatticeHom`. -/
def toBoundedLatticeHom (f : CompleteLatticeHom α β) : BoundedLatticeHom α β :=
f
-- Porting note: We do not want CoeFun for this in lean 4
-- /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_toFun`
-- directly. -/
-- instance : CoeFun (CompleteLatticeHom α β) fun _ => α → β :=
-- DFunLike.hasCoeToFun
lemma toFun_eq_coe (f : CompleteLatticeHom α β) : f.toFun = f := rfl
@[simp] lemma coe_tosInfHom (f : CompleteLatticeHom α β) : ⇑f.tosInfHom = f := rfl
@[simp] lemma coe_tosSupHom (f : CompleteLatticeHom α β) : ⇑f.tosSupHom = f := rfl
@[simp] lemma coe_toBoundedLatticeHom (f : CompleteLatticeHom α β) : ⇑f.toBoundedLatticeHom = f :=
rfl
@[simp] lemma coe_mk (f : sInfHom α β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : CompleteLatticeHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `CompleteLatticeHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) :
CompleteLatticeHom α β :=
{ f.tosSupHom.copy f' h with tosInfHom := f.tosInfHom.copy f' h }
@[simp]
theorem coe_copy (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : CompleteLatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `CompleteLatticeHom`. -/
protected def id : CompleteLatticeHom α α :=
{ sSupHom.id α, sInfHom.id α with toFun := id }
instance : Inhabited (CompleteLatticeHom α α) :=
⟨CompleteLatticeHom.id α⟩
@[simp]
theorem coe_id : ⇑(CompleteLatticeHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : CompleteLatticeHom.id α a = a :=
rfl
/-- Composition of `CompleteLatticeHom`s as a `CompleteLatticeHom`. -/
def comp (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) : CompleteLatticeHom α γ :=
{ f.tosSupHom.comp g.tosSupHom with tosInfHom := f.tosInfHom.comp g.tosInfHom }
@[simp]
theorem coe_comp (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) : ⇑(f.comp g) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : CompleteLatticeHom β γ) (g : CompleteLatticeHom α β) (a : α) :
(f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : CompleteLatticeHom γ δ) (g : CompleteLatticeHom β γ)
(h : CompleteLatticeHom α β) : (f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : CompleteLatticeHom α β) : f.comp (CompleteLatticeHom.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : CompleteLatticeHom α β) : (CompleteLatticeHom.id β).comp f = f :=
ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : CompleteLatticeHom β γ} {f : CompleteLatticeHom α β}
(hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun a ↦ comp a f)⟩
@[simp]
theorem cancel_left {g : CompleteLatticeHom β γ} {f₁ f₂ : CompleteLatticeHom α β}
(hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end CompleteLatticeHom
/-! ### Dual homs -/
namespace sSupHom
variable [SupSet α] [SupSet β] [SupSet γ]
/-- Reinterpret a `⨆`-homomorphism as an `⨅`-homomorphism between the dual orders. -/
@[simps]
protected def dual : sSupHom α β ≃ sInfHom αᵒᵈ βᵒᵈ where
toFun f := ⟨toDual ∘ f ∘ ofDual, f.map_sSup'⟩
invFun f := ⟨ofDual ∘ f ∘ toDual, f.map_sInf'⟩
left_inv _ := sSupHom.ext fun _ => rfl
right_inv _ := sInfHom.ext fun _ => rfl
@[simp]
theorem dual_id : sSupHom.dual (sSupHom.id α) = sInfHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : sSupHom β γ) (f : sSupHom α β) :
sSupHom.dual (g.comp f) = (sSupHom.dual g).comp (sSupHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : sSupHom.dual.symm (sInfHom.id _) = sSupHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : sInfHom βᵒᵈ γᵒᵈ) (f : sInfHom αᵒᵈ βᵒᵈ) :
sSupHom.dual.symm (g.comp f) = (sSupHom.dual.symm g).comp (sSupHom.dual.symm f) :=
rfl
end sSupHom
namespace sInfHom
variable [InfSet α] [InfSet β] [InfSet γ]
/-- Reinterpret an `⨅`-homomorphism as a `⨆`-homomorphism between the dual orders. -/
@[simps]
protected def dual : sInfHom α β ≃ sSupHom αᵒᵈ βᵒᵈ where
toFun f :=
{ toFun := toDual ∘ f ∘ ofDual
map_sSup' := fun _ => congr_arg toDual (map_sInf f _) }
invFun f :=
{ toFun := ofDual ∘ f ∘ toDual
map_sInf' := fun _ => congr_arg ofDual (map_sSup f _) }
left_inv _ := sInfHom.ext fun _ => rfl
right_inv _ := sSupHom.ext fun _ => rfl
@[simp]
theorem dual_id : sInfHom.dual (sInfHom.id α) = sSupHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : sInfHom β γ) (f : sInfHom α β) :
sInfHom.dual (g.comp f) = (sInfHom.dual g).comp (sInfHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : sInfHom.dual.symm (sSupHom.id _) = sInfHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : sSupHom βᵒᵈ γᵒᵈ) (f : sSupHom αᵒᵈ βᵒᵈ) :
sInfHom.dual.symm (g.comp f) = (sInfHom.dual.symm g).comp (sInfHom.dual.symm f) :=
rfl
end sInfHom
namespace CompleteLatticeHom
variable [CompleteLattice α] [CompleteLattice β] [CompleteLattice γ]
/-- Reinterpret a complete lattice homomorphism as a complete lattice homomorphism between the dual
lattices. -/
@[simps!]
protected def dual : CompleteLatticeHom α β ≃ CompleteLatticeHom αᵒᵈ βᵒᵈ where
toFun f := ⟨sSupHom.dual f.tosSupHom, fun s ↦ f.map_sInf' s⟩
invFun f := ⟨sSupHom.dual f.tosSupHom, fun s ↦ f.map_sInf' s⟩
left_inv _ := ext fun _ => rfl
right_inv _ := ext fun _ => rfl
@[simp]
theorem dual_id : CompleteLatticeHom.dual (CompleteLatticeHom.id α) = CompleteLatticeHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : CompleteLatticeHom β γ) (f : CompleteLatticeHom α β) :
CompleteLatticeHom.dual (g.comp f) =
(CompleteLatticeHom.dual g).comp (CompleteLatticeHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id :
CompleteLatticeHom.dual.symm (CompleteLatticeHom.id _) = CompleteLatticeHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : CompleteLatticeHom βᵒᵈ γᵒᵈ) (f : CompleteLatticeHom αᵒᵈ βᵒᵈ) :
CompleteLatticeHom.dual.symm (g.comp f) =
(CompleteLatticeHom.dual.symm g).comp (CompleteLatticeHom.dual.symm f) :=
rfl
end CompleteLatticeHom
/-! ### Concrete homs -/
namespace CompleteLatticeHom
/-- `Set.preimage` as a complete lattice homomorphism.
See also `sSupHom.setImage`. -/
def setPreimage (f : α → β) : CompleteLatticeHom (Set β) (Set α) where
toFun := preimage f
map_sSup' s := preimage_sUnion.trans <| by simp only [Set.sSup_eq_sUnion, Set.sUnion_image]
map_sInf' s := preimage_sInter.trans <| by simp only [Set.sInf_eq_sInter, Set.sInter_image]
@[simp]
theorem coe_setPreimage (f : α → β) : ⇑(setPreimage f) = preimage f :=
rfl
@[simp]
theorem setPreimage_apply (f : α → β) (s : Set β) : setPreimage f s = s.preimage f :=
rfl
@[simp]
theorem setPreimage_id : setPreimage (id : α → α) = CompleteLatticeHom.id _ :=
rfl
-- This lemma can't be `simp` because `g ∘ f` matches anything (`id ∘ f = f` syntactically)
theorem setPreimage_comp (g : β → γ) (f : α → β) :
setPreimage (g ∘ f) = (setPreimage f).comp (setPreimage g) :=
rfl
end CompleteLatticeHom
theorem Set.image_sSup {f : α → β} (s : Set (Set α)) : f '' sSup s = sSup (image f '' s) :=
Set.image_sUnion
/-- Using `Set.image`, a function between types yields a `sSupHom` between their lattices of
subsets.
See also `CompleteLatticeHom.setPreimage`. -/
@[simps]
def sSupHom.setImage (f : α → β) : sSupHom (Set α) (Set β) where
toFun := image f
map_sSup' := Set.image_sSup
/-- An equivalence of types yields an order isomorphism between their lattices of subsets. -/
@[simps]
def Equiv.toOrderIsoSet (e : α ≃ β) : Set α ≃o Set β where
toFun s := e '' s
invFun s := e.symm '' s
left_inv s := by simp only [← image_comp, Equiv.symm_comp_self, id, image_id']
right_inv s := by simp only [← image_comp, Equiv.self_comp_symm, id, image_id']
map_rel_iff' :=
⟨fun h => by simpa using @monotone_image _ _ e.symm _ _ h, fun h => monotone_image h⟩
variable [CompleteLattice α] (x : α × α)
/-- The map `(a, b) ↦ a ⊔ b` as a `sSupHom`. -/
def supsSupHom : sSupHom (α × α) α where
toFun x := x.1 ⊔ x.2
map_sSup' s := by simp_rw [Prod.fst_sSup, Prod.snd_sSup, sSup_image, iSup_sup_eq]
/-- The map `(a, b) ↦ a ⊓ b` as an `sInfHom`. -/
def infsInfHom : sInfHom (α × α) α where
toFun x := x.1 ⊓ x.2
map_sInf' s := by simp_rw [Prod.fst_sInf, Prod.snd_sInf, sInf_image, iInf_inf_eq]
@[simp, norm_cast]
theorem supsSupHom_apply : supsSupHom x = x.1 ⊔ x.2 :=
rfl
@[simp, norm_cast]
theorem infsInfHom_apply : infsInfHom x = x.1 ⊓ x.2 :=
rfl
|
Order\Hom\Lattice.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Bounded
import Mathlib.Order.SymmDiff
/-!
# Lattice homomorphisms
This file defines (bounded) lattice homomorphisms.
We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `SupHom`: Maps which preserve `⊔`.
* `InfHom`: Maps which preserve `⊓`.
* `SupBotHom`: Finitary supremum homomorphisms. Maps which preserve `⊔` and `⊥`.
* `InfTopHom`: Finitary infimum homomorphisms. Maps which preserve `⊓` and `⊤`.
* `LatticeHom`: Lattice homomorphisms. Maps which preserve `⊔` and `⊓`.
* `BoundedLatticeHom`: Bounded lattice homomorphisms. Maps which preserve `⊤`, `⊥`, `⊔` and `⊓`.
## Typeclasses
* `SupHomClass`
* `InfHomClass`
* `SupBotHomClass`
* `InfTopHomClass`
* `LatticeHomClass`
* `BoundedLatticeHomClass`
## TODO
Do we need more intersections between `BotHom`, `TopHom` and lattice homomorphisms?
-/
open Function OrderDual
variable {F ι α β γ δ : Type*}
/-- The type of `⊔`-preserving functions from `α` to `β`. -/
structure SupHom (α β : Type*) [Sup α] [Sup β] where
/-- The underlying function of a `SupHom` -/
toFun : α → β
/-- A `SupHom` preserves suprema. -/
map_sup' (a b : α) : toFun (a ⊔ b) = toFun a ⊔ toFun b
/-- The type of `⊓`-preserving functions from `α` to `β`. -/
structure InfHom (α β : Type*) [Inf α] [Inf β] where
/-- The underlying function of an `InfHom` -/
toFun : α → β
/-- An `InfHom` preserves infima. -/
map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b
/-- The type of finitary supremum-preserving homomorphisms from `α` to `β`. -/
structure SupBotHom (α β : Type*) [Sup α] [Sup β] [Bot α] [Bot β] extends SupHom α β where
/-- A `SupBotHom` preserves the bottom element. -/
map_bot' : toFun ⊥ = ⊥
/-- The type of finitary infimum-preserving homomorphisms from `α` to `β`. -/
structure InfTopHom (α β : Type*) [Inf α] [Inf β] [Top α] [Top β] extends InfHom α β where
/-- An `InfTopHom` preserves the top element. -/
map_top' : toFun ⊤ = ⊤
/-- The type of lattice homomorphisms from `α` to `β`. -/
structure LatticeHom (α β : Type*) [Lattice α] [Lattice β] extends SupHom α β where
/-- A `LatticeHom` preserves infima. -/
map_inf' (a b : α) : toFun (a ⊓ b) = toFun a ⊓ toFun b
/-- The type of bounded lattice homomorphisms from `α` to `β`. -/
structure BoundedLatticeHom (α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α]
[BoundedOrder β] extends LatticeHom α β where
/-- A `BoundedLatticeHom` preserves the top element. -/
map_top' : toFun ⊤ = ⊤
/-- A `BoundedLatticeHom` preserves the bottom element. -/
map_bot' : toFun ⊥ = ⊥
-- Porting note (#11215): TODO: remove this configuration and use the default configuration.
-- We keep this to be consistent with Lean 3.
initialize_simps_projections SupBotHom (+toSupHom, -toFun)
initialize_simps_projections InfTopHom (+toInfHom, -toFun)
initialize_simps_projections LatticeHom (+toSupHom, -toFun)
initialize_simps_projections BoundedLatticeHom (+toLatticeHom, -toFun)
section
/-- `SupHomClass F α β` states that `F` is a type of `⊔`-preserving morphisms.
You should extend this class when you extend `SupHom`. -/
class SupHomClass (F α β : Type*) [Sup α] [Sup β] [FunLike F α β] : Prop where
/-- A `SupHomClass` morphism preserves suprema. -/
map_sup (f : F) (a b : α) : f (a ⊔ b) = f a ⊔ f b
/-- `InfHomClass F α β` states that `F` is a type of `⊓`-preserving morphisms.
You should extend this class when you extend `InfHom`. -/
class InfHomClass (F α β : Type*) [Inf α] [Inf β] [FunLike F α β] : Prop where
/-- An `InfHomClass` morphism preserves infima. -/
map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b
/-- `SupBotHomClass F α β` states that `F` is a type of finitary supremum-preserving morphisms.
You should extend this class when you extend `SupBotHom`. -/
class SupBotHomClass (F α β : Type*) [Sup α] [Sup β] [Bot α] [Bot β] [FunLike F α β]
extends SupHomClass F α β : Prop where
/-- A `SupBotHomClass` morphism preserves the bottom element. -/
map_bot (f : F) : f ⊥ = ⊥
/-- `InfTopHomClass F α β` states that `F` is a type of finitary infimum-preserving morphisms.
You should extend this class when you extend `SupBotHom`. -/
class InfTopHomClass (F α β : Type*) [Inf α] [Inf β] [Top α] [Top β] [FunLike F α β]
extends InfHomClass F α β : Prop where
/-- An `InfTopHomClass` morphism preserves the top element. -/
map_top (f : F) : f ⊤ = ⊤
/-- `LatticeHomClass F α β` states that `F` is a type of lattice morphisms.
You should extend this class when you extend `LatticeHom`. -/
class LatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [FunLike F α β]
extends SupHomClass F α β : Prop where
/-- A `LatticeHomClass` morphism preserves infima. -/
map_inf (f : F) (a b : α) : f (a ⊓ b) = f a ⊓ f b
/-- `BoundedLatticeHomClass F α β` states that `F` is a type of bounded lattice morphisms.
You should extend this class when you extend `BoundedLatticeHom`. -/
class BoundedLatticeHomClass (F α β : Type*) [Lattice α] [Lattice β] [BoundedOrder α]
[BoundedOrder β] [FunLike F α β] extends LatticeHomClass F α β : Prop where
/-- A `BoundedLatticeHomClass` morphism preserves the top element. -/
map_top (f : F) : f ⊤ = ⊤
/-- A `BoundedLatticeHomClass` morphism preserves the bottom element. -/
map_bot (f : F) : f ⊥ = ⊥
end
export SupHomClass (map_sup)
export InfHomClass (map_inf)
attribute [simp] map_top map_bot map_sup map_inf
section Hom
variable [FunLike F α β]
-- Porting note: changes to the typeclass inference system mean that we need to
-- make a lot of changes here, adding `outParams`, changing `[]`s into `{}` and
-- so on.
-- See note [lower instance priority]
instance (priority := 100) SupHomClass.toOrderHomClass [SemilatticeSup α] [SemilatticeSup β]
[SupHomClass F α β] : OrderHomClass F α β :=
{ ‹SupHomClass F α β› with
map_rel := fun f a b h => by rw [← sup_eq_right, ← map_sup, sup_eq_right.2 h] }
-- See note [lower instance priority]
instance (priority := 100) InfHomClass.toOrderHomClass [SemilatticeInf α] [SemilatticeInf β]
[InfHomClass F α β] : OrderHomClass F α β :=
{ ‹InfHomClass F α β› with
map_rel := fun f a b h => by rw [← inf_eq_left, ← map_inf, inf_eq_left.2 h] }
-- See note [lower instance priority]
instance (priority := 100) SupBotHomClass.toBotHomClass [Sup α] [Sup β] [Bot α]
[Bot β] [SupBotHomClass F α β] : BotHomClass F α β :=
{ ‹SupBotHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) InfTopHomClass.toTopHomClass [Inf α] [Inf β] [Top α]
[Top β] [InfTopHomClass F α β] : TopHomClass F α β :=
{ ‹InfTopHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) LatticeHomClass.toInfHomClass [Lattice α] [Lattice β]
[LatticeHomClass F α β] : InfHomClass F α β :=
{ ‹LatticeHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) BoundedLatticeHomClass.toSupBotHomClass [Lattice α] [Lattice β]
[BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] :
SupBotHomClass F α β :=
{ ‹BoundedLatticeHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) BoundedLatticeHomClass.toInfTopHomClass [Lattice α] [Lattice β]
[BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] :
InfTopHomClass F α β :=
{ ‹BoundedLatticeHomClass F α β› with }
-- See note [lower instance priority]
instance (priority := 100) BoundedLatticeHomClass.toBoundedOrderHomClass [Lattice α]
[Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] :
BoundedOrderHomClass F α β :=
{ show OrderHomClass F α β from inferInstance, ‹BoundedLatticeHomClass F α β› with }
end Hom
section Equiv
variable [EquivLike F α β]
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toSupHomClass [SemilatticeSup α] [SemilatticeSup β]
[OrderIsoClass F α β] : SupHomClass F α β :=
{ show OrderHomClass F α β from inferInstance with
map_sup := fun f a b =>
eq_of_forall_ge_iff fun c => by simp only [← le_map_inv_iff, sup_le_iff] }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toInfHomClass [SemilatticeInf α] [SemilatticeInf β]
[OrderIsoClass F α β] : InfHomClass F α β :=
{ show OrderHomClass F α β from inferInstance with
map_inf := fun f a b =>
eq_of_forall_le_iff fun c => by simp only [← map_inv_le_iff, le_inf_iff] }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toSupBotHomClass [SemilatticeSup α] [OrderBot α]
[SemilatticeSup β] [OrderBot β] [OrderIsoClass F α β] : SupBotHomClass F α β :=
{ OrderIsoClass.toSupHomClass, OrderIsoClass.toBotHomClass with }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toInfTopHomClass [SemilatticeInf α] [OrderTop α]
[SemilatticeInf β] [OrderTop β] [OrderIsoClass F α β] : InfTopHomClass F α β :=
{ OrderIsoClass.toInfHomClass, OrderIsoClass.toTopHomClass with }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toLatticeHomClass [Lattice α] [Lattice β]
[OrderIsoClass F α β] : LatticeHomClass F α β :=
{ OrderIsoClass.toSupHomClass, OrderIsoClass.toInfHomClass with }
-- See note [lower instance priority]
instance (priority := 100) OrderIsoClass.toBoundedLatticeHomClass [Lattice α] [Lattice β]
[BoundedOrder α] [BoundedOrder β] [OrderIsoClass F α β] :
BoundedLatticeHomClass F α β :=
{ OrderIsoClass.toLatticeHomClass, OrderIsoClass.toBoundedOrderHomClass with }
end Equiv
section OrderEmbedding
variable [FunLike F α β]
/-- We can regard an injective map preserving binary infima as an order embedding. -/
@[simps! apply]
def orderEmbeddingOfInjective [SemilatticeInf α] [SemilatticeInf β] (f : F) [InfHomClass F α β]
(hf : Injective f) : α ↪o β :=
OrderEmbedding.ofMapLEIff f (fun x y ↦ by
refine ⟨fun h ↦ ?_, fun h ↦ OrderHomClass.mono f h⟩
rwa [← inf_eq_left, ← hf.eq_iff, map_inf, inf_eq_left])
end OrderEmbedding
section BoundedLattice
variable [Lattice α] [BoundedOrder α] [Lattice β] [BoundedOrder β]
variable [FunLike F α β] [BoundedLatticeHomClass F α β]
variable (f : F) {a b : α}
theorem Disjoint.map (h : Disjoint a b) : Disjoint (f a) (f b) := by
rw [disjoint_iff, ← map_inf, h.eq_bot, map_bot]
theorem Codisjoint.map (h : Codisjoint a b) : Codisjoint (f a) (f b) := by
rw [codisjoint_iff, ← map_sup, h.eq_top, map_top]
theorem IsCompl.map (h : IsCompl a b) : IsCompl (f a) (f b) :=
⟨h.1.map _, h.2.map _⟩
end BoundedLattice
section BooleanAlgebra
variable [BooleanAlgebra α] [BooleanAlgebra β] [FunLike F α β] [BoundedLatticeHomClass F α β]
variable (f : F)
/-- Special case of `map_compl` for boolean algebras. -/
theorem map_compl' (a : α) : f aᶜ = (f a)ᶜ :=
(isCompl_compl.map _).compl_eq.symm
/-- Special case of `map_sdiff` for boolean algebras. -/
theorem map_sdiff' (a b : α) : f (a \ b) = f a \ f b := by
rw [sdiff_eq, sdiff_eq, map_inf, map_compl']
open scoped symmDiff in
/-- Special case of `map_symmDiff` for boolean algebras. -/
theorem map_symmDiff' (a b : α) : f (a ∆ b) = f a ∆ f b := by
rw [symmDiff, symmDiff, map_sup, map_sdiff', map_sdiff']
end BooleanAlgebra
variable [FunLike F α β]
instance [Sup α] [Sup β] [SupHomClass F α β] : CoeTC F (SupHom α β) :=
⟨fun f => ⟨f, map_sup f⟩⟩
instance [Inf α] [Inf β] [InfHomClass F α β] : CoeTC F (InfHom α β) :=
⟨fun f => ⟨f, map_inf f⟩⟩
instance [Sup α] [Sup β] [Bot α] [Bot β] [SupBotHomClass F α β] : CoeTC F (SupBotHom α β) :=
⟨fun f => ⟨f, map_bot f⟩⟩
instance [Inf α] [Inf β] [Top α] [Top β] [InfTopHomClass F α β] : CoeTC F (InfTopHom α β) :=
⟨fun f => ⟨f, map_top f⟩⟩
instance [Lattice α] [Lattice β] [LatticeHomClass F α β] : CoeTC F (LatticeHom α β) :=
⟨fun f =>
{ toFun := f
map_sup' := map_sup f
map_inf' := map_inf f }⟩
instance [Lattice α] [Lattice β] [BoundedOrder α] [BoundedOrder β] [BoundedLatticeHomClass F α β] :
CoeTC F (BoundedLatticeHom α β) :=
⟨fun f =>
{ (f : LatticeHom α β) with
toFun := f
map_top' := map_top f
map_bot' := map_bot f }⟩
/-! ### Supremum homomorphisms -/
namespace SupHom
variable [Sup α]
section Sup
variable [Sup β] [Sup γ] [Sup δ]
instance : FunLike (SupHom α β) α β where
coe := SupHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : SupHomClass (SupHom α β) α β where
map_sup := SupHom.map_sup'
@[simp] lemma toFun_eq_coe (f : SupHom α β) : f.toFun = f := rfl
@[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : SupHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `SupHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : SupHom α β) (f' : α → β) (h : f' = f) : SupHom α β where
toFun := f'
map_sup' := h.symm ▸ f.map_sup'
@[simp]
theorem coe_copy (f : SupHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : SupHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `SupHom`. -/
protected def id : SupHom α α :=
⟨id, fun _ _ => rfl⟩
instance : Inhabited (SupHom α α) :=
⟨SupHom.id α⟩
@[simp]
theorem coe_id : ⇑(SupHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : SupHom.id α a = a :=
rfl
/-- Composition of `SupHom`s as a `SupHom`. -/
def comp (f : SupHom β γ) (g : SupHom α β) : SupHom α γ where
toFun := f ∘ g
map_sup' a b := by rw [comp_apply, map_sup, map_sup]; rfl
@[simp]
theorem coe_comp (f : SupHom β γ) (g : SupHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : SupHom β γ) (g : SupHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : SupHom γ δ) (g : SupHom β γ) (h : SupHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp] theorem comp_id (f : SupHom α β) : f.comp (SupHom.id α) = f := rfl
@[simp] theorem id_comp (f : SupHom α β) : (SupHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : SupHom β γ} {f : SupHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => SupHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : SupHom β γ} {f₁ f₂ : SupHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => SupHom.ext fun a => hg <| by rw [← SupHom.comp_apply, h, SupHom.comp_apply],
congr_arg _⟩
end Sup
variable (α) [SemilatticeSup β]
/-- The constant function as a `SupHom`. -/
def const (b : β) : SupHom α β := ⟨fun _ ↦ b, fun _ _ ↦ (sup_idem _).symm⟩
@[simp]
theorem coe_const (b : β) : ⇑(const α b) = Function.const α b :=
rfl
@[simp]
theorem const_apply (b : β) (a : α) : const α b a = b :=
rfl
variable {α}
instance : Sup (SupHom α β) :=
⟨fun f g =>
⟨f ⊔ g, fun a b => by
rw [Pi.sup_apply, map_sup, map_sup]
exact sup_sup_sup_comm _ _ _ _⟩⟩
instance : SemilatticeSup (SupHom α β) :=
(DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl
instance [Bot β] : Bot (SupHom α β) :=
⟨SupHom.const α ⊥⟩
instance [Top β] : Top (SupHom α β) :=
⟨SupHom.const α ⊤⟩
instance [OrderBot β] : OrderBot (SupHom α β) :=
OrderBot.lift ((↑) : _ → α → β) (fun _ _ => id) rfl
instance [OrderTop β] : OrderTop (SupHom α β) :=
OrderTop.lift ((↑) : _ → α → β) (fun _ _ => id) rfl
instance [BoundedOrder β] : BoundedOrder (SupHom α β) :=
BoundedOrder.lift ((↑) : _ → α → β) (fun _ _ => id) rfl rfl
@[simp]
theorem coe_sup (f g : SupHom α β) : DFunLike.coe (f ⊔ g) = f ⊔ g :=
rfl
@[simp]
theorem coe_bot [Bot β] : ⇑(⊥ : SupHom α β) = ⊥ :=
rfl
@[simp]
theorem coe_top [Top β] : ⇑(⊤ : SupHom α β) = ⊤ :=
rfl
@[simp]
theorem sup_apply (f g : SupHom α β) (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
@[simp]
theorem bot_apply [Bot β] (a : α) : (⊥ : SupHom α β) a = ⊥ :=
rfl
@[simp]
theorem top_apply [Top β] (a : α) : (⊤ : SupHom α β) a = ⊤ :=
rfl
end SupHom
/-! ### Infimum homomorphisms -/
namespace InfHom
variable [Inf α]
section Inf
variable [Inf β] [Inf γ] [Inf δ]
instance : FunLike (InfHom α β) α β where
coe := InfHom.toFun
coe_injective' f g h := by cases f; cases g; congr
instance : InfHomClass (InfHom α β) α β where
map_inf := InfHom.map_inf'
@[simp] lemma toFun_eq_coe (f : InfHom α β) : f.toFun = (f : α → β) := rfl
@[simp, norm_cast] lemma coe_mk (f : α → β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : InfHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of an `InfHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : InfHom α β) (f' : α → β) (h : f' = f) : InfHom α β where
toFun := f'
map_inf' := h.symm ▸ f.map_inf'
@[simp]
theorem coe_copy (f : InfHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : InfHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as an `InfHom`. -/
protected def id : InfHom α α :=
⟨id, fun _ _ => rfl⟩
instance : Inhabited (InfHom α α) :=
⟨InfHom.id α⟩
@[simp]
theorem coe_id : ⇑(InfHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : InfHom.id α a = a :=
rfl
/-- Composition of `InfHom`s as an `InfHom`. -/
def comp (f : InfHom β γ) (g : InfHom α β) : InfHom α γ where
toFun := f ∘ g
map_inf' a b := by rw [comp_apply, map_inf, map_inf]; rfl
@[simp]
theorem coe_comp (f : InfHom β γ) (g : InfHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : InfHom β γ) (g : InfHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : InfHom γ δ) (g : InfHom β γ) (h : InfHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp] theorem comp_id (f : InfHom α β) : f.comp (InfHom.id α) = f := rfl
@[simp] theorem id_comp (f : InfHom α β) : (InfHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : InfHom β γ} {f : InfHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => InfHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : InfHom β γ} {f₁ f₂ : InfHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => InfHom.ext fun a => hg <| by rw [← InfHom.comp_apply, h, InfHom.comp_apply],
congr_arg _⟩
end Inf
variable (α) [SemilatticeInf β]
/-- The constant function as an `InfHom`. -/
def const (b : β) : InfHom α β := ⟨fun _ ↦ b, fun _ _ ↦ (inf_idem _).symm⟩
@[simp]
theorem coe_const (b : β) : ⇑(const α b) = Function.const α b :=
rfl
@[simp]
theorem const_apply (b : β) (a : α) : const α b a = b :=
rfl
variable {α}
instance : Inf (InfHom α β) :=
⟨fun f g =>
⟨f ⊓ g, fun a b => by
rw [Pi.inf_apply, map_inf, map_inf]
exact inf_inf_inf_comm _ _ _ _⟩⟩
instance : SemilatticeInf (InfHom α β) :=
(DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl
instance [Bot β] : Bot (InfHom α β) :=
⟨InfHom.const α ⊥⟩
instance [Top β] : Top (InfHom α β) :=
⟨InfHom.const α ⊤⟩
instance [OrderBot β] : OrderBot (InfHom α β) :=
OrderBot.lift ((↑) : _ → α → β) (fun _ _ => id) rfl
instance [OrderTop β] : OrderTop (InfHom α β) :=
OrderTop.lift ((↑) : _ → α → β) (fun _ _ => id) rfl
instance [BoundedOrder β] : BoundedOrder (InfHom α β) :=
BoundedOrder.lift ((↑) : _ → α → β) (fun _ _ => id) rfl rfl
@[simp]
theorem coe_inf (f g : InfHom α β) : DFunLike.coe (f ⊓ g) = f ⊓ g :=
rfl
@[simp]
theorem coe_bot [Bot β] : ⇑(⊥ : InfHom α β) = ⊥ :=
rfl
@[simp]
theorem coe_top [Top β] : ⇑(⊤ : InfHom α β) = ⊤ :=
rfl
@[simp]
theorem inf_apply (f g : InfHom α β) (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
@[simp]
theorem bot_apply [Bot β] (a : α) : (⊥ : InfHom α β) a = ⊥ :=
rfl
@[simp]
theorem top_apply [Top β] (a : α) : (⊤ : InfHom α β) a = ⊤ :=
rfl
end InfHom
/-! ### Finitary supremum homomorphisms -/
namespace SupBotHom
variable [Sup α] [Bot α]
section Sup
variable [Sup β] [Bot β] [Sup γ] [Bot γ] [Sup δ] [Bot δ]
/-- Reinterpret a `SupBotHom` as a `BotHom`. -/
def toBotHom (f : SupBotHom α β) : BotHom α β :=
{ f with }
instance : FunLike (SupBotHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨_, _⟩, _⟩ := f
obtain ⟨⟨_, _⟩, _⟩ := g
congr
instance : SupBotHomClass (SupBotHom α β) α β where
map_sup f := f.map_sup'
map_bot f := f.map_bot'
lemma toFun_eq_coe (f : SupBotHom α β) : f.toFun = f := rfl
@[simp] lemma coe_toSupHom (f : SupBotHom α β) : ⇑f.toSupHom = f := rfl
@[simp] lemma coe_toBotHom (f : SupBotHom α β) : ⇑f.toBotHom = f := rfl
@[simp] lemma coe_mk (f : SupHom α β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : SupBotHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `SupBotHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : SupBotHom α β) (f' : α → β) (h : f' = f) : SupBotHom α β :=
{ f.toBotHom.copy f' h with toSupHom := f.toSupHom.copy f' h }
@[simp]
theorem coe_copy (f : SupBotHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : SupBotHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `SupBotHom`. -/
@[simps]
protected def id : SupBotHom α α :=
⟨SupHom.id α, rfl⟩
instance : Inhabited (SupBotHom α α) :=
⟨SupBotHom.id α⟩
@[simp]
theorem coe_id : ⇑(SupBotHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : SupBotHom.id α a = a :=
rfl
/-- Composition of `SupBotHom`s as a `SupBotHom`. -/
def comp (f : SupBotHom β γ) (g : SupBotHom α β) : SupBotHom α γ :=
{ f.toSupHom.comp g.toSupHom, f.toBotHom.comp g.toBotHom with }
@[simp]
theorem coe_comp (f : SupBotHom β γ) (g : SupBotHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : SupBotHom β γ) (g : SupBotHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : SupBotHom γ δ) (g : SupBotHom β γ) (h : SupBotHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp] theorem comp_id (f : SupBotHom α β) : f.comp (SupBotHom.id α) = f := rfl
@[simp] theorem id_comp (f : SupBotHom α β) : (SupBotHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : SupBotHom β γ} {f : SupBotHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : SupBotHom β γ} {f₁ f₂ : SupBotHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => SupBotHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end Sup
variable [SemilatticeSup β] [OrderBot β]
instance : Sup (SupBotHom α β) :=
⟨fun f g => { f.toBotHom ⊔ g.toBotHom with toSupHom := f.toSupHom ⊔ g.toSupHom }⟩
instance : SemilatticeSup (SupBotHom α β) :=
(DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl
instance : OrderBot (SupBotHom α β) where
bot := ⟨⊥, rfl⟩
bot_le _ _ := bot_le
@[simp]
theorem coe_sup (f g : SupBotHom α β) : DFunLike.coe (f ⊔ g) = f ⊔ g :=
rfl
@[simp]
theorem coe_bot : ⇑(⊥ : SupBotHom α β) = ⊥ :=
rfl
@[simp]
theorem sup_apply (f g : SupBotHom α β) (a : α) : (f ⊔ g) a = f a ⊔ g a :=
rfl
@[simp]
theorem bot_apply (a : α) : (⊥ : SupBotHom α β) a = ⊥ :=
rfl
end SupBotHom
/-! ### Finitary infimum homomorphisms -/
namespace InfTopHom
variable [Inf α] [Top α]
section Inf
variable [Inf β] [Top β] [Inf γ] [Top γ] [Inf δ] [Top δ]
/-- Reinterpret an `InfTopHom` as a `TopHom`. -/
def toTopHom (f : InfTopHom α β) : TopHom α β :=
{ f with }
instance : FunLike (InfTopHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨_, _⟩, _⟩ := f
obtain ⟨⟨_, _⟩, _⟩ := g
congr
instance : InfTopHomClass (InfTopHom α β) α β where
map_inf f := f.map_inf'
map_top f := f.map_top'
theorem toFun_eq_coe (f : InfTopHom α β) : f.toFun = f := rfl
@[simp] lemma coe_toInfHom (f : InfTopHom α β) : ⇑f.toInfHom = f := rfl
@[simp] lemma coe_toTopHom (f : InfTopHom α β) : ⇑f.toTopHom = f := rfl
@[simp] lemma coe_mk (f : InfHom α β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : InfTopHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of an `InfTopHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : InfTopHom α β) (f' : α → β) (h : f' = f) : InfTopHom α β :=
{ f.toTopHom.copy f' h with toInfHom := f.toInfHom.copy f' h }
@[simp]
theorem coe_copy (f : InfTopHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : InfTopHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as an `InfTopHom`. -/
@[simps]
protected def id : InfTopHom α α :=
⟨InfHom.id α, rfl⟩
instance : Inhabited (InfTopHom α α) :=
⟨InfTopHom.id α⟩
@[simp]
theorem coe_id : ⇑(InfTopHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : InfTopHom.id α a = a :=
rfl
/-- Composition of `InfTopHom`s as an `InfTopHom`. -/
def comp (f : InfTopHom β γ) (g : InfTopHom α β) : InfTopHom α γ :=
{ f.toInfHom.comp g.toInfHom, f.toTopHom.comp g.toTopHom with }
@[simp]
theorem coe_comp (f : InfTopHom β γ) (g : InfTopHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : InfTopHom β γ) (g : InfTopHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
theorem comp_assoc (f : InfTopHom γ δ) (g : InfTopHom β γ) (h : InfTopHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp] theorem comp_id (f : InfTopHom α β) : f.comp (InfTopHom.id α) = f := rfl
@[simp] theorem id_comp (f : InfTopHom α β) : (InfTopHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : InfTopHom β γ} {f : InfTopHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : InfTopHom β γ} {f₁ f₂ : InfTopHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => InfTopHom.ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end Inf
variable [SemilatticeInf β] [OrderTop β]
instance : Inf (InfTopHom α β) :=
⟨fun f g => { f.toTopHom ⊓ g.toTopHom with toInfHom := f.toInfHom ⊓ g.toInfHom }⟩
instance : SemilatticeInf (InfTopHom α β) :=
(DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl
instance : OrderTop (InfTopHom α β) where
top := ⟨⊤, rfl⟩
le_top _ _ := le_top
@[simp]
theorem coe_inf (f g : InfTopHom α β) : DFunLike.coe (f ⊓ g) = f ⊓ g :=
rfl
@[simp]
theorem coe_top : ⇑(⊤ : InfTopHom α β) = ⊤ :=
rfl
@[simp]
theorem inf_apply (f g : InfTopHom α β) (a : α) : (f ⊓ g) a = f a ⊓ g a :=
rfl
@[simp]
theorem top_apply (a : α) : (⊤ : InfTopHom α β) a = ⊤ :=
rfl
end InfTopHom
/-! ### Lattice homomorphisms -/
namespace LatticeHom
variable [Lattice α] [Lattice β] [Lattice γ] [Lattice δ]
/-- Reinterpret a `LatticeHom` as an `InfHom`. -/
def toInfHom (f : LatticeHom α β) : InfHom α β :=
{ f with }
instance : FunLike (LatticeHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f; obtain ⟨⟨_, _⟩, _⟩ := g; congr
instance : LatticeHomClass (LatticeHom α β) α β where
map_sup f := f.map_sup'
map_inf f := f.map_inf'
lemma toFun_eq_coe (f : LatticeHom α β) : f.toFun = f := rfl
@[simp] lemma coe_toSupHom (f : LatticeHom α β) : ⇑f.toSupHom = f := rfl
@[simp] lemma coe_toInfHom (f : LatticeHom α β) : ⇑f.toInfHom = f := rfl
@[simp] lemma coe_mk (f : SupHom α β) (hf) : ⇑(mk f hf) = f := rfl
@[ext]
theorem ext {f g : LatticeHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `LatticeHom` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (f : LatticeHom α β) (f' : α → β) (h : f' = f) : LatticeHom α β :=
{ f.toSupHom.copy f' h, f.toInfHom.copy f' h with }
@[simp]
theorem coe_copy (f : LatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : LatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `LatticeHom`. -/
protected def id : LatticeHom α α where
toFun := id
map_sup' _ _ := rfl
map_inf' _ _ := rfl
instance : Inhabited (LatticeHom α α) :=
⟨LatticeHom.id α⟩
@[simp]
theorem coe_id : ⇑(LatticeHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : LatticeHom.id α a = a :=
rfl
/-- Composition of `LatticeHom`s as a `LatticeHom`. -/
def comp (f : LatticeHom β γ) (g : LatticeHom α β) : LatticeHom α γ :=
{ f.toSupHom.comp g.toSupHom, f.toInfHom.comp g.toInfHom with }
@[simp]
theorem coe_comp (f : LatticeHom β γ) (g : LatticeHom α β) : (f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : LatticeHom β γ) (g : LatticeHom α β) (a : α) : (f.comp g) a = f (g a) :=
rfl
@[simp]
-- Porting note: `simp`-normal form of `coe_comp_sup_hom`
theorem coe_comp_sup_hom' (f : LatticeHom β γ) (g : LatticeHom α β) :
⟨f ∘ g, map_sup (f.comp g)⟩ = (f : SupHom β γ).comp g :=
rfl
theorem coe_comp_sup_hom (f : LatticeHom β γ) (g : LatticeHom α β) :
(f.comp g : SupHom α γ) = (f : SupHom β γ).comp g :=
rfl
@[simp]
-- Porting note: `simp`-normal form of `coe_comp_inf_hom`
theorem coe_comp_inf_hom' (f : LatticeHom β γ) (g : LatticeHom α β) :
⟨f ∘ g, map_inf (f.comp g)⟩ = (f : InfHom β γ).comp g :=
rfl
theorem coe_comp_inf_hom (f : LatticeHom β γ) (g : LatticeHom α β) :
(f.comp g : InfHom α γ) = (f : InfHom β γ).comp g :=
rfl
@[simp]
theorem comp_assoc (f : LatticeHom γ δ) (g : LatticeHom β γ) (h : LatticeHom α β) :
(f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp]
theorem comp_id (f : LatticeHom α β) : f.comp (LatticeHom.id α) = f :=
LatticeHom.ext fun _ => rfl
@[simp]
theorem id_comp (f : LatticeHom α β) : (LatticeHom.id β).comp f = f :=
LatticeHom.ext fun _ => rfl
@[simp]
theorem cancel_right {g₁ g₂ : LatticeHom β γ} {f : LatticeHom α β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => LatticeHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : LatticeHom β γ} {f₁ f₂ : LatticeHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => LatticeHom.ext fun a => hg <| by rw [← LatticeHom.comp_apply, h, LatticeHom.comp_apply],
congr_arg _⟩
end LatticeHom
namespace OrderHomClass
variable (α β) [LinearOrder α] [Lattice β] [FunLike F α β] [OrderHomClass F α β]
/-- An order homomorphism from a linear order is a lattice homomorphism. -/
-- Porting note: made it an `instance` because we're no longer afraid of loops
instance (priority := 100) toLatticeHomClass : LatticeHomClass F α β :=
{ ‹OrderHomClass F α β› with
map_sup := fun f a b => by
obtain h | h := le_total a b
· rw [sup_eq_right.2 h, sup_eq_right.2 (OrderHomClass.mono f h : f a ≤ f b)]
· rw [sup_eq_left.2 h, sup_eq_left.2 (OrderHomClass.mono f h : f b ≤ f a)]
map_inf := fun f a b => by
obtain h | h := le_total a b
· rw [inf_eq_left.2 h, inf_eq_left.2 (OrderHomClass.mono f h : f a ≤ f b)]
· rw [inf_eq_right.2 h, inf_eq_right.2 (OrderHomClass.mono f h : f b ≤ f a)] }
/-- Reinterpret an order homomorphism to a linear order as a `LatticeHom`. -/
def toLatticeHom (f : F) : LatticeHom α β := f
@[simp]
theorem coe_to_lattice_hom (f : F) : ⇑(toLatticeHom α β f) = f :=
rfl
@[simp]
theorem to_lattice_hom_apply (f : F) (a : α) : toLatticeHom α β f a = f a :=
rfl
end OrderHomClass
/-! ### Bounded lattice homomorphisms -/
namespace BoundedLatticeHom
variable [Lattice α] [Lattice β] [Lattice γ] [Lattice δ] [BoundedOrder α] [BoundedOrder β]
[BoundedOrder γ] [BoundedOrder δ]
/-- Reinterpret a `BoundedLatticeHom` as a `SupBotHom`. -/
def toSupBotHom (f : BoundedLatticeHom α β) : SupBotHom α β :=
{ f with }
/-- Reinterpret a `BoundedLatticeHom` as an `InfTopHom`. -/
def toInfTopHom (f : BoundedLatticeHom α β) : InfTopHom α β :=
{ f with }
/-- Reinterpret a `BoundedLatticeHom` as a `BoundedOrderHom`. -/
def toBoundedOrderHom (f : BoundedLatticeHom α β) : BoundedOrderHom α β :=
{ f, (f.toLatticeHom : α →o β) with }
instance instFunLike : FunLike (BoundedLatticeHom α β) α β where
coe f := f.toFun
coe_injective' f g h := by obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := f; obtain ⟨⟨⟨_, _⟩, _⟩, _⟩ := g; congr
instance instBoundedLatticeHomClass : BoundedLatticeHomClass (BoundedLatticeHom α β) α β where
map_sup f := f.map_sup'
map_inf f := f.map_inf'
map_top f := f.map_top'
map_bot f := f.map_bot'
@[simp] lemma toFun_eq_coe (f : BoundedLatticeHom α β) : f.toFun = f := rfl
@[simp] lemma coe_toLatticeHom (f : BoundedLatticeHom α β) : ⇑f.toLatticeHom = f := rfl
@[simp] lemma coe_toSupBotHom (f : BoundedLatticeHom α β) : ⇑f.toSupBotHom = f := rfl
@[simp] lemma coe_toInfTopHom (f : BoundedLatticeHom α β) : ⇑f.toInfTopHom = f := rfl
@[simp] lemma coe_toBoundedOrderHom (f : BoundedLatticeHom α β) : ⇑f.toBoundedOrderHom = f := rfl
@[simp] lemma coe_mk (f : LatticeHom α β) (hf hf') : ⇑(mk f hf hf') = f := rfl
@[ext]
theorem ext {f g : BoundedLatticeHom α β} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext f g h
/-- Copy of a `BoundedLatticeHom` with a new `toFun` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : BoundedLatticeHom α β :=
{ f.toLatticeHom.copy f' h, f.toBoundedOrderHom.copy f' h with }
@[simp]
theorem coe_copy (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' :=
rfl
theorem copy_eq (f : BoundedLatticeHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable (α)
/-- `id` as a `BoundedLatticeHom`. -/
protected def id : BoundedLatticeHom α α :=
{ LatticeHom.id α, BoundedOrderHom.id α with }
instance : Inhabited (BoundedLatticeHom α α) :=
⟨BoundedLatticeHom.id α⟩
@[simp]
theorem coe_id : ⇑(BoundedLatticeHom.id α) = id :=
rfl
variable {α}
@[simp]
theorem id_apply (a : α) : BoundedLatticeHom.id α a = a :=
rfl
/-- Composition of `BoundedLatticeHom`s as a `BoundedLatticeHom`. -/
def comp (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) : BoundedLatticeHom α γ :=
{ f.toLatticeHom.comp g.toLatticeHom, f.toBoundedOrderHom.comp g.toBoundedOrderHom with }
@[simp]
theorem coe_comp (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
(f.comp g : α → γ) = f ∘ g :=
rfl
@[simp]
theorem comp_apply (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) (a : α) :
(f.comp g) a = f (g a) :=
rfl
@[simp]
-- Porting note: `simp`-normal form of `coe_comp_lattice_hom`
theorem coe_comp_lattice_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
(⟨(f : SupHom β γ).comp g, map_inf (f.comp g)⟩ : LatticeHom α γ) =
(f : LatticeHom β γ).comp g :=
rfl
theorem coe_comp_lattice_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
(f.comp g : LatticeHom α γ) = (f : LatticeHom β γ).comp g :=
rfl
@[simp]
-- Porting note: `simp`-normal form of `coe_comp_sup_hom`
theorem coe_comp_sup_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
⟨f ∘ g, map_sup (f.comp g)⟩ = (f : SupHom β γ).comp g :=
rfl
theorem coe_comp_sup_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
(f.comp g : SupHom α γ) = (f : SupHom β γ).comp g :=
rfl
@[simp]
-- Porting note: `simp`-normal form of `coe_comp_inf_hom`
theorem coe_comp_inf_hom' (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
⟨f ∘ g, map_inf (f.comp g)⟩ = (f : InfHom β γ).comp g :=
rfl
theorem coe_comp_inf_hom (f : BoundedLatticeHom β γ) (g : BoundedLatticeHom α β) :
(f.comp g : InfHom α γ) = (f : InfHom β γ).comp g :=
rfl
@[simp]
theorem comp_assoc (f : BoundedLatticeHom γ δ) (g : BoundedLatticeHom β γ)
(h : BoundedLatticeHom α β) : (f.comp g).comp h = f.comp (g.comp h) :=
rfl
@[simp] theorem comp_id (f : BoundedLatticeHom α β) : f.comp (BoundedLatticeHom.id α) = f := rfl
@[simp] theorem id_comp (f : BoundedLatticeHom α β) : (BoundedLatticeHom.id β).comp f = f := rfl
@[simp]
theorem cancel_right {g₁ g₂ : BoundedLatticeHom β γ} {f : BoundedLatticeHom α β}
(hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => BoundedLatticeHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h,
fun h => congr_arg₂ _ h rfl⟩
@[simp]
theorem cancel_left {g : BoundedLatticeHom β γ} {f₁ f₂ : BoundedLatticeHom α β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => ext fun a => hg <| by rw [← comp_apply, h, comp_apply], congr_arg _⟩
end BoundedLatticeHom
/-! ### Dual homs -/
namespace SupHom
variable [Sup α] [Sup β] [Sup γ]
/-- Reinterpret a supremum homomorphism as an infimum homomorphism between the dual lattices. -/
@[simps]
protected def dual : SupHom α β ≃ InfHom αᵒᵈ βᵒᵈ where
toFun f := ⟨f, f.map_sup'⟩
invFun f := ⟨f, f.map_inf'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp]
theorem dual_id : SupHom.dual (SupHom.id α) = InfHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : SupHom β γ) (f : SupHom α β) :
SupHom.dual (g.comp f) = (SupHom.dual g).comp (SupHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : SupHom.dual.symm (InfHom.id _) = SupHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : InfHom βᵒᵈ γᵒᵈ) (f : InfHom αᵒᵈ βᵒᵈ) :
SupHom.dual.symm (g.comp f) =
(SupHom.dual.symm g).comp (SupHom.dual.symm f) :=
rfl
end SupHom
namespace InfHom
variable [Inf α] [Inf β] [Inf γ]
/-- Reinterpret an infimum homomorphism as a supremum homomorphism between the dual lattices. -/
@[simps]
protected def dual : InfHom α β ≃ SupHom αᵒᵈ βᵒᵈ where
toFun f := ⟨f, f.map_inf'⟩
invFun f := ⟨f, f.map_sup'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp]
theorem dual_id : InfHom.dual (InfHom.id α) = SupHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : InfHom β γ) (f : InfHom α β) :
InfHom.dual (g.comp f) = (InfHom.dual g).comp (InfHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : InfHom.dual.symm (SupHom.id _) = InfHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : SupHom βᵒᵈ γᵒᵈ) (f : SupHom αᵒᵈ βᵒᵈ) :
InfHom.dual.symm (g.comp f) =
(InfHom.dual.symm g).comp (InfHom.dual.symm f) :=
rfl
end InfHom
namespace SupBotHom
variable [Sup α] [Bot α] [Sup β] [Bot β] [Sup γ] [Bot γ]
/-- Reinterpret a finitary supremum homomorphism as a finitary infimum homomorphism between the dual
lattices. -/
def dual : SupBotHom α β ≃ InfTopHom αᵒᵈ βᵒᵈ where
toFun f := ⟨SupHom.dual f.toSupHom, f.map_bot'⟩
invFun f := ⟨SupHom.dual.symm f.toInfHom, f.map_top'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp] theorem dual_id : SupBotHom.dual (SupBotHom.id α) = InfTopHom.id _ := rfl
@[simp]
theorem dual_comp (g : SupBotHom β γ) (f : SupBotHom α β) :
SupBotHom.dual (g.comp f) = (SupBotHom.dual g).comp (SupBotHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : SupBotHom.dual.symm (InfTopHom.id _) = SupBotHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : InfTopHom βᵒᵈ γᵒᵈ) (f : InfTopHom αᵒᵈ βᵒᵈ) :
SupBotHom.dual.symm (g.comp f) =
(SupBotHom.dual.symm g).comp (SupBotHom.dual.symm f) :=
rfl
end SupBotHom
namespace InfTopHom
variable [Inf α] [Top α] [Inf β] [Top β] [Inf γ] [Top γ]
/-- Reinterpret a finitary infimum homomorphism as a finitary supremum homomorphism between the dual
lattices. -/
@[simps]
protected def dual : InfTopHom α β ≃ SupBotHom αᵒᵈ βᵒᵈ where
toFun f := ⟨InfHom.dual f.toInfHom, f.map_top'⟩
invFun f := ⟨InfHom.dual.symm f.toSupHom, f.map_bot'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp]
theorem dual_id : InfTopHom.dual (InfTopHom.id α) = SupBotHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : InfTopHom β γ) (f : InfTopHom α β) :
InfTopHom.dual (g.comp f) = (InfTopHom.dual g).comp (InfTopHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : InfTopHom.dual.symm (SupBotHom.id _) = InfTopHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : SupBotHom βᵒᵈ γᵒᵈ) (f : SupBotHom αᵒᵈ βᵒᵈ) :
InfTopHom.dual.symm (g.comp f) =
(InfTopHom.dual.symm g).comp (InfTopHom.dual.symm f) :=
rfl
end InfTopHom
namespace LatticeHom
variable [Lattice α] [Lattice β] [Lattice γ]
/-- Reinterpret a lattice homomorphism as a lattice homomorphism between the dual lattices. -/
@[simps]
protected def dual : LatticeHom α β ≃ LatticeHom αᵒᵈ βᵒᵈ where
toFun f := ⟨InfHom.dual f.toInfHom, f.map_sup'⟩
invFun f := ⟨SupHom.dual.symm f.toInfHom, f.map_sup'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp] theorem dual_id : LatticeHom.dual (LatticeHom.id α) = LatticeHom.id _ := rfl
@[simp]
theorem dual_comp (g : LatticeHom β γ) (f : LatticeHom α β) :
LatticeHom.dual (g.comp f) = (LatticeHom.dual g).comp (LatticeHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id : LatticeHom.dual.symm (LatticeHom.id _) = LatticeHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : LatticeHom βᵒᵈ γᵒᵈ) (f : LatticeHom αᵒᵈ βᵒᵈ) :
LatticeHom.dual.symm (g.comp f) =
(LatticeHom.dual.symm g).comp (LatticeHom.dual.symm f) :=
rfl
end LatticeHom
namespace BoundedLatticeHom
variable [Lattice α] [BoundedOrder α] [Lattice β] [BoundedOrder β] [Lattice γ] [BoundedOrder γ]
/-- Reinterpret a bounded lattice homomorphism as a bounded lattice homomorphism between the dual
bounded lattices. -/
@[simps]
protected def dual : BoundedLatticeHom α β ≃ BoundedLatticeHom αᵒᵈ βᵒᵈ where
toFun f := ⟨LatticeHom.dual f.toLatticeHom, f.map_bot', f.map_top'⟩
invFun f := ⟨LatticeHom.dual.symm f.toLatticeHom, f.map_bot', f.map_top'⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp]
theorem dual_id : BoundedLatticeHom.dual (BoundedLatticeHom.id α) = BoundedLatticeHom.id _ :=
rfl
@[simp]
theorem dual_comp (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) :
BoundedLatticeHom.dual (g.comp f) =
(BoundedLatticeHom.dual g).comp (BoundedLatticeHom.dual f) :=
rfl
@[simp]
theorem symm_dual_id :
BoundedLatticeHom.dual.symm (BoundedLatticeHom.id _) = BoundedLatticeHom.id α :=
rfl
@[simp]
theorem symm_dual_comp (g : BoundedLatticeHom βᵒᵈ γᵒᵈ) (f : BoundedLatticeHom αᵒᵈ βᵒᵈ) :
BoundedLatticeHom.dual.symm (g.comp f) =
(BoundedLatticeHom.dual.symm g).comp (BoundedLatticeHom.dual.symm f) :=
rfl
end BoundedLatticeHom
/-! ### Prod -/
namespace LatticeHom
variable [Lattice α] [Lattice β]
/-- Natural projection homomorphism from `α × β` to `α`. -/
def fst : LatticeHom (α × β) α where
toFun := Prod.fst
map_sup' _ _ := rfl
map_inf' _ _ := rfl
/-- Natural projection homomorphism from `α × β` to `β`. -/
def snd : LatticeHom (α × β) β where
toFun := Prod.snd
map_sup' _ _ := rfl
map_inf' _ _ := rfl
@[simp, norm_cast] lemma coe_fst : ⇑(fst (α := α) (β := β)) = Prod.fst := rfl
@[simp, norm_cast] lemma coe_snd : ⇑(snd (α := α) (β := β)) = Prod.snd := rfl
lemma fst_apply (x : α × β) : fst x = x.fst := rfl
lemma snd_apply (x : α × β) : snd x = x.snd := rfl
end LatticeHom
/-! ### Pi -/
namespace Pi
variable {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)]
/-- Evaluation as a lattice homomorphism. -/
def evalLatticeHom (i : ι) : LatticeHom (∀ i, α i) (α i) where
toFun := Function.eval i
map_sup' _a _b := rfl
map_inf' _a _b := rfl
@[simp, norm_cast]
lemma coe_evalLatticeHom (i : ι) : ⇑(evalLatticeHom (α := α) i) = Function.eval i := rfl
lemma evalLatticeHom_apply (i : ι) (f : ∀ i, α i) : evalLatticeHom i f = f i := rfl
end Pi
/-! ### `WithTop`, `WithBot` -/
namespace SupHom
variable [SemilatticeSup α] [SemilatticeSup β] [SemilatticeSup γ]
/-- Adjoins a `⊤` to the domain and codomain of a `SupHom`. -/
@[simps]
protected def withTop (f : SupHom α β) : SupHom (WithTop α) (WithTop β) where
-- Porting note: this was `Option.map f`
toFun := WithTop.map f
map_sup' a b :=
match a, b with
| ⊤, ⊤ => rfl
| ⊤, (b : α) => rfl
| (a : α), ⊤ => rfl
| (a : α), (b : α) => congr_arg _ (f.map_sup' _ _)
@[simp]
theorem withTop_id : (SupHom.id α).withTop = SupHom.id _ := DFunLike.coe_injective Option.map_id
@[simp]
theorem withTop_comp (f : SupHom β γ) (g : SupHom α β) :
(f.comp g).withTop = f.withTop.comp g.withTop :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊥` to the domain and codomain of a `SupHom`. -/
@[simps]
protected def withBot (f : SupHom α β) : SupBotHom (WithBot α) (WithBot β) where
toFun := Option.map f
map_sup' a b :=
match a, b with
| ⊥, ⊥ => rfl
| ⊥, (b : α) => rfl
| (a : α), ⊥ => rfl
| (a : α), (b : α) => congr_arg _ (f.map_sup' _ _)
map_bot' := rfl
@[simp]
theorem withBot_id : (SupHom.id α).withBot = SupBotHom.id _ := DFunLike.coe_injective Option.map_id
@[simp]
theorem withBot_comp (f : SupHom β γ) (g : SupHom α β) :
(f.comp g).withBot = f.withBot.comp g.withBot :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊤` to the codomain of a `SupHom`. -/
@[simps]
def withTop' [OrderTop β] (f : SupHom α β) : SupHom (WithTop α) β where
toFun a := a.elim ⊤ f
map_sup' a b :=
match a, b with
| ⊤, ⊤ => (top_sup_eq _).symm
| ⊤, (b : α) => (top_sup_eq _).symm
| (a : α), ⊤ => (sup_top_eq _).symm
| (a : α), (b : α) => f.map_sup' _ _
/-- Adjoins a `⊥` to the domain of a `SupHom`. -/
@[simps]
def withBot' [OrderBot β] (f : SupHom α β) : SupBotHom (WithBot α) β where
toFun a := a.elim ⊥ f
map_sup' a b :=
match a, b with
| ⊥, ⊥ => (bot_sup_eq _).symm
| ⊥, (b : α) => (bot_sup_eq _).symm
| (a : α), ⊥ => (sup_bot_eq _).symm
| (a : α), (b : α) => f.map_sup' _ _
map_bot' := rfl
end SupHom
namespace InfHom
variable [SemilatticeInf α] [SemilatticeInf β] [SemilatticeInf γ]
/-- Adjoins a `⊤` to the domain and codomain of an `InfHom`. -/
@[simps]
protected def withTop (f : InfHom α β) : InfTopHom (WithTop α) (WithTop β) where
toFun := Option.map f
map_inf' a b :=
match a, b with
| ⊤, ⊤ => rfl
| ⊤, (b : α) => rfl
| (a : α), ⊤ => rfl
| (a : α), (b : α) => congr_arg _ (f.map_inf' _ _)
map_top' := rfl
@[simp]
theorem withTop_id : (InfHom.id α).withTop = InfTopHom.id _ := DFunLike.coe_injective Option.map_id
@[simp]
theorem withTop_comp (f : InfHom β γ) (g : InfHom α β) :
(f.comp g).withTop = f.withTop.comp g.withTop :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊥` to the domain and codomain of an `InfHom`. -/
@[simps]
protected def withBot (f : InfHom α β) : InfHom (WithBot α) (WithBot β) where
toFun := Option.map f
map_inf' a b :=
match a, b with
| ⊥, ⊥ => rfl
| ⊥, (b : α) => rfl
| (a : α), ⊥ => rfl
| (a : α), (b : α) => congr_arg _ (f.map_inf' _ _)
@[simp]
theorem withBot_id : (InfHom.id α).withBot = InfHom.id _ := DFunLike.coe_injective Option.map_id
@[simp]
theorem withBot_comp (f : InfHom β γ) (g : InfHom α β) :
(f.comp g).withBot = f.withBot.comp g.withBot :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊤` to the codomain of an `InfHom`. -/
@[simps]
def withTop' [OrderTop β] (f : InfHom α β) : InfTopHom (WithTop α) β where
toFun a := a.elim ⊤ f
map_inf' a b :=
match a, b with
| ⊤, ⊤ => (top_inf_eq _).symm
| ⊤, (b : α) => (top_inf_eq _).symm
| (a : α), ⊤ => (inf_top_eq _).symm
| (a : α), (b : α) => f.map_inf' _ _
map_top' := rfl
/-- Adjoins a `⊥` to the codomain of an `InfHom`. -/
@[simps]
def withBot' [OrderBot β] (f : InfHom α β) : InfHom (WithBot α) β where
toFun a := a.elim ⊥ f
map_inf' a b :=
match a, b with
| ⊥, ⊥ => (bot_inf_eq _).symm
| ⊥, (b : α) => (bot_inf_eq _).symm
| (a : α), ⊥ => (inf_bot_eq _).symm
| (a : α), (b : α) => f.map_inf' _ _
end InfHom
namespace LatticeHom
variable [Lattice α] [Lattice β] [Lattice γ]
/-- Adjoins a `⊤` to the domain and codomain of a `LatticeHom`. -/
@[simps]
protected def withTop (f : LatticeHom α β) : LatticeHom (WithTop α) (WithTop β) :=
{ f.toInfHom.withTop with toSupHom := f.toSupHom.withTop }
-- Porting note: `simps` doesn't generate those
@[simp, norm_cast]
lemma coe_withTop (f : LatticeHom α β) : ⇑f.withTop = WithTop.map f := rfl
lemma withTop_apply (f : LatticeHom α β) (a : WithTop α) : f.withTop a = a.map f := rfl
@[simp]
theorem withTop_id : (LatticeHom.id α).withTop = LatticeHom.id _ :=
DFunLike.coe_injective Option.map_id
@[simp]
theorem withTop_comp (f : LatticeHom β γ) (g : LatticeHom α β) :
(f.comp g).withTop = f.withTop.comp g.withTop :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊥` to the domain and codomain of a `LatticeHom`. -/
@[simps]
protected def withBot (f : LatticeHom α β) : LatticeHom (WithBot α) (WithBot β) :=
{ f.toInfHom.withBot with toSupHom := f.toSupHom.withBot }
-- Porting note: `simps` doesn't generate those
@[simp, norm_cast]
lemma coe_withBot (f : LatticeHom α β) : ⇑f.withBot = Option.map f := rfl
lemma withBot_apply (f : LatticeHom α β) (a : WithBot α) : f.withBot a = a.map f := rfl
@[simp]
theorem withBot_id : (LatticeHom.id α).withBot = LatticeHom.id _ :=
DFunLike.coe_injective Option.map_id
@[simp]
theorem withBot_comp (f : LatticeHom β γ) (g : LatticeHom α β) :
(f.comp g).withBot = f.withBot.comp g.withBot :=
-- Porting note: Proof was `DFunLike.coe_injective (Option.map_comp_map _ _).symm`
DFunLike.coe_injective <| Eq.symm <| Option.map_comp_map _ _
/-- Adjoins a `⊤` and `⊥` to the domain and codomain of a `LatticeHom`. -/
@[simps]
def withTopWithBot (f : LatticeHom α β) :
BoundedLatticeHom (WithTop <| WithBot α) (WithTop <| WithBot β) :=
⟨f.withBot.withTop, rfl, rfl⟩
-- Porting note: `simps` doesn't generate those
@[simp, norm_cast]
lemma coe_withTopWithBot (f : LatticeHom α β) : ⇑f.withTopWithBot = Option.map (Option.map f) := rfl
lemma withTopWithBot_apply (f : LatticeHom α β) (a : WithTop <| WithBot α) :
f.withTopWithBot a = a.map (Option.map f) := rfl
@[simp]
theorem withTopWithBot_id : (LatticeHom.id α).withTopWithBot = BoundedLatticeHom.id _ :=
DFunLike.coe_injective <| by
refine (congr_arg Option.map ?_).trans Option.map_id
rw [withBot_id]
rfl
@[simp]
theorem withTopWithBot_comp (f : LatticeHom β γ) (g : LatticeHom α β) :
(f.comp g).withTopWithBot = f.withTopWithBot.comp g.withTopWithBot := by
ext; simp
/-- Adjoins a `⊥` to the codomain of a `LatticeHom`. -/
@[simps]
def withTop' [OrderTop β] (f : LatticeHom α β) : LatticeHom (WithTop α) β :=
{ f.toSupHom.withTop', f.toInfHom.withTop' with }
/-- Adjoins a `⊥` to the domain and codomain of a `LatticeHom`. -/
@[simps]
def withBot' [OrderBot β] (f : LatticeHom α β) : LatticeHom (WithBot α) β :=
{ f.toSupHom.withBot', f.toInfHom.withBot' with }
/-- Adjoins a `⊤` and `⊥` to the codomain of a `LatticeHom`. -/
@[simps]
def withTopWithBot' [BoundedOrder β] (f : LatticeHom α β) :
BoundedLatticeHom (WithTop <| WithBot α) β where
toLatticeHom := f.withBot'.withTop'
map_top' := rfl
map_bot' := rfl
end LatticeHom
|
Order\Hom\Order.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Anne Baanen
-/
import Mathlib.Logic.Function.Iterate
import Mathlib.Order.GaloisConnection
import Mathlib.Order.Hom.Basic
/-!
# Lattice structure on order homomorphisms
This file defines the lattice structure on order homomorphisms, which are bundled
monotone functions.
## Main definitions
* `OrderHom.CompleteLattice`: if `β` is a complete lattice, so is `α →o β`
## Tags
monotone map, bundled morphism
-/
namespace OrderHom
variable {α β : Type*}
section Preorder
variable [Preorder α]
instance [SemilatticeSup β] : Sup (α →o β) where
sup f g := ⟨fun a => f a ⊔ g a, f.mono.sup g.mono⟩
-- Porting note: this is the lemma that could have been generated by `@[simps]` on the
--above instance but with a nicer name
@[simp] lemma coe_sup [SemilatticeSup β] (f g : α →o β) :
((f ⊔ g : α →o β) : α → β) = (f : α → β) ⊔ g := rfl
instance [SemilatticeSup β] : SemilatticeSup (α →o β) :=
{ (_ : PartialOrder (α →o β)) with
sup := Sup.sup
le_sup_left := fun _ _ _ => le_sup_left
le_sup_right := fun _ _ _ => le_sup_right
sup_le := fun _ _ _ h₀ h₁ x => sup_le (h₀ x) (h₁ x) }
instance [SemilatticeInf β] : Inf (α →o β) where
inf f g := ⟨fun a => f a ⊓ g a, f.mono.inf g.mono⟩
-- Porting note: this is the lemma that could have been generated by `@[simps]` on the
--above instance but with a nicer name
@[simp] lemma coe_inf [SemilatticeInf β] (f g : α →o β) :
((f ⊓ g : α →o β) : α → β) = (f : α → β) ⊓ g := rfl
instance [SemilatticeInf β] : SemilatticeInf (α →o β) :=
{ (_ : PartialOrder (α →o β)), (dualIso α β).symm.toGaloisInsertion.liftSemilatticeInf with
inf := (· ⊓ ·) }
instance lattice [Lattice β] : Lattice (α →o β) :=
{ (_ : SemilatticeSup (α →o β)), (_ : SemilatticeInf (α →o β)) with }
@[simps]
instance [Preorder β] [OrderBot β] : Bot (α →o β) where
bot := const α ⊥
instance orderBot [Preorder β] [OrderBot β] : OrderBot (α →o β) where
bot := ⊥
bot_le _ _ := bot_le
@[simps]
instance instTopOrderHom [Preorder β] [OrderTop β] : Top (α →o β) where
top := const α ⊤
instance orderTop [Preorder β] [OrderTop β] : OrderTop (α →o β) where
top := ⊤
le_top _ _ := le_top
instance [CompleteLattice β] : InfSet (α →o β) where
sInf s := ⟨fun x => ⨅ f ∈ s, (f : _) x, fun _ _ h => iInf₂_mono fun f _ => f.mono h⟩
@[simp]
theorem sInf_apply [CompleteLattice β] (s : Set (α →o β)) (x : α) :
sInf s x = ⨅ f ∈ s, (f : _) x :=
rfl
theorem iInf_apply {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) (x : α) :
(⨅ i, f i) x = ⨅ i, f i x :=
(sInf_apply _ _).trans iInf_range
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) :
((⨅ i, f i : α →o β) : α → β) = ⨅ i, (f i : α → β) := by
funext x; simp [iInf_apply]
instance [CompleteLattice β] : SupSet (α →o β) where
sSup s := ⟨fun x => ⨆ f ∈ s, (f : _) x, fun _ _ h => iSup₂_mono fun f _ => f.mono h⟩
@[simp]
theorem sSup_apply [CompleteLattice β] (s : Set (α →o β)) (x : α) :
sSup s x = ⨆ f ∈ s, (f : _) x :=
rfl
theorem iSup_apply {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) (x : α) :
(⨆ i, f i) x = ⨆ i, f i x :=
(sSup_apply _ _).trans iSup_range
@[simp, norm_cast]
theorem coe_iSup {ι : Sort*} [CompleteLattice β] (f : ι → α →o β) :
((⨆ i, f i : α →o β) : α → β) = ⨆ i, (f i : α → β) := by
funext x; simp [iSup_apply]
instance [CompleteLattice β] : CompleteLattice (α →o β) :=
{ (_ : Lattice (α →o β)), OrderHom.orderTop, OrderHom.orderBot with
-- sSup := SupSet.sSup -- Porting note: removed, unnecessary?
-- Porting note: Added `by apply`, was `fun s f hf x => le_iSup_of_le f (le_iSup _ hf)`
le_sSup := fun s f hf x => le_iSup_of_le f (by apply le_iSup _ hf)
sSup_le := fun s f hf x => iSup₂_le fun g hg => hf g hg x
--inf := sInf -- Porting note: removed, unnecessary?
le_sInf := fun s f hf x => le_iInf₂ fun g hg => hf g hg x
sInf_le := fun s f hf x => iInf_le_of_le f (iInf_le _ hf)
}
theorem iterate_sup_le_sup_iff {α : Type*} [SemilatticeSup α] (f : α →o α) :
(∀ n₁ n₂ a₁ a₂, f^[n₁ + n₂] (a₁ ⊔ a₂) ≤ f^[n₁] a₁ ⊔ f^[n₂] a₂) ↔
∀ a₁ a₂, f (a₁ ⊔ a₂) ≤ f a₁ ⊔ a₂ := by
constructor <;> intro h
· exact h 1 0
· intro n₁ n₂ a₁ a₂
have h' : ∀ n a₁ a₂, f^[n] (a₁ ⊔ a₂) ≤ f^[n] a₁ ⊔ a₂ := by
intro n
induction' n with n ih <;> intro a₁ a₂
· rfl
· calc
f^[n + 1] (a₁ ⊔ a₂) = f^[n] (f (a₁ ⊔ a₂)) := Function.iterate_succ_apply f n _
_ ≤ f^[n] (f a₁ ⊔ a₂) := f.mono.iterate n (h a₁ a₂)
_ ≤ f^[n] (f a₁) ⊔ a₂ := ih _ _
_ = f^[n + 1] a₁ ⊔ a₂ := by rw [← Function.iterate_succ_apply]
calc
f^[n₁ + n₂] (a₁ ⊔ a₂) = f^[n₁] (f^[n₂] (a₁ ⊔ a₂)) :=
Function.iterate_add_apply f n₁ n₂ _
_ = f^[n₁] (f^[n₂] (a₂ ⊔ a₁)) := by rw [sup_comm]
_ ≤ f^[n₁] (f^[n₂] a₂ ⊔ a₁) := f.mono.iterate n₁ (h' n₂ _ _)
_ = f^[n₁] (a₁ ⊔ f^[n₂] a₂) := by rw [sup_comm]
_ ≤ f^[n₁] a₁ ⊔ f^[n₂] a₂ := h' n₁ a₁ _
end Preorder
end OrderHom
|
Order\Hom\Set.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Order.Hom.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Data.Set.Image
/-!
# Order homomorphisms and sets
-/
open OrderDual
variable {F α β γ δ : Type*}
namespace OrderIso
section LE
variable [LE α] [LE β] [LE γ]
theorem range_eq (e : α ≃o β) : Set.range e = Set.univ :=
e.surjective.range_eq
@[simp]
theorem symm_image_image (e : α ≃o β) (s : Set α) : e.symm '' (e '' s) = s :=
e.toEquiv.symm_image_image s
@[simp]
theorem image_symm_image (e : α ≃o β) (s : Set β) : e '' (e.symm '' s) = s :=
e.toEquiv.image_symm_image s
theorem image_eq_preimage (e : α ≃o β) (s : Set α) : e '' s = e.symm ⁻¹' s :=
e.toEquiv.image_eq_preimage s
@[simp]
theorem preimage_symm_preimage (e : α ≃o β) (s : Set α) : e ⁻¹' (e.symm ⁻¹' s) = s :=
e.toEquiv.preimage_symm_preimage s
@[simp]
theorem symm_preimage_preimage (e : α ≃o β) (s : Set β) : e.symm ⁻¹' (e ⁻¹' s) = s :=
e.toEquiv.symm_preimage_preimage s
@[simp]
theorem image_preimage (e : α ≃o β) (s : Set β) : e '' (e ⁻¹' s) = s :=
e.toEquiv.image_preimage s
@[simp]
theorem preimage_image (e : α ≃o β) (s : Set α) : e ⁻¹' (e '' s) = s :=
e.toEquiv.preimage_image s
end LE
open Set
variable [Preorder α] [Preorder β] [Preorder γ]
/-- Order isomorphism between two equal sets. -/
def setCongr (s t : Set α) (h : s = t) :
s ≃o t where
toEquiv := Equiv.setCongr h
map_rel_iff' := Iff.rfl
/-- Order isomorphism between `univ : Set α` and `α`. -/
def Set.univ : (Set.univ : Set α) ≃o α where
toEquiv := Equiv.Set.univ α
map_rel_iff' := Iff.rfl
end OrderIso
/-- We can regard an order embedding as an order isomorphism to its range. -/
@[simps! apply]
noncomputable def OrderEmbedding.orderIso [LE α] [LE β] {f : α ↪o β} :
α ≃o Set.range f :=
{ Equiv.ofInjective _ f.injective with
map_rel_iff' := f.map_rel_iff }
/-- If a function `f` is strictly monotone on a set `s`, then it defines an order isomorphism
between `s` and its image. -/
protected noncomputable def StrictMonoOn.orderIso {α β} [LinearOrder α] [Preorder β] (f : α → β)
(s : Set α) (hf : StrictMonoOn f s) :
s ≃o f '' s where
toEquiv := hf.injOn.bijOn_image.equiv _
map_rel_iff' := hf.le_iff_le (Subtype.property _) (Subtype.property _)
namespace StrictMono
variable [LinearOrder α] [Preorder β]
variable (f : α → β) (h_mono : StrictMono f) (h_surj : Function.Surjective f)
/-- A strictly monotone function from a linear order is an order isomorphism between its domain and
its range. -/
@[simps! apply]
protected noncomputable def orderIso :
α ≃o Set.range f where
toEquiv := Equiv.ofInjective f h_mono.injective
map_rel_iff' := h_mono.le_iff_le
/-- A strictly monotone surjective function from a linear order is an order isomorphism. -/
noncomputable def orderIsoOfSurjective : α ≃o β :=
(h_mono.orderIso f).trans <|
(OrderIso.setCongr _ _ h_surj.range_eq).trans OrderIso.Set.univ
@[simp]
theorem coe_orderIsoOfSurjective : (orderIsoOfSurjective f h_mono h_surj : α → β) = f :=
rfl
@[simp]
theorem orderIsoOfSurjective_symm_apply_self (a : α) :
(orderIsoOfSurjective f h_mono h_surj).symm (f a) = a :=
(orderIsoOfSurjective f h_mono h_surj).symm_apply_apply _
theorem orderIsoOfSurjective_self_symm_apply (b : β) :
f ((orderIsoOfSurjective f h_mono h_surj).symm b) = b :=
(orderIsoOfSurjective f h_mono h_surj).apply_symm_apply _
end StrictMono
section BooleanAlgebra
variable (α) [BooleanAlgebra α]
/-- Taking complements as an order isomorphism to the order dual. -/
@[simps!]
def OrderIso.compl : α ≃o αᵒᵈ where
toFun := OrderDual.toDual ∘ HasCompl.compl
invFun := HasCompl.compl ∘ OrderDual.ofDual
left_inv := compl_compl
right_inv := compl_compl (α := αᵒᵈ)
map_rel_iff' := compl_le_compl_iff_le
theorem compl_strictAnti : StrictAnti (compl : α → α) :=
(OrderIso.compl α).strictMono
theorem compl_antitone : Antitone (compl : α → α) :=
(OrderIso.compl α).monotone
end BooleanAlgebra
|
Order\Interval\Basic.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.Lattice
import Mathlib.Data.SetLike.Basic
/-!
# Order intervals
This file defines (nonempty) closed intervals in an order (see `Set.Icc`). This is a prototype for
interval arithmetic.
## Main declarations
* `NonemptyInterval`: Nonempty intervals. Pairs where the second element is greater than the first.
* `Interval`: Intervals. Either `∅` or a nonempty interval.
-/
open Function OrderDual Set
variable {α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*}
/-- The nonempty closed intervals in an order.
We define intervals by the pair of endpoints `fst`, `snd`. To convert intervals to the set of
elements between these endpoints, use the coercion `NonemptyInterval α → Set α`. -/
@[ext (flat := false)]
structure NonemptyInterval (α : Type*) [LE α] extends Prod α α where
/-- The starting point of an interval is smaller than the endpoint. -/
fst_le_snd : fst ≤ snd
namespace NonemptyInterval
section LE
variable [LE α] {s t : NonemptyInterval α}
theorem toProd_injective : Injective (toProd : NonemptyInterval α → α × α) :=
fun s t h => by cases s; cases t; congr
/-- The injection that induces the order on intervals. -/
def toDualProd : NonemptyInterval α → αᵒᵈ × α :=
toProd
@[simp]
theorem toDualProd_apply (s : NonemptyInterval α) : s.toDualProd = (toDual s.fst, s.snd) :=
rfl
theorem toDualProd_injective : Injective (toDualProd : NonemptyInterval α → αᵒᵈ × α) :=
toProd_injective
instance [IsEmpty α] : IsEmpty (NonemptyInterval α) :=
⟨fun s => isEmptyElim s.fst⟩
instance [Subsingleton α] : Subsingleton (NonemptyInterval α) :=
toDualProd_injective.subsingleton
instance le : LE (NonemptyInterval α) :=
⟨fun s t => t.fst ≤ s.fst ∧ s.snd ≤ t.snd⟩
theorem le_def : s ≤ t ↔ t.fst ≤ s.fst ∧ s.snd ≤ t.snd :=
Iff.rfl
/-- `toDualProd` as an order embedding. -/
@[simps]
def toDualProdHom : NonemptyInterval α ↪o αᵒᵈ × α where
toFun := toDualProd
inj' := toDualProd_injective
map_rel_iff' := Iff.rfl
/-- Turn an interval into an interval in the dual order. -/
def dual : NonemptyInterval α ≃ NonemptyInterval αᵒᵈ where
toFun s := ⟨s.toProd.swap, s.fst_le_snd⟩
invFun s := ⟨s.toProd.swap, s.fst_le_snd⟩
left_inv _ := rfl
right_inv _ := rfl
@[simp]
theorem fst_dual (s : NonemptyInterval α) : s.dual.fst = toDual s.snd :=
rfl
@[simp]
theorem snd_dual (s : NonemptyInterval α) : s.dual.snd = toDual s.fst :=
rfl
end LE
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] {s : NonemptyInterval α} {x : α × α}
{a : α}
instance : Preorder (NonemptyInterval α) :=
Preorder.lift toDualProd
instance : Coe (NonemptyInterval α) (Set α) :=
⟨fun s => Icc s.fst s.snd⟩
instance (priority := 100) : Membership α (NonemptyInterval α) :=
⟨fun a s => a ∈ (s : Set α)⟩
@[simp]
theorem mem_mk {hx : x.1 ≤ x.2} : a ∈ mk x hx ↔ x.1 ≤ a ∧ a ≤ x.2 :=
Iff.rfl
theorem mem_def : a ∈ s ↔ s.fst ≤ a ∧ a ≤ s.snd :=
Iff.rfl
-- @[simp] -- Porting note: not in simpNF
theorem coe_nonempty (s : NonemptyInterval α) : (s : Set α).Nonempty :=
nonempty_Icc.2 s.fst_le_snd
/-- `{a}` as an interval. -/
@[simps]
def pure (a : α) : NonemptyInterval α :=
⟨⟨a, a⟩, le_rfl⟩
theorem mem_pure_self (a : α) : a ∈ pure a :=
⟨le_rfl, le_rfl⟩
theorem pure_injective : Injective (pure : α → NonemptyInterval α) := fun _ _ =>
congr_arg <| Prod.fst ∘ toProd
@[simp]
theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) :=
rfl
instance [Inhabited α] : Inhabited (NonemptyInterval α) :=
⟨pure default⟩
instance [Nonempty α] : Nonempty (NonemptyInterval α) :=
Nonempty.map pure (by infer_instance)
instance [Nontrivial α] : Nontrivial (NonemptyInterval α) :=
pure_injective.nontrivial
/-- Pushforward of nonempty intervals. -/
@[simps!]
def map (f : α →o β) (a : NonemptyInterval α) : NonemptyInterval β :=
⟨a.toProd.map f f, f.mono a.fst_le_snd⟩
@[simp]
theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) :=
rfl
@[simp]
theorem map_map (g : β →o γ) (f : α →o β) (a : NonemptyInterval α) :
(a.map f).map g = a.map (g.comp f) :=
rfl
@[simp]
theorem dual_map (f : α →o β) (a : NonemptyInterval α) :
dual (a.map f) = a.dual.map (OrderHom.dual f) :=
rfl
/-- Binary pushforward of nonempty intervals. -/
@[simps]
def map₂ (f : α → β → γ) (h₀ : ∀ b, Monotone fun a => f a b) (h₁ : ∀ a, Monotone (f a)) :
NonemptyInterval α → NonemptyInterval β → NonemptyInterval γ := fun s t =>
⟨(f s.fst t.fst, f s.snd t.snd), (h₀ _ s.fst_le_snd).trans <| h₁ _ t.fst_le_snd⟩
@[simp]
theorem map₂_pure (f : α → β → γ) (h₀ h₁) (a : α) (b : β) :
map₂ f h₀ h₁ (pure a) (pure b) = pure (f a b) :=
rfl
@[simp]
theorem dual_map₂ (f : α → β → γ) (h₀ h₁ s t) :
dual (map₂ f h₀ h₁ s t) =
map₂ (fun a b => toDual <| f (ofDual a) <| ofDual b) (fun _ => (h₀ _).dual)
(fun _ => (h₁ _).dual) (dual s) (dual t) :=
rfl
variable [BoundedOrder α]
instance : OrderTop (NonemptyInterval α) where
top := ⟨⟨⊥, ⊤⟩, bot_le⟩
le_top _ := ⟨bot_le, le_top⟩
@[simp]
theorem dual_top : dual (⊤ : NonemptyInterval α) = ⊤ :=
rfl
end Preorder
section PartialOrder
variable [PartialOrder α] [PartialOrder β] {s t : NonemptyInterval α} {x : α × α} {a b : α}
instance : PartialOrder (NonemptyInterval α) :=
PartialOrder.lift _ toDualProd_injective
/-- Consider a nonempty interval `[a, b]` as the set `[a, b]`. -/
def coeHom : NonemptyInterval α ↪o Set α :=
OrderEmbedding.ofMapLEIff (fun s => Icc s.fst s.snd) fun s _ => Icc_subset_Icc_iff s.fst_le_snd
instance setLike : SetLike (NonemptyInterval α) α where
coe s := Icc s.fst s.snd
coe_injective' := coeHom.injective
@[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF
theorem coe_subset_coe : (s : Set α) ⊆ t ↔ (s : NonemptyInterval α) ≤ t :=
(@coeHom α _).le_iff_le
@[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF
theorem coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t :=
(@coeHom α _).lt_iff_lt
@[simp]
theorem coe_coeHom : (coeHom : NonemptyInterval α → Set α) = ((↑) : NonemptyInterval α → Set α) :=
rfl
theorem coe_def (s : NonemptyInterval α) : (s : Set α) = Set.Icc s.toProd.1 s.toProd.2 := rfl
@[simp, norm_cast]
theorem coe_pure (a : α) : (pure a : Set α) = {a} :=
Icc_self _
@[simp]
theorem mem_pure : b ∈ pure a ↔ b = a := by
rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff]
@[simp, norm_cast]
theorem coe_top [BoundedOrder α] : ((⊤ : NonemptyInterval α) : Set α) = univ :=
Icc_bot_top
@[simp, norm_cast]
theorem coe_dual (s : NonemptyInterval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s :=
dual_Icc
theorem subset_coe_map (f : α →o β) (s : NonemptyInterval α) : f '' s ⊆ s.map f :=
image_subset_iff.2 fun _ ha => ⟨f.mono ha.1, f.mono ha.2⟩
end PartialOrder
section Lattice
variable [Lattice α]
instance : Sup (NonemptyInterval α) :=
⟨fun s t => ⟨⟨s.fst ⊓ t.fst, s.snd ⊔ t.snd⟩, inf_le_left.trans <| s.fst_le_snd.trans le_sup_left⟩⟩
instance : SemilatticeSup (NonemptyInterval α) :=
toDualProd_injective.semilatticeSup _ fun _ _ => rfl
@[simp]
theorem fst_sup (s t : NonemptyInterval α) : (s ⊔ t).fst = s.fst ⊓ t.fst :=
rfl
@[simp]
theorem snd_sup (s t : NonemptyInterval α) : (s ⊔ t).snd = s.snd ⊔ t.snd :=
rfl
end Lattice
end NonemptyInterval
/-- The closed intervals in an order.
We represent intervals either as `⊥` or a nonempty interval given by its endpoints `fst`, `snd`.
To convert intervals to the set of elements between these endpoints, use the coercion
`Interval α → Set α`. -/
-- Porting note: added reducible, it seems to help with coercions
abbrev Interval (α : Type*) [LE α] :=
WithBot (NonemptyInterval α) -- deriving Inhabited, LE, OrderBot
namespace Interval
section LE
variable [LE α] {s t : Interval α}
-- Porting note: previously found using `deriving`
instance : Inhabited (Interval α) := WithBot.inhabited
instance : LE (Interval α) := WithBot.le
instance : OrderBot (Interval α) := WithBot.orderBot
instance : Coe (NonemptyInterval α) (Interval α) :=
WithBot.coe
instance canLift : CanLift (Interval α) (NonemptyInterval α) (↑) fun r => r ≠ ⊥ :=
WithBot.canLift
/-- Recursor for `Interval` using the preferred forms `⊥` and `↑a`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
def recBotCoe {C : Interval α → Sort*} (bot : C ⊥) (coe : ∀ a : NonemptyInterval α, C a) :
∀ n : Interval α, C n :=
WithBot.recBotCoe bot coe
theorem coe_injective : Injective ((↑) : NonemptyInterval α → Interval α) :=
WithBot.coe_injective
@[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF
theorem coe_inj {s t : NonemptyInterval α} : (s : Interval α) = t ↔ s = t :=
WithBot.coe_inj
protected
theorem «forall» {p : Interval α → Prop} : (∀ s, p s) ↔ p ⊥ ∧ ∀ s : NonemptyInterval α, p s :=
Option.forall
protected
theorem «exists» {p : Interval α → Prop} : (∃ s, p s) ↔ p ⊥ ∨ ∃ s : NonemptyInterval α, p s :=
Option.exists
instance [IsEmpty α] : Unique (Interval α) :=
inferInstanceAs <| Unique (Option _)
/-- Turn an interval into an interval in the dual order. -/
def dual : Interval α ≃ Interval αᵒᵈ :=
NonemptyInterval.dual.optionCongr
end LE
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ]
instance : Preorder (Interval α) :=
WithBot.preorder
/-- `{a}` as an interval. -/
def pure (a : α) : Interval α :=
NonemptyInterval.pure a
theorem pure_injective : Injective (pure : α → Interval α) :=
coe_injective.comp NonemptyInterval.pure_injective
@[simp]
theorem dual_pure (a : α) : dual (pure a) = pure (toDual a) :=
rfl
@[simp]
theorem dual_bot : dual (⊥ : Interval α) = ⊥ :=
rfl
@[simp]
theorem pure_ne_bot {a : α} : pure a ≠ ⊥ :=
WithBot.coe_ne_bot
@[simp]
theorem bot_ne_pure {a : α} : ⊥ ≠ pure a :=
WithBot.bot_ne_coe
instance [Nonempty α] : Nontrivial (Interval α) :=
Option.nontrivial
/-- Pushforward of intervals. -/
def map (f : α →o β) : Interval α → Interval β :=
WithBot.map (NonemptyInterval.map f)
@[simp]
theorem map_pure (f : α →o β) (a : α) : (pure a).map f = pure (f a) :=
rfl
@[simp]
theorem map_map (g : β →o γ) (f : α →o β) (s : Interval α) : (s.map f).map g = s.map (g.comp f) :=
Option.map_map _ _ _
@[simp]
theorem dual_map (f : α →o β) (s : Interval α) : dual (s.map f) = s.dual.map (OrderHom.dual f) := by
cases s
· rfl
· exact WithBot.map_comm rfl _
variable [BoundedOrder α]
instance boundedOrder : BoundedOrder (Interval α) :=
WithBot.instBoundedOrder
@[simp]
theorem dual_top : dual (⊤ : Interval α) = ⊤ :=
rfl
end Preorder
section PartialOrder
variable [PartialOrder α] [PartialOrder β] {s t : Interval α} {a b : α}
instance partialOrder : PartialOrder (Interval α) :=
WithBot.partialOrder
/-- Consider an interval `[a, b]` as the set `[a, b]`. -/
def coeHom : Interval α ↪o Set α :=
OrderEmbedding.ofMapLEIff
(fun s =>
match s with
| ⊥ => ∅
| some s => s)
fun s t =>
match s, t with
| ⊥, _ => iff_of_true bot_le bot_le
| some s, ⊥ =>
iff_of_false (fun h => s.coe_nonempty.ne_empty <| le_bot_iff.1 h) (WithBot.not_coe_le_bot _)
| some _, some _ => (@NonemptyInterval.coeHom α _).le_iff_le.trans WithBot.coe_le_coe.symm
instance setLike : SetLike (Interval α) α where
coe := coeHom
coe_injective' := coeHom.injective
@[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF
theorem coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t :=
(@coeHom α _).le_iff_le
@[norm_cast] -- @[simp, norm_cast] -- Porting note: not in simpNF
theorem coe_sSubset_coe : (s : Set α) ⊂ t ↔ s < t :=
(@coeHom α _).lt_iff_lt
@[simp, norm_cast]
theorem coe_pure (a : α) : (pure a : Set α) = {a} :=
Icc_self _
@[simp, norm_cast]
theorem coe_coe (s : NonemptyInterval α) : ((s : Interval α) : Set α) = s :=
rfl
@[simp, norm_cast]
theorem coe_bot : ((⊥ : Interval α) : Set α) = ∅ :=
rfl
@[simp, norm_cast]
theorem coe_top [BoundedOrder α] : ((⊤ : Interval α) : Set α) = univ :=
Icc_bot_top
@[simp, norm_cast]
theorem coe_dual (s : Interval α) : (dual s : Set αᵒᵈ) = ofDual ⁻¹' s := by
cases s with
| bot => rfl
| coe s₀ => exact NonemptyInterval.coe_dual s₀
theorem subset_coe_map (f : α →o β) : ∀ s : Interval α, f '' s ⊆ s.map f
| ⊥ => by simp
| (s : NonemptyInterval α) => s.subset_coe_map _
@[simp]
theorem mem_pure : b ∈ pure a ↔ b = a := by rw [← SetLike.mem_coe, coe_pure, mem_singleton_iff]
theorem mem_pure_self (a : α) : a ∈ pure a :=
mem_pure.2 rfl
end PartialOrder
section Lattice
variable [Lattice α]
instance semilatticeSup : SemilatticeSup (Interval α) :=
WithBot.semilatticeSup
section Decidable
variable [@DecidableRel α (· ≤ ·)]
instance lattice : Lattice (Interval α) :=
{ Interval.semilatticeSup with
inf := fun s t =>
match s, t with
| ⊥, _ => ⊥
| _, ⊥ => ⊥
| some s, some t =>
if h : s.fst ≤ t.snd ∧ t.fst ≤ s.snd then
WithBot.some
⟨⟨s.fst ⊔ t.fst, s.snd ⊓ t.snd⟩,
sup_le (le_inf s.fst_le_snd h.1) <| le_inf h.2 t.fst_le_snd⟩
else ⊥
inf_le_left := fun s t =>
match s, t with
| ⊥, ⊥ => bot_le
| ⊥, some _ => bot_le
| some s, ⊥ => bot_le
| some s, some t => by
change dite _ _ _ ≤ _
split_ifs
· exact WithBot.coe_le_coe.2 ⟨le_sup_left, inf_le_left⟩
· exact bot_le
inf_le_right := fun s t =>
match s, t with
| ⊥, ⊥ => bot_le
| ⊥, some t => bot_le
| some _, ⊥ => bot_le
| some s, some t => by
change dite _ _ _ ≤ _
split_ifs
· exact WithBot.coe_le_coe.2 ⟨le_sup_right, inf_le_right⟩
· exact bot_le
le_inf := fun s t c =>
match s, t, c with
| ⊥, t, c => fun _ _ => bot_le
| (s : NonemptyInterval α), t, c => fun hb hc => by
lift t to NonemptyInterval α using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hb
lift c to NonemptyInterval α using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hc
change _ ≤ dite _ _ _
simp only [WithBot.coe_le_coe] at hb hc ⊢
rw [dif_pos, WithBot.coe_le_coe]
· exact ⟨sup_le hb.1 hc.1, le_inf hb.2 hc.2⟩
-- Porting note: had to add the next 6 lines including the changes because
-- it seems that lean cannot automatically turn `NonemptyInterval.toDualProd s`
-- into `s.toProd` anymore.
rcases hb with ⟨hb₁, hb₂⟩
rcases hc with ⟨hc₁, hc₂⟩
change t.toProd.fst ≤ s.toProd.fst at hb₁
change s.toProd.snd ≤ t.toProd.snd at hb₂
change c.toProd.fst ≤ s.toProd.fst at hc₁
change s.toProd.snd ≤ c.toProd.snd at hc₂
-- Porting note: originally it just had `hb.1` etc. in this next line
exact ⟨hb₁.trans <| s.fst_le_snd.trans hc₂, hc₁.trans <| s.fst_le_snd.trans hb₂⟩ }
@[simp, norm_cast]
theorem coe_inf : ∀ s t : Interval α, (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t
| ⊥, _ => by
rw [bot_inf_eq]
exact (empty_inter _).symm
| (s : NonemptyInterval α), ⊥ => by
rw [inf_bot_eq]
exact (inter_empty _).symm
| (s : NonemptyInterval α), (t : NonemptyInterval α) => by
simp only [Inf.inf, coe_coe, NonemptyInterval.coe_def, Icc_inter_Icc]
split_ifs with h
· simp only [coe_coe, NonemptyInterval.coe_def]
· refine (Icc_eq_empty <| mt ?_ h).symm
exact fun h ↦ ⟨le_sup_left.trans <| h.trans inf_le_right,
le_sup_right.trans <| h.trans inf_le_left⟩
end Decidable
@[simp, norm_cast]
theorem disjoint_coe (s t : Interval α) : Disjoint (s : Set α) t ↔ Disjoint s t := by
classical
rw [disjoint_iff_inf_le, disjoint_iff_inf_le, ← coe_subset_coe, coe_inf]
rfl
end Lattice
end Interval
namespace NonemptyInterval
section Preorder
variable [Preorder α] {s : NonemptyInterval α} {a : α}
@[simp, norm_cast]
theorem coe_pure_interval (a : α) : (pure a : Interval α) = Interval.pure a :=
rfl
@[simp, norm_cast]
theorem coe_eq_pure : (s : Interval α) = Interval.pure a ↔ s = pure a := by
rw [← Interval.coe_inj, coe_pure_interval]
@[simp, norm_cast]
theorem coe_top_interval [BoundedOrder α] : ((⊤ : NonemptyInterval α) : Interval α) = ⊤ :=
rfl
end Preorder
@[simp, norm_cast]
theorem mem_coe_interval [PartialOrder α] {s : NonemptyInterval α} {x : α} :
x ∈ (s : Interval α) ↔ x ∈ s :=
Iff.rfl
@[simp, norm_cast]
theorem coe_sup_interval [Lattice α] (s t : NonemptyInterval α) :
(↑(s ⊔ t) : Interval α) = ↑s ⊔ ↑t :=
rfl
end NonemptyInterval
namespace Interval
section CompleteLattice
variable [CompleteLattice α]
noncomputable instance completeLattice [@DecidableRel α (· ≤ ·)] :
CompleteLattice (Interval α) := by
classical
exact
{ Interval.lattice, Interval.boundedOrder with
sSup := fun S =>
if h : S ⊆ {⊥} then ⊥
else
WithBot.some
⟨⟨⨅ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.fst,
⨆ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.snd⟩, by
obtain ⟨s, hs, ha⟩ := not_subset.1 h
lift s to NonemptyInterval α using ha
exact iInf₂_le_of_le s hs (le_iSup₂_of_le s hs s.fst_le_snd)⟩
le_sSup := fun s s ha => by
dsimp only -- Porting note (#10752): added `dsimp only`
split_ifs with h
· exact (h ha).le
cases s
· exact bot_le
· -- Porting note: This case was
-- `exact WithBot.some_le_some.2 ⟨iInf₂_le _ ha, le_iSup₂_of_le _ ha le_rfl⟩`
-- but there seems to be a defEq-problem at `iInf₂_le` that lean cannot resolve yet.
apply WithBot.coe_le_coe.2
constructor
· apply iInf₂_le
exact ha
· exact le_iSup₂_of_le _ ha le_rfl
sSup_le := fun s s ha => by
dsimp only -- Porting note (#10752): added `dsimp only`
split_ifs with h
· exact bot_le
obtain ⟨b, hs, hb⟩ := not_subset.1 h
lift s to NonemptyInterval α using ne_bot_of_le_ne_bot hb (ha _ hs)
exact
WithBot.coe_le_coe.2
⟨le_iInf₂ fun c hc => (WithBot.coe_le_coe.1 <| ha _ hc).1,
iSup₂_le fun c hc => (WithBot.coe_le_coe.1 <| ha _ hc).2⟩
sInf := fun S =>
if h :
⊥ ∉ S ∧
∀ ⦃s : NonemptyInterval α⦄,
↑s ∈ S → ∀ ⦃t : NonemptyInterval α⦄, ↑t ∈ S → s.fst ≤ t.snd then
WithBot.some
⟨⟨⨆ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.fst,
⨅ (s : NonemptyInterval α) (_ : ↑s ∈ S), s.snd⟩,
iSup₂_le fun s hs => le_iInf₂ <| h.2 hs⟩
else ⊥
sInf_le := fun s₁ s ha => by
dsimp only -- Porting note (#10752): added `dsimp only`
split_ifs with h
· lift s to NonemptyInterval α using ne_of_mem_of_not_mem ha h.1
-- Porting note: Lean failed to figure out the function `f` by itself,
-- so I added it through manually
let f := fun (s : NonemptyInterval α) (_ : ↑s ∈ s₁) => s.toProd.fst
exact WithBot.coe_le_coe.2 ⟨le_iSup₂ (f := f) s ha, iInf₂_le s ha⟩
· exact bot_le
le_sInf := by
intro S s ha
cases s with
| bot => exact bot_le
| coe s =>
dsimp -- Porting note (#11227): added a `dsimp`
split_ifs with h
· exact WithBot.coe_le_coe.2
⟨iSup₂_le fun t hb => (WithBot.coe_le_coe.1 <| ha _ hb).1,
le_iInf₂ fun t hb => (WithBot.coe_le_coe.1 <| ha _ hb).2⟩
· rw [not_and_or, not_not] at h
rcases h with h | h
· exact ha _ h
· -- Porting note: ungolfed, due to identification problems
-- between `toProd` and `toDualProd`. Original mathport output:
-- cases h fun t hb c hc =>
-- (WithBot.coe_le_coe.1 <| ha _ hb).1.trans <|
-- s.fst_le_snd.trans (WithBot.coe_le_coe.1 <| ha _ hc).2 }
exfalso
apply h
intro b hb c hc
have h₁ := (WithBot.coe_le_coe.1 <| ha _ hb).1
repeat rw [NonemptyInterval.toDualProd_apply] at h₁
rw [OrderDual.toDual_le_toDual] at h₁
exact h₁.trans (s.fst_le_snd.trans (WithBot.coe_le_coe.1 <| ha _ hc).2)
}
@[simp, norm_cast]
theorem coe_sInf [@DecidableRel α (· ≤ ·)] (S : Set (Interval α)) :
↑(sInf S) = ⋂ s ∈ S, (s : Set α) := by
classical -- Porting note: added
-- Porting note: this `change` was
-- change ↑ (dite _ _ _) = _
change ((dite _ _ _ : Interval α) : Set α) = ⋂ (s : Interval α) (_ : s ∈ S), (s : Set α)
split_ifs with h
· ext
simp [Interval.forall, h.1, ← forall_and, ← NonemptyInterval.mem_def]
simp_rw [not_and_or, Classical.not_not] at h
rcases h with h | h
· refine (eq_empty_of_subset_empty ?_).symm
exact iInter₂_subset_of_subset _ h Subset.rfl
· refine (not_nonempty_iff_eq_empty.1 ?_).symm
rintro ⟨x, hx⟩
rw [mem_iInter₂] at hx
exact h fun s ha t hb => (hx _ ha).1.trans (hx _ hb).2
@[simp, norm_cast]
theorem coe_iInf [@DecidableRel α (· ≤ ·)] (f : ι → Interval α) :
↑(⨅ i, f i) = ⋂ i, (f i : Set α) := by simp [iInf]
-- @[simp] -- Porting note: not in simpNF
@[norm_cast]
theorem coe_iInf₂ [@DecidableRel α (· ≤ ·)] (f : ∀ i, κ i → Interval α) :
↑(⨅ (i) (j), f i j) = ⋂ (i) (j), (f i j : Set α) := by simp_rw [coe_iInf]
end CompleteLattice
end Interval
|
Order\Interval\Multiset.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Interval.Finset.Basic
/-!
# Intervals as multisets
This file defines intervals as multisets.
## Main declarations
In a `LocallyFiniteOrder`,
* `Multiset.Icc`: Closed-closed interval as a multiset.
* `Multiset.Ico`: Closed-open interval as a multiset.
* `Multiset.Ioc`: Open-closed interval as a multiset.
* `Multiset.Ioo`: Open-open interval as a multiset.
In a `LocallyFiniteOrderTop`,
* `Multiset.Ici`: Closed-infinite interval as a multiset.
* `Multiset.Ioi`: Open-infinite interval as a multiset.
In a `LocallyFiniteOrderBot`,
* `Multiset.Iic`: Infinite-open interval as a multiset.
* `Multiset.Iio`: Infinite-closed interval as a multiset.
## TODO
Do we really need this file at all? (March 2024)
-/
variable {α : Type*}
namespace Multiset
section LocallyFiniteOrder
variable [Preorder α] [LocallyFiniteOrder α] {a b x : α}
/-- The multiset of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a
multiset. -/
def Icc (a b : α) : Multiset α := (Finset.Icc a b).val
/-- The multiset of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a
multiset. -/
def Ico (a b : α) : Multiset α := (Finset.Ico a b).val
/-- The multiset of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a
multiset. -/
def Ioc (a b : α) : Multiset α := (Finset.Ioc a b).val
/-- The multiset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a
multiset. -/
def Ioo (a b : α) : Multiset α := (Finset.Ioo a b).val
@[simp] lemma mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := by rw [Icc, ← Finset.mem_def, Finset.mem_Icc]
@[simp] lemma mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := by rw [Ico, ← Finset.mem_def, Finset.mem_Ico]
@[simp] lemma mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := by rw [Ioc, ← Finset.mem_def, Finset.mem_Ioc]
@[simp] lemma mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := by rw [Ioo, ← Finset.mem_def, Finset.mem_Ioo]
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [Preorder α] [LocallyFiniteOrderTop α] {a x : α}
/-- The multiset of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a multiset. -/
def Ici (a : α) : Multiset α := (Finset.Ici a).val
/-- The multiset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a multiset. -/
def Ioi (a : α) : Multiset α := (Finset.Ioi a).val
@[simp] lemma mem_Ici : x ∈ Ici a ↔ a ≤ x := by rw [Ici, ← Finset.mem_def, Finset.mem_Ici]
@[simp] lemma mem_Ioi : x ∈ Ioi a ↔ a < x := by rw [Ioi, ← Finset.mem_def, Finset.mem_Ioi]
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [Preorder α] [LocallyFiniteOrderBot α] {b x : α}
/-- The multiset of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a multiset. -/
def Iic (b : α) : Multiset α := (Finset.Iic b).val
/-- The multiset of elements `x` such that `x < b`. Basically `Set.Iio b` as a multiset. -/
def Iio (b : α) : Multiset α := (Finset.Iio b).val
@[simp] lemma mem_Iic : x ∈ Iic b ↔ x ≤ b := by rw [Iic, ← Finset.mem_def, Finset.mem_Iic]
@[simp] lemma mem_Iio : x ∈ Iio b ↔ x < b := by rw [Iio, ← Finset.mem_def, Finset.mem_Iio]
end LocallyFiniteOrderBot
section Preorder
variable [Preorder α] [LocallyFiniteOrder α] {a b c : α}
theorem nodup_Icc : (Icc a b).Nodup :=
Finset.nodup _
theorem nodup_Ico : (Ico a b).Nodup :=
Finset.nodup _
theorem nodup_Ioc : (Ioc a b).Nodup :=
Finset.nodup _
theorem nodup_Ioo : (Ioo a b).Nodup :=
Finset.nodup _
@[simp]
theorem Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b := by
rw [Icc, Finset.val_eq_zero, Finset.Icc_eq_empty_iff]
@[simp]
theorem Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b := by
rw [Ico, Finset.val_eq_zero, Finset.Ico_eq_empty_iff]
@[simp]
theorem Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b := by
rw [Ioc, Finset.val_eq_zero, Finset.Ioc_eq_empty_iff]
@[simp]
theorem Ioo_eq_zero_iff [DenselyOrdered α] : Ioo a b = 0 ↔ ¬a < b := by
rw [Ioo, Finset.val_eq_zero, Finset.Ioo_eq_empty_iff]
alias ⟨_, Icc_eq_zero⟩ := Icc_eq_zero_iff
alias ⟨_, Ico_eq_zero⟩ := Ico_eq_zero_iff
alias ⟨_, Ioc_eq_zero⟩ := Ioc_eq_zero_iff
@[simp]
theorem Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 :=
eq_zero_iff_forall_not_mem.2 fun _x hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp]
theorem Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 :=
Icc_eq_zero h.not_le
@[simp]
theorem Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 :=
Ico_eq_zero h.not_lt
@[simp]
theorem Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 :=
Ioc_eq_zero h.not_lt
@[simp]
theorem Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 :=
Ioo_eq_zero h.not_lt
variable (a)
-- Porting note (#10618): simp can prove this -- @[simp]
theorem Ico_self : Ico a a = 0 := by rw [Ico, Finset.Ico_self, Finset.empty_val]
-- Porting note (#10618): simp can prove this -- @[simp]
theorem Ioc_self : Ioc a a = 0 := by rw [Ioc, Finset.Ioc_self, Finset.empty_val]
-- Porting note (#10618): simp can prove this -- @[simp]
theorem Ioo_self : Ioo a a = 0 := by rw [Ioo, Finset.Ioo_self, Finset.empty_val]
variable {a}
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b :=
Finset.left_mem_Icc
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b :=
Finset.left_mem_Ico
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b :=
Finset.right_mem_Icc
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b :=
Finset.right_mem_Ioc
-- Porting note (#10618): simp can prove this -- @[simp]
theorem left_not_mem_Ioc : a ∉ Ioc a b :=
Finset.left_not_mem_Ioc
-- Porting note (#10618): simp can prove this -- @[simp]
theorem left_not_mem_Ioo : a ∉ Ioo a b :=
Finset.left_not_mem_Ioo
-- Porting note (#10618): simp can prove this -- @[simp]
theorem right_not_mem_Ico : b ∉ Ico a b :=
Finset.right_not_mem_Ico
-- Porting note (#10618): simp can prove this -- @[simp]
theorem right_not_mem_Ioo : b ∉ Ioo a b :=
Finset.right_not_mem_Ioo
theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) :
((Ico a b).filter fun x => x < c) = ∅ := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_left hca]
rfl
theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) :
((Ico a b).filter fun x => x < c) = Ico a b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_right_le hbc]
theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) :
((Ico a b).filter fun x => x < c) = Ico a c := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_right hcb]
rfl
theorem Ico_filter_le_of_le_left [DecidablePred (c ≤ ·)] (hca : c ≤ a) :
((Ico a b).filter fun x => c ≤ x) = Ico a b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_le_left hca]
theorem Ico_filter_le_of_right_le [DecidablePred (b ≤ ·)] :
((Ico a b).filter fun x => b ≤ x) = ∅ := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_right_le]
rfl
theorem Ico_filter_le_of_left_le [DecidablePred (c ≤ ·)] (hac : a ≤ c) :
((Ico a b).filter fun x => c ≤ x) = Ico c b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_left_le hac]
rfl
end Preorder
section PartialOrder
variable [PartialOrder α] [LocallyFiniteOrder α] {a b : α}
@[simp]
theorem Icc_self (a : α) : Icc a a = {a} := by rw [Icc, Finset.Icc_self, Finset.singleton_val]
theorem Ico_cons_right (h : a ≤ b) : b ::ₘ Ico a b = Icc a b := by
classical
rw [Ico, ← Finset.insert_val_of_not_mem right_not_mem_Ico, Finset.Ico_insert_right h]
rfl
theorem Ioo_cons_left (h : a < b) : a ::ₘ Ioo a b = Ico a b := by
classical
rw [Ioo, ← Finset.insert_val_of_not_mem left_not_mem_Ioo, Finset.Ioo_insert_left h]
rfl
theorem Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : (Ico a b).Disjoint (Ico c d) :=
fun x hab hbc => by
rw [mem_Ico] at hab hbc
exact hab.2.not_le (h.trans hbc.1)
@[simp]
theorem Ico_inter_Ico_of_le [DecidableEq α] {a b c d : α} (h : b ≤ c) : Ico a b ∩ Ico c d = 0 :=
Multiset.inter_eq_zero_iff_disjoint.2 <| Ico_disjoint_Ico h
theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) :
((Ico a b).filter fun x => x ≤ a) = {a} := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_left hab]
rfl
theorem card_Ico_eq_card_Icc_sub_one (a b : α) : card (Ico a b) = card (Icc a b) - 1 :=
Finset.card_Ico_eq_card_Icc_sub_one _ _
theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : card (Ioc a b) = card (Icc a b) - 1 :=
Finset.card_Ioc_eq_card_Icc_sub_one _ _
theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : card (Ioo a b) = card (Ico a b) - 1 :=
Finset.card_Ioo_eq_card_Ico_sub_one _ _
theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : card (Ioo a b) = card (Icc a b) - 2 :=
Finset.card_Ioo_eq_card_Icc_sub_two _ _
end PartialOrder
section LinearOrder
variable [LinearOrder α] [LocallyFiniteOrder α] {a b c d : α}
theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
Finset.Ico_subset_Ico_iff h
theorem Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) :
Ico a b + Ico b c = Ico a c := by
rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ← Finset.union_val,
Finset.Ico_union_Ico_eq_Ico hab hbc]
theorem Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by
rw [Ico, Ico, Ico, ← Finset.inter_val, Finset.Ico_inter_Ico]
@[simp]
theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by
rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_lt]
@[simp]
theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by
rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_le]
@[simp]
theorem Ico_sub_Ico_left (a b c : α) : Ico a b - Ico a c = Ico (max a c) b := by
rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_left]
@[simp]
theorem Ico_sub_Ico_right (a b c : α) : Ico a b - Ico c b = Ico a (min b c) := by
rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_right]
end LinearOrder
end Multiset
|
Order\Interval\Finset\Basic.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Yaël Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.Interval.Finset.Defs
/-!
# Intervals as finsets
This file provides basic results about all the `Finset.Ixx`, which are defined in
`Order.Interval.Finset.Defs`.
In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of,
respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly
functions whose domain is a locally finite order. In particular, this file proves:
* `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿`
* `lt_iff_transGen_covBy`: `≤` is the transitive closure of `⩿`
* `monotone_iff_forall_wcovBy`: Characterization of monotone functions
* `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions
## TODO
This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to
generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general,
what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure.
Complete the API. See
https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235
for some ideas.
-/
assert_not_exists MonoidWithZero
assert_not_exists Finset.sum
open Function OrderDual
open FinsetInterval
variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α}
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by
rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc]
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo]
@[simp]
theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by
rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff]
@[simp]
theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff]
@[simp]
theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff]
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff]
alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff
alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff
alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff
@[simp]
theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ :=
Icc_eq_empty h.not_le
@[simp]
theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ :=
Ico_eq_empty h.not_lt
@[simp]
theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ :=
Ioc_eq_empty h.not_lt
@[simp]
theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ :=
Ioo_eq_empty h.not_lt
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2
theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by
simpa [← coe_subset] using Set.Icc_subset_Icc ha hb
theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by
simpa [← coe_subset] using Set.Ico_subset_Ico ha hb
theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by
simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb
theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by
simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb
theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b :=
Icc_subset_Icc h le_rfl
theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b :=
Ico_subset_Ico h le_rfl
theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b :=
Ioc_subset_Ioc h le_rfl
theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b :=
Ioo_subset_Ioo h le_rfl
theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ :=
Icc_subset_Icc le_rfl h
theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ :=
Ico_subset_Ico le_rfl h
theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ :=
Ioc_subset_Ioc le_rfl h
theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ :=
Ioo_subset_Ioo le_rfl h
theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by
rw [← coe_subset, coe_Ico, coe_Ioo]
exact Set.Ico_subset_Ioo_left h
theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by
rw [← coe_subset, coe_Ioc, coe_Ioo]
exact Set.Ioc_subset_Ioo_right h
theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by
rw [← coe_subset, coe_Icc, coe_Ico]
exact Set.Icc_subset_Ico_right h
theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by
rw [← coe_subset, coe_Ioo, coe_Ico]
exact Set.Ioo_subset_Ico_self
theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by
rw [← coe_subset, coe_Ioo, coe_Ioc]
exact Set.Ioo_subset_Ioc_self
theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by
rw [← coe_subset, coe_Ico, coe_Icc]
exact Set.Ico_subset_Icc_self
theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by
rw [← coe_subset, coe_Ioc, coe_Icc]
exact Set.Ioc_subset_Icc_self
theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b :=
Ioo_subset_Ico_self.trans Ico_subset_Icc_self
theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by
rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁]
theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by
rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁]
theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by
rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁]
theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ :=
(Icc_subset_Ico_iff h₁.dual).trans and_comm
--TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff`
theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) :
Icc a₁ b₁ ⊂ Icc a₂ b₂ := by
rw [← coe_ssubset, coe_Icc, coe_Icc]
exact Set.Icc_ssubset_Icc_left hI ha hb
theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) :
Icc a₁ b₁ ⊂ Icc a₂ b₂ := by
rw [← coe_ssubset, coe_Icc, coe_Icc]
exact Set.Icc_ssubset_Icc_right hI ha hb
variable (a)
-- porting note (#10618): simp can prove this
-- @[simp]
theorem Ico_self : Ico a a = ∅ :=
Ico_eq_empty <| lt_irrefl _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem Ioc_self : Ioc a a = ∅ :=
Ioc_eq_empty <| lt_irrefl _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem Ioo_self : Ioo a a = ∅ :=
Ioo_eq_empty <| lt_irrefl _
variable {a}
/-- A set with upper and lower bounds in a locally finite order is a fintype -/
def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s)
(hb : b ∈ upperBounds s) : Fintype s :=
Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩
section Filter
theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) :
(Ico a b).filter (· < c) = ∅ :=
filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt
theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) :
(Ico a b).filter (· < c) = Ico a b :=
filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc
theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) :
(Ico a b).filter (· < c) = Ico a c := by
ext x
rw [mem_filter, mem_Ico, mem_Ico, and_right_comm]
exact and_iff_left_of_imp fun h => h.2.trans_le hcb
theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) :
(Ico a b).filter (c ≤ ·) = Ico a b :=
filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1
theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] :
(Ico a b).filter (b ≤ ·) = ∅ :=
filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le
theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) :
(Ico a b).filter (c ≤ ·) = Ico c b := by
ext x
rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm]
exact and_iff_right_of_imp fun h => hac.trans h.1
theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) :
(Icc a b).filter (· < c) = Icc a b :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h
theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) :
(Ioc a b).filter (· < c) = Ioc a b :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h
theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α}
[DecidablePred (· < c)] (h : a < c) : (Iic a).filter (· < c) = Iic a :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h
variable (a b) [Fintype α]
theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] :
(univ.filter fun j => a < j ∧ j < b) = Ioo a b := by
ext
simp
theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] :
(univ.filter fun j => a < j ∧ j ≤ b) = Ioc a b := by
ext
simp
theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] :
(univ.filter fun j => a ≤ j ∧ j < b) = Ico a b := by
ext
simp
theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] :
(univ.filter fun j => a ≤ j ∧ j ≤ b) = Icc a b := by
ext
simp
end Filter
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty]
variable [LocallyFiniteOrder α]
theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by
simpa [← coe_subset] using Set.Icc_subset_Ici_self
theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by
simpa [← coe_subset] using Set.Ico_subset_Ici_self
theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by
simpa [← coe_subset] using Set.Ioc_subset_Ioi_self
theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by
simpa [← coe_subset] using Set.Ioo_subset_Ioi_self
theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a :=
Ioc_subset_Icc_self.trans Icc_subset_Ici_self
theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a :=
Ioo_subset_Ico_self.trans Ico_subset_Ici_self
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α]
@[simp] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩
@[simp] lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty]
variable [LocallyFiniteOrder α]
theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by
simpa [← coe_subset] using Set.Icc_subset_Iic_self
theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by
simpa [← coe_subset] using Set.Ioc_subset_Iic_self
theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by
simpa [← coe_subset] using Set.Ico_subset_Iio_self
theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by
simpa [← coe_subset] using Set.Ioo_subset_Iio_self
theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b :=
Ico_subset_Icc_self.trans Icc_subset_Iic_self
theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b :=
Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self
end LocallyFiniteOrderBot
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] {a : α}
theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by
simpa [← coe_subset] using Set.Ioi_subset_Ici_self
theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite :=
let ⟨a, ha⟩ := hs
(Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx
theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s :=
mt BddBelow.finite
variable [Fintype α]
theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : univ.filter (a < ·) = Ioi a := by
ext
simp
theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : univ.filter (a ≤ ·) = Ici a := by
ext
simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] {a : α}
theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by
simpa [← coe_subset] using Set.Iio_subset_Iic_self
theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite :=
hs.dual.finite
theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s :=
mt BddAbove.finite
variable [Fintype α]
theorem filter_gt_eq_Iio [DecidablePred (· < a)] : univ.filter (· < a) = Iio a := by
ext
simp
theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : univ.filter (· ≤ a) = Iic a := by
ext
simp
end LocallyFiniteOrderBot
variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α]
theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) :=
disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba
end Preorder
section PartialOrder
variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α}
@[simp]
theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self]
@[simp]
theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by
rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff]
theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) :=
disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1
section DecidableEq
variable [DecidableEq α]
@[simp]
theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj]
@[simp]
theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj]
@[simp]
theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj]
@[simp]
theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj]
@[simp]
theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj]
@[simp]
theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by
rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h]
@[simp]
theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by
rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h]
@[simp]
theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by
rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h]
@[simp]
theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by
rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h]
@[simp]
theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h]
@[simp]
theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h]
@[simp]
theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h]
@[simp]
theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h]
@[simp]
theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h]
@[simp]
theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ :=
(Ico_disjoint_Ico_consecutive a b c).eq_bot
end DecidableEq
-- Those lemmas are purposefully the other way around
/-- `Finset.cons` version of `Finset.Ico_insert_right`. -/
theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by
classical rw [cons_eq_insert, Ico_insert_right h]
/-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/
theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by
classical rw [cons_eq_insert, Ioc_insert_left h]
/-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/
theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by
classical rw [cons_eq_insert, Ioo_insert_right h]
/-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/
theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by
classical rw [cons_eq_insert, Ioo_insert_left h]
theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) :
((Ico a b).filter fun x => x ≤ a) = {a} := by
ext x
rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm]
exact and_iff_left_of_imp fun h => h.le.trans_lt hab
theorem card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 := by
classical
by_cases h : a ≤ b
· rw [Icc_eq_cons_Ico h, card_cons]
exact (Nat.add_sub_cancel _ _).symm
· rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub]
theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 :=
@card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _
theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 := by
classical
by_cases h : a < b
· rw [Ico_eq_cons_Ioo h, card_cons]
exact (Nat.add_sub_cancel _ _).symm
· rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub]
theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : (Ioo a b).card = (Ioc a b).card - 1 :=
@card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _
theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 := by
rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one]
rfl
end PartialOrder
section BoundedPartialOrder
variable [PartialOrder α]
section OrderTop
variable [LocallyFiniteOrderTop α]
@[simp]
theorem Ici_erase [DecidableEq α] (a : α) : (Ici a).erase a = Ioi a := by
ext
simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm]
@[simp]
theorem Ioi_insert [DecidableEq α] (a : α) : insert a (Ioi a) = Ici a := by
ext
simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem not_mem_Ioi_self {b : α} : b ∉ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h)
-- Purposefully written the other way around
/-- `Finset.cons` version of `Finset.Ioi_insert`. -/
theorem Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by
classical rw [cons_eq_insert, Ioi_insert]
theorem card_Ioi_eq_card_Ici_sub_one (a : α) : (Ioi a).card = (Ici a).card - 1 := by
rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right]
end OrderTop
section OrderBot
variable [LocallyFiniteOrderBot α]
@[simp]
theorem Iic_erase [DecidableEq α] (b : α) : (Iic b).erase b = Iio b := by
ext
simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm]
@[simp]
theorem Iio_insert [DecidableEq α] (b : α) : insert b (Iio b) = Iic b := by
ext
simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem not_mem_Iio_self {b : α} : b ∉ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h)
-- Purposefully written the other way around
/-- `Finset.cons` version of `Finset.Iio_insert`. -/
theorem Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self := by
classical rw [cons_eq_insert, Iio_insert]
theorem card_Iio_eq_card_Iic_sub_one (a : α) : (Iio a).card = (Iic a).card - 1 := by
rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right]
end OrderBot
end BoundedPartialOrder
section SemilatticeSup
variable [SemilatticeSup α] [LocallyFiniteOrderBot α]
-- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`?
lemma sup'_Iic (a : α) : (Iic a).sup' nonempty_Iic id = a :=
le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a
@[simp] lemma sup_Iic [OrderBot α] (a : α) : (Iic a).sup id = a :=
le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [LocallyFiniteOrderTop α]
lemma inf'_Ici (a : α) : (Ici a).inf' nonempty_Ici id = a :=
ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a
@[simp] lemma inf_Ici [OrderTop α] (a : α) : (Ici a).inf id = a :=
le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1
end SemilatticeInf
section LinearOrder
variable [LinearOrder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] {a b : α}
theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by
rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h]
theorem Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) :
Ico a b ∪ Ico b c = Ico a c := by
rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc]
@[simp]
theorem Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) :
Ioc a b ∪ Ioc b c = Ioc a c := by
rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ h₂]
theorem Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by
rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico]
exact Set.Ico_subset_Ico_union_Ico
theorem Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) :
Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by
rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had]
theorem Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) :
Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by
rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ h₂]
theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by
rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, ← inf_eq_min, ← sup_eq_max,
Set.Ico_inter_Ico]
@[simp]
theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by
cases le_total b c with
| inl h => rw [Ico_filter_lt_of_right_le h, min_eq_left h]
| inr h => rw [Ico_filter_lt_of_le_right h, min_eq_right h]
@[simp]
theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by
cases le_total a c with
| inl h => rw [Ico_filter_le_of_left_le h, max_eq_right h]
| inr h => rw [Ico_filter_le_of_le_left h, max_eq_left h]
@[simp]
theorem Ioo_filter_lt (a b c : α) : (Ioo a b).filter (· < c) = Ioo a (min b c) := by
ext
simp [and_assoc]
@[simp]
theorem Iio_filter_lt {α} [LinearOrder α] [LocallyFiniteOrderBot α] (a b : α) :
(Iio a).filter (· < b) = Iio (min a b) := by
ext
simp [and_assoc]
@[simp]
theorem Ico_diff_Ico_left (a b c : α) : Ico a b \ Ico a c = Ico (max a c) b := by
cases le_total a c with
| inl h =>
ext x
rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and_right_comm, not_and, not_lt]
exact and_congr_left' ⟨fun hx => hx.2 hx.1, fun hx => ⟨h.trans hx, fun _ => hx⟩⟩
| inr h => rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h]
@[simp]
theorem Ico_diff_Ico_right (a b c : α) : Ico a b \ Ico c b = Ico a (min b c) := by
cases le_total b c with
| inl h => rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h]
| inr h =>
ext x
rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le]
exact and_congr_right' ⟨fun hx => hx.2 hx.1, fun hx => ⟨hx.trans_le h, fun _ => hx⟩⟩
end LocallyFiniteOrder
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] {s : Set α}
theorem _root_.Set.Infinite.exists_gt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, a < b :=
not_bddAbove_iff.1 hs.not_bddAbove
theorem _root_.Set.infinite_iff_exists_gt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, a < b :=
⟨Set.Infinite.exists_gt, Set.infinite_of_forall_exists_gt⟩
end LocallyFiniteOrderBot
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] {s : Set α}
theorem _root_.Set.Infinite.exists_lt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, b < a :=
not_bddBelow_iff.1 hs.not_bddBelow
theorem _root_.Set.infinite_iff_exists_lt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, b < a :=
⟨Set.Infinite.exists_lt, Set.infinite_of_forall_exists_lt⟩
end LocallyFiniteOrderTop
variable [Fintype α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α]
theorem Ioi_disjUnion_Iio (a : α) :
(Ioi a).disjUnion (Iio a) (disjoint_Ioi_Iio a) = ({a} : Finset α)ᶜ := by
ext
simp [eq_comm]
end LinearOrder
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α}
theorem uIcc_toDual (a b : α) : [[toDual a, toDual b]] = [[a, b]].map toDual.toEmbedding :=
Icc_toDual _ _
@[simp]
theorem uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by
rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h]
@[simp]
theorem uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by
rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h]
theorem uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by
rw [uIcc, uIcc, inf_comm, sup_comm]
-- porting note (#10618): simp can prove this
-- @[simp]
theorem uIcc_self : [[a, a]] = {a} := by simp [uIcc]
@[simp]
theorem nonempty_uIcc : Finset.Nonempty [[a, b]] :=
nonempty_Icc.2 inf_le_sup
theorem Icc_subset_uIcc : Icc a b ⊆ [[a, b]] :=
Icc_subset_Icc inf_le_left le_sup_right
theorem Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] :=
Icc_subset_Icc inf_le_right le_sup_left
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_mem_uIcc : a ∈ [[a, b]] :=
mem_Icc.2 ⟨inf_le_left, le_sup_left⟩
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_mem_uIcc : b ∈ [[a, b]] :=
mem_Icc.2 ⟨inf_le_right, le_sup_right⟩
theorem mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] :=
Icc_subset_uIcc <| mem_Icc.2 ⟨ha, hb⟩
theorem mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] :=
Icc_subset_uIcc' <| mem_Icc.2 ⟨hb, ha⟩
theorem uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) :
[[a₁, b₁]] ⊆ [[a₂, b₂]] := by
rw [mem_uIcc] at h₁ h₂
exact Icc_subset_Icc (_root_.le_inf h₁.1 h₂.1) (_root_.sup_le h₁.2 h₂.2)
theorem uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := by
rw [mem_Icc] at ha hb
exact Icc_subset_Icc (_root_.le_inf ha.1 hb.1) (_root_.sup_le ha.2 hb.2)
theorem uIcc_subset_uIcc_iff_mem : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] :=
⟨fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩, fun h => uIcc_subset_uIcc h.1 h.2⟩
theorem uIcc_subset_uIcc_iff_le' :
[[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ :=
Icc_subset_Icc_iff inf_le_sup
theorem uIcc_subset_uIcc_right (h : x ∈ [[a, b]]) : [[x, b]] ⊆ [[a, b]] :=
uIcc_subset_uIcc h right_mem_uIcc
theorem uIcc_subset_uIcc_left (h : x ∈ [[a, b]]) : [[a, x]] ⊆ [[a, b]] :=
uIcc_subset_uIcc left_mem_uIcc h
end Lattice
section DistribLattice
variable [DistribLattice α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α}
theorem eq_of_mem_uIcc_of_mem_uIcc : a ∈ [[b, c]] → b ∈ [[a, c]] → a = b := by
simp_rw [mem_uIcc]
exact Set.eq_of_mem_uIcc_of_mem_uIcc
theorem eq_of_mem_uIcc_of_mem_uIcc' : b ∈ [[a, c]] → c ∈ [[a, b]] → b = c := by
simp_rw [mem_uIcc]
exact Set.eq_of_mem_uIcc_of_mem_uIcc'
theorem uIcc_injective_right (a : α) : Injective fun b => [[b, a]] := fun b c h => by
rw [ext_iff] at h
exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc)
theorem uIcc_injective_left (a : α) : Injective (uIcc a) := by
simpa only [uIcc_comm] using uIcc_injective_right a
end DistribLattice
section LinearOrder
variable [LinearOrder α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α}
theorem Icc_min_max : Icc (min a b) (max a b) = [[a, b]] :=
rfl
theorem uIcc_of_not_le (h : ¬a ≤ b) : [[a, b]] = Icc b a :=
uIcc_of_ge <| le_of_not_ge h
theorem uIcc_of_not_ge (h : ¬b ≤ a) : [[a, b]] = Icc a b :=
uIcc_of_le <| le_of_not_ge h
theorem uIcc_eq_union : [[a, b]] = Icc a b ∪ Icc b a :=
coe_injective <| by
push_cast
exact Set.uIcc_eq_union
theorem mem_uIcc' : a ∈ [[b, c]] ↔ b ≤ a ∧ a ≤ c ∨ c ≤ a ∧ a ≤ b := by simp [uIcc_eq_union]
theorem not_mem_uIcc_of_lt : c < a → c < b → c ∉ [[a, b]] := by
rw [mem_uIcc]
exact Set.not_mem_uIcc_of_lt
theorem not_mem_uIcc_of_gt : a < c → b < c → c ∉ [[a, b]] := by
rw [mem_uIcc]
exact Set.not_mem_uIcc_of_gt
theorem uIcc_subset_uIcc_iff_le :
[[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ :=
uIcc_subset_uIcc_iff_le'
/-- A sort of triangle inequality. -/
theorem uIcc_subset_uIcc_union_uIcc : [[a, c]] ⊆ [[a, b]] ∪ [[b, c]] :=
coe_subset.1 <| by
push_cast
exact Set.uIcc_subset_uIcc_union_uIcc
end LinearOrder
end Finset
/-! ### `⩿`, `⋖` and monotonicity -/
section Cover
open Finset Relation
set_option linter.unusedVariables false in -- `have` for wf induction triggers linter
lemma transGen_wcovBy_of_le [Preorder α] [LocallyFiniteOrder α] {x y : α} (hxy : x ≤ y) :
TransGen (· ⩿ ·) x y := by
-- We proceed by well-founded induction on the cardinality of `Icc x y`.
-- It's impossible for the cardinality to be zero since `x ≤ y`
have : (Ico x y).card < (Icc x y).card := card_lt_card <|
⟨Ico_subset_Icc_self, not_subset.mpr ⟨y, ⟨right_mem_Icc.mpr hxy, right_not_mem_Ico⟩⟩⟩
by_cases hxy' : y ≤ x
-- If `y ≤ x`, then `x ⩿ y`
· exact .single <| wcovBy_of_le_of_le hxy hxy'
/- and if `¬ y ≤ x`, then `x < y`, not because it is a linear order, but because `x ≤ y`
already. In that case, since `z` is maximal in `Ico x y`, then `z ⩿ y` and we can use the
induction hypothesis to show that `Relation.TransGen (· ⩿ ·) x z`. -/
· have h_non : (Ico x y).Nonempty := ⟨x, mem_Ico.mpr ⟨le_rfl, lt_of_le_not_le hxy hxy'⟩⟩
obtain ⟨z, z_mem, hz⟩ := (Ico x y).exists_maximal h_non
have z_card : (Icc x z).card <(Icc x y).card := calc
(Icc x z).card ≤ (Ico x y).card :=
card_le_card <| Icc_subset_Ico_right (mem_Ico.mp z_mem).2
_ < (Icc x y).card := this
have h₁ := transGen_wcovBy_of_le (mem_Ico.mp z_mem).1
have h₂ : z ⩿ y := by
refine ⟨(mem_Ico.mp z_mem).2.le, fun c hzc hcy ↦ hz c ?_ hzc⟩
exact mem_Ico.mpr <| ⟨(mem_Ico.mp z_mem).1.trans hzc.le, hcy⟩
exact .tail h₁ h₂
termination_by (Icc x y).card
/-- In a locally finite preorder, `≤` is the transitive closure of `⩿`. -/
lemma le_iff_transGen_wcovBy [Preorder α] [LocallyFiniteOrder α] {x y : α} :
x ≤ y ↔ TransGen (· ⩿ ·) x y := by
refine ⟨transGen_wcovBy_of_le, fun h ↦ ?_⟩
induction h with
| single h => exact h.le
| tail _ h₁ h₂ => exact h₂.trans h₁.le
/-- In a locally finite partial order, `≤` is the reflexive transitive closure of `⋖`. -/
lemma le_iff_reflTransGen_covBy [PartialOrder α] [LocallyFiniteOrder α] {x y : α} :
x ≤ y ↔ ReflTransGen (· ⋖ ·) x y := by
rw [le_iff_transGen_wcovBy, wcovBy_eq_reflGen_covBy, transGen_reflGen]
set_option linter.unusedVariables false in -- `have` for wf induction triggers linter
lemma transGen_covBy_of_lt [Preorder α] [LocallyFiniteOrder α] {x y : α} (hxy : x < y) :
TransGen (· ⋖ ·) x y := by
-- We proceed by well-founded induction on the cardinality of `Ico x y`.
-- It's impossible for the cardinality to be zero since `x < y`
have h_non : (Ico x y).Nonempty := ⟨x, mem_Ico.mpr ⟨le_rfl, hxy⟩⟩
-- `Ico x y` is a nonempty finset and so contains a maximal element `z` and
-- `Ico x z` has cardinality strictly less than the cardinality of `Ico x y`
obtain ⟨z, z_mem, hz⟩ := (Ico x y).exists_maximal h_non
have z_card : (Ico x z).card < (Ico x y).card := card_lt_card <| ssubset_iff_of_subset
(Ico_subset_Ico le_rfl (mem_Ico.mp z_mem).2.le) |>.mpr ⟨z, z_mem, right_not_mem_Ico⟩
/- Since `z` is maximal in `Ico x y`, `z ⋖ y`. -/
have hzy : z ⋖ y := by
refine ⟨(mem_Ico.mp z_mem).2, fun c hc hcy ↦ ?_⟩
exact hz _ (mem_Ico.mpr ⟨((mem_Ico.mp z_mem).1.trans_lt hc).le, hcy⟩) hc
by_cases hxz : x < z
/- when `x < z`, then we may use the induction hypothesis to get a chain
`Relation.TransGen (· ⋖ ·) x z`, which we can extend with `Relation.TransGen.tail`. -/
· exact .tail (transGen_covBy_of_lt hxz) hzy
/- when `¬ x < z`, then actually `z ≤ x` (not because it's a linear order, but because
`x ≤ z`), and since `z ⋖ y` we conclude that `x ⋖ y` , then `Relation.TransGen.single`. -/
· simp only [lt_iff_le_not_le, not_and, not_not] at hxz
exact .single (hzy.of_le_of_lt (hxz (mem_Ico.mp z_mem).1) hxy)
termination_by (Ico x y).card
/-- In a locally finite preorder, `<` is the transitive closure of `⋖`. -/
lemma lt_iff_transGen_covBy [Preorder α] [LocallyFiniteOrder α] {x y : α} :
x < y ↔ TransGen (· ⋖ ·) x y := by
refine ⟨transGen_covBy_of_lt, fun h ↦ ?_⟩
induction h with
| single hx => exact hx.1
| tail _ hb ih => exact ih.trans hb.1
variable {β : Type*}
/-- A function from a locally finite preorder is monotone if and only if it is monotone when
restricted to pairs satisfying `a ⩿ b`. -/
lemma monotone_iff_forall_wcovBy [Preorder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : Monotone f ↔ ∀ a b : α, a ⩿ b → f a ≤ f b := by
refine ⟨fun hf _ _ h ↦ hf h.le, fun h a b hab ↦ ?_⟩
simpa [transGen_eq_self (r := ((· : β) ≤ ·)) transitive_le]
using TransGen.lift f h <| le_iff_transGen_wcovBy.mp hab
/-- A function from a locally finite partial order is monotone if and only if it is monotone when
restricted to pairs satisfying `a ⋖ b`. -/
lemma monotone_iff_forall_covBy [PartialOrder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : Monotone f ↔ ∀ a b : α, a ⋖ b → f a ≤ f b := by
refine ⟨fun hf _ _ h ↦ hf h.le, fun h a b hab ↦ ?_⟩
simpa [reflTransGen_eq_self (r := ((· : β) ≤ ·)) IsRefl.reflexive transitive_le]
using ReflTransGen.lift f h <| le_iff_reflTransGen_covBy.mp hab
/-- A function from a locally finite preorder is strictly monotone if and only if it is strictly
monotone when restricted to pairs satisfying `a ⋖ b`. -/
lemma strictMono_iff_forall_covBy [Preorder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : StrictMono f ↔ ∀ a b : α, a ⋖ b → f a < f b := by
refine ⟨fun hf _ _ h ↦ hf h.lt, fun h a b hab ↦ ?_⟩
have := Relation.TransGen.lift f h (a := a) (b := b)
rw [← lt_iff_transGen_covBy, transGen_eq_self (@lt_trans β _)] at this
exact this hab
/-- A function from a locally finite preorder is antitone if and only if it is antitone when
restricted to pairs satisfying `a ⩿ b`. -/
lemma antitone_iff_forall_wcovBy [Preorder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : Antitone f ↔ ∀ a b : α, a ⩿ b → f b ≤ f a :=
monotone_iff_forall_wcovBy (β := βᵒᵈ) f
/-- A function from a locally finite partial order is antitone if and only if it is antitone when
restricted to pairs satisfying `a ⋖ b`. -/
lemma antitone_iff_forall_covBy [PartialOrder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : Antitone f ↔ ∀ a b : α, a ⋖ b → f b ≤ f a :=
monotone_iff_forall_covBy (β := βᵒᵈ) f
/-- A function from a locally finite preorder is strictly antitone if and only if it is strictly
antitone when restricted to pairs satisfying `a ⋖ b`. -/
lemma strictAnti_iff_forall_covBy [Preorder α] [LocallyFiniteOrder α] [Preorder β]
(f : α → β) : StrictAnti f ↔ ∀ a b : α, a ⋖ b → f b < f a :=
strictMono_iff_forall_covBy (β := βᵒᵈ) f
end Cover
|
Order\Interval\Finset\Box.lean | /-
Copyright (c) 2024 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Order.Ring.Prod
import Mathlib.Data.Int.Interval
import Mathlib.Order.Disjointed
import Mathlib.Tactic.AdaptationNote
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Zify
/-!
# Decomposing a locally finite ordered ring into boxes
This file proves that any locally finite ordered ring can be decomposed into "boxes", namely
differences of consecutive intervals.
## Implementation notes
We don't need the full ring structure, only that there is an order embedding `ℤ → `
-/
/-! ### General locally finite ordered ring -/
namespace Finset
variable {α : Type*} [OrderedRing α] [LocallyFiniteOrder α] {n : ℕ}
private lemma Icc_neg_mono : Monotone fun n : ℕ ↦ Icc (-n : α) n := by
refine fun m n hmn ↦ by apply Icc_subset_Icc <;> simpa using Nat.mono_cast hmn
variable [DecidableEq α]
/-- Hollow box centered at `0 : α` going from `-n` to `n`. -/
def box : ℕ → Finset α := disjointed fun n ↦ Icc (-n : α) n
@[simp] lemma box_zero : (box 0 : Finset α) = {0} := by simp [box]
lemma box_succ_eq_sdiff (n : ℕ) :
box (n + 1) = Icc (-n.succ : α) n.succ \ Icc (-n) n := Icc_neg_mono.disjointed_succ _
lemma disjoint_box_succ_prod (n : ℕ) : Disjoint (box (n + 1)) (Icc (-n : α) n) := by
rw [box_succ_eq_sdiff]; exact disjoint_sdiff_self_left
@[simp] lemma box_succ_union_prod (n : ℕ) :
box (n + 1) ∪ Icc (-n : α) n = Icc (-n.succ : α) n.succ := Icc_neg_mono.disjointed_succ_sup _
lemma box_succ_disjUnion (n : ℕ) :
(box (n + 1)).disjUnion (Icc (-n : α) n) (disjoint_box_succ_prod _) =
Icc (-n.succ : α) n.succ := by rw [disjUnion_eq_union, box_succ_union_prod]
@[simp] lemma zero_mem_box : (0 : α) ∈ box n ↔ n = 0 := by cases n <;> simp [box_succ_eq_sdiff]
lemma eq_zero_iff_eq_zero_of_mem_box {x : α} (hx : x ∈ box n) : x = 0 ↔ n = 0 :=
⟨zero_mem_box.mp ∘ (· ▸ hx), fun hn ↦ by rwa [hn, box_zero, mem_singleton] at hx⟩
end Finset
open Finset
/-! ### Product of locally finite ordered rings -/
namespace Prod
variable {α β : Type*} [OrderedRing α] [OrderedRing β] [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableEq α] [DecidableEq β] [@DecidableRel (α × β) (· ≤ ·)]
@[simp] lemma card_box_succ (n : ℕ) :
(box (n + 1) : Finset (α × β)).card =
(Icc (-n.succ : α) n.succ).card * (Icc (-n.succ : β) n.succ).card -
(Icc (-n : α) n).card * (Icc (-n : β) n).card := by
rw [box_succ_eq_sdiff, card_sdiff (Icc_neg_mono n.le_succ), Prod.card_Icc, Prod.card_Icc]; rfl
end Prod
/-! ### `ℤ × ℤ` -/
namespace Int
variable {n : ℕ} {x : ℤ × ℤ}
attribute [norm_cast] toNat_ofNat
lemma card_box : ∀ {n}, n ≠ 0 → (box n : Finset (ℤ × ℤ)).card = 8 * n
| n + 1, _ => by
simp_rw [Prod.card_box_succ, card_Icc, sub_neg_eq_add]
norm_cast
refine tsub_eq_of_eq_add ?_
zify
ring
@[simp] lemma mem_box : ∀ {n}, x ∈ box n ↔ max x.1.natAbs x.2.natAbs = n
| 0 => by simp [Prod.ext_iff]
| n + 1 => by
simp [box_succ_eq_sdiff, Prod.le_def]
#adaptation_note /-- v4.7.0-rc1: `omega` no longer identifies atoms up to defeq.
(This had become a performance bottleneck.)
We need a tactic for normalising instances, to avoid the `have`/`simp` dance below: -/
have : @Nat.cast ℤ instNatCastInt n = @Nat.cast ℤ AddMonoidWithOne.toNatCast n := rfl
simp only [this]
omega
-- TODO: Can this be generalised to locally finite archimedean ordered rings?
lemma existsUnique_mem_box (x : ℤ × ℤ) : ∃! n : ℕ, x ∈ box n := by
use max x.1.natAbs x.2.natAbs; simp only [mem_box, and_self_iff, forall_eq']
end Int
|
Order\Interval\Finset\Defs.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Preimage
import Mathlib.Order.Interval.Set.Image
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Locally finite orders
This file defines locally finite orders.
A locally finite order is an order for which all bounded intervals are finite. This allows to make
sense of `Icc`/`Ico`/`Ioc`/`Ioo` as lists, multisets, or finsets.
Further, if the order is bounded above (resp. below), then we can also make sense of the
"unbounded" intervals `Ici`/`Ioi` (resp. `Iic`/`Iio`).
Many theorems about these intervals can be found in `Mathlib.Order.Interval.Finset.Basic`.
## Examples
Naturally occurring locally finite orders are `ℕ`, `ℤ`, `ℕ+`, `Fin n`, `α × β` the product of two
locally finite orders, `α →₀ β` the finitely supported functions to a locally finite order `β`...
## Main declarations
In a `LocallyFiniteOrder`,
* `Finset.Icc`: Closed-closed interval as a finset.
* `Finset.Ico`: Closed-open interval as a finset.
* `Finset.Ioc`: Open-closed interval as a finset.
* `Finset.Ioo`: Open-open interval as a finset.
* `Finset.uIcc`: Unordered closed interval as a finset.
In a `LocallyFiniteOrderTop`,
* `Finset.Ici`: Closed-infinite interval as a finset.
* `Finset.Ioi`: Open-infinite interval as a finset.
In a `LocallyFiniteOrderBot`,
* `Finset.Iic`: Infinite-open interval as a finset.
* `Finset.Iio`: Infinite-closed interval as a finset.
## Instances
A `LocallyFiniteOrder` instance can be built
* for a subtype of a locally finite order. See `Subtype.locallyFiniteOrder`.
* for the product of two locally finite orders. See `Prod.locallyFiniteOrder`.
* for any fintype (but not as an instance). See `Fintype.toLocallyFiniteOrder`.
* from a definition of `Finset.Icc` alone. See `LocallyFiniteOrder.ofIcc`.
* by pulling back `LocallyFiniteOrder β` through an order embedding `f : α →o β`. See
`OrderEmbedding.locallyFiniteOrder`.
Instances for concrete types are proved in their respective files:
* `ℕ` is in `Order.Interval.Finset.Nat`
* `ℤ` is in `Data.Int.Interval`
* `ℕ+` is in `Data.PNat.Interval`
* `Fin n` is in `Order.Interval.Finset.Fin`
* `Finset α` is in `Data.Finset.Interval`
* `Σ i, α i` is in `Data.Sigma.Interval`
Along, you will find lemmas about the cardinality of those finite intervals.
## TODO
Provide the `LocallyFiniteOrder` instance for `α ×ₗ β` where `LocallyFiniteOrder α` and
`Fintype β`.
Provide the `LocallyFiniteOrder` instance for `α →₀ β` where `β` is locally finite. Provide the
`LocallyFiniteOrder` instance for `Π₀ i, β i` where all the `β i` are locally finite.
From `LinearOrder α`, `NoMaxOrder α`, `LocallyFiniteOrder α`, we can also define an
order isomorphism `α ≃ ℕ` or `α ≃ ℤ`, depending on whether we have `OrderBot α` or
`NoMinOrder α` and `Nonempty α`. When `OrderBot α`, we can match `a : α` to `(Iio a).card`.
We can provide `SuccOrder α` from `LinearOrder α` and `LocallyFiniteOrder α` using
```lean
lemma exists_min_greater [LinearOrder α] [LocallyFiniteOrder α] {x ub : α} (hx : x < ub) :
∃ lub, x < lub ∧ ∀ y, x < y → lub ≤ y := by
-- very non golfed
have h : (Finset.Ioc x ub).Nonempty := ⟨ub, Finset.mem_Ioc.2 ⟨hx, le_rfl⟩⟩
use Finset.min' (Finset.Ioc x ub) h
constructor
· exact (Finset.mem_Ioc.mp <| Finset.min'_mem _ h).1
rintro y hxy
obtain hy | hy := le_total y ub
· refine Finset.min'_le (Ioc x ub) y ?_
simp [*] at *
· exact (Finset.min'_le _ _ (Finset.mem_Ioc.2 ⟨hx, le_rfl⟩)).trans hy
```
Note that the converse is not true. Consider `{-2^z | z : ℤ} ∪ {2^z | z : ℤ}`. Any element has a
successor (and actually a predecessor as well), so it is a `SuccOrder`, but it's not locally finite
as `Icc (-1) 1` is infinite.
-/
open Finset Function
/-- This is a mixin class describing a locally finite order,
that is, is an order where bounded intervals are finite.
When you don't care too much about definitional equality, you can use `LocallyFiniteOrder.ofIcc` or
`LocallyFiniteOrder.ofFiniteIcc` to build a locally finite order from just `Finset.Icc`. -/
class LocallyFiniteOrder (α : Type*) [Preorder α] where
/-- Left-closed right-closed interval -/
finsetIcc : α → α → Finset α
/-- Left-closed right-open interval -/
finsetIco : α → α → Finset α
/-- Left-open right-closed interval -/
finsetIoc : α → α → Finset α
/-- Left-open right-open interval -/
finsetIoo : α → α → Finset α
/-- `x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b` -/
finset_mem_Icc : ∀ a b x : α, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b
/-- `x ∈ finsetIco a b ↔ a ≤ x ∧ x < b` -/
finset_mem_Ico : ∀ a b x : α, x ∈ finsetIco a b ↔ a ≤ x ∧ x < b
/-- `x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b` -/
finset_mem_Ioc : ∀ a b x : α, x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b
/-- `x ∈ finsetIoo a b ↔ a < x ∧ x < b` -/
finset_mem_Ioo : ∀ a b x : α, x ∈ finsetIoo a b ↔ a < x ∧ x < b
/-- This mixin class describes an order where all intervals bounded below are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderTop` as it allows empty types. -/
class LocallyFiniteOrderTop (α : Type*) [Preorder α] where
/-- Left-open right-infinite interval -/
finsetIoi : α → Finset α
/-- Left-closed right-infinite interval -/
finsetIci : α → Finset α
/-- `x ∈ finsetIci a ↔ a ≤ x` -/
finset_mem_Ici : ∀ a x : α, x ∈ finsetIci a ↔ a ≤ x
/-- `x ∈ finsetIoi a ↔ a < x` -/
finset_mem_Ioi : ∀ a x : α, x ∈ finsetIoi a ↔ a < x
/-- This mixin class describes an order where all intervals bounded above are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderBot` as it allows empty types. -/
class LocallyFiniteOrderBot (α : Type*) [Preorder α] where
/-- Left-infinite right-open interval -/
finsetIio : α → Finset α
/-- Left-infinite right-closed interval -/
finsetIic : α → Finset α
/-- `x ∈ finsetIic a ↔ x ≤ a` -/
finset_mem_Iic : ∀ a x : α, x ∈ finsetIic a ↔ x ≤ a
/-- `x ∈ finsetIio a ↔ x < a` -/
finset_mem_Iio : ∀ a x : α, x ∈ finsetIio a ↔ x < a
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableRel (· ≤ ·)` but
only `Preorder`. -/
def LocallyFiniteOrder.ofIcc' (α : Type*) [Preorder α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α :=
{ finsetIcc
finsetIco := fun a b => (finsetIcc a b).filter fun x => ¬b ≤ x
finsetIoc := fun a b => (finsetIcc a b).filter fun x => ¬x ≤ a
finsetIoo := fun a b => (finsetIcc a b).filter fun x => ¬x ≤ a ∧ ¬b ≤ x
finset_mem_Icc := mem_Icc
finset_mem_Ico := fun a b x => by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_not_le]
finset_mem_Ioc := fun a b x => by
rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_not_le]
finset_mem_Ioo := fun a b x => by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_not_le, lt_iff_le_not_le] }
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc'`, this one requires `PartialOrder` but only
`DecidableEq`. -/
def LocallyFiniteOrder.ofIcc (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α :=
{ finsetIcc
finsetIco := fun a b => (finsetIcc a b).filter fun x => x ≠ b
finsetIoc := fun a b => (finsetIcc a b).filter fun x => a ≠ x
finsetIoo := fun a b => (finsetIcc a b).filter fun x => a ≠ x ∧ x ≠ b
finset_mem_Icc := mem_Icc
finset_mem_Ico := fun a b x => by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_and_ne]
finset_mem_Ioc := fun a b x => by
rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_and_ne]
finset_mem_Ioo := fun a b x => by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_and_ne, lt_iff_le_and_ne] }
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci`, this one requires `DecidableRel (· ≤ ·)` but
only `Preorder`. -/
def LocallyFiniteOrderTop.ofIci' (α : Type*) [Preorder α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α :=
{ finsetIci
finsetIoi := fun a => (finsetIci a).filter fun x => ¬x ≤ a
finset_mem_Ici := mem_Ici
finset_mem_Ioi := fun a x => by rw [mem_filter, mem_Ici, lt_iff_le_not_le] }
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderTop.ofIci (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α :=
{ finsetIci
finsetIoi := fun a => (finsetIci a).filter fun x => a ≠ x
finset_mem_Ici := mem_Ici
finset_mem_Ioi := fun a x => by rw [mem_filter, mem_Ici, lt_iff_le_and_ne] }
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic`, this one requires `DecidableRel (· ≤ ·)` but
only `Preorder`. -/
def LocallyFiniteOrderBot.ofIic' (α : Type*) [Preorder α] [DecidableRel ((· ≤ ·) : α → α → Prop)]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α :=
{ finsetIic
finsetIio := fun a => (finsetIic a).filter fun x => ¬a ≤ x
finset_mem_Iic := mem_Iic
finset_mem_Iio := fun a x => by rw [mem_filter, mem_Iic, lt_iff_le_not_le] }
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderBot.ofIic (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α :=
{ finsetIic
finsetIio := fun a => (finsetIic a).filter fun x => x ≠ a
finset_mem_Iic := mem_Iic
finset_mem_Iio := fun a x => by rw [mem_filter, mem_Iic, lt_iff_le_and_ne] }
-- Note: this was in the wrong namespace in Mathlib 3.
variable {α β : Type*}
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrder [Preorder α] [IsEmpty α] : LocallyFiniteOrder α where
finsetIcc := isEmptyElim
finsetIco := isEmptyElim
finsetIoc := isEmptyElim
finsetIoo := isEmptyElim
finset_mem_Icc := isEmptyElim
finset_mem_Ico := isEmptyElim
finset_mem_Ioc := isEmptyElim
finset_mem_Ioo := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderTop [Preorder α] [IsEmpty α] :
LocallyFiniteOrderTop α where
finsetIci := isEmptyElim
finsetIoi := isEmptyElim
finset_mem_Ici := isEmptyElim
finset_mem_Ioi := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderBot [Preorder α] [IsEmpty α] :
LocallyFiniteOrderBot α where
finsetIic := isEmptyElim
finsetIio := isEmptyElim
finset_mem_Iic := isEmptyElim
finset_mem_Iio := isEmptyElim
/-! ### Intervals as finsets -/
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] {a b x : α}
/-- The finset of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a finset.
-/
def Icc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIcc a b
/-- The finset of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a finset.
-/
def Ico (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIco a b
/-- The finset of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a finset.
-/
def Ioc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoc a b
/-- The finset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a finset.
-/
def Ioo (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoo a b
@[simp]
theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Icc a b x
@[simp]
theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ico a b x
@[simp]
theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Ioc a b x
@[simp]
theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ioo a b x
@[simp, norm_cast]
theorem coe_Icc (a b : α) : (Icc a b : Set α) = Set.Icc a b :=
Set.ext fun _ => mem_Icc
@[simp, norm_cast]
theorem coe_Ico (a b : α) : (Ico a b : Set α) = Set.Ico a b :=
Set.ext fun _ => mem_Ico
@[simp, norm_cast]
theorem coe_Ioc (a b : α) : (Ioc a b : Set α) = Set.Ioc a b :=
Set.ext fun _ => mem_Ioc
@[simp, norm_cast]
theorem coe_Ioo (a b : α) : (Ioo a b : Set α) = Set.Ioo a b :=
Set.ext fun _ => mem_Ioo
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] {a x : α}
/-- The finset of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a finset. -/
def Ici (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIci a
/-- The finset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a finset. -/
def Ioi (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIoi a
@[simp]
theorem mem_Ici : x ∈ Ici a ↔ a ≤ x :=
LocallyFiniteOrderTop.finset_mem_Ici _ _
@[simp]
theorem mem_Ioi : x ∈ Ioi a ↔ a < x :=
LocallyFiniteOrderTop.finset_mem_Ioi _ _
@[simp, norm_cast]
theorem coe_Ici (a : α) : (Ici a : Set α) = Set.Ici a :=
Set.ext fun _ => mem_Ici
@[simp, norm_cast]
theorem coe_Ioi (a : α) : (Ioi a : Set α) = Set.Ioi a :=
Set.ext fun _ => mem_Ioi
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] {a x : α}
/-- The finset of elements `x` such that `a ≤ x`. Basically `Set.Iic a` as a finset. -/
def Iic (a : α) : Finset α :=
LocallyFiniteOrderBot.finsetIic a
/-- The finset of elements `x` such that `a < x`. Basically `Set.Iio a` as a finset. -/
def Iio (a : α) : Finset α :=
LocallyFiniteOrderBot.finsetIio a
@[simp]
theorem mem_Iic : x ∈ Iic a ↔ x ≤ a :=
LocallyFiniteOrderBot.finset_mem_Iic _ _
@[simp]
theorem mem_Iio : x ∈ Iio a ↔ x < a :=
LocallyFiniteOrderBot.finset_mem_Iio _ _
@[simp, norm_cast]
theorem coe_Iic (a : α) : (Iic a : Set α) = Set.Iic a :=
Set.ext fun _ => mem_Iic
@[simp, norm_cast]
theorem coe_Iio (a : α) : (Iio a : Set α) = Set.Iio a :=
Set.ext fun _ => mem_Iio
end LocallyFiniteOrderBot
section OrderTop
variable [LocallyFiniteOrder α] [OrderTop α] {a x : α}
-- See note [lower priority instance]
instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderTop :
LocallyFiniteOrderTop α where
finsetIci b := Icc b ⊤
finsetIoi b := Ioc b ⊤
finset_mem_Ici a x := by rw [mem_Icc, and_iff_left le_top]
finset_mem_Ioi a x := by rw [mem_Ioc, and_iff_left le_top]
theorem Ici_eq_Icc (a : α) : Ici a = Icc a ⊤ :=
rfl
theorem Ioi_eq_Ioc (a : α) : Ioi a = Ioc a ⊤ :=
rfl
end OrderTop
section OrderBot
variable [OrderBot α] [LocallyFiniteOrder α] {b x : α}
-- See note [lower priority instance]
instance (priority := 100) LocallyFiniteOrder.toLocallyFiniteOrderBot :
LocallyFiniteOrderBot α where
finsetIic := Icc ⊥
finsetIio := Ico ⊥
finset_mem_Iic a x := by rw [mem_Icc, and_iff_right bot_le]
finset_mem_Iio a x := by rw [mem_Ico, and_iff_right bot_le]
theorem Iic_eq_Icc : Iic = Icc (⊥ : α) :=
rfl
theorem Iio_eq_Ico : Iio = Ico (⊥ : α) :=
rfl
end OrderBot
end Preorder
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] {a b x : α}
/-- `Finset.uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.
Note that we define it more generally in a lattice as `Finset.Icc (a ⊓ b) (a ⊔ b)`. In a
product type, `Finset.uIcc` corresponds to the bounding box of the two elements. -/
def uIcc (a b : α) : Finset α :=
Icc (a ⊓ b) (a ⊔ b)
@[inherit_doc]
scoped[FinsetInterval] notation "[[" a ", " b "]]" => Finset.uIcc a b
@[simp]
theorem mem_uIcc : x ∈ uIcc a b ↔ a ⊓ b ≤ x ∧ x ≤ a ⊔ b :=
mem_Icc
@[simp, norm_cast]
theorem coe_uIcc (a b : α) : (Finset.uIcc a b : Set α) = Set.uIcc a b :=
coe_Icc _ _
end Lattice
end Finset
/-! ### Finiteness of `Set` intervals -/
namespace Set
section Preorder
variable [Preorder α] [LocallyFiniteOrder α] (a b : α)
instance fintypeIcc : Fintype (Icc a b) := Fintype.ofFinset (Finset.Icc a b) fun _ => Finset.mem_Icc
instance fintypeIco : Fintype (Ico a b) := Fintype.ofFinset (Finset.Ico a b) fun _ => Finset.mem_Ico
instance fintypeIoc : Fintype (Ioc a b) := Fintype.ofFinset (Finset.Ioc a b) fun _ => Finset.mem_Ioc
instance fintypeIoo : Fintype (Ioo a b) := Fintype.ofFinset (Finset.Ioo a b) fun _ => Finset.mem_Ioo
theorem finite_Icc : (Icc a b).Finite :=
(Icc a b).toFinite
theorem finite_Ico : (Ico a b).Finite :=
(Ico a b).toFinite
theorem finite_Ioc : (Ioc a b).Finite :=
(Ioc a b).toFinite
theorem finite_Ioo : (Ioo a b).Finite :=
(Ioo a b).toFinite
end Preorder
section OrderTop
variable [Preorder α] [LocallyFiniteOrderTop α] (a : α)
instance fintypeIci : Fintype (Ici a) := Fintype.ofFinset (Finset.Ici a) fun _ => Finset.mem_Ici
instance fintypeIoi : Fintype (Ioi a) := Fintype.ofFinset (Finset.Ioi a) fun _ => Finset.mem_Ioi
theorem finite_Ici : (Ici a).Finite :=
(Ici a).toFinite
theorem finite_Ioi : (Ioi a).Finite :=
(Ioi a).toFinite
end OrderTop
section OrderBot
variable [Preorder α] [LocallyFiniteOrderBot α] (b : α)
instance fintypeIic : Fintype (Iic b) := Fintype.ofFinset (Finset.Iic b) fun _ => Finset.mem_Iic
instance fintypeIio : Fintype (Iio b) := Fintype.ofFinset (Finset.Iio b) fun _ => Finset.mem_Iio
theorem finite_Iic : (Iic b).Finite :=
(Iic b).toFinite
theorem finite_Iio : (Iio b).Finite :=
(Iio b).toFinite
end OrderBot
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] (a b : α)
instance fintypeUIcc : Fintype (uIcc a b) :=
Fintype.ofFinset (Finset.uIcc a b) fun _ => Finset.mem_uIcc
@[simp]
theorem finite_interval : (uIcc a b).Finite := (uIcc _ _).toFinite
end Lattice
end Set
/-! ### Instances -/
open Finset
section Preorder
variable [Preorder α] [Preorder β]
/-- A noncomputable constructor from the finiteness of all closed intervals. -/
noncomputable def LocallyFiniteOrder.ofFiniteIcc (h : ∀ a b : α, (Set.Icc a b).Finite) :
LocallyFiniteOrder α :=
@LocallyFiniteOrder.ofIcc' α _ (Classical.decRel _) (fun a b => (h a b).toFinset) fun a b x => by
rw [Set.Finite.mem_toFinset, Set.mem_Icc]
/-- A fintype is a locally finite order.
This is not an instance as it would not be defeq to better instances such as
`Fin.locallyFiniteOrder`.
-/
abbrev Fintype.toLocallyFiniteOrder [Fintype α] [@DecidableRel α (· < ·)]
[@DecidableRel α (· ≤ ·)] : LocallyFiniteOrder α where
finsetIcc a b := (Set.Icc a b).toFinset
finsetIco a b := (Set.Ico a b).toFinset
finsetIoc a b := (Set.Ioc a b).toFinset
finsetIoo a b := (Set.Ioo a b).toFinset
finset_mem_Icc a b x := by simp only [Set.mem_toFinset, Set.mem_Icc]
finset_mem_Ico a b x := by simp only [Set.mem_toFinset, Set.mem_Ico]
finset_mem_Ioc a b x := by simp only [Set.mem_toFinset, Set.mem_Ioc]
finset_mem_Ioo a b x := by simp only [Set.mem_toFinset, Set.mem_Ioo]
instance : Subsingleton (LocallyFiniteOrder α) :=
Subsingleton.intro fun h₀ h₁ => by
cases' h₀ with h₀_finset_Icc h₀_finset_Ico h₀_finset_Ioc h₀_finset_Ioo
h₀_finset_mem_Icc h₀_finset_mem_Ico h₀_finset_mem_Ioc h₀_finset_mem_Ioo
cases' h₁ with h₁_finset_Icc h₁_finset_Ico h₁_finset_Ioc h₁_finset_Ioo
h₁_finset_mem_Icc h₁_finset_mem_Ico h₁_finset_mem_Ioc h₁_finset_mem_Ioo
have hIcc : h₀_finset_Icc = h₁_finset_Icc := by
ext a b x
rw [h₀_finset_mem_Icc, h₁_finset_mem_Icc]
have hIco : h₀_finset_Ico = h₁_finset_Ico := by
ext a b x
rw [h₀_finset_mem_Ico, h₁_finset_mem_Ico]
have hIoc : h₀_finset_Ioc = h₁_finset_Ioc := by
ext a b x
rw [h₀_finset_mem_Ioc, h₁_finset_mem_Ioc]
have hIoo : h₀_finset_Ioo = h₁_finset_Ioo := by
ext a b x
rw [h₀_finset_mem_Ioo, h₁_finset_mem_Ioo]
simp_rw [hIcc, hIco, hIoc, hIoo]
instance : Subsingleton (LocallyFiniteOrderTop α) :=
Subsingleton.intro fun h₀ h₁ => by
cases' h₀ with h₀_finset_Ioi h₀_finset_Ici h₀_finset_mem_Ici h₀_finset_mem_Ioi
cases' h₁ with h₁_finset_Ioi h₁_finset_Ici h₁_finset_mem_Ici h₁_finset_mem_Ioi
have hIci : h₀_finset_Ici = h₁_finset_Ici := by
ext a b
rw [h₀_finset_mem_Ici, h₁_finset_mem_Ici]
have hIoi : h₀_finset_Ioi = h₁_finset_Ioi := by
ext a b
rw [h₀_finset_mem_Ioi, h₁_finset_mem_Ioi]
simp_rw [hIci, hIoi]
instance : Subsingleton (LocallyFiniteOrderBot α) :=
Subsingleton.intro fun h₀ h₁ => by
cases' h₀ with h₀_finset_Iio h₀_finset_Iic h₀_finset_mem_Iic h₀_finset_mem_Iio
cases' h₁ with h₁_finset_Iio h₁_finset_Iic h₁_finset_mem_Iic h₁_finset_mem_Iio
have hIic : h₀_finset_Iic = h₁_finset_Iic := by
ext a b
rw [h₀_finset_mem_Iic, h₁_finset_mem_Iic]
have hIio : h₀_finset_Iio = h₁_finset_Iio := by
ext a b
rw [h₀_finset_mem_Iio, h₁_finset_mem_Iio]
simp_rw [hIic, hIio]
-- Should this be called `LocallyFiniteOrder.lift`?
/-- Given an order embedding `α ↪o β`, pulls back the `LocallyFiniteOrder` on `β` to `α`. -/
protected noncomputable def OrderEmbedding.locallyFiniteOrder [LocallyFiniteOrder β] (f : α ↪o β) :
LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIco a b := (Ico (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoc a b := (Ioc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoo a b := (Ioo (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finset_mem_Icc a b x := by rw [mem_preimage, mem_Icc, f.le_iff_le, f.le_iff_le]
finset_mem_Ico a b x := by rw [mem_preimage, mem_Ico, f.le_iff_le, f.lt_iff_lt]
finset_mem_Ioc a b x := by rw [mem_preimage, mem_Ioc, f.lt_iff_lt, f.le_iff_le]
finset_mem_Ioo a b x := by rw [mem_preimage, mem_Ioo, f.lt_iff_lt, f.lt_iff_lt]
open OrderDual
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : α)
/-- Note we define `Icc (toDual a) (toDual b)` as `Icc α _ _ b a` (which has type `Finset α` not
`Finset αᵒᵈ`!) instead of `(Icc b a).map toDual.toEmbedding` as this means the
following is defeq:
```
lemma this : (Icc (toDual (toDual a)) (toDual (toDual b)) : _) = (Icc a b : _) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrder : LocallyFiniteOrder αᵒᵈ where
finsetIcc a b := @Icc α _ _ (ofDual b) (ofDual a)
finsetIco a b := @Ioc α _ _ (ofDual b) (ofDual a)
finsetIoc a b := @Ico α _ _ (ofDual b) (ofDual a)
finsetIoo a b := @Ioo α _ _ (ofDual b) (ofDual a)
finset_mem_Icc _ _ _ := (mem_Icc (α := α)).trans and_comm
finset_mem_Ico _ _ _ := (mem_Ioc (α := α)).trans and_comm
finset_mem_Ioc _ _ _ := (mem_Ico (α := α)).trans and_comm
finset_mem_Ioo _ _ _ := (mem_Ioo (α := α)).trans and_comm
theorem Icc_toDual : Icc (toDual a) (toDual b) = (Icc b a).map toDual.toEmbedding := map_refl.symm
theorem Ico_toDual : Ico (toDual a) (toDual b) = (Ioc b a).map toDual.toEmbedding := map_refl.symm
theorem Ioc_toDual : Ioc (toDual a) (toDual b) = (Ico b a).map toDual.toEmbedding := map_refl.symm
theorem Ioo_toDual : Ioo (toDual a) (toDual b) = (Ioo b a).map toDual.toEmbedding := map_refl.symm
theorem Icc_ofDual (a b : αᵒᵈ) : Icc (ofDual a) (ofDual b) = (Icc b a).map ofDual.toEmbedding :=
map_refl.symm
theorem Ico_ofDual (a b : αᵒᵈ) : Ico (ofDual a) (ofDual b) = (Ioc b a).map ofDual.toEmbedding :=
map_refl.symm
theorem Ioc_ofDual (a b : αᵒᵈ) : Ioc (ofDual a) (ofDual b) = (Ico b a).map ofDual.toEmbedding :=
map_refl.symm
theorem Ioo_ofDual (a b : αᵒᵈ) : Ioo (ofDual a) (ofDual b) = (Ioo b a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
/-- Note we define `Iic (toDual a)` as `Ici a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Ici a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Iic (toDual (toDual a)) : _) = (Iic a : _) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderBot : LocallyFiniteOrderBot αᵒᵈ where
finsetIic a := @Ici α _ _ (ofDual a)
finsetIio a := @Ioi α _ _ (ofDual a)
finset_mem_Iic _ _ := mem_Ici (α := α)
finset_mem_Iio _ _ := mem_Ioi (α := α)
theorem Iic_toDual (a : α) : Iic (toDual a) = (Ici a).map toDual.toEmbedding :=
map_refl.symm
theorem Iio_toDual (a : α) : Iio (toDual a) = (Ioi a).map toDual.toEmbedding :=
map_refl.symm
theorem Ici_ofDual (a : αᵒᵈ) : Ici (ofDual a) = (Iic a).map ofDual.toEmbedding :=
map_refl.symm
theorem Ioi_ofDual (a : αᵒᵈ) : Ioi (ofDual a) = (Iio a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderBot α]
/-- Note we define `Ici (toDual a)` as `Iic a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Iic a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Ici (toDual (toDual a)) : _) = (Ici a : _) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderTop : LocallyFiniteOrderTop αᵒᵈ where
finsetIci a := @Iic α _ _ (ofDual a)
finsetIoi a := @Iio α _ _ (ofDual a)
finset_mem_Ici _ _ := mem_Iic (α := α)
finset_mem_Ioi _ _ := mem_Iio (α := α)
theorem Ici_toDual (a : α) : Ici (toDual a) = (Iic a).map toDual.toEmbedding :=
map_refl.symm
theorem Ioi_toDual (a : α) : Ioi (toDual a) = (Iio a).map toDual.toEmbedding :=
map_refl.symm
theorem Iic_ofDual (a : αᵒᵈ) : Iic (ofDual a) = (Ici a).map ofDual.toEmbedding :=
map_refl.symm
theorem Iio_ofDual (a : αᵒᵈ) : Iio (ofDual a) = (Ioi a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
namespace Prod
instance [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] : LocallyFiniteOrder (α × β) :=
LocallyFiniteOrder.ofIcc' (α × β) (fun a b => Icc a.fst b.fst ×ˢ Icc a.snd b.snd) fun a b x => by
rw [mem_product, mem_Icc, mem_Icc, and_and_and_comm, le_def, le_def]
instance [LocallyFiniteOrderTop α] [LocallyFiniteOrderTop β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] : LocallyFiniteOrderTop (α × β) :=
LocallyFiniteOrderTop.ofIci' (α × β) (fun a => Ici a.fst ×ˢ Ici a.snd) fun a x => by
rw [mem_product, mem_Ici, mem_Ici, le_def]
instance [LocallyFiniteOrderBot α] [LocallyFiniteOrderBot β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] : LocallyFiniteOrderBot (α × β) :=
LocallyFiniteOrderBot.ofIic' (α × β) (fun a => Iic a.fst ×ˢ Iic a.snd) fun a x => by
rw [mem_product, mem_Iic, mem_Iic, le_def]
theorem Icc_eq [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (p q : α × β) :
Finset.Icc p q = Finset.Icc p.1 q.1 ×ˢ Finset.Icc p.2 q.2 :=
rfl
@[simp]
theorem Icc_mk_mk [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (a₁ a₂ : α) (b₁ b₂ : β) :
Finset.Icc (a₁, b₁) (a₂, b₂) = Finset.Icc a₁ a₂ ×ˢ Finset.Icc b₁ b₂ :=
rfl
theorem card_Icc [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (p q : α × β) :
(Finset.Icc p q).card = (Finset.Icc p.1 q.1).card * (Finset.Icc p.2 q.2).card :=
Finset.card_product _ _
end Prod
end Preorder
namespace Prod
variable [Lattice α] [Lattice β]
theorem uIcc_eq [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (p q : α × β) :
Finset.uIcc p q = Finset.uIcc p.1 q.1 ×ˢ Finset.uIcc p.2 q.2 :=
rfl
@[simp]
theorem uIcc_mk_mk [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (a₁ a₂ : α) (b₁ b₂ : β) :
Finset.uIcc (a₁, b₁) (a₂, b₂) = Finset.uIcc a₁ a₂ ×ˢ Finset.uIcc b₁ b₂ :=
rfl
theorem card_uIcc [LocallyFiniteOrder α] [LocallyFiniteOrder β]
[DecidableRel ((· ≤ ·) : α × β → α × β → Prop)] (p q : α × β) :
(Finset.uIcc p q).card = (Finset.uIcc p.1 q.1).card * (Finset.uIcc p.2 q.2).card :=
Prod.card_Icc _ _
end Prod
/-!
#### `WithTop`, `WithBot`
Adding a `⊤` to a locally finite `OrderTop` keeps it locally finite.
Adding a `⊥` to a locally finite `OrderBot` keeps it locally finite.
-/
namespace WithTop
private lemma aux (x : α) (p : α → Prop) :
(∃ a : α, p a ∧ WithTop.some a = WithTop.some x) ↔ p x := by
simp
variable (α) [PartialOrder α] [OrderTop α] [LocallyFiniteOrder α]
instance locallyFiniteOrder : LocallyFiniteOrder (WithTop α) where
finsetIcc a b :=
match a, b with
| ⊤, ⊤ => {⊤}
| ⊤, (b : α) => ∅
| (a : α), ⊤ => insertNone (Ici a)
| (a : α), (b : α) => (Icc a b).map Embedding.some
finsetIco a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ici a).map Embedding.some
| (a : α), (b : α) => (Ico a b).map Embedding.some
finsetIoc a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => insertNone (Ioi a)
| (a : α), (b : α) => (Ioc a b).map Embedding.some
finsetIoo a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ioi a).map Embedding.some
| (a : α), (b : α) => (Ioo a b).map Embedding.some
-- Porting note: the proofs below got much worse
finset_mem_Icc a b x :=
match a, b, x with
| ⊤, ⊤, x => mem_singleton.trans (le_antisymm_iff.trans and_comm)
| ⊤, (b : α), x =>
iff_of_false (not_mem_empty _) fun h => (h.1.trans h.2).not_lt <| coe_lt_top _
| (a : α), ⊤, ⊤ => by simp [WithTop.some, WithTop.top, insertNone]
| (a : α), ⊤, (x : α) => by
simp only [le_eq_subset, coe_le_coe, le_top, and_true]
rw [← some_eq_coe, some_mem_insertNone, mem_Ici]
| (a : α), (b : α), ⊤ => by
simp only [Embedding.some, mem_map, mem_Icc, and_false, exists_const, some, le_top,
top_le_iff]
| (a : α), (b : α), (x : α) => by
simp only [le_eq_subset, Embedding.some, mem_map, mem_Icc, Embedding.coeFn_mk, coe_le_coe]
-- This used to be in the above `simp` before leanprover/lean4#2644
erw [aux]
finset_mem_Ico a b x :=
match a, b, x with
| ⊤, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans_lt h.2
| (a : α), ⊤, ⊤ => by simp [some, Embedding.some]
| (a : α), ⊤, (x : α) => by
simp only [Embedding.some, mem_map, mem_Ici, Embedding.coeFn_mk, coe_le_coe, aux,
coe_lt_top, and_true]
-- This used to be in the above `simp` before leanprover/lean4#2644
erw [aux]
| (a : α), (b : α), ⊤ => by simp [some, Embedding.some]
| (a : α), (b : α), (x : α) => by simp [some, Embedding.some, aux]
-- This used to be in the above `simp` before
-- leanprover/lean4#2644
erw [aux]
finset_mem_Ioc a b x :=
match a, b, x with
| ⊤, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans_le h.2
| (a : α), ⊤, ⊤ => by simp [some, insertNone, top]
| (a : α), ⊤, (x : α) => by simp [some, Embedding.some, insertNone, aux]
-- This used to be in the above `simp` before
-- leanprover/lean4#2644
erw [aux]
| (a : α), (b : α), ⊤ => by simp [some, Embedding.some, insertNone]
| (a : α), (b : α), (x : α) => by simp [some, Embedding.some, insertNone, aux]
-- This used to be in the above `simp` before
-- leanprover/lean4#2644
erw [aux]
finset_mem_Ioo a b x :=
match a, b, x with
| ⊤, b, x => iff_of_false (not_mem_empty _) fun h => not_top_lt <| h.1.trans h.2
| (a : α), ⊤, ⊤ => by simp [some, Embedding.some, insertNone]
| (a : α), ⊤, (x : α) => by simp [some, Embedding.some, insertNone, aux, top]
-- This used to be in the above `simp` before
-- leanprover/lean4#2644
erw [aux]
| (a : α), (b : α), ⊤ => by simp [some, Embedding.some, insertNone]
| (a : α), (b : α), (x : α) => by
simp [some, Embedding.some, insertNone, aux]
-- This used to be in the above `simp` before
-- leanprover/lean4#2644
erw [aux]
variable (a b : α)
theorem Icc_coe_top : Icc (a : WithTop α) ⊤ = insertNone (Ici a) :=
rfl
theorem Icc_coe_coe : Icc (a : WithTop α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_coe_top : Ico (a : WithTop α) ⊤ = (Ici a).map Embedding.some :=
rfl
theorem Ico_coe_coe : Ico (a : WithTop α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_coe_top : Ioc (a : WithTop α) ⊤ = insertNone (Ioi a) :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithTop α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_coe_top : Ioo (a : WithTop α) ⊤ = (Ioi a).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithTop α) b = (Ioo a b).map Embedding.some :=
rfl
end WithTop
namespace WithBot
variable (α) [PartialOrder α] [OrderBot α] [LocallyFiniteOrder α]
instance instLocallyFiniteOrder : LocallyFiniteOrder (WithBot α) :=
OrderDual.instLocallyFiniteOrder (α := WithTop αᵒᵈ)
variable (a b : α)
theorem Icc_bot_coe : Icc (⊥ : WithBot α) b = insertNone (Iic b) :=
rfl
theorem Icc_coe_coe : Icc (a : WithBot α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_bot_coe : Ico (⊥ : WithBot α) b = insertNone (Iio b) :=
rfl
theorem Ico_coe_coe : Ico (a : WithBot α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_bot_coe : Ioc (⊥ : WithBot α) b = (Iic b).map Embedding.some :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithBot α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_bot_coe : Ioo (⊥ : WithBot α) b = (Iio b).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithBot α) b = (Ioo a b).map Embedding.some :=
rfl
end WithBot
namespace OrderIso
variable [Preorder α] [Preorder β]
/-! #### Transfer locally finite orders across order isomorphisms -/
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrder` across an `OrderIso`. -/
abbrev locallyFiniteOrder [LocallyFiniteOrder β] (f : α ≃o β) : LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIco a b := (Ico (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoc a b := (Ioc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoo a b := (Ioo (f a) (f b)).map f.symm.toEquiv.toEmbedding
finset_mem_Icc := by simp
finset_mem_Ico := by simp
finset_mem_Ioc := by simp
finset_mem_Ioo := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderTop` across an `OrderIso`. -/
abbrev locallyFiniteOrderTop [LocallyFiniteOrderTop β] (f : α ≃o β) : LocallyFiniteOrderTop α where
finsetIci a := (Ici (f a)).map f.symm.toEquiv.toEmbedding
finsetIoi a := (Ioi (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Ici := by simp
finset_mem_Ioi := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderBot` across an `OrderIso`. -/
abbrev locallyFiniteOrderBot [LocallyFiniteOrderBot β] (f : α ≃o β) : LocallyFiniteOrderBot α where
finsetIic a := (Iic (f a)).map f.symm.toEquiv.toEmbedding
finsetIio a := (Iio (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Iic := by simp
finset_mem_Iio := by simp
end OrderIso
/-! #### Subtype of a locally finite order -/
variable [Preorder α] (p : α → Prop) [DecidablePred p]
instance Subtype.instLocallyFiniteOrder [LocallyFiniteOrder α] :
LocallyFiniteOrder (Subtype p) where
finsetIcc a b := (Icc (a : α) b).subtype p
finsetIco a b := (Ico (a : α) b).subtype p
finsetIoc a b := (Ioc (a : α) b).subtype p
finsetIoo a b := (Ioo (a : α) b).subtype p
finset_mem_Icc a b x := by simp_rw [Finset.mem_subtype, mem_Icc, Subtype.coe_le_coe]
finset_mem_Ico a b x := by
simp_rw [Finset.mem_subtype, mem_Ico, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioc a b x := by
simp_rw [Finset.mem_subtype, mem_Ioc, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioo a b x := by simp_rw [Finset.mem_subtype, mem_Ioo, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderTop [LocallyFiniteOrderTop α] :
LocallyFiniteOrderTop (Subtype p) where
finsetIci a := (Ici (a : α)).subtype p
finsetIoi a := (Ioi (a : α)).subtype p
finset_mem_Ici a x := by simp_rw [Finset.mem_subtype, mem_Ici, Subtype.coe_le_coe]
finset_mem_Ioi a x := by simp_rw [Finset.mem_subtype, mem_Ioi, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderBot [LocallyFiniteOrderBot α] :
LocallyFiniteOrderBot (Subtype p) where
finsetIic a := (Iic (a : α)).subtype p
finsetIio a := (Iio (a : α)).subtype p
finset_mem_Iic a x := by simp_rw [Finset.mem_subtype, mem_Iic, Subtype.coe_le_coe]
finset_mem_Iio a x := by simp_rw [Finset.mem_subtype, mem_Iio, Subtype.coe_lt_coe]
namespace Finset
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : Subtype p)
theorem subtype_Icc_eq : Icc a b = (Icc (a : α) b).subtype p :=
rfl
theorem subtype_Ico_eq : Ico a b = (Ico (a : α) b).subtype p :=
rfl
theorem subtype_Ioc_eq : Ioc a b = (Ioc (a : α) b).subtype p :=
rfl
theorem subtype_Ioo_eq : Ioo a b = (Ioo (a : α) b).subtype p :=
rfl
theorem map_subtype_embedding_Icc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Icc a b).map (Embedding.subtype p) = (Icc a b : Finset α) := by
rw [subtype_Icc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Icc] at hx
exact hp hx.1 hx.2 a.prop b.prop
theorem map_subtype_embedding_Ico (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ico a b).map (Embedding.subtype p) = (Ico a b : Finset α) := by
rw [subtype_Ico_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ico] at hx
exact hp hx.1 hx.2.le a.prop b.prop
theorem map_subtype_embedding_Ioc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ioc a b).map (Embedding.subtype p) = (Ioc a b : Finset α) := by
rw [subtype_Ioc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioc] at hx
exact hp hx.1.le hx.2 a.prop b.prop
theorem map_subtype_embedding_Ioo (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ioo a b).map (Embedding.subtype p) = (Ioo a b : Finset α) := by
rw [subtype_Ioo_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioo] at hx
exact hp hx.1.le hx.2.le a.prop b.prop
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] (a : Subtype p)
theorem subtype_Ici_eq : Ici a = (Ici (a : α)).subtype p :=
rfl
theorem subtype_Ioi_eq : Ioi a = (Ioi (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Ici (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ici a).map (Embedding.subtype p) = (Ici a : Finset α) := by
rw [subtype_Ici_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ici.1 hx) a.prop
theorem map_subtype_embedding_Ioi (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ioi a).map (Embedding.subtype p) = (Ioi a : Finset α) := by
rw [subtype_Ioi_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ioi.1 hx).le a.prop
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] (a : Subtype p)
theorem subtype_Iic_eq : Iic a = (Iic (a : α)).subtype p :=
rfl
theorem subtype_Iio_eq : Iio a = (Iio (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Iic (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iic a).map (Embedding.subtype p) = (Iic a : Finset α) := by
rw [subtype_Iic_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iic.1 hx) a.prop
theorem map_subtype_embedding_Iio (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iio a).map (Embedding.subtype p) = (Iio a : Finset α) := by
rw [subtype_Iio_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iio.1 hx).le a.prop
end LocallyFiniteOrderBot
end Finset
section Finite
variable {α : Type*} {s : Set α}
theorem BddBelow.finite_of_bddAbove [Preorder α] [LocallyFiniteOrder α]
{s : Set α} (h₀ : BddBelow s) (h₁ : BddAbove s) :
s.Finite :=
let ⟨a, ha⟩ := h₀
let ⟨b, hb⟩ := h₁
(Set.finite_Icc a b).subset fun _x hx ↦ ⟨ha hx, hb hx⟩
theorem Set.finite_iff_bddAbove [SemilatticeSup α] [LocallyFiniteOrder α] [OrderBot α] :
s.Finite ↔ BddAbove s :=
⟨fun h ↦ ⟨h.toFinset.sup id, fun _ hx ↦ Finset.le_sup (f := id) ((Finite.mem_toFinset h).mpr hx)⟩,
fun ⟨m, hm⟩ ↦ (Set.finite_Icc ⊥ m).subset (fun _ hx ↦ ⟨bot_le, hm hx⟩)⟩
theorem Set.finite_iff_bddBelow [SemilatticeInf α] [LocallyFiniteOrder α] [OrderTop α] :
s.Finite ↔ BddBelow s :=
finite_iff_bddAbove (α := αᵒᵈ)
theorem Set.finite_iff_bddBelow_bddAbove [Nonempty α] [Lattice α] [LocallyFiniteOrder α] :
s.Finite ↔ BddBelow s ∧ BddAbove s := by
obtain (rfl | hs) := s.eq_empty_or_nonempty
· simp only [Set.finite_empty, bddBelow_empty, bddAbove_empty, and_self]
exact ⟨fun h ↦ ⟨⟨h.toFinset.inf' ((Finite.toFinset_nonempty h).mpr hs) id,
fun x hx ↦ Finset.inf'_le id ((Finite.mem_toFinset h).mpr hx)⟩,
⟨h.toFinset.sup' ((Finite.toFinset_nonempty h).mpr hs) id, fun x hx ↦ Finset.le_sup' id
((Finite.mem_toFinset h).mpr hx)⟩⟩,
fun ⟨h₀, h₁⟩ ↦ BddBelow.finite_of_bddAbove h₀ h₁⟩
end Finite
/-! We make the instances below low priority
so when alternative constructions are available they are preferred. -/
variable {y : α}
instance (priority := low) [Preorder α] [DecidableRel ((· : α) ≤ ·)] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x ≤ y } where
finsetIoi a := Finset.Ioc a ⟨y, by rfl⟩
finsetIci a := Finset.Icc a ⟨y, by rfl⟩
finset_mem_Ici a b := by
simp only [Finset.mem_Icc, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_Ioc, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableRel ((· : α) < ·)] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x < y } where
finsetIoi a := (Finset.Ioo ↑a y).subtype _
finsetIci a := (Finset.Ico ↑a y).subtype _
finset_mem_Ici a b := by
simp only [Finset.mem_subtype, Finset.mem_Ico, Subtype.coe_le_coe, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableRel ((· : α) ≤ ·)] [LocallyFiniteOrder α] :
LocallyFiniteOrderBot { x : α // y ≤ x } where
finsetIio a := Finset.Ico ⟨y, by rfl⟩ a
finsetIic a := Finset.Icc ⟨y, by rfl⟩ a
finset_mem_Iic a b := by
simp only [Finset.mem_Icc, and_iff_right_iff_imp]
exact fun _ => b.property
finset_mem_Iio a b := by
simp only [Finset.mem_Ico, and_iff_right_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableRel ((· : α) < ·)] [LocallyFiniteOrder α] :
LocallyFiniteOrderBot { x : α // y < x } where
finsetIio a := (Finset.Ioo y ↑a).subtype _
finsetIic a := (Finset.Ioc y ↑a).subtype _
finset_mem_Iic a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioc, Subtype.coe_le_coe, and_iff_right_iff_imp]
exact fun _ => b.property
finset_mem_Iio a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_right_iff_imp]
exact fun _ => b.property
instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x ≤ y } := by
simpa only [coe_Iic] using (Finset.Iic y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x < y } := by
simpa only [coe_Iio] using (Finset.Iio y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y ≤ x } := by
simpa only [coe_Ici] using (Finset.Ici y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y < x } := by
simpa only [coe_Ioi] using (Finset.Ioi y).finite_toSet
namespace Set
variable {α : Type*} [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α]
@[simp] lemma toFinset_Icc (a b : α) [Fintype (Icc a b)] : (Icc a b).toFinset = Finset.Icc a b := by
ext; simp
@[simp] lemma toFinset_Ico (a b : α) [Fintype (Ico a b)] : (Ico a b).toFinset = Finset.Ico a b := by
ext; simp
@[simp] lemma toFinset_Ioc (a b : α) [Fintype (Ioc a b)] : (Ioc a b).toFinset = Finset.Ioc a b := by
ext; simp
@[simp] lemma toFinset_Ioo (a b : α) [Fintype (Ioo a b)] : (Ioo a b).toFinset = Finset.Ioo a b := by
ext; simp
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
@[simp]
lemma toFinset_Ici (a : α) [Fintype (Ici a)] : (Ici a).toFinset = Finset.Ici a := by ext; simp
@[simp]
lemma toFinset_Ioi (a : α) [Fintype (Ioi a)] : (Ioi a).toFinset = Finset.Ioi a := by ext; simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α]
@[simp]
lemma toFinset_Iic (a : α) [Fintype (Iic a)] : (Iic a).toFinset = Finset.Iic a := by ext; simp
@[simp]
lemma toFinset_Iio (a : α) [Fintype (Iio a)] : (Iio a).toFinset = Finset.Iio a := by ext; simp
end LocallyFiniteOrderBot
end Set
|
Order\Interval\Finset\Fin.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Interval.Finset.Nat
/-!
# Finite intervals in `Fin n`
This file proves that `Fin n` is a `LocallyFiniteOrder` and calculates the cardinality of its
intervals as Finsets and Fintypes.
-/
assert_not_exists MonoidWithZero
namespace Fin
variable {n : ℕ} (a b : Fin n)
@[simp, norm_cast]
theorem coe_sup : ↑(a ⊔ b) = (a ⊔ b : ℕ) := rfl
@[simp, norm_cast]
theorem coe_inf : ↑(a ⊓ b) = (a ⊓ b : ℕ) := rfl
@[simp, norm_cast]
theorem coe_max : ↑(max a b) = (max a b : ℕ) := rfl
@[simp, norm_cast]
theorem coe_min : ↑(min a b) = (min a b : ℕ) := rfl
end Fin
open Finset Fin Function
namespace Fin
variable (n : ℕ)
instance instLocallyFiniteOrder : LocallyFiniteOrder (Fin n) :=
OrderIso.locallyFiniteOrder Fin.orderIsoSubtype
instance instLocallyFiniteOrderBot : LocallyFiniteOrderBot (Fin n) :=
OrderIso.locallyFiniteOrderBot Fin.orderIsoSubtype
instance instLocallyFiniteOrderTop : ∀ n, LocallyFiniteOrderTop (Fin n)
| 0 => IsEmpty.toLocallyFiniteOrderTop
| _ + 1 => inferInstance
variable {n} (a b : Fin n)
theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).fin n :=
rfl
theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).fin n :=
rfl
theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).fin n :=
rfl
theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).fin n :=
rfl
theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).fin n := rfl
@[simp]
theorem map_valEmbedding_Icc : (Icc a b).map Fin.valEmbedding = Icc ↑a ↑b := by
simp [Icc_eq_finset_subtype, Finset.fin, Finset.map_map, Icc_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Ico : (Ico a b).map Fin.valEmbedding = Ico ↑a ↑b := by
simp [Ico_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem map_valEmbedding_Ioc : (Ioc a b).map Fin.valEmbedding = Ioc ↑a ↑b := by
simp [Ioc_eq_finset_subtype, Finset.fin, Finset.map_map, Ioc_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Ioo : (Ioo a b).map Fin.valEmbedding = Ioo ↑a ↑b := by
simp [Ioo_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem map_subtype_embedding_uIcc : (uIcc a b).map valEmbedding = uIcc ↑a ↑b :=
map_valEmbedding_Icc _ _
@[simp]
theorem card_Icc : (Icc a b).card = b + 1 - a := by
rw [← Nat.card_Icc, ← map_valEmbedding_Icc, card_map]
@[simp]
theorem card_Ico : (Ico a b).card = b - a := by
rw [← Nat.card_Ico, ← map_valEmbedding_Ico, card_map]
@[simp]
theorem card_Ioc : (Ioc a b).card = b - a := by
rw [← Nat.card_Ioc, ← map_valEmbedding_Ioc, card_map]
@[simp]
theorem card_Ioo : (Ioo a b).card = b - a - 1 := by
rw [← Nat.card_Ioo, ← map_valEmbedding_Ioo, card_map]
@[simp]
theorem card_uIcc : (uIcc a b).card = (b - a : ℤ).natAbs + 1 := by
rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by
rw [← card_Icc, Fintype.card_ofFinset]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by
rw [← card_Ico, Fintype.card_ofFinset]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by
rw [← card_Ioc, Fintype.card_ofFinset]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by
rw [← card_Ioo, Fintype.card_ofFinset]
theorem card_fintype_uIcc : Fintype.card (Set.uIcc a b) = (b - a : ℤ).natAbs + 1 := by
rw [← card_uIcc, Fintype.card_ofFinset]
theorem Ici_eq_finset_subtype : Ici a = (Icc (a : ℕ) n).fin n := by
ext
simp
theorem Ioi_eq_finset_subtype : Ioi a = (Ioc (a : ℕ) n).fin n := by
ext
simp
theorem Iic_eq_finset_subtype : Iic b = (Iic (b : ℕ)).fin n :=
rfl
theorem Iio_eq_finset_subtype : Iio b = (Iio (b : ℕ)).fin n :=
rfl
@[simp]
theorem map_valEmbedding_Ici : (Ici a).map Fin.valEmbedding = Icc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
clear b
ext x
simp only [exists_prop, Embedding.coe_subtype, mem_Ici, mem_map, mem_Icc]
constructor
· rintro ⟨x, hx, rfl⟩
exact ⟨hx, Nat.le_sub_of_add_le <| x.2⟩
cases n
· exact Fin.elim0 a
· exact fun hx => ⟨⟨x, Nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩
@[simp]
theorem map_valEmbedding_Ioi : (Ioi a).map Fin.valEmbedding = Ioc ↑a (n - 1) := by
-- Porting note: without `clear b` Lean includes `b` in the statement (because the `rfl`) in the
-- `rintro` below acts on it.
clear b
ext x
simp only [exists_prop, Embedding.coe_subtype, mem_Ioi, mem_map, mem_Ioc]
constructor
· rintro ⟨x, hx, rfl⟩
exact ⟨hx, Nat.le_sub_of_add_le <| x.2⟩
cases n
· exact Fin.elim0 a
· exact fun hx => ⟨⟨x, Nat.lt_succ_iff.2 hx.2⟩, hx.1, rfl⟩
@[simp]
theorem map_valEmbedding_Iic : (Iic b).map Fin.valEmbedding = Iic ↑b := by
simp [Iic_eq_finset_subtype, Finset.fin, Finset.map_map, Iic_filter_lt_of_lt_right]
@[simp]
theorem map_valEmbedding_Iio : (Iio b).map Fin.valEmbedding = Iio ↑b := by
simp [Iio_eq_finset_subtype, Finset.fin, Finset.map_map]
@[simp]
theorem card_Ici : (Ici a).card = n - a := by
-- Porting note: without `clear b` Lean includes `b` in the statement.
clear b
cases n with
| zero => exact Fin.elim0 a
| succ =>
rw [← card_map, map_valEmbedding_Ici, Nat.card_Icc, Nat.add_one_sub_one]
@[simp]
theorem card_Ioi : (Ioi a).card = n - 1 - a := by
rw [← card_map, map_valEmbedding_Ioi, Nat.card_Ioc]
@[simp]
theorem card_Iic : (Iic b).card = b + 1 := by
rw [← Nat.card_Iic b, ← map_valEmbedding_Iic, card_map]
@[simp]
theorem card_Iio : (Iio b).card = b := by
rw [← Nat.card_Iio b, ← map_valEmbedding_Iio, card_map]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIci : Fintype.card (Set.Ici a) = n - a := by
rw [Fintype.card_ofFinset, card_Ici]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIoi : Fintype.card (Set.Ioi a) = n - 1 - a := by
rw [Fintype.card_ofFinset, card_Ioi]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by
rw [Fintype.card_ofFinset, card_Iic]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIio : Fintype.card (Set.Iio b) = b := by
rw [Fintype.card_ofFinset, card_Iio]
end Fin
|
Order\Interval\Finset\Nat.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Interval.Multiset
/-!
# Finite intervals of naturals
This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its
intervals as finsets and fintypes.
## TODO
Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedCommMonoid` or `SuccOrder`
and subsequently be moved upstream to `Order.Interval.Finset`.
-/
-- TODO
-- assert_not_exists Ring
open Finset Nat
variable (a b c : ℕ)
namespace Nat
instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where
finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range' _ _⟩
finsetIco a b := ⟨List.range' a (b - a), List.nodup_range' _ _⟩
finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range' _ _⟩
finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range' _ _⟩
finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega
finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega
finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega
finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega
theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range' _ _⟩ :=
rfl
theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range' _ _⟩ :=
rfl
theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range' _ _⟩ :=
rfl
theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range' _ _⟩ :=
rfl
theorem uIcc_eq_range' :
uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range' _ _⟩ := rfl
theorem Iio_eq_range : Iio = range := by
ext b x
rw [mem_Iio, mem_range]
@[simp]
theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range]
lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by
ext b
simp_all only [mem_Icc, zero_le, true_and, mem_range]
exact lt_iff_le_pred (zero_lt_of_ne_zero hn)
theorem _root_.Finset.range_eq_Ico : range = Ico 0 :=
Ico_zero_eq_range.symm
@[simp]
theorem card_Icc : (Icc a b).card = b + 1 - a :=
List.length_range' _ _ _
@[simp]
theorem card_Ico : (Ico a b).card = b - a :=
List.length_range' _ _ _
@[simp]
theorem card_Ioc : (Ioc a b).card = b - a :=
List.length_range' _ _ _
@[simp]
theorem card_Ioo : (Ioo a b).card = b - a - 1 :=
List.length_range' _ _ _
@[simp]
theorem card_uIcc : (uIcc a b).card = (b - a : ℤ).natAbs + 1 :=
(card_Icc _ _).trans $ by rw [← Int.natCast_inj, sup_eq_max, inf_eq_min, Int.ofNat_sub] <;> omega
@[simp]
lemma card_Iic : (Iic b).card = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero]
@[simp]
theorem card_Iio : (Iio b).card = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by
rw [Fintype.card_ofFinset, card_Icc]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by
rw [Fintype.card_ofFinset, card_Ico]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by
rw [Fintype.card_ofFinset, card_Ioc]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by
rw [Fintype.card_ofFinset, card_Ioo]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by
rw [Fintype.card_ofFinset, card_Iic]
-- Porting note (#10618): simp can prove this
-- @[simp]
theorem card_fintypeIio : Fintype.card (Set.Iio b) = b := by rw [Fintype.card_ofFinset, card_Iio]
-- TODO@Yaël: Generalize all the following lemmas to `SuccOrder`
theorem Icc_succ_left : Icc a.succ b = Ioc a b := by
ext x
rw [mem_Icc, mem_Ioc, succ_le_iff]
theorem Ico_succ_right : Ico a b.succ = Icc a b := by
ext x
rw [mem_Ico, mem_Icc, Nat.lt_succ_iff]
theorem Ico_succ_left : Ico a.succ b = Ioo a b := by
ext x
rw [mem_Ico, mem_Ioo, succ_le_iff]
theorem Icc_pred_right {b : ℕ} (h : 0 < b) : Icc a (b - 1) = Ico a b := by
ext x
rw [mem_Icc, mem_Ico, lt_iff_le_pred h]
theorem Ico_succ_succ : Ico a.succ b.succ = Ioc a b := by
ext x
rw [mem_Ico, mem_Ioc, succ_le_iff, Nat.lt_succ_iff]
@[simp]
theorem Ico_succ_singleton : Ico a (a + 1) = {a} := by rw [Ico_succ_right, Icc_self]
@[simp]
theorem Ico_pred_singleton {a : ℕ} (h : 0 < a) : Ico (a - 1) a = {a - 1} := by
rw [← Icc_pred_right _ h, Icc_self]
@[simp]
theorem Ioc_succ_singleton : Ioc b (b + 1) = {b + 1} := by rw [← Nat.Icc_succ_left, Icc_self]
variable {a b c}
theorem Ico_succ_right_eq_insert_Ico (h : a ≤ b) : Ico a (b + 1) = insert b (Ico a b) := by
rw [Ico_succ_right, ← Ico_insert_right h]
theorem Ico_insert_succ_left (h : a < b) : insert a (Ico a.succ b) = Ico a b := by
rw [Ico_succ_left, ← Ioo_insert_left h]
lemma Icc_insert_succ_left (h : a ≤ b) : insert a (Icc (a + 1) b) = Icc a b := by
ext x
simp only [mem_insert, mem_Icc]
omega
lemma Icc_insert_succ_right (h : a ≤ b + 1) : insert (b + 1) (Icc a b) = Icc a (b + 1) := by
ext x
simp only [mem_insert, mem_Icc]
omega
theorem image_sub_const_Ico (h : c ≤ a) :
((Ico a b).image fun x => x - c) = Ico (a - c) (b - c) := by
ext x
simp_rw [mem_image, mem_Ico]
refine ⟨?_, fun h ↦ ⟨x + c, by omega⟩⟩
rintro ⟨x, hx, rfl⟩
omega
theorem Ico_image_const_sub_eq_Ico (hac : a ≤ c) :
((Ico a b).image fun x => c - x) = Ico (c + 1 - b) (c + 1 - a) := by
ext x
simp_rw [mem_image, mem_Ico]
refine ⟨?_, fun h ↦ ⟨c - x, by omega⟩⟩
rintro ⟨x, hx, rfl⟩
omega
theorem Ico_succ_left_eq_erase_Ico : Ico a.succ b = erase (Ico a b) a := by
ext x
rw [Ico_succ_left, mem_erase, mem_Ico, mem_Ioo, ← and_assoc, ne_comm, @and_comm (a ≠ x),
lt_iff_le_and_ne]
theorem mod_injOn_Ico (n a : ℕ) : Set.InjOn (· % a) (Finset.Ico n (n + a)) := by
induction' n with n ih
· simp only [zero_add, Nat.zero_eq, Ico_zero_eq_range]
rintro k hk l hl (hkl : k % a = l % a)
simp only [Finset.mem_range, Finset.mem_coe] at hk hl
rwa [mod_eq_of_lt hk, mod_eq_of_lt hl] at hkl
rw [Ico_succ_left_eq_erase_Ico, succ_add, succ_eq_add_one,
Ico_succ_right_eq_insert_Ico (by omega)]
rintro k hk l hl (hkl : k % a = l % a)
have ha : 0 < a := Nat.pos_iff_ne_zero.2 $ by rintro rfl; simp at hk
simp only [Finset.mem_coe, Finset.mem_insert, Finset.mem_erase] at hk hl
rcases hk with ⟨hkn, rfl | hk⟩ <;> rcases hl with ⟨hln, rfl | hl⟩
· rfl
· rw [add_mod_right] at hkl
refine (hln <| ih hl ?_ hkl.symm).elim
simpa using Nat.lt_add_of_pos_right (n := n) ha
· rw [add_mod_right] at hkl
suffices k = n by contradiction
refine ih hk ?_ hkl
simpa using Nat.lt_add_of_pos_right (n := n) ha
· refine ih ?_ ?_ hkl <;> simp only [Finset.mem_coe, hk, hl]
/-- Note that while this lemma cannot be easily generalized to a type class, it holds for ℤ as
well. See `Int.image_Ico_emod` for the ℤ version. -/
theorem image_Ico_mod (n a : ℕ) : (Ico n (n + a)).image (· % a) = range a := by
obtain rfl | ha := eq_or_ne a 0
· rw [range_zero, add_zero, Ico_self, image_empty]
ext i
simp only [mem_image, exists_prop, mem_range, mem_Ico]
constructor
· rintro ⟨i, _, rfl⟩
exact mod_lt i ha.bot_lt
intro hia
have hn := Nat.mod_add_div n a
obtain hi | hi := lt_or_le i (n % a)
· refine ⟨i + a * (n / a + 1), ⟨?_, ?_⟩, ?_⟩
· rw [add_comm (n / a), Nat.mul_add, mul_one, ← add_assoc]
refine hn.symm.le.trans (Nat.add_le_add_right ?_ _)
simpa only [zero_add] using add_le_add (zero_le i) (Nat.mod_lt n ha.bot_lt).le
· refine lt_of_lt_of_le (Nat.add_lt_add_right hi (a * (n / a + 1))) ?_
rw [Nat.mul_add, mul_one, ← add_assoc, hn]
· rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia]
· refine ⟨i + a * (n / a), ⟨?_, ?_⟩, ?_⟩
· omega
· omega
· rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hia]
section Multiset
open Multiset
theorem multiset_Ico_map_mod (n a : ℕ) :
(Multiset.Ico n (n + a)).map (· % a) = Multiset.range a := by
convert congr_arg Finset.val (image_Ico_mod n a)
refine ((nodup_map_iff_inj_on (Finset.Ico _ _).nodup).2 <| ?_).dedup.symm
exact mod_injOn_Ico _ _
end Multiset
end Nat
namespace Finset
theorem range_image_pred_top_sub (n : ℕ) :
((Finset.range n).image fun j => n - 1 - j) = Finset.range n := by
cases n
· rw [range_zero, image_empty]
· rw [Finset.range_eq_Ico, Nat.Ico_image_const_sub_eq_Ico (Nat.zero_le _)]
simp_rw [succ_sub_succ, Nat.sub_zero, Nat.sub_self]
theorem range_add_eq_union : range (a + b) = range a ∪ (range b).map (addLeftEmbedding a) := by
rw [Finset.range_eq_Ico, map_eq_image]
convert (Ico_union_Ico_eq_Ico a.zero_le (a.le_add_right b)).symm
ext x
simp only [Ico_zero_eq_range, mem_image, mem_range, addLeftEmbedding_apply, mem_Ico]
constructor
· aesop
· rintro h
exact ⟨x - a, by omega⟩
end Finset
section Induction
variable {P : ℕ → Prop}
theorem Nat.decreasing_induction_of_not_bddAbove (h : ∀ n, P (n + 1) → P n)
(hP : ¬BddAbove { x | P x }) (n : ℕ) : P n :=
let ⟨_, hm, hl⟩ := not_bddAbove_iff.1 hP n
decreasingInduction (fun _ _ => h _) hm hl.le
@[elab_as_elim]
lemma Nat.strong_decreasing_induction (base : ∃ n, ∀ m > n, P m) (step : ∀ n, (∀ m > n, P m) → P n)
(n : ℕ) : P n := by
apply Nat.decreasing_induction_of_not_bddAbove (P := fun n ↦ ∀ m ≥ n, P m) _ _ n n le_rfl
· intro n ih m hm
rcases hm.eq_or_lt with rfl | hm
· exact step n ih
· exact ih m hm
· rintro ⟨b, hb⟩
rcases base with ⟨n, hn⟩
specialize @hb (n + b + 1) (fun m hm ↦ hn _ _)
all_goals omega
theorem Nat.decreasing_induction_of_infinite
(h : ∀ n, P (n + 1) → P n) (hP : { x | P x }.Infinite) (n : ℕ) : P n :=
Nat.decreasing_induction_of_not_bddAbove h (mt BddAbove.finite hP) n
theorem Nat.cauchy_induction' (seed : ℕ) (h : ∀ n, P (n + 1) → P n) (hs : P seed)
(hi : ∀ x, seed ≤ x → P x → ∃ y, x < y ∧ P y) (n : ℕ) : P n := by
apply Nat.decreasing_induction_of_infinite h fun hf => _
intro hf
obtain ⟨m, hP, hm⟩ := hf.exists_maximal_wrt id _ ⟨seed, hs⟩
obtain ⟨y, hl, hy⟩ := hi m (le_of_not_lt fun hl => hl.ne <| hm seed hs hl.le) hP
exact hl.ne (hm y hy hl.le)
theorem Nat.cauchy_induction (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed) (f : ℕ → ℕ)
(hf : ∀ x, seed ≤ x → P x → x < f x ∧ P (f x)) (n : ℕ) : P n :=
seed.cauchy_induction' h hs (fun x hl hx => ⟨f x, hf x hl hx⟩) n
theorem Nat.cauchy_induction_mul (h : ∀ (n : ℕ), P (n + 1) → P n) (k seed : ℕ) (hk : 1 < k)
(hs : P seed.succ) (hm : ∀ x, seed < x → P x → P (k * x)) (n : ℕ) : P n := by
apply Nat.cauchy_induction h _ hs (k * ·) fun x hl hP => ⟨_, hm x hl hP⟩
intro _ hl _
convert (Nat.mul_lt_mul_right <| seed.succ_pos.trans_le hl).2 hk
rw [one_mul]
theorem Nat.cauchy_induction_two_mul (h : ∀ n, P (n + 1) → P n) (seed : ℕ) (hs : P seed.succ)
(hm : ∀ x, seed < x → P x → P (2 * x)) (n : ℕ) : P n :=
Nat.cauchy_induction_mul h 2 seed Nat.one_lt_two hs hm n
theorem Nat.pow_imp_self_of_one_lt {M} [Monoid M] (k : ℕ) (hk : 1 < k)
(P : M → Prop) (hmul : ∀ x y, P x → P (x * y) ∨ P (y * x))
(hpow : ∀ x, P (x ^ k) → P x) : ∀ n x, P (x ^ n) → P x :=
k.cauchy_induction_mul (fun n ih x hx ↦ ih x <| (hmul _ x hx).elim
(fun h ↦ by rwa [_root_.pow_succ]) fun h ↦ by rwa [_root_.pow_succ']) 0 hk
(fun x hx ↦ pow_one x ▸ hx) fun n _ hn x hx ↦ hpow x <| hn _ <| (pow_mul x k n).subst hx
end Induction
|
Order\Interval\Set\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne
-/
import Mathlib.Order.MinMax
import Mathlib.Data.Set.Subsingleton
import Mathlib.Tactic.Says
/-!
# Intervals
In any preorder `α`, we define intervals (which on each side can be either infinite, open, or
closed) using the following naming conventions:
- `i`: infinite
- `o`: open
- `c`: closed
Each interval has the name `I` + letter for left side + letter for right side. For instance,
`Ioc a b` denotes the interval `(a, b]`.
This file contains these definitions, and basic facts on inclusion, intersection, difference of
intervals (where the precise statements may depend on the properties of the order, in particular
for some statements it should be `LinearOrder` or `DenselyOrdered`).
TODO: This is just the beginning; a lot of rules are missing
-/
open Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
namespace Set
section Preorder
variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α}
/-- Left-open right-open interval -/
def Ioo (a b : α) :=
{ x | a < x ∧ x < b }
/-- Left-closed right-open interval -/
def Ico (a b : α) :=
{ x | a ≤ x ∧ x < b }
/-- Left-infinite right-open interval -/
def Iio (a : α) :=
{ x | x < a }
/-- Left-closed right-closed interval -/
def Icc (a b : α) :=
{ x | a ≤ x ∧ x ≤ b }
/-- Left-infinite right-closed interval -/
def Iic (b : α) :=
{ x | x ≤ b }
/-- Left-open right-closed interval -/
def Ioc (a b : α) :=
{ x | a < x ∧ x ≤ b }
/-- Left-closed right-infinite interval -/
def Ici (a : α) :=
{ x | a ≤ x }
/-- Left-open right-infinite interval -/
def Ioi (a : α) :=
{ x | a < x }
theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b :=
rfl
theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b :=
rfl
theorem Iio_def (a : α) : { x | x < a } = Iio a :=
rfl
theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b :=
rfl
theorem Iic_def (b : α) : { x | x ≤ b } = Iic b :=
rfl
theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b :=
rfl
theorem Ici_def (a : α) : { x | a ≤ x } = Ici a :=
rfl
theorem Ioi_def (a : α) : { x | a < x } = Ioi a :=
rfl
@[simp]
theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b :=
Iff.rfl
@[simp]
theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b :=
Iff.rfl
@[simp]
theorem mem_Iio : x ∈ Iio b ↔ x < b :=
Iff.rfl
@[simp]
theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b :=
Iff.rfl
@[simp]
theorem mem_Iic : x ∈ Iic b ↔ x ≤ b :=
Iff.rfl
@[simp]
theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b :=
Iff.rfl
@[simp]
theorem mem_Ici : x ∈ Ici a ↔ a ≤ x :=
Iff.rfl
@[simp]
theorem mem_Ioi : x ∈ Ioi a ↔ a < x :=
Iff.rfl
instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption
instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption
instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption
instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption
instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption
instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption
instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption
instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl]
theorem left_mem_Ici : a ∈ Ici a := by simp
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl]
theorem right_mem_Iic : a ∈ Iic a := by simp
@[simp]
theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a :=
rfl
@[simp]
theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a :=
rfl
@[simp]
theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a :=
rfl
@[simp]
theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a :=
rfl
@[simp]
theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a :=
Set.ext fun _ => and_comm
@[simp]
theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a :=
Set.ext fun _ => and_comm
@[simp]
theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a :=
Set.ext fun _ => and_comm
@[simp]
theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a :=
Set.ext fun _ => and_comm
@[simp]
theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b :=
⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩
@[simp]
theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b :=
⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩
@[simp]
theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b :=
⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩
@[simp]
theorem nonempty_Ici : (Ici a).Nonempty :=
⟨a, left_mem_Ici⟩
@[simp]
theorem nonempty_Iic : (Iic a).Nonempty :=
⟨a, right_mem_Iic⟩
@[simp]
theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b :=
⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩
@[simp]
theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty :=
exists_gt a
@[simp]
theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty :=
exists_lt a
theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) :=
Nonempty.to_subtype (nonempty_Icc.mpr h)
theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) :=
Nonempty.to_subtype (nonempty_Ico.mpr h)
theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) :=
Nonempty.to_subtype (nonempty_Ioc.mpr h)
/-- An interval `Ici a` is nonempty. -/
instance nonempty_Ici_subtype : Nonempty (Ici a) :=
Nonempty.to_subtype nonempty_Ici
/-- An interval `Iic a` is nonempty. -/
instance nonempty_Iic_subtype : Nonempty (Iic a) :=
Nonempty.to_subtype nonempty_Iic
theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) :=
Nonempty.to_subtype (nonempty_Ioo.mpr h)
/-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/
instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) :=
Nonempty.to_subtype nonempty_Ioi
/-- In an order without minimal elements, the intervals `Iio` are nonempty. -/
instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) :=
Nonempty.to_subtype nonempty_Iio
instance [NoMinOrder α] : NoMinOrder (Iio a) :=
⟨fun a =>
let ⟨b, hb⟩ := exists_lt (a : α)
⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩
instance [NoMinOrder α] : NoMinOrder (Iic a) :=
⟨fun a =>
let ⟨b, hb⟩ := exists_lt (a : α)
⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩
instance [NoMaxOrder α] : NoMaxOrder (Ioi a) :=
OrderDual.noMaxOrder (α := Iio (toDual a))
instance [NoMaxOrder α] : NoMaxOrder (Ici a) :=
OrderDual.noMaxOrder (α := Iic (toDual a))
@[simp]
theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb)
@[simp]
theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb)
@[simp]
theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb)
@[simp]
theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb)
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ :=
Icc_eq_empty h.not_le
@[simp]
theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ :=
Ico_eq_empty h.not_lt
@[simp]
theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ :=
Ioc_eq_empty h.not_lt
@[simp]
theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ :=
Ioo_eq_empty h.not_lt
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem Ico_self (a : α) : Ico a a = ∅ :=
Ico_eq_empty <| lt_irrefl _
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem Ioc_self (a : α) : Ioc a a = ∅ :=
Ioc_eq_empty <| lt_irrefl _
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem Ioo_self (a : α) : Ioo a a = ∅ :=
Ioo_eq_empty <| lt_irrefl _
theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a :=
⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩
@[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici
theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b :=
@Ici_subset_Ici αᵒᵈ _ _ _
@[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic
theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a :=
⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩
theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b :=
⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩
@[gcongr]
theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ =>
⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩
@[gcongr]
theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b :=
Ioo_subset_Ioo h le_rfl
@[gcongr]
theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ :=
Ioo_subset_Ioo le_rfl h
@[gcongr]
theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ =>
⟨h₁.trans hx₁, hx₂.trans_le h₂⟩
@[gcongr]
theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b :=
Ico_subset_Ico h le_rfl
@[gcongr]
theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ :=
Ico_subset_Ico le_rfl h
@[gcongr]
theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ =>
⟨h₁.trans hx₁, le_trans hx₂ h₂⟩
@[gcongr]
theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b :=
Icc_subset_Icc h le_rfl
@[gcongr]
theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ :=
Icc_subset_Icc le_rfl h
theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx =>
⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩
theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left
theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right
theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right
@[gcongr]
theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ =>
⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩
@[gcongr]
theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b :=
Ioc_subset_Ioc h le_rfl
@[gcongr]
theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ :=
Ioc_subset_Ioc le_rfl h
theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ =>
And.imp_left h₁.trans_le
theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ =>
And.imp_right fun h' => h'.trans_lt h
theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ =>
And.imp_right fun h₂ => h₂.trans_lt h₁
theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt
theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt
theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt
theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt
theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b :=
Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self
theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right
theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right
theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left
theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left
theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx
theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx
theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left
theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a :=
⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩
theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a :=
@Ioi_ssubset_Ici_self αᵒᵈ _ _
theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ =>
⟨h.trans hx, hx'.trans h'⟩⟩
theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ :=
⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ =>
⟨h.trans_le hx, hx'.trans_lt h'⟩⟩
theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ :=
⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ =>
⟨h.trans hx, hx'.trans_lt h'⟩⟩
theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ :=
⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ =>
⟨h.trans_le hx, hx'.trans h'⟩⟩
theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ :=
⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩
theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ :=
⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩
theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ :=
⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩
theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ :=
⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩
theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ :=
(ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr
⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩
theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) :
Icc a₁ b₁ ⊂ Icc a₂ b₂ :=
(ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr
⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩
/-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/
@[gcongr]
theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx
/-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/
theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a :=
Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self
/-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/
@[gcongr]
theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h
/-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/
theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b :=
Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self
theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b :=
rfl
theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b :=
rfl
theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b :=
rfl
theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b :=
rfl
theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a :=
inter_comm _ _
theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a :=
inter_comm _ _
theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a :=
inter_comm _ _
theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a :=
inter_comm _ _
theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b :=
Ioo_subset_Icc_self h
theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b :=
Ioo_subset_Ico_self h
theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b :=
Ioo_subset_Ioc_self h
theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b :=
Ico_subset_Icc_self h
theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b :=
Ioc_subset_Icc_self h
theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a :=
Ioi_subset_Ici_self h
theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a :=
Iio_subset_Iic_self h
theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by
rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc]
theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by
rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]
theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by
rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc]
theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by
rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo]
theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ :=
eq_univ_of_forall h
theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ :=
eq_univ_of_forall h
theorem _root_.IsMax.Ioi_eq (h : IsMax a) : Ioi a = ∅ :=
eq_empty_of_subset_empty fun _ => h.not_lt
theorem _root_.IsMin.Iio_eq (h : IsMin a) : Iio a = ∅ :=
eq_empty_of_subset_empty fun _ => h.not_lt
theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a :=
ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩
theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1
theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2
theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1
theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _
theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha
theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb
theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha
theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb
end Preorder
section PartialOrder
variable [PartialOrder α] {a b c : α}
@[simp]
theorem Icc_self (a : α) : Icc a a = {a} :=
Set.ext <| by simp [Icc, le_antisymm_iff, and_comm]
instance instIccUnique : Unique (Set.Icc a a) where
default := ⟨a, by simp⟩
uniq y := Subtype.ext <| by simpa using y.2
@[simp]
theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by
refine ⟨fun h => ?_, ?_⟩
· have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c)
exact
⟨eq_of_mem_singleton <| h.subst <| left_mem_Icc.2 hab,
eq_of_mem_singleton <| h.subst <| right_mem_Icc.2 hab⟩
· rintro ⟨rfl, rfl⟩
exact Icc_self _
lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) :=
fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm
(le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba)
@[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} :
Set.Subsingleton (Icc a b) ↔ b ≤ a := by
refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩
contrapose! h
simp only [gt_iff_lt, not_subsingleton_iff]
exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩
@[simp]
theorem Icc_diff_left : Icc a b \ {a} = Ioc a b :=
ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm]
@[simp]
theorem Icc_diff_right : Icc a b \ {b} = Ico a b :=
ext fun x => by simp [lt_iff_le_and_ne, and_assoc]
@[simp]
theorem Ico_diff_left : Ico a b \ {a} = Ioo a b :=
ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm]
@[simp]
theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b :=
ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne]
@[simp]
theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by
rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right]
@[simp]
theorem Ici_diff_left : Ici a \ {a} = Ioi a :=
ext fun x => by simp [lt_iff_le_and_ne, eq_comm]
@[simp]
theorem Iic_diff_right : Iic a \ {a} = Iio a :=
ext fun x => by simp [lt_iff_le_and_ne]
@[simp]
theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by
rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)]
@[simp]
theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by
rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)]
@[simp]
theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by
rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)]
@[simp]
theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by
rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)]
@[simp]
theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by
rw [← Icc_diff_both, diff_diff_cancel_left]
simp [insert_subset_iff, h]
@[simp]
theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by
rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)]
@[simp]
theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by
rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem Ioi_union_left : Ioi a ∪ {a} = Ici a :=
ext fun x => by simp [eq_comm, le_iff_eq_or_lt]
-- Porting note (#10618): `simp` can prove this
-- @[simp]
theorem Iio_union_right : Iio a ∪ {a} = Iic a :=
ext fun _ => le_iff_lt_or_eq.symm
theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by
rw [← Ico_diff_left, diff_union_self,
union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)]
theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by
simpa only [dual_Ioo, dual_Ico] using Ioo_union_left hab.dual
theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by
have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun
| x, .inl rfl => left_mem_Icc.mpr h
| x, .inr rfl => right_mem_Icc.mpr h
rw [← this, Icc_diff_both]
theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by
rw [← Icc_diff_left, diff_union_self,
union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)]
theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by
simpa only [dual_Ioc, dual_Icc] using Ioc_union_left hab.dual
@[simp]
theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by
rw [insert_eq, union_comm, Ico_union_right h]
@[simp]
theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by
rw [insert_eq, union_comm, Ioc_union_left h]
@[simp]
theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by
rw [insert_eq, union_comm, Ioo_union_left h]
@[simp]
theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by
rw [insert_eq, union_comm, Ioo_union_right h]
@[simp]
theorem Iio_insert : insert a (Iio a) = Iic a :=
ext fun _ => le_iff_eq_or_lt.symm
@[simp]
theorem Ioi_insert : insert a (Ioi a) = Ici a :=
ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm
theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) :
s ∈ ({Ici a, Ioi a} : Set (Set α)) :=
by_cases
(fun h : a ∈ s =>
Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*])
fun h =>
Or.inr <| Subset.antisymm (fun x hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho
theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) :
s ∈ ({Iic a, Iio a} : Set (Set α)) :=
@mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc
theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) :
s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by
classical
by_cases ha : a ∈ s <;> by_cases hb : b ∈ s
· refine Or.inl (Subset.antisymm hc ?_)
rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right,
diff_singleton_subset_iff, insert_eq_of_mem hb] at ho
· refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_
· rw [← Icc_diff_right]
exact subset_diff_singleton hc hb
· rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho
· refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_
· rw [← Icc_diff_left]
exact subset_diff_singleton hc ha
· rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho
· refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho
rw [← Ico_diff_left, ← Icc_diff_right]
apply_rules [subset_diff_singleton]
theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b :=
hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩
theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b :=
hmem.2.eq_or_lt.imp_right <| And.intro hmem.1
theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) :
x = a ∨ x = b ∨ x ∈ Ioo a b :=
hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩
theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} :=
eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩
theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} :=
h.toDual.Ici_eq
theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ =>
eq_of_forall_ge_iff ∘ Set.ext_iff.1
theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ =>
eq_of_forall_le_iff ∘ Set.ext_iff.1
theorem Ici_inj : Ici a = Ici b ↔ a = b :=
Ici_injective.eq_iff
theorem Iic_inj : Iic a = Iic b ↔ a = b :=
Iic_injective.eq_iff
end PartialOrder
section OrderTop
@[simp]
theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} :=
isMax_top.Ici_eq
variable [Preorder α] [OrderTop α] {a : α}
@[simp]
theorem Ioi_top : Ioi (⊤ : α) = ∅ :=
isMax_top.Ioi_eq
@[simp]
theorem Iic_top : Iic (⊤ : α) = univ :=
isTop_top.Iic_eq
@[simp]
theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic]
@[simp]
theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic]
end OrderTop
section OrderBot
@[simp]
theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} :=
isMin_bot.Iic_eq
variable [Preorder α] [OrderBot α] {a : α}
@[simp]
theorem Iio_bot : Iio (⊥ : α) = ∅ :=
isMin_bot.Iio_eq
@[simp]
theorem Ici_bot : Ici (⊥ : α) = univ :=
isBot_bot.Ici_eq
@[simp]
theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic]
@[simp]
theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio]
end OrderBot
theorem Icc_bot_top [PartialOrder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp
section LinearOrder
variable [LinearOrder α] {a a₁ a₂ b b₁ b₂ c d : α}
theorem not_mem_Ici : c ∉ Ici a ↔ c < a :=
not_le
theorem not_mem_Iic : c ∉ Iic b ↔ b < c :=
not_le
theorem not_mem_Ioi : c ∉ Ioi a ↔ c ≤ a :=
not_lt
theorem not_mem_Iio : c ∉ Iio b ↔ b ≤ c :=
not_lt
@[simp]
theorem compl_Iic : (Iic a)ᶜ = Ioi a :=
ext fun _ => not_le
@[simp]
theorem compl_Ici : (Ici a)ᶜ = Iio a :=
ext fun _ => not_le
@[simp]
theorem compl_Iio : (Iio a)ᶜ = Ici a :=
ext fun _ => not_lt
@[simp]
theorem compl_Ioi : (Ioi a)ᶜ = Iic a :=
ext fun _ => not_lt
@[simp]
theorem Ici_diff_Ici : Ici a \ Ici b = Ico a b := by rw [diff_eq, compl_Ici, Ici_inter_Iio]
@[simp]
theorem Ici_diff_Ioi : Ici a \ Ioi b = Icc a b := by rw [diff_eq, compl_Ioi, Ici_inter_Iic]
@[simp]
theorem Ioi_diff_Ioi : Ioi a \ Ioi b = Ioc a b := by rw [diff_eq, compl_Ioi, Ioi_inter_Iic]
@[simp]
theorem Ioi_diff_Ici : Ioi a \ Ici b = Ioo a b := by rw [diff_eq, compl_Ici, Ioi_inter_Iio]
@[simp]
theorem Iic_diff_Iic : Iic b \ Iic a = Ioc a b := by
rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iic]
@[simp]
theorem Iio_diff_Iic : Iio b \ Iic a = Ioo a b := by
rw [diff_eq, compl_Iic, inter_comm, Ioi_inter_Iio]
@[simp]
theorem Iic_diff_Iio : Iic b \ Iio a = Icc a b := by
rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iic]
@[simp]
theorem Iio_diff_Iio : Iio b \ Iio a = Ico a b := by
rw [diff_eq, compl_Iio, inter_comm, Ici_inter_Iio]
theorem Ioi_injective : Injective (Ioi : α → Set α) := fun _ _ =>
eq_of_forall_gt_iff ∘ Set.ext_iff.1
theorem Iio_injective : Injective (Iio : α → Set α) := fun _ _ =>
eq_of_forall_lt_iff ∘ Set.ext_iff.1
theorem Ioi_inj : Ioi a = Ioi b ↔ a = b :=
Ioi_injective.eq_iff
theorem Iio_inj : Iio a = Iio b ↔ a = b :=
Iio_injective.eq_iff
theorem Ico_subset_Ico_iff (h₁ : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨fun h =>
have : a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_rfl, h₁⟩
⟨this.1, le_of_not_lt fun h' => lt_irrefl b₂ (h ⟨this.2.le, h'⟩).2⟩,
fun ⟨h₁, h₂⟩ => Ico_subset_Ico h₁ h₂⟩
theorem Ioc_subset_Ioc_iff (h₁ : a₁ < b₁) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ b₁ ≤ b₂ ∧ a₂ ≤ a₁ := by
convert @Ico_subset_Ico_iff αᵒᵈ _ b₁ b₂ a₁ a₂ h₁ using 2 <;> exact (@dual_Ico α _ _ _).symm
theorem Ioo_subset_Ioo_iff [DenselyOrdered α] (h₁ : a₁ < b₁) :
Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨fun h => by
rcases exists_between h₁ with ⟨x, xa, xb⟩
constructor <;> refine le_of_not_lt fun h' => ?_
· have ab := (h ⟨xa, xb⟩).1.trans xb
exact lt_irrefl _ (h ⟨h', ab⟩).1
· have ab := xa.trans (h ⟨xa, xb⟩).2
exact lt_irrefl _ (h ⟨ab, h'⟩).2,
fun ⟨h₁, h₂⟩ => Ioo_subset_Ioo h₁ h₂⟩
theorem Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ :=
⟨fun e => by
simp only [Subset.antisymm_iff] at e
simp only [le_antisymm_iff]
cases' h with h h <;>
simp only [gt_iff_lt, not_lt, Ico_subset_Ico_iff h] at e <;>
[ rcases e with ⟨⟨h₁, h₂⟩, e'⟩; rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ] <;>
-- Porting note: restore `tauto`
have hab := (Ico_subset_Ico_iff <| h₁.trans_lt <| h.trans_le h₂).1 e' <;>
[ exact ⟨⟨hab.left, h₁⟩, ⟨h₂, hab.right⟩⟩; exact ⟨⟨h₁, hab.left⟩, ⟨hab.right, h₂⟩⟩ ],
fun ⟨h₁, h₂⟩ => by rw [h₁, h₂]⟩
lemma Ici_eq_singleton_iff_isTop {x : α} : (Ici x = {x}) ↔ IsTop x := by
refine ⟨fun h y ↦ ?_, fun h ↦ by ext y; simp [(h y).ge_iff_eq]⟩
by_contra! H
have : y ∈ Ici x := H.le
rw [h, mem_singleton_iff] at this
exact lt_irrefl y (this.le.trans_lt H)
@[simp]
theorem Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b := by
refine ⟨fun h => ?_, fun h => Ioi_subset_Ioi h⟩
by_contra ba
exact lt_irrefl _ (h (not_le.mp ba))
@[simp]
theorem Ioi_subset_Ici_iff [DenselyOrdered α] : Ioi b ⊆ Ici a ↔ a ≤ b := by
refine ⟨fun h => ?_, fun h => Ioi_subset_Ici h⟩
by_contra ba
obtain ⟨c, bc, ca⟩ : ∃ c, b < c ∧ c < a := exists_between (not_le.mp ba)
exact lt_irrefl _ (ca.trans_le (h bc))
@[simp]
theorem Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b := by
refine ⟨fun h => ?_, fun h => Iio_subset_Iio h⟩
by_contra ab
exact lt_irrefl _ (h (not_le.mp ab))
@[simp]
theorem Iio_subset_Iic_iff [DenselyOrdered α] : Iio a ⊆ Iic b ↔ a ≤ b := by
rw [← diff_eq_empty, Iio_diff_Iic, Ioo_eq_empty_iff, not_lt]
/-! ### Unions of adjacent intervals -/
/-! #### Two infinite intervals -/
theorem Iic_union_Ioi_of_le (h : a ≤ b) : Iic b ∪ Ioi a = univ :=
eq_univ_of_forall fun x => (h.lt_or_le x).symm
theorem Iio_union_Ici_of_le (h : a ≤ b) : Iio b ∪ Ici a = univ :=
eq_univ_of_forall fun x => (h.le_or_lt x).symm
theorem Iic_union_Ici_of_le (h : a ≤ b) : Iic b ∪ Ici a = univ :=
eq_univ_of_forall fun x => (h.le_or_le x).symm
theorem Iio_union_Ioi_of_lt (h : a < b) : Iio b ∪ Ioi a = univ :=
eq_univ_of_forall fun x => (h.lt_or_lt x).symm
@[simp]
theorem Iic_union_Ici : Iic a ∪ Ici a = univ :=
Iic_union_Ici_of_le le_rfl
@[simp]
theorem Iio_union_Ici : Iio a ∪ Ici a = univ :=
Iio_union_Ici_of_le le_rfl
@[simp]
theorem Iic_union_Ioi : Iic a ∪ Ioi a = univ :=
Iic_union_Ioi_of_le le_rfl
@[simp]
theorem Iio_union_Ioi : Iio a ∪ Ioi a = {a}ᶜ :=
ext fun _ => lt_or_lt_iff_ne
/-! #### A finite and an infinite interval -/
theorem Ioo_union_Ioi' (h₁ : c < b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by
ext1 x
simp_rw [mem_union, mem_Ioo, mem_Ioi, min_lt_iff]
by_cases hc : c < x
· simp only [hc, or_true] -- Porting note: restore `tauto`
· have hxb : x < b := (le_of_not_gt hc).trans_lt h₁
simp only [hxb, and_true] -- Porting note: restore `tauto`
theorem Ioo_union_Ioi (h : c < max a b) : Ioo a b ∪ Ioi c = Ioi (min a c) := by
rcases le_total a b with hab | hab <;> simp [hab] at h
· exact Ioo_union_Ioi' h
· rw [min_comm]
simp [*, min_eq_left_of_lt]
theorem Ioi_subset_Ioo_union_Ici : Ioi a ⊆ Ioo a b ∪ Ici b := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb
@[simp]
theorem Ioo_union_Ici_eq_Ioi (h : a < b) : Ioo a b ∪ Ici b = Ioi a :=
Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioo_union_Ici
theorem Ici_subset_Ico_union_Ici : Ici a ⊆ Ico a b ∪ Ici b := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb
@[simp]
theorem Ico_union_Ici_eq_Ici (h : a ≤ b) : Ico a b ∪ Ici b = Ici a :=
Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Ico_union_Ici
theorem Ico_union_Ici' (h₁ : c ≤ b) : Ico a b ∪ Ici c = Ici (min a c) := by
ext1 x
simp_rw [mem_union, mem_Ico, mem_Ici, min_le_iff]
by_cases hc : c ≤ x
· simp only [hc, or_true] -- Porting note: restore `tauto`
· have hxb : x < b := (lt_of_not_ge hc).trans_le h₁
simp only [hxb, and_true] -- Porting note: restore `tauto`
theorem Ico_union_Ici (h : c ≤ max a b) : Ico a b ∪ Ici c = Ici (min a c) := by
rcases le_total a b with hab | hab <;> simp [hab] at h
· exact Ico_union_Ici' h
· simp [*]
theorem Ioi_subset_Ioc_union_Ioi : Ioi a ⊆ Ioc a b ∪ Ioi b := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb
@[simp]
theorem Ioc_union_Ioi_eq_Ioi (h : a ≤ b) : Ioc a b ∪ Ioi b = Ioi a :=
Subset.antisymm (fun _ hx => hx.elim And.left h.trans_lt) Ioi_subset_Ioc_union_Ioi
theorem Ioc_union_Ioi' (h₁ : c ≤ b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by
ext1 x
simp_rw [mem_union, mem_Ioc, mem_Ioi, min_lt_iff]
by_cases hc : c < x
· simp only [hc, or_true] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_gt hc).trans h₁
simp only [hxb, and_true] -- Porting note: restore `tauto`
theorem Ioc_union_Ioi (h : c ≤ max a b) : Ioc a b ∪ Ioi c = Ioi (min a c) := by
rcases le_total a b with hab | hab <;> simp [hab] at h
· exact Ioc_union_Ioi' h
· simp [*]
theorem Ici_subset_Icc_union_Ioi : Ici a ⊆ Icc a b ∪ Ioi b := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx, hxb⟩) fun hxb => Or.inr hxb
@[simp]
theorem Icc_union_Ioi_eq_Ici (h : a ≤ b) : Icc a b ∪ Ioi b = Ici a :=
Subset.antisymm (fun _ hx => (hx.elim And.left) fun hx' => h.trans <| le_of_lt hx')
Ici_subset_Icc_union_Ioi
theorem Ioi_subset_Ioc_union_Ici : Ioi a ⊆ Ioc a b ∪ Ici b :=
Subset.trans Ioi_subset_Ioo_union_Ici (union_subset_union_left _ Ioo_subset_Ioc_self)
@[simp]
theorem Ioc_union_Ici_eq_Ioi (h : a < b) : Ioc a b ∪ Ici b = Ioi a :=
Subset.antisymm (fun _ hx => hx.elim And.left h.trans_le) Ioi_subset_Ioc_union_Ici
theorem Ici_subset_Icc_union_Ici : Ici a ⊆ Icc a b ∪ Ici b :=
Subset.trans Ici_subset_Ico_union_Ici (union_subset_union_left _ Ico_subset_Icc_self)
@[simp]
theorem Icc_union_Ici_eq_Ici (h : a ≤ b) : Icc a b ∪ Ici b = Ici a :=
Subset.antisymm (fun _ hx => hx.elim And.left h.trans) Ici_subset_Icc_union_Ici
theorem Icc_union_Ici' (h₁ : c ≤ b) : Icc a b ∪ Ici c = Ici (min a c) := by
ext1 x
simp_rw [mem_union, mem_Icc, mem_Ici, min_le_iff]
by_cases hc : c ≤ x
· simp only [hc, or_true] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_ge hc).trans h₁
simp only [hxb, and_true] -- Porting note: restore `tauto`
theorem Icc_union_Ici (h : c ≤ max a b) : Icc a b ∪ Ici c = Ici (min a c) := by
rcases le_or_lt a b with hab | hab <;> simp [hab] at h
· exact Icc_union_Ici' h
· cases' h with h h
· simp [*]
· have hca : c ≤ a := h.trans hab.le
simp [*]
/-! #### An infinite and a finite interval -/
theorem Iic_subset_Iio_union_Icc : Iic b ⊆ Iio a ∪ Icc a b := fun x hx =>
(lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩
@[simp]
theorem Iio_union_Icc_eq_Iic (h : a ≤ b) : Iio a ∪ Icc a b = Iic b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx => (le_of_lt hx).trans h) And.right)
Iic_subset_Iio_union_Icc
theorem Iio_subset_Iio_union_Ico : Iio b ⊆ Iio a ∪ Ico a b := fun x hx =>
(lt_or_le x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩
@[simp]
theorem Iio_union_Ico_eq_Iio (h : a ≤ b) : Iio a ∪ Ico a b = Iio b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_lt_of_le hx' h) And.right)
Iio_subset_Iio_union_Ico
theorem Iio_union_Ico' (h₁ : c ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by
ext1 x
simp_rw [mem_union, mem_Iio, mem_Ico, lt_max_iff]
by_cases hc : c ≤ x
· simp only [hc, true_and] -- Porting note: restore `tauto`
· have hxb : x < b := (lt_of_not_ge hc).trans_le h₁
simp only [hxb, true_or] -- Porting note: restore `tauto`
theorem Iio_union_Ico (h : min c d ≤ b) : Iio b ∪ Ico c d = Iio (max b d) := by
rcases le_total c d with hcd | hcd <;> simp [hcd] at h
· exact Iio_union_Ico' h
· simp [*]
theorem Iic_subset_Iic_union_Ioc : Iic b ⊆ Iic a ∪ Ioc a b := fun x hx =>
(le_or_lt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩
@[simp]
theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right)
Iic_subset_Iic_union_Ioc
theorem Iic_union_Ioc' (h₁ : c < b) : Iic b ∪ Ioc c d = Iic (max b d) := by
ext1 x
simp_rw [mem_union, mem_Iic, mem_Ioc, le_max_iff]
by_cases hc : c < x
· simp only [hc, true_and] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_gt hc).trans h₁.le
simp only [hxb, true_or] -- Porting note: restore `tauto`
theorem Iic_union_Ioc (h : min c d < b) : Iic b ∪ Ioc c d = Iic (max b d) := by
rcases le_total c d with hcd | hcd <;> simp [hcd] at h
· exact Iic_union_Ioc' h
· rw [max_comm]
simp [*, max_eq_right_of_lt h]
theorem Iio_subset_Iic_union_Ioo : Iio b ⊆ Iic a ∪ Ioo a b := fun x hx =>
(le_or_lt x a).elim (fun hxa => Or.inl hxa) fun hxa => Or.inr ⟨hxa, hx⟩
@[simp]
theorem Iic_union_Ioo_eq_Iio (h : a < b) : Iic a ∪ Ioo a b = Iio b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right)
Iio_subset_Iic_union_Ioo
theorem Iio_union_Ioo' (h₁ : c < b) : Iio b ∪ Ioo c d = Iio (max b d) := by
ext x
cases' lt_or_le x b with hba hba
· simp [hba, h₁]
· simp only [mem_Iio, mem_union, mem_Ioo, lt_max_iff]
refine or_congr Iff.rfl ⟨And.right, ?_⟩
exact fun h₂ => ⟨h₁.trans_le hba, h₂⟩
theorem Iio_union_Ioo (h : min c d < b) : Iio b ∪ Ioo c d = Iio (max b d) := by
rcases le_total c d with hcd | hcd <;> simp [hcd] at h
· exact Iio_union_Ioo' h
· rw [max_comm]
simp [*, max_eq_right_of_lt h]
theorem Iic_subset_Iic_union_Icc : Iic b ⊆ Iic a ∪ Icc a b :=
Subset.trans Iic_subset_Iic_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)
@[simp]
theorem Iic_union_Icc_eq_Iic (h : a ≤ b) : Iic a ∪ Icc a b = Iic b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx' => le_trans hx' h) And.right)
Iic_subset_Iic_union_Icc
theorem Iic_union_Icc' (h₁ : c ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by
ext1 x
simp_rw [mem_union, mem_Iic, mem_Icc, le_max_iff]
by_cases hc : c ≤ x
· simp only [hc, true_and] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_ge hc).trans h₁
simp only [hxb, true_or] -- Porting note: restore `tauto`
theorem Iic_union_Icc (h : min c d ≤ b) : Iic b ∪ Icc c d = Iic (max b d) := by
rcases le_or_lt c d with hcd | hcd <;> simp [hcd] at h
· exact Iic_union_Icc' h
· cases' h with h h
· have hdb : d ≤ b := hcd.le.trans h
simp [*]
· simp [*]
theorem Iio_subset_Iic_union_Ico : Iio b ⊆ Iic a ∪ Ico a b :=
Subset.trans Iio_subset_Iic_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)
@[simp]
theorem Iic_union_Ico_eq_Iio (h : a < b) : Iic a ∪ Ico a b = Iio b :=
Subset.antisymm (fun _ hx => hx.elim (fun hx' => lt_of_le_of_lt hx' h) And.right)
Iio_subset_Iic_union_Ico
/-! #### Two finite intervals, `I?o` and `Ic?` -/
theorem Ioo_subset_Ioo_union_Ico : Ioo a c ⊆ Ioo a b ∪ Ico b c := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ioo_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Ico b c = Ioo a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩)
Ioo_subset_Ioo_union_Ico
theorem Ico_subset_Ico_union_Ico : Ico a c ⊆ Ico a b ∪ Ico b c := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ico_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Ico b c = Ico a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_le h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩)
Ico_subset_Ico_union_Ico
theorem Ico_union_Ico' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by
ext1 x
simp_rw [mem_union, mem_Ico, min_le_iff, lt_max_iff]
by_cases hc : c ≤ x <;> by_cases hd : x < d
· simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto`
· have hax : a ≤ x := h₂.trans (le_of_not_gt hd)
simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto`
· have hxb : x < b := (lt_of_not_ge hc).trans_le h₁
simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto`
· simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto`
theorem Ico_union_Ico (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) :
Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by
rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;> simp [*] at h₁ h₂
· exact Ico_union_Ico' h₂ h₁
all_goals simp [*]
theorem Icc_subset_Ico_union_Icc : Icc a c ⊆ Ico a b ∪ Icc b c := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ico_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ico a b ∪ Icc b c = Icc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩)
Icc_subset_Ico_union_Icc
theorem Ioc_subset_Ioo_union_Icc : Ioc a c ⊆ Ioo a b ∪ Icc b c := fun x hx =>
(lt_or_le x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ioo_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioo a b ∪ Icc b c = Ioc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.le.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩)
Ioc_subset_Ioo_union_Icc
/-! #### Two finite intervals, `I?c` and `Io?` -/
theorem Ioo_subset_Ioc_union_Ioo : Ioo a c ⊆ Ioc a b ∪ Ioo b c := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ioc_union_Ioo_eq_Ioo (h₁ : a ≤ b) (h₂ : b < c) : Ioc a b ∪ Ioo b c = Ioo a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩)
Ioo_subset_Ioc_union_Ioo
theorem Ico_subset_Icc_union_Ioo : Ico a c ⊆ Icc a b ∪ Ioo b c := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Icc_union_Ioo_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ioo b c = Ico a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩)
Ico_subset_Icc_union_Ioo
theorem Icc_subset_Icc_union_Ioc : Icc a c ⊆ Icc a b ∪ Ioc b c := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Icc_union_Ioc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Ioc b c = Icc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1.le, hx.2⟩)
Icc_subset_Icc_union_Ioc
theorem Ioc_subset_Ioc_union_Ioc : Ioc a c ⊆ Ioc a b ∪ Ioc b c := fun x hx =>
(le_or_lt x b).elim (fun hxb => Or.inl ⟨hx.1, hxb⟩) fun hxb => Or.inr ⟨hxb, hx.2⟩
@[simp]
theorem Ioc_union_Ioc_eq_Ioc (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_lt hx.1, hx.2⟩)
Ioc_subset_Ioc_union_Ioc
theorem Ioc_union_Ioc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by
ext1 x
simp_rw [mem_union, mem_Ioc, min_lt_iff, le_max_iff]
by_cases hc : c < x <;> by_cases hd : x ≤ d
· simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto`
· have hax : a < x := h₂.trans_lt (lt_of_not_ge hd)
simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_gt hc).trans h₁
simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto`
· simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto`
theorem Ioc_union_Ioc (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) :
Ioc a b ∪ Ioc c d = Ioc (min a c) (max b d) := by
rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;> simp [*] at h₁ h₂
· exact Ioc_union_Ioc' h₂ h₁
all_goals simp [*]
/-! #### Two finite intervals with a common point -/
theorem Ioo_subset_Ioc_union_Ico : Ioo a c ⊆ Ioc a b ∪ Ico b c :=
Subset.trans Ioo_subset_Ioc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)
@[simp]
theorem Ioc_union_Ico_eq_Ioo (h₁ : a < b) (h₂ : b < c) : Ioc a b ∪ Ico b c = Ioo a c :=
Subset.antisymm
(fun _ hx =>
hx.elim (fun hx' => ⟨hx'.1, hx'.2.trans_lt h₂⟩) fun hx' => ⟨h₁.trans_le hx'.1, hx'.2⟩)
Ioo_subset_Ioc_union_Ico
theorem Ico_subset_Icc_union_Ico : Ico a c ⊆ Icc a b ∪ Ico b c :=
Subset.trans Ico_subset_Icc_union_Ioo (union_subset_union_right _ Ioo_subset_Ico_self)
@[simp]
theorem Icc_union_Ico_eq_Ico (h₁ : a ≤ b) (h₂ : b < c) : Icc a b ∪ Ico b c = Ico a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans_lt h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩)
Ico_subset_Icc_union_Ico
theorem Icc_subset_Icc_union_Icc : Icc a c ⊆ Icc a b ∪ Icc b c :=
Subset.trans Icc_subset_Icc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)
@[simp]
theorem Icc_union_Icc_eq_Icc (h₁ : a ≤ b) (h₂ : b ≤ c) : Icc a b ∪ Icc b c = Icc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans hx.1, hx.2⟩)
Icc_subset_Icc_union_Icc
theorem Icc_union_Icc' (h₁ : c ≤ b) (h₂ : a ≤ d) : Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by
ext1 x
simp_rw [mem_union, mem_Icc, min_le_iff, le_max_iff]
by_cases hc : c ≤ x <;> by_cases hd : x ≤ d
· simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto`
· have hax : a ≤ x := h₂.trans (le_of_not_ge hd)
simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto`
· have hxb : x ≤ b := (le_of_not_ge hc).trans h₁
simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto`
· simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto`
/-- We cannot replace `<` by `≤` in the hypotheses.
Otherwise for `b < a = d < c` the l.h.s. is `∅` and the r.h.s. is `{a}`.
-/
theorem Icc_union_Icc (h₁ : min a b < max c d) (h₂ : min c d < max a b) :
Icc a b ∪ Icc c d = Icc (min a c) (max b d) := by
rcases le_or_lt a b with hab | hab <;> rcases le_or_lt c d with hcd | hcd <;>
simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, min_eq_left_of_lt,
min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt, hab, hcd] at h₁ h₂
· exact Icc_union_Icc' h₂.le h₁.le
all_goals simp [*, min_eq_left_of_lt, max_eq_left_of_lt, min_eq_right_of_lt, max_eq_right_of_lt]
theorem Ioc_subset_Ioc_union_Icc : Ioc a c ⊆ Ioc a b ∪ Icc b c :=
Subset.trans Ioc_subset_Ioc_union_Ioc (union_subset_union_right _ Ioc_subset_Icc_self)
@[simp]
theorem Ioc_union_Icc_eq_Ioc (h₁ : a < b) (h₂ : b ≤ c) : Ioc a b ∪ Icc b c = Ioc a c :=
Subset.antisymm
(fun _ hx => hx.elim (fun hx => ⟨hx.1, hx.2.trans h₂⟩) fun hx => ⟨h₁.trans_le hx.1, hx.2⟩)
Ioc_subset_Ioc_union_Icc
theorem Ioo_union_Ioo' (h₁ : c < b) (h₂ : a < d) : Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by
ext1 x
simp_rw [mem_union, mem_Ioo, min_lt_iff, lt_max_iff]
by_cases hc : c < x <;> by_cases hd : x < d
· simp only [hc, hd, and_self, or_true] -- Porting note: restore `tauto`
· have hax : a < x := h₂.trans_le (le_of_not_lt hd)
simp only [hax, true_and, hc, or_self] -- Porting note: restore `tauto`
· have hxb : x < b := (le_of_not_lt hc).trans_lt h₁
simp only [hxb, and_true, hc, false_and, or_false, true_or] -- Porting note: restore `tauto`
· simp only [hc, hd, and_self, or_false] -- Porting note: restore `tauto`
theorem Ioo_union_Ioo (h₁ : min a b < max c d) (h₂ : min c d < max a b) :
Ioo a b ∪ Ioo c d = Ioo (min a c) (max b d) := by
rcases le_total a b with hab | hab <;> rcases le_total c d with hcd | hcd <;>
simp only [min_eq_left, min_eq_right, max_eq_left, max_eq_right, hab, hcd] at h₁ h₂
· exact Ioo_union_Ioo' h₂ h₁
all_goals
simp [*, min_eq_left_of_lt, min_eq_right_of_lt, max_eq_left_of_lt, max_eq_right_of_lt,
le_of_lt h₂, le_of_lt h₁]
end LinearOrder
section Lattice
section Inf
variable [SemilatticeInf α]
@[simp]
theorem Iic_inter_Iic {a b : α} : Iic a ∩ Iic b = Iic (a ⊓ b) := by
ext x
simp [Iic]
@[simp]
theorem Ioc_inter_Iic (a b c : α) : Ioc a b ∩ Iic c = Ioc a (b ⊓ c) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_assoc, Iic_inter_Iic]
end Inf
section Sup
variable [SemilatticeSup α]
@[simp]
theorem Ici_inter_Ici {a b : α} : Ici a ∩ Ici b = Ici (a ⊔ b) := by
ext x
simp [Ici]
@[simp]
theorem Ico_inter_Ici (a b c : α) : Ico a b ∩ Ici c = Ico (a ⊔ c) b := by
rw [← Ici_inter_Iio, ← Ici_inter_Iio, ← Ici_inter_Ici, inter_right_comm]
end Sup
section Both
variable [Lattice α] {a b c a₁ a₂ b₁ b₂ : α}
theorem Icc_inter_Icc : Icc a₁ b₁ ∩ Icc a₂ b₂ = Icc (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by
simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_rfl
@[simp]
theorem Icc_inter_Icc_eq_singleton (hab : a ≤ b) (hbc : b ≤ c) : Icc a b ∩ Icc b c = {b} := by
rw [Icc_inter_Icc, sup_of_le_right hab, inf_of_le_left hbc, Icc_self]
end Both
end Lattice
section LinearOrder
variable [LinearOrder α] [LinearOrder β] {f : α → β} {a a₁ a₂ b b₁ b₂ c d : α}
@[simp]
theorem Ioi_inter_Ioi : Ioi a ∩ Ioi b = Ioi (a ⊔ b) :=
ext fun _ => sup_lt_iff.symm
@[simp]
theorem Iio_inter_Iio : Iio a ∩ Iio b = Iio (a ⊓ b) :=
ext fun _ => lt_inf_iff.symm
theorem Ico_inter_Ico : Ico a₁ b₁ ∩ Ico a₂ b₂ = Ico (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by
simp only [Ici_inter_Iio.symm, Ici_inter_Ici.symm, Iio_inter_Iio.symm]; ac_rfl
theorem Ioc_inter_Ioc : Ioc a₁ b₁ ∩ Ioc a₂ b₂ = Ioc (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by
simp only [Ioi_inter_Iic.symm, Ioi_inter_Ioi.symm, Iic_inter_Iic.symm]; ac_rfl
theorem Ioo_inter_Ioo : Ioo a₁ b₁ ∩ Ioo a₂ b₂ = Ioo (a₁ ⊔ a₂) (b₁ ⊓ b₂) := by
simp only [Ioi_inter_Iio.symm, Ioi_inter_Ioi.symm, Iio_inter_Iio.symm]; ac_rfl
theorem Ioo_inter_Iio : Ioo a b ∩ Iio c = Ioo a (min b c) := by
ext
simp_rw [mem_inter_iff, mem_Ioo, mem_Iio, lt_min_iff, and_assoc]
theorem Iio_inter_Ioo : Iio a ∩ Ioo b c = Ioo b (min a c) := by
rw [Set.inter_comm, Set.Ioo_inter_Iio, min_comm]
theorem Ioo_inter_Ioi : Ioo a b ∩ Ioi c = Ioo (max a c) b := by
ext
simp_rw [mem_inter_iff, mem_Ioo, mem_Ioi, max_lt_iff, and_assoc, and_comm]
theorem Ioi_inter_Ioo : Set.Ioi a ∩ Set.Ioo b c = Set.Ioo (max a b) c := by
rw [inter_comm, Ioo_inter_Ioi, max_comm]
theorem Ioc_inter_Ioo_of_left_lt (h : b₁ < b₂) : Ioc a₁ b₁ ∩ Ioo a₂ b₂ = Ioc (max a₁ a₂) b₁ :=
ext fun x => by
simp [and_assoc, @and_left_comm (x ≤ _), and_iff_left_iff_imp.2 fun h' => lt_of_le_of_lt h' h]
theorem Ioc_inter_Ioo_of_right_le (h : b₂ ≤ b₁) : Ioc a₁ b₁ ∩ Ioo a₂ b₂ = Ioo (max a₁ a₂) b₂ :=
ext fun x => by
simp [and_assoc, @and_left_comm (x ≤ _),
and_iff_right_iff_imp.2 fun h' => (le_of_lt h').trans h]
theorem Ioo_inter_Ioc_of_left_le (h : b₁ ≤ b₂) : Ioo a₁ b₁ ∩ Ioc a₂ b₂ = Ioo (max a₁ a₂) b₁ := by
rw [inter_comm, Ioc_inter_Ioo_of_right_le h, max_comm]
theorem Ioo_inter_Ioc_of_right_lt (h : b₂ < b₁) : Ioo a₁ b₁ ∩ Ioc a₂ b₂ = Ioc (max a₁ a₂) b₂ := by
rw [inter_comm, Ioc_inter_Ioo_of_left_lt h, max_comm]
@[simp]
theorem Ico_diff_Iio : Ico a b \ Iio c = Ico (max a c) b := by
rw [diff_eq, compl_Iio, Ico_inter_Ici, sup_eq_max]
@[simp]
theorem Ioc_diff_Ioi : Ioc a b \ Ioi c = Ioc a (min b c) :=
ext <| by simp (config := { contextual := true }) [iff_def]
@[simp]
theorem Ioc_inter_Ioi : Ioc a b ∩ Ioi c = Ioc (a ⊔ c) b := by
rw [← Ioi_inter_Iic, inter_assoc, inter_comm, inter_assoc, Ioi_inter_Ioi, inter_comm,
Ioi_inter_Iic, sup_comm]
@[simp]
theorem Ico_inter_Iio : Ico a b ∩ Iio c = Ico a (min b c) :=
ext <| by simp (config := { contextual := true }) [iff_def]
@[simp]
theorem Ioc_diff_Iic : Ioc a b \ Iic c = Ioc (max a c) b := by
rw [diff_eq, compl_Iic, Ioc_inter_Ioi, sup_eq_max]
@[simp]
theorem Ioc_union_Ioc_right : Ioc a b ∪ Ioc a c = Ioc a (max b c) := by
rw [Ioc_union_Ioc, min_self] <;> exact (min_le_left _ _).trans (le_max_left _ _)
@[simp]
theorem Ioc_union_Ioc_left : Ioc a c ∪ Ioc b c = Ioc (min a b) c := by
rw [Ioc_union_Ioc, max_self] <;> exact (min_le_right _ _).trans (le_max_right _ _)
@[simp]
theorem Ioc_union_Ioc_symm : Ioc a b ∪ Ioc b a = Ioc (min a b) (max a b) := by
rw [max_comm]
apply Ioc_union_Ioc <;> rw [max_comm] <;> exact min_le_max
@[simp]
theorem Ioc_union_Ioc_union_Ioc_cycle :
Ioc a b ∪ Ioc b c ∪ Ioc c a = Ioc (min a (min b c)) (max a (max b c)) := by
rw [Ioc_union_Ioc, Ioc_union_Ioc] <;>
-- Porting note: mathlib3 proof finished from here as follows:
-- (It can probably be restored after https://github.com/leanprover-community/mathlib4/pull/856)
-- ac_rfl
-- all_goals
-- solve_by_elim (config := { max_depth := 5 }) [min_le_of_left_le, min_le_of_right_le,
-- le_max_of_le_left, le_max_of_le_right, le_refl]
simp [min_le_of_left_le, min_le_of_right_le, le_max_of_le_left, le_max_of_le_right, le_refl,
min_assoc, max_comm]
end LinearOrder
/-!
### Closed intervals in `α × β`
-/
section Prod
variable [Preorder α] [Preorder β]
@[simp]
theorem Iic_prod_Iic (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) :=
rfl
@[simp]
theorem Ici_prod_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) :=
rfl
theorem Ici_prod_eq (a : α × β) : Ici a = Ici a.1 ×ˢ Ici a.2 :=
rfl
theorem Iic_prod_eq (a : α × β) : Iic a = Iic a.1 ×ˢ Iic a.2 :=
rfl
@[simp]
theorem Icc_prod_Icc (a₁ a₂ : α) (b₁ b₂ : β) : Icc a₁ a₂ ×ˢ Icc b₁ b₂ = Icc (a₁, b₁) (a₂, b₂) := by
ext ⟨x, y⟩
simp [and_assoc, and_comm, and_left_comm]
theorem Icc_prod_eq (a b : α × β) : Icc a b = Icc a.1 b.1 ×ˢ Icc a.2 b.2 := by simp
end Prod
end Set
/-! ### Lemmas about intervals in dense orders -/
section Dense
variable (α) [Preorder α] [DenselyOrdered α] {x y : α}
instance : NoMinOrder (Set.Ioo x y) :=
⟨fun ⟨a, ha₁, ha₂⟩ => by
rcases exists_between ha₁ with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, hb₁, hb₂.trans ha₂⟩, hb₂⟩⟩
instance : NoMinOrder (Set.Ioc x y) :=
⟨fun ⟨a, ha₁, ha₂⟩ => by
rcases exists_between ha₁ with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, hb₁, hb₂.le.trans ha₂⟩, hb₂⟩⟩
instance : NoMinOrder (Set.Ioi x) :=
⟨fun ⟨a, ha⟩ => by
rcases exists_between ha with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, hb₁⟩, hb₂⟩⟩
instance : NoMaxOrder (Set.Ioo x y) :=
⟨fun ⟨a, ha₁, ha₂⟩ => by
rcases exists_between ha₂ with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, ha₁.trans hb₁, hb₂⟩, hb₁⟩⟩
instance : NoMaxOrder (Set.Ico x y) :=
⟨fun ⟨a, ha₁, ha₂⟩ => by
rcases exists_between ha₂ with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, ha₁.trans hb₁.le, hb₂⟩, hb₁⟩⟩
instance : NoMaxOrder (Set.Iio x) :=
⟨fun ⟨a, ha⟩ => by
rcases exists_between ha with ⟨b, hb₁, hb₂⟩
exact ⟨⟨b, hb₂⟩, hb₁⟩⟩
end Dense
|
Order\Interval\Set\Disjoint.lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Data.Set.Lattice
/-!
# Extra lemmas about intervals
This file contains lemmas about intervals that cannot be included into `Order.Interval.Set.Basic`
because this would create an `import` cycle. Namely, lemmas in this file can use definitions
from `Data.Set.Lattice`, including `Disjoint`.
We consider various intersections and unions of half infinite intervals.
-/
universe u v w
variable {ι : Sort u} {α : Type v} {β : Type w}
open Set
open OrderDual (toDual)
namespace Set
section Preorder
variable [Preorder α] {a b c : α}
@[simp]
theorem Iic_disjoint_Ioi (h : a ≤ b) : Disjoint (Iic a) (Ioi b) :=
disjoint_left.mpr fun _ ha hb => (h.trans_lt hb).not_le ha
@[simp]
theorem Iio_disjoint_Ici (h : a ≤ b) : Disjoint (Iio a) (Ici b) :=
disjoint_left.mpr fun _ ha hb => (h.trans_lt' ha).not_le hb
@[simp]
theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) :=
(Iic_disjoint_Ioi h).mono le_rfl Ioc_subset_Ioi_self
@[simp]
theorem Ioc_disjoint_Ioc_same : Disjoint (Ioc a b) (Ioc b c) :=
(Iic_disjoint_Ioc le_rfl).mono Ioc_subset_Iic_self le_rfl
@[simp]
theorem Ico_disjoint_Ico_same : Disjoint (Ico a b) (Ico b c) :=
disjoint_left.mpr fun _ hab hbc => hab.2.not_le hbc.1
@[simp]
theorem Ici_disjoint_Iic : Disjoint (Ici a) (Iic b) ↔ ¬a ≤ b := by
rw [Set.disjoint_iff_inter_eq_empty, Ici_inter_Iic, Icc_eq_empty_iff]
@[simp]
theorem Iic_disjoint_Ici : Disjoint (Iic a) (Ici b) ↔ ¬b ≤ a :=
disjoint_comm.trans Ici_disjoint_Iic
@[simp]
theorem Ioc_disjoint_Ioi (h : b ≤ c) : Disjoint (Ioc a b) (Ioi c) :=
disjoint_left.mpr (fun _ hx hy ↦ (hx.2.trans h).not_lt hy)
theorem Ioc_disjoint_Ioi_same : Disjoint (Ioc a b) (Ioi b) :=
Ioc_disjoint_Ioi le_rfl
@[simp]
theorem iUnion_Iic : ⋃ a : α, Iic a = univ :=
iUnion_eq_univ_iff.2 fun x => ⟨x, right_mem_Iic⟩
@[simp]
theorem iUnion_Ici : ⋃ a : α, Ici a = univ :=
iUnion_eq_univ_iff.2 fun x => ⟨x, left_mem_Ici⟩
@[simp]
theorem iUnion_Icc_right (a : α) : ⋃ b, Icc a b = Ici a := by
simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ]
@[simp]
theorem iUnion_Ioc_right (a : α) : ⋃ b, Ioc a b = Ioi a := by
simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic, inter_univ]
@[simp]
theorem iUnion_Icc_left (b : α) : ⋃ a, Icc a b = Iic b := by
simp only [← Ici_inter_Iic, ← iUnion_inter, iUnion_Ici, univ_inter]
@[simp]
theorem iUnion_Ico_left (b : α) : ⋃ a, Ico a b = Iio b := by
simp only [← Ici_inter_Iio, ← iUnion_inter, iUnion_Ici, univ_inter]
@[simp]
theorem iUnion_Iio [NoMaxOrder α] : ⋃ a : α, Iio a = univ :=
iUnion_eq_univ_iff.2 exists_gt
@[simp]
theorem iUnion_Ioi [NoMinOrder α] : ⋃ a : α, Ioi a = univ :=
iUnion_eq_univ_iff.2 exists_lt
@[simp]
theorem iUnion_Ico_right [NoMaxOrder α] (a : α) : ⋃ b, Ico a b = Ici a := by
simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ]
@[simp]
theorem iUnion_Ioo_right [NoMaxOrder α] (a : α) : ⋃ b, Ioo a b = Ioi a := by
simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio, inter_univ]
@[simp]
theorem iUnion_Ioc_left [NoMinOrder α] (b : α) : ⋃ a, Ioc a b = Iic b := by
simp only [← Ioi_inter_Iic, ← iUnion_inter, iUnion_Ioi, univ_inter]
@[simp]
theorem iUnion_Ioo_left [NoMinOrder α] (b : α) : ⋃ a, Ioo a b = Iio b := by
simp only [← Ioi_inter_Iio, ← iUnion_inter, iUnion_Ioi, univ_inter]
end Preorder
section LinearOrder
variable [LinearOrder α] {a₁ a₂ b₁ b₂ : α}
@[simp]
theorem Ico_disjoint_Ico : Disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by
simp_rw [Set.disjoint_iff_inter_eq_empty, Ico_inter_Ico, Ico_eq_empty_iff, inf_eq_min, sup_eq_max,
not_lt]
@[simp]
theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by
have h : _ ↔ min (toDual a₁) (toDual b₁) ≤ max (toDual a₂) (toDual b₂) := Ico_disjoint_Ico
simpa only [dual_Ico] using h
@[simp]
theorem Ioo_disjoint_Ioo [DenselyOrdered α] :
Disjoint (Set.Ioo a₁ a₂) (Set.Ioo b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by
simp_rw [Set.disjoint_iff_inter_eq_empty, Ioo_inter_Ioo, Ioo_eq_empty_iff, inf_eq_min, sup_eq_max,
not_lt]
/-- If two half-open intervals are disjoint and the endpoint of one lies in the other,
then it must be equal to the endpoint of the other. -/
theorem eq_of_Ico_disjoint {x₁ x₂ y₁ y₂ : α} (h : Disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂)
(h2 : x₂ ∈ Ico y₁ y₂) : y₁ = x₂ := by
rw [Ico_disjoint_Ico, min_eq_left (le_of_lt h2.2), le_max_iff] at h
apply le_antisymm h2.1
exact h.elim (fun h => absurd hx (not_lt_of_le h)) id
@[simp]
theorem iUnion_Ico_eq_Iio_self_iff {f : ι → α} {a : α} :
⋃ i, Ico (f i) a = Iio a ↔ ∀ x < a, ∃ i, f i ≤ x := by
simp [← Ici_inter_Iio, ← iUnion_inter, subset_def]
@[simp]
theorem iUnion_Ioc_eq_Ioi_self_iff {f : ι → α} {a : α} :
⋃ i, Ioc a (f i) = Ioi a ↔ ∀ x, a < x → ∃ i, x ≤ f i := by
simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def]
@[simp]
theorem biUnion_Ico_eq_Iio_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} :
⋃ (i) (hi : p i), Ico (f i hi) a = Iio a ↔ ∀ x < a, ∃ i hi, f i hi ≤ x := by
simp [← Ici_inter_Iio, ← iUnion_inter, subset_def]
@[simp]
theorem biUnion_Ioc_eq_Ioi_self_iff {p : ι → Prop} {f : ∀ i, p i → α} {a : α} :
⋃ (i) (hi : p i), Ioc a (f i hi) = Ioi a ↔ ∀ x, a < x → ∃ i hi, x ≤ f i hi := by
simp [← Ioi_inter_Iic, ← inter_iUnion, subset_def]
end LinearOrder
end Set
section UnionIxx
variable [LinearOrder α] {s : Set α} {a : α} {f : ι → α}
theorem IsGLB.biUnion_Ioi_eq (h : IsGLB s a) : ⋃ x ∈ s, Ioi x = Ioi a := by
refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_
· exact Ioi_subset_Ioi (h.1 hx)
· rcases h.exists_between hx with ⟨y, hys, _, hyx⟩
exact mem_biUnion hys hyx
theorem IsGLB.iUnion_Ioi_eq (h : IsGLB (range f) a) : ⋃ x, Ioi (f x) = Ioi a :=
biUnion_range.symm.trans h.biUnion_Ioi_eq
theorem IsLUB.biUnion_Iio_eq (h : IsLUB s a) : ⋃ x ∈ s, Iio x = Iio a :=
h.dual.biUnion_Ioi_eq
theorem IsLUB.iUnion_Iio_eq (h : IsLUB (range f) a) : ⋃ x, Iio (f x) = Iio a :=
h.dual.iUnion_Ioi_eq
theorem IsGLB.biUnion_Ici_eq_Ioi (a_glb : IsGLB s a) (a_not_mem : a ∉ s) :
⋃ x ∈ s, Ici x = Ioi a := by
refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_
· exact Ici_subset_Ioi.mpr (lt_of_le_of_ne (a_glb.1 hx) fun h => (h ▸ a_not_mem) hx)
· rcases a_glb.exists_between hx with ⟨y, hys, _, hyx⟩
rw [mem_iUnion₂]
exact ⟨y, hys, hyx.le⟩
theorem IsGLB.biUnion_Ici_eq_Ici (a_glb : IsGLB s a) (a_mem : a ∈ s) :
⋃ x ∈ s, Ici x = Ici a := by
refine (iUnion₂_subset fun x hx => ?_).antisymm fun x hx => ?_
· exact Ici_subset_Ici.mpr (mem_lowerBounds.mp a_glb.1 x hx)
· exact mem_iUnion₂.mpr ⟨a, a_mem, hx⟩
theorem IsLUB.biUnion_Iic_eq_Iio (a_lub : IsLUB s a) (a_not_mem : a ∉ s) :
⋃ x ∈ s, Iic x = Iio a :=
a_lub.dual.biUnion_Ici_eq_Ioi a_not_mem
theorem IsLUB.biUnion_Iic_eq_Iic (a_lub : IsLUB s a) (a_mem : a ∈ s) : ⋃ x ∈ s, Iic x = Iic a :=
a_lub.dual.biUnion_Ici_eq_Ici a_mem
theorem iUnion_Ici_eq_Ioi_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R}
(no_least_elem : ⨅ i, f i ∉ range f) : ⋃ i : ι, Ici (f i) = Ioi (⨅ i, f i) := by
simp only [← IsGLB.biUnion_Ici_eq_Ioi (@isGLB_iInf _ _ _ f) no_least_elem, mem_range,
iUnion_exists, iUnion_iUnion_eq']
theorem iUnion_Iic_eq_Iio_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R}
(no_greatest_elem : (⨆ i, f i) ∉ range f) : ⋃ i : ι, Iic (f i) = Iio (⨆ i, f i) :=
@iUnion_Ici_eq_Ioi_iInf ι (OrderDual R) _ f no_greatest_elem
theorem iUnion_Ici_eq_Ici_iInf {R : Type*} [CompleteLinearOrder R] {f : ι → R}
(has_least_elem : (⨅ i, f i) ∈ range f) : ⋃ i : ι, Ici (f i) = Ici (⨅ i, f i) := by
simp only [← IsGLB.biUnion_Ici_eq_Ici (@isGLB_iInf _ _ _ f) has_least_elem, mem_range,
iUnion_exists, iUnion_iUnion_eq']
theorem iUnion_Iic_eq_Iic_iSup {R : Type*} [CompleteLinearOrder R] {f : ι → R}
(has_greatest_elem : (⨆ i, f i) ∈ range f) : ⋃ i : ι, Iic (f i) = Iic (⨆ i, f i) :=
@iUnion_Ici_eq_Ici_iInf ι (OrderDual R) _ f has_greatest_elem
theorem iUnion_Iio_eq_univ_iff : ⋃ i, Iio (f i) = univ ↔ (¬ BddAbove (range f)) := by
simp [not_bddAbove_iff, Set.eq_univ_iff_forall]
theorem iUnion_Iic_of_not_bddAbove_range (hf : ¬ BddAbove (range f)) : ⋃ i, Iic (f i) = univ := by
refine Set.eq_univ_of_subset ?_ (iUnion_Iio_eq_univ_iff.mpr hf)
gcongr
exact Iio_subset_Iic_self
theorem iInter_Iic_eq_empty_iff : ⋂ i, Iic (f i) = ∅ ↔ ¬ BddBelow (range f) := by
simp [not_bddBelow_iff, Set.eq_empty_iff_forall_not_mem]
theorem iInter_Iio_of_not_bddBelow_range (hf : ¬ BddBelow (range f)) : ⋂ i, Iio (f i) = ∅ := by
refine eq_empty_of_subset_empty ?_
rw [← iInter_Iic_eq_empty_iff.mpr hf]
gcongr
exact Iio_subset_Iic_self
end UnionIxx
|
Order\Interval\Set\Image.lean | /-
Copyright (c) 2023 Kim Liesinger. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Liesinger, Yaël Dillies
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.Function
import Mathlib.Order.Directed
/-!
# Monotone functions on intervals
This file shows many variants of the fact that a monotone function `f` sends an interval with
endpoints `a` and `b` to the interval with endpoints `f a` and `f b`.
-/
variable {α β : Type*} {f : α → β}
open Set
section Preorder
variable [Preorder α] [Preorder β] {a b : α}
lemma MonotoneOn.mapsTo_Ici (h : MonotoneOn f (Ici a)) : MapsTo f (Ici a) (Ici (f a)) :=
fun _ _ ↦ by aesop
lemma MonotoneOn.mapsTo_Iic (h : MonotoneOn f (Iic b)) : MapsTo f (Iic b) (Iic (f b)) :=
fun _ _ ↦ by aesop
lemma MonotoneOn.mapsTo_Icc (h : MonotoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f a) (f b)) :=
fun _c hc ↦
⟨h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1, h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2⟩
lemma AntitoneOn.mapsTo_Ici (h : AntitoneOn f (Ici a)) : MapsTo f (Ici a) (Iic (f a)) :=
fun _ _ ↦ by aesop
lemma AntitoneOn.mapsTo_Iic (h : AntitoneOn f (Iic b)) : MapsTo f (Iic b) (Ici (f b)) :=
fun _ _ ↦ by aesop
lemma AntitoneOn.mapsTo_Icc (h : AntitoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f b) (f a)) :=
fun _c hc ↦
⟨h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1⟩
lemma StrictMonoOn.mapsTo_Ioi (h : StrictMonoOn f (Ici a)) : MapsTo f (Ioi a) (Ioi (f a)) :=
fun _c hc ↦ h le_rfl hc.le hc
lemma StrictMonoOn.mapsTo_Iio (h : StrictMonoOn f (Iic b)) : MapsTo f (Iio b) (Iio (f b)) :=
fun _c hc ↦ h hc.le le_rfl hc
lemma StrictMonoOn.mapsTo_Ioo (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ioo a b) (Ioo (f a) (f b)) :=
fun _c hc ↦
⟨h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1,
h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2⟩
lemma StrictAntiOn.mapsTo_Ioi (h : StrictAntiOn f (Ici a)) : MapsTo f (Ioi a) (Iio (f a)) :=
fun _c hc ↦ h le_rfl hc.le hc
lemma StrictAntiOn.mapsTo_Iio (h : StrictAntiOn f (Iic b)) : MapsTo f (Iio b) (Ioi (f b)) :=
fun _c hc ↦ h hc.le le_rfl hc
lemma StrictAntiOn.mapsTo_Ioo (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ioo a b) (Ioo (f b) (f a)) :=
fun _c hc ↦
⟨h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2,
h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1⟩
lemma Monotone.mapsTo_Ici (h : Monotone f) : MapsTo f (Ici a) (Ici (f a)) :=
(h.monotoneOn _).mapsTo_Ici
lemma Monotone.mapsTo_Iic (h : Monotone f) : MapsTo f (Iic b) (Iic (f b)) :=
(h.monotoneOn _).mapsTo_Iic
lemma Monotone.mapsTo_Icc (h : Monotone f) : MapsTo f (Icc a b) (Icc (f a) (f b)) :=
(h.monotoneOn _).mapsTo_Icc
lemma Antitone.mapsTo_Ici (h : Antitone f) : MapsTo f (Ici a) (Iic (f a)) :=
(h.antitoneOn _).mapsTo_Ici
lemma Antitone.mapsTo_Iic (h : Antitone f) : MapsTo f (Iic b) (Ici (f b)) :=
(h.antitoneOn _).mapsTo_Iic
lemma Antitone.mapsTo_Icc (h : Antitone f) : MapsTo f (Icc a b) (Icc (f b) (f a)) :=
(h.antitoneOn _).mapsTo_Icc
lemma StrictMono.mapsTo_Ioi (h : StrictMono f) : MapsTo f (Ioi a) (Ioi (f a)) :=
(h.strictMonoOn _).mapsTo_Ioi
lemma StrictMono.mapsTo_Iio (h : StrictMono f) : MapsTo f (Iio b) (Iio (f b)) :=
(h.strictMonoOn _).mapsTo_Iio
lemma StrictMono.mapsTo_Ioo (h : StrictMono f) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ioo
lemma StrictAnti.mapsTo_Ioi (h : StrictAnti f) : MapsTo f (Ioi a) (Iio (f a)) :=
(h.strictAntiOn _).mapsTo_Ioi
lemma StrictAnti.mapsTo_Iio (h : StrictAnti f) : MapsTo f (Iio b) (Ioi (f b)) :=
(h.strictAntiOn _).mapsTo_Iio
lemma StrictAnti.mapsTo_Ioo (h : StrictAnti f) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ioo
lemma MonotoneOn.image_Ici_subset (h : MonotoneOn f (Ici a)) : f '' Ici a ⊆ Ici (f a) :=
h.mapsTo_Ici.image_subset
lemma MonotoneOn.image_Iic_subset (h : MonotoneOn f (Iic b)) : f '' Iic b ⊆ Iic (f b) :=
h.mapsTo_Iic.image_subset
lemma MonotoneOn.image_Icc_subset (h : MonotoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f a) (f b) :=
h.mapsTo_Icc.image_subset
lemma AntitoneOn.image_Ici_subset (h : AntitoneOn f (Ici a)) : f '' Ici a ⊆ Iic (f a) :=
h.mapsTo_Ici.image_subset
lemma AntitoneOn.image_Iic_subset (h : AntitoneOn f (Iic b)) : f '' Iic b ⊆ Ici (f b) :=
h.mapsTo_Iic.image_subset
lemma AntitoneOn.image_Icc_subset (h : AntitoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f b) (f a) :=
h.mapsTo_Icc.image_subset
lemma StrictMonoOn.image_Ioi_subset (h : StrictMonoOn f (Ici a)) : f '' Ioi a ⊆ Ioi (f a) :=
h.mapsTo_Ioi.image_subset
lemma StrictMonoOn.image_Iio_subset (h : StrictMonoOn f (Iic b)) : f '' Iio b ⊆ Iio (f b) :=
h.mapsTo_Iio.image_subset
lemma StrictMonoOn.image_Ioo_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ioo a b ⊆ Ioo (f a) (f b) := h.mapsTo_Ioo.image_subset
lemma StrictAntiOn.image_Ioi_subset (h : StrictAntiOn f (Ici a)) : f '' Ioi a ⊆ Iio (f a) :=
h.mapsTo_Ioi.image_subset
lemma StrictAntiOn.image_Iio_subset (h : StrictAntiOn f (Iic b)) : f '' Iio b ⊆ Ioi (f b) :=
h.mapsTo_Iio.image_subset
lemma StrictAntiOn.image_Ioo_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ioo a b ⊆ Ioo (f b) (f a) := h.mapsTo_Ioo.image_subset
lemma Monotone.image_Ici_subset (h : Monotone f) : f '' Ici a ⊆ Ici (f a) :=
(h.monotoneOn _).image_Ici_subset
lemma Monotone.image_Iic_subset (h : Monotone f) : f '' Iic b ⊆ Iic (f b) :=
(h.monotoneOn _).image_Iic_subset
lemma Monotone.image_Icc_subset (h : Monotone f) : f '' Icc a b ⊆ Icc (f a) (f b) :=
(h.monotoneOn _).image_Icc_subset
lemma Antitone.image_Ici_subset (h : Antitone f) : f '' Ici a ⊆ Iic (f a) :=
(h.antitoneOn _).image_Ici_subset
lemma Antitone.image_Iic_subset (h : Antitone f) : f '' Iic b ⊆ Ici (f b) :=
(h.antitoneOn _).image_Iic_subset
lemma Antitone.image_Icc_subset (h : Antitone f) : f '' Icc a b ⊆ Icc (f b) (f a) :=
(h.antitoneOn _).image_Icc_subset
lemma StrictMono.image_Ioi_subset (h : StrictMono f) : f '' Ioi a ⊆ Ioi (f a) :=
(h.strictMonoOn _).image_Ioi_subset
lemma StrictMono.image_Iio_subset (h : StrictMono f) : f '' Iio b ⊆ Iio (f b) :=
(h.strictMonoOn _).image_Iio_subset
lemma StrictMono.image_Ioo_subset (h : StrictMono f) : f '' Ioo a b ⊆ Ioo (f a) (f b) :=
(h.strictMonoOn _).image_Ioo_subset
lemma StrictAnti.image_Ioi_subset (h : StrictAnti f) : f '' Ioi a ⊆ Iio (f a) :=
(h.strictAntiOn _).image_Ioi_subset
lemma StrictAnti.image_Iio_subset (h : StrictAnti f) : f '' Iio b ⊆ Ioi (f b) :=
(h.strictAntiOn _).image_Iio_subset
lemma StrictAnti.image_Ioo_subset (h : StrictAnti f) : f '' Ioo a b ⊆ Ioo (f b) (f a) :=
(h.strictAntiOn _).image_Ioo_subset
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β] {a b : α}
lemma StrictMonoOn.mapsTo_Ico (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ico a b) (Ico (f a) (f b)) :=
fun _c hc ↦ ⟨h.monotoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1,
h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2⟩
lemma StrictMonoOn.mapsTo_Ioc (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ioc a b) (Ioc (f a) (f b)) :=
fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1,
h.monotoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2⟩
lemma StrictAntiOn.mapsTo_Ico (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ico a b) (Ioc (f b) (f a)) :=
fun _c hc ↦ ⟨h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2,
h.antitoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1⟩
lemma StrictAntiOn.mapsTo_Ioc (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ioc a b) (Ico (f b) (f a)) :=
fun _c hc ↦ ⟨h.antitoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2,
h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1⟩
lemma StrictMono.mapsTo_Ico (h : StrictMono f) : MapsTo f (Ico a b) (Ico (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ico
lemma StrictMono.mapsTo_Ioc (h : StrictMono f) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ioc
lemma StrictAnti.mapsTo_Ico (h : StrictAnti f) : MapsTo f (Ico a b) (Ioc (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ico
lemma StrictAnti.mapsTo_Ioc (h : StrictAnti f) : MapsTo f (Ioc a b) (Ico (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ioc
lemma StrictMonoOn.image_Ico_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ico a b ⊆ Ico (f a) (f b) := h.mapsTo_Ico.image_subset
lemma StrictMonoOn.image_Ioc_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ioc a b ⊆ Ioc (f a) (f b) :=
h.mapsTo_Ioc.image_subset
lemma StrictAntiOn.image_Ico_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ico a b ⊆ Ioc (f b) (f a) := h.mapsTo_Ico.image_subset
lemma StrictAntiOn.image_Ioc_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ioc a b ⊆ Ico (f b) (f a) := h.mapsTo_Ioc.image_subset
lemma StrictMono.image_Ico_subset (h : StrictMono f) : f '' Ico a b ⊆ Ico (f a) (f b) :=
(h.strictMonoOn _).image_Ico_subset
lemma StrictMono.image_Ioc_subset (h : StrictMono f) : f '' Ioc a b ⊆ Ioc (f a) (f b) :=
(h.strictMonoOn _).image_Ioc_subset
lemma StrictAnti.image_Ico_subset (h : StrictAnti f) : f '' Ico a b ⊆ Ioc (f b) (f a) :=
(h.strictAntiOn _).image_Ico_subset
lemma StrictAnti.image_Ioc_subset (h : StrictAnti f) : f '' Ioc a b ⊆ Ico (f b) (f a) :=
(h.strictAntiOn _).image_Ioc_subset
end PartialOrder
namespace Set
private lemma image_subtype_val_Ixx_Ixi {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b})
(h : ∀ {x}, r c x → p a x) :
Subtype.val '' {y : {x // p a x ∧ q x b} | r c.1 y.1} = {y : α | r c.1 y ∧ q y b} :=
(Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r c.1 y}).trans <| by
ext; simp (config := { contextual := true }) [@and_comm (r _ _), h]
private lemma image_subtype_val_Ixx_Iix {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b})
(h : ∀ {x}, r x c → q x b) :
Subtype.val '' {y : {x // p a x ∧ q x b} | r y.1 c.1} = {y : α | p a y ∧ r y c.1} :=
(Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r y c.1}).trans <| by
ext; simp (config := { contextual := true}) [h]
variable [Preorder α] {p : α → Prop}
@[simp] lemma preimage_subtype_val_Ici (a : {x // p x}) : (↑) ⁻¹' (Ici a.1) = Ici a := rfl
@[simp] lemma preimage_subtype_val_Iic (a : {x // p x}) : (↑) ⁻¹' (Iic a.1) = Iic a := rfl
@[simp] lemma preimage_subtype_val_Ioi (a : {x // p x}) : (↑) ⁻¹' (Ioi a.1) = Ioi a := rfl
@[simp] lemma preimage_subtype_val_Iio (a : {x // p x}) : (↑) ⁻¹' (Iio a.1) = Iio a := rfl
@[simp] lemma preimage_subtype_val_Icc (a b : {x // p x}) : (↑) ⁻¹' (Icc a.1 b) = Icc a b := rfl
@[simp] lemma preimage_subtype_val_Ico (a b : {x // p x}) : (↑) ⁻¹' (Ico a.1 b) = Ico a b := rfl
@[simp] lemma preimage_subtype_val_Ioc (a b : {x // p x}) : (↑) ⁻¹' (Ioc a.1 b) = Ioc a b := rfl
@[simp] lemma preimage_subtype_val_Ioo (a b : {x // p x}) : (↑) ⁻¹' (Ioo a.1 b) = Ioo a b := rfl
theorem image_subtype_val_Icc_subset (a b : {x // p x}) :
Subtype.val '' Icc a b ⊆ Icc a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ico_subset (a b : {x // p x}) :
Subtype.val '' Ico a b ⊆ Ico a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioc_subset (a b : {x // p x}) :
Subtype.val '' Ioc a b ⊆ Ioc a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioo_subset (a b : {x // p x}) :
Subtype.val '' Ioo a b ⊆ Ioo a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Iic_subset (a : {x // p x}) :
Subtype.val '' Iic a ⊆ Iic a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Iio_subset (a : {x // p x}) :
Subtype.val '' Iio a ⊆ Iio a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ici_subset (a : {x // p x}) :
Subtype.val '' Ici a ⊆ Ici a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioi_subset (a : {x // p x}) :
Subtype.val '' Ioi a ⊆ Ioi a.val :=
image_subset_iff.mpr fun _ m => m
@[simp]
lemma image_subtype_val_Ici_Iic {a : α} (b : Ici a) : Subtype.val '' Iic b = Icc a b :=
(Subtype.image_preimage_val (Ici a) (Iic b.1)).trans Ici_inter_Iic
@[simp]
lemma image_subtype_val_Ici_Iio {a : α} (b : Ici a) : Subtype.val '' Iio b = Ico a b :=
(Subtype.image_preimage_val (Ici a) (Iio b.1)).trans Ici_inter_Iio
@[simp]
lemma image_subtype_val_Ici_Ici {a : α} (b : Ici a) : Subtype.val '' Ici b = Ici b.1 :=
(Subtype.image_preimage_val (Ici a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ici.2 b.2
@[simp]
lemma image_subtype_val_Ici_Ioi {a : α} (b : Ici a) : Subtype.val '' Ioi b = Ioi b.1 :=
(Subtype.image_preimage_val (Ici a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ici b.2
@[simp]
lemma image_subtype_val_Iic_Ici {a : α} (b : Iic a) : Subtype.val '' Ici b = Icc b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iic_Ioi {a : α} (b : Iic a) : Subtype.val '' Ioi b = Ioc b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iic_Iic {a : α} (b : Iic a) : Subtype.val '' Iic b = Iic b.1 :=
image_subtype_val_Ici_Ici (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Iic_Iio {a : α} (b : Iic a) : Subtype.val '' Iio b = Iio b.1 :=
image_subtype_val_Ici_Ioi (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Ioi_Ici {a : α} (b : Ioi a) : Subtype.val '' Ici b = Ici b.1 :=
(Subtype.image_preimage_val (Ioi a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ioi.2 b.2
@[simp]
lemma image_subtype_val_Ioi_Iic {a : α} (b : Ioi a) : Subtype.val '' Iic b = Ioc a b :=
(Subtype.image_preimage_val (Ioi a) (Iic b.1)).trans Ioi_inter_Iic
@[simp]
lemma image_subtype_val_Ioi_Ioi {a : α} (b : Ioi a) : Subtype.val '' Ioi b = Ioi b.1 :=
(Subtype.image_preimage_val (Ioi a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ioi b.2.le
@[simp]
lemma image_subtype_val_Ioi_Iio {a : α} (b : Ioi a) : Subtype.val '' Iio b = Ioo a b :=
(Subtype.image_preimage_val (Ioi a) (Iio b.1)).trans Ioi_inter_Iio
@[simp]
lemma image_subtype_val_Iio_Ici {a : α} (b : Iio a) : Subtype.val '' Ici b = Ico b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iio_Iic {a : α} (b : Iio a) : Subtype.val '' Iic b = Iic b.1 :=
image_subtype_val_Ioi_Ici (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Iio_Ioi {a : α} (b : Iio a) : Subtype.val '' Ioi b = Ioo b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iio_Iio {a : α} (b : Iio a) : Subtype.val '' Iio b = Iio b.1 :=
image_subtype_val_Ioi_Ioi (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Icc_Ici {a b : α} (c : Icc a b) : Subtype.val '' Ici c = Icc c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans
@[simp]
lemma image_subtype_val_Icc_Iic {a b : α} (c : Icc a b) : Subtype.val '' Iic c = Icc a c :=
image_subtype_val_Ixx_Iix c (le_trans · c.2.2)
@[simp]
lemma image_subtype_val_Icc_Ioi {a b : α} (c : Icc a b) : Subtype.val '' Ioi c = Ioc c.1 b :=
image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·)
@[simp]
lemma image_subtype_val_Icc_Iio {a b : α} (c : Icc a b) : Subtype.val '' Iio c = Ico a c :=
image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2
@[simp]
lemma image_subtype_val_Ico_Ici {a b : α} (c : Ico a b) : Subtype.val '' Ici c = Ico c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans
@[simp]
lemma image_subtype_val_Ico_Iic {a b : α} (c : Ico a b) : Subtype.val '' Iic c = Icc a c :=
image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2)
@[simp]
lemma image_subtype_val_Ico_Ioi {a b : α} (c : Ico a b) : Subtype.val '' Ioi c = Ioo c.1 b :=
image_subtype_val_Ixx_Ixi c (c.2.1.trans <| le_of_lt ·)
@[simp]
lemma image_subtype_val_Ico_Iio {a b : α} (c : Ico a b) : Subtype.val '' Iio c = Ico a c :=
image_subtype_val_Ixx_Iix c (lt_trans · c.2.2)
@[simp]
lemma image_subtype_val_Ioc_Ici {a b : α} (c : Ioc a b) : Subtype.val '' Ici c = Icc c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans_le
@[simp]
lemma image_subtype_val_Ioc_Iic {a b : α} (c : Ioc a b) : Subtype.val '' Iic c = Ioc a c :=
image_subtype_val_Ixx_Iix c (le_trans · c.2.2)
@[simp]
lemma image_subtype_val_Ioc_Ioi {a b : α} (c : Ioc a b) : Subtype.val '' Ioi c = Ioc c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans
@[simp]
lemma image_subtype_val_Ioc_Iio {a b : α} (c : Ioc a b) : Subtype.val '' Iio c = Ioo a c :=
image_subtype_val_Ixx_Iix c fun h ↦ (le_of_lt h).trans c.2.2
@[simp]
lemma image_subtype_val_Ioo_Ici {a b : α} (c : Ioo a b) : Subtype.val '' Ici c = Ico c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans_le
@[simp]
lemma image_subtype_val_Ioo_Iic {a b : α} (c : Ioo a b) : Subtype.val '' Iic c = Ioc a c :=
image_subtype_val_Ixx_Iix c (lt_of_le_of_lt · c.2.2)
@[simp]
lemma image_subtype_val_Ioo_Ioi {a b : α} (c : Ioo a b) : Subtype.val '' Ioi c = Ioo c.1 b :=
image_subtype_val_Ixx_Ixi c c.2.1.trans
@[simp]
lemma image_subtype_val_Ioo_Iio {a b : α} (c : Ioo a b) : Subtype.val '' Iio c = Ioo a c :=
image_subtype_val_Ixx_Iix c (lt_trans · c.2.2)
end Set
section Preorder
variable [Preorder α]
lemma directedOn_le_Iic (b : α) : DirectedOn (· ≤ ·) (Iic b) :=
fun _x hx _y hy ↦ ⟨b, le_rfl, hx, hy⟩
lemma directedOn_le_Icc (a b : α) : DirectedOn (· ≤ ·) (Icc a b) :=
fun _x hx _y hy ↦ ⟨b, right_mem_Icc.2 $ hx.1.trans hx.2, hx.2, hy.2⟩
lemma directedOn_le_Ioc (a b : α) : DirectedOn (· ≤ ·) (Ioc a b) :=
fun _x hx _y hy ↦ ⟨b, right_mem_Ioc.2 $ hx.1.trans_le hx.2, hx.2, hy.2⟩
lemma directedOn_ge_Ici (a : α) : DirectedOn (· ≥ ·) (Ici a) :=
fun _x hx _y hy ↦ ⟨a, le_rfl, hx, hy⟩
lemma directedOn_ge_Icc (a b : α) : DirectedOn (· ≥ ·) (Icc a b) :=
fun _x hx _y hy ↦ ⟨a, left_mem_Icc.2 $ hx.1.trans hx.2, hx.1, hy.1⟩
lemma directedOn_ge_Ico (a b : α) : DirectedOn (· ≥ ·) (Ico a b) :=
fun _x hx _y hy ↦ ⟨a, left_mem_Ico.2 $ hx.1.trans_lt hx.2, hx.1, hy.1⟩
end Preorder
|
Order\Interval\Set\Infinite.lean | /-
Copyright (c) 2020 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import Mathlib.Data.Set.Finite
/-!
# Infinitude of intervals
Bounded intervals in dense orders are infinite, as are unbounded intervals
in orders that are unbounded on the appropriate side. We also prove that an unbounded
preorder is an infinite type.
-/
variable {α : Type*} [Preorder α]
/-- A nonempty preorder with no maximal element is infinite. This is not an instance to avoid
a cycle with `Infinite α → Nontrivial α → Nonempty α`. -/
theorem NoMaxOrder.infinite [Nonempty α] [NoMaxOrder α] : Infinite α :=
let ⟨f, hf⟩ := Nat.exists_strictMono α
Infinite.of_injective f hf.injective
/-- A nonempty preorder with no minimal element is infinite. This is not an instance to avoid
a cycle with `Infinite α → Nontrivial α → Nonempty α`. -/
theorem NoMinOrder.infinite [Nonempty α] [NoMinOrder α] : Infinite α :=
@NoMaxOrder.infinite αᵒᵈ _ _ _
namespace Set
section DenselyOrdered
variable [DenselyOrdered α] {a b : α} (h : a < b)
theorem Ioo.infinite : Infinite (Ioo a b) :=
@NoMaxOrder.infinite _ _ (nonempty_Ioo_subtype h) _
theorem Ioo_infinite : (Ioo a b).Infinite :=
infinite_coe_iff.1 <| Ioo.infinite h
theorem Ico_infinite : (Ico a b).Infinite :=
(Ioo_infinite h).mono Ioo_subset_Ico_self
theorem Ico.infinite : Infinite (Ico a b) :=
infinite_coe_iff.2 <| Ico_infinite h
theorem Ioc_infinite : (Ioc a b).Infinite :=
(Ioo_infinite h).mono Ioo_subset_Ioc_self
theorem Ioc.infinite : Infinite (Ioc a b) :=
infinite_coe_iff.2 <| Ioc_infinite h
theorem Icc_infinite : (Icc a b).Infinite :=
(Ioo_infinite h).mono Ioo_subset_Icc_self
theorem Icc.infinite : Infinite (Icc a b) :=
infinite_coe_iff.2 <| Icc_infinite h
end DenselyOrdered
instance [NoMinOrder α] {a : α} : Infinite (Iio a) :=
NoMinOrder.infinite
theorem Iio_infinite [NoMinOrder α] (a : α) : (Iio a).Infinite :=
infinite_coe_iff.1 inferInstance
instance [NoMinOrder α] {a : α} : Infinite (Iic a) :=
NoMinOrder.infinite
theorem Iic_infinite [NoMinOrder α] (a : α) : (Iic a).Infinite :=
infinite_coe_iff.1 inferInstance
instance [NoMaxOrder α] {a : α} : Infinite (Ioi a) :=
NoMaxOrder.infinite
theorem Ioi_infinite [NoMaxOrder α] (a : α) : (Ioi a).Infinite :=
infinite_coe_iff.1 inferInstance
instance [NoMaxOrder α] {a : α} : Infinite (Ici a) :=
NoMaxOrder.infinite
theorem Ici_infinite [NoMaxOrder α] (a : α) : (Ici a).Infinite :=
infinite_coe_iff.1 inferInstance
end Set
|
Order\Interval\Set\IsoIoo.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Monotone.Odd
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Tactic.FieldSimp
/-!
# Order isomorphism between a linear ordered field and `(-1, 1)`
In this file we provide an order isomorphism `orderIsoIooNegOneOne` between the open interval
`(-1, 1)` in a linear ordered field and the whole field.
-/
/- Porting note: `Mathlib.Algebra.Order.Field.Basic` added to imports for `abs` -/
open Set
/- Porting note: Had to manually coerce `x : Ioo (-1 : k) 1` to `x : k`. -/
/-- In a linear ordered field, the whole field is order isomorphic to the open interval `(-1, 1)`.
We consider the actual implementation to be a "black box", so it is irreducible.
-/
@[irreducible]
def orderIsoIooNegOneOne (k : Type*) [LinearOrderedField k] : k ≃o Ioo (-1 : k) 1 := by
refine StrictMono.orderIsoOfRightInverse ?_ ?_ (fun x ↦ x / (1 - |↑x|)) ?_
· refine codRestrict (fun x ↦ x / (1 + |x|)) _ fun x ↦ abs_lt.1 ?_
have H : 0 < 1 + |x| := (abs_nonneg x).trans_lt (lt_one_add _)
calc
|x / (1 + |x|)| = |x| / (1 + |x|) := by rw [abs_div, abs_of_pos H]
_ < 1 := (div_lt_one H).2 (lt_one_add _)
· refine (strictMono_of_odd_strictMonoOn_nonneg ?_ ?_).codRestrict _
· intro x
simp only [abs_neg, neg_div]
· rintro x (hx : 0 ≤ x) y (hy : 0 ≤ y) hxy
simp [abs_of_nonneg, mul_add, mul_comm x y, div_lt_div_iff, hx.trans_lt (lt_one_add _),
hy.trans_lt (lt_one_add _), *]
· refine fun x ↦ Subtype.ext ?_
have : 0 < 1 - |(x : k)| := sub_pos.2 (abs_lt.2 x.2)
field_simp [abs_div, this.ne', abs_of_pos this]
|
Order\Interval\Set\Monotone.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.Disjoint
import Mathlib.Order.SuccPred.Basic
/-!
# Monotonicity on intervals
In this file we prove that `Set.Ici` etc are monotone/antitone functions. We also prove some lemmas
about functions monotone on intervals in `SuccOrder`s.
-/
open Set
section Ixx
variable {α β : Type*} [Preorder α] [Preorder β] {f g : α → β} {s : Set α}
theorem antitone_Ici : Antitone (Ici : α → Set α) := fun _ _ => Ici_subset_Ici.2
theorem monotone_Iic : Monotone (Iic : α → Set α) := fun _ _ => Iic_subset_Iic.2
theorem antitone_Ioi : Antitone (Ioi : α → Set α) := fun _ _ => Ioi_subset_Ioi
theorem monotone_Iio : Monotone (Iio : α → Set α) := fun _ _ => Iio_subset_Iio
protected theorem Monotone.Ici (hf : Monotone f) : Antitone fun x => Ici (f x) :=
antitone_Ici.comp_monotone hf
protected theorem MonotoneOn.Ici (hf : MonotoneOn f s) : AntitoneOn (fun x => Ici (f x)) s :=
antitone_Ici.comp_monotoneOn hf
protected theorem Antitone.Ici (hf : Antitone f) : Monotone fun x => Ici (f x) :=
antitone_Ici.comp hf
protected theorem AntitoneOn.Ici (hf : AntitoneOn f s) : MonotoneOn (fun x => Ici (f x)) s :=
antitone_Ici.comp_antitoneOn hf
protected theorem Monotone.Iic (hf : Monotone f) : Monotone fun x => Iic (f x) :=
monotone_Iic.comp hf
protected theorem MonotoneOn.Iic (hf : MonotoneOn f s) : MonotoneOn (fun x => Iic (f x)) s :=
monotone_Iic.comp_monotoneOn hf
protected theorem Antitone.Iic (hf : Antitone f) : Antitone fun x => Iic (f x) :=
monotone_Iic.comp_antitone hf
protected theorem AntitoneOn.Iic (hf : AntitoneOn f s) : AntitoneOn (fun x => Iic (f x)) s :=
monotone_Iic.comp_antitoneOn hf
protected theorem Monotone.Ioi (hf : Monotone f) : Antitone fun x => Ioi (f x) :=
antitone_Ioi.comp_monotone hf
protected theorem MonotoneOn.Ioi (hf : MonotoneOn f s) : AntitoneOn (fun x => Ioi (f x)) s :=
antitone_Ioi.comp_monotoneOn hf
protected theorem Antitone.Ioi (hf : Antitone f) : Monotone fun x => Ioi (f x) :=
antitone_Ioi.comp hf
protected theorem AntitoneOn.Ioi (hf : AntitoneOn f s) : MonotoneOn (fun x => Ioi (f x)) s :=
antitone_Ioi.comp_antitoneOn hf
protected theorem Monotone.Iio (hf : Monotone f) : Monotone fun x => Iio (f x) :=
monotone_Iio.comp hf
protected theorem MonotoneOn.Iio (hf : MonotoneOn f s) : MonotoneOn (fun x => Iio (f x)) s :=
monotone_Iio.comp_monotoneOn hf
protected theorem Antitone.Iio (hf : Antitone f) : Antitone fun x => Iio (f x) :=
monotone_Iio.comp_antitone hf
protected theorem AntitoneOn.Iio (hf : AntitoneOn f s) : AntitoneOn (fun x => Iio (f x)) s :=
monotone_Iio.comp_antitoneOn hf
protected theorem Monotone.Icc (hf : Monotone f) (hg : Antitone g) :
Antitone fun x => Icc (f x) (g x) :=
hf.Ici.inter hg.Iic
protected theorem MonotoneOn.Icc (hf : MonotoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => Icc (f x) (g x)) s :=
hf.Ici.inter hg.Iic
protected theorem Antitone.Icc (hf : Antitone f) (hg : Monotone g) :
Monotone fun x => Icc (f x) (g x) :=
hf.Ici.inter hg.Iic
protected theorem AntitoneOn.Icc (hf : AntitoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => Icc (f x) (g x)) s :=
hf.Ici.inter hg.Iic
protected theorem Monotone.Ico (hf : Monotone f) (hg : Antitone g) :
Antitone fun x => Ico (f x) (g x) :=
hf.Ici.inter hg.Iio
protected theorem MonotoneOn.Ico (hf : MonotoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => Ico (f x) (g x)) s :=
hf.Ici.inter hg.Iio
protected theorem Antitone.Ico (hf : Antitone f) (hg : Monotone g) :
Monotone fun x => Ico (f x) (g x) :=
hf.Ici.inter hg.Iio
protected theorem AntitoneOn.Ico (hf : AntitoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => Ico (f x) (g x)) s :=
hf.Ici.inter hg.Iio
protected theorem Monotone.Ioc (hf : Monotone f) (hg : Antitone g) :
Antitone fun x => Ioc (f x) (g x) :=
hf.Ioi.inter hg.Iic
protected theorem MonotoneOn.Ioc (hf : MonotoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => Ioc (f x) (g x)) s :=
hf.Ioi.inter hg.Iic
protected theorem Antitone.Ioc (hf : Antitone f) (hg : Monotone g) :
Monotone fun x => Ioc (f x) (g x) :=
hf.Ioi.inter hg.Iic
protected theorem AntitoneOn.Ioc (hf : AntitoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => Ioc (f x) (g x)) s :=
hf.Ioi.inter hg.Iic
protected theorem Monotone.Ioo (hf : Monotone f) (hg : Antitone g) :
Antitone fun x => Ioo (f x) (g x) :=
hf.Ioi.inter hg.Iio
protected theorem MonotoneOn.Ioo (hf : MonotoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => Ioo (f x) (g x)) s :=
hf.Ioi.inter hg.Iio
protected theorem Antitone.Ioo (hf : Antitone f) (hg : Monotone g) :
Monotone fun x => Ioo (f x) (g x) :=
hf.Ioi.inter hg.Iio
protected theorem AntitoneOn.Ioo (hf : AntitoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => Ioo (f x) (g x)) s :=
hf.Ioi.inter hg.Iio
end Ixx
section iUnion
variable {α β : Type*} [SemilatticeSup α] [LinearOrder β] {f g : α → β} {a b : β}
theorem iUnion_Ioo_of_mono_of_isGLB_of_isLUB (hf : Antitone f) (hg : Monotone g)
(ha : IsGLB (range f) a) (hb : IsLUB (range g) b) : ⋃ x, Ioo (f x) (g x) = Ioo a b :=
calc
⋃ x, Ioo (f x) (g x) = (⋃ x, Ioi (f x)) ∩ ⋃ x, Iio (g x) :=
iUnion_inter_of_monotone hf.Ioi hg.Iio
_ = Ioi a ∩ Iio b := congr_arg₂ (· ∩ ·) ha.iUnion_Ioi_eq hb.iUnion_Iio_eq
end iUnion
section SuccOrder
open Order
variable {α β : Type*} [PartialOrder α]
theorem StrictMonoOn.Iic_id_le [SuccOrder α] [IsSuccArchimedean α] [OrderBot α] {n : α} {φ : α → α}
(hφ : StrictMonoOn φ (Set.Iic n)) : ∀ m ≤ n, m ≤ φ m := by
revert hφ
refine
Succ.rec_bot (fun n => StrictMonoOn φ (Set.Iic n) → ∀ m ≤ n, m ≤ φ m)
(fun _ _ hm => hm.trans bot_le) ?_ _
rintro k ih hφ m hm
by_cases hk : IsMax k
· rw [succ_eq_iff_isMax.2 hk] at hm
exact ih (hφ.mono <| Iic_subset_Iic.2 (le_succ _)) _ hm
obtain rfl | h := le_succ_iff_eq_or_le.1 hm
· specialize ih (StrictMonoOn.mono hφ fun x hx => le_trans hx (le_succ _)) k le_rfl
refine le_trans (succ_mono ih) (succ_le_of_lt (hφ (le_succ _) le_rfl ?_))
rw [lt_succ_iff_eq_or_lt_of_not_isMax hk]
exact Or.inl rfl
· exact ih (StrictMonoOn.mono hφ fun x hx => le_trans hx (le_succ _)) _ h
theorem StrictMonoOn.Ici_le_id [PredOrder α] [IsPredArchimedean α] [OrderTop α] {n : α} {φ : α → α}
(hφ : StrictMonoOn φ (Set.Ici n)) : ∀ m, n ≤ m → φ m ≤ m :=
StrictMonoOn.Iic_id_le (α := αᵒᵈ) fun _ hi _ hj hij => hφ hj hi hij
variable [Preorder β] {ψ : α → β}
/-- A function `ψ` on a `SuccOrder` is strictly monotone before some `n` if for all `m` such that
`m < n`, we have `ψ m < ψ (succ m)`. -/
theorem strictMonoOn_Iic_of_lt_succ [SuccOrder α] [IsSuccArchimedean α] {n : α}
(hψ : ∀ m, m < n → ψ m < ψ (succ m)) : StrictMonoOn ψ (Set.Iic n) := by
intro x hx y hy hxy
obtain ⟨i, rfl⟩ := hxy.le.exists_succ_iterate
induction' i with k ih
· simp at hxy
cases' k with k
· exact hψ _ (lt_of_lt_of_le hxy hy)
rw [Set.mem_Iic] at *
simp only [Function.iterate_succ', Function.comp_apply] at ih hxy hy ⊢
by_cases hmax : IsMax (succ^[k] x)
· rw [succ_eq_iff_isMax.2 hmax] at hxy ⊢
exact ih (le_trans (le_succ _) hy) hxy
by_cases hmax' : IsMax (succ (succ^[k] x))
· rw [succ_eq_iff_isMax.2 hmax'] at hxy ⊢
exact ih (le_trans (le_succ _) hy) hxy
refine
lt_trans
(ih (le_trans (le_succ _) hy)
(lt_of_le_of_lt (le_succ_iterate k _) (lt_succ_iff_not_isMax.2 hmax)))
?_
rw [← Function.comp_apply (f := succ), ← Function.iterate_succ']
refine hψ _ (lt_of_lt_of_le ?_ hy)
rwa [Function.iterate_succ', Function.comp_apply, lt_succ_iff_not_isMax]
theorem strictAntiOn_Iic_of_succ_lt [SuccOrder α] [IsSuccArchimedean α] {n : α}
(hψ : ∀ m, m < n → ψ (succ m) < ψ m) : StrictAntiOn ψ (Set.Iic n) := fun i hi j hj hij =>
@strictMonoOn_Iic_of_lt_succ α βᵒᵈ _ _ ψ _ _ n hψ i hi j hj hij
theorem strictMonoOn_Ici_of_pred_lt [PredOrder α] [IsPredArchimedean α] {n : α}
(hψ : ∀ m, n < m → ψ (pred m) < ψ m) : StrictMonoOn ψ (Set.Ici n) := fun i hi j hj hij =>
@strictMonoOn_Iic_of_lt_succ αᵒᵈ βᵒᵈ _ _ ψ _ _ n hψ j hj i hi hij
theorem strictAntiOn_Ici_of_lt_pred [PredOrder α] [IsPredArchimedean α] {n : α}
(hψ : ∀ m, n < m → ψ m < ψ (pred m)) : StrictAntiOn ψ (Set.Ici n) := fun i hi j hj hij =>
@strictAntiOn_Iic_of_succ_lt αᵒᵈ βᵒᵈ _ _ ψ _ _ n hψ j hj i hi hij
end SuccOrder
|
Order\Interval\Set\OrdConnected.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Order.Interval.Set.OrderEmbedding
import Mathlib.Order.Antichain
import Mathlib.Order.SetNotation
/-!
# Order-connected sets
We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the
interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with
the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a
`LinearOrderedField`, then this condition is also equivalent to `Convex α s`.
In this file we prove that intersection of a family of `OrdConnected` sets is `OrdConnected` and
that all standard intervals are `OrdConnected`.
-/
open scoped Interval
open Set
open OrderDual (toDual ofDual)
namespace Set
section Preorder
variable {α β : Type*} [Preorder α] [Preorder β] {s t : Set α}
/-- We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the
interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with
the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a
`LinearOrderedField`, then this condition is also equivalent to `Convex α s`. -/
class OrdConnected (s : Set α) : Prop where
/-- `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. -/
out' ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) : Icc x y ⊆ s
theorem OrdConnected.out (h : OrdConnected s) : ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s :=
h.1
theorem ordConnected_def : OrdConnected s ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
/-- It suffices to prove `[[x, y]] ⊆ s` for `x y ∈ s`, `x ≤ y`. -/
theorem ordConnected_iff : OrdConnected s ↔ ∀ x ∈ s, ∀ y ∈ s, x ≤ y → Icc x y ⊆ s :=
ordConnected_def.trans
⟨fun hs _ hx _ hy _ => hs hx hy, fun H x hx y hy _ hz => H x hx y hy (le_trans hz.1 hz.2) hz⟩
theorem ordConnected_of_Ioo {α : Type*} [PartialOrder α] {s : Set α}
(hs : ∀ x ∈ s, ∀ y ∈ s, x < y → Ioo x y ⊆ s) : OrdConnected s := by
rw [ordConnected_iff]
intro x hx y hy hxy
rcases eq_or_lt_of_le hxy with (rfl | hxy'); · simpa
rw [← Ioc_insert_left hxy, ← Ioo_insert_right hxy']
exact insert_subset_iff.2 ⟨hx, insert_subset_iff.2 ⟨hy, hs x hx y hy hxy'⟩⟩
theorem OrdConnected.preimage_mono {f : β → α} (hs : OrdConnected s) (hf : Monotone f) :
OrdConnected (f ⁻¹' s) :=
⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨hf hz.1, hf hz.2⟩⟩
theorem OrdConnected.preimage_anti {f : β → α} (hs : OrdConnected s) (hf : Antitone f) :
OrdConnected (f ⁻¹' s) :=
⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hf hz.2, hf hz.1⟩⟩
protected theorem Icc_subset (s : Set α) [hs : OrdConnected s] {x y} (hx : x ∈ s) (hy : y ∈ s) :
Icc x y ⊆ s :=
hs.out hx hy
end Preorder
end Set
namespace OrderEmbedding
variable {α β : Type*} [Preorder α] [Preorder β]
theorem image_Icc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) :
e '' Icc x y = Icc (e x) (e y) := by
rw [← e.preimage_Icc, image_preimage_eq_inter_range, inter_eq_left.2 (he.out ⟨_, rfl⟩ ⟨_, rfl⟩)]
theorem image_Ico (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) :
e '' Ico x y = Ico (e x) (e y) := by
rw [← e.preimage_Ico, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ico_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩]
theorem image_Ioc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) :
e '' Ioc x y = Ioc (e x) (e y) := by
rw [← e.preimage_Ioc, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ioc_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩]
theorem image_Ioo (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) :
e '' Ioo x y = Ioo (e x) (e y) := by
rw [← e.preimage_Ioo, image_preimage_eq_inter_range,
inter_eq_left.2 <| Ioo_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩]
end OrderEmbedding
namespace Set
section Preorder
variable {α β : Type*} [Preorder α] [Preorder β] {s t : Set α}
@[simp]
lemma image_subtype_val_Icc {s : Set α} [OrdConnected s] (x y : s) :
Subtype.val '' Icc x y = Icc x.1 y :=
(OrderEmbedding.subtype (· ∈ s)).image_Icc (by simpa) x y
@[simp]
lemma image_subtype_val_Ico {s : Set α} [OrdConnected s] (x y : s) :
Subtype.val '' Ico x y = Ico x.1 y :=
(OrderEmbedding.subtype (· ∈ s)).image_Ico (by simpa) x y
@[simp]
lemma image_subtype_val_Ioc {s : Set α} [OrdConnected s] (x y : s) :
Subtype.val '' Ioc x y = Ioc x.1 y :=
(OrderEmbedding.subtype (· ∈ s)).image_Ioc (by simpa) x y
@[simp]
lemma image_subtype_val_Ioo {s : Set α} [OrdConnected s] (x y : s) :
Subtype.val '' Ioo x y = Ioo x.1 y :=
(OrderEmbedding.subtype (· ∈ s)).image_Ioo (by simpa) x y
theorem OrdConnected.inter {s t : Set α} (hs : OrdConnected s) (ht : OrdConnected t) :
OrdConnected (s ∩ t) :=
⟨fun _ hx _ hy => subset_inter (hs.out hx.1 hy.1) (ht.out hx.2 hy.2)⟩
instance OrdConnected.inter' {s t : Set α} [OrdConnected s] [OrdConnected t] :
OrdConnected (s ∩ t) :=
OrdConnected.inter ‹_› ‹_›
theorem OrdConnected.dual {s : Set α} (hs : OrdConnected s) :
OrdConnected (OrderDual.ofDual ⁻¹' s) :=
⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hz.2, hz.1⟩⟩
theorem ordConnected_dual {s : Set α} : OrdConnected (OrderDual.ofDual ⁻¹' s) ↔ OrdConnected s :=
⟨fun h => by simpa only [ordConnected_def] using h.dual, fun h => h.dual⟩
theorem ordConnected_sInter {S : Set (Set α)} (hS : ∀ s ∈ S, OrdConnected s) :
OrdConnected (⋂₀ S) :=
⟨fun _x hx _y hy _z hz s hs => (hS s hs).out (hx s hs) (hy s hs) hz⟩
theorem ordConnected_iInter {ι : Sort*} {s : ι → Set α} (hs : ∀ i, OrdConnected (s i)) :
OrdConnected (⋂ i, s i) :=
ordConnected_sInter <| forall_mem_range.2 hs
instance ordConnected_iInter' {ι : Sort*} {s : ι → Set α} [∀ i, OrdConnected (s i)] :
OrdConnected (⋂ i, s i) :=
ordConnected_iInter ‹_›
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i hi) -/
theorem ordConnected_biInter {ι : Sort*} {p : ι → Prop} {s : ∀ i, p i → Set α}
(hs : ∀ i hi, OrdConnected (s i hi)) : OrdConnected (⋂ (i) (hi), s i hi) :=
ordConnected_iInter fun i => ordConnected_iInter <| hs i
theorem ordConnected_pi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (h : ∀ i ∈ s, OrdConnected (t i)) : OrdConnected (s.pi t) :=
⟨fun _ hx _ hy _ hz i hi => (h i hi).out (hx i hi) (hy i hi) ⟨hz.1 i, hz.2 i⟩⟩
instance ordConnected_pi' {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} [h : ∀ i, OrdConnected (t i)] : OrdConnected (s.pi t) :=
ordConnected_pi fun i _ => h i
@[instance]
theorem ordConnected_Ici {a : α} : OrdConnected (Ici a) :=
⟨fun _ hx _ _ _ hz => le_trans hx hz.1⟩
@[instance]
theorem ordConnected_Iic {a : α} : OrdConnected (Iic a) :=
⟨fun _ _ _ hy _ hz => le_trans hz.2 hy⟩
@[instance]
theorem ordConnected_Ioi {a : α} : OrdConnected (Ioi a) :=
⟨fun _ hx _ _ _ hz => lt_of_lt_of_le hx hz.1⟩
@[instance]
theorem ordConnected_Iio {a : α} : OrdConnected (Iio a) :=
⟨fun _ _ _ hy _ hz => lt_of_le_of_lt hz.2 hy⟩
@[instance]
theorem ordConnected_Icc {a b : α} : OrdConnected (Icc a b) :=
ordConnected_Ici.inter ordConnected_Iic
@[instance]
theorem ordConnected_Ico {a b : α} : OrdConnected (Ico a b) :=
ordConnected_Ici.inter ordConnected_Iio
@[instance]
theorem ordConnected_Ioc {a b : α} : OrdConnected (Ioc a b) :=
ordConnected_Ioi.inter ordConnected_Iic
@[instance]
theorem ordConnected_Ioo {a b : α} : OrdConnected (Ioo a b) :=
ordConnected_Ioi.inter ordConnected_Iio
@[instance]
theorem ordConnected_singleton {α : Type*} [PartialOrder α] {a : α} :
OrdConnected ({a} : Set α) := by
rw [← Icc_self]
exact ordConnected_Icc
@[instance]
theorem ordConnected_empty : OrdConnected (∅ : Set α) :=
⟨fun _ => False.elim⟩
@[instance]
theorem ordConnected_univ : OrdConnected (univ : Set α) :=
⟨fun _ _ _ _ => subset_univ _⟩
/-- In a dense order `α`, the subtype from an `OrdConnected` set is also densely ordered. -/
instance instDenselyOrdered [DenselyOrdered α] {s : Set α} [hs : OrdConnected s] :
DenselyOrdered s :=
⟨fun a b (h : (a : α) < b) =>
let ⟨x, H⟩ := exists_between h
⟨⟨x, (hs.out a.2 b.2) (Ioo_subset_Icc_self H)⟩, H⟩⟩
@[instance]
theorem ordConnected_preimage {F : Type*} [FunLike F α β] [OrderHomClass F α β] (f : F)
{s : Set β} [hs : OrdConnected s] : OrdConnected (f ⁻¹' s) :=
⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨OrderHomClass.mono _ hz.1, OrderHomClass.mono _ hz.2⟩⟩
@[instance]
theorem ordConnected_image {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) {s : Set α}
[hs : OrdConnected s] : OrdConnected (e '' s) := by
erw [(e : α ≃o β).image_eq_preimage]
apply ordConnected_preimage (e : α ≃o β).symm
-- Porting note: split up `simp_rw [← image_univ, OrdConnected_image e]`, would not work otherwise
@[instance]
theorem ordConnected_range {E : Type*} [EquivLike E α β] [OrderIsoClass E α β] (e : E) :
OrdConnected (range e) := by
simp_rw [← image_univ]
exact ordConnected_image (e : α ≃o β)
@[simp]
theorem dual_ordConnected_iff {s : Set α} : OrdConnected (ofDual ⁻¹' s) ↔ OrdConnected s := by
simp_rw [ordConnected_def, toDual.surjective.forall, dual_Icc, Subtype.forall']
exact forall_swap
@[instance]
theorem dual_ordConnected {s : Set α} [OrdConnected s] : OrdConnected (ofDual ⁻¹' s) :=
dual_ordConnected_iff.2 ‹_›
end Preorder
section PartialOrder
variable {α : Type*} [PartialOrder α] {s : Set α} {x y : α}
protected theorem _root_.IsAntichain.ordConnected (hs : IsAntichain (· ≤ ·) s) : s.OrdConnected :=
⟨fun x hx y hy z hz => by
obtain rfl := hs.eq hx hy (hz.1.trans hz.2)
rw [Icc_self, mem_singleton_iff] at hz
rwa [hz]⟩
lemma ordConnected_inter_Icc_of_subset (h : Ioo x y ⊆ s) : OrdConnected (s ∩ Icc x y) :=
ordConnected_of_Ioo fun _u ⟨_, hu, _⟩ _v ⟨_, _, hv⟩ _ ↦
Ioo_subset_Ioo hu hv |>.trans <| subset_inter h Ioo_subset_Icc_self
lemma ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) :
OrdConnected (s ∩ Icc x y) ↔ Ioo x y ⊆ s := by
refine ⟨fun h ↦ Ioo_subset_Icc_self.trans fun z hz ↦ ?_, ordConnected_inter_Icc_of_subset⟩
have hxy : x ≤ y := hz.1.trans hz.2
exact h.out ⟨hx, left_mem_Icc.2 hxy⟩ ⟨hy, right_mem_Icc.2 hxy⟩ hz |>.1
lemma not_ordConnected_inter_Icc_iff (hx : x ∈ s) (hy : y ∈ s) :
¬ OrdConnected (s ∩ Icc x y) ↔ ∃ z ∉ s, z ∈ Ioo x y := by
simp_rw [ordConnected_inter_Icc_iff hx hy, subset_def, not_forall, exists_prop, and_comm]
end PartialOrder
section LinearOrder
variable {α : Type*} [LinearOrder α] {s : Set α} {x : α}
@[instance]
theorem ordConnected_uIcc {a b : α} : OrdConnected [[a, b]] :=
ordConnected_Icc
@[instance]
theorem ordConnected_uIoc {a b : α} : OrdConnected (Ι a b) :=
ordConnected_Ioc
theorem OrdConnected.uIcc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) :
[[x, y]] ⊆ s :=
hs.out (min_rec' (· ∈ s) hx hy) (max_rec' (· ∈ s) hx hy)
theorem OrdConnected.uIoc_subset (hs : OrdConnected s) ⦃x⦄ (hx : x ∈ s) ⦃y⦄ (hy : y ∈ s) :
Ι x y ⊆ s :=
Ioc_subset_Icc_self.trans <| hs.uIcc_subset hx hy
theorem ordConnected_iff_uIcc_subset :
OrdConnected s ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), [[x, y]] ⊆ s :=
⟨fun h => h.uIcc_subset, fun H => ⟨fun _ hx _ hy => Icc_subset_uIcc.trans <| H hx hy⟩⟩
theorem ordConnected_of_uIcc_subset_left (h : ∀ y ∈ s, [[x, y]] ⊆ s) : OrdConnected s :=
ordConnected_iff_uIcc_subset.2 fun y hy z hz =>
calc
[[y, z]] ⊆ [[y, x]] ∪ [[x, z]] := uIcc_subset_uIcc_union_uIcc
_ = [[x, y]] ∪ [[x, z]] := by rw [uIcc_comm]
_ ⊆ s := union_subset (h y hy) (h z hz)
theorem ordConnected_iff_uIcc_subset_left (hx : x ∈ s) :
OrdConnected s ↔ ∀ ⦃y⦄, y ∈ s → [[x, y]] ⊆ s :=
⟨fun hs => hs.uIcc_subset hx, ordConnected_of_uIcc_subset_left⟩
theorem ordConnected_iff_uIcc_subset_right (hx : x ∈ s) :
OrdConnected s ↔ ∀ ⦃y⦄, y ∈ s → [[y, x]] ⊆ s := by
simp_rw [ordConnected_iff_uIcc_subset_left hx, uIcc_comm]
end LinearOrder
end Set
|
Order\Interval\Set\OrdConnectedComponent.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.OrdConnected
import Mathlib.Data.Set.Lattice
/-!
# Order connected components of a set
In this file we define `Set.ordConnectedComponent s x` to be the set of `y` such that
`Set.uIcc x y ⊆ s` and prove some basic facts about this definition. At the moment of writing,
this construction is used only to prove that any linear order with order topology is a T₅ space,
so we only add API needed for this lemma.
-/
open Interval Function OrderDual
namespace Set
variable {α : Type*} [LinearOrder α] {s t : Set α} {x y z : α}
/-- Order-connected component of a point `x` in a set `s`. It is defined as the set of `y` such that
`Set.uIcc x y ⊆ s`. Note that it is empty if and only if `x ∉ s`. -/
def ordConnectedComponent (s : Set α) (x : α) : Set α :=
{ y | [[x, y]] ⊆ s }
theorem mem_ordConnectedComponent : y ∈ ordConnectedComponent s x ↔ [[x, y]] ⊆ s :=
Iff.rfl
theorem dual_ordConnectedComponent :
ordConnectedComponent (ofDual ⁻¹' s) (toDual x) = ofDual ⁻¹' ordConnectedComponent s x :=
ext <| (Surjective.forall toDual.surjective).2 fun x => by
rw [mem_ordConnectedComponent, dual_uIcc]
rfl
theorem ordConnectedComponent_subset : ordConnectedComponent s x ⊆ s := fun _ hy =>
hy right_mem_uIcc
theorem subset_ordConnectedComponent {t} [h : OrdConnected s] (hs : x ∈ s) (ht : s ⊆ t) :
s ⊆ ordConnectedComponent t x := fun _ hy => (h.uIcc_subset hs hy).trans ht
@[simp]
theorem self_mem_ordConnectedComponent : x ∈ ordConnectedComponent s x ↔ x ∈ s := by
rw [mem_ordConnectedComponent, uIcc_self, singleton_subset_iff]
@[simp]
theorem nonempty_ordConnectedComponent : (ordConnectedComponent s x).Nonempty ↔ x ∈ s :=
⟨fun ⟨_, hy⟩ => hy <| left_mem_uIcc, fun h => ⟨x, self_mem_ordConnectedComponent.2 h⟩⟩
@[simp]
theorem ordConnectedComponent_eq_empty : ordConnectedComponent s x = ∅ ↔ x ∉ s := by
rw [← not_nonempty_iff_eq_empty, nonempty_ordConnectedComponent]
@[simp]
theorem ordConnectedComponent_empty : ordConnectedComponent ∅ x = ∅ :=
ordConnectedComponent_eq_empty.2 (not_mem_empty x)
@[simp]
theorem ordConnectedComponent_univ : ordConnectedComponent univ x = univ := by
simp [ordConnectedComponent]
theorem ordConnectedComponent_inter (s t : Set α) (x : α) :
ordConnectedComponent (s ∩ t) x = ordConnectedComponent s x ∩ ordConnectedComponent t x := by
simp [ordConnectedComponent, setOf_and]
theorem mem_ordConnectedComponent_comm :
y ∈ ordConnectedComponent s x ↔ x ∈ ordConnectedComponent s y := by
rw [mem_ordConnectedComponent, mem_ordConnectedComponent, uIcc_comm]
theorem mem_ordConnectedComponent_trans (hxy : y ∈ ordConnectedComponent s x)
(hyz : z ∈ ordConnectedComponent s y) : z ∈ ordConnectedComponent s x :=
calc
[[x, z]] ⊆ [[x, y]] ∪ [[y, z]] := uIcc_subset_uIcc_union_uIcc
_ ⊆ s := union_subset hxy hyz
theorem ordConnectedComponent_eq (h : [[x, y]] ⊆ s) :
ordConnectedComponent s x = ordConnectedComponent s y :=
ext fun _ =>
⟨mem_ordConnectedComponent_trans (mem_ordConnectedComponent_comm.2 h),
mem_ordConnectedComponent_trans h⟩
instance : OrdConnected (ordConnectedComponent s x) :=
ordConnected_of_uIcc_subset_left fun _ hy _ hz => (uIcc_subset_uIcc_left hz).trans hy
/-- Projection from `s : Set α` to `α` sending each order connected component of `s` to a single
point of this component. -/
noncomputable def ordConnectedProj (s : Set α) : s → α := fun x : s =>
(nonempty_ordConnectedComponent.2 x.2).some
theorem ordConnectedProj_mem_ordConnectedComponent (s : Set α) (x : s) :
ordConnectedProj s x ∈ ordConnectedComponent s x :=
Nonempty.some_mem _
theorem mem_ordConnectedComponent_ordConnectedProj (s : Set α) (x : s) :
↑x ∈ ordConnectedComponent s (ordConnectedProj s x) :=
mem_ordConnectedComponent_comm.2 <| ordConnectedProj_mem_ordConnectedComponent s x
@[simp]
theorem ordConnectedComponent_ordConnectedProj (s : Set α) (x : s) :
ordConnectedComponent s (ordConnectedProj s x) = ordConnectedComponent s x :=
ordConnectedComponent_eq <| mem_ordConnectedComponent_ordConnectedProj _ _
@[simp]
theorem ordConnectedProj_eq {x y : s} :
ordConnectedProj s x = ordConnectedProj s y ↔ [[(x : α), y]] ⊆ s := by
constructor <;> intro h
· rw [← mem_ordConnectedComponent, ← ordConnectedComponent_ordConnectedProj, h,
ordConnectedComponent_ordConnectedProj, self_mem_ordConnectedComponent]
exact y.2
· simp only [ordConnectedProj, ordConnectedComponent_eq h]
/-- A set that intersects each order connected component of a set by a single point. Defined as the
range of `Set.ordConnectedProj s`. -/
def ordConnectedSection (s : Set α) : Set α :=
range <| ordConnectedProj s
theorem dual_ordConnectedSection (s : Set α) :
ordConnectedSection (ofDual ⁻¹' s) = ofDual ⁻¹' ordConnectedSection s := by
simp only [ordConnectedSection]
simp (config := { unfoldPartialApp := true }) only [ordConnectedProj]
ext x
simp only [mem_range, Subtype.exists, mem_preimage, OrderDual.exists, dual_ordConnectedComponent,
ofDual_toDual]
tauto
theorem ordConnectedSection_subset : ordConnectedSection s ⊆ s :=
range_subset_iff.2 fun _ => ordConnectedComponent_subset <| Nonempty.some_mem _
theorem eq_of_mem_ordConnectedSection_of_uIcc_subset (hx : x ∈ ordConnectedSection s)
(hy : y ∈ ordConnectedSection s) (h : [[x, y]] ⊆ s) : x = y := by
rcases hx with ⟨x, rfl⟩; rcases hy with ⟨y, rfl⟩
exact
ordConnectedProj_eq.2
(mem_ordConnectedComponent_trans
(mem_ordConnectedComponent_trans (ordConnectedProj_mem_ordConnectedComponent _ _) h)
(mem_ordConnectedComponent_ordConnectedProj _ _))
/-- Given two sets `s t : Set α`, the set `Set.orderSeparatingSet s t` is the set of points that
belong both to some `Set.ordConnectedComponent tᶜ x`, `x ∈ s`, and to some
`Set.ordConnectedComponent sᶜ x`, `x ∈ t`. In the case of two disjoint closed sets, this is the
union of all open intervals $(a, b)$ such that their endpoints belong to different sets. -/
def ordSeparatingSet (s t : Set α) : Set α :=
(⋃ x ∈ s, ordConnectedComponent tᶜ x) ∩ ⋃ x ∈ t, ordConnectedComponent sᶜ x
theorem ordSeparatingSet_comm (s t : Set α) : ordSeparatingSet s t = ordSeparatingSet t s :=
inter_comm _ _
theorem disjoint_left_ordSeparatingSet : Disjoint s (ordSeparatingSet s t) :=
Disjoint.inter_right' _ <|
disjoint_iUnion₂_right.2 fun _ _ =>
disjoint_compl_right.mono_right <| ordConnectedComponent_subset
theorem disjoint_right_ordSeparatingSet : Disjoint t (ordSeparatingSet s t) :=
ordSeparatingSet_comm t s ▸ disjoint_left_ordSeparatingSet
theorem dual_ordSeparatingSet :
ordSeparatingSet (ofDual ⁻¹' s) (ofDual ⁻¹' t) = ofDual ⁻¹' ordSeparatingSet s t := by
simp only [ordSeparatingSet, mem_preimage, ← toDual.surjective.iUnion_comp, ofDual_toDual,
dual_ordConnectedComponent, ← preimage_compl, preimage_inter, preimage_iUnion]
/-- An auxiliary neighborhood that will be used in the proof of
`OrderTopology.CompletelyNormalSpace`. -/
def ordT5Nhd (s t : Set α) : Set α :=
⋃ x ∈ s, ordConnectedComponent (tᶜ ∩ (ordConnectedSection <| ordSeparatingSet s t)ᶜ) x
theorem disjoint_ordT5Nhd : Disjoint (ordT5Nhd s t) (ordT5Nhd t s) := by
clear x y z
rw [disjoint_iff_inf_le]
rintro x ⟨hx₁, hx₂⟩
rcases mem_iUnion₂.1 hx₁ with ⟨a, has, ha⟩
clear hx₁
rcases mem_iUnion₂.1 hx₂ with ⟨b, hbt, hb⟩
clear hx₂
rw [mem_ordConnectedComponent, subset_inter_iff] at ha hb
wlog hab : a ≤ b with H
· exact H b hbt hb a has ha (le_of_not_le hab)
cases' ha with ha ha'
cases' hb with hb hb'
have hsub : [[a, b]] ⊆ (ordSeparatingSet s t).ordConnectedSectionᶜ := by
rw [ordSeparatingSet_comm, uIcc_comm] at hb'
calc
[[a, b]] ⊆ [[a, x]] ∪ [[x, b]] := uIcc_subset_uIcc_union_uIcc
_ ⊆ (ordSeparatingSet s t).ordConnectedSectionᶜ := union_subset ha' hb'
clear ha' hb'
rcases le_total x a with hxa | hax
· exact hb (Icc_subset_uIcc' ⟨hxa, hab⟩) has
rcases le_total b x with hbx | hxb
· exact ha (Icc_subset_uIcc ⟨hab, hbx⟩) hbt
have h' : x ∈ ordSeparatingSet s t := ⟨mem_iUnion₂.2 ⟨a, has, ha⟩, mem_iUnion₂.2 ⟨b, hbt, hb⟩⟩
lift x to ordSeparatingSet s t using h'
suffices ordConnectedComponent (ordSeparatingSet s t) x ⊆ [[a, b]] from
hsub (this <| ordConnectedProj_mem_ordConnectedComponent _ x) (mem_range_self _)
rintro y hy
rw [uIcc_of_le hab, mem_Icc, ← not_lt, ← not_lt]
have sol1 := fun (hya : y < a) =>
(disjoint_left (t := ordSeparatingSet s t)).1 disjoint_left_ordSeparatingSet has
(hy <| Icc_subset_uIcc' ⟨hya.le, hax⟩)
have sol2 := fun (hby : b < y) =>
(disjoint_left (t := ordSeparatingSet s t)).1 disjoint_right_ordSeparatingSet hbt
(hy <| Icc_subset_uIcc ⟨hxb, hby.le⟩)
exact ⟨sol1, sol2⟩
end Set
|
Order\Interval\Set\OrderEmbedding.lean | /-
Copyright (c) 2024 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Interval.Set.UnorderedInterval
import Mathlib.Order.Hom.Basic
/-!
# Preimages of intervals under order embeddings
In this file we prove that the preimage of an interval in the codomain under an `OrderEmbedding`
is an interval in the domain.
Note that similar statements about images require the range to be order-connected.
-/
open Set
namespace OrderEmbedding
variable {α β : Type*}
section Preorder
variable [Preorder α] [Preorder β] (e : α ↪o β) (x y : α)
@[simp] theorem preimage_Ici : e ⁻¹' Ici (e x) = Ici x := ext fun _ ↦ e.le_iff_le
@[simp] theorem preimage_Iic : e ⁻¹' Iic (e x) = Iic x := ext fun _ ↦ e.le_iff_le
@[simp] theorem preimage_Ioi : e ⁻¹' Ioi (e x) = Ioi x := ext fun _ ↦ e.lt_iff_lt
@[simp] theorem preimage_Iio : e ⁻¹' Iio (e x) = Iio x := ext fun _ ↦ e.lt_iff_lt
@[simp] theorem preimage_Icc : e ⁻¹' Icc (e x) (e y) = Icc x y := by ext; simp
@[simp] theorem preimage_Ico : e ⁻¹' Ico (e x) (e y) = Ico x y := by ext; simp
@[simp] theorem preimage_Ioc : e ⁻¹' Ioc (e x) (e y) = Ioc x y := by ext; simp
@[simp] theorem preimage_Ioo : e ⁻¹' Ioo (e x) (e y) = Ioo x y := by ext; simp
end Preorder
variable [LinearOrder α]
@[simp] theorem preimage_uIcc [Lattice β] (e : α ↪o β) (x y : α) :
e ⁻¹' (uIcc (e x) (e y)) = uIcc x y := by
cases le_total x y <;> simp [*]
@[simp] theorem preimage_uIoc [LinearOrder β] (e : α ↪o β) (x y : α) :
e ⁻¹' (uIoc (e x) (e y)) = uIoc x y := by
cases le_total x y <;> simp [*]
end OrderEmbedding
|
Order\Interval\Set\OrderIso.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.Hom.Set
/-!
# Lemmas about images of intervals under order isomorphisms.
-/
open Set
namespace OrderIso
section Preorder
variable {α β : Type*} [Preorder α] [Preorder β]
@[simp]
theorem preimage_Iic (e : α ≃o β) (b : β) : e ⁻¹' Iic b = Iic (e.symm b) := by
ext x
simp [← e.le_iff_le]
@[simp]
theorem preimage_Ici (e : α ≃o β) (b : β) : e ⁻¹' Ici b = Ici (e.symm b) := by
ext x
simp [← e.le_iff_le]
@[simp]
theorem preimage_Iio (e : α ≃o β) (b : β) : e ⁻¹' Iio b = Iio (e.symm b) := by
ext x
simp [← e.lt_iff_lt]
@[simp]
theorem preimage_Ioi (e : α ≃o β) (b : β) : e ⁻¹' Ioi b = Ioi (e.symm b) := by
ext x
simp [← e.lt_iff_lt]
@[simp]
theorem preimage_Icc (e : α ≃o β) (a b : β) : e ⁻¹' Icc a b = Icc (e.symm a) (e.symm b) := by
simp [← Ici_inter_Iic]
@[simp]
theorem preimage_Ico (e : α ≃o β) (a b : β) : e ⁻¹' Ico a b = Ico (e.symm a) (e.symm b) := by
simp [← Ici_inter_Iio]
@[simp]
theorem preimage_Ioc (e : α ≃o β) (a b : β) : e ⁻¹' Ioc a b = Ioc (e.symm a) (e.symm b) := by
simp [← Ioi_inter_Iic]
@[simp]
theorem preimage_Ioo (e : α ≃o β) (a b : β) : e ⁻¹' Ioo a b = Ioo (e.symm a) (e.symm b) := by
simp [← Ioi_inter_Iio]
@[simp]
theorem image_Iic (e : α ≃o β) (a : α) : e '' Iic a = Iic (e a) := by
rw [e.image_eq_preimage, e.symm.preimage_Iic, e.symm_symm]
@[simp]
theorem image_Ici (e : α ≃o β) (a : α) : e '' Ici a = Ici (e a) :=
e.dual.image_Iic a
@[simp]
theorem image_Iio (e : α ≃o β) (a : α) : e '' Iio a = Iio (e a) := by
rw [e.image_eq_preimage, e.symm.preimage_Iio, e.symm_symm]
@[simp]
theorem image_Ioi (e : α ≃o β) (a : α) : e '' Ioi a = Ioi (e a) :=
e.dual.image_Iio a
@[simp]
theorem image_Ioo (e : α ≃o β) (a b : α) : e '' Ioo a b = Ioo (e a) (e b) := by
rw [e.image_eq_preimage, e.symm.preimage_Ioo, e.symm_symm]
@[simp]
theorem image_Ioc (e : α ≃o β) (a b : α) : e '' Ioc a b = Ioc (e a) (e b) := by
rw [e.image_eq_preimage, e.symm.preimage_Ioc, e.symm_symm]
@[simp]
theorem image_Ico (e : α ≃o β) (a b : α) : e '' Ico a b = Ico (e a) (e b) := by
rw [e.image_eq_preimage, e.symm.preimage_Ico, e.symm_symm]
@[simp]
theorem image_Icc (e : α ≃o β) (a b : α) : e '' Icc a b = Icc (e a) (e b) := by
rw [e.image_eq_preimage, e.symm.preimage_Icc, e.symm_symm]
end Preorder
/-- Order isomorphism between `Iic (⊤ : α)` and `α` when `α` has a top element -/
def IicTop {α : Type*} [Preorder α] [OrderTop α] : Iic (⊤ : α) ≃o α :=
{ @Equiv.subtypeUnivEquiv α (Iic (⊤ : α)) fun x => le_top with
map_rel_iff' := @fun x y => by rfl }
/-- Order isomorphism between `Ici (⊥ : α)` and `α` when `α` has a bottom element -/
def IciBot {α : Type*} [Preorder α] [OrderBot α] : Ici (⊥ : α) ≃o α :=
{ @Equiv.subtypeUnivEquiv α (Ici (⊥ : α)) fun x => bot_le with
map_rel_iff' := @fun x y => by rfl }
end OrderIso
|
Order\Interval\Set\Pi.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
import Mathlib.Data.Set.Lattice
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
-- Porting note: Added, since dot notation no longer works on `Function.update`
open Function
variable {ι : Type*} {α : ι → Type*}
namespace Set
section PiPreorder
variable [∀ i, Preorder (α i)] (x y : ∀ i, α i)
@[simp]
theorem pi_univ_Ici : (pi univ fun i ↦ Ici (x i)) = Ici x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Iic : (pi univ fun i ↦ Iic (x i)) = Iic x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Icc : (pi univ fun i ↦ Icc (x i) (y i)) = Icc x y :=
ext fun y ↦ by simp [Pi.le_def, forall_and]
theorem piecewise_mem_Icc {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
⟨le_piecewise (fun i hi ↦ (h₁ i hi).1) fun i hi ↦ (h₂ i hi).1,
piecewise_le (fun i hi ↦ (h₁ i hi).2) fun i hi ↦ (h₂ i hi).2⟩
theorem piecewise_mem_Icc' {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
piecewise_mem_Icc (fun _ _ ↦ ⟨h₁.1 _, h₁.2 _⟩) fun _ _ ↦ ⟨h₂.1 _, h₂.2 _⟩
section Nonempty
theorem pi_univ_Ioi_subset [Nonempty ι]: (pi univ fun i ↦ Ioi (x i)) ⊆ Ioi x := fun z hz ↦
⟨fun i ↦ le_of_lt <| hz i trivial, fun h ↦
(‹Nonempty ι›.elim) fun i ↦ not_lt_of_le (h i) (hz i trivial)⟩
theorem pi_univ_Iio_subset [Nonempty ι]: (pi univ fun i ↦ Iio (x i)) ⊆ Iio x :=
pi_univ_Ioi_subset (α := fun i ↦ (α i)ᵒᵈ) x
theorem pi_univ_Ioo_subset [Nonempty ι]: (pi univ fun i ↦ Ioo (x i) (y i)) ⊆ Ioo x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
theorem pi_univ_Ioc_subset [Nonempty ι]: (pi univ fun i ↦ Ioc (x i) (y i)) ⊆ Ioc x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, fun i ↦ (hx i trivial).2⟩
theorem pi_univ_Ico_subset [Nonempty ι]: (pi univ fun i ↦ Ico (x i) (y i)) ⊆ Ico x y := fun _ hx ↦
⟨fun i ↦ (hx i trivial).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
end Nonempty
variable [DecidableEq ι]
open Function (update)
theorem pi_univ_Ioc_update_left {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) :
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
{ z | m < z i₀ } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc,
inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)]
simp_rw [univ_pi_update i₀ _ _ fun i z ↦ Ioc z (y i), ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem pi_univ_Ioc_update_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) :
(pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) =
{ z | z i₀ ≤ m } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm,
inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)]
simp_rw [univ_pi_update i₀ y m fun i z ↦ Ioc (x i) z, ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem disjoint_pi_univ_Ioc_update_left_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} :
Disjoint (pi univ fun i ↦ Ioc (x i) (update y i₀ m i))
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) := by
rw [disjoint_left]
rintro z h₁ h₂
refine (h₁ i₀ (mem_univ _)).2.not_lt ?_
simpa only [Function.update_same] using (h₂ i₀ (mem_univ _)).1
end PiPreorder
section PiPartialOrder
variable [DecidableEq ι] [∀ i, PartialOrder (α i)]
-- Porting note: Dot notation on `Function.update` broke
theorem image_update_Icc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Icc a b = Icc (update f i a) (update f i b) := by
ext x
rw [← Set.pi_univ_Icc]
refine ⟨?_, fun h => ⟨x i, ?_, ?_⟩⟩
· rintro ⟨c, hc, rfl⟩
simpa [update_le_update_iff]
· simpa only [Function.update_same] using h i (mem_univ i)
· ext j
obtain rfl | hij := eq_or_ne i j
· exact Function.update_same _ _ _
· simpa only [Function.update_noteq hij.symm, le_antisymm_iff] using h j (mem_univ j)
theorem image_update_Ico (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ico a b = Ico (update f i a) (update f i b) := by
rw [← Icc_diff_right, ← Icc_diff_right, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioc a b = Ioc (update f i a) (update f i b) := by
rw [← Icc_diff_left, ← Icc_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioo (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioo a b = Ioo (update f i a) (update f i b) := by
rw [← Ico_diff_left, ← Ico_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Ico]
theorem image_update_Icc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Icc a (f i) = Icc (update f i a) f := by simpa using image_update_Icc f i a (f i)
theorem image_update_Ico_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ico a (f i) = Ico (update f i a) f := by simpa using image_update_Ico f i a (f i)
theorem image_update_Ioc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioc a (f i) = Ioc (update f i a) f := by simpa using image_update_Ioc f i a (f i)
theorem image_update_Ioo_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioo a (f i) = Ioo (update f i a) f := by simpa using image_update_Ioo f i a (f i)
theorem image_update_Icc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Icc (f i) b = Icc f (update f i b) := by simpa using image_update_Icc f i (f i) b
theorem image_update_Ico_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ico (f i) b = Ico f (update f i b) := by simpa using image_update_Ico f i (f i) b
theorem image_update_Ioc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioc (f i) b = Ioc f (update f i b) := by simpa using image_update_Ioc f i (f i) b
theorem image_update_Ioo_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioo (f i) b = Ioo f (update f i b) := by simpa using image_update_Ioo f i (f i) b
variable [∀ i, One (α i)]
@[to_additive]
theorem image_mulSingle_Icc (i : ι) (a b : α i) :
Pi.mulSingle i '' Icc a b = Icc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Icc _ _ _ _
@[to_additive]
theorem image_mulSingle_Ico (i : ι) (a b : α i) :
Pi.mulSingle i '' Ico a b = Ico (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ico _ _ _ _
@[to_additive]
theorem image_mulSingle_Ioc (i : ι) (a b : α i) :
Pi.mulSingle i '' Ioc a b = Ioc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ioc _ _ _ _
@[to_additive]
theorem image_mulSingle_Ioo (i : ι) (a b : α i) :
Pi.mulSingle i '' Ioo a b = Ioo (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ioo _ _ _ _
@[to_additive]
theorem image_mulSingle_Icc_left (i : ι) (a : α i) :
Pi.mulSingle i '' Icc a 1 = Icc (Pi.mulSingle i a) 1 :=
image_update_Icc_left _ _ _
@[to_additive]
theorem image_mulSingle_Ico_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ico a 1 = Ico (Pi.mulSingle i a) 1 :=
image_update_Ico_left _ _ _
@[to_additive]
theorem image_mulSingle_Ioc_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ioc a 1 = Ioc (Pi.mulSingle i a) 1 :=
image_update_Ioc_left _ _ _
@[to_additive]
theorem image_mulSingle_Ioo_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ioo a 1 = Ioo (Pi.mulSingle i a) 1 :=
image_update_Ioo_left _ _ _
@[to_additive]
theorem image_mulSingle_Icc_right (i : ι) (b : α i) :
Pi.mulSingle i '' Icc 1 b = Icc 1 (Pi.mulSingle i b) :=
image_update_Icc_right _ _ _
@[to_additive]
theorem image_mulSingle_Ico_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ico 1 b = Ico 1 (Pi.mulSingle i b) :=
image_update_Ico_right _ _ _
@[to_additive]
theorem image_mulSingle_Ioc_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ioc 1 b = Ioc 1 (Pi.mulSingle i b) :=
image_update_Ioc_right _ _ _
@[to_additive]
theorem image_mulSingle_Ioo_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ioo 1 b = Ioo 1 (Pi.mulSingle i b) :=
image_update_Ioo_right _ _ _
end PiPartialOrder
section PiLattice
variable [∀ i, Lattice (α i)]
@[simp]
theorem pi_univ_uIcc (a b : ∀ i, α i) : (pi univ fun i => uIcc (a i) (b i)) = uIcc a b :=
pi_univ_Icc _ _
variable [DecidableEq ι]
theorem image_update_uIcc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' uIcc a b = uIcc (update f i a) (update f i b) :=
(image_update_Icc _ _ _ _).trans <| by simp_rw [uIcc, update_sup, update_inf]
theorem image_update_uIcc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' uIcc a (f i) = uIcc (update f i a) f := by
simpa using image_update_uIcc f i a (f i)
theorem image_update_uIcc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' uIcc (f i) b = uIcc f (update f i b) := by
simpa using image_update_uIcc f i (f i) b
variable [∀ i, One (α i)]
@[to_additive]
theorem image_mulSingle_uIcc (i : ι) (a b : α i) :
Pi.mulSingle i '' uIcc a b = uIcc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_uIcc _ _ _ _
@[to_additive]
theorem image_mulSingle_uIcc_left (i : ι) (a : α i) :
Pi.mulSingle i '' uIcc a 1 = uIcc (Pi.mulSingle i a) 1 :=
image_update_uIcc_left _ _ _
@[to_additive]
theorem image_mulSingle_uIcc_right (i : ι) (b : α i) :
Pi.mulSingle i '' uIcc 1 b = uIcc 1 (Pi.mulSingle i b) :=
image_update_uIcc_right _ _ _
end PiLattice
variable [DecidableEq ι] [∀ i, LinearOrder (α i)]
open Function (update)
theorem pi_univ_Ioc_update_union (x y : ∀ i, α i) (i₀ : ι) (m : α i₀) (hm : m ∈ Icc (x i₀) (y i₀)) :
((pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) ∪
pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
pi univ fun i ↦ Ioc (x i) (y i) := by
simp_rw [pi_univ_Ioc_update_left hm.1, pi_univ_Ioc_update_right hm.2, ← union_inter_distrib_right,
← setOf_or, le_or_lt, setOf_true, univ_inter]
/-- If `x`, `y`, `x'`, and `y'` are functions `Π i : ι, α i`, then
the set difference between the box `[x, y]` and the product of the open intervals `(x' i, y' i)`
is covered by the union of the following boxes: for each `i : ι`, we take
`[x, update y i (x' i)]` and `[update x i (y' i), y]`.
E.g., if `x' = x` and `y' = y`, then this lemma states that the difference between a closed box
`[x, y]` and the corresponding open box `{z | ∀ i, x i < z i < y i}` is covered by the union
of the faces of `[x, y]`. -/
theorem Icc_diff_pi_univ_Ioo_subset (x y x' y' : ∀ i, α i) :
(Icc x y \ pi univ fun i ↦ Ioo (x' i) (y' i)) ⊆
(⋃ i : ι, Icc x (update y i (x' i))) ∪ ⋃ i : ι, Icc (update x i (y' i)) y := by
rintro a ⟨⟨hxa, hay⟩, ha'⟩
simp only [mem_pi, mem_univ, mem_Ioo, true_implies, not_forall] at ha'
simp only [le_update_iff, update_le_iff, mem_union, mem_iUnion, mem_Icc,
hxa, hay _, hxa _, hay, ← exists_or]
rcases ha' with ⟨w, hw⟩
apply Exists.intro w
cases lt_or_le (x' w) (a w) <;> simp_all
/-- If `x`, `y`, `z` are functions `Π i : ι, α i`, then
the set difference between the box `[x, z]` and the product of the intervals `(y i, z i]`
is covered by the union of the boxes `[x, update z i (y i)]`.
E.g., if `x = y`, then this lemma states that the difference between a closed box
`[x, y]` and the product of half-open intervals `{z | ∀ i, x i < z i ≤ y i}` is covered by the union
of the faces of `[x, y]` adjacent to `x`. -/
theorem Icc_diff_pi_univ_Ioc_subset (x y z : ∀ i, α i) :
(Icc x z \ pi univ fun i ↦ Ioc (y i) (z i)) ⊆ ⋃ i : ι, Icc x (update z i (y i)) := by
rintro a ⟨⟨hax, haz⟩, hay⟩
simpa [not_and_or, hax, le_update_iff, haz _] using hay
end Set
|
Order\Interval\Set\ProjIcc.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Patrick Massot
-/
import Mathlib.Data.Set.Function
import Mathlib.Order.Interval.Set.OrdConnected
/-!
# Projection of a line onto a closed interval
Given a linearly ordered type `α`, in this file we define
* `Set.projIci (a : α)` to be the map `α → [a, ∞)` sending `(-∞, a]` to `a`, and each point
`x ∈ [a, ∞)` to itself;
* `Set.projIic (b : α)` to be the map `α → (-∞, b[` sending `[b, ∞)` to `b`, and each point
`x ∈ (-∞, b]` to itself;
* `Set.projIcc (a b : α) (h : a ≤ b)` to be the map `α → [a, b]` sending `(-∞, a]` to `a`, `[b, ∞)`
to `b`, and each point `x ∈ [a, b]` to itself;
* `Set.IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β)` to be the extension of `f` to `α` defined
as `f ∘ projIcc a b h`.
* `Set.IciExtend {a : α} (f : Ici a → β)` to be the extension of `f` to `α` defined
as `f ∘ projIci a`.
* `Set.IicExtend {b : α} (f : Iic b → β)` to be the extension of `f` to `α` defined
as `f ∘ projIic b`.
We also prove some trivial properties of these maps.
-/
variable {α β : Type*} [LinearOrder α]
open Function
namespace Set
/-- Projection of `α` to the closed interval `[a, ∞)`. -/
def projIci (a x : α) : Ici a := ⟨max a x, le_max_left _ _⟩
/-- Projection of `α` to the closed interval `(-∞, b]`. -/
def projIic (b x : α) : Iic b := ⟨min b x, min_le_left _ _⟩
/-- Projection of `α` to the closed interval `[a, b]`. -/
def projIcc (a b : α) (h : a ≤ b) (x : α) : Icc a b :=
⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩
variable {a b : α} (h : a ≤ b) {x : α}
@[norm_cast]
theorem coe_projIci (a x : α) : (projIci a x : α) = max a x := rfl
@[norm_cast]
theorem coe_projIic (b x : α) : (projIic b x : α) = min b x := rfl
@[norm_cast]
theorem coe_projIcc (a b : α) (h : a ≤ b) (x : α) : (projIcc a b h x : α) = max a (min b x) := rfl
theorem projIci_of_le (hx : x ≤ a) : projIci a x = ⟨a, le_rfl⟩ := Subtype.ext <| max_eq_left hx
theorem projIic_of_le (hx : b ≤ x) : projIic b x = ⟨b, le_rfl⟩ := Subtype.ext <| min_eq_left hx
theorem projIcc_of_le_left (hx : x ≤ a) : projIcc a b h x = ⟨a, left_mem_Icc.2 h⟩ := by
simp [projIcc, hx, hx.trans h]
theorem projIcc_of_right_le (hx : b ≤ x) : projIcc a b h x = ⟨b, right_mem_Icc.2 h⟩ := by
simp [projIcc, hx, h]
@[simp]
theorem projIci_self (a : α) : projIci a a = ⟨a, le_rfl⟩ := projIci_of_le le_rfl
@[simp]
theorem projIic_self (b : α) : projIic b b = ⟨b, le_rfl⟩ := projIic_of_le le_rfl
@[simp]
theorem projIcc_left : projIcc a b h a = ⟨a, left_mem_Icc.2 h⟩ :=
projIcc_of_le_left h le_rfl
@[simp]
theorem projIcc_right : projIcc a b h b = ⟨b, right_mem_Icc.2 h⟩ :=
projIcc_of_right_le h le_rfl
theorem projIci_eq_self : projIci a x = ⟨a, le_rfl⟩ ↔ x ≤ a := by simp [projIci, Subtype.ext_iff]
theorem projIic_eq_self : projIic b x = ⟨b, le_rfl⟩ ↔ b ≤ x := by simp [projIic, Subtype.ext_iff]
theorem projIcc_eq_left (h : a < b) : projIcc a b h.le x = ⟨a, left_mem_Icc.mpr h.le⟩ ↔ x ≤ a := by
simp [projIcc, Subtype.ext_iff, h.not_le]
theorem projIcc_eq_right (h : a < b) : projIcc a b h.le x = ⟨b, right_mem_Icc.2 h.le⟩ ↔ b ≤ x := by
simp [projIcc, Subtype.ext_iff, max_min_distrib_left, h.le, h.not_le]
theorem projIci_of_mem (hx : x ∈ Ici a) : projIci a x = ⟨x, hx⟩ := by simpa [projIci]
theorem projIic_of_mem (hx : x ∈ Iic b) : projIic b x = ⟨x, hx⟩ := by simpa [projIic]
theorem projIcc_of_mem (hx : x ∈ Icc a b) : projIcc a b h x = ⟨x, hx⟩ := by
simp [projIcc, hx.1, hx.2]
@[simp]
theorem projIci_coe (x : Ici a) : projIci a x = x := by cases x; apply projIci_of_mem
@[simp]
theorem projIic_coe (x : Iic b) : projIic b x = x := by cases x; apply projIic_of_mem
@[simp]
theorem projIcc_val (x : Icc a b) : projIcc a b h x = x := by
cases x
apply projIcc_of_mem
theorem projIci_surjOn : SurjOn (projIci a) (Ici a) univ := fun x _ => ⟨x, x.2, projIci_coe x⟩
theorem projIic_surjOn : SurjOn (projIic b) (Iic b) univ := fun x _ => ⟨x, x.2, projIic_coe x⟩
theorem projIcc_surjOn : SurjOn (projIcc a b h) (Icc a b) univ := fun x _ =>
⟨x, x.2, projIcc_val h x⟩
theorem projIci_surjective : Surjective (projIci a) := fun x => ⟨x, projIci_coe x⟩
theorem projIic_surjective : Surjective (projIic b) := fun x => ⟨x, projIic_coe x⟩
theorem projIcc_surjective : Surjective (projIcc a b h) := fun x => ⟨x, projIcc_val h x⟩
@[simp]
theorem range_projIci : range (projIci a) = univ := projIci_surjective.range_eq
@[simp]
theorem range_projIic : range (projIic a) = univ := projIic_surjective.range_eq
@[simp]
theorem range_projIcc : range (projIcc a b h) = univ :=
(projIcc_surjective h).range_eq
theorem monotone_projIci : Monotone (projIci a) := fun _ _ => max_le_max le_rfl
theorem monotone_projIic : Monotone (projIic a) := fun _ _ => min_le_min le_rfl
theorem monotone_projIcc : Monotone (projIcc a b h) := fun _ _ hxy =>
max_le_max le_rfl <| min_le_min le_rfl hxy
theorem strictMonoOn_projIci : StrictMonoOn (projIci a) (Ici a) := fun x hx y hy hxy => by
simpa only [projIci_of_mem, hx, hy]
theorem strictMonoOn_projIic : StrictMonoOn (projIic b) (Iic b) := fun x hx y hy hxy => by
simpa only [projIic_of_mem, hx, hy]
theorem strictMonoOn_projIcc : StrictMonoOn (projIcc a b h) (Icc a b) := fun x hx y hy hxy => by
simpa only [projIcc_of_mem, hx, hy]
/-- Extend a function `[a, ∞) → β` to a map `α → β`. -/
def IciExtend (f : Ici a → β) : α → β :=
f ∘ projIci a
/-- Extend a function `(-∞, b] → β` to a map `α → β`. -/
def IicExtend (f : Iic b → β) : α → β :=
f ∘ projIic b
/-- Extend a function `[a, b] → β` to a map `α → β`. -/
def IccExtend {a b : α} (h : a ≤ b) (f : Icc a b → β) : α → β :=
f ∘ projIcc a b h
theorem IciExtend_apply (f : Ici a → β) (x : α) : IciExtend f x = f ⟨max a x, le_max_left _ _⟩ :=
rfl
theorem IicExtend_apply (f : Iic b → β) (x : α) : IicExtend f x = f ⟨min b x, min_le_left _ _⟩ :=
rfl
theorem IccExtend_apply (h : a ≤ b) (f : Icc a b → β) (x : α) :
IccExtend h f x = f ⟨max a (min b x), le_max_left _ _, max_le h (min_le_left _ _)⟩ := rfl
@[simp]
theorem range_IciExtend (f : Ici a → β) : range (IciExtend f) = range f := by
simp only [IciExtend, range_comp f, range_projIci, range_id', image_univ]
@[simp]
theorem range_IicExtend (f : Iic b → β) : range (IicExtend f) = range f := by
simp only [IicExtend, range_comp f, range_projIic, range_id', image_univ]
@[simp]
theorem IccExtend_range (f : Icc a b → β) : range (IccExtend h f) = range f := by
simp only [IccExtend, range_comp f, range_projIcc, image_univ]
theorem IciExtend_of_le (f : Ici a → β) (hx : x ≤ a) : IciExtend f x = f ⟨a, le_rfl⟩ :=
congr_arg f <| projIci_of_le hx
theorem IicExtend_of_le (f : Iic b → β) (hx : b ≤ x) : IicExtend f x = f ⟨b, le_rfl⟩ :=
congr_arg f <| projIic_of_le hx
theorem IccExtend_of_le_left (f : Icc a b → β) (hx : x ≤ a) :
IccExtend h f x = f ⟨a, left_mem_Icc.2 h⟩ :=
congr_arg f <| projIcc_of_le_left h hx
theorem IccExtend_of_right_le (f : Icc a b → β) (hx : b ≤ x) :
IccExtend h f x = f ⟨b, right_mem_Icc.2 h⟩ :=
congr_arg f <| projIcc_of_right_le h hx
@[simp]
theorem IciExtend_self (f : Ici a → β) : IciExtend f a = f ⟨a, le_rfl⟩ :=
IciExtend_of_le f le_rfl
@[simp]
theorem IicExtend_self (f : Iic b → β) : IicExtend f b = f ⟨b, le_rfl⟩ :=
IicExtend_of_le f le_rfl
@[simp]
theorem IccExtend_left (f : Icc a b → β) : IccExtend h f a = f ⟨a, left_mem_Icc.2 h⟩ :=
IccExtend_of_le_left h f le_rfl
@[simp]
theorem IccExtend_right (f : Icc a b → β) : IccExtend h f b = f ⟨b, right_mem_Icc.2 h⟩ :=
IccExtend_of_right_le h f le_rfl
theorem IciExtend_of_mem (f : Ici a → β) (hx : x ∈ Ici a) : IciExtend f x = f ⟨x, hx⟩ :=
congr_arg f <| projIci_of_mem hx
theorem IicExtend_of_mem (f : Iic b → β) (hx : x ∈ Iic b) : IicExtend f x = f ⟨x, hx⟩ :=
congr_arg f <| projIic_of_mem hx
theorem IccExtend_of_mem (f : Icc a b → β) (hx : x ∈ Icc a b) : IccExtend h f x = f ⟨x, hx⟩ :=
congr_arg f <| projIcc_of_mem h hx
@[simp]
theorem IciExtend_coe (f : Ici a → β) (x : Ici a) : IciExtend f x = f x :=
congr_arg f <| projIci_coe x
@[simp]
theorem IicExtend_coe (f : Iic b → β) (x : Iic b) : IicExtend f x = f x :=
congr_arg f <| projIic_coe x
@[simp]
theorem IccExtend_val (f : Icc a b → β) (x : Icc a b) : IccExtend h f x = f x :=
congr_arg f <| projIcc_val h x
/-- If `f : α → β` is a constant both on $(-∞, a]$ and on $[b, +∞)$, then the extension of this
function from $[a, b]$ to the whole line is equal to the original function. -/
theorem IccExtend_eq_self (f : α → β) (ha : ∀ x < a, f x = f a) (hb : ∀ x, b < x → f x = f b) :
IccExtend h (f ∘ (↑)) = f := by
ext x
cases' lt_or_le x a with hxa hax
· simp [IccExtend_of_le_left _ _ hxa.le, ha x hxa]
· rcases le_or_lt x b with hxb | hbx
· lift x to Icc a b using ⟨hax, hxb⟩
rw [IccExtend_val, comp_apply]
· simp [IccExtend_of_right_le _ _ hbx.le, hb x hbx]
end Set
open Set
variable [Preorder β] {s t : Set α} {a b : α} (h : a ≤ b) {f : Icc a b → β}
protected theorem Monotone.IciExtend {f : Ici a → β} (hf : Monotone f) : Monotone (IciExtend f) :=
hf.comp monotone_projIci
protected theorem Monotone.IicExtend {f : Iic b → β} (hf : Monotone f) : Monotone (IicExtend f) :=
hf.comp monotone_projIic
protected theorem Monotone.IccExtend (hf : Monotone f) : Monotone (IccExtend h f) :=
hf.comp <| monotone_projIcc h
theorem StrictMono.strictMonoOn_IciExtend {f : Ici a → β} (hf : StrictMono f) :
StrictMonoOn (IciExtend f) (Ici a) :=
hf.comp_strictMonoOn strictMonoOn_projIci
theorem StrictMono.strictMonoOn_IicExtend {f : Iic b → β} (hf : StrictMono f) :
StrictMonoOn (IicExtend f) (Iic b) :=
hf.comp_strictMonoOn strictMonoOn_projIic
theorem StrictMono.strictMonoOn_IccExtend (hf : StrictMono f) :
StrictMonoOn (IccExtend h f) (Icc a b) :=
hf.comp_strictMonoOn (strictMonoOn_projIcc h)
protected theorem Set.OrdConnected.IciExtend {s : Set (Ici a)} (hs : s.OrdConnected) :
{x | IciExtend (· ∈ s) x}.OrdConnected :=
⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨max_le_max le_rfl hz.1, max_le_max le_rfl hz.2⟩⟩
protected theorem Set.OrdConnected.IicExtend {s : Set (Iic b)} (hs : s.OrdConnected) :
{x | IicExtend (· ∈ s) x}.OrdConnected :=
⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨min_le_min le_rfl hz.1, min_le_min le_rfl hz.2⟩⟩
protected theorem Set.OrdConnected.restrict (hs : s.OrdConnected) :
{x | restrict t (· ∈ s) x}.OrdConnected :=
⟨fun _ hx _ hy _ hz => hs.out hx hy hz⟩
|
Order\Interval\Set\SurjOn.lean | /-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.Function
/-!
# Monotone surjective functions are surjective on intervals
A monotone surjective function sends any interval in the domain onto the interval with corresponding
endpoints in the range. This is expressed in this file using `Set.surjOn`, and provided for all
permutations of interval endpoints.
-/
variable {α : Type*} {β : Type*} [LinearOrder α] [PartialOrder β] {f : α → β}
open Set Function
open OrderDual (toDual)
theorem surjOn_Ioo_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a b : α) : SurjOn f (Ioo a b) (Ioo (f a) (f b)) := by
intro p hp
rcases h_surj p with ⟨x, rfl⟩
refine ⟨x, mem_Ioo.2 ?_, rfl⟩
contrapose! hp
exact fun h => h.2.not_le (h_mono <| hp <| h_mono.reflect_lt h.1)
theorem surjOn_Ico_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a b : α) : SurjOn f (Ico a b) (Ico (f a) (f b)) := by
obtain hab | hab := lt_or_le a b
· intro p hp
rcases eq_left_or_mem_Ioo_of_mem_Ico hp with (rfl | hp')
· exact mem_image_of_mem f (left_mem_Ico.mpr hab)
· have := surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp'
exact image_subset f Ioo_subset_Ico_self this
· rw [Ico_eq_empty (h_mono hab).not_lt]
exact surjOn_empty f _
theorem surjOn_Ioc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a b : α) : SurjOn f (Ioc a b) (Ioc (f a) (f b)) := by
simpa using surjOn_Ico_of_monotone_surjective h_mono.dual h_surj (toDual b) (toDual a)
-- to see that the hypothesis `a ≤ b` is necessary, consider a constant function
theorem surjOn_Icc_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
{a b : α} (hab : a ≤ b) : SurjOn f (Icc a b) (Icc (f a) (f b)) := by
intro p hp
rcases eq_endpoints_or_mem_Ioo_of_mem_Icc hp with (rfl | rfl | hp')
· exact ⟨a, left_mem_Icc.mpr hab, rfl⟩
· exact ⟨b, right_mem_Icc.mpr hab, rfl⟩
· have := surjOn_Ioo_of_monotone_surjective h_mono h_surj a b hp'
exact image_subset f Ioo_subset_Icc_self this
theorem surjOn_Ioi_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a : α) : SurjOn f (Ioi a) (Ioi (f a)) := by
rw [← compl_Iic, ← compl_compl (Ioi (f a))]
refine MapsTo.surjOn_compl ?_ h_surj
exact fun x hx => (h_mono hx).not_lt
theorem surjOn_Iio_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a : α) : SurjOn f (Iio a) (Iio (f a)) :=
@surjOn_Ioi_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a
theorem surjOn_Ici_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a : α) : SurjOn f (Ici a) (Ici (f a)) := by
rw [← Ioi_union_left, ← Ioi_union_left]
exact
(surjOn_Ioi_of_monotone_surjective h_mono h_surj a).union_union
(@image_singleton _ _ f a ▸ surjOn_image _ _)
theorem surjOn_Iic_of_monotone_surjective (h_mono : Monotone f) (h_surj : Function.Surjective f)
(a : α) : SurjOn f (Iic a) (Iic (f a)) :=
@surjOn_Ici_of_monotone_surjective _ _ _ _ _ h_mono.dual h_surj a
|
Order\Interval\Set\UnorderedInterval.lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.Order.Interval.Set.Image
import Mathlib.Order.Bounds.Basic
import Mathlib.Tactic.Common
/-!
# Intervals without endpoints ordering
In any lattice `α`, we define `uIcc a b` to be `Icc (a ⊓ b) (a ⊔ b)`, which in a linear order is
the set of elements lying between `a` and `b`.
`Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The
interval as defined in this file is always the set of things lying between `a` and `b`, regardless
of the relative order of `a` and `b`.
For real numbers, `uIcc a b` is the same as `segment ℝ a b`.
In a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example,
`uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`,
`(-1, 1)`, `(1, 1)`.
In `Finset α` (seen as a hypercube of dimension `Fintype.card α`), `uIcc a b` is the smallest
subcube containing both `a` and `b`.
## Notation
We use the localized notation `[[a, b]]` for `uIcc a b`. One can open the locale `Interval` to
make the notation available.
-/
open Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
namespace Set
section Lattice
variable [Lattice α] [Lattice β] {a a₁ a₂ b b₁ b₂ c x : α}
/-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.
Note that we define it more generally in a lattice as `Set.Icc (a ⊓ b) (a ⊔ b)`. In a product type,
`uIcc` corresponds to the bounding box of the two elements. -/
def uIcc (a b : α) : Set α := Icc (a ⊓ b) (a ⊔ b)
-- Porting note: temporarily remove `scoped[uIcc]` and use `[[]]` instead of `[]` before a
-- workaround is found.
-- Porting note 2 : now `scoped[Interval]` works again.
/-- `[[a, b]]` denotes the set of elements lying between `a` and `b`, inclusive. -/
scoped[Interval] notation "[[" a ", " b "]]" => Set.uIcc a b
open Interval
@[simp] lemma dual_uIcc (a b : α) : [[toDual a, toDual b]] = ofDual ⁻¹' [[a, b]] :=
-- Note: needed to hint `(α := α)` after #8386 (elaboration order?)
dual_Icc (α := α)
@[simp]
lemma uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h]
@[simp]
lemma uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h]
lemma uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by simp_rw [uIcc, inf_comm, sup_comm]
lemma uIcc_of_lt (h : a < b) : [[a, b]] = Icc a b := uIcc_of_le h.le
lemma uIcc_of_gt (h : b < a) : [[a, b]] = Icc b a := uIcc_of_ge h.le
-- Porting note (#10618): `simp` can prove this
-- @[simp]
lemma uIcc_self : [[a, a]] = {a} := by simp [uIcc]
@[simp] lemma nonempty_uIcc : [[a, b]].Nonempty := nonempty_Icc.2 inf_le_sup
lemma Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right
lemma Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left
@[simp] lemma left_mem_uIcc : a ∈ [[a, b]] := ⟨inf_le_left, le_sup_left⟩
@[simp] lemma right_mem_uIcc : b ∈ [[a, b]] := ⟨inf_le_right, le_sup_right⟩
lemma mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc ⟨ha, hb⟩
lemma mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' ⟨hb, ha⟩
lemma uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) :
[[a₁, b₁]] ⊆ [[a₂, b₂]] :=
Icc_subset_Icc (le_inf h₁.1 h₂.1) (sup_le h₁.2 h₂.2)
lemma uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) :
[[a₁, b₁]] ⊆ Icc a₂ b₂ :=
Icc_subset_Icc (le_inf ha.1 hb.1) (sup_le ha.2 hb.2)
lemma uIcc_subset_uIcc_iff_mem :
[[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] :=
Iff.intro (fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩) fun h =>
uIcc_subset_uIcc h.1 h.2
lemma uIcc_subset_uIcc_iff_le' :
[[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ :=
Icc_subset_Icc_iff inf_le_sup
lemma uIcc_subset_uIcc_right (h : x ∈ [[a, b]]) : [[x, b]] ⊆ [[a, b]] :=
uIcc_subset_uIcc h right_mem_uIcc
lemma uIcc_subset_uIcc_left (h : x ∈ [[a, b]]) : [[a, x]] ⊆ [[a, b]] :=
uIcc_subset_uIcc left_mem_uIcc h
lemma bdd_below_bdd_above_iff_subset_uIcc (s : Set α) :
BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ [[a, b]] :=
bddBelow_bddAbove_iff_subset_Icc.trans
⟨fun ⟨a, b, h⟩ => ⟨a, b, fun _ hx => Icc_subset_uIcc (h hx)⟩, fun ⟨_, _, h⟩ => ⟨_, _, h⟩⟩
section Prod
@[simp]
theorem uIcc_prod_uIcc (a₁ a₂ : α) (b₁ b₂ : β) :
[[a₁, a₂]] ×ˢ [[b₁, b₂]] = [[(a₁, b₁), (a₂, b₂)]] :=
Icc_prod_Icc _ _ _ _
theorem uIcc_prod_eq (a b : α × β) : [[a, b]] = [[a.1, b.1]] ×ˢ [[a.2, b.2]] := by simp
end Prod
end Lattice
open Interval
section DistribLattice
variable [DistribLattice α] {a a₁ a₂ b b₁ b₂ c x : α}
lemma eq_of_mem_uIcc_of_mem_uIcc (ha : a ∈ [[b, c]]) (hb : b ∈ [[a, c]]) : a = b :=
eq_of_inf_eq_sup_eq (inf_congr_right ha.1 hb.1) <| sup_congr_right ha.2 hb.2
lemma eq_of_mem_uIcc_of_mem_uIcc' : b ∈ [[a, c]] → c ∈ [[a, b]] → b = c := by
simpa only [uIcc_comm a] using eq_of_mem_uIcc_of_mem_uIcc
lemma uIcc_injective_right (a : α) : Injective fun b => uIcc b a := fun b c h => by
rw [Set.ext_iff] at h
exact eq_of_mem_uIcc_of_mem_uIcc ((h _).1 left_mem_uIcc) ((h _).2 left_mem_uIcc)
lemma uIcc_injective_left (a : α) : Injective (uIcc a) := by
simpa only [uIcc_comm] using uIcc_injective_right a
end DistribLattice
section LinearOrder
variable [LinearOrder α]
section Lattice
variable [Lattice β] {f : α → β} {s : Set α} {a b : α}
lemma _root_.MonotoneOn.mapsTo_uIcc (hf : MonotoneOn f (uIcc a b)) :
MapsTo f (uIcc a b) (uIcc (f a) (f b)) := by
rw [uIcc, uIcc, ← hf.map_sup, ← hf.map_inf] <;>
apply_rules [left_mem_uIcc, right_mem_uIcc, hf.mapsTo_Icc]
lemma _root_.AntitoneOn.mapsTo_uIcc (hf : AntitoneOn f (uIcc a b)) :
MapsTo f (uIcc a b) (uIcc (f a) (f b)) := by
rw [uIcc, uIcc, ← hf.map_sup, ← hf.map_inf] <;>
apply_rules [left_mem_uIcc, right_mem_uIcc, hf.mapsTo_Icc]
lemma _root_.Monotone.mapsTo_uIcc (hf : Monotone f) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) :=
(hf.monotoneOn _).mapsTo_uIcc
lemma _root_.Antitone.mapsTo_uIcc (hf : Antitone f) : MapsTo f (uIcc a b) (uIcc (f a) (f b)) :=
(hf.antitoneOn _).mapsTo_uIcc
lemma _root_.MonotoneOn.image_uIcc_subset (hf : MonotoneOn f (uIcc a b)) :
f '' uIcc a b ⊆ uIcc (f a) (f b) := hf.mapsTo_uIcc.image_subset
lemma _root_.AntitoneOn.image_uIcc_subset (hf : AntitoneOn f (uIcc a b)) :
f '' uIcc a b ⊆ uIcc (f a) (f b) := hf.mapsTo_uIcc.image_subset
lemma _root_.Monotone.image_uIcc_subset (hf : Monotone f) : f '' uIcc a b ⊆ uIcc (f a) (f b) :=
(hf.monotoneOn _).image_uIcc_subset
lemma _root_.Antitone.image_uIcc_subset (hf : Antitone f) : f '' uIcc a b ⊆ uIcc (f a) (f b) :=
(hf.antitoneOn _).image_uIcc_subset
end Lattice
variable [LinearOrder β] {f : α → β} {s : Set α} {a a₁ a₂ b b₁ b₂ c d x : α}
theorem Icc_min_max : Icc (min a b) (max a b) = [[a, b]] :=
rfl
lemma uIcc_of_not_le (h : ¬a ≤ b) : [[a, b]] = Icc b a := uIcc_of_gt <| lt_of_not_ge h
lemma uIcc_of_not_ge (h : ¬b ≤ a) : [[a, b]] = Icc a b := uIcc_of_lt <| lt_of_not_ge h
lemma uIcc_eq_union : [[a, b]] = Icc a b ∪ Icc b a := by rw [Icc_union_Icc', max_comm] <;> rfl
lemma mem_uIcc : a ∈ [[b, c]] ↔ b ≤ a ∧ a ≤ c ∨ c ≤ a ∧ a ≤ b := by simp [uIcc_eq_union]
lemma not_mem_uIcc_of_lt (ha : c < a) (hb : c < b) : c ∉ [[a, b]] :=
not_mem_Icc_of_lt <| lt_min_iff.mpr ⟨ha, hb⟩
lemma not_mem_uIcc_of_gt (ha : a < c) (hb : b < c) : c ∉ [[a, b]] :=
not_mem_Icc_of_gt <| max_lt_iff.mpr ⟨ha, hb⟩
lemma uIcc_subset_uIcc_iff_le :
[[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ min a₂ b₂ ≤ min a₁ b₁ ∧ max a₁ b₁ ≤ max a₂ b₂ :=
uIcc_subset_uIcc_iff_le'
/-- A sort of triangle inequality. -/
lemma uIcc_subset_uIcc_union_uIcc : [[a, c]] ⊆ [[a, b]] ∪ [[b, c]] := fun x => by
simp only [mem_uIcc, mem_union]
rcases le_total x b with h2 | h2 <;> tauto
lemma monotone_or_antitone_iff_uIcc :
Monotone f ∨ Antitone f ↔ ∀ a b c, c ∈ [[a, b]] → f c ∈ [[f a, f b]] := by
constructor
· rintro (hf | hf) a b c <;> simp_rw [← Icc_min_max, ← hf.map_min, ← hf.map_max]
exacts [fun hc => ⟨hf hc.1, hf hc.2⟩, fun hc => ⟨hf hc.2, hf hc.1⟩]
contrapose!
rw [not_monotone_not_antitone_iff_exists_le_le]
rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩
· exact ⟨a, c, b, Icc_subset_uIcc ⟨hab, hbc⟩, fun h => h.2.not_lt <| max_lt hfab hfcb⟩
· exact ⟨a, c, b, Icc_subset_uIcc ⟨hab, hbc⟩, fun h => h.1.not_lt <| lt_min hfba hfbc⟩
-- Porting note: mathport expands the syntactic sugar `∀ a b c ∈ s` differently than Lean3
lemma monotoneOn_or_antitoneOn_iff_uIcc :
MonotoneOn f s ∨ AntitoneOn f s ↔
∀ᵉ (a ∈ s) (b ∈ s) (c ∈ s), c ∈ [[a, b]] → f c ∈ [[f a, f b]] := by
simp [monotoneOn_iff_monotone, antitoneOn_iff_antitone, monotone_or_antitone_iff_uIcc,
mem_uIcc]
-- Porting note: what should the naming scheme be here? This is a term, so should be `uIoc`,
-- but we also want to match the `Ioc` convention.
/-- The open-closed uIcc with unordered bounds. -/
def uIoc : α → α → Set α := fun a b => Ioc (min a b) (max a b)
-- Porting note: removed `scoped[uIcc]` temporarily before a workaround is found
-- Below is a capital iota
/-- `Ι a b` denotes the open-closed interval with unordered bounds. Here, `Ι` is a capital iota,
distinguished from a capital `i`. -/
notation "Ι" => Set.uIoc
@[simp] lemma uIoc_of_le (h : a ≤ b) : Ι a b = Ioc a b := by simp [uIoc, h]
@[simp] lemma uIoc_of_ge (h : b ≤ a) : Ι a b = Ioc b a := by simp [uIoc, h]
lemma uIoc_eq_union : Ι a b = Ioc a b ∪ Ioc b a := by
cases le_total a b <;> simp [uIoc, *]
lemma mem_uIoc : a ∈ Ι b c ↔ b < a ∧ a ≤ c ∨ c < a ∧ a ≤ b := by
rw [uIoc_eq_union, mem_union, mem_Ioc, mem_Ioc]
lemma not_mem_uIoc : a ∉ Ι b c ↔ a ≤ b ∧ a ≤ c ∨ c < a ∧ b < a := by
simp only [uIoc_eq_union, mem_union, mem_Ioc, not_lt, ← not_le]
tauto
@[simp] lemma left_mem_uIoc : a ∈ Ι a b ↔ b < a := by simp [mem_uIoc]
@[simp] lemma right_mem_uIoc : b ∈ Ι a b ↔ a < b := by simp [mem_uIoc]
lemma forall_uIoc_iff {P : α → Prop} :
(∀ x ∈ Ι a b, P x) ↔ (∀ x ∈ Ioc a b, P x) ∧ ∀ x ∈ Ioc b a, P x := by
simp only [uIoc_eq_union, mem_union, or_imp, forall_and]
lemma uIoc_subset_uIoc_of_uIcc_subset_uIcc {a b c d : α}
(h : [[a, b]] ⊆ [[c, d]]) : Ι a b ⊆ Ι c d :=
Ioc_subset_Ioc (uIcc_subset_uIcc_iff_le.1 h).1 (uIcc_subset_uIcc_iff_le.1 h).2
lemma uIoc_comm (a b : α) : Ι a b = Ι b a := by simp only [uIoc, min_comm a b, max_comm a b]
lemma Ioc_subset_uIoc : Ioc a b ⊆ Ι a b := Ioc_subset_Ioc (min_le_left _ _) (le_max_right _ _)
lemma Ioc_subset_uIoc' : Ioc a b ⊆ Ι b a := Ioc_subset_Ioc (min_le_right _ _) (le_max_left _ _)
lemma uIoc_subset_uIcc : Ι a b ⊆ uIcc a b := Ioc_subset_Icc_self
lemma eq_of_mem_uIoc_of_mem_uIoc : a ∈ Ι b c → b ∈ Ι a c → a = b := by
simp_rw [mem_uIoc]; rintro (⟨_, _⟩ | ⟨_, _⟩) (⟨_, _⟩ | ⟨_, _⟩) <;> apply le_antisymm <;>
first |assumption|exact le_of_lt ‹_›|exact le_trans ‹_› (le_of_lt ‹_›)
lemma eq_of_mem_uIoc_of_mem_uIoc' : b ∈ Ι a c → c ∈ Ι a b → b = c := by
simpa only [uIoc_comm a] using eq_of_mem_uIoc_of_mem_uIoc
lemma eq_of_not_mem_uIoc_of_not_mem_uIoc (ha : a ≤ c) (hb : b ≤ c) :
a ∉ Ι b c → b ∉ Ι a c → a = b := by
simp_rw [not_mem_uIoc]
rintro (⟨_, _⟩ | ⟨_, _⟩) (⟨_, _⟩ | ⟨_, _⟩) <;>
apply le_antisymm <;>
first |assumption|exact le_of_lt ‹_›|
exact absurd hb (not_le_of_lt ‹c < b›)|exact absurd ha (not_le_of_lt ‹c < a›)
lemma uIoc_injective_right (a : α) : Injective fun b => Ι b a := by
rintro b c h
rw [Set.ext_iff] at h
obtain ha | ha := le_or_lt b a
· have hb := (h b).not
simp only [ha, left_mem_uIoc, not_lt, true_iff_iff, not_mem_uIoc, ← not_le,
and_true_iff, not_true, false_and_iff, not_false_iff, true_iff_iff, or_false_iff] at hb
refine hb.eq_of_not_lt fun hc => ?_
simpa [ha, and_iff_right hc, ← @not_le _ _ _ a, iff_not_self, -not_le] using h c
· refine
eq_of_mem_uIoc_of_mem_uIoc ((h _).1 <| left_mem_uIoc.2 ha)
((h _).2 <| left_mem_uIoc.2 <| ha.trans_le ?_)
simpa [ha, ha.not_le, mem_uIoc] using h b
lemma uIoc_injective_left (a : α) : Injective (Ι a) := by
simpa only [uIoc_comm] using uIoc_injective_right a
end LinearOrder
end Set
|
Order\Interval\Set\WithBotTop.lean | /-
Copyright (c) 2022 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Data.Set.Image
import Mathlib.Order.Interval.Set.Basic
/-!
# Intervals in `WithTop α` and `WithBot α`
In this file we prove various lemmas about `Set.image`s and `Set.preimage`s of intervals under
`some : α → WithTop α` and `some : α → WithBot α`.
-/
open Set
variable {α : Type*}
/-! ### `WithTop` -/
namespace WithTop
@[simp]
theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊤} = (∅ : Set α) :=
eq_empty_of_subset_empty fun _ => coe_ne_top
variable [Preorder α] {a b : α}
theorem range_coe : range (some : α → WithTop α) = Iio ⊤ := by
ext x
rw [mem_Iio, WithTop.lt_top_iff_ne_top, mem_range, ne_top_iff_exists]
@[simp]
theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic]
@[simp]
theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio]
@[simp]
theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic]
@[simp]
theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio]
@[simp]
theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊤ = univ := by
rw [← range_coe, preimage_range]
@[simp]
theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊤ = Ici a := by
simp [← Ici_inter_Iio]
@[simp]
theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊤ = Ioi a := by
simp [← Ioi_inter_Iio]
theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊤ := by
rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio]
theorem image_coe_Ici : (some : α → WithTop α) '' Ici a = Ico (a : WithTop α) ⊤ := by
rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, Ici_inter_Iio]
theorem image_coe_Iio : (some : α → WithTop α) '' Iio a = Iio (a : WithTop α) := by
rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Iio_subset_Iio le_top)]
theorem image_coe_Iic : (some : α → WithTop α) '' Iic a = Iic (a : WithTop α) := by
rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Iic_subset_Iio.2 <| coe_lt_top a)]
theorem image_coe_Icc : (some : α → WithTop α) '' Icc a b = Icc (a : WithTop α) b := by
rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left
(Subset.trans Icc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)]
theorem image_coe_Ico : (some : α → WithTop α) '' Ico a b = Ico (a : WithTop α) b := by
rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Subset.trans Ico_subset_Iio_self <| Iio_subset_Iio le_top)]
theorem image_coe_Ioc : (some : α → WithTop α) '' Ioc a b = Ioc (a : WithTop α) b := by
rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left
(Subset.trans Ioc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)]
theorem image_coe_Ioo : (some : α → WithTop α) '' Ioo a b = Ioo (a : WithTop α) b := by
rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Iio_self <| Iio_subset_Iio le_top)]
end WithTop
/-! ### `WithBot` -/
namespace WithBot
@[simp]
theorem preimage_coe_bot : (some : α → WithBot α) ⁻¹' {⊥} = (∅ : Set α) :=
@WithTop.preimage_coe_top αᵒᵈ
variable [Preorder α] {a b : α}
theorem range_coe : range (some : α → WithBot α) = Ioi ⊥ :=
@WithTop.range_coe αᵒᵈ _
@[simp]
theorem preimage_coe_Ioi : (some : α → WithBot α) ⁻¹' Ioi a = Ioi a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Ici : (some : α → WithBot α) ⁻¹' Ici a = Ici a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Iio : (some : α → WithBot α) ⁻¹' Iio a = Iio a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Iic : (some : α → WithBot α) ⁻¹' Iic a = Iic a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Icc : (some : α → WithBot α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic]
@[simp]
theorem preimage_coe_Ico : (some : α → WithBot α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio]
@[simp]
theorem preimage_coe_Ioc : (some : α → WithBot α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic]
@[simp]
theorem preimage_coe_Ioo : (some : α → WithBot α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio]
@[simp]
theorem preimage_coe_Ioi_bot : (some : α → WithBot α) ⁻¹' Ioi ⊥ = univ := by
rw [← range_coe, preimage_range]
@[simp]
theorem preimage_coe_Ioc_bot : (some : α → WithBot α) ⁻¹' Ioc ⊥ a = Iic a := by
simp [← Ioi_inter_Iic]
@[simp]
theorem preimage_coe_Ioo_bot : (some : α → WithBot α) ⁻¹' Ioo ⊥ a = Iio a := by
simp [← Ioi_inter_Iio]
theorem image_coe_Iio : (some : α → WithBot α) '' Iio a = Ioo (⊥ : WithBot α) a := by
rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iio]
theorem image_coe_Iic : (some : α → WithBot α) '' Iic a = Ioc (⊥ : WithBot α) a := by
rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iic]
theorem image_coe_Ioi : (some : α → WithBot α) '' Ioi a = Ioi (a : WithBot α) := by
rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Ioi_subset_Ioi bot_le)]
theorem image_coe_Ici : (some : α → WithBot α) '' Ici a = Ici (a : WithBot α) := by
rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Ici_subset_Ioi.2 <| bot_lt_coe a)]
theorem image_coe_Icc : (some : α → WithBot α) '' Icc a b = Icc (a : WithBot α) b := by
rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left
(Subset.trans Icc_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)]
theorem image_coe_Ioc : (some : α → WithBot α) '' Ioc a b = Ioc (a : WithBot α) b := by
rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Ioi_self <| Ioi_subset_Ioi bot_le)]
theorem image_coe_Ico : (some : α → WithBot α) '' Ico a b = Ico (a : WithBot α) b := by
rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left
(Subset.trans Ico_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)]
theorem image_coe_Ioo : (some : α → WithBot α) '' Ioo a b = Ioo (a : WithBot α) b := by
rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe,
inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Ioi_self <| Ioi_subset_Ioi bot_le)]
end WithBot
|
Order\Monotone\Basic.lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yaël Dillies
-/
import Mathlib.Logic.Function.Iterate
import Mathlib.Init.Data.Int.Order
import Mathlib.Order.Compare
import Mathlib.Order.Max
import Mathlib.Order.RelClasses
import Mathlib.Tactic.Coe
import Mathlib.Tactic.Choose
/-!
# Monotonicity
This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage,
"monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti"
to mean "decreasing".
## Definitions
* `Monotone f`: A function `f` between two preorders is monotone if `a ≤ b` implies `f a ≤ f b`.
* `Antitone f`: A function `f` between two preorders is antitone if `a ≤ b` implies `f b ≤ f a`.
* `MonotoneOn f s`: Same as `Monotone f`, but for all `a, b ∈ s`.
* `AntitoneOn f s`: Same as `Antitone f`, but for all `a, b ∈ s`.
* `StrictMono f` : A function `f` between two preorders is strictly monotone if `a < b` implies
`f a < f b`.
* `StrictAnti f` : A function `f` between two preorders is strictly antitone if `a < b` implies
`f b < f a`.
* `StrictMonoOn f s`: Same as `StrictMono f`, but for all `a, b ∈ s`.
* `StrictAntiOn f s`: Same as `StrictAnti f`, but for all `a, b ∈ s`.
## Main theorems
* `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n ≤ f (n + 1)` for all `n`, then `f` is monotone.
* `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) ≤ f n` for all `n`, then `f` is antitone.
* `strictMono_nat_of_lt_succ`, `strictMono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n < f (n + 1)` for all `n`, then `f` is strictly monotone.
* `strictAnti_nat_of_succ_lt`, `strictAnti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) < f n` for all `n`, then `f` is strictly antitone.
## Implementation notes
Some of these definitions used to only require `LE α` or `LT α`. The advantage of this is
unclear and it led to slight elaboration issues. Now, everything requires `Preorder α` and seems to
work fine. Related Zulip discussion:
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352.
## TODO
The above theorems are also true in `ℕ+`, `Fin n`... To make that work, we need `SuccOrder α`
and `IsSuccArchimedean α`.
## Tags
monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing,
decreasing, strictly decreasing
-/
open Function OrderDual
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {π : ι → Type*}
{r : α → α → Prop}
section MonotoneDef
variable [Preorder α] [Preorder β]
/-- A function `f` is monotone if `a ≤ b` implies `f a ≤ f b`. -/
def Monotone (f : α → β) : Prop :=
∀ ⦃a b⦄, a ≤ b → f a ≤ f b
/-- A function `f` is antitone if `a ≤ b` implies `f b ≤ f a`. -/
def Antitone (f : α → β) : Prop :=
∀ ⦃a b⦄, a ≤ b → f b ≤ f a
/-- A function `f` is monotone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f a ≤ f b`. -/
def MonotoneOn (f : α → β) (s : Set α) : Prop :=
∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f a ≤ f b
/-- A function `f` is antitone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f b ≤ f a`. -/
def AntitoneOn (f : α → β) (s : Set α) : Prop :=
∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a ≤ b → f b ≤ f a
/-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/
def StrictMono (f : α → β) : Prop :=
∀ ⦃a b⦄, a < b → f a < f b
/-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/
def StrictAnti (f : α → β) : Prop :=
∀ ⦃a b⦄, a < b → f b < f a
/-- A function `f` is strictly monotone on `s` if, for all `a, b ∈ s`, `a < b` implies
`f a < f b`. -/
def StrictMonoOn (f : α → β) (s : Set α) : Prop :=
∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a < f b
/-- A function `f` is strictly antitone on `s` if, for all `a, b ∈ s`, `a < b` implies
`f b < f a`. -/
def StrictAntiOn (f : α → β) (s : Set α) : Prop :=
∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b < f a
end MonotoneDef
section Decidable
variable [Preorder α] [Preorder β] {f : α → β} {s : Set α}
instance [i : Decidable (∀ a b, a ≤ b → f a ≤ f b)] : Decidable (Monotone f) := i
instance [i : Decidable (∀ a b, a ≤ b → f b ≤ f a)] : Decidable (Antitone f) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f a ≤ f b)] :
Decidable (MonotoneOn f s) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a ≤ b → f b ≤ f a)] :
Decidable (AntitoneOn f s) := i
instance [i : Decidable (∀ a b, a < b → f a < f b)] : Decidable (StrictMono f) := i
instance [i : Decidable (∀ a b, a < b → f b < f a)] : Decidable (StrictAnti f) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f a < f b)] :
Decidable (StrictMonoOn f s) := i
instance [i : Decidable (∀ a ∈ s, ∀ b ∈ s, a < b → f b < f a)] :
Decidable (StrictAntiOn f s) := i
end Decidable
lemma monotone_inclusion_le_le_of_le [Preorder α] {k j : α} (hkj : k ≤ j) :
Monotone (fun ⟨i, hi⟩ => ⟨i, hi.trans hkj⟩ : { i // i ≤ k } → { i // i ≤ j}) :=
fun _ _ h => h
lemma monotone_inclusion_lt_le_of_le [Preorder α] {k j : α} (hkj : k ≤ j) :
Monotone (fun ⟨i, hi⟩ => ⟨i, hi.le.trans hkj⟩ : { i // i < k } → { i // i ≤ j}) :=
fun _ _ h => h
lemma monotone_inclusion_lt_lt_of_le [Preorder α] {k j : α} (hkj : k ≤ j) :
Monotone (fun ⟨i, hi⟩ => ⟨i, lt_of_lt_of_le hi hkj⟩ : { i // i < k } → { i // i < j}) :=
fun _ _ h => h
/-! ### Monotonicity on the dual order
Strictly, many of the `*On.dual` lemmas in this section should use `ofDual ⁻¹' s` instead of `s`,
but right now this is not possible as `Set.preimage` is not defined yet, and importing it creates
an import cycle.
Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`,
`.dual_left` or `.dual_right` to your `Monotone`/`Antitone` hypothesis.
-/
section OrderDual
variable [Preorder α] [Preorder β] {f : α → β} {s : Set α}
@[simp]
theorem monotone_comp_ofDual_iff : Monotone (f ∘ ofDual) ↔ Antitone f :=
forall_swap
@[simp]
theorem antitone_comp_ofDual_iff : Antitone (f ∘ ofDual) ↔ Monotone f :=
forall_swap
-- Porting note:
-- Here (and below) without the type ascription, Lean is seeing through the
-- defeq `βᵒᵈ = β` and picking up the wrong `Preorder` instance.
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/logic.2Eequiv.2Ebasic.20mathlib4.23631/near/311744939
@[simp]
theorem monotone_toDual_comp_iff : Monotone (toDual ∘ f : α → βᵒᵈ) ↔ Antitone f :=
Iff.rfl
@[simp]
theorem antitone_toDual_comp_iff : Antitone (toDual ∘ f : α → βᵒᵈ) ↔ Monotone f :=
Iff.rfl
@[simp]
theorem monotoneOn_comp_ofDual_iff : MonotoneOn (f ∘ ofDual) s ↔ AntitoneOn f s :=
forall₂_swap
@[simp]
theorem antitoneOn_comp_ofDual_iff : AntitoneOn (f ∘ ofDual) s ↔ MonotoneOn f s :=
forall₂_swap
@[simp]
theorem monotoneOn_toDual_comp_iff : MonotoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ AntitoneOn f s :=
Iff.rfl
@[simp]
theorem antitoneOn_toDual_comp_iff : AntitoneOn (toDual ∘ f : α → βᵒᵈ) s ↔ MonotoneOn f s :=
Iff.rfl
@[simp]
theorem strictMono_comp_ofDual_iff : StrictMono (f ∘ ofDual) ↔ StrictAnti f :=
forall_swap
@[simp]
theorem strictAnti_comp_ofDual_iff : StrictAnti (f ∘ ofDual) ↔ StrictMono f :=
forall_swap
@[simp]
theorem strictMono_toDual_comp_iff : StrictMono (toDual ∘ f : α → βᵒᵈ) ↔ StrictAnti f :=
Iff.rfl
@[simp]
theorem strictAnti_toDual_comp_iff : StrictAnti (toDual ∘ f : α → βᵒᵈ) ↔ StrictMono f :=
Iff.rfl
@[simp]
theorem strictMonoOn_comp_ofDual_iff : StrictMonoOn (f ∘ ofDual) s ↔ StrictAntiOn f s :=
forall₂_swap
@[simp]
theorem strictAntiOn_comp_ofDual_iff : StrictAntiOn (f ∘ ofDual) s ↔ StrictMonoOn f s :=
forall₂_swap
@[simp]
theorem strictMonoOn_toDual_comp_iff : StrictMonoOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictAntiOn f s :=
Iff.rfl
@[simp]
theorem strictAntiOn_toDual_comp_iff : StrictAntiOn (toDual ∘ f : α → βᵒᵈ) s ↔ StrictMonoOn f s :=
Iff.rfl
theorem monotone_dual_iff : Monotone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Monotone f := by
rw [monotone_toDual_comp_iff, antitone_comp_ofDual_iff]
theorem antitone_dual_iff : Antitone (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ Antitone f := by
rw [antitone_toDual_comp_iff, monotone_comp_ofDual_iff]
theorem monotoneOn_dual_iff : MonotoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ MonotoneOn f s := by
rw [monotoneOn_toDual_comp_iff, antitoneOn_comp_ofDual_iff]
theorem antitoneOn_dual_iff : AntitoneOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ AntitoneOn f s := by
rw [antitoneOn_toDual_comp_iff, monotoneOn_comp_ofDual_iff]
theorem strictMono_dual_iff : StrictMono (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictMono f := by
rw [strictMono_toDual_comp_iff, strictAnti_comp_ofDual_iff]
theorem strictAnti_dual_iff : StrictAnti (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) ↔ StrictAnti f := by
rw [strictAnti_toDual_comp_iff, strictMono_comp_ofDual_iff]
theorem strictMonoOn_dual_iff :
StrictMonoOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictMonoOn f s := by
rw [strictMonoOn_toDual_comp_iff, strictAntiOn_comp_ofDual_iff]
theorem strictAntiOn_dual_iff :
StrictAntiOn (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ) s ↔ StrictAntiOn f s := by
rw [strictAntiOn_toDual_comp_iff, strictMonoOn_comp_ofDual_iff]
alias ⟨_, Monotone.dual_left⟩ := antitone_comp_ofDual_iff
alias ⟨_, Antitone.dual_left⟩ := monotone_comp_ofDual_iff
alias ⟨_, Monotone.dual_right⟩ := antitone_toDual_comp_iff
alias ⟨_, Antitone.dual_right⟩ := monotone_toDual_comp_iff
alias ⟨_, MonotoneOn.dual_left⟩ := antitoneOn_comp_ofDual_iff
alias ⟨_, AntitoneOn.dual_left⟩ := monotoneOn_comp_ofDual_iff
alias ⟨_, MonotoneOn.dual_right⟩ := antitoneOn_toDual_comp_iff
alias ⟨_, AntitoneOn.dual_right⟩ := monotoneOn_toDual_comp_iff
alias ⟨_, StrictMono.dual_left⟩ := strictAnti_comp_ofDual_iff
alias ⟨_, StrictAnti.dual_left⟩ := strictMono_comp_ofDual_iff
alias ⟨_, StrictMono.dual_right⟩ := strictAnti_toDual_comp_iff
alias ⟨_, StrictAnti.dual_right⟩ := strictMono_toDual_comp_iff
alias ⟨_, StrictMonoOn.dual_left⟩ := strictAntiOn_comp_ofDual_iff
alias ⟨_, StrictAntiOn.dual_left⟩ := strictMonoOn_comp_ofDual_iff
alias ⟨_, StrictMonoOn.dual_right⟩ := strictAntiOn_toDual_comp_iff
alias ⟨_, StrictAntiOn.dual_right⟩ := strictMonoOn_toDual_comp_iff
alias ⟨_, Monotone.dual⟩ := monotone_dual_iff
alias ⟨_, Antitone.dual⟩ := antitone_dual_iff
alias ⟨_, MonotoneOn.dual⟩ := monotoneOn_dual_iff
alias ⟨_, AntitoneOn.dual⟩ := antitoneOn_dual_iff
alias ⟨_, StrictMono.dual⟩ := strictMono_dual_iff
alias ⟨_, StrictAnti.dual⟩ := strictAnti_dual_iff
alias ⟨_, StrictMonoOn.dual⟩ := strictMonoOn_dual_iff
alias ⟨_, StrictAntiOn.dual⟩ := strictAntiOn_dual_iff
end OrderDual
/-! ### Monotonicity in function spaces -/
section Preorder
variable [Preorder α]
theorem Monotone.comp_le_comp_left
[Preorder β] {f : β → α} {g h : γ → β} (hf : Monotone f) (le_gh : g ≤ h) :
LE.le.{max w u} (f ∘ g) (f ∘ h) :=
fun x ↦ hf (le_gh x)
variable [Preorder γ]
theorem monotone_lam {f : α → β → γ} (hf : ∀ b, Monotone fun a ↦ f a b) : Monotone f :=
fun _ _ h b ↦ hf b h
theorem monotone_app (f : β → α → γ) (b : β) (hf : Monotone fun a b ↦ f b a) : Monotone (f b) :=
fun _ _ h ↦ hf h b
theorem antitone_lam {f : α → β → γ} (hf : ∀ b, Antitone fun a ↦ f a b) : Antitone f :=
fun _ _ h b ↦ hf b h
theorem antitone_app (f : β → α → γ) (b : β) (hf : Antitone fun a b ↦ f b a) : Antitone (f b) :=
fun _ _ h ↦ hf h b
end Preorder
theorem Function.monotone_eval {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] (i : ι) :
Monotone (Function.eval i : (∀ i, α i) → α i) := fun _ _ H ↦ H i
/-! ### Monotonicity hierarchy -/
section Preorder
variable [Preorder α]
section Preorder
variable [Preorder β] {f : α → β} {a b : α}
/-!
These four lemmas are there to strip off the semi-implicit arguments `⦃a b : α⦄`. This is useful
when you do not want to apply a `Monotone` assumption (i.e. your goal is `a ≤ b → f a ≤ f b`).
However if you find yourself writing `hf.imp h`, then you should have written `hf h` instead.
-/
theorem Monotone.imp (hf : Monotone f) (h : a ≤ b) : f a ≤ f b :=
hf h
theorem Antitone.imp (hf : Antitone f) (h : a ≤ b) : f b ≤ f a :=
hf h
theorem StrictMono.imp (hf : StrictMono f) (h : a < b) : f a < f b :=
hf h
theorem StrictAnti.imp (hf : StrictAnti f) (h : a < b) : f b < f a :=
hf h
protected theorem Monotone.monotoneOn (hf : Monotone f) (s : Set α) : MonotoneOn f s :=
fun _ _ _ _ ↦ hf.imp
protected theorem Antitone.antitoneOn (hf : Antitone f) (s : Set α) : AntitoneOn f s :=
fun _ _ _ _ ↦ hf.imp
@[simp] theorem monotoneOn_univ : MonotoneOn f Set.univ ↔ Monotone f :=
⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.monotoneOn _⟩
@[simp] theorem antitoneOn_univ : AntitoneOn f Set.univ ↔ Antitone f :=
⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.antitoneOn _⟩
protected theorem StrictMono.strictMonoOn (hf : StrictMono f) (s : Set α) : StrictMonoOn f s :=
fun _ _ _ _ ↦ hf.imp
protected theorem StrictAnti.strictAntiOn (hf : StrictAnti f) (s : Set α) : StrictAntiOn f s :=
fun _ _ _ _ ↦ hf.imp
@[simp] theorem strictMonoOn_univ : StrictMonoOn f Set.univ ↔ StrictMono f :=
⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictMonoOn _⟩
@[simp] theorem strictAntiOn_univ : StrictAntiOn f Set.univ ↔ StrictAnti f :=
⟨fun h _ _ ↦ h trivial trivial, fun h ↦ h.strictAntiOn _⟩
end Preorder
section PartialOrder
variable [PartialOrder β] {f : α → β}
theorem Monotone.strictMono_of_injective (h₁ : Monotone f) (h₂ : Injective f) : StrictMono f :=
fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H
theorem Antitone.strictAnti_of_injective (h₁ : Antitone f) (h₂ : Injective f) : StrictAnti f :=
fun _ _ h ↦ (h₁ h.le).lt_of_ne fun H ↦ h.ne <| h₂ H.symm
end PartialOrder
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β] {f : α → β} {s : Set α}
theorem monotone_iff_forall_lt : Monotone f ↔ ∀ ⦃a b⦄, a < b → f a ≤ f b :=
forall₂_congr fun _ _ ↦
⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) hf⟩
theorem antitone_iff_forall_lt : Antitone f ↔ ∀ ⦃a b⦄, a < b → f b ≤ f a :=
forall₂_congr fun _ _ ↦
⟨fun hf h ↦ hf h.le, fun hf h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) hf⟩
theorem monotoneOn_iff_forall_lt :
MonotoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f a ≤ f b :=
⟨fun hf _ ha _ hb h ↦ hf ha hb h.le,
fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).le) (hf ha hb)⟩
theorem antitoneOn_iff_forall_lt :
AntitoneOn f s ↔ ∀ ⦃a⦄ (_ : a ∈ s) ⦃b⦄ (_ : b ∈ s), a < b → f b ≤ f a :=
⟨fun hf _ ha _ hb h ↦ hf ha hb h.le,
fun hf _ ha _ hb h ↦ h.eq_or_lt.elim (fun H ↦ (congr_arg _ H).ge) (hf ha hb)⟩
-- `Preorder α` isn't strong enough: if the preorder on `α` is an equivalence relation,
-- then `StrictMono f` is vacuously true.
protected theorem StrictMonoOn.monotoneOn (hf : StrictMonoOn f s) : MonotoneOn f s :=
monotoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le
protected theorem StrictAntiOn.antitoneOn (hf : StrictAntiOn f s) : AntitoneOn f s :=
antitoneOn_iff_forall_lt.2 fun _ ha _ hb h ↦ (hf ha hb h).le
protected theorem StrictMono.monotone (hf : StrictMono f) : Monotone f :=
monotone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le
protected theorem StrictAnti.antitone (hf : StrictAnti f) : Antitone f :=
antitone_iff_forall_lt.2 fun _ _ h ↦ (hf h).le
end PartialOrder
/-! ### Monotonicity from and to subsingletons -/
namespace Subsingleton
variable [Preorder α] [Preorder β]
protected theorem monotone [Subsingleton α] (f : α → β) : Monotone f :=
fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le
protected theorem antitone [Subsingleton α] (f : α → β) : Antitone f :=
fun _ _ _ ↦ (congr_arg _ <| Subsingleton.elim _ _).le
theorem monotone' [Subsingleton β] (f : α → β) : Monotone f :=
fun _ _ _ ↦ (Subsingleton.elim _ _).le
theorem antitone' [Subsingleton β] (f : α → β) : Antitone f :=
fun _ _ _ ↦ (Subsingleton.elim _ _).le
protected theorem strictMono [Subsingleton α] (f : α → β) : StrictMono f :=
fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim
protected theorem strictAnti [Subsingleton α] (f : α → β) : StrictAnti f :=
fun _ _ h ↦ (h.ne <| Subsingleton.elim _ _).elim
end Subsingleton
/-! ### Miscellaneous monotonicity results -/
theorem monotone_id [Preorder α] : Monotone (id : α → α) := fun _ _ ↦ id
theorem monotoneOn_id [Preorder α] {s : Set α} : MonotoneOn id s := fun _ _ _ _ ↦ id
theorem strictMono_id [Preorder α] : StrictMono (id : α → α) := fun _ _ ↦ id
theorem strictMonoOn_id [Preorder α] {s : Set α} : StrictMonoOn id s := fun _ _ _ _ ↦ id
theorem monotone_const [Preorder α] [Preorder β] {c : β} : Monotone fun _ : α ↦ c :=
fun _ _ _ ↦ le_rfl
theorem monotoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} :
MonotoneOn (fun _ : α ↦ c) s :=
fun _ _ _ _ _ ↦ le_rfl
theorem antitone_const [Preorder α] [Preorder β] {c : β} : Antitone fun _ : α ↦ c :=
fun _ _ _ ↦ le_refl c
theorem antitoneOn_const [Preorder α] [Preorder β] {c : β} {s : Set α} :
AntitoneOn (fun _ : α ↦ c) s :=
fun _ _ _ _ _ ↦ le_rfl
theorem strictMono_of_le_iff_le [Preorder α] [Preorder β] {f : α → β}
(h : ∀ x y, x ≤ y ↔ f x ≤ f y) : StrictMono f :=
fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1
theorem strictAnti_of_le_iff_le [Preorder α] [Preorder β] {f : α → β}
(h : ∀ x y, x ≤ y ↔ f y ≤ f x) : StrictAnti f :=
fun _ _ ↦ (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1
-- Porting note: mathlib3 proof uses `contrapose` tactic
theorem injective_of_lt_imp_ne [LinearOrder α] {f : α → β} (h : ∀ x y, x < y → f x ≠ f y) :
Injective f := by
intro x y hf
rcases lt_trichotomy x y with (hxy | rfl | hxy)
· exact absurd hf <| h _ _ hxy
· rfl
· exact absurd hf.symm <| h _ _ hxy
theorem injective_of_le_imp_le [PartialOrder α] [Preorder β] (f : α → β)
(h : ∀ {x y}, f x ≤ f y → x ≤ y) : Injective f :=
fun _ _ hxy ↦ (h hxy.le).antisymm (h hxy.ge)
section Preorder
variable [Preorder α] [Preorder β] {f g : α → β} {a : α}
theorem StrictMono.isMax_of_apply (hf : StrictMono f) (ha : IsMax (f a)) : IsMax a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMax_iff.1 h
(hf hb).not_isMax ha
theorem StrictMono.isMin_of_apply (hf : StrictMono f) (ha : IsMin (f a)) : IsMin a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMin_iff.1 h
(hf hb).not_isMin ha
theorem StrictAnti.isMax_of_apply (hf : StrictAnti f) (ha : IsMin (f a)) : IsMax a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMax_iff.1 h
(hf hb).not_isMin ha
theorem StrictAnti.isMin_of_apply (hf : StrictAnti f) (ha : IsMax (f a)) : IsMin a :=
of_not_not fun h ↦
let ⟨_, hb⟩ := not_isMin_iff.1 h
(hf hb).not_isMax ha
lemma StrictMono.add_le_nat {f : ℕ → ℕ} (hf : StrictMono f) (m n : ℕ) : m + f n ≤ f (m + n) := by
rw [Nat.add_comm m, Nat.add_comm m]
induction' m with m ih
· rw [Nat.add_zero, Nat.add_zero]
· rw [← Nat.add_assoc, ← Nat.add_assoc, Nat.succ_le]
exact ih.trans_lt (hf (n + m).lt_succ_self)
protected theorem StrictMono.ite' (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop}
[DecidablePred p]
(hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) :
StrictMono fun x ↦ if p x then f x else g x := by
intro x y h
by_cases hy : p y
· have hx : p x := hp h hy
simpa [hx, hy] using hf h
by_cases hx : p x
· simpa [hx, hy] using hfg hx hy h
· simpa [hx, hy] using hg h
protected theorem StrictMono.ite (hf : StrictMono f) (hg : StrictMono g) {p : α → Prop}
[DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) :
StrictMono fun x ↦ if p x then f x else g x :=
(hf.ite' hg hp) fun _ y _ _ h ↦ (hf h).trans_le (hfg y)
-- Porting note: `Strict*.dual_right` dot notation is not working here for some reason
protected theorem StrictAnti.ite' (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop}
[DecidablePred p]
(hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) :
StrictAnti fun x ↦ if p x then f x else g x :=
StrictMono.ite' (StrictAnti.dual_right hf) (StrictAnti.dual_right hg) hp hfg
protected theorem StrictAnti.ite (hf : StrictAnti f) (hg : StrictAnti g) {p : α → Prop}
[DecidablePred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) :
StrictAnti fun x ↦ if p x then f x else g x :=
(hf.ite' hg hp) fun _ y _ _ h ↦ (hfg y).trans_lt (hf h)
end Preorder
/-! ### Monotonicity under composition -/
section Composition
variable [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} {s : Set α}
protected theorem Monotone.comp (hg : Monotone g) (hf : Monotone f) : Monotone (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
theorem Monotone.comp_antitone (hg : Monotone g) (hf : Antitone f) : Antitone (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
protected theorem Antitone.comp (hg : Antitone g) (hf : Antitone f) : Monotone (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
theorem Antitone.comp_monotone (hg : Antitone g) (hf : Monotone f) : Antitone (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
protected theorem Monotone.iterate {f : α → α} (hf : Monotone f) (n : ℕ) : Monotone f^[n] :=
Nat.recOn n monotone_id fun _ h ↦ h.comp hf
protected theorem Monotone.comp_monotoneOn (hg : Monotone g) (hf : MonotoneOn f s) :
MonotoneOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
theorem Monotone.comp_antitoneOn (hg : Monotone g) (hf : AntitoneOn f s) : AntitoneOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
protected theorem Antitone.comp_antitoneOn (hg : Antitone g) (hf : AntitoneOn f s) :
MonotoneOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
theorem Antitone.comp_monotoneOn (hg : Antitone g) (hf : MonotoneOn f s) : AntitoneOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
protected theorem StrictMono.comp (hg : StrictMono g) (hf : StrictMono f) : StrictMono (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
theorem StrictMono.comp_strictAnti (hg : StrictMono g) (hf : StrictAnti f) : StrictAnti (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
protected theorem StrictAnti.comp (hg : StrictAnti g) (hf : StrictAnti f) : StrictMono (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
theorem StrictAnti.comp_strictMono (hg : StrictAnti g) (hf : StrictMono f) : StrictAnti (g ∘ f) :=
fun _ _ h ↦ hg (hf h)
protected theorem StrictMono.iterate {f : α → α} (hf : StrictMono f) (n : ℕ) : StrictMono f^[n] :=
Nat.recOn n strictMono_id fun _ h ↦ h.comp hf
protected theorem StrictMono.comp_strictMonoOn (hg : StrictMono g) (hf : StrictMonoOn f s) :
StrictMonoOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
theorem StrictMono.comp_strictAntiOn (hg : StrictMono g) (hf : StrictAntiOn f s) :
StrictAntiOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
protected theorem StrictAnti.comp_strictAntiOn (hg : StrictAnti g) (hf : StrictAntiOn f s) :
StrictMonoOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
theorem StrictAnti.comp_strictMonoOn (hg : StrictAnti g) (hf : StrictMonoOn f s) :
StrictAntiOn (g ∘ f) s :=
fun _ ha _ hb h ↦ hg (hf ha hb h)
end Composition
namespace List
section Fold
theorem foldl_monotone [Preorder α] {f : α → β → α} (H : ∀ b, Monotone fun a ↦ f a b)
(l : List β) : Monotone fun a ↦ l.foldl f a :=
List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h)
theorem foldr_monotone [Preorder β] {f : α → β → β} (H : ∀ a, Monotone (f a)) (l : List α) :
Monotone fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl
theorem foldl_strictMono [Preorder α] {f : α → β → α} (H : ∀ b, StrictMono fun a ↦ f a b)
(l : List β) : StrictMono fun a ↦ l.foldl f a :=
List.recOn l (fun _ _ ↦ id) fun _ _ hl _ _ h ↦ hl (H _ h)
theorem foldr_strictMono [Preorder β] {f : α → β → β} (H : ∀ a, StrictMono (f a)) (l : List α) :
StrictMono fun b ↦ l.foldr f b := fun _ _ h ↦ List.recOn l h fun i _ hl ↦ H i hl
end Fold
end List
/-! ### Monotonicity in linear orders -/
section LinearOrder
variable [LinearOrder α]
section Preorder
variable [Preorder β] {f : α → β} {s : Set α}
open Ordering
theorem Monotone.reflect_lt (hf : Monotone f) {a b : α} (h : f a < f b) : a < b :=
lt_of_not_ge fun h' ↦ h.not_le (hf h')
theorem Antitone.reflect_lt (hf : Antitone f) {a b : α} (h : f a < f b) : b < a :=
lt_of_not_ge fun h' ↦ h.not_le (hf h')
theorem MonotoneOn.reflect_lt (hf : MonotoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s)
(h : f a < f b) : a < b :=
lt_of_not_ge fun h' ↦ h.not_le <| hf hb ha h'
theorem AntitoneOn.reflect_lt (hf : AntitoneOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s)
(h : f a < f b) : b < a :=
lt_of_not_ge fun h' ↦ h.not_le <| hf ha hb h'
theorem StrictMonoOn.le_iff_le (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ a ≤ b :=
⟨fun h ↦ le_of_not_gt fun h' ↦ (hf hb ha h').not_le h, fun h ↦
h.lt_or_eq_dec.elim (fun h' ↦ (hf ha hb h').le) fun h' ↦ h' ▸ le_rfl⟩
theorem StrictAntiOn.le_iff_le (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ b ≤ a :=
hf.dual_right.le_iff_le hb ha
theorem StrictMonoOn.eq_iff_eq (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ a = b :=
⟨fun h ↦ le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge), by
rintro rfl
rfl⟩
theorem StrictAntiOn.eq_iff_eq (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ b = a :=
(hf.dual_right.eq_iff_eq ha hb).trans eq_comm
theorem StrictMonoOn.lt_iff_lt (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ a < b := by
rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha]
theorem StrictAntiOn.lt_iff_lt (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ b < a :=
hf.dual_right.lt_iff_lt hb ha
theorem StrictMono.le_iff_le (hf : StrictMono f) {a b : α} : f a ≤ f b ↔ a ≤ b :=
(hf.strictMonoOn Set.univ).le_iff_le trivial trivial
theorem StrictAnti.le_iff_le (hf : StrictAnti f) {a b : α} : f a ≤ f b ↔ b ≤ a :=
(hf.strictAntiOn Set.univ).le_iff_le trivial trivial
theorem StrictMono.lt_iff_lt (hf : StrictMono f) {a b : α} : f a < f b ↔ a < b :=
(hf.strictMonoOn Set.univ).lt_iff_lt trivial trivial
theorem StrictAnti.lt_iff_lt (hf : StrictAnti f) {a b : α} : f a < f b ↔ b < a :=
(hf.strictAntiOn Set.univ).lt_iff_lt trivial trivial
protected theorem StrictMonoOn.compares (hf : StrictMonoOn f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) : ∀ {o : Ordering}, o.Compares (f a) (f b) ↔ o.Compares a b
| Ordering.lt => hf.lt_iff_lt ha hb
| Ordering.eq => ⟨fun h ↦ ((hf.le_iff_le ha hb).1 h.le).antisymm
((hf.le_iff_le hb ha).1 h.symm.le), congr_arg _⟩
| Ordering.gt => hf.lt_iff_lt hb ha
protected theorem StrictAntiOn.compares (hf : StrictAntiOn f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) {o : Ordering} : o.Compares (f a) (f b) ↔ o.Compares b a :=
toDual_compares_toDual.trans <| hf.dual_right.compares hb ha
protected theorem StrictMono.compares (hf : StrictMono f) {a b : α} {o : Ordering} :
o.Compares (f a) (f b) ↔ o.Compares a b :=
(hf.strictMonoOn Set.univ).compares trivial trivial
protected theorem StrictAnti.compares (hf : StrictAnti f) {a b : α} {o : Ordering} :
o.Compares (f a) (f b) ↔ o.Compares b a :=
(hf.strictAntiOn Set.univ).compares trivial trivial
theorem StrictMono.injective (hf : StrictMono f) : Injective f :=
fun x y h ↦ show Compares eq x y from hf.compares.1 h
theorem StrictAnti.injective (hf : StrictAnti f) : Injective f :=
fun x y h ↦ show Compares eq x y from hf.compares.1 h.symm
theorem StrictMono.maximal_of_maximal_image (hf : StrictMono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmax (f x))
theorem StrictMono.minimal_of_minimal_image (hf : StrictMono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmin (f x))
theorem StrictAnti.minimal_of_maximal_image (hf : StrictAnti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmax (f x))
theorem StrictAnti.maximal_of_minimal_image (hf : StrictAnti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmin (f x))
end Preorder
section PartialOrder
variable [PartialOrder β] {f : α → β}
theorem Monotone.strictMono_iff_injective (hf : Monotone f) : StrictMono f ↔ Injective f :=
⟨fun h ↦ h.injective, hf.strictMono_of_injective⟩
theorem Antitone.strictAnti_iff_injective (hf : Antitone f) : StrictAnti f ↔ Injective f :=
⟨fun h ↦ h.injective, hf.strictAnti_of_injective⟩
/-- If a monotone function is equal at two points, it is equal between all of them -/
theorem Monotone.eq_of_le_of_le {a₁ a₂ : α} (h_mon : Monotone f) (h_fa : f a₁ = f a₂) {i : α}
(h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by
apply le_antisymm
· rw [h_fa]; exact h_mon h₂
· exact h_mon h₁
/-- If an antitone function is equal at two points, it is equal between all of them -/
theorem Antitone.eq_of_le_of_le {a₁ a₂ : α} (h_anti : Antitone f) (h_fa : f a₁ = f a₂) {i : α}
(h₁ : a₁ ≤ i) (h₂ : i ≤ a₂) : f i = f a₁ := by
apply le_antisymm
· exact h_anti h₁
· rw [h_fa]; exact h_anti h₂
end PartialOrder
variable [LinearOrder β] {f : α → β} {s : Set α} {x y : α}
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_le_le :
¬ Monotone f ∧ ¬ Antitone f ↔
∃ a b c, a ≤ b ∧ b ≤ c ∧ ((f a < f b ∧ f c < f b) ∨ (f b < f a ∧ f b < f c)) := by
simp_rw [Monotone, Antitone, not_forall, not_le]
refine Iff.symm ⟨?_, ?_⟩
· rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩
exacts [⟨⟨_, _, hbc, hfcb⟩, _, _, hab, hfab⟩, ⟨⟨_, _, hab, hfba⟩, _, _, hbc, hfbc⟩]
rintro ⟨⟨a, b, hab, hfba⟩, c, d, hcd, hfcd⟩
obtain hda | had := le_total d a
· obtain hfad | hfda := le_total (f a) (f d)
· exact ⟨c, d, b, hcd, hda.trans hab, Or.inl ⟨hfcd, hfba.trans_le hfad⟩⟩
· exact ⟨c, a, b, hcd.trans hda, hab, Or.inl ⟨hfcd.trans_le hfda, hfba⟩⟩
obtain hac | hca := le_total a c
· obtain hfdb | hfbd := le_or_lt (f d) (f b)
· exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfcd.trans <| hfdb.trans_lt hfba, hfcd⟩⟩
obtain hfca | hfac := lt_or_le (f c) (f a)
· exact ⟨a, c, d, hac, hcd, Or.inr ⟨hfca, hfcd⟩⟩
obtain hbd | hdb := le_total b d
· exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩
· exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩
· obtain hfdb | hfbd := le_or_lt (f d) (f b)
· exact ⟨c, a, b, hca, hab, Or.inl ⟨hfcd.trans <| hfdb.trans_lt hfba, hfba⟩⟩
obtain hfca | hfac := lt_or_le (f c) (f a)
· exact ⟨c, a, b, hca, hab, Or.inl ⟨hfca, hfba⟩⟩
obtain hbd | hdb := le_total b d
· exact ⟨a, b, d, hab, hbd, Or.inr ⟨hfba, hfbd⟩⟩
· exact ⟨a, d, b, had, hdb, Or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_lt_lt :
¬ Monotone f ∧ ¬ Antitone f ↔ ∃ a b c, a < b ∧ b < c ∧
(f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) := by
simp_rw [not_monotone_not_antitone_iff_exists_le_le, ← and_assoc]
refine exists₃_congr (fun a b c ↦ and_congr_left <|
fun h ↦ (Ne.le_iff_lt ?_).and <| Ne.le_iff_lt ?_) <;>
(rintro rfl; simp at h)
/-!
### Strictly monotone functions and `cmp`
-/
theorem StrictMonoOn.cmp_map_eq (hf : StrictMonoOn f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp x y :=
((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq
theorem StrictMono.cmp_map_eq (hf : StrictMono f) (x y : α) : cmp (f x) (f y) = cmp x y :=
(hf.strictMonoOn Set.univ).cmp_map_eq trivial trivial
theorem StrictAntiOn.cmp_map_eq (hf : StrictAntiOn f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp y x :=
hf.dual_right.cmp_map_eq hy hx
theorem StrictAnti.cmp_map_eq (hf : StrictAnti f) (x y : α) : cmp (f x) (f y) = cmp y x :=
(hf.strictAntiOn Set.univ).cmp_map_eq trivial trivial
end LinearOrder
/-! ### Monotonicity in `ℕ` and `ℤ` -/
section Preorder
variable [Preorder α]
theorem Nat.rel_of_forall_rel_succ_of_le_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β} {a : ℕ}
(h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b < c) :
r (f b) (f c) := by
induction' hbc with k b_lt_k r_b_k
exacts [h _ hab, _root_.trans r_b_k (h _ (hab.trans_lt b_lt_k).le)]
theorem Nat.rel_of_forall_rel_succ_of_le_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r]
{f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1)))
⦃b c : ℕ⦄ (hab : a ≤ b) (hbc : b ≤ c) : r (f b) (f c) :=
hbc.eq_or_lt.elim (fun h ↦ h ▸ refl _) (Nat.rel_of_forall_rel_succ_of_le_of_lt r h hab)
theorem Nat.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℕ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a < b) : r (f a) (f b) :=
Nat.rel_of_forall_rel_succ_of_le_of_lt r (fun n _ ↦ h n) le_rfl hab
theorem Nat.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℕ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a ≤ b) : r (f a) (f b) :=
Nat.rel_of_forall_rel_succ_of_le_of_le r (fun n _ ↦ h n) le_rfl hab
theorem monotone_nat_of_le_succ {f : ℕ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f :=
Nat.rel_of_forall_rel_succ_of_le (· ≤ ·) hf
theorem antitone_nat_of_succ_le {f : ℕ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f :=
@monotone_nat_of_le_succ αᵒᵈ _ _ hf
theorem strictMono_nat_of_lt_succ {f : ℕ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f :=
Nat.rel_of_forall_rel_succ_of_lt (· < ·) hf
theorem strictAnti_nat_of_succ_lt {f : ℕ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f :=
@strictMono_nat_of_lt_succ αᵒᵈ _ f hf
namespace Nat
/-- If `α` is a preorder with no maximal elements, then there exists a strictly monotone function
`ℕ → α` with any prescribed value of `f 0`. -/
theorem exists_strictMono' [NoMaxOrder α] (a : α) : ∃ f : ℕ → α, StrictMono f ∧ f 0 = a := by
choose g hg using fun x : α ↦ exists_gt x
exact ⟨fun n ↦ Nat.recOn n a fun _ ↦ g, strictMono_nat_of_lt_succ fun n ↦ hg _, rfl⟩
/-- If `α` is a preorder with no maximal elements, then there exists a strictly antitone function
`ℕ → α` with any prescribed value of `f 0`. -/
theorem exists_strictAnti' [NoMinOrder α] (a : α) : ∃ f : ℕ → α, StrictAnti f ∧ f 0 = a :=
exists_strictMono' (OrderDual.toDual a)
variable (α)
/-- If `α` is a nonempty preorder with no maximal elements, then there exists a strictly monotone
function `ℕ → α`. -/
theorem exists_strictMono [Nonempty α] [NoMaxOrder α] : ∃ f : ℕ → α, StrictMono f :=
let ⟨a⟩ := ‹Nonempty α›
let ⟨f, hf, _⟩ := exists_strictMono' a
⟨f, hf⟩
/-- If `α` is a nonempty preorder with no minimal elements, then there exists a strictly antitone
function `ℕ → α`. -/
theorem exists_strictAnti [Nonempty α] [NoMinOrder α] : ∃ f : ℕ → α, StrictAnti f :=
exists_strictMono αᵒᵈ
end Nat
theorem Int.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [IsTrans β r] {f : ℤ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a < b) : r (f a) (f b) := by
rcases lt.dest hab with ⟨n, rfl⟩
clear hab
induction' n with n ihn
· rw [Int.ofNat_one]
apply h
· rw [Int.ofNat_succ, ← Int.add_assoc]
exact _root_.trans ihn (h _)
theorem Int.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [IsRefl β r] [IsTrans β r] {f : ℤ → β}
(h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a ≤ b) : r (f a) (f b) :=
hab.eq_or_lt.elim (fun h ↦ h ▸ refl _) fun h' ↦ Int.rel_of_forall_rel_succ_of_lt r h h'
theorem monotone_int_of_le_succ {f : ℤ → α} (hf : ∀ n, f n ≤ f (n + 1)) : Monotone f :=
Int.rel_of_forall_rel_succ_of_le (· ≤ ·) hf
theorem antitone_int_of_succ_le {f : ℤ → α} (hf : ∀ n, f (n + 1) ≤ f n) : Antitone f :=
Int.rel_of_forall_rel_succ_of_le (· ≥ ·) hf
theorem strictMono_int_of_lt_succ {f : ℤ → α} (hf : ∀ n, f n < f (n + 1)) : StrictMono f :=
Int.rel_of_forall_rel_succ_of_lt (· < ·) hf
theorem strictAnti_int_of_succ_lt {f : ℤ → α} (hf : ∀ n, f (n + 1) < f n) : StrictAnti f :=
Int.rel_of_forall_rel_succ_of_lt (· > ·) hf
namespace Int
variable (α)
variable [Nonempty α] [NoMinOrder α] [NoMaxOrder α]
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
monotone function `f : ℤ → α`. -/
theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by
inhabit α
rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩
rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩
refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩
rintro (n | _ | n)
· exact hf n.lt_succ_self
· show g 1 < f 0
rw [hf₀, ← hg₀]
exact hg Nat.zero_lt_one
· exact hg (Nat.lt_succ_self _)
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
antitone function `f : ℤ → α`. -/
theorem exists_strictAnti : ∃ f : ℤ → α, StrictAnti f :=
exists_strictMono αᵒᵈ
end Int
-- TODO@Yael: Generalize the following four to succ orders
/-- If `f` is a monotone function from `ℕ` to a preorder such that `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
theorem Monotone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Monotone f) (n : ℕ) {x : α} (h1 : f n < x)
(h2 : x < f (n + 1)) (a : ℕ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h1).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h2)
/-- If `f` is an antitone function from `ℕ` to a preorder such that `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
theorem Antitone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : Antitone f) (n : ℕ) {x : α}
(h1 : f (n + 1) < x) (h2 : x < f n) (a : ℕ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h2).not_le (Nat.le_of_lt_succ <| hf.reflect_lt h1)
/-- If `f` is a monotone function from `ℤ` to a preorder and `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
theorem Monotone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Monotone f) (n : ℤ) {x : α} (h1 : f n < x)
(h2 : x < f (n + 1)) (a : ℤ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h1).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h2)
/-- If `f` is an antitone function from `ℤ` to a preorder and `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
theorem Antitone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : Antitone f) (n : ℤ) {x : α}
(h1 : f (n + 1) < x) (h2 : x < f n) (a : ℤ) : f a ≠ x := by
rintro rfl
exact (hf.reflect_lt h2).not_le (Int.le_of_lt_add_one <| hf.reflect_lt h1)
theorem StrictMono.id_le {φ : ℕ → ℕ} (h : StrictMono φ) : ∀ n, n ≤ φ n := fun n ↦
Nat.recOn n (Nat.zero_le _) fun n hn ↦ Nat.succ_le_of_lt (hn.trans_lt <| h <| Nat.lt_succ_self n)
end Preorder
theorem Subtype.mono_coe [Preorder α] (t : Set α) : Monotone ((↑) : Subtype t → α) :=
fun _ _ ↦ id
theorem Subtype.strictMono_coe [Preorder α] (t : Set α) :
StrictMono ((↑) : Subtype t → α) :=
fun _ _ ↦ id
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] [Preorder δ] {f : α → γ} {g : β → δ} {a b : α}
theorem monotone_fst : Monotone (@Prod.fst α β) := fun _ _ ↦ And.left
theorem monotone_snd : Monotone (@Prod.snd α β) := fun _ _ ↦ And.right
theorem Monotone.prod_map (hf : Monotone f) (hg : Monotone g) : Monotone (Prod.map f g) :=
fun _ _ h ↦ ⟨hf h.1, hg h.2⟩
theorem Antitone.prod_map (hf : Antitone f) (hg : Antitone g) : Antitone (Prod.map f g) :=
fun _ _ h ↦ ⟨hf h.1, hg h.2⟩
end Preorder
section PartialOrder
variable [PartialOrder α] [PartialOrder β] [Preorder γ] [Preorder δ] {f : α → γ} {g : β → δ}
theorem StrictMono.prod_map (hf : StrictMono f) (hg : StrictMono g) : StrictMono (Prod.map f g) :=
fun a b ↦ by
simp only [Prod.lt_iff]
exact Or.imp (And.imp hf.imp hg.monotone.imp) (And.imp hf.monotone.imp hg.imp)
theorem StrictAnti.prod_map (hf : StrictAnti f) (hg : StrictAnti g) : StrictAnti (Prod.map f g) :=
fun a b ↦ by
simp only [Prod.lt_iff]
exact Or.imp (And.imp hf.imp hg.antitone.imp) (And.imp hf.antitone.imp hg.imp)
end PartialOrder
/-! ### Pi types -/
namespace Function
variable [Preorder α] [DecidableEq ι] [∀ i, Preorder (π i)] {f : ∀ i, π i} {i : ι}
-- Porting note: Dot notation breaks in `f.update i`
theorem update_mono : Monotone (update f i) := fun _ _ => update_le_update_iff'.2
theorem update_strictMono : StrictMono (update f i) := fun _ _ => update_lt_update_iff.2
theorem const_mono : Monotone (const β : α → β → α) := fun _ _ h _ ↦ h
theorem const_strictMono [Nonempty β] : StrictMono (const β : α → β → α) :=
fun _ _ ↦ const_lt_const.2
end Function
section apply
variable {ι α : Type*} {β : ι → Type*} [∀ i, Preorder (β i)] [Preorder α] {f : α → ∀ i, β i}
lemma monotone_iff_apply₂ : Monotone f ↔ ∀ i, Monotone (f · i) := by
simp [Monotone, Pi.le_def, @forall_swap ι]
lemma antitone_iff_apply₂ : Antitone f ↔ ∀ i, Antitone (f · i) := by
simp [Antitone, Pi.le_def, @forall_swap ι]
alias ⟨Monotone.apply₂, Monotone.of_apply₂⟩ := monotone_iff_apply₂
alias ⟨Antitone.apply₂, Antitone.of_apply₂⟩ := antitone_iff_apply₂
end apply
|
Order\Monotone\Extension.lean | /-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Extension of a monotone function from a set to the whole space
In this file we prove that if a function is monotone and is bounded on a set `s`, then it admits a
monotone extension to the whole space.
-/
open Set
variable {α β : Type*} [LinearOrder α] [ConditionallyCompleteLinearOrder β] {f : α → β} {s : Set α}
{a b : α}
/-- If a function is monotone and is bounded on a set `s`, then it admits a monotone extension to
the whole space. -/
theorem MonotoneOn.exists_monotone_extension (h : MonotoneOn f s) (hl : BddBelow (f '' s))
(hu : BddAbove (f '' s)) : ∃ g : α → β, Monotone g ∧ EqOn f g s := by
classical
/- The extension is defined by `f x = f a` for `x ≤ a`, and `f x` is the supremum of the values
of `f` to the left of `x` for `x ≥ a`. -/
rcases hl with ⟨a, ha⟩
have hu' : ∀ x, BddAbove (f '' (Iic x ∩ s)) := fun x =>
hu.mono (image_subset _ inter_subset_right)
let g : α → β := fun x => if Disjoint (Iic x) s then a else sSup (f '' (Iic x ∩ s))
have hgs : EqOn f g s := by
intro x hx
simp only [g]
have : IsGreatest (Iic x ∩ s) x := ⟨⟨right_mem_Iic, hx⟩, fun y hy => hy.1⟩
rw [if_neg this.nonempty.not_disjoint,
((h.mono inter_subset_right).map_isGreatest this).csSup_eq]
refine ⟨g, fun x y hxy => ?_, hgs⟩
by_cases hx : Disjoint (Iic x) s <;> by_cases hy : Disjoint (Iic y) s <;>
simp only [g, if_pos, if_neg, not_false_iff, *, refl]
· rcases not_disjoint_iff_nonempty_inter.1 hy with ⟨z, hz⟩
exact le_csSup_of_le (hu' _) (mem_image_of_mem _ hz) (ha <| mem_image_of_mem _ hz.2)
· exact (hx <| hy.mono_left <| Iic_subset_Iic.2 hxy).elim
· rw [not_disjoint_iff_nonempty_inter] at hx hy
refine csSup_le_csSup (hu' _) (hx.image _) (image_subset _ ?_)
exact inter_subset_inter_left _ (Iic_subset_Iic.2 hxy)
/-- If a function is antitone and is bounded on a set `s`, then it admits an antitone extension to
the whole space. -/
theorem AntitoneOn.exists_antitone_extension (h : AntitoneOn f s) (hl : BddBelow (f '' s))
(hu : BddAbove (f '' s)) : ∃ g : α → β, Antitone g ∧ EqOn f g s :=
h.dual_right.exists_monotone_extension hu hl
|
Order\Monotone\Monovary.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Defs
import Mathlib.Order.Lattice
/-!
# Monovariance of functions
Two functions *vary together* if a strict change in the first implies a change in the second.
This is in some sense a way to say that two functions `f : ι → α`, `g : ι → β` are "monotone
together", without actually having an order on `ι`.
This condition comes up in the rearrangement inequality. See `Algebra.Order.Rearrangement`.
## Main declarations
* `Monovary f g`: `f` monovaries with `g`. If `g i < g j`, then `f i ≤ f j`.
* `Antivary f g`: `f` antivaries with `g`. If `g i < g j`, then `f j ≤ f i`.
* `MonovaryOn f g s`: `f` monovaries with `g` on `s`.
* `AntivaryOn f g s`: `f` antivaries with `g` on `s`.
-/
open Function Set
variable {ι ι' α β γ : Type*}
section Preorder
variable [Preorder α] [Preorder β] [Preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {g' : β → γ}
{s t : Set ι}
/-- `f` monovaries with `g` if `g i < g j` implies `f i ≤ f j`. -/
def Monovary (f : ι → α) (g : ι → β) : Prop :=
∀ ⦃i j⦄, g i < g j → f i ≤ f j
/-- `f` antivaries with `g` if `g i < g j` implies `f j ≤ f i`. -/
def Antivary (f : ι → α) (g : ι → β) : Prop :=
∀ ⦃i j⦄, g i < g j → f j ≤ f i
/-- `f` monovaries with `g` on `s` if `g i < g j` implies `f i ≤ f j` for all `i, j ∈ s`. -/
def MonovaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop :=
∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f i ≤ f j
/-- `f` antivaries with `g` on `s` if `g i < g j` implies `f j ≤ f i` for all `i, j ∈ s`. -/
def AntivaryOn (f : ι → α) (g : ι → β) (s : Set ι) : Prop :=
∀ ⦃i⦄ (_ : i ∈ s) ⦃j⦄ (_ : j ∈ s), g i < g j → f j ≤ f i
protected theorem Monovary.monovaryOn (h : Monovary f g) (s : Set ι) : MonovaryOn f g s :=
fun _ _ _ _ hij => h hij
protected theorem Antivary.antivaryOn (h : Antivary f g) (s : Set ι) : AntivaryOn f g s :=
fun _ _ _ _ hij => h hij
@[simp]
theorem MonovaryOn.empty : MonovaryOn f g ∅ := fun _ => False.elim
@[simp]
theorem AntivaryOn.empty : AntivaryOn f g ∅ := fun _ => False.elim
@[simp]
theorem monovaryOn_univ : MonovaryOn f g univ ↔ Monovary f g :=
⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩
@[simp]
theorem antivaryOn_univ : AntivaryOn f g univ ↔ Antivary f g :=
⟨fun h _ _ => h trivial trivial, fun h _ _ _ _ hij => h hij⟩
protected theorem MonovaryOn.subset (hst : s ⊆ t) (h : MonovaryOn f g t) : MonovaryOn f g s :=
fun _ hi _ hj => h (hst hi) (hst hj)
protected theorem AntivaryOn.subset (hst : s ⊆ t) (h : AntivaryOn f g t) : AntivaryOn f g s :=
fun _ hi _ hj => h (hst hi) (hst hj)
theorem monovary_const_left (g : ι → β) (a : α) : Monovary (const ι a) g := fun _ _ _ => le_rfl
theorem antivary_const_left (g : ι → β) (a : α) : Antivary (const ι a) g := fun _ _ _ => le_rfl
theorem monovary_const_right (f : ι → α) (b : β) : Monovary f (const ι b) := fun _ _ h =>
(h.ne rfl).elim
theorem antivary_const_right (f : ι → α) (b : β) : Antivary f (const ι b) := fun _ _ h =>
(h.ne rfl).elim
theorem monovary_self (f : ι → α) : Monovary f f := fun _ _ => le_of_lt
theorem monovaryOn_self (f : ι → α) (s : Set ι) : MonovaryOn f f s := fun _ _ _ _ => le_of_lt
protected theorem Subsingleton.monovary [Subsingleton ι] (f : ι → α) (g : ι → β) : Monovary f g :=
fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim
protected theorem Subsingleton.antivary [Subsingleton ι] (f : ι → α) (g : ι → β) : Antivary f g :=
fun _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim
protected theorem Subsingleton.monovaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) :
MonovaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim
protected theorem Subsingleton.antivaryOn [Subsingleton ι] (f : ι → α) (g : ι → β) (s : Set ι) :
AntivaryOn f g s := fun _ _ _ _ h => (ne_of_apply_ne _ h.ne <| Subsingleton.elim _ _).elim
theorem monovaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : MonovaryOn (const ι a) g s :=
fun _ _ _ _ _ => le_rfl
theorem antivaryOn_const_left (g : ι → β) (a : α) (s : Set ι) : AntivaryOn (const ι a) g s :=
fun _ _ _ _ _ => le_rfl
theorem monovaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : MonovaryOn f (const ι b) s :=
fun _ _ _ _ h => (h.ne rfl).elim
theorem antivaryOn_const_right (f : ι → α) (b : β) (s : Set ι) : AntivaryOn f (const ι b) s :=
fun _ _ _ _ h => (h.ne rfl).elim
theorem Monovary.comp_right (h : Monovary f g) (k : ι' → ι) : Monovary (f ∘ k) (g ∘ k) :=
fun _ _ hij => h hij
theorem Antivary.comp_right (h : Antivary f g) (k : ι' → ι) : Antivary (f ∘ k) (g ∘ k) :=
fun _ _ hij => h hij
theorem MonovaryOn.comp_right (h : MonovaryOn f g s) (k : ι' → ι) :
MonovaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj
theorem AntivaryOn.comp_right (h : AntivaryOn f g s) (k : ι' → ι) :
AntivaryOn (f ∘ k) (g ∘ k) (k ⁻¹' s) := fun _ hi _ hj => h hi hj
theorem Monovary.comp_monotone_left (h : Monovary f g) (hf : Monotone f') : Monovary (f' ∘ f) g :=
fun _ _ hij => hf <| h hij
theorem Monovary.comp_antitone_left (h : Monovary f g) (hf : Antitone f') : Antivary (f' ∘ f) g :=
fun _ _ hij => hf <| h hij
theorem Antivary.comp_monotone_left (h : Antivary f g) (hf : Monotone f') : Antivary (f' ∘ f) g :=
fun _ _ hij => hf <| h hij
theorem Antivary.comp_antitone_left (h : Antivary f g) (hf : Antitone f') : Monovary (f' ∘ f) g :=
fun _ _ hij => hf <| h hij
theorem MonovaryOn.comp_monotone_on_left (h : MonovaryOn f g s) (hf : Monotone f') :
MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij
theorem MonovaryOn.comp_antitone_on_left (h : MonovaryOn f g s) (hf : Antitone f') :
AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij
theorem AntivaryOn.comp_monotone_on_left (h : AntivaryOn f g s) (hf : Monotone f') :
AntivaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij
theorem AntivaryOn.comp_antitone_on_left (h : AntivaryOn f g s) (hf : Antitone f') :
MonovaryOn (f' ∘ f) g s := fun _ hi _ hj hij => hf <| h hi hj hij
section OrderDual
open OrderDual
theorem Monovary.dual : Monovary f g → Monovary (toDual ∘ f) (toDual ∘ g) :=
swap
theorem Antivary.dual : Antivary f g → Antivary (toDual ∘ f) (toDual ∘ g) :=
swap
theorem Monovary.dual_left : Monovary f g → Antivary (toDual ∘ f) g :=
id
theorem Antivary.dual_left : Antivary f g → Monovary (toDual ∘ f) g :=
id
theorem Monovary.dual_right : Monovary f g → Antivary f (toDual ∘ g) :=
swap
theorem Antivary.dual_right : Antivary f g → Monovary f (toDual ∘ g) :=
swap
theorem MonovaryOn.dual : MonovaryOn f g s → MonovaryOn (toDual ∘ f) (toDual ∘ g) s :=
swap₂
theorem AntivaryOn.dual : AntivaryOn f g s → AntivaryOn (toDual ∘ f) (toDual ∘ g) s :=
swap₂
theorem MonovaryOn.dual_left : MonovaryOn f g s → AntivaryOn (toDual ∘ f) g s :=
id
theorem AntivaryOn.dual_left : AntivaryOn f g s → MonovaryOn (toDual ∘ f) g s :=
id
theorem MonovaryOn.dual_right : MonovaryOn f g s → AntivaryOn f (toDual ∘ g) s :=
swap₂
theorem AntivaryOn.dual_right : AntivaryOn f g s → MonovaryOn f (toDual ∘ g) s :=
swap₂
@[simp]
theorem monovary_toDual_left : Monovary (toDual ∘ f) g ↔ Antivary f g :=
Iff.rfl
@[simp]
theorem monovary_toDual_right : Monovary f (toDual ∘ g) ↔ Antivary f g :=
forall_swap
@[simp]
theorem antivary_toDual_left : Antivary (toDual ∘ f) g ↔ Monovary f g :=
Iff.rfl
@[simp]
theorem antivary_toDual_right : Antivary f (toDual ∘ g) ↔ Monovary f g :=
forall_swap
@[simp]
theorem monovaryOn_toDual_left : MonovaryOn (toDual ∘ f) g s ↔ AntivaryOn f g s :=
Iff.rfl
@[simp]
theorem monovaryOn_toDual_right : MonovaryOn f (toDual ∘ g) s ↔ AntivaryOn f g s :=
forall₂_swap
@[simp]
theorem antivaryOn_toDual_left : AntivaryOn (toDual ∘ f) g s ↔ MonovaryOn f g s :=
Iff.rfl
@[simp]
theorem antivaryOn_toDual_right : AntivaryOn f (toDual ∘ g) s ↔ MonovaryOn f g s :=
forall₂_swap
end OrderDual
section PartialOrder
variable [PartialOrder ι]
@[simp]
theorem monovary_id_iff : Monovary f id ↔ Monotone f :=
monotone_iff_forall_lt.symm
@[simp]
theorem antivary_id_iff : Antivary f id ↔ Antitone f :=
antitone_iff_forall_lt.symm
@[simp]
theorem monovaryOn_id_iff : MonovaryOn f id s ↔ MonotoneOn f s :=
monotoneOn_iff_forall_lt.symm
@[simp]
theorem antivaryOn_id_iff : AntivaryOn f id s ↔ AntitoneOn f s :=
antitoneOn_iff_forall_lt.symm
end PartialOrder
variable [LinearOrder ι]
/- Porting note: Due to a bug in `alias`, many of the below lemmas have dot notation removed in the
proof-/
protected theorem Monotone.monovary (hf : Monotone f) (hg : Monotone g) : Monovary f g :=
fun _ _ hij => hf (hg.reflect_lt hij).le
protected theorem Monotone.antivary (hf : Monotone f) (hg : Antitone g) : Antivary f g :=
(hf.monovary hg.dual_right).dual_right
protected theorem Antitone.monovary (hf : Antitone f) (hg : Antitone g) : Monovary f g :=
(hf.dual_right.antivary hg).dual_left
protected theorem Antitone.antivary (hf : Antitone f) (hg : Monotone g) : Antivary f g :=
(hf.monovary hg.dual_right).dual_right
protected theorem MonotoneOn.monovaryOn (hf : MonotoneOn f s) (hg : MonotoneOn g s) :
MonovaryOn f g s := fun _ hi _ hj hij => hf hi hj (hg.reflect_lt hi hj hij).le
protected theorem MonotoneOn.antivaryOn (hf : MonotoneOn f s) (hg : AntitoneOn g s) :
AntivaryOn f g s :=
(hf.monovaryOn hg.dual_right).dual_right
protected theorem AntitoneOn.monovaryOn (hf : AntitoneOn f s) (hg : AntitoneOn g s) :
MonovaryOn f g s :=
(hf.dual_right.antivaryOn hg).dual_left
protected theorem AntitoneOn.antivaryOn (hf : AntitoneOn f s) (hg : MonotoneOn g s) :
AntivaryOn f g s :=
(hf.monovaryOn hg.dual_right).dual_right
end Preorder
section LinearOrder
variable [Preorder α] [LinearOrder β] [Preorder γ] {f : ι → α} {f' : α → γ} {g : ι → β} {g' : β → γ}
{s : Set ι}
theorem MonovaryOn.comp_monotoneOn_right (h : MonovaryOn f g s) (hg : MonotoneOn g' (g '' s)) :
MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij =>
h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij
theorem MonovaryOn.comp_antitoneOn_right (h : MonovaryOn f g s) (hg : AntitoneOn g' (g '' s)) :
AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij =>
h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij
theorem AntivaryOn.comp_monotoneOn_right (h : AntivaryOn f g s) (hg : MonotoneOn g' (g '' s)) :
AntivaryOn f (g' ∘ g) s := fun _ hi _ hj hij =>
h hi hj <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij
theorem AntivaryOn.comp_antitoneOn_right (h : AntivaryOn f g s) (hg : AntitoneOn g' (g '' s)) :
MonovaryOn f (g' ∘ g) s := fun _ hi _ hj hij =>
h hj hi <| hg.reflect_lt (mem_image_of_mem _ hi) (mem_image_of_mem _ hj) hij
@[symm]
protected theorem Monovary.symm (h : Monovary f g) : Monovary g f := fun _ _ hf =>
le_of_not_lt fun hg => hf.not_le <| h hg
@[symm]
protected theorem Antivary.symm (h : Antivary f g) : Antivary g f := fun _ _ hf =>
le_of_not_lt fun hg => hf.not_le <| h hg
@[symm]
protected theorem MonovaryOn.symm (h : MonovaryOn f g s) : MonovaryOn g f s := fun _ hi _ hj hf =>
le_of_not_lt fun hg => hf.not_le <| h hj hi hg
@[symm]
protected theorem AntivaryOn.symm (h : AntivaryOn f g s) : AntivaryOn g f s := fun _ hi _ hj hf =>
le_of_not_lt fun hg => hf.not_le <| h hi hj hg
end LinearOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β] {f : ι → α} {g : ι → β} {s : Set ι}
theorem monovary_comm : Monovary f g ↔ Monovary g f :=
⟨Monovary.symm, Monovary.symm⟩
theorem antivary_comm : Antivary f g ↔ Antivary g f :=
⟨Antivary.symm, Antivary.symm⟩
theorem monovaryOn_comm : MonovaryOn f g s ↔ MonovaryOn g f s :=
⟨MonovaryOn.symm, MonovaryOn.symm⟩
theorem antivaryOn_comm : AntivaryOn f g s ↔ AntivaryOn g f s :=
⟨AntivaryOn.symm, AntivaryOn.symm⟩
end LinearOrder
|
Order\Monotone\Odd.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Order.Monotone.Union
import Mathlib.Algebra.Order.Group.Instances
/-!
# Monotonicity of odd functions
An odd function on a linear ordered additive commutative group `G` is monotone on the whole group
provided that it is monotone on `Set.Ici 0`, see `monotone_of_odd_of_monotoneOn_nonneg`. We also
prove versions of this lemma for `Antitone`, `StrictMono`, and `StrictAnti`.
-/
open Set
variable {G H : Type*} [LinearOrderedAddCommGroup G] [OrderedAddCommGroup H]
/-- An odd function on a linear ordered additive commutative group is strictly monotone on the whole
group provided that it is strictly monotone on `Set.Ici 0`. -/
theorem strictMono_of_odd_strictMonoOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)
(h₂ : StrictMonoOn f (Ici 0)) : StrictMono f := by
refine StrictMonoOn.Iic_union_Ici (fun x hx y hy hxy => neg_lt_neg_iff.1 ?_) h₂
rw [← h₁, ← h₁]
exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_lt_neg hxy)
/-- An odd function on a linear ordered additive commutative group is strictly antitone on the whole
group provided that it is strictly antitone on `Set.Ici 0`. -/
theorem strictAnti_of_odd_strictAntiOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)
(h₂ : StrictAntiOn f (Ici 0)) : StrictAnti f :=
@strictMono_of_odd_strictMonoOn_nonneg G Hᵒᵈ _ _ _ h₁ h₂
/-- An odd function on a linear ordered additive commutative group is monotone on the whole group
provided that it is monotone on `Set.Ici 0`. -/
theorem monotone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)
(h₂ : MonotoneOn f (Ici 0)) : Monotone f := by
refine MonotoneOn.Iic_union_Ici (fun x hx y hy hxy => neg_le_neg_iff.1 ?_) h₂
rw [← h₁, ← h₁]
exact h₂ (neg_nonneg.2 hy) (neg_nonneg.2 hx) (neg_le_neg hxy)
/-- An odd function on a linear ordered additive commutative group is antitone on the whole group
provided that it is monotone on `Set.Ici 0`. -/
theorem antitone_of_odd_of_monotoneOn_nonneg {f : G → H} (h₁ : ∀ x, f (-x) = -f x)
(h₂ : AntitoneOn f (Ici 0)) : Antitone f :=
@monotone_of_odd_of_monotoneOn_nonneg G Hᵒᵈ _ _ _ h₁ h₂
|
Order\Monotone\Union.lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel
-/
import Mathlib.Order.Bounds.Basic
/-!
# Monotonicity on intervals
In this file we prove that a function is (strictly) monotone (or antitone) on a linear order `α`
provided that it is (strictly) monotone on `(-∞, a]` and on `[a, +∞)`. This is a special case
of a more general statement where one deduces monotonicity on a union from monotonicity on each
set.
-/
open Set
variable {α β : Type*} [LinearOrder α] [Preorder β] {a : α} {f : α → β}
/-- If `f` is strictly monotone both on `s` and `t`, with `s` to the left of `t` and the center
point belonging to both `s` and `t`, then `f` is strictly monotone on `s ∪ t` -/
protected theorem StrictMonoOn.union {s t : Set α} {c : α} (h₁ : StrictMonoOn f s)
(h₂ : StrictMonoOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : StrictMonoOn f (s ∪ t) := by
have A : ∀ x, x ∈ s ∪ t → x ≤ c → x ∈ s := by
intro x hx hxc
cases hx
· assumption
rcases eq_or_lt_of_le hxc with (rfl | h'x)
· exact hs.1
exact (lt_irrefl _ (h'x.trans_le (ht.2 (by assumption)))).elim
have B : ∀ x, x ∈ s ∪ t → c ≤ x → x ∈ t := by
intro x hx hxc
match hx with
| Or.inr hx => exact hx
| Or.inl hx =>
rcases eq_or_lt_of_le hxc with (rfl | h'x)
· exact ht.1
exact (lt_irrefl _ (h'x.trans_le (hs.2 hx))).elim
intro x hx y hy hxy
rcases lt_or_le x c with (hxc | hcx)
· have xs : x ∈ s := A _ hx hxc.le
rcases lt_or_le y c with (hyc | hcy)
· exact h₁ xs (A _ hy hyc.le) hxy
· exact (h₁ xs hs.1 hxc).trans_le (h₂.monotoneOn ht.1 (B _ hy hcy) hcy)
· have xt : x ∈ t := B _ hx hcx
have yt : y ∈ t := B _ hy (hcx.trans hxy.le)
exact h₂ xt yt hxy
/-- If `f` is strictly monotone both on `(-∞, a]` and `[a, ∞)`, then it is strictly monotone on the
whole line. -/
protected theorem StrictMonoOn.Iic_union_Ici (h₁ : StrictMonoOn f (Iic a))
(h₂ : StrictMonoOn f (Ici a)) : StrictMono f := by
rw [← strictMonoOn_univ, ← @Iic_union_Ici _ _ a]
exact StrictMonoOn.union h₁ h₂ isGreatest_Iic isLeast_Ici
/-- If `f` is strictly antitone both on `s` and `t`, with `s` to the left of `t` and the center
point belonging to both `s` and `t`, then `f` is strictly antitone on `s ∪ t` -/
protected theorem StrictAntiOn.union {s t : Set α} {c : α} (h₁ : StrictAntiOn f s)
(h₂ : StrictAntiOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : StrictAntiOn f (s ∪ t) :=
(h₁.dual_right.union h₂.dual_right hs ht).dual_right
/-- If `f` is strictly antitone both on `(-∞, a]` and `[a, ∞)`, then it is strictly antitone on the
whole line. -/
protected theorem StrictAntiOn.Iic_union_Ici (h₁ : StrictAntiOn f (Iic a))
(h₂ : StrictAntiOn f (Ici a)) : StrictAnti f :=
(h₁.dual_right.Iic_union_Ici h₂.dual_right).dual_right
/-- If `f` is monotone both on `s` and `t`, with `s` to the left of `t` and the center
point belonging to both `s` and `t`, then `f` is monotone on `s ∪ t` -/
protected theorem MonotoneOn.union_right {s t : Set α} {c : α} (h₁ : MonotoneOn f s)
(h₂ : MonotoneOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : MonotoneOn f (s ∪ t) := by
have A : ∀ x, x ∈ s ∪ t → x ≤ c → x ∈ s := by
intro x hx hxc
cases hx
· assumption
rcases eq_or_lt_of_le hxc with (rfl | h'x)
· exact hs.1
exact (lt_irrefl _ (h'x.trans_le (ht.2 (by assumption)))).elim
have B : ∀ x, x ∈ s ∪ t → c ≤ x → x ∈ t := by
intro x hx hxc
match hx with
| Or.inr hx => exact hx
| Or.inl hx =>
rcases eq_or_lt_of_le hxc with (rfl | h'x)
· exact ht.1
exact (lt_irrefl _ (h'x.trans_le (hs.2 hx))).elim
intro x hx y hy hxy
rcases lt_or_le x c with (hxc | hcx)
· have xs : x ∈ s := A _ hx hxc.le
rcases lt_or_le y c with (hyc | hcy)
· exact h₁ xs (A _ hy hyc.le) hxy
· exact (h₁ xs hs.1 hxc.le).trans (h₂ ht.1 (B _ hy hcy) hcy)
· have xt : x ∈ t := B _ hx hcx
have yt : y ∈ t := B _ hy (hcx.trans hxy)
exact h₂ xt yt hxy
/-- If `f` is monotone both on `(-∞, a]` and `[a, ∞)`, then it is monotone on the whole line. -/
protected theorem MonotoneOn.Iic_union_Ici (h₁ : MonotoneOn f (Iic a)) (h₂ : MonotoneOn f (Ici a)) :
Monotone f := by
rw [← monotoneOn_univ, ← @Iic_union_Ici _ _ a]
exact MonotoneOn.union_right h₁ h₂ isGreatest_Iic isLeast_Ici
/-- If `f` is antitone both on `s` and `t`, with `s` to the left of `t` and the center
point belonging to both `s` and `t`, then `f` is antitone on `s ∪ t` -/
protected theorem AntitoneOn.union_right {s t : Set α} {c : α} (h₁ : AntitoneOn f s)
(h₂ : AntitoneOn f t) (hs : IsGreatest s c) (ht : IsLeast t c) : AntitoneOn f (s ∪ t) :=
(h₁.dual_right.union_right h₂.dual_right hs ht).dual_right
/-- If `f` is antitone both on `(-∞, a]` and `[a, ∞)`, then it is antitone on the whole line. -/
protected theorem AntitoneOn.Iic_union_Ici (h₁ : AntitoneOn f (Iic a)) (h₂ : AntitoneOn f (Ici a)) :
Antitone f :=
(h₁.dual_right.Iic_union_Ici h₂.dual_right).dual_right
|
Order\Partition\Equipartition.lean | /-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Data.Set.Equitable
import Mathlib.Logic.Equiv.Fin
import Mathlib.Order.Partition.Finpartition
/-!
# Finite equipartitions
This file defines finite equipartitions, the partitions whose parts all are the same size up to a
difference of `1`.
## Main declarations
* `Finpartition.IsEquipartition`: Predicate for a `Finpartition` to be an equipartition.
* `Finpartition.IsEquipartition.exists_partPreservingEquiv`: part-preserving enumeration of a finset
equipped with an equipartition. Indices of elements in the same part are congruent modulo
the number of parts.
-/
open Finset Fintype
namespace Finpartition
variable {α : Type*} [DecidableEq α] {s t : Finset α} (P : Finpartition s)
/-- An equipartition is a partition whose parts are all the same size, up to a difference of `1`. -/
def IsEquipartition : Prop :=
(P.parts : Set (Finset α)).EquitableOn card
theorem isEquipartition_iff_card_parts_eq_average :
P.IsEquipartition ↔
∀ a : Finset α,
a ∈ P.parts → a.card = s.card / P.parts.card ∨ a.card = s.card / P.parts.card + 1 := by
simp_rw [IsEquipartition, Finset.equitableOn_iff, P.sum_card_parts]
variable {P}
lemma not_isEquipartition :
¬P.IsEquipartition ↔ ∃ a ∈ P.parts, ∃ b ∈ P.parts, b.card + 1 < a.card :=
Set.not_equitableOn
theorem _root_.Set.Subsingleton.isEquipartition (h : (P.parts : Set (Finset α)).Subsingleton) :
P.IsEquipartition :=
Set.Subsingleton.equitableOn h _
theorem IsEquipartition.card_parts_eq_average (hP : P.IsEquipartition) (ht : t ∈ P.parts) :
t.card = s.card / P.parts.card ∨ t.card = s.card / P.parts.card + 1 :=
P.isEquipartition_iff_card_parts_eq_average.1 hP _ ht
theorem IsEquipartition.card_part_eq_average_iff (hP : P.IsEquipartition) (ht : t ∈ P.parts) :
t.card = s.card / P.parts.card ↔ t.card ≠ s.card / P.parts.card + 1 := by
have a := hP.card_parts_eq_average ht
have b : ¬(t.card = s.card / P.parts.card ∧ t.card = s.card / P.parts.card + 1) := by
by_contra h; exact absurd (h.1 ▸ h.2) (lt_add_one _).ne
tauto
theorem IsEquipartition.average_le_card_part (hP : P.IsEquipartition) (ht : t ∈ P.parts) :
s.card / P.parts.card ≤ t.card := by
rw [← P.sum_card_parts]
exact Finset.EquitableOn.le hP ht
theorem IsEquipartition.card_part_le_average_add_one (hP : P.IsEquipartition) (ht : t ∈ P.parts) :
t.card ≤ s.card / P.parts.card + 1 := by
rw [← P.sum_card_parts]
exact Finset.EquitableOn.le_add_one hP ht
theorem IsEquipartition.filter_ne_average_add_one_eq_average (hP : P.IsEquipartition) :
P.parts.filter (fun p ↦ ¬p.card = s.card / P.parts.card + 1) =
P.parts.filter (fun p ↦ p.card = s.card / P.parts.card) := by
ext p
simp only [mem_filter, and_congr_right_iff]
exact fun hp ↦ (hP.card_part_eq_average_iff hp).symm
/-- An equipartition of a finset with `n` elements into `k` parts has
`n % k` parts of size `n / k + 1`. -/
theorem IsEquipartition.card_large_parts_eq_mod (hP : P.IsEquipartition) :
(P.parts.filter fun p ↦ p.card = s.card / P.parts.card + 1).card = s.card % P.parts.card := by
have z := P.sum_card_parts
rw [← sum_filter_add_sum_filter_not (s := P.parts)
(p := fun x ↦ x.card = s.card / P.parts.card + 1),
hP.filter_ne_average_add_one_eq_average,
sum_const_nat (m := s.card / P.parts.card + 1) (by simp),
sum_const_nat (m := s.card / P.parts.card) (by simp),
← hP.filter_ne_average_add_one_eq_average,
mul_add, add_comm, ← add_assoc, ← add_mul, mul_one, add_comm (Finset.card _),
filter_card_add_filter_neg_card_eq_card, add_comm] at z
rw [← add_left_inj, Nat.mod_add_div, z]
/-- An equipartition of a finset with `n` elements into `k` parts has
`n - n % k` parts of size `n / k`. -/
theorem IsEquipartition.card_small_parts_eq_mod (hP : P.IsEquipartition) :
(P.parts.filter fun p ↦ p.card = s.card / P.parts.card).card =
P.parts.card - s.card % P.parts.card := by
conv_rhs =>
arg 1
rw [← filter_card_add_filter_neg_card_eq_card (p := fun p ↦ p.card = s.card / P.parts.card + 1)]
rw [hP.card_large_parts_eq_mod, add_tsub_cancel_left, hP.filter_ne_average_add_one_eq_average]
/-- There exists an enumeration of an equipartition's parts where
larger parts map to smaller numbers and vice versa. -/
theorem IsEquipartition.exists_partsEquiv (hP : P.IsEquipartition) :
∃ f : P.parts ≃ Fin P.parts.card,
∀ t, t.1.card = s.card / P.parts.card + 1 ↔ f t < s.card % P.parts.card := by
let el := (P.parts.filter fun p ↦ p.card = s.card / P.parts.card + 1).equivFin
let es := (P.parts.filter fun p ↦ p.card = s.card / P.parts.card).equivFin
simp_rw [mem_filter, hP.card_large_parts_eq_mod] at el
simp_rw [mem_filter, hP.card_small_parts_eq_mod] at es
let sneg : { x // x ∈ P.parts ∧ ¬x.card = s.card / P.parts.card + 1 } ≃
{ x // x ∈ P.parts ∧ x.card = s.card / P.parts.card } := by
apply (Equiv.refl _).subtypeEquiv
simp only [Equiv.refl_apply, and_congr_right_iff]
exact fun _ ha ↦ by rw [hP.card_part_eq_average_iff ha, ne_eq]
replace el : { x : P.parts // x.1.card = s.card / P.parts.card + 1 } ≃
Fin (s.card % P.parts.card) := (Equiv.Set.sep ..).symm.trans el
replace es : { x : P.parts // ¬x.1.card = s.card / P.parts.card + 1 } ≃
Fin (P.parts.card - s.card % P.parts.card) := (Equiv.Set.sep ..).symm.trans (sneg.trans es)
let f := (Equiv.sumCompl _).symm.trans ((el.sumCongr es).trans finSumFinEquiv)
use f.trans (finCongr (Nat.add_sub_of_le P.card_mod_card_parts_le))
intro ⟨p, _⟩
simp_rw [f, Equiv.trans_apply, Equiv.sumCongr_apply, finCongr_apply, Fin.coe_cast]
by_cases hc : p.card = s.card / P.parts.card + 1 <;> simp [hc]
/-- Given a finset equipartitioned into `k` parts, its elements can be enumerated such that
elements in the same part have congruent indices modulo `k`. -/
theorem IsEquipartition.exists_partPreservingEquiv (hP : P.IsEquipartition) : ∃ f : s ≃ Fin s.card,
∀ a b : s, P.part a = P.part b ↔ f a % P.parts.card = f b % P.parts.card := by
obtain ⟨f, hf⟩ := P.exists_enumeration
obtain ⟨g, hg⟩ := hP.exists_partsEquiv
let z := fun a ↦ P.parts.card * (f a).2 + g (f a).1
have gl := fun a ↦ (g (f a).1).2
have less : ∀ a, z a < s.card := fun a ↦ by
rcases hP.card_parts_eq_average (f a).1.2 with (c | c)
· calc
_ < P.parts.card * ((f a).2 + 1) := add_lt_add_left (gl a) _
_ ≤ P.parts.card * (s.card / P.parts.card) := mul_le_mul_left' (c ▸ (f a).2.2) _
_ ≤ P.parts.card * (s.card / P.parts.card) + s.card % P.parts.card := Nat.le_add_right ..
_ = _ := Nat.div_add_mod ..
· rw [← Nat.div_add_mod s.card P.parts.card]
exact add_lt_add_of_le_of_lt (mul_le_mul_left' (by omega) _) ((hg (f a).1).mp c)
let z' : s → Fin s.card := fun a ↦ ⟨z a, less a⟩
have bij : z'.Bijective := by
refine (bijective_iff_injective_and_card z').mpr ⟨fun a b e ↦ ?_, by simp⟩
simp_rw [z', z, Fin.mk.injEq, mul_comm P.parts.card] at e
haveI : NeZero P.parts.card := ⟨((Nat.zero_le _).trans_lt (gl a)).ne'⟩
change P.parts.card.divModEquiv.symm (_, _) = P.parts.card.divModEquiv.symm (_, _) at e
simp only [Equiv.apply_eq_iff_eq, Prod.mk.injEq] at e
apply_fun f
exact Sigma.ext e.2 <| (Fin.heq_ext_iff (by rw [e.2])).mpr e.1
use Equiv.ofBijective _ bij
intro a b
simp_rw [Equiv.ofBijective_apply, z, hf a b, Nat.mul_add_mod,
Nat.mod_eq_of_lt (gl a), Nat.mod_eq_of_lt (gl b), Fin.val_eq_val, g.apply_eq_iff_eq]
/-! ### Discrete and indiscrete finpartitions -/
variable (s) -- [Decidable (a = ⊥)]
theorem bot_isEquipartition : (⊥ : Finpartition s).IsEquipartition :=
Set.equitableOn_iff_exists_eq_eq_add_one.2 ⟨1, by simp⟩
theorem top_isEquipartition [Decidable (s = ⊥)] : (⊤ : Finpartition s).IsEquipartition :=
Set.Subsingleton.isEquipartition (parts_top_subsingleton _)
theorem indiscrete_isEquipartition {hs : s ≠ ∅} : (indiscrete hs).IsEquipartition := by
rw [IsEquipartition, indiscrete_parts, coe_singleton]
exact Set.equitableOn_singleton s _
end Finpartition
|
Order\Partition\Finpartition.lean | /-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Order.SupIndep
import Mathlib.Order.Atoms
/-!
# Finite partitions
In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise
disjoint parts `parts : Finset α` which does not contain `⊥` and whose supremum is `a`.
Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied
purely order theoretically in Sperner theory.
## Constructions
We provide many ways to build finpartitions:
* `Finpartition.ofErase`: Builds a finpartition by erasing `⊥` for you.
* `Finpartition.ofSubset`: Builds a finpartition from a subset of the parts of a previous
finpartition.
* `Finpartition.empty`: The empty finpartition of `⊥`.
* `Finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single
part.
* `Finpartition.discrete`: The discrete finpartition of `s : Finset α` made of singletons.
* `Finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new
finpartition.
* `Finpartition.ofSetoid`: With `Fintype α`, constructs the finpartition of `univ : Finset α`
induced by the equivalence classes of `s : Setoid α`.
* `Finpartition.atomise`: Makes a finpartition of `s : Finset α` by breaking `s` along all finsets
in `F : Finset (Finset α)`. Two elements of `s` belong to the same part iff they belong to the
same elements of `F`.
`Finpartition.indiscrete` and `Finpartition.bind` together form the monadic structure of
`Finpartition`.
## Implementation notes
Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning
operations on `Finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's
not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing
`⊥` to be a part makes `Finpartition.bind` uglier and doesn't rid us of the need of
`Finpartition.ofErase`.
## TODO
The order is the wrong way around to make `Finpartition a` a graded order. Is it bad to depart from
the literature and turn the order around?
-/
open Finset Function
variable {α : Type*}
/-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is
`a`. We forbid `⊥` as a part. -/
@[ext]
structure Finpartition [Lattice α] [OrderBot α] (a : α) where
-- Porting note: Docstrings added
/-- The elements of the finite partition of `a` -/
parts : Finset α
/-- The partition is supremum-independent -/
supIndep : parts.SupIndep id
/-- The supremum of the partition is `a` -/
sup_parts : parts.sup id = a
/-- No element of the partition is bottom-/
not_bot_mem : ⊥ ∉ parts
deriving DecidableEq
-- Porting note: attribute [protected] doesn't work
-- attribute [protected] Finpartition.supIndep
namespace Finpartition
section Lattice
variable [Lattice α] [OrderBot α]
/-- A `Finpartition` constructor which does not insist on `⊥` not being a part. -/
@[simps]
def ofErase [DecidableEq α] {a : α} (parts : Finset α) (sup_indep : parts.SupIndep id)
(sup_parts : parts.sup id = a) : Finpartition a where
parts := parts.erase ⊥
supIndep := sup_indep.subset (erase_subset _ _)
sup_parts := (sup_erase_bot _).trans sup_parts
not_bot_mem := not_mem_erase _ _
/-- A `Finpartition` constructor from a bigger existing finpartition. -/
@[simps]
def ofSubset {a b : α} (P : Finpartition a) {parts : Finset α} (subset : parts ⊆ P.parts)
(sup_parts : parts.sup id = b) : Finpartition b :=
{ parts := parts
supIndep := P.supIndep.subset subset
sup_parts := sup_parts
not_bot_mem := fun h ↦ P.not_bot_mem (subset h) }
/-- Changes the type of a finpartition to an equal one. -/
@[simps]
def copy {a b : α} (P : Finpartition a) (h : a = b) : Finpartition b where
parts := P.parts
supIndep := P.supIndep
sup_parts := h ▸ P.sup_parts
not_bot_mem := P.not_bot_mem
/-- Transfer a finpartition over an order isomorphism. -/
def map {β : Type*} [Lattice β] [OrderBot β] {a : α} (e : α ≃o β) (P : Finpartition a) :
Finpartition (e a) where
parts := P.parts.map e
supIndep u hu _ hb hbu _ hx hxu := by
rw [← map_symm_subset] at hu
simp only [mem_map_equiv] at hb
have := P.supIndep hu hb (by simp [hbu]) (map_rel e.symm hx) ?_
· rw [← e.symm.map_bot] at this
exact e.symm.map_rel_iff.mp this
· convert e.symm.map_rel_iff.mpr hxu
rw [map_finset_sup, sup_map]
rfl
sup_parts := by simp [← P.sup_parts]
not_bot_mem := by
rw [mem_map_equiv]
convert P.not_bot_mem
exact e.symm.map_bot
@[simp]
theorem parts_map {β : Type*} [Lattice β] [OrderBot β] {a : α} {e : α ≃o β} {P : Finpartition a} :
(P.map e).parts = P.parts.map e := rfl
variable (α)
/-- The empty finpartition. -/
@[simps]
protected def empty : Finpartition (⊥ : α) where
parts := ∅
supIndep := supIndep_empty _
sup_parts := Finset.sup_empty
not_bot_mem := not_mem_empty ⊥
instance : Inhabited (Finpartition (⊥ : α)) :=
⟨Finpartition.empty α⟩
@[simp]
theorem default_eq_empty : (default : Finpartition (⊥ : α)) = Finpartition.empty α :=
rfl
variable {α} {a : α}
/-- The finpartition in one part, aka indiscrete finpartition. -/
@[simps]
def indiscrete (ha : a ≠ ⊥) : Finpartition a where
parts := {a}
supIndep := supIndep_singleton _ _
sup_parts := Finset.sup_singleton
not_bot_mem h := ha (mem_singleton.1 h).symm
variable (P : Finpartition a)
protected theorem le {b : α} (hb : b ∈ P.parts) : b ≤ a :=
(le_sup hb).trans P.sup_parts.le
theorem ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := by
intro h
refine P.not_bot_mem (?_)
rw [h] at hb
exact hb
protected theorem disjoint : (P.parts : Set α).PairwiseDisjoint id :=
P.supIndep.pairwiseDisjoint
variable {P}
theorem parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ := by
simp_rw [← P.sup_parts]
refine ⟨fun h ↦ ?_, fun h ↦ eq_empty_iff_forall_not_mem.2 fun b hb ↦ P.not_bot_mem ?_⟩
· rw [h]
exact Finset.sup_empty
· rwa [← le_bot_iff.1 ((le_sup hb).trans h.le)]
theorem parts_nonempty_iff : P.parts.Nonempty ↔ a ≠ ⊥ := by
rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff]
theorem parts_nonempty (P : Finpartition a) (ha : a ≠ ⊥) : P.parts.Nonempty :=
parts_nonempty_iff.2 ha
instance : Unique (Finpartition (⊥ : α)) :=
{ (inferInstance : Inhabited (Finpartition (⊥ : α))) with
uniq := fun P ↦ by
ext a
exact iff_of_false (fun h ↦ P.ne_bot h <| le_bot_iff.1 <| P.le h) (not_mem_empty a) }
-- See note [reducible non instances]
/-- There's a unique partition of an atom. -/
abbrev _root_.IsAtom.uniqueFinpartition (ha : IsAtom a) : Unique (Finpartition a) where
default := indiscrete ha.1
uniq P := by
have h : ∀ b ∈ P.parts, b = a := fun _ hb ↦
(ha.le_iff.mp <| P.le hb).resolve_left (P.ne_bot hb)
ext b
refine Iff.trans ⟨h b, ?_⟩ mem_singleton.symm
rintro rfl
obtain ⟨c, hc⟩ := P.parts_nonempty ha.1
simp_rw [← h c hc]
exact hc
instance [Fintype α] [DecidableEq α] (a : α) : Fintype (Finpartition a) :=
@Fintype.ofSurjective { p : Finset α // p.SupIndep id ∧ p.sup id = a ∧ ⊥ ∉ p } (Finpartition a) _
(Subtype.fintype _) (fun i ↦ ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) fun ⟨_, y, z, w⟩ ↦
⟨⟨_, y, z, w⟩, rfl⟩
/-! ### Refinement order -/
section Order
/-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/
instance : LE (Finpartition a) :=
⟨fun P Q ↦ ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩
instance : PartialOrder (Finpartition a) :=
{ (inferInstance : LE (Finpartition a)) with
le_refl := fun P b hb ↦ ⟨b, hb, le_rfl⟩
le_trans := fun P Q R hPQ hQR b hb ↦ by
obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hcd⟩ := hQR hc
exact ⟨d, hd, hbc.trans hcd⟩
le_antisymm := fun P Q hPQ hQP ↦ by
ext b
refine ⟨fun hb ↦ ?_, fun hb ↦ ?_⟩
· obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hcd⟩ := hQP hc
rwa [hbc.antisymm]
rwa [P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd)]
· obtain ⟨c, hc, hbc⟩ := hQP hb
obtain ⟨d, hd, hcd⟩ := hPQ hc
rwa [hbc.antisymm]
rwa [Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd)] }
instance [Decidable (a = ⊥)] : OrderTop (Finpartition a) where
top := if ha : a = ⊥ then (Finpartition.empty α).copy ha.symm else indiscrete ha
le_top P := by
split_ifs with h
· intro x hx
simpa [h, P.ne_bot hx] using P.le hx
· exact fun b hb ↦ ⟨a, mem_singleton_self _, P.le hb⟩
theorem parts_top_subset (a : α) [Decidable (a = ⊥)] : (⊤ : Finpartition a).parts ⊆ {a} := by
intro b hb
have hb : b ∈ Finpartition.parts (dite _ _ _) := hb
split_ifs at hb
· simp only [copy_parts, empty_parts, not_mem_empty] at hb
· exact hb
theorem parts_top_subsingleton (a : α) [Decidable (a = ⊥)] :
((⊤ : Finpartition a).parts : Set α).Subsingleton :=
Set.subsingleton_of_subset_singleton fun _ hb ↦ mem_singleton.1 <| parts_top_subset _ hb
end Order
end Lattice
section DistribLattice
variable [DistribLattice α] [OrderBot α]
section Inf
variable [DecidableEq α] {a b c : α}
instance : Inf (Finpartition a) :=
⟨fun P Q ↦
ofErase ((P.parts ×ˢ Q.parts).image fun bc ↦ bc.1 ⊓ bc.2)
(by
rw [supIndep_iff_disjoint_erase]
simp only [mem_image, and_imp, exists_prop, forall_exists_index, id, Prod.exists,
mem_product, Finset.disjoint_sup_right, mem_erase, Ne]
rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl
rcases eq_or_ne x₁ x₂ with (rfl | xdiff)
· refine Disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ ?_)
intro t
simp [t] at h
exact Disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff))
(by
rw [sup_image, id_comp, sup_product_left]
trans P.parts.sup id ⊓ Q.parts.sup id
· simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left]
rfl
· rw [P.sup_parts, Q.sup_parts, inf_idem])⟩
@[simp]
theorem parts_inf (P Q : Finpartition a) :
(P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image fun bc : α × α ↦ bc.1 ⊓ bc.2).erase ⊥ :=
rfl
instance : SemilatticeInf (Finpartition a) :=
{ (inferInstance : PartialOrder (Finpartition a)),
(inferInstance : Inf (Finpartition a)) with
inf_le_left := fun P Q b hb ↦ by
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb)
rw [mem_product] at hc
exact ⟨c.1, hc.1, inf_le_left⟩
inf_le_right := fun P Q b hb ↦ by
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb)
rw [mem_product] at hc
exact ⟨c.2, hc.2, inf_le_right⟩
le_inf := fun P Q R hPQ hPR b hb ↦ by
obtain ⟨c, hc, hbc⟩ := hPQ hb
obtain ⟨d, hd, hbd⟩ := hPR hb
have h := _root_.le_inf hbc hbd
refine
⟨c ⊓ d,
mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h)
(mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩),
h⟩ }
end Inf
theorem exists_le_of_le {a b : α} {P Q : Finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) :
∃ c ∈ P.parts, c ≤ b := by
by_contra H
refine Q.ne_bot hb (disjoint_self.1 <| Disjoint.mono_right (Q.le hb) ?_)
rw [← P.sup_parts, Finset.disjoint_sup_right]
rintro c hc
obtain ⟨d, hd, hcd⟩ := h hc
refine (Q.disjoint hb hd ?_).mono_right hcd
rintro rfl
simp only [not_exists, not_and] at H
exact H _ hc hcd
theorem card_mono {a : α} {P Q : Finpartition a} (h : P ≤ Q) : Q.parts.card ≤ P.parts.card := by
classical
have : ∀ b ∈ Q.parts, ∃ c ∈ P.parts, c ≤ b := fun b ↦ exists_le_of_le h
choose f hP hf using this
rw [← card_attach]
refine card_le_card_of_injOn (fun b ↦ f _ b.2) (fun b _ ↦ hP _ b.2) fun b _ c _ h ↦ ?_
exact
Subtype.coe_injective
(Q.disjoint.elim b.2 c.2 fun H ↦
P.ne_bot (hP _ b.2) <| disjoint_self.1 <| H.mono (hf _ b.2) <| h.le.trans <| hf _ c.2)
variable [DecidableEq α] {a b c : α}
section Bind
variable {P : Finpartition a} {Q : ∀ i ∈ P.parts, Finpartition i}
/-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the
finpartition of `a` obtained by juxtaposing all the subpartitions. -/
@[simps]
def bind (P : Finpartition a) (Q : ∀ i ∈ P.parts, Finpartition i) : Finpartition a where
parts := P.parts.attach.biUnion fun i ↦ (Q i.1 i.2).parts
supIndep := by
rw [supIndep_iff_pairwiseDisjoint]
rintro a ha b hb h
rw [Finset.mem_coe, Finset.mem_biUnion] at ha hb
obtain ⟨⟨A, hA⟩, -, ha⟩ := ha
obtain ⟨⟨B, hB⟩, -, hb⟩ := hb
obtain rfl | hAB := eq_or_ne A B
· exact (Q A hA).disjoint ha hb h
· exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb)
sup_parts := by
simp_rw [sup_biUnion]
trans (sup P.parts id)
· rw [eq_comm, ← Finset.sup_attach]
exact sup_congr rfl fun b _hb ↦ (Q b.1 b.2).sup_parts.symm
· exact P.sup_parts
not_bot_mem h := by
rw [Finset.mem_biUnion] at h
obtain ⟨⟨A, hA⟩, -, h⟩ := h
exact (Q A hA).not_bot_mem h
theorem mem_bind : b ∈ (P.bind Q).parts ↔ ∃ A hA, b ∈ (Q A hA).parts := by
rw [bind, mem_biUnion]
constructor
· rintro ⟨⟨A, hA⟩, -, h⟩
exact ⟨A, hA, h⟩
· rintro ⟨A, hA, h⟩
exact ⟨⟨A, hA⟩, mem_attach _ ⟨A, hA⟩, h⟩
theorem card_bind (Q : ∀ i ∈ P.parts, Finpartition i) :
(P.bind Q).parts.card = ∑ A ∈ P.parts.attach, (Q _ A.2).parts.card := by
apply card_biUnion
rintro ⟨b, hb⟩ - ⟨c, hc⟩ - hbc
rw [Finset.disjoint_left]
rintro d hdb hdc
rw [Ne, Subtype.mk_eq_mk] at hbc
exact
(Q b hb).ne_bot hdb
(eq_bot_iff.2 <|
(le_inf ((Q b hb).le hdb) <| (Q c hc).le hdc).trans <| (P.disjoint hb hc hbc).le_bot)
end Bind
/-- Adds `b` to a finpartition of `a` to make a finpartition of `a ⊔ b`. -/
@[simps]
def extend (P : Finpartition a) (hb : b ≠ ⊥) (hab : Disjoint a b) (hc : a ⊔ b = c) :
Finpartition c where
parts := insert b P.parts
supIndep := by
rw [supIndep_iff_pairwiseDisjoint, coe_insert]
exact P.disjoint.insert fun d hd _ ↦ hab.symm.mono_right <| P.le hd
sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm]
not_bot_mem h := (mem_insert.1 h).elim hb.symm P.not_bot_mem
theorem card_extend (P : Finpartition a) (b c : α) {hb : b ≠ ⊥} {hab : Disjoint a b}
{hc : a ⊔ b = c} : (P.extend hb hab hc).parts.card = P.parts.card + 1 :=
card_insert_of_not_mem fun h ↦ hb <| hab.symm.eq_bot_of_le <| P.le h
end DistribLattice
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] [DecidableEq α] {a b c : α} (P : Finpartition a)
/-- Restricts a finpartition to avoid a given element. -/
@[simps!]
def avoid (b : α) : Finpartition (a \ b) :=
ofErase
(P.parts.image (· \ b))
(P.disjoint.image_finset_of_le fun a ↦ sdiff_le).supIndep
(by rw [sup_image, id_comp, Finset.sup_sdiff_right, ← Function.id_def, P.sup_parts])
@[simp]
theorem mem_avoid : c ∈ (P.avoid b).parts ↔ ∃ d ∈ P.parts, ¬d ≤ b ∧ d \ b = c := by
simp only [avoid, ofErase, mem_erase, Ne, mem_image, exists_prop, ← exists_and_left,
@and_left_comm (c ≠ ⊥)]
refine exists_congr fun d ↦ and_congr_right' <| and_congr_left ?_
rintro rfl
rw [sdiff_eq_bot_iff]
end GeneralizedBooleanAlgebra
end Finpartition
/-! ### Finite partitions of finsets -/
namespace Finpartition
variable [DecidableEq α] {s t u : Finset α} (P : Finpartition s) {a : α}
theorem nonempty_of_mem_parts {a : Finset α} (ha : a ∈ P.parts) : a.Nonempty :=
nonempty_iff_ne_empty.2 <| P.ne_bot ha
lemma eq_of_mem_parts (ht : t ∈ P.parts) (hu : u ∈ P.parts) (hat : a ∈ t) (hau : a ∈ u) : t = u :=
P.disjoint.elim ht hu <| not_disjoint_iff.2 ⟨a, hat, hau⟩
theorem exists_mem (ha : a ∈ s) : ∃ t ∈ P.parts, a ∈ t := by
simp_rw [← P.sup_parts] at ha
exact mem_sup.1 ha
theorem biUnion_parts : P.parts.biUnion id = s :=
(sup_eq_biUnion _ _).symm.trans P.sup_parts
theorem existsUnique_mem (ha : a ∈ s) : ∃! t, t ∈ P.parts ∧ a ∈ t := by
obtain ⟨t, ht, ht'⟩ := P.exists_mem ha
refine ⟨t, ⟨ht, ht'⟩, ?_⟩
rintro u ⟨hu, hu'⟩
exact P.eq_of_mem_parts hu ht hu' ht'
/-- The part of the finpartition that `a` lies in. -/
def part (a : α) : Finset α := if ha : a ∈ s then choose (hp := P.existsUnique_mem ha) else ∅
lemma part_mem (ha : a ∈ s) : P.part a ∈ P.parts := by simp [part, ha, choose_mem]
lemma mem_part (ha : a ∈ s) : a ∈ P.part a := by simp [part, ha, choose_property]
lemma part_eq_of_mem (ht : t ∈ P.parts) (hat : a ∈ t) : P.part a = t := by
apply P.eq_of_mem_parts (P.part_mem _) ht (P.mem_part _) hat <;> exact mem_of_subset (P.le ht) hat
lemma mem_part_iff_part_eq_part {b : α} (ha : a ∈ s) (hb : b ∈ s) :
a ∈ P.part b ↔ P.part a = P.part b :=
⟨fun c ↦ (P.part_eq_of_mem (P.part_mem hb) c), fun c ↦ c ▸ P.mem_part ha⟩
theorem part_surjOn : Set.SurjOn P.part s P.parts := fun p hp ↦ by
obtain ⟨x, hx⟩ := P.nonempty_of_mem_parts hp
have hx' := mem_of_subset (P.le hp) hx
use x, hx', (P.existsUnique_mem hx').unique ⟨P.part_mem hx', P.mem_part hx'⟩ ⟨hp, hx⟩
theorem exists_subset_part_bijOn : ∃ r ⊆ s, Set.BijOn P.part r P.parts := by
obtain ⟨r, hrs, hr⟩ := P.part_surjOn.exists_bijOn_subset
lift r to Finset α using s.finite_toSet.subset hrs
exact ⟨r, mod_cast hrs, hr⟩
/-- Equivalence between a finpartition's parts as a dependent sum and the partitioned set. -/
def equivSigmaParts : s ≃ Σ t : P.parts, t.1 where
toFun x := ⟨⟨P.part x.1, P.part_mem x.2⟩, ⟨x, P.mem_part x.2⟩⟩
invFun x := ⟨x.2, mem_of_subset (P.le x.1.2) x.2.2⟩
left_inv x := by simp
right_inv x := by
ext e
· obtain ⟨⟨p, mp⟩, ⟨f, mf⟩⟩ := x
dsimp only at mf ⊢
rw [P.part_eq_of_mem mp mf]
· simp
lemma exists_enumeration : ∃ f : s ≃ Σ t : P.parts, Fin t.1.card,
∀ a b : s, P.part a = P.part b ↔ (f a).1 = (f b).1 := by
use P.equivSigmaParts.trans ((Equiv.refl _).sigmaCongr (fun t ↦ t.1.equivFin))
simp [equivSigmaParts, Equiv.sigmaCongr, Equiv.sigmaCongrLeft]
theorem sum_card_parts : ∑ i ∈ P.parts, i.card = s.card := by
convert congr_arg Finset.card P.biUnion_parts
rw [card_biUnion P.supIndep.pairwiseDisjoint]
rfl
/-- `⊥` is the partition in singletons, aka discrete partition. -/
instance (s : Finset α) : Bot (Finpartition s) :=
⟨{ parts := s.map ⟨singleton, singleton_injective⟩
supIndep :=
Set.PairwiseDisjoint.supIndep
(by
rw [Finset.coe_map]
exact Finset.pairwiseDisjoint_range_singleton.subset (Set.image_subset_range _ _))
sup_parts := by rw [sup_map, id_comp, Embedding.coeFn_mk, Finset.sup_singleton']
not_bot_mem := by simp }⟩
@[simp]
theorem parts_bot (s : Finset α) :
(⊥ : Finpartition s).parts = s.map ⟨singleton, singleton_injective⟩ :=
rfl
theorem card_bot (s : Finset α) : (⊥ : Finpartition s).parts.card = s.card :=
Finset.card_map _
theorem mem_bot_iff : t ∈ (⊥ : Finpartition s).parts ↔ ∃ a ∈ s, {a} = t :=
mem_map
instance (s : Finset α) : OrderBot (Finpartition s) :=
{ (inferInstance : Bot (Finpartition s)) with
bot_le := fun P t ht ↦ by
rw [mem_bot_iff] at ht
obtain ⟨a, ha, rfl⟩ := ht
obtain ⟨t, ht, hat⟩ := P.exists_mem ha
exact ⟨t, ht, singleton_subset_iff.2 hat⟩ }
theorem card_parts_le_card : P.parts.card ≤ s.card := by
rw [← card_bot s]
exact card_mono bot_le
lemma card_mod_card_parts_le : s.card % P.parts.card ≤ P.parts.card := by
rcases P.parts.card.eq_zero_or_pos with h | h
· have h' := h
rw [Finset.card_eq_zero, parts_eq_empty_iff, bot_eq_empty, ← Finset.card_eq_zero] at h'
rw [h, h']
· exact (Nat.mod_lt _ h).le
variable [Fintype α]
/-- A setoid over a finite type induces a finpartition of the type's elements,
where the parts are the setoid's equivalence classes. -/
def ofSetoid (s : Setoid α) [DecidableRel s.r] : Finpartition (univ : Finset α) where
parts := univ.image fun a => univ.filter (s.r a)
supIndep := by
simp only [mem_univ, forall_true_left, supIndep_iff_pairwiseDisjoint, Set.PairwiseDisjoint,
Set.Pairwise, coe_image, coe_univ, Set.image_univ, Set.mem_range, ne_eq,
forall_exists_index, forall_apply_eq_imp_iff]
intro _ _ q
contrapose! q
rw [not_disjoint_iff] at q
obtain ⟨c, ⟨d1, d2⟩⟩ := q
rw [id_eq, mem_filter] at d1 d2
ext y
simp only [mem_univ, forall_true_left, mem_filter, true_and]
exact ⟨fun r1 => s.trans (s.trans d2.2 (s.symm d1.2)) r1,
fun r2 => s.trans (s.trans d1.2 (s.symm d2.2)) r2⟩
sup_parts := by
ext a
simp only [sup_image, Function.id_comp, mem_univ, mem_sup, mem_filter, true_and, iff_true]
use a; exact s.refl a
not_bot_mem := by
rw [bot_eq_empty, mem_image, not_exists]
intro a
simp only [filter_eq_empty_iff, not_forall, mem_univ, forall_true_left, true_and, not_not]
use a; exact s.refl a
theorem mem_part_ofSetoid_iff_rel {s : Setoid α} [DecidableRel s.r] {b : α} :
b ∈ (ofSetoid s).part a ↔ s.r a b := by
simp_rw [part, ofSetoid, mem_univ, reduceDIte]
generalize_proofs H
have := choose_spec _ _ H
simp only [mem_univ, mem_image, true_and] at this
obtain ⟨⟨_, hc⟩, this⟩ := this
simp only [← hc, mem_univ, mem_filter, true_and] at this ⊢
exact ⟨s.trans (s.symm this), s.trans this⟩
section Atomise
/-- Cuts `s` along the finsets in `F`: Two elements of `s` will be in the same part if they are
in the same finsets of `F`. -/
def atomise (s : Finset α) (F : Finset (Finset α)) : Finpartition s :=
ofErase (F.powerset.image fun Q ↦ s.filter fun i ↦ ∀ t ∈ F, t ∈ Q ↔ i ∈ t)
(Set.PairwiseDisjoint.supIndep fun x hx y hy h ↦
disjoint_left.mpr fun z hz1 hz2 ↦
h (by
rw [mem_coe, mem_image] at hx hy
obtain ⟨Q, hQ, rfl⟩ := hx
obtain ⟨R, hR, rfl⟩ := hy
suffices h' : Q = R by
subst h'
exact of_eq_true (eq_self (
filter (fun i ↦ ∀ (t : Finset α), t ∈ F → (t ∈ Q ↔ i ∈ t)) s))
rw [id, mem_filter] at hz1 hz2
rw [mem_powerset] at hQ hR
ext i
refine ⟨fun hi ↦ ?_, fun hi ↦ ?_⟩
· rwa [hz2.2 _ (hQ hi), ← hz1.2 _ (hQ hi)]
· rwa [hz1.2 _ (hR hi), ← hz2.2 _ (hR hi)]))
(by
refine (Finset.sup_le fun t ht ↦ ?_).antisymm fun a ha ↦ ?_
· rw [mem_image] at ht
obtain ⟨A, _, rfl⟩ := ht
exact s.filter_subset _
· rw [mem_sup]
refine
⟨s.filter fun i ↦ ∀ t, t ∈ F → ((t ∈ F.filter fun u ↦ a ∈ u) ↔ i ∈ t),
mem_image_of_mem _ (mem_powerset.2 <| filter_subset _ _),
mem_filter.2 ⟨ha, fun t ht ↦ ?_⟩⟩
rw [mem_filter]
exact and_iff_right ht)
variable {F : Finset (Finset α)}
theorem mem_atomise :
t ∈ (atomise s F).parts ↔
t.Nonempty ∧ ∃ Q ⊆ F, (s.filter fun i ↦ ∀ u ∈ F, u ∈ Q ↔ i ∈ u) = t := by
simp only [atomise, ofErase, bot_eq_empty, mem_erase, mem_image, nonempty_iff_ne_empty,
mem_singleton, and_comm, mem_powerset, exists_prop]
theorem atomise_empty (hs : s.Nonempty) : (atomise s ∅).parts = {s} := by
simp only [atomise, powerset_empty, image_singleton, not_mem_empty, IsEmpty.forall_iff,
imp_true_iff, filter_True]
exact erase_eq_of_not_mem (not_mem_singleton.2 hs.ne_empty.symm)
theorem card_atomise_le : (atomise s F).parts.card ≤ 2 ^ F.card :=
(card_le_card <| erase_subset _ _).trans <| Finset.card_image_le.trans (card_powerset _).le
theorem biUnion_filter_atomise (ht : t ∈ F) (hts : t ⊆ s) :
((atomise s F).parts.filter fun u ↦ u ⊆ t ∧ u.Nonempty).biUnion id = t := by
ext a
refine mem_biUnion.trans ⟨fun ⟨u, hu, ha⟩ ↦ (mem_filter.1 hu).2.1 ha, fun ha ↦ ?_⟩
obtain ⟨u, hu, hau⟩ := (atomise s F).exists_mem (hts ha)
refine ⟨u, mem_filter.2 ⟨hu, fun b hb ↦ ?_, _, hau⟩, hau⟩
obtain ⟨Q, _hQ, rfl⟩ := (mem_atomise.1 hu).2
rw [mem_filter] at hau hb
rwa [← hb.2 _ ht, hau.2 _ ht]
theorem card_filter_atomise_le_two_pow (ht : t ∈ F) :
((atomise s F).parts.filter fun u ↦ u ⊆ t ∧ u.Nonempty).card ≤ 2 ^ (F.card - 1) := by
suffices h :
((atomise s F).parts.filter fun u ↦ u ⊆ t ∧ u.Nonempty) ⊆
(F.erase t).powerset.image fun P ↦ s.filter fun i ↦ ∀ x ∈ F, x ∈ insert t P ↔ i ∈ x by
refine (card_le_card h).trans (card_image_le.trans ?_)
rw [card_powerset, card_erase_of_mem ht]
rw [subset_iff]
simp_rw [mem_image, mem_powerset, mem_filter, and_imp, Finset.Nonempty, exists_imp, mem_atomise,
and_imp, Finset.Nonempty, exists_imp, and_imp]
rintro P' i hi P PQ rfl hy₂ j _hj
refine ⟨P.erase t, erase_subset_erase _ PQ, ?_⟩
simp only [insert_erase (((mem_filter.1 hi).2 _ ht).2 <| hy₂ hi)]
end Atomise
end Finpartition
|
Order\Rel\GaloisConnection.lean | /-
Copyright (c) 2024 Lagrange Mathematics and Computing Research Center. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anthony Bordg
-/
import Mathlib.Data.Rel
import Mathlib.Order.GaloisConnection
/-!
# The Galois Connection Induced by a Relation
In this file, we show that an arbitrary relation `R` between a pair of types `α` and `β` defines
a pair `toDual ∘ R.leftDual` and `R.rightDual ∘ ofDual` of adjoint order-preserving maps between the
corresponding posets `Set α` and `(Set β)ᵒᵈ`.
We define `R.leftFixedPoints` (resp. `R.rightFixedPoints`) as the set of fixed points `J`
(resp. `I`) of `Set α` (resp. `Set β`) such that `rightDual (leftDual J) = J`
(resp. `leftDual (rightDual I) = I`).
## Main Results
⋆ `Rel.gc_leftDual_rightDual`: we prove that the maps `toDual ∘ R.leftDual` and
`R.rightDual ∘ ofDual` form a Galois connection.
⋆ `Rel.equivFixedPoints`: we prove that the maps `R.leftDual` and `R.rightDual` induce inverse
bijections between the sets of fixed points.
## References
⋆ Engendrement de topologies, démontrabilité et opérations sur les sous-topos, Olivia Caramello and
Laurent Lafforgue (in preparation)
## Tags
relation, Galois connection, induced bijection, fixed points
-/
variable {α β : Type*} (R : Rel α β)
namespace Rel
/-! ### Pairs of adjoint maps defined by relations -/
open OrderDual
/-- `leftDual` maps any set `J` of elements of type `α` to the set `{b : β | ∀ a ∈ J, R a b}` of
elements `b` of type `β` such that `R a b` for every element `a` of `J`. -/
def leftDual (J : Set α) : Set β := {b : β | ∀ ⦃a⦄, a ∈ J → R a b}
/-- `rightDual` maps any set `I` of elements of type `β` to the set `{a : α | ∀ b ∈ I, R a b}`
of elements `a` of type `α` such that `R a b` for every element `b` of `I`. -/
def rightDual (I : Set β) : Set α := {a : α | ∀ ⦃b⦄, b ∈ I → R a b}
/-- The pair of functions `toDual ∘ leftDual` and `rightDual ∘ ofDual` forms a Galois connection. -/
theorem gc_leftDual_rightDual : GaloisConnection (toDual ∘ R.leftDual) (R.rightDual ∘ ofDual) :=
fun J I ↦ ⟨fun h a ha b hb ↦ h (by simpa) ha, fun h b hb a ha ↦ h (by simpa) hb⟩
/-! ### Induced equivalences between fixed points -/
/-- `leftFixedPoints` is the set of elements `J : Set α` satisfying `rightDual (leftDual J) = J`. -/
def leftFixedPoints := {J : Set α | R.rightDual (R.leftDual J) = J}
/-- `rightFixedPoints` is the set of elements `I : Set β` satisfying `leftDual (rightDual I) = I`.
-/
def rightFixedPoints := {I : Set β | R.leftDual (R.rightDual I) = I}
open GaloisConnection
/-- `leftDual` maps every element `J` to `rightFixedPoints`. -/
theorem leftDual_mem_rightFixedPoint (J : Set α) : R.leftDual J ∈ R.rightFixedPoints := by
apply le_antisymm
· apply R.gc_leftDual_rightDual.monotone_l; exact R.gc_leftDual_rightDual.le_u_l J
· exact R.gc_leftDual_rightDual.l_u_le (R.leftDual J)
/-- `rightDual` maps every element `I` to `leftFixedPoints`. -/
theorem rightDual_mem_leftFixedPoint (I : Set β) : R.rightDual I ∈ R.leftFixedPoints := by
apply le_antisymm
· apply R.gc_leftDual_rightDual.monotone_u; exact R.gc_leftDual_rightDual.l_u_le I
· exact R.gc_leftDual_rightDual.le_u_l (R.rightDual I)
/-- The maps `leftDual` and `rightDual` induce inverse bijections between the sets of fixed points.
-/
def equivFixedPoints : R.leftFixedPoints ≃ R.rightFixedPoints where
toFun := fun ⟨J, _⟩ => ⟨R.leftDual J, R.leftDual_mem_rightFixedPoint J⟩
invFun := fun ⟨I, _⟩ => ⟨R.rightDual I, R.rightDual_mem_leftFixedPoint I⟩
left_inv J := by cases' J with J hJ; rw [Subtype.mk.injEq, hJ]
right_inv I := by cases' I with I hI; rw [Subtype.mk.injEq, hI]
theorem rightDual_leftDual_le_of_le {J J' : Set α} (h : J' ∈ R.leftFixedPoints) (h₁ : J ≤ J') :
R.rightDual (R.leftDual J) ≤ J' := by
rw [← h]
apply R.gc_leftDual_rightDual.monotone_u
apply R.gc_leftDual_rightDual.monotone_l
exact h₁
theorem leftDual_rightDual_le_of_le {I I' : Set β} (h : I' ∈ R.rightFixedPoints) (h₁ : I ≤ I') :
R.leftDual (R.rightDual I) ≤ I' := by
rw [← h]
apply R.gc_leftDual_rightDual.monotone_l
apply R.gc_leftDual_rightDual.monotone_u
exact h₁
end Rel
|
Order\RelIso\Basic.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Init.Algebra.Classes
import Mathlib.Data.FunLike.Basic
import Mathlib.Logic.Embedding.Basic
import Mathlib.Order.RelClasses
/-!
# Relation homomorphisms, embeddings, isomorphisms
This file defines relation homomorphisms, embeddings, isomorphisms and order embeddings and
isomorphisms.
## Main declarations
* `RelHom`: Relation homomorphism. A `RelHom r s` is a function `f : α → β` such that
`r a b → s (f a) (f b)`.
* `RelEmbedding`: Relation embedding. A `RelEmbedding r s` is an embedding `f : α ↪ β` such that
`r a b ↔ s (f a) (f b)`.
* `RelIso`: Relation isomorphism. A `RelIso r s` is an equivalence `f : α ≃ β` such that
`r a b ↔ s (f a) (f b)`.
* `sumLexCongr`, `prodLexCongr`: Creates a relation homomorphism between two `Sum.Lex` or two
`Prod.Lex` from relation homomorphisms between their arguments.
## Notation
* `→r`: `RelHom`
* `↪r`: `RelEmbedding`
* `≃r`: `RelIso`
-/
open Function
universe u v w
variable {α β γ δ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} {u : δ → δ → Prop}
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : α → β` such that `r a b → s (f a) (f b)`. -/
structure RelHom {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) where
/-- The underlying function of a `RelHom` -/
toFun : α → β
/-- A `RelHom` sends related elements to related elements -/
map_rel' : ∀ {a b}, r a b → s (toFun a) (toFun b)
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : α → β` such that `r a b → s (f a) (f b)`. -/
infixl:25 " →r " => RelHom
section
/-- `RelHomClass F r s` asserts that `F` is a type of functions such that all `f : F`
satisfy `r a b → s (f a) (f b)`.
The relations `r` and `s` are `outParam`s since figuring them out from a goal is a higher-order
matching problem that Lean usually can't do unaided.
-/
class RelHomClass (F : Type*) {α β : Type*} (r : outParam <| α → α → Prop)
(s : outParam <| β → β → Prop) [FunLike F α β] : Prop where
/-- A `RelHomClass` sends related elements to related elements -/
map_rel : ∀ (f : F) {a b}, r a b → s (f a) (f b)
export RelHomClass (map_rel)
end
namespace RelHomClass
variable {F : Type*} [FunLike F α β]
protected theorem isIrrefl [RelHomClass F r s] (f : F) : ∀ [IsIrrefl β s], IsIrrefl α r
| ⟨H⟩ => ⟨fun _ h => H _ (map_rel f h)⟩
protected theorem isAsymm [RelHomClass F r s] (f : F) : ∀ [IsAsymm β s], IsAsymm α r
| ⟨H⟩ => ⟨fun _ _ h₁ h₂ => H _ _ (map_rel f h₁) (map_rel f h₂)⟩
protected theorem acc [RelHomClass F r s] (f : F) (a : α) : Acc s (f a) → Acc r a := by
generalize h : f a = b
intro ac
induction' ac with _ H IH generalizing a
subst h
exact ⟨_, fun a' h => IH (f a') (map_rel f h) _ rfl⟩
protected theorem wellFounded [RelHomClass F r s] (f : F) : WellFounded s → WellFounded r
| ⟨H⟩ => ⟨fun _ => RelHomClass.acc f _ (H _)⟩
end RelHomClass
namespace RelHom
instance : FunLike (r →r s) α β where
coe o := o.toFun
coe_injective' f g h := by
cases f
cases g
congr
instance : RelHomClass (r →r s) r s where
map_rel := map_rel'
initialize_simps_projections RelHom (toFun → apply)
protected theorem map_rel (f : r →r s) {a b} : r a b → s (f a) (f b) :=
f.map_rel'
@[simp]
theorem coe_fn_toFun (f : r →r s) : f.toFun = (f : α → β) :=
rfl
/-- The map `coe_fn : (r →r s) → (α → β)` is injective. -/
theorem coe_fn_injective : Injective fun (f : r →r s) => (f : α → β) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : r →r s⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
/-- Identity map is a relation homomorphism. -/
@[refl, simps]
protected def id (r : α → α → Prop) : r →r r :=
⟨fun x => x, fun x => x⟩
/-- Composition of two relation homomorphisms is a relation homomorphism. -/
@[simps]
protected def comp (g : s →r t) (f : r →r s) : r →r t :=
⟨fun x => g (f x), fun h => g.2 (f.2 h)⟩
/-- A relation homomorphism is also a relation homomorphism between dual relations. -/
protected def swap (f : r →r s) : swap r →r swap s :=
⟨f, f.map_rel⟩
/-- A function is a relation homomorphism from the preimage relation of `s` to `s`. -/
def preimage (f : α → β) (s : β → β → Prop) : f ⁻¹'o s →r s :=
⟨f, id⟩
end RelHom
/-- An increasing function is injective -/
theorem injective_of_increasing (r : α → α → Prop) (s : β → β → Prop) [IsTrichotomous α r]
[IsIrrefl β s] (f : α → β) (hf : ∀ {x y}, r x y → s (f x) (f y)) : Injective f := by
intro x y hxy
rcases trichotomous_of r x y with (h | h | h)
· have := hf h
rw [hxy] at this
exfalso
exact irrefl_of s (f y) this
· exact h
· have := hf h
rw [hxy] at this
exfalso
exact irrefl_of s (f y) this
/-- An increasing function is injective -/
theorem RelHom.injective_of_increasing [IsTrichotomous α r] [IsIrrefl β s] (f : r →r s) :
Injective f :=
_root_.injective_of_increasing r s f f.map_rel
theorem Function.Surjective.wellFounded_iff {f : α → β} (hf : Surjective f)
(o : ∀ {a b}, r a b ↔ s (f a) (f b)) :
WellFounded r ↔ WellFounded s :=
Iff.intro
(RelHomClass.wellFounded (⟨surjInv hf,
fun h => by simpa only [o, surjInv_eq hf] using h⟩ : s →r r))
(RelHomClass.wellFounded (⟨f, o.1⟩ : r →r s))
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. -/
structure RelEmbedding {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ↪ β where
/-- Elements are related iff they are related after apply a `RelEmbedding` -/
map_rel_iff' : ∀ {a b}, s (toEmbedding a) (toEmbedding b) ↔ r a b
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : α ↪ β` such that `r a b ↔ s (f a) (f b)`. -/
infixl:25 " ↪r " => RelEmbedding
/-- The induced relation on a subtype is an embedding under the natural inclusion. -/
def Subtype.relEmbedding {X : Type*} (r : X → X → Prop) (p : X → Prop) :
(Subtype.val : Subtype p → X) ⁻¹'o r ↪r r :=
⟨Embedding.subtype p, Iff.rfl⟩
theorem preimage_equivalence {α β} (f : α → β) {s : β → β → Prop} (hs : Equivalence s) :
Equivalence (f ⁻¹'o s) :=
⟨fun _ => hs.1 _, fun h => hs.2 h, fun h₁ h₂ => hs.3 h₁ h₂⟩
namespace RelEmbedding
/-- A relation embedding is also a relation homomorphism -/
def toRelHom (f : r ↪r s) : r →r s where
toFun := f.toEmbedding.toFun
map_rel' := (map_rel_iff' f).mpr
instance : Coe (r ↪r s) (r →r s) :=
⟨toRelHom⟩
-- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined
instance : FunLike (r ↪r s) α β where
coe := fun x => x.toFun
coe_injective' f g h := by
rcases f with ⟨⟨⟩⟩
rcases g with ⟨⟨⟩⟩
congr
-- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined
instance : RelHomClass (r ↪r s) r s where
map_rel f _ _ := Iff.mpr (map_rel_iff' f)
initialize_simps_projections RelEmbedding (toFun → apply)
instance : EmbeddingLike (r ↪r s) α β where
injective' f := f.inj'
@[simp]
theorem coe_toEmbedding {f : r ↪r s} : ((f : r ↪r s).toEmbedding : α → β) = f :=
rfl
@[simp]
theorem coe_toRelHom {f : r ↪r s} : ((f : r ↪r s).toRelHom : α → β) = f :=
rfl
theorem toEmbedding_injective : Injective (toEmbedding : r ↪r s → (α ↪ β)) := by
rintro ⟨f, -⟩ ⟨g, -⟩; simp
@[simp]
theorem toEmbedding_inj {f g : r ↪r s} : f.toEmbedding = g.toEmbedding ↔ f = g :=
toEmbedding_injective.eq_iff
theorem injective (f : r ↪r s) : Injective f :=
f.inj'
theorem inj (f : r ↪r s) {a b} : f a = f b ↔ a = b := f.injective.eq_iff
theorem map_rel_iff (f : r ↪r s) {a b} : s (f a) (f b) ↔ r a b :=
f.map_rel_iff'
@[simp]
theorem coe_mk {f} {h} : ⇑(⟨f, h⟩ : r ↪r s) = f :=
rfl
/-- The map `coe_fn : (r ↪r s) → (α → β)` is injective. -/
theorem coe_fn_injective : Injective fun f : r ↪r s => (f : α → β) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : r ↪r s⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
/-- Identity map is a relation embedding. -/
@[refl, simps!]
protected def refl (r : α → α → Prop) : r ↪r r :=
⟨Embedding.refl _, Iff.rfl⟩
/-- Composition of two relation embeddings is a relation embedding. -/
protected def trans (f : r ↪r s) (g : s ↪r t) : r ↪r t :=
⟨f.1.trans g.1, by simp [f.map_rel_iff, g.map_rel_iff]⟩
instance (r : α → α → Prop) : Inhabited (r ↪r r) :=
⟨RelEmbedding.refl _⟩
theorem trans_apply (f : r ↪r s) (g : s ↪r t) (a : α) : (f.trans g) a = g (f a) :=
rfl
@[simp]
theorem coe_trans (f : r ↪r s) (g : s ↪r t) : (f.trans g) = g ∘ f :=
rfl
/-- A relation embedding is also a relation embedding between dual relations. -/
protected def swap (f : r ↪r s) : swap r ↪r swap s :=
⟨f.toEmbedding, f.map_rel_iff⟩
/-- If `f` is injective, then it is a relation embedding from the
preimage relation of `s` to `s`. -/
def preimage (f : α ↪ β) (s : β → β → Prop) : f ⁻¹'o s ↪r s :=
⟨f, Iff.rfl⟩
theorem eq_preimage (f : r ↪r s) : r = f ⁻¹'o s := by
ext a b
exact f.map_rel_iff.symm
protected theorem isIrrefl (f : r ↪r s) [IsIrrefl β s] : IsIrrefl α r :=
⟨fun a => mt f.map_rel_iff.2 (irrefl (f a))⟩
protected theorem isRefl (f : r ↪r s) [IsRefl β s] : IsRefl α r :=
⟨fun _ => f.map_rel_iff.1 <| refl _⟩
protected theorem isSymm (f : r ↪r s) [IsSymm β s] : IsSymm α r :=
⟨fun _ _ => imp_imp_imp f.map_rel_iff.2 f.map_rel_iff.1 symm⟩
protected theorem isAsymm (f : r ↪r s) [IsAsymm β s] : IsAsymm α r :=
⟨fun _ _ h₁ h₂ => asymm (f.map_rel_iff.2 h₁) (f.map_rel_iff.2 h₂)⟩
protected theorem isAntisymm : ∀ (_ : r ↪r s) [IsAntisymm β s], IsAntisymm α r
| ⟨f, o⟩, ⟨H⟩ => ⟨fun _ _ h₁ h₂ => f.inj' (H _ _ (o.2 h₁) (o.2 h₂))⟩
protected theorem isTrans : ∀ (_ : r ↪r s) [IsTrans β s], IsTrans α r
| ⟨_, o⟩, ⟨H⟩ => ⟨fun _ _ _ h₁ h₂ => o.1 (H _ _ _ (o.2 h₁) (o.2 h₂))⟩
protected theorem isTotal : ∀ (_ : r ↪r s) [IsTotal β s], IsTotal α r
| ⟨_, o⟩, ⟨H⟩ => ⟨fun _ _ => (or_congr o o).1 (H _ _)⟩
protected theorem isPreorder : ∀ (_ : r ↪r s) [IsPreorder β s], IsPreorder α r
| f, _ => { f.isRefl, f.isTrans with }
protected theorem isPartialOrder : ∀ (_ : r ↪r s) [IsPartialOrder β s], IsPartialOrder α r
| f, _ => { f.isPreorder, f.isAntisymm with }
protected theorem isLinearOrder : ∀ (_ : r ↪r s) [IsLinearOrder β s], IsLinearOrder α r
| f, _ => { f.isPartialOrder, f.isTotal with }
protected theorem isStrictOrder : ∀ (_ : r ↪r s) [IsStrictOrder β s], IsStrictOrder α r
| f, _ => { f.isIrrefl, f.isTrans with }
protected theorem isTrichotomous : ∀ (_ : r ↪r s) [IsTrichotomous β s], IsTrichotomous α r
| ⟨f, o⟩, ⟨H⟩ => ⟨fun _ _ => (or_congr o (or_congr f.inj'.eq_iff o)).1 (H _ _)⟩
protected theorem isStrictTotalOrder : ∀ (_ : r ↪r s) [IsStrictTotalOrder β s],
IsStrictTotalOrder α r
| f, _ => { f.isTrichotomous, f.isStrictOrder with }
protected theorem acc (f : r ↪r s) (a : α) : Acc s (f a) → Acc r a := by
generalize h : f a = b
intro ac
induction' ac with _ H IH generalizing a
subst h
exact ⟨_, fun a' h => IH (f a') (f.map_rel_iff.2 h) _ rfl⟩
protected theorem wellFounded : ∀ (_ : r ↪r s) (_ : WellFounded s), WellFounded r
| f, ⟨H⟩ => ⟨fun _ => f.acc _ (H _)⟩
protected theorem isWellFounded (f : r ↪r s) [IsWellFounded β s] : IsWellFounded α r :=
⟨f.wellFounded IsWellFounded.wf⟩
protected theorem isWellOrder : ∀ (_ : r ↪r s) [IsWellOrder β s], IsWellOrder α r
| f, H => { f.isStrictTotalOrder with wf := f.wellFounded H.wf }
end RelEmbedding
instance Subtype.wellFoundedLT [LT α] [WellFoundedLT α] (p : α → Prop) :
WellFoundedLT (Subtype p) :=
(Subtype.relEmbedding (· < ·) p).isWellFounded
instance Subtype.wellFoundedGT [LT α] [WellFoundedGT α] (p : α → Prop) :
WellFoundedGT (Subtype p) :=
(Subtype.relEmbedding (· > ·) p).isWellFounded
/-- `Quotient.mk'` as a relation homomorphism between the relation and the lift of a relation. -/
@[simps]
def Quotient.mkRelHom [Setoid α] {r : α → α → Prop}
(H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂) : r →r Quotient.lift₂ r H :=
⟨@Quotient.mk' α _, id⟩
/-- `Quotient.out` as a relation embedding between the lift of a relation and the relation. -/
@[simps!]
noncomputable def Quotient.outRelEmbedding [Setoid α] {r : α → α → Prop}
(H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂) : Quotient.lift₂ r H ↪r r :=
⟨Embedding.quotientOut α, by
refine @fun x y => Quotient.inductionOn₂ x y fun a b => ?_
apply iff_iff_eq.2 (H _ _ _ _ _ _) <;> apply Quotient.mk_out⟩
/-- `Quotient.out'` as a relation embedding between the lift of a relation and the relation. -/
@[simps]
noncomputable def Quotient.out'RelEmbedding {_ : Setoid α} {r : α → α → Prop}
(H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂) :
(fun a b => Quotient.liftOn₂' a b r H) ↪r r :=
{ Quotient.outRelEmbedding H with toFun := Quotient.out' }
@[simp]
theorem acc_lift₂_iff [Setoid α] {r : α → α → Prop}
{H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂} {a} :
Acc (Quotient.lift₂ r H) ⟦a⟧ ↔ Acc r a := by
constructor
· exact RelHomClass.acc (Quotient.mkRelHom H) a
· intro ac
induction' ac with _ _ IH
refine ⟨_, fun q h => ?_⟩
obtain ⟨a', rfl⟩ := q.exists_rep
exact IH a' h
@[simp]
theorem acc_liftOn₂'_iff {s : Setoid α} {r : α → α → Prop} {H} {a} :
Acc (fun x y => Quotient.liftOn₂' x y r H) (Quotient.mk'' a : Quotient s) ↔ Acc r a :=
acc_lift₂_iff (H := H)
/-- A relation is well founded iff its lift to a quotient is. -/
@[simp]
theorem wellFounded_lift₂_iff [Setoid α] {r : α → α → Prop}
{H : ∀ (a₁ b₁ a₂ b₂ : α), a₁ ≈ a₂ → b₁ ≈ b₂ → r a₁ b₁ = r a₂ b₂} :
WellFounded (Quotient.lift₂ r H) ↔ WellFounded r := by
constructor
· exact RelHomClass.wellFounded (Quotient.mkRelHom H)
· refine fun wf => ⟨fun q => ?_⟩
obtain ⟨a, rfl⟩ := q.exists_rep
exact acc_lift₂_iff.2 (wf.apply a)
alias ⟨WellFounded.of_quotient_lift₂, WellFounded.quotient_lift₂⟩ := wellFounded_lift₂_iff
@[simp]
theorem wellFounded_liftOn₂'_iff {s : Setoid α} {r : α → α → Prop} {H} :
(WellFounded fun x y : Quotient s => Quotient.liftOn₂' x y r H) ↔ WellFounded r :=
wellFounded_lift₂_iff (H := H)
alias ⟨WellFounded.of_quotient_liftOn₂', WellFounded.quotient_liftOn₂'⟩ := wellFounded_liftOn₂'_iff
namespace RelEmbedding
/-- To define a relation embedding from an antisymmetric relation `r` to a reflexive relation `s`
it suffices to give a function together with a proof that it satisfies `s (f a) (f b) ↔ r a b`.
-/
def ofMapRelIff (f : α → β) [IsAntisymm α r] [IsRefl β s] (hf : ∀ a b, s (f a) (f b) ↔ r a b) :
r ↪r s where
toFun := f
inj' _ _ h := antisymm ((hf _ _).1 (h ▸ refl _)) ((hf _ _).1 (h ▸ refl _))
map_rel_iff' := hf _ _
@[simp]
theorem ofMapRelIff_coe (f : α → β) [IsAntisymm α r] [IsRefl β s]
(hf : ∀ a b, s (f a) (f b) ↔ r a b) :
(ofMapRelIff f hf : r ↪r s) = f :=
rfl
/-- It suffices to prove `f` is monotone between strict relations
to show it is a relation embedding. -/
def ofMonotone [IsTrichotomous α r] [IsAsymm β s] (f : α → β) (H : ∀ a b, r a b → s (f a) (f b)) :
r ↪r s := by
haveI := @IsAsymm.isIrrefl β s _
refine ⟨⟨f, fun a b e => ?_⟩, @fun a b => ⟨fun h => ?_, H _ _⟩⟩
· refine ((@trichotomous _ r _ a b).resolve_left ?_).resolve_right ?_
· exact fun h => irrefl (r := s) (f a) (by simpa [e] using H _ _ h)
· exact fun h => irrefl (r := s) (f b) (by simpa [e] using H _ _ h)
· refine (@trichotomous _ r _ a b).resolve_right (Or.rec (fun e => ?_) fun h' => ?_)
· subst e
exact irrefl _ h
· exact asymm (H _ _ h') h
@[simp]
theorem ofMonotone_coe [IsTrichotomous α r] [IsAsymm β s] (f : α → β) (H) :
(@ofMonotone _ _ r s _ _ f H : α → β) = f :=
rfl
/-- A relation embedding from an empty type. -/
def ofIsEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] : r ↪r s :=
⟨Embedding.ofIsEmpty, @fun a => isEmptyElim a⟩
/-- `Sum.inl` as a relation embedding into `Sum.LiftRel r s`. -/
@[simps]
def sumLiftRelInl (r : α → α → Prop) (s : β → β → Prop) : r ↪r Sum.LiftRel r s where
toFun := Sum.inl
inj' := Sum.inl_injective
map_rel_iff' := Sum.liftRel_inl_inl
/-- `Sum.inr` as a relation embedding into `Sum.LiftRel r s`. -/
@[simps]
def sumLiftRelInr (r : α → α → Prop) (s : β → β → Prop) : s ↪r Sum.LiftRel r s where
toFun := Sum.inr
inj' := Sum.inr_injective
map_rel_iff' := Sum.liftRel_inr_inr
/-- `Sum.map` as a relation embedding between `Sum.LiftRel` relations. -/
@[simps]
def sumLiftRelMap (f : r ↪r s) (g : t ↪r u) : Sum.LiftRel r t ↪r Sum.LiftRel s u where
toFun := Sum.map f g
inj' := f.injective.sum_map g.injective
map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff]
/-- `Sum.inl` as a relation embedding into `Sum.Lex r s`. -/
@[simps]
def sumLexInl (r : α → α → Prop) (s : β → β → Prop) : r ↪r Sum.Lex r s where
toFun := Sum.inl
inj' := Sum.inl_injective
map_rel_iff' := Sum.lex_inl_inl
/-- `Sum.inr` as a relation embedding into `Sum.Lex r s`. -/
@[simps]
def sumLexInr (r : α → α → Prop) (s : β → β → Prop) : s ↪r Sum.Lex r s where
toFun := Sum.inr
inj' := Sum.inr_injective
map_rel_iff' := Sum.lex_inr_inr
/-- `Sum.map` as a relation embedding between `Sum.Lex` relations. -/
@[simps]
def sumLexMap (f : r ↪r s) (g : t ↪r u) : Sum.Lex r t ↪r Sum.Lex s u where
toFun := Sum.map f g
inj' := f.injective.sum_map g.injective
map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff]
/-- `fun b ↦ Prod.mk a b` as a relation embedding. -/
@[simps]
def prodLexMkLeft (s : β → β → Prop) {a : α} (h : ¬r a a) : s ↪r Prod.Lex r s where
toFun := Prod.mk a
inj' := Prod.mk.inj_left a
map_rel_iff' := by simp [Prod.lex_def, h]
/-- `fun a ↦ Prod.mk a b` as a relation embedding. -/
@[simps]
def prodLexMkRight (r : α → α → Prop) {b : β} (h : ¬s b b) : r ↪r Prod.Lex r s where
toFun a := (a, b)
inj' := Prod.mk.inj_right b
map_rel_iff' := by simp [Prod.lex_def, h]
/-- `Prod.map` as a relation embedding. -/
@[simps]
def prodLexMap (f : r ↪r s) (g : t ↪r u) : Prod.Lex r t ↪r Prod.Lex s u where
toFun := Prod.map f g
inj' := f.injective.prodMap g.injective
map_rel_iff' := by simp [Prod.lex_def, f.map_rel_iff, g.map_rel_iff, f.inj]
end RelEmbedding
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
structure RelIso {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ≃ β where
/-- Elements are related iff they are related after apply a `RelIso` -/
map_rel_iff' : ∀ {a b}, s (toEquiv a) (toEquiv b) ↔ r a b
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
infixl:25 " ≃r " => RelIso
namespace RelIso
/-- Convert a `RelIso` to a `RelEmbedding`. This function is also available as a coercion
but often it is easier to write `f.toRelEmbedding` than to write explicitly `r` and `s`
in the target type. -/
def toRelEmbedding (f : r ≃r s) : r ↪r s :=
⟨f.toEquiv.toEmbedding, f.map_rel_iff'⟩
theorem toEquiv_injective : Injective (toEquiv : r ≃r s → α ≃ β)
| ⟨e₁, o₁⟩, ⟨e₂, _⟩, h => by congr
instance : CoeOut (r ≃r s) (r ↪r s) :=
⟨toRelEmbedding⟩
-- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined
instance : FunLike (r ≃r s) α β where
coe := fun x => x
coe_injective' := Equiv.coe_fn_injective.comp toEquiv_injective
-- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined
instance : RelHomClass (r ≃r s) r s where
map_rel f _ _ := Iff.mpr (map_rel_iff' f)
instance : EquivLike (r ≃r s) α β where
coe f := f
inv f := f.toEquiv.symm
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' _ _ hf _ := DFunLike.ext' hf
@[simp]
theorem coe_toRelEmbedding (f : r ≃r s) : (f.toRelEmbedding : α → β) = f :=
rfl
@[simp]
theorem coe_toEmbedding (f : r ≃r s) : (f.toEmbedding : α → β) = f :=
rfl
theorem map_rel_iff (f : r ≃r s) {a b} : s (f a) (f b) ↔ r a b :=
f.map_rel_iff'
@[simp]
theorem coe_fn_mk (f : α ≃ β) (o : ∀ ⦃a b⦄, s (f a) (f b) ↔ r a b) :
(RelIso.mk f @o : α → β) = f :=
rfl
@[simp]
theorem coe_fn_toEquiv (f : r ≃r s) : (f.toEquiv : α → β) = f :=
rfl
/-- The map `coe_fn : (r ≃r s) → (α → β)` is injective. Lean fails to parse
`Function.Injective (fun e : r ≃r s ↦ (e : α → β))`, so we use a trick to say the same. -/
theorem coe_fn_injective : Injective fun f : r ≃r s => (f : α → β) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : r ≃r s⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
/-- Inverse map of a relation isomorphism is a relation isomorphism. -/
protected def symm (f : r ≃r s) : s ≃r r :=
⟨f.toEquiv.symm, @fun a b => by erw [← f.map_rel_iff, f.1.apply_symm_apply, f.1.apply_symm_apply]⟩
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because `RelIso` defines custom coercions other than the ones given by `DFunLike`. -/
def Simps.apply (h : r ≃r s) : α → β :=
h
/-- See Note [custom simps projection]. -/
def Simps.symm_apply (h : r ≃r s) : β → α :=
h.symm
initialize_simps_projections RelIso (toFun → apply, invFun → symm_apply)
/-- Identity map is a relation isomorphism. -/
@[refl, simps! apply]
protected def refl (r : α → α → Prop) : r ≃r r :=
⟨Equiv.refl _, Iff.rfl⟩
/-- Composition of two relation isomorphisms is a relation isomorphism. -/
@[simps! apply]
protected def trans (f₁ : r ≃r s) (f₂ : s ≃r t) : r ≃r t :=
⟨f₁.toEquiv.trans f₂.toEquiv, f₂.map_rel_iff.trans f₁.map_rel_iff⟩
instance (r : α → α → Prop) : Inhabited (r ≃r r) :=
⟨RelIso.refl _⟩
@[simp]
theorem default_def (r : α → α → Prop) : default = RelIso.refl r :=
rfl
/-- A relation isomorphism between equal relations on equal types. -/
@[simps! toEquiv apply]
protected def cast {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} (h₁ : α = β)
(h₂ : HEq r s) : r ≃r s :=
⟨Equiv.cast h₁, @fun a b => by
subst h₁
rw [eq_of_heq h₂]
rfl⟩
@[simp]
protected theorem cast_symm {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} (h₁ : α = β)
(h₂ : HEq r s) : (RelIso.cast h₁ h₂).symm = RelIso.cast h₁.symm h₂.symm :=
rfl
@[simp]
protected theorem cast_refl {α : Type u} {r : α → α → Prop} (h₁ : α = α := rfl)
(h₂ : HEq r r := HEq.rfl) : RelIso.cast h₁ h₂ = RelIso.refl r :=
rfl
@[simp]
protected theorem cast_trans {α β γ : Type u} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop} (h₁ : α = β) (h₁' : β = γ) (h₂ : HEq r s) (h₂' : HEq s t) :
(RelIso.cast h₁ h₂).trans (RelIso.cast h₁' h₂') = RelIso.cast (h₁.trans h₁') (h₂.trans h₂') :=
ext fun x => by subst h₁; rfl
/-- a relation isomorphism is also a relation isomorphism between dual relations. -/
protected def swap (f : r ≃r s) : swap r ≃r swap s :=
⟨f.toEquiv, f.map_rel_iff⟩
@[simp]
theorem coe_fn_symm_mk (f o) : ((@RelIso.mk _ _ r s f @o).symm : β → α) = f.symm :=
rfl
@[simp]
theorem apply_symm_apply (e : r ≃r s) (x : β) : e (e.symm x) = x :=
e.toEquiv.apply_symm_apply x
@[simp]
theorem symm_apply_apply (e : r ≃r s) (x : α) : e.symm (e x) = x :=
e.toEquiv.symm_apply_apply x
theorem rel_symm_apply (e : r ≃r s) {x y} : r x (e.symm y) ↔ s (e x) y := by
rw [← e.map_rel_iff, e.apply_symm_apply]
theorem symm_apply_rel (e : r ≃r s) {x y} : r (e.symm x) y ↔ s x (e y) := by
rw [← e.map_rel_iff, e.apply_symm_apply]
@[simp]
theorem self_trans_symm (e : r ≃r s) : e.trans e.symm = RelIso.refl r :=
ext e.symm_apply_apply
@[simp]
theorem symm_trans_self (e : r ≃r s) : e.symm.trans e = RelIso.refl s :=
ext e.apply_symm_apply
protected theorem bijective (e : r ≃r s) : Bijective e :=
e.toEquiv.bijective
protected theorem injective (e : r ≃r s) : Injective e :=
e.toEquiv.injective
protected theorem surjective (e : r ≃r s) : Surjective e :=
e.toEquiv.surjective
theorem eq_iff_eq (f : r ≃r s) {a b} : f a = f b ↔ a = b :=
f.injective.eq_iff
/-- Any equivalence lifts to a relation isomorphism between `s` and its preimage. -/
protected def preimage (f : α ≃ β) (s : β → β → Prop) : f ⁻¹'o s ≃r s :=
⟨f, Iff.rfl⟩
instance IsWellOrder.preimage {α : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) :
IsWellOrder β (f ⁻¹'o r) :=
@RelEmbedding.isWellOrder _ _ (f ⁻¹'o r) r (RelIso.preimage f r) _
instance IsWellOrder.ulift {α : Type u} (r : α → α → Prop) [IsWellOrder α r] :
IsWellOrder (ULift α) (ULift.down ⁻¹'o r) :=
IsWellOrder.preimage r Equiv.ulift
/-- A surjective relation embedding is a relation isomorphism. -/
@[simps! apply]
noncomputable def ofSurjective (f : r ↪r s) (H : Surjective f) : r ≃r s :=
⟨Equiv.ofBijective f ⟨f.injective, H⟩, f.map_rel_iff⟩
/-- Given relation isomorphisms `r₁ ≃r s₁` and `r₂ ≃r s₂`, construct a relation isomorphism for the
lexicographic orders on the sum.
-/
def sumLexCongr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @RelIso α₁ β₁ r₁ s₁) (e₂ : @RelIso α₂ β₂ r₂ s₂) :
Sum.Lex r₁ r₂ ≃r Sum.Lex s₁ s₂ :=
⟨Equiv.sumCongr e₁.toEquiv e₂.toEquiv, @fun a b => by
cases' e₁ with f hf; cases' e₂ with g hg; cases a <;> cases b <;> simp [hf, hg]⟩
/-- Given relation isomorphisms `r₁ ≃r s₁` and `r₂ ≃r s₂`, construct a relation isomorphism for the
lexicographic orders on the product.
-/
def prodLexCongr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂} (e₁ : @RelIso α₁ β₁ r₁ s₁) (e₂ : @RelIso α₂ β₂ r₂ s₂) :
Prod.Lex r₁ r₂ ≃r Prod.Lex s₁ s₂ :=
⟨Equiv.prodCongr e₁.toEquiv e₂.toEquiv, by simp [Prod.lex_def, e₁.map_rel_iff, e₂.map_rel_iff,
e₁.injective.eq_iff]⟩
/-- Two relations on empty types are isomorphic. -/
def relIsoOfIsEmpty (r : α → α → Prop) (s : β → β → Prop) [IsEmpty α] [IsEmpty β] : r ≃r s :=
⟨Equiv.equivOfIsEmpty α β, @fun a => isEmptyElim a⟩
/-- Two irreflexive relations on a unique type are isomorphic. -/
def relIsoOfUniqueOfIrrefl (r : α → α → Prop) (s : β → β → Prop) [IsIrrefl α r]
[IsIrrefl β s] [Unique α] [Unique β] : r ≃r s :=
⟨Equiv.equivOfUnique α β, iff_of_false (not_rel_of_subsingleton s _ _)
(not_rel_of_subsingleton r _ _) ⟩
/-- Two reflexive relations on a unique type are isomorphic. -/
def relIsoOfUniqueOfRefl (r : α → α → Prop) (s : β → β → Prop) [IsRefl α r] [IsRefl β s]
[Unique α] [Unique β] : r ≃r s :=
⟨Equiv.equivOfUnique α β, iff_of_true (rel_of_subsingleton s _ _) (rel_of_subsingleton r _ _)⟩
end RelIso
|
Order\RelIso\Group.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Order.RelIso.Basic
/-!
# Relation isomorphisms form a group
-/
variable {α : Type*} {r : α → α → Prop}
namespace RelIso
instance : Group (r ≃r r) where
one := RelIso.refl r
mul f₁ f₂ := f₂.trans f₁
inv := RelIso.symm
mul_assoc f₁ f₂ f₃ := rfl
one_mul f := ext fun _ => rfl
mul_one f := ext fun _ => rfl
mul_left_inv f := ext f.symm_apply_apply
@[simp]
theorem coe_one : ((1 : r ≃r r) : α → α) = id :=
rfl
@[simp]
theorem coe_mul (e₁ e₂ : r ≃r r) : ((e₁ * e₂) : α → α) = e₁ ∘ e₂ :=
rfl
theorem mul_apply (e₁ e₂ : r ≃r r) (x : α) : (e₁ * e₂) x = e₁ (e₂ x) :=
rfl
@[simp]
theorem inv_apply_self (e : r ≃r r) (x) : e⁻¹ (e x) = x :=
e.symm_apply_apply x
@[simp]
theorem apply_inv_self (e : r ≃r r) (x) : e (e⁻¹ x) = x :=
e.apply_symm_apply x
end RelIso
|
Order\RelIso\Set.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Order.RelIso.Basic
import Mathlib.Logic.Embedding.Set
import Mathlib.Logic.Equiv.Set
/-!
# Interactions between relation homomorphisms and sets
It is likely that there are better homes for many of these statement,
in files further down the import graph.
-/
open Function
universe u v w
variable {α β γ δ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
{u : δ → δ → Prop}
namespace RelHomClass
variable {F : Type*}
theorem map_inf [SemilatticeInf α] [LinearOrder β] [FunLike F β α]
[RelHomClass F (· < ·) (· < ·)] (a : F) (m n : β) :
a (m ⊓ n) = a m ⊓ a n :=
(StrictMono.monotone fun _ _ => map_rel a).map_inf m n
theorem map_sup [SemilatticeSup α] [LinearOrder β] [FunLike F β α]
[RelHomClass F (· > ·) (· > ·)] (a : F) (m n : β) :
a (m ⊔ n) = a m ⊔ a n :=
map_inf (α := αᵒᵈ) (β := βᵒᵈ) _ _ _
end RelHomClass
namespace RelIso
@[simp]
theorem range_eq (e : r ≃r s) : Set.range e = Set.univ :=
e.surjective.range_eq
end RelIso
/-- `Subrel r p` is the inherited relation on a subset. -/
def Subrel (r : α → α → Prop) (p : Set α) : p → p → Prop :=
(Subtype.val : p → α) ⁻¹'o r
@[simp]
theorem subrel_val (r : α → α → Prop) (p : Set α) {a b} : Subrel r p a b ↔ r a.1 b.1 :=
Iff.rfl
namespace Subrel
/-- The relation embedding from the inherited relation on a subset. -/
protected def relEmbedding (r : α → α → Prop) (p : Set α) : Subrel r p ↪r r :=
⟨Embedding.subtype _, Iff.rfl⟩
@[simp]
theorem relEmbedding_apply (r : α → α → Prop) (p a) : Subrel.relEmbedding r p a = a.1 :=
rfl
instance (r : α → α → Prop) [IsWellOrder α r] (p : Set α) : IsWellOrder p (Subrel r p) :=
RelEmbedding.isWellOrder (Subrel.relEmbedding r p)
instance (r : α → α → Prop) [IsRefl α r] (p : Set α) : IsRefl p (Subrel r p) :=
⟨fun x => @IsRefl.refl α r _ x⟩
instance (r : α → α → Prop) [IsSymm α r] (p : Set α) : IsSymm p (Subrel r p) :=
⟨fun x y => @IsSymm.symm α r _ x y⟩
instance (r : α → α → Prop) [IsTrans α r] (p : Set α) : IsTrans p (Subrel r p) :=
⟨fun x y z => @IsTrans.trans α r _ x y z⟩
instance (r : α → α → Prop) [IsIrrefl α r] (p : Set α) : IsIrrefl p (Subrel r p) :=
⟨fun x => @IsIrrefl.irrefl α r _ x⟩
end Subrel
/-- Restrict the codomain of a relation embedding. -/
def RelEmbedding.codRestrict (p : Set β) (f : r ↪r s) (H : ∀ a, f a ∈ p) : r ↪r Subrel s p :=
⟨f.toEmbedding.codRestrict p H, f.map_rel_iff'⟩
@[simp]
theorem RelEmbedding.codRestrict_apply (p) (f : r ↪r s) (H a) :
RelEmbedding.codRestrict p f H a = ⟨f a, H a⟩ :=
rfl
section image
variable {α β : Type*} {r : α → α → Prop} {s : β → β → Prop}
theorem RelIso.image_eq_preimage_symm (e : r ≃r s) (t : Set α) : e '' t = e.symm ⁻¹' t :=
e.toEquiv.image_eq_preimage t
theorem RelIso.preimage_eq_image_symm (e : r ≃r s) (t : Set β) : e ⁻¹' t = e.symm '' t := by
rw [e.symm.image_eq_preimage_symm]; rfl
end image
|
Order\SuccPred\Basic.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.CompleteLattice
import Mathlib.Order.Cover
import Mathlib.Order.GaloisConnection
import Mathlib.Order.Iterate
import Mathlib.Order.WellFounded
/-!
# Successor and predecessor
This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is
the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples
include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor
order...
## Typeclasses
* `SuccOrder`: Order equipped with a sensible successor function.
* `PredOrder`: Order equipped with a sensible predecessor function.
* `IsSuccArchimedean`: `SuccOrder` where `succ` iterated to an element gives all the greater
ones.
* `IsPredArchimedean`: `PredOrder` where `pred` iterated to an element gives all the smaller
ones.
## Implementation notes
Maximal elements don't have a sensible successor. Thus the naïve typeclass
```lean
class NaiveSuccOrder (α : Type*) [Preorder α] :=
(succ : α → α)
(succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b)
(lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b)
```
can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and
`lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`).
The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a`
for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of
`max_of_succ_le`).
The stricter condition of every element having a sensible successor can be obtained through the
combination of `SuccOrder α` and `NoMaxOrder α`.
-/
open Function OrderDual Set
variable {α β : Type*}
/-- Order equipped with a sensible successor function. -/
@[ext]
class SuccOrder (α : Type*) [Preorder α] where
/-- Successor function-/
succ : α → α
/-- Proof of basic ordering with respect to `succ`-/
le_succ : ∀ a, a ≤ succ a
/-- Proof of interaction between `succ` and maximal element-/
max_of_succ_le {a} : succ a ≤ a → IsMax a
/-- Proof that `succ` satisfies ordering invariants between `LT` and `LE`-/
succ_le_of_lt {a b} : a < b → succ a ≤ b
/-- Proof that `succ` satisfies ordering invariants between `LE` and `LT`-/
le_of_lt_succ {a b} : a < succ b → a ≤ b
/-- Order equipped with a sensible predecessor function. -/
@[ext]
class PredOrder (α : Type*) [Preorder α] where
/-- Predecessor function-/
pred : α → α
/-- Proof of basic ordering with respect to `pred`-/
pred_le : ∀ a, pred a ≤ a
/-- Proof of interaction between `pred` and minimal element-/
min_of_le_pred {a} : a ≤ pred a → IsMin a
/-- Proof that `pred` satisfies ordering invariants between `LT` and `LE`-/
le_pred_of_lt {a b} : a < b → a ≤ pred b
/-- Proof that `pred` satisfies ordering invariants between `LE` and `LT`-/
le_of_pred_lt {a b} : pred a < b → a ≤ b
instance [Preorder α] [SuccOrder α] :
PredOrder αᵒᵈ where
pred := toDual ∘ SuccOrder.succ ∘ ofDual
pred_le := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
SuccOrder.le_succ, implies_true]
min_of_le_pred h := by apply SuccOrder.max_of_succ_le h
le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h
le_of_pred_lt := SuccOrder.le_of_lt_succ
instance [Preorder α] [PredOrder α] :
SuccOrder αᵒᵈ where
succ := toDual ∘ PredOrder.pred ∘ ofDual
le_succ := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
PredOrder.pred_le, implies_true]
max_of_succ_le h := by apply PredOrder.min_of_le_pred h
succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h
le_of_lt_succ := PredOrder.le_of_pred_lt
section Preorder
variable [Preorder α]
/-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/
def SuccOrder.ofSuccLeIffOfLeLtSucc (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b)
(hle_of_lt_succ : ∀ {a b}, a < succ b → a ≤ b) : SuccOrder α :=
{ succ
le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le
max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim
succ_le_of_lt := fun h => hsucc_le_iff.2 h
le_of_lt_succ := fun h => hle_of_lt_succ h}
/-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/
def PredOrder.ofLePredIffOfPredLePred (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b)
(hle_of_pred_lt : ∀ {a b}, pred a < b → a ≤ b) : PredOrder α :=
{ pred
pred_le := fun _ => (hle_pred_iff.1 le_rfl).le
min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim
le_pred_of_lt := fun h => hle_pred_iff.2 h
le_of_pred_lt := fun h => hle_of_pred_lt h }
end Preorder
section LinearOrder
variable [LinearOrder α]
/-- A constructor for `SuccOrder α` for `α` a linear order. -/
@[simps]
def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b)
(hm : ∀ a, IsMax a → succ a = a) : SuccOrder α :=
{ succ
succ_le_of_lt := fun {a b} =>
by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp
le_succ := fun a =>
by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not
le_of_lt_succ := fun {a b} hab =>
by_cases (fun h => hm b h ▸ hab.le) fun h => by simpa [hab] using (hn h a).not
max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
/-- A constructor for `PredOrder α` for `α` a linear order. -/
@[simps]
def PredOrder.ofCore {α} [LinearOrder α] (pred : α → α)
(hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) :
PredOrder α :=
{ pred
le_pred_of_lt := fun {a b} =>
by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr
pred_le := fun a =>
by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not
le_of_pred_lt := fun {a b} hab =>
by_cases (fun h => hm a h ▸ hab.le) fun h => by simpa [hab] using (hn h b).not
min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
/-- A constructor for `SuccOrder α` usable when `α` is a linear order with no maximal element. -/
def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) :
SuccOrder α :=
{ succ
le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le
max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim
succ_le_of_lt := fun h => hsucc_le_iff.2 h
le_of_lt_succ := fun {_ _} h => le_of_not_lt ((not_congr hsucc_le_iff).1 h.not_le) }
/-- A constructor for `PredOrder α` usable when `α` is a linear order with no minimal element. -/
def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) :
PredOrder α :=
{ pred
pred_le := fun _ => (hle_pred_iff.1 le_rfl).le
min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim
le_pred_of_lt := fun h => hle_pred_iff.2 h
le_of_pred_lt := fun {_ _} h => le_of_not_lt ((not_congr hle_pred_iff).1 h.not_le) }
open scoped Classical
variable (α)
/-- A well-order is a `SuccOrder`. -/
noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α :=
ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a)
(fun ha _ ↦ by
rw [not_isMax_iff] at ha
simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha]
exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩)
fun a ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·)
/-- A linear order with well-founded greater-than relation is a `PredOrder`. -/
noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] :
PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ)
end LinearOrder
/-! ### Successor order -/
namespace Order
section Preorder
variable [Preorder α] [SuccOrder α] {a b : α}
/-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater
than `a`. If `a` is maximal, then `succ a = a`. -/
def succ : α → α :=
SuccOrder.succ
theorem le_succ : ∀ a : α, a ≤ succ a :=
SuccOrder.le_succ
theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a :=
SuccOrder.max_of_succ_le
theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b :=
SuccOrder.succ_le_of_lt
alias _root_.LT.lt.succ_le := succ_le_of_lt
theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b :=
SuccOrder.le_of_lt_succ
@[simp]
theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a :=
⟨max_of_succ_le, fun h => h <| le_succ _⟩
alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax
@[simp]
theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a :=
⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩
alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax
theorem wcovBy_succ (a : α) : a ⩿ succ a :=
⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩
theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a :=
(wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h
theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a :=
⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩
theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b :=
⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩
lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b :=
(lt_succ_iff_of_not_isMax hb).2 <| succ_le_of_lt h
theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a < succ b ↔ a < b := by
rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha]
theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a ≤ succ b ↔ a ≤ b := by
rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb]
@[simp, mono]
theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by
by_cases hb : IsMax b
· by_cases hba : b ≤ a
· exact (hb <| hba.trans <| le_succ _).trans (le_succ _)
· exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b)
· rwa [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h, lt_succ_iff_of_not_isMax hb]
theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ
/-- See also `Order.succ_eq_of_covBy`. -/
lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by
obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le
· by_contra hba
exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) $ hab.lt.succ_le.lt_of_not_le hba
· exact hba.trans (le_succ _)
alias _root_.WCovBy.le_succ := le_succ_of_wcovBy
theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := by
conv_lhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)]
exact Monotone.le_iterate_of_le succ_mono le_succ k x
theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a)
(h_lt : n < m) : IsMax (succ^[n] a) := by
refine max_of_succ_le (le_trans ?_ h_eq.symm.le)
have : succ (succ^[n] a) = succ^[n + 1] a := by rw [Function.iterate_succ', comp]
rw [this]
have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt
exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le
theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a)
(h_ne : n ≠ m) : IsMax (succ^[n] a) := by
rcases le_total n m with h | h
· exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne)
· rw [h_eq]
exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm)
theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a :=
Set.ext fun _ => lt_succ_iff_of_not_isMax ha
theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a :=
Set.ext fun _ => succ_le_iff_of_not_isMax ha
theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by
rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic]
theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by
rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic]
theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by
rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic]
theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by
rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio]
section NoMaxOrder
variable [NoMaxOrder α]
theorem lt_succ (a : α) : a < succ a :=
lt_succ_of_not_isMax <| not_isMax a
@[simp]
theorem lt_succ_iff : a < succ b ↔ a ≤ b :=
lt_succ_iff_of_not_isMax <| not_isMax b
@[simp]
theorem succ_le_iff : succ a ≤ b ↔ a < b :=
succ_le_iff_of_not_isMax <| not_isMax a
theorem succ_le_succ_iff : succ a ≤ succ b ↔ a ≤ b := by simp
theorem succ_lt_succ_iff : succ a < succ b ↔ a < b := by simp
alias ⟨le_of_succ_le_succ, _⟩ := succ_le_succ_iff
alias ⟨lt_of_succ_lt_succ, succ_lt_succ⟩ := succ_lt_succ_iff
theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ
theorem covBy_succ (a : α) : a ⋖ succ a :=
covBy_succ_of_not_isMax <| not_isMax a
@[simp]
theorem Iio_succ (a : α) : Iio (succ a) = Iic a :=
Iio_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Ici_succ (a : α) : Ici (succ a) = Ioi a :=
Ici_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_right (a b : α) : Ico a (succ b) = Icc a b :=
Ico_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Ioo_succ_right (a b : α) : Ioo a (succ b) = Ioc a b :=
Ioo_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b :=
Icc_succ_left_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b :=
Ico_succ_left_of_not_isMax <| not_isMax _
end NoMaxOrder
end Preorder
section PartialOrder
variable [PartialOrder α] [SuccOrder α] {a b : α}
@[simp]
theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a :=
⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩
alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax
theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) :
succ a = succ b ↔ a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb,
succ_lt_succ_iff_of_not_isMax ha hb]
theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by
refine
⟨fun h =>
or_iff_not_imp_left.2 fun hba : b ≠ a =>
h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm),
?_⟩
rintro (rfl | rfl)
· exact ⟨le_rfl, le_succ b⟩
· exact ⟨le_succ a, le_rfl⟩
/-- See also `Order.le_succ_of_wcovBy`. -/
lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ
alias _root_.CovBy.succ_eq := succ_eq_of_covBy
theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by
by_cases hb : IsMax b
· rw [hb.succ_eq, or_iff_right_of_imp le_of_eq]
· rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt]
theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b :=
(lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
theorem Iic_succ (a : α) : Iic (succ a) = insert (succ a) (Iic a) :=
ext fun _ => le_succ_iff_eq_or_le
theorem Icc_succ_right (h : a ≤ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by
simp_rw [← Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)]
theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by
simp_rw [← Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)]
theorem Iio_succ_eq_insert_of_not_isMax (h : ¬IsMax a) : Iio (succ a) = insert a (Iio a) :=
ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h
theorem Ico_succ_right_eq_insert_of_not_isMax (h₁ : a ≤ b) (h₂ : ¬IsMax b) :
Ico a (succ b) = insert b (Ico a b) := by
simp_rw [← Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ici.2 h₁)]
theorem Ioo_succ_right_eq_insert_of_not_isMax (h₁ : a < b) (h₂ : ¬IsMax b) :
Ioo a (succ b) = insert b (Ioo a b) := by
simp_rw [← Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax h₂, insert_inter_of_mem (mem_Ioi.2 h₁)]
section NoMaxOrder
variable [NoMaxOrder α]
@[simp]
theorem succ_eq_succ_iff : succ a = succ b ↔ a = b :=
succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b)
theorem succ_injective : Injective (succ : α → α) := fun _ _ => succ_eq_succ_iff.1
theorem succ_ne_succ_iff : succ a ≠ succ b ↔ a ≠ b :=
succ_injective.ne_iff
alias ⟨_, succ_ne_succ⟩ := succ_ne_succ_iff
theorem lt_succ_iff_eq_or_lt : a < succ b ↔ a = b ∨ a < b :=
lt_succ_iff.trans le_iff_eq_or_lt
theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b :=
⟨by
rintro rfl
exact covBy_succ _, CovBy.succ_eq⟩
theorem Iio_succ_eq_insert (a : α) : Iio (succ a) = insert a (Iio a) :=
Iio_succ_eq_insert_of_not_isMax <| not_isMax a
theorem Ico_succ_right_eq_insert (h : a ≤ b) : Ico a (succ b) = insert b (Ico a b) :=
Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b
theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) :=
Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b
end NoMaxOrder
section OrderTop
variable [OrderTop α]
@[simp]
theorem succ_top : succ (⊤ : α) = ⊤ := by
rw [succ_eq_iff_isMax, isMax_iff_eq_top]
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ :=
succ_le_iff_isMax.trans isMax_iff_eq_top
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ :=
lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top
end OrderTop
section OrderBot
variable [OrderBot α]
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem lt_succ_bot_iff [NoMaxOrder α] : a < succ ⊥ ↔ a = ⊥ := by rw [lt_succ_iff, le_bot_iff]
theorem le_succ_bot_iff : a ≤ succ ⊥ ↔ a = ⊥ ∨ a = succ ⊥ := by
rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm]
variable [Nontrivial α]
theorem bot_lt_succ (a : α) : ⊥ < succ a :=
(lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le
theorem succ_ne_bot (a : α) : succ a ≠ ⊥ :=
(bot_lt_succ a).ne'
end OrderBot
end PartialOrder
/-- There is at most one way to define the successors in a `PartialOrder`. -/
instance [PartialOrder α] : Subsingleton (SuccOrder α) :=
⟨by
intro h₀ h₁
ext a
by_cases ha : IsMax a
· exact (@IsMax.succ_eq _ _ h₀ _ ha).trans ha.succ_eq.symm
· exact @CovBy.succ_eq _ _ h₀ _ _ (covBy_succ_of_not_isMax ha)⟩
section CompleteLattice
variable [CompleteLattice α] [SuccOrder α]
theorem succ_eq_iInf (a : α) : succ a = ⨅ (b) (_ : a < b), b := by
refine le_antisymm (le_iInf fun b => le_iInf succ_le_of_lt) ?_
obtain rfl | ha := eq_or_ne a ⊤
· rw [succ_top]
exact le_top
exact iInf₂_le _ (lt_succ_iff_ne_top.2 ha)
end CompleteLattice
/-! ### Predecessor order -/
section Preorder
variable [Preorder α] [PredOrder α] {a b : α}
/-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less
than `a`. If `a` is minimal, then `pred a = a`. -/
def pred : α → α :=
PredOrder.pred
theorem pred_le : ∀ a : α, pred a ≤ a :=
PredOrder.pred_le
theorem min_of_le_pred {a : α} : a ≤ pred a → IsMin a :=
PredOrder.min_of_le_pred
theorem le_pred_of_lt {a b : α} : a < b → a ≤ pred b :=
PredOrder.le_pred_of_lt
alias _root_.LT.lt.le_pred := le_pred_of_lt
theorem le_of_pred_lt {a b : α} : pred a < b → a ≤ b :=
PredOrder.le_of_pred_lt
@[simp]
theorem le_pred_iff_isMin : a ≤ pred a ↔ IsMin a :=
⟨min_of_le_pred, fun h => h <| pred_le _⟩
alias ⟨_root_.IsMin.of_le_pred, _root_.IsMin.le_pred⟩ := le_pred_iff_isMin
@[simp]
theorem pred_lt_iff_not_isMin : pred a < a ↔ ¬IsMin a :=
⟨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_le fun h => ha <| min_of_le_pred h⟩
alias ⟨_, pred_lt_of_not_isMin⟩ := pred_lt_iff_not_isMin
theorem pred_wcovBy (a : α) : pred a ⩿ a :=
⟨pred_le a, fun _ hb => (le_of_pred_lt hb).not_lt⟩
theorem pred_covBy_of_not_isMin (h : ¬IsMin a) : pred a ⋖ a :=
(pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h
theorem pred_lt_iff_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a ≤ b :=
⟨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_le⟩
theorem le_pred_iff_of_not_isMin (ha : ¬IsMin a) : b ≤ pred a ↔ b < a :=
⟨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_lt⟩
lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : ¬ IsMin a) : pred a < pred b :=
(pred_lt_iff_of_not_isMin ha).2 <| le_pred_of_lt h
theorem pred_lt_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a < pred b ↔ a < b := by
rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb]
theorem pred_le_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a ≤ pred b ↔ a ≤ b := by
rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha]
@[simp, mono]
theorem pred_le_pred {a b : α} (h : a ≤ b) : pred a ≤ pred b :=
succ_le_succ h.dual
theorem pred_mono : Monotone (pred : α → α) := fun _ _ => pred_le_pred
/-- See also `Order.pred_eq_of_covBy`. -/
lemma pred_le_of_wcovBy (h : a ⩿ b) : pred b ≤ a := by
obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le
· by_contra hba
exact h.2 (hab.lt.le_pred.lt_of_not_le hba) (pred_lt_of_not_isMin hab.lt.not_isMin)
· exact (pred_le _).trans hba
alias _root_.WCovBy.pred_le := pred_le_of_wcovBy
theorem pred_iterate_le (k : ℕ) (x : α) : pred^[k] x ≤ x := by
conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)]
exact Monotone.iterate_le_of_le pred_mono pred_le k x
theorem isMin_iterate_pred_of_eq_of_lt {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a)
(h_lt : n < m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_lt αᵒᵈ _ _ _ _ _ h_eq h_lt
theorem isMin_iterate_pred_of_eq_of_ne {n m : ℕ} (h_eq : pred^[n] a = pred^[m] a)
(h_ne : n ≠ m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_ne αᵒᵈ _ _ _ _ _ h_eq h_ne
theorem Ioi_pred_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = Ici a :=
Set.ext fun _ => pred_lt_iff_of_not_isMin ha
theorem Iic_pred_of_not_isMin (ha : ¬IsMin a) : Iic (pred a) = Iio a :=
Set.ext fun _ => le_pred_iff_of_not_isMin ha
theorem Ioc_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioc (pred a) b = Icc a b := by
rw [← Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic]
theorem Ioo_pred_left_of_not_isMin (ha : ¬IsMin a) : Ioo (pred a) b = Ico a b := by
rw [← Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio]
theorem Icc_pred_right_of_not_isMin (ha : ¬IsMin b) : Icc a (pred b) = Ico a b := by
rw [← Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio]
theorem Ioc_pred_right_of_not_isMin (ha : ¬IsMin b) : Ioc a (pred b) = Ioo a b := by
rw [← Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio]
section NoMinOrder
variable [NoMinOrder α]
theorem pred_lt (a : α) : pred a < a :=
pred_lt_of_not_isMin <| not_isMin a
@[simp]
theorem pred_lt_iff : pred a < b ↔ a ≤ b :=
pred_lt_iff_of_not_isMin <| not_isMin a
@[simp]
theorem le_pred_iff : a ≤ pred b ↔ a < b :=
le_pred_iff_of_not_isMin <| not_isMin b
theorem pred_le_pred_iff : pred a ≤ pred b ↔ a ≤ b := by simp
theorem pred_lt_pred_iff : pred a < pred b ↔ a < b := by simp
alias ⟨le_of_pred_le_pred, _⟩ := pred_le_pred_iff
alias ⟨lt_of_pred_lt_pred, pred_lt_pred⟩ := pred_lt_pred_iff
theorem pred_strictMono : StrictMono (pred : α → α) := fun _ _ => pred_lt_pred
theorem pred_covBy (a : α) : pred a ⋖ a :=
pred_covBy_of_not_isMin <| not_isMin a
@[simp]
theorem Ioi_pred (a : α) : Ioi (pred a) = Ici a :=
Ioi_pred_of_not_isMin <| not_isMin a
@[simp]
theorem Iic_pred (a : α) : Iic (pred a) = Iio a :=
Iic_pred_of_not_isMin <| not_isMin a
@[simp]
theorem Ioc_pred_left (a b : α) : Ioc (pred a) b = Icc a b :=
Ioc_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Ioo_pred_left (a b : α) : Ioo (pred a) b = Ico a b :=
Ioo_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Icc_pred_right (a b : α) : Icc a (pred b) = Ico a b :=
Icc_pred_right_of_not_isMin <| not_isMin _
@[simp]
theorem Ioc_pred_right (a b : α) : Ioc a (pred b) = Ioo a b :=
Ioc_pred_right_of_not_isMin <| not_isMin _
end NoMinOrder
end Preorder
section PartialOrder
variable [PartialOrder α] [PredOrder α] {a b : α}
@[simp]
theorem pred_eq_iff_isMin : pred a = a ↔ IsMin a :=
⟨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _⟩
alias ⟨_, _root_.IsMin.pred_eq⟩ := pred_eq_iff_isMin
theorem pred_eq_pred_iff_of_not_isMin (ha : ¬IsMin a) (hb : ¬IsMin b) :
pred a = pred b ↔ a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, pred_le_pred_iff_of_not_isMin ha hb,
pred_lt_pred_iff_of_not_isMin ha hb]
theorem pred_le_le_iff {a b : α} : pred a ≤ b ∧ b ≤ a ↔ b = a ∨ b = pred a := by
refine
⟨fun h =>
or_iff_not_imp_left.2 fun hba : b ≠ a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_⟩
rintro (rfl | rfl)
· exact ⟨pred_le b, le_rfl⟩
· exact ⟨le_rfl, pred_le a⟩
/-- See also `Order.pred_le_of_wcovBy`. -/
lemma pred_eq_of_covBy (h : a ⋖ b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt)
alias _root_.CovBy.pred_eq := pred_eq_of_covBy
theorem pred_le_iff_eq_or_le : pred a ≤ b ↔ b = pred a ∨ a ≤ b := by
by_cases ha : IsMin a
· rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq]
· rw [← pred_lt_iff_of_not_isMin ha, le_iff_eq_or_lt, eq_comm]
theorem pred_lt_iff_eq_or_lt_of_not_isMin (ha : ¬IsMin a) : pred a < b ↔ a = b ∨ a < b :=
(pred_lt_iff_of_not_isMin ha).trans le_iff_eq_or_lt
theorem Ici_pred (a : α) : Ici (pred a) = insert (pred a) (Ici a) :=
ext fun _ => pred_le_iff_eq_or_le
theorem Ioi_pred_eq_insert_of_not_isMin (ha : ¬IsMin a) : Ioi (pred a) = insert a (Ioi a) := by
ext x; simp only [insert, mem_setOf, @eq_comm _ x a, mem_Ioi, Set.insert]
exact pred_lt_iff_eq_or_lt_of_not_isMin ha
theorem Icc_pred_left (h : pred a ≤ b) : Icc (pred a) b = insert (pred a) (Icc a b) := by
simp_rw [← Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)]
theorem Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) := by
simp_rw [← Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)]
section NoMinOrder
variable [NoMinOrder α]
@[simp]
theorem pred_eq_pred_iff : pred a = pred b ↔ a = b := by
simp_rw [eq_iff_le_not_lt, pred_le_pred_iff, pred_lt_pred_iff]
theorem pred_injective : Injective (pred : α → α) := fun _ _ => pred_eq_pred_iff.1
theorem pred_ne_pred_iff : pred a ≠ pred b ↔ a ≠ b :=
pred_injective.ne_iff
alias ⟨_, pred_ne_pred⟩ := pred_ne_pred_iff
theorem pred_lt_iff_eq_or_lt : pred a < b ↔ a = b ∨ a < b :=
pred_lt_iff.trans le_iff_eq_or_lt
theorem pred_eq_iff_covBy : pred b = a ↔ a ⋖ b :=
⟨by
rintro rfl
exact pred_covBy _, CovBy.pred_eq⟩
theorem Ioi_pred_eq_insert (a : α) : Ioi (pred a) = insert a (Ioi a) :=
ext fun _ => pred_lt_iff_eq_or_lt.trans <| or_congr_left eq_comm
theorem Ico_pred_right_eq_insert (h : a ≤ b) : Ioc (pred a) b = insert a (Ioc a b) := by
simp_rw [← Ioi_inter_Iic, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iic.2 h)]
theorem Ioo_pred_right_eq_insert (h : a < b) : Ioo (pred a) b = insert a (Ioo a b) := by
simp_rw [← Ioi_inter_Iio, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iio.2 h)]
end NoMinOrder
section OrderBot
variable [OrderBot α]
@[simp]
theorem pred_bot : pred (⊥ : α) = ⊥ :=
isMin_bot.pred_eq
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem le_pred_iff_eq_bot : a ≤ pred a ↔ a = ⊥ :=
@succ_le_iff_eq_top αᵒᵈ _ _ _ _
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem pred_lt_iff_ne_bot : pred a < a ↔ a ≠ ⊥ :=
@lt_succ_iff_ne_top αᵒᵈ _ _ _ _
end OrderBot
section OrderTop
variable [OrderTop α]
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem pred_top_lt_iff [NoMinOrder α] : pred ⊤ < a ↔ a = ⊤ :=
@lt_succ_bot_iff αᵒᵈ _ _ _ _ _
theorem pred_top_le_iff : pred ⊤ ≤ a ↔ a = ⊤ ∨ a = pred ⊤ :=
@le_succ_bot_iff αᵒᵈ _ _ _ _
variable [Nontrivial α]
theorem pred_lt_top (a : α) : pred a < ⊤ :=
(pred_mono le_top).trans_lt <| pred_lt_of_not_isMin not_isMin_top
theorem pred_ne_top (a : α) : pred a ≠ ⊤ :=
(pred_lt_top a).ne
end OrderTop
end PartialOrder
/-- There is at most one way to define the predecessors in a `PartialOrder`. -/
instance [PartialOrder α] : Subsingleton (PredOrder α) :=
⟨by
intro h₀ h₁
ext a
by_cases ha : IsMin a
· exact (@IsMin.pred_eq _ _ h₀ _ ha).trans ha.pred_eq.symm
· exact @CovBy.pred_eq _ _ h₀ _ _ (pred_covBy_of_not_isMin ha)⟩
section CompleteLattice
variable [CompleteLattice α] [PredOrder α]
theorem pred_eq_iSup (a : α) : pred a = ⨆ (b) (_ : b < a), b := by
refine le_antisymm ?_ (iSup_le fun b => iSup_le le_pred_of_lt)
obtain rfl | ha := eq_or_ne a ⊥
· rw [pred_bot]
exact bot_le
· exact @le_iSup₂ _ _ (fun b => b < a) _ (fun a _ => a) (pred a) (pred_lt_iff_ne_bot.2 ha)
end CompleteLattice
/-! ### Successor-predecessor orders -/
section SuccPredOrder
section Preorder
variable [Preorder α] [SuccOrder α] [PredOrder α] {a b : α}
lemma le_succ_pred (a : α) : a ≤ succ (pred a) := (pred_wcovBy _).le_succ
lemma pred_succ_le (a : α) : pred (succ a) ≤ a := (wcovBy_succ _).pred_le
lemma pred_le_iff_le_succ : pred a ≤ b ↔ a ≤ succ b where
mp hab := (le_succ_pred _).trans (succ_mono hab)
mpr hab := (pred_mono hab).trans (pred_succ_le _)
lemma gc_pred_succ : GaloisConnection (pred : α → α) succ := fun _ _ ↦ pred_le_iff_le_succ
end Preorder
variable [PartialOrder α] [SuccOrder α] [PredOrder α] {a b : α}
@[simp]
theorem succ_pred_of_not_isMin (h : ¬IsMin a) : succ (pred a) = a :=
CovBy.succ_eq (pred_covBy_of_not_isMin h)
@[simp]
theorem pred_succ_of_not_isMax (h : ¬IsMax a) : pred (succ a) = a :=
CovBy.pred_eq (covBy_succ_of_not_isMax h)
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem succ_pred [NoMinOrder α] (a : α) : succ (pred a) = a :=
CovBy.succ_eq (pred_covBy _)
-- Porting note (#10618): removing @[simp],`simp` can prove it
theorem pred_succ [NoMaxOrder α] (a : α) : pred (succ a) = a :=
CovBy.pred_eq (covBy_succ _)
theorem pred_succ_iterate_of_not_isMax (i : α) (n : ℕ) (hin : ¬IsMax (succ^[n - 1] i)) :
pred^[n] (succ^[n] i) = i := by
induction' n with n hn
· simp only [Nat.zero_eq, Function.iterate_zero, id]
rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hin
have h_not_max : ¬IsMax (succ^[n - 1] i) := by
cases' n with n
· simpa using hin
rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hn ⊢
have h_sub_le : succ^[n] i ≤ succ^[n.succ] i := by
rw [Function.iterate_succ']
exact le_succ _
refine fun h_max => hin fun j hj => ?_
have hj_le : j ≤ succ^[n] i := h_max (h_sub_le.trans hj)
exact hj_le.trans h_sub_le
rw [Function.iterate_succ, Function.iterate_succ']
simp only [Function.comp_apply]
rw [pred_succ_of_not_isMax hin]
exact hn h_not_max
theorem succ_pred_iterate_of_not_isMin (i : α) (n : ℕ) (hin : ¬IsMin (pred^[n - 1] i)) :
succ^[n] (pred^[n] i) = i :=
@pred_succ_iterate_of_not_isMax αᵒᵈ _ _ _ i n hin
end SuccPredOrder
end Order
open Order
/-! ### `WithBot`, `WithTop`
Adding a greatest/least element to a `SuccOrder` or to a `PredOrder`.
As far as successors and predecessors are concerned, there are four ways to add a bottom or top
element to an order:
* Adding a `⊤` to an `OrderTop`: Preserves `succ` and `pred`.
* Adding a `⊤` to a `NoMaxOrder`: Preserves `succ`. Never preserves `pred`.
* Adding a `⊥` to an `OrderBot`: Preserves `succ` and `pred`.
* Adding a `⊥` to a `NoMinOrder`: Preserves `pred`. Never preserves `succ`.
where "preserves `(succ/pred)`" means
`(Succ/Pred)Order α → (Succ/Pred)Order ((WithTop/WithBot) α)`.
-/
namespace WithTop
/-! #### Adding a `⊤` to an `OrderTop` -/
section Succ
variable [DecidableEq α] [PartialOrder α] [OrderTop α] [SuccOrder α]
instance : SuccOrder (WithTop α) where
succ a :=
match a with
| ⊤ => ⊤
| Option.some a => ite (a = ⊤) ⊤ (some (succ a))
le_succ a := by
cases' a with a a
· exact le_top
change _ ≤ ite _ _ _
split_ifs
· exact le_top
· exact coe_le_coe.2 (le_succ a)
max_of_succ_le {a} ha := by
cases a
· exact isMax_top
dsimp only at ha
split_ifs at ha with ha'
· exact (not_top_le_coe _ ha).elim
· rw [coe_le_coe, succ_le_iff_eq_top] at ha
exact (ha' ha).elim
succ_le_of_lt {a b} h := by
cases b
· exact le_top
cases a
· exact (not_top_lt h).elim
rw [coe_lt_coe] at h
change ite _ _ _ ≤ _
split_ifs with ha
· rw [ha] at h
exact (not_top_lt h).elim
· exact coe_le_coe.2 (succ_le_of_lt h)
le_of_lt_succ {a b} h := by
cases a
· exact (not_top_lt h).elim
cases b
· exact le_top
dsimp only at h
rw [coe_le_coe]
split_ifs at h with hb
· rw [hb]
exact le_top
· exact le_of_lt_succ (coe_lt_coe.1 h)
@[simp]
theorem succ_coe_top : succ ↑(⊤ : α) = (⊤ : WithTop α) :=
dif_pos rfl
theorem succ_coe_of_ne_top {a : α} (h : a ≠ ⊤) : succ (↑a : WithTop α) = ↑(succ a) :=
dif_neg h
end Succ
section Pred
variable [Preorder α] [OrderTop α] [PredOrder α]
instance : PredOrder (WithTop α) where
pred a :=
match a with
| ⊤ => some ⊤
| Option.some a => some (pred a)
pred_le a :=
match a with
| ⊤ => le_top
| Option.some a => coe_le_coe.2 (pred_le a)
min_of_le_pred {a} ha := by
cases a
· exact ((coe_lt_top (⊤ : α)).not_le ha).elim
· exact (min_of_le_pred <| coe_le_coe.1 ha).withTop
le_pred_of_lt {a b} h := by
cases a
· exact (le_top.not_lt h).elim
cases b
· exact coe_le_coe.2 le_top
exact coe_le_coe.2 (le_pred_of_lt <| coe_lt_coe.1 h)
le_of_pred_lt {a b} h := by
cases b
· exact le_top
cases a
· exact (not_top_lt <| coe_lt_coe.1 h).elim
· exact coe_le_coe.2 (le_of_pred_lt <| coe_lt_coe.1 h)
@[simp]
theorem pred_top : pred (⊤ : WithTop α) = ↑(⊤ : α) :=
rfl
@[simp]
theorem pred_coe (a : α) : pred (↑a : WithTop α) = ↑(pred a) :=
rfl
@[simp]
theorem pred_untop :
∀ (a : WithTop α) (ha : a ≠ ⊤),
pred (a.untop ha) = (pred a).untop (by induction a <;> simp)
| ⊤, ha => (ha rfl).elim
| (a : α), _ => rfl
end Pred
/-! #### Adding a `⊤` to a `NoMaxOrder` -/
section Succ
variable [Preorder α] [NoMaxOrder α] [SuccOrder α]
instance succOrderOfNoMaxOrder : SuccOrder (WithTop α) where
succ a :=
match a with
| ⊤ => ⊤
| Option.some a => some (succ a)
le_succ a := by
cases' a with a a
· exact le_top
· exact coe_le_coe.2 (le_succ a)
max_of_succ_le {a} ha := by
cases a
· exact isMax_top
· exact (not_isMax _ <| max_of_succ_le <| coe_le_coe.1 ha).elim
succ_le_of_lt {a b} h := by
cases a
· exact (not_top_lt h).elim
cases b
· exact le_top
· exact coe_le_coe.2 (succ_le_of_lt <| coe_lt_coe.1 h)
le_of_lt_succ {a b} h := by
cases a
· exact (not_top_lt h).elim
cases b
· exact le_top
· exact coe_le_coe.2 (le_of_lt_succ <| coe_lt_coe.1 h)
@[simp]
theorem succ_coe (a : α) : succ (↑a : WithTop α) = ↑(succ a) :=
rfl
end Succ
section Pred
variable [Preorder α] [NoMaxOrder α]
instance [hα : Nonempty α] : IsEmpty (PredOrder (WithTop α)) :=
⟨by
intro
cases' h : pred (⊤ : WithTop α) with a ha
· exact hα.elim fun a => (min_of_le_pred h.ge).not_lt <| coe_lt_top a
· obtain ⟨c, hc⟩ := exists_gt a
rw [← coe_lt_coe, ← h] at hc
exact (le_of_pred_lt hc).not_lt (coe_lt_top _)⟩
end Pred
end WithTop
namespace WithBot
/-! #### Adding a `⊥` to an `OrderBot` -/
section Succ
variable [Preorder α] [OrderBot α] [SuccOrder α]
instance : SuccOrder (WithBot α) where
succ a :=
match a with
| ⊥ => some ⊥
| Option.some a => some (succ a)
le_succ a :=
match a with
| ⊥ => bot_le
| Option.some a => coe_le_coe.2 (le_succ a)
max_of_succ_le {a} ha := by
cases a
· exact ((bot_lt_coe (⊥ : α)).not_le ha).elim
· exact (max_of_succ_le <| coe_le_coe.1 ha).withBot
succ_le_of_lt {a b} h := by
cases b
· exact (not_lt_bot h).elim
cases a
· exact coe_le_coe.2 bot_le
· exact coe_le_coe.2 (succ_le_of_lt <| coe_lt_coe.1 h)
le_of_lt_succ {a b} h := by
cases a
· exact bot_le
cases b
· exact (not_lt_bot <| coe_lt_coe.1 h).elim
· exact coe_le_coe.2 (le_of_lt_succ <| coe_lt_coe.1 h)
@[simp]
theorem succ_bot : succ (⊥ : WithBot α) = ↑(⊥ : α) :=
rfl
@[simp]
theorem succ_coe (a : α) : succ (↑a : WithBot α) = ↑(succ a) :=
rfl
@[simp]
theorem succ_unbot :
∀ (a : WithBot α) (ha : a ≠ ⊥),
succ (a.unbot ha) = (succ a).unbot (by induction a <;> simp)
| ⊥, ha => (ha rfl).elim
| (a : α), _ => rfl
end Succ
section Pred
variable [DecidableEq α] [PartialOrder α] [OrderBot α] [PredOrder α]
instance : PredOrder (WithBot α) where
pred a :=
match a with
| ⊥ => ⊥
| Option.some a => ite (a = ⊥) ⊥ (some (pred a))
pred_le a := by
cases' a with a a
· exact bot_le
change ite _ _ _ ≤ _
split_ifs
· exact bot_le
· exact coe_le_coe.2 (pred_le a)
min_of_le_pred {a} ha := by
cases' a with a a
· exact isMin_bot
dsimp only at ha
split_ifs at ha with ha'
· exact (not_coe_le_bot _ ha).elim
· rw [coe_le_coe, le_pred_iff_eq_bot] at ha
exact (ha' ha).elim
le_pred_of_lt {a b} h := by
cases a
· exact bot_le
cases b
· exact (not_lt_bot h).elim
rw [coe_lt_coe] at h
change _ ≤ ite _ _ _
split_ifs with hb
· rw [hb] at h
exact (not_lt_bot h).elim
· exact coe_le_coe.2 (le_pred_of_lt h)
le_of_pred_lt {a b} h := by
cases b
· exact (not_lt_bot h).elim
cases a
· exact bot_le
dsimp only at h
rw [coe_le_coe]
split_ifs at h with ha
· rw [ha]
exact bot_le
· exact le_of_pred_lt (coe_lt_coe.1 h)
@[simp]
theorem pred_coe_bot : pred ↑(⊥ : α) = (⊥ : WithBot α) :=
dif_pos rfl
theorem pred_coe_of_ne_bot {a : α} (h : a ≠ ⊥) : pred (↑a : WithBot α) = ↑(pred a) :=
dif_neg h
end Pred
/-! #### Adding a `⊥` to a `NoMinOrder` -/
section Succ
variable [Preorder α] [NoMinOrder α]
instance [hα : Nonempty α] : IsEmpty (SuccOrder (WithBot α)) :=
⟨by
intro
cases' h : succ (⊥ : WithBot α) with a ha
· exact hα.elim fun a => (max_of_succ_le h.le).not_lt <| bot_lt_coe a
· obtain ⟨c, hc⟩ := exists_lt a
rw [← coe_lt_coe, ← h] at hc
exact (le_of_lt_succ hc).not_lt (bot_lt_coe _)⟩
end Succ
section Pred
variable [Preorder α] [NoMinOrder α] [PredOrder α]
instance predOrderOfNoMinOrder : PredOrder (WithBot α) where
pred a :=
match a with
| ⊥ => ⊥
| Option.some a => some (pred a)
pred_le a := by
cases' a with a a
· exact bot_le
· exact coe_le_coe.2 (pred_le a)
min_of_le_pred {a} ha := by
cases a
· exact isMin_bot
· exact (not_isMin _ <| min_of_le_pred <| coe_le_coe.1 ha).elim
le_pred_of_lt {a b} h := by
cases b
· exact (not_lt_bot h).elim
cases a
· exact bot_le
· exact coe_le_coe.2 (le_pred_of_lt <| coe_lt_coe.1 h)
le_of_pred_lt {a b} h := by
cases b
· exact (not_lt_bot h).elim
cases a
· exact bot_le
· exact coe_le_coe.2 (le_of_pred_lt <| coe_lt_coe.1 h)
@[simp]
theorem pred_coe (a : α) : pred (↑a : WithBot α) = ↑(pred a) :=
rfl
end Pred
end WithBot
/-! ### Archimedeanness -/
/-- A `SuccOrder` is succ-archimedean if one can go from any two comparable elements by iterating
`succ` -/
class IsSuccArchimedean (α : Type*) [Preorder α] [SuccOrder α] : Prop where
/-- If `a ≤ b` then one can get to `a` from `b` by iterating `succ` -/
exists_succ_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, succ^[n] a = b
/-- A `PredOrder` is pred-archimedean if one can go from any two comparable elements by iterating
`pred` -/
class IsPredArchimedean (α : Type*) [Preorder α] [PredOrder α] : Prop where
/-- If `a ≤ b` then one can get to `b` from `a` by iterating `pred` -/
exists_pred_iterate_of_le {a b : α} (h : a ≤ b) : ∃ n, pred^[n] b = a
export IsSuccArchimedean (exists_succ_iterate_of_le)
export IsPredArchimedean (exists_pred_iterate_of_le)
section Preorder
variable [Preorder α]
section SuccOrder
variable [SuccOrder α] [IsSuccArchimedean α] {a b : α}
instance : IsPredArchimedean αᵒᵈ :=
⟨fun {a b} h => by convert exists_succ_iterate_of_le h.ofDual⟩
theorem LE.le.exists_succ_iterate (h : a ≤ b) : ∃ n, succ^[n] a = b :=
exists_succ_iterate_of_le h
theorem exists_succ_iterate_iff_le : (∃ n, succ^[n] a = b) ↔ a ≤ b := by
refine ⟨?_, exists_succ_iterate_of_le⟩
rintro ⟨n, rfl⟩
exact id_le_iterate_of_id_le le_succ n a
/-- Induction principle on a type with a `SuccOrder` for all elements above a given element `m`. -/
@[elab_as_elim]
theorem Succ.rec {P : α → Prop} {m : α} (h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (succ n)) ⦃n : α⦄
(hmn : m ≤ n) : P n := by
obtain ⟨n, rfl⟩ := hmn.exists_succ_iterate; clear hmn
induction' n with n ih
· exact h0
· rw [Function.iterate_succ_apply']
exact h1 _ (id_le_iterate_of_id_le le_succ n m) ih
theorem Succ.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) {a b : α} (h : a ≤ b) :
p a ↔ p b := by
obtain ⟨n, rfl⟩ := h.exists_succ_iterate
exact Iterate.rec (fun b => p a ↔ p b) (fun c hc => hc.trans (hsucc _)) Iff.rfl n
end SuccOrder
section PredOrder
variable [PredOrder α] [IsPredArchimedean α] {a b : α}
instance : IsSuccArchimedean αᵒᵈ :=
⟨fun {a b} h => by convert exists_pred_iterate_of_le h.ofDual⟩
theorem LE.le.exists_pred_iterate (h : a ≤ b) : ∃ n, pred^[n] b = a :=
exists_pred_iterate_of_le h
theorem exists_pred_iterate_iff_le : (∃ n, pred^[n] b = a) ↔ a ≤ b :=
exists_succ_iterate_iff_le (α := αᵒᵈ)
/-- Induction principle on a type with a `PredOrder` for all elements below a given element `m`. -/
@[elab_as_elim]
theorem Pred.rec {P : α → Prop} {m : α} (h0 : P m) (h1 : ∀ n, n ≤ m → P n → P (pred n)) ⦃n : α⦄
(hmn : n ≤ m) : P n :=
Succ.rec (α := αᵒᵈ) (P := P) h0 h1 hmn
theorem Pred.rec_iff {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) {a b : α} (h : a ≤ b) :
p a ↔ p b :=
(Succ.rec_iff (α := αᵒᵈ) hsucc h).symm
end PredOrder
end Preorder
section LinearOrder
variable [LinearOrder α]
section SuccOrder
variable [SuccOrder α]
lemma succ_max (a b : α) : succ (max a b) = max (succ a) (succ b) := succ_mono.map_max
lemma succ_min (a b : α) : succ (min a b) = min (succ a) (succ b) := succ_mono.map_min
variable [IsSuccArchimedean α] {a b : α}
theorem exists_succ_iterate_or : (∃ n, succ^[n] a = b) ∨ ∃ n, succ^[n] b = a :=
(le_total a b).imp exists_succ_iterate_of_le exists_succ_iterate_of_le
theorem Succ.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (succ a)) (a b : α) : p a ↔ p b :=
(le_total a b).elim (Succ.rec_iff hsucc) fun h => (Succ.rec_iff hsucc h).symm
end SuccOrder
section PredOrder
variable [PredOrder α]
lemma pred_max (a b : α) : pred (max a b) = max (pred a) (pred b) := pred_mono.map_max
lemma pred_min (a b : α) : pred (min a b) = min (pred a) (pred b) := pred_mono.map_min
variable [IsPredArchimedean α] {a b : α}
theorem exists_pred_iterate_or : (∃ n, pred^[n] b = a) ∨ ∃ n, pred^[n] a = b :=
(le_total a b).imp exists_pred_iterate_of_le exists_pred_iterate_of_le
theorem Pred.rec_linear {p : α → Prop} (hsucc : ∀ a, p a ↔ p (pred a)) (a b : α) : p a ↔ p b :=
(le_total a b).elim (Pred.rec_iff hsucc) fun h => (Pred.rec_iff hsucc h).symm
end PredOrder
end LinearOrder
section bdd_range
variable [Preorder α] [Nonempty α] [Preorder β] {f : α → β}
lemma StrictMono.not_bddAbove_range [NoMaxOrder α] [SuccOrder β] [IsSuccArchimedean β]
(hf : StrictMono f) : ¬ BddAbove (Set.range f) := by
rintro ⟨m, hm⟩
have hm' : ∀ a, f a ≤ m := fun a ↦ hm <| Set.mem_range_self _
obtain ⟨a₀⟩ := ‹Nonempty α›
suffices ∀ b, f a₀ ≤ b → ∃ a, b < f a by
obtain ⟨a, ha⟩ : ∃ a, m < f a := this m (hm' a₀)
exact ha.not_le (hm' a)
have h : ∀ a, ∃ a', f a < f a' := fun a ↦ (exists_gt a).imp (fun a' h ↦ hf h)
apply Succ.rec
· exact h a₀
rintro b _ ⟨a, hba⟩
exact (h a).imp (fun a' ↦ (succ_le_of_lt hba).trans_lt)
lemma StrictMono.not_bddBelow_range [NoMinOrder α] [PredOrder β] [IsPredArchimedean β]
(hf : StrictMono f) : ¬ BddBelow (Set.range f) := hf.dual.not_bddAbove_range
lemma StrictAnti.not_bddAbove_range [NoMinOrder α] [SuccOrder β] [IsSuccArchimedean β]
(hf : StrictAnti f) : ¬ BddAbove (Set.range f) := hf.dual_right.not_bddBelow_range
lemma StrictAnti.not_bddBelow_range [NoMaxOrder α] [PredOrder β] [IsPredArchimedean β]
(hf : StrictAnti f) : ¬ BddBelow (Set.range f) := hf.dual_right.not_bddAbove_range
end bdd_range
section IsWellOrder
variable [LinearOrder α]
instance (priority := 100) IsWellOrder.toIsPredArchimedean [h : IsWellOrder α (· < ·)]
[PredOrder α] : IsPredArchimedean α :=
⟨fun {a b} => by
refine WellFounded.fix (C := fun b => a ≤ b → ∃ n, Nat.iterate pred n b = a)
h.wf ?_ b
intros b ih hab
replace hab := eq_or_lt_of_le hab
rcases hab with (rfl | hab)
· exact ⟨0, rfl⟩
rcases le_or_lt b (pred b) with hb | hb
· cases (min_of_le_pred hb).not_lt hab
dsimp at ih
obtain ⟨k, hk⟩ := ih (pred b) hb (le_pred_of_lt hab)
refine ⟨k + 1, ?_⟩
rw [iterate_add_apply, iterate_one, hk]⟩
instance (priority := 100) IsWellOrder.toIsSuccArchimedean [h : IsWellOrder α (· > ·)]
[SuccOrder α] : IsSuccArchimedean α :=
let h : IsPredArchimedean αᵒᵈ := by infer_instance
⟨h.1⟩
end IsWellOrder
section OrderBot
variable [Preorder α] [OrderBot α] [SuccOrder α] [IsSuccArchimedean α]
theorem Succ.rec_bot (p : α → Prop) (hbot : p ⊥) (hsucc : ∀ a, p a → p (succ a)) (a : α) : p a :=
Succ.rec hbot (fun x _ h => hsucc x h) (bot_le : ⊥ ≤ a)
end OrderBot
section OrderTop
variable [Preorder α] [OrderTop α] [PredOrder α] [IsPredArchimedean α]
theorem Pred.rec_top (p : α → Prop) (htop : p ⊤) (hpred : ∀ a, p a → p (pred a)) (a : α) : p a :=
Pred.rec htop (fun x _ h => hpred x h) (le_top : a ≤ ⊤)
end OrderTop
lemma SuccOrder.forall_ne_bot_iff
[Nontrivial α] [PartialOrder α] [OrderBot α] [SuccOrder α] [IsSuccArchimedean α]
(P : α → Prop) :
(∀ i, i ≠ ⊥ → P i) ↔ (∀ i, P (SuccOrder.succ i)) := by
refine ⟨fun h i ↦ h _ (Order.succ_ne_bot i), fun h i hi ↦ ?_⟩
obtain ⟨j, rfl⟩ := exists_succ_iterate_of_le (bot_le : ⊥ ≤ i)
have hj : 0 < j := by apply Nat.pos_of_ne_zero; contrapose! hi; simp [hi]
rw [← Nat.succ_pred_eq_of_pos hj]
simp only [Function.iterate_succ', Function.comp_apply]
apply h
|
Order\SuccPred\CompleteLinearOrder.lean | /-
Copyright (c) 2023 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Order.SuccPred.Limit
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Relation between `IsSuccLimit` and `iSup` in (conditionally) complete linear orders.
-/
open Order
variable {ι α : Type*}
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [Nonempty ι] {f : ι → α} {s : Set α} {x : α}
lemma csSup_mem_of_not_isSuccLimit
(hne : s.Nonempty) (hbdd : BddAbove s) (hlim : ¬ IsSuccLimit (sSup s)) :
sSup s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := exists_lt_of_lt_csSup hne hy.lt
exact eq_of_le_of_not_lt (le_csSup hbdd his) (hy.2 hi) ▸ his
lemma csInf_mem_of_not_isPredLimit
(hne : s.Nonempty) (hbdd : BddBelow s) (hlim : ¬ IsPredLimit (sInf s)) :
sInf s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := exists_lt_of_csInf_lt hne hy.lt
exact eq_of_le_of_not_lt (csInf_le hbdd his) (hy.2 · hi) ▸ his
lemma exists_eq_ciSup_of_not_isSuccLimit
(hf : BddAbove (Set.range f)) (hf' : ¬ IsSuccLimit (⨆ i, f i)) :
∃ i, f i = ⨆ i, f i :=
csSup_mem_of_not_isSuccLimit (Set.range_nonempty f) hf hf'
lemma exists_eq_ciInf_of_not_isPredLimit
(hf : BddBelow (Set.range f)) (hf' : ¬ IsPredLimit (⨅ i, f i)) :
∃ i, f i = ⨅ i, f i :=
csInf_mem_of_not_isPredLimit (Set.range_nonempty f) hf hf'
lemma IsLUB.mem_of_nonempty_of_not_isSuccLimit
(hs : IsLUB s x) (hne : s.Nonempty) (hx : ¬ IsSuccLimit x) : x ∈ s :=
hs.csSup_eq hne ▸ csSup_mem_of_not_isSuccLimit hne hs.bddAbove (hs.csSup_eq hne ▸ hx)
lemma IsGLB.mem_of_nonempty_of_not_isPredLimit
(hs : IsGLB s x) (hne : s.Nonempty) (hx : ¬ IsPredLimit x) : x ∈ s :=
hs.csInf_eq hne ▸ csInf_mem_of_not_isPredLimit hne hs.bddBelow (hs.csInf_eq hne ▸ hx)
lemma IsLUB.exists_of_nonempty_of_not_isSuccLimit
(hf : IsLUB (Set.range f) x) (hx : ¬ IsSuccLimit x) :
∃ i, f i = x := hf.mem_of_nonempty_of_not_isSuccLimit (Set.range_nonempty f) hx
lemma IsGLB.exists_of_nonempty_of_not_isPredLimit
(hf : IsGLB (Set.range f) x) (hx : ¬ IsPredLimit x) :
∃ i, f i = x := hf.mem_of_nonempty_of_not_isPredLimit (Set.range_nonempty f) hx
end ConditionallyCompleteLinearOrder
section ConditionallyCompleteLinearOrderBot
variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α} {s : Set α} {x : α}
/-- See `csSup_mem_of_not_isSuccLimit` for the `ConditionallyCompleteLinearOrder` version. -/
lemma csSup_mem_of_not_isSuccLimit'
(hbdd : BddAbove s) (hlim : ¬ IsSuccLimit (sSup s)) :
sSup s ∈ s := by
obtain (rfl|hs) := s.eq_empty_or_nonempty
· simp [isSuccLimit_bot] at hlim
· exact csSup_mem_of_not_isSuccLimit hs hbdd hlim
/-- See `exists_eq_ciSup_of_not_isSuccLimit` for the
`ConditionallyCompleteLinearOrder` version. -/
lemma exists_eq_ciSup_of_not_isSuccLimit'
(hf : BddAbove (Set.range f)) (hf' : ¬ IsSuccLimit (⨆ i, f i)) :
∃ i, f i = ⨆ i, f i :=
csSup_mem_of_not_isSuccLimit' hf hf'
lemma IsLUB.mem_of_not_isSuccLimit (hs : IsLUB s x) (hx : ¬ IsSuccLimit x) :
x ∈ s := by
obtain (rfl|hs') := s.eq_empty_or_nonempty
· simp [show x = ⊥ by simpa using hs, isSuccLimit_bot] at hx
· exact hs.mem_of_nonempty_of_not_isSuccLimit hs' hx
lemma IsLUB.exists_of_not_isSuccLimit (hf : IsLUB (Set.range f) x) (hx : ¬ IsSuccLimit x) :
∃ i, f i = x := hf.mem_of_not_isSuccLimit hx
end ConditionallyCompleteLinearOrderBot
section CompleteLinearOrder
variable [CompleteLinearOrder α] {s : Set α} {f : ι → α} {x : α}
lemma sSup_mem_of_not_isSuccLimit (hlim : ¬ IsSuccLimit (sSup s)) :
sSup s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := lt_sSup_iff.mp hy.lt
exact eq_of_le_of_not_lt (le_sSup his) (hy.2 hi) ▸ his
lemma sInf_mem_of_not_isPredLimit (hlim : ¬ IsPredLimit (sInf s)) :
sInf s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := sInf_lt_iff.mp hy.lt
exact eq_of_le_of_not_lt (sInf_le his) (hy.2 · hi) ▸ his
lemma exists_eq_iSup_of_not_isSuccLimit (hf : ¬ IsSuccLimit (⨆ i, f i)) :
∃ i, f i = ⨆ i, f i :=
sSup_mem_of_not_isSuccLimit hf
lemma exists_eq_iInf_of_not_isPredLimit (hf : ¬ IsPredLimit (⨅ i, f i)) :
∃ i, f i = ⨅ i, f i :=
sInf_mem_of_not_isPredLimit hf
lemma IsGLB.mem_of_not_isPredLimit (hs : IsGLB s x) (hx : ¬ IsPredLimit x) :
x ∈ s :=
hs.sInf_eq ▸ sInf_mem_of_not_isPredLimit (hs.sInf_eq ▸ hx)
lemma IsGLB.exists_of_not_isPredLimit (hf : IsGLB (Set.range f) x) (hx : ¬ IsPredLimit x) :
∃ i, f i = x := hf.mem_of_not_isPredLimit hx
end CompleteLinearOrder
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.