Skip to content

Commit 50b6a3e

Browse files
committed
feat: use to_dual for HeytingAlgebra (leanprover-community#33543)
This PR adds `to_dual` for `HeytingAlgebra`, `BiheytingAlgebra`, `GeneralizedHeytingAlgebra`. There is a bit of friction around dualizing `compl` to `hnot`, because this means that theorems about `compl` in boolean algebras will not be able to be translated nicely with `to_dual`. This should not be that many theorems, so this is acceptable. See also https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Dualize.20sdiff.20and.20himp/with/599261487 Since we have `GeneralizedCoheytingAlgebra.toDistribLattice`, I removed `CoheytingAlgebra.toDistribLattice`. Aligning the `Heyting` and `Coheyting` API is kind of awkward, because they are unfortunately quite different. One reason is that the arguments of `sup`/`inf` are often swapped in the dual version, which is not compatible with `to_dual`. I've worked around this with extensive use of `to_dual none`. There are quite some lemmas that in my eyes seem unnecessary, such as `le_sup_sdiff_sup_sdiff`, but I haven't removed any in this PR.
1 parent 86a97b0 commit 50b6a3e

8 files changed

Lines changed: 202 additions & 390 deletions

File tree

Mathlib/Combinatorics/SetFamily/Kleitman.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ theorem Finset.card_biUnion_le_of_intersecting (s : Finset ι) (f : ι → Finse
6464
refine (card_le_card <| biUnion_mono fun j hj ↦ (hf₁ _ hj).1).trans ?_
6565
nth_rw 1 [cons_eq_insert i]
6666
rw [biUnion_insert]
67-
refine (card_mono <| @le_sup_sdiff _ _ _ <| f' i).trans ((card_union_le _ _).trans ?_)
67+
refine (card_mono <| @le_sup_sdiff _ _ (f' i) _).trans ((card_union_le _ _).trans ?_)
6868
rw [union_sdiff_left, sdiff_eq_inter_compl]
6969
refine le_of_mul_le_mul_left ?_ (pow_pos (zero_lt_two' ℕ) <| Fintype.card α + 1)
7070
rw [pow_succ, mul_add, mul_assoc, mul_comm _ 2, mul_assoc]

Mathlib/Data/Finset/Lattice/Fold.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,14 @@ theorem sup_himp_left (hs : s.Nonempty) (f : ι → α) (a : α) :
407407
(s.sup fun b => a ⇨ f b) = a ⇨ s.sup f :=
408408
@inf_sdiff_right αᵒᵈ _ _ _ hs _ _
409409

410-
@[to_dual (attr := simp)]
410+
@[simp]
411411
protected theorem compl_sup (s : Finset ι) (f : ι → α) : (s.sup f)ᶜ = s.inf fun i => (f i)ᶜ :=
412412
map_finset_sup (OrderIso.compl α) _ _
413413

414+
@[simp]
415+
protected theorem compl_inf (s : Finset ι) (f : ι → α) : (s.inf f)ᶜ = s.sup fun i => (f i)ᶜ :=
416+
map_finset_inf (OrderIso.compl α) _ _
417+
414418
end BooleanAlgebra
415419

416420
section LinearOrder

Mathlib/Order/Basic.lean

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,16 @@ lemma LinearOrder.ext_lt {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A;
522522
instance Prop.instCompl : Compl Prop :=
523523
⟨Not⟩
524524

525+
@[to_dual instHNot]
525526
instance Pi.instCompl [∀ i, Compl (π i)] : Compl (∀ i, π i) :=
526527
fun x i ↦ (x i)ᶜ⟩
527528

528-
@[push ←]
529+
@[to_dual (attr := push ←) hnot_def]
529530
theorem Pi.compl_def [∀ i, Compl (π i)] (x : ∀ i, π i) :
530531
xᶜ = fun i ↦ (x i)ᶜ :=
531532
rfl
532533

533-
@[simp]
534+
@[to_dual (attr := simp) hnot_apply]
534535
theorem Pi.compl_apply [∀ i, Compl (π i)] (x : ∀ i, π i) (i : ι) :
535536
xᶜ i = (x i)ᶜ :=
536537
rfl
@@ -647,15 +648,16 @@ theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_
647648

648649
end Function
649650

650-
instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
651+
@[to_dual instHImp]
652+
instance Pi.instSDiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
651653
fun x y i ↦ x i \ y i⟩
652654

653-
@[push ←]
655+
@[to_dual (attr := push ←) himp_def]
654656
theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) :
655657
x \ y = fun i ↦ x i \ y i :=
656658
rfl
657659

658-
@[simp]
660+
@[to_dual (attr := simp) himp_apply]
659661
theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) :
660662
(x \ y) i = x i \ y i :=
661663
rfl

Mathlib/Order/BooleanAlgebra/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ lemma inf_sdiff_left_comm (a b c : α) : a ⊓ (b \ c) = b ⊓ (a \ c) := by
352352
simp_rw [← inf_sdiff_assoc, inf_comm]
353353

354354
theorem inf_sdiff_distrib_left (a b c : α) : a ⊓ b \ c = (a ⊓ b) \ (a ⊓ c) := by
355-
rw [sdiff_inf, sdiff_eq_bot_iff.2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
355+
rw [sdiff_inf, (sdiff_eq_bot_iff (α := α)).2 inf_le_left, bot_sup_eq, inf_sdiff_assoc]
356356

357357
theorem inf_sdiff_distrib_right (a b c : α) : a \ b ⊓ c = (a ⊓ c) \ (b ⊓ c) := by
358358
simp_rw [inf_comm _ c, inf_sdiff_distrib_left]

Mathlib/Order/Disjoint.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ section DistribLattice
307307

308308
variable [DistribLattice α] [BoundedOrder α] {a b c : α}
309309

310+
@[to_dual]
310311
theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by
311312
rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right]
312313
exact inf_le_inf_right _ le_sup_left

Mathlib/Order/GaloisConnection/Basic.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ end CompleteLattice
119119
-- Constructing Galois connections
120120
section Constructions
121121

122-
@[to_dual self]
123122
protected theorem compl [BooleanAlgebra α] [BooleanAlgebra β] {l : α → β} {u : β → α}
124123
(gc : GaloisConnection l u) :
125124
GaloisConnection (compl ∘ u ∘ compl) (compl ∘ l ∘ compl) := fun a b ↦ by

0 commit comments

Comments
 (0)