Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions Mathlib/Order/CompleteBooleanAlgebra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ whose `⊔` distributes over `⨅`. -/
@[to_dual]
class Order.Coframe (α : Type*) extends CompleteLattice α, CoheytingAlgebra α where

to_dual_for Order.Frame.le_himp_iff := sdiff_le_iff'
to_dual_for Order.Coframe.sdiff_le_iff := le_himp_iff'
to_dual_for Order.Frame.mk :=
{ sdiff_le_iff a b c := by
rw [le_himp_iff, sup_comm]
top_sdiff := himp_bot }
to_dual_for Order.Coframe.mk :=
{ le_himp_iff a b c := by
rw [sdiff_le_iff, inf_comm]
himp_bot := top_sdiff }

open Order

/-- `⊓` distributes over `⨆`. -/
Expand Down Expand Up @@ -108,6 +119,14 @@ distribute over `⨅` and `⨆`. -/
class CompleteDistribLattice (α : Type*) extends Frame α, Coframe α, BiheytingAlgebra α

attribute [to_dual existing] CompleteDistribLattice.toFrame
to_dual_for CompleteDistribLattice.toHNot := self.toCompl
to_dual_for CompleteDistribLattice.toSDiff := self.toHImp
to_dual_for CompleteDistribLattice.top_sdiff := self.himp_bot a
to_dual_for CompleteDistribLattice.sdiff_le_iff := le_himp_iff'
to_dual_for CompleteDistribLattice.mk :=
{ le_himp_iff a b c := by
rw [sdiff_le_iff, inf_comm]
himp_bot := top_sdiff }

/-- Structure containing the minimal axioms required to check that an order is a completely
distributive. Do NOT use, except for implementing `CompletelyDistribLattice` via
Expand Down Expand Up @@ -349,6 +368,7 @@ section Frame

variable [Frame α] {s t : Set α} {a b c d : α}

@[to_dual]
instance OrderDual.instCoframe : Coframe αᵒᵈ where
__ := instCompleteLattice
__ := instCoheytingAlgebra
Expand Down Expand Up @@ -466,10 +486,12 @@ instance (priority := 100) Order.Frame.toDistribLattice : DistribLattice α :=
DistribLattice.ofInfSupLe fun a b c => by
rw [← sSup_pair, ← sSup_pair, inf_sSup_eq, ← sSup_image, image_pair]

@[to_dual]
instance Prod.instFrame [Frame β] : Frame (α × β) where
__ := instCompleteLattice
__ := instHeytingAlgebra

@[to_dual]
instance Pi.instFrame {ι : Type*} {π : ι → Type*} [∀ i, Frame (π i)] : Frame (∀ i, π i) where
__ := instCompleteLattice
__ := instHeytingAlgebra
Expand Down Expand Up @@ -528,11 +550,6 @@ section Coframe

variable [Coframe α] {s t : Set α} {a b c d : α}

@[to_dual existing]
instance OrderDual.instFrame : Frame αᵒᵈ where
__ := instCompleteLattice
__ := instHeytingAlgebra

theorem sdiff_eq_sInf : a \ b = sInf {w | a ≤ b ⊔ w} :=
(isLeast_sdiff a b).isGLB.sInf_eq.symm

Expand All @@ -541,16 +558,6 @@ theorem hnot_eq_sInf_codisjoint : ¬a = sInf {w | Codisjoint a w} :=

lemma le_sdiff_iff : a ≤ b \ c ↔ ∀ d, b ≤ c ⊔ d → a ≤ d := by simp [sdiff_eq_sInf]

@[to_dual existing]
instance Prod.instCoframe [Coframe β] : Coframe (α × β) where
__ := instCompleteLattice
__ := instCoheytingAlgebra

@[to_dual existing]
instance Pi.instCoframe {ι : Type*} {π : ι → Type*} [∀ i, Coframe (π i)] : Coframe (∀ i, π i) where
__ := instCompleteLattice
__ := instCoheytingAlgebra

end Coframe

section CompleteDistribLattice
Expand Down
121 changes: 37 additions & 84 deletions Mathlib/Order/Heyting/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,30 @@ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, Orde
/-- `⊤ \ a` is `¬a` -/
top_sdiff (a : α) : ⊤ \ a = ¬a

to_dual_for GeneralizedHeytingAlgebra.le_himp_iff := by
rw [self.sdiff_le_iff, sup_comm]
to_dual_for GeneralizedCoheytingAlgebra.sdiff_le_iff := by
rw [self.le_himp_iff, inf_comm]
to_dual_for GeneralizedHeytingAlgebra.mk :=
{ sdiff_le_iff a b c := by
rw [le_himp_iff, sup_comm] }
to_dual_for GeneralizedCoheytingAlgebra.mk :=
{ le_himp_iff a b c := by
rw [sdiff_le_iff, inf_comm] }

/-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/
class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, CoheytingAlgebra α where

attribute [to_dual existing] BiheytingAlgebra.toHeytingAlgebra
to_dual_for BiheytingAlgebra.toHNot := self.toCompl
to_dual_for BiheytingAlgebra.toSDiff := self.toHImp
to_dual_for BiheytingAlgebra.top_sdiff := self.himp_bot a
to_dual_for BiheytingAlgebra.sdiff_le_iff := by
rw [self.le_himp_iff, inf_comm]
to_dual_for BiheytingAlgebra.mk :=
{ le_himp_iff a b c := by
rw [sdiff_le_iff, inf_comm]
himp_bot := top_sdiff }

-- See note [lower instance priority]
attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop
Expand All @@ -135,6 +155,8 @@ instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : B

-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/
@[to_dual
/-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/]
abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α)
(le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α :=
{ ‹DistribLattice α›, ‹BoundedOrder α› with
Expand All @@ -145,32 +167,15 @@ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α

-- See note [reducible non-instances]
/-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/
@[to_dual
/-- Construct a co-Heyting algebra from the lattice structure and co-Heyting negation 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 _ => 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
Expand All @@ -179,23 +184,17 @@ the same in this logic.
See also `Prop.heytingAlgebra`. -/
section GeneralizedHeytingAlgebra

@[simp low] -- low priority so that it doesn't overwrite user-provided simp lemmas
-- low priority so that it doesn't overwrite user-provided simp lemmas
@[to_dual le_himp_iff', simp low]
theorem sdiff_le_iff [GeneralizedCoheytingAlgebra α] {a b c : α} : a \ b ≤ c ↔ a ≤ b ⊔ c :=
GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _

theorem sdiff_le_iff' [GeneralizedCoheytingAlgebra α] {a b c : α} : a \ b ≤ c ↔ a ≤ c ⊔ b := by
rw [sdiff_le_iff, sup_comm]

variable [GeneralizedHeytingAlgebra α] {a b c d : α}

/-- `p → q → r ↔ p ∧ q → r` -/
@[to_dual existing sdiff_le_iff', simp]
theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
@[to_dual sdiff_le_iff', simp]
theorem le_himp_iff [GeneralizedHeytingAlgebra α] {a b c : α} : a ≤ b ⇨ c ↔ a ⊓ b ≤ c :=
GeneralizedHeytingAlgebra.le_himp_iff _ _ _

/-- `p → q → r ↔ q ∧ p → r` -/
@[to_dual existing sdiff_le_iff]
theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm]
variable [GeneralizedHeytingAlgebra α] {a b c d : α}

/-- `p → q → r ↔ q → p → r` -/
@[to_dual sdiff_le_comm]
Expand Down Expand Up @@ -353,14 +352,17 @@ instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribL
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

@[to_dual]
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

@[to_dual]
instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] :
GeneralizedHeytingAlgebra (α × β) where
le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff

@[to_dual]
instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] :
GeneralizedHeytingAlgebra (∀ i, α i) where
le_himp_iff i := by simp [le_def]
Expand Down Expand Up @@ -511,21 +513,6 @@ instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : Distri
le_sup_inf :=
fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl }

@[to_dual existing]
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

@[to_dual existing]
instance Prod.instGeneralizedCoheytingAlgebra [GeneralizedCoheytingAlgebra β] :
GeneralizedCoheytingAlgebra (α × β) where
sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff

@[to_dual existing]
instance Pi.instGeneralizedCoheytingAlgebra {α : ι → Type*}
[∀ i, GeneralizedCoheytingAlgebra (α i)] : GeneralizedCoheytingAlgebra (∀ i, α i) where
sdiff_le_iff i := by simp [le_def]

end GeneralizedCoheytingAlgebra

section HeytingAlgebra
Expand Down Expand Up @@ -707,19 +694,13 @@ theorem compl_compl_himp_distrib (a b : α) : (a ⇨ b)ᶜᶜ = aᶜᶜ ⇨ bᶜ
le_compl_iff_disjoint_right]
exact inf_himp_le

@[to_dual]
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 α _

@[to_dual existing]
instance OrderDual.instHeytingAlgebra {α : Type u_2} [CoheytingAlgebra α] : 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' α _

@[to_dual (attr := simp)]
theorem ofDual_hnot (a : αᵒᵈ) : ofDual (¬a) = (ofDual a)ᶜ :=
rfl
Expand All @@ -735,31 +716,17 @@ theorem toDual_compl (a : α) : toDual aᶜ = ¬toDual a :=
theorem toDual_himp (a b : α) : toDual (a ⇨ b) = toDual b \ toDual a :=
rfl

@[to_dual]
instance Prod.instHeytingAlgebra [HeytingAlgebra β] : HeytingAlgebra (α × β) where
himp_bot a := Prod.ext_iff.2 ⟨himp_bot a.1, himp_bot a.2⟩

@[to_dual]
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 : α}

@[to_dual existing]
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⟩

@[to_dual existing]
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 : α}
Expand Down Expand Up @@ -823,6 +790,8 @@ section lift

-- See note [reducible non-instances]
/-- Pullback a `GeneralizedHeytingAlgebra` along an injection. -/
@[to_dual (reorder := 3 4, le (x y), lt (x y), map_sup map_inf, map_himp (a b))
/-- Pullback a `GeneralizedCoheytingAlgebra` along an injection. -/]
protected abbrev Function.Injective.generalizedHeytingAlgebra [Max α] [Min α]
[LE α] [LT α] [Top α] [HImp α] [GeneralizedHeytingAlgebra β] (f : α → β) (hf : Injective f)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) (lt : ∀ {x y}, f x < f y ↔ x < y)
Expand All @@ -836,22 +805,6 @@ protected abbrev Function.Injective.generalizedHeytingAlgebra [Max α] [Min α]
le_himp_iff a b c := by
rw [← le, ← le, map_himp, map_inf, le_himp_iff]

-- See note [reducible non-instances]
/-- Pullback a `GeneralizedCoheytingAlgebra` along an injection. -/
@[to_dual existing (reorder := 3 4, le (x y), lt (x y), map_sup map_inf, map_sdiff (a b))]
protected abbrev Function.Injective.generalizedCoheytingAlgebra [Max α] [Min α]
[LE α] [LT α] [Bot α] [SDiff α] [GeneralizedCoheytingAlgebra β] (f : α → β) (hf : Injective f)
(le : ∀ {x y}, f x ≤ f y ↔ x ≤ y) (lt : ∀ {x y}, f x < f y ↔ x < y)
(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 α where
__ := hf.lattice f le lt map_sup map_inf
bot_le a := by
rw [← le, map_bot]
exact bot_le
sdiff_le_iff a b c := by
rw [← le, ← le, map_sdiff, map_sup, sdiff_le_iff]

-- See note [reducible non-instances]
/-- Pullback a `HeytingAlgebra` along an injection. -/
@[to_dual (reorder := le (x y), lt (x y), map_sup map_inf, map_top map_bot, map_himp (a b))
Expand Down