Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 02cdc81

Browse files
committed
refactor(order/sup_indep): Get rid of decidable equality assumption (#10673)
The `erase` in the definition required a `decidable_eq`. We can make do without it while keeping it functionally the same.
1 parent 9525f5e commit 02cdc81

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed

src/order/sup_indep.lean

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Copyright (c) 2021 Yaël Dillies. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yaël Dillies
55
-/
6-
import data.finset.lattice
6+
import data.finset.pairwise
7+
import data.set.finite
78

89
/-!
910
# Finite supremum independence
@@ -13,6 +14,11 @@ sup-independent if, for all `a`, `f a` and the supremum of the rest are disjoint
1314
1415
In distributive lattices, this is equivalent to being pairwise disjoint.
1516
17+
## Implementation notes
18+
19+
We avoid the "obvious" definition `∀ i ∈ s, disjoint (f i) ((s.erase i).sup f)` because `erase`
20+
would require decidable equality on `ι`.
21+
1622
## TODO
1723
1824
`complete_lattice.independent` and `complete_lattice.set_independent` should live in this file.
@@ -21,74 +27,83 @@ In distributive lattices, this is equivalent to being pairwise disjoint.
2127
variables {α β ι ι' : Type*}
2228

2329
namespace finset
24-
variables [lattice α] [order_bot α] [decidable_eq ι] [decidable_eq ι']
30+
section lattice
31+
variables [lattice α] [order_bot α]
2532

26-
/-- Supremum independence of finite sets. -/
27-
def sup_indep (s : finset ι) (f : ι → α) : Prop := ∀ ⦃a⦄, a ∈ s → disjoint (f a) ((s.erase a).sup f)
33+
/-- Supremum independence of finite sets. We avoid the "obvious" definition using`s.erase i` because
34+
`erase` would require decidable equality on `ι`. -/
35+
def sup_indep (s : finset ι) (f : ι → α) : Prop :=
36+
∀ ⦃t⦄, t ⊆ s → ∀ ⦃i⦄, i ∈ s → i ∉ t → disjoint (f i) (t.sup f)
2837

29-
variables {s t : finset ι} {f : ι → α}
38+
variables {s t : finset ι} {f : ι → α} {i : ι}
3039

3140
lemma sup_indep.subset (ht : t.sup_indep f) (h : s ⊆ t) : s.sup_indep f :=
32-
λ a ha, (ht $ h ha).mono_right $ sup_mono $ erase_subset_erase _ h
41+
λ u hu i hi, ht (hu.trans h) (h hi)
3342

34-
lemma sup_indep_empty (f : ι → α) : (∅ : finset ι).sup_indep f := λ a ha, ha.elim
43+
lemma sup_indep_empty (f : ι → α) : (∅ : finset ι).sup_indep f := λ _ _ a ha, ha.elim
3544

3645
lemma sup_indep_singleton (i : ι) (f : ι → α) : ({i} : finset ι).sup_indep f :=
37-
λ j hj, by { rw [mem_singleton.1 hj, erase_singleton, sup_empty], exact disjoint_bot_right }
46+
λ s hs j hji hj, begin
47+
rw [eq_empty_of_ssubset_singleton ⟨hs, λ h, hj (h hji)⟩, sup_empty],
48+
exact disjoint_bot_right,
49+
end
50+
51+
lemma sup_indep.pairwise_disjoint (hs : s.sup_indep f) : (s : set ι).pairwise_disjoint f :=
52+
λ a ha b hb hab, sup_singleton.subst $ hs (singleton_subset_iff.2 hb) ha $ not_mem_singleton.2 hab
53+
54+
/-- The RHS looks like the definition of `complete_lattice.independent`. -/
55+
lemma sup_indep_iff_disjoint_erase [decidable_eq ι] :
56+
s.sup_indep f ↔ ∀ i ∈ s, disjoint (f i) ((s.erase i).sup f) :=
57+
⟨λ hs i hi, hs (erase_subset _ _) hi (not_mem_erase _ _), λ hs t ht i hi hit,
58+
(hs i hi).mono_right (sup_mono $ λ j hj, mem_erase.2 ⟨ne_of_mem_of_not_mem hj hit, ht hj⟩)⟩
3859

3960
lemma sup_indep.attach (hs : s.sup_indep f) : s.attach.sup_indep (f ∘ subtype.val) :=
40-
λ i _,
41-
by { rw [←finset.sup_image, image_erase subtype.val_injective, attach_image_val], exact hs i.2 }
61+
begin
62+
intros t ht i _ hi,
63+
classical,
64+
rw ←finset.sup_image,
65+
refine hs (image_subset_iff.2 $ λ (j : {x // x ∈ s}) _, j.2) i.2 (λ hi', hi _),
66+
rw mem_image at hi',
67+
obtain ⟨j, hj, hji⟩ := hi',
68+
rwa subtype.ext hji at hj,
69+
end
70+
71+
end lattice
72+
73+
section distrib_lattice
74+
variables [distrib_lattice α] [order_bot α] {s : finset ι} {f : ι → α}
75+
76+
lemma sup_indep_iff_pairwise_disjoint : s.sup_indep f ↔ (s : set ι).pairwise_disjoint f :=
77+
⟨sup_indep.pairwise_disjoint, λ hs t ht i hi hit,
78+
disjoint_sup_right.2 $ λ j hj, hs hi (ht hj) (ne_of_mem_of_not_mem hj hit).symm⟩
79+
80+
alias sup_indep_iff_pairwise_disjoint ↔ finset.sup_indep.pairwise_disjoint
81+
set.pairwise_disjoint.sup_indep
4282

4383
/-- Bind operation for `sup_indep`. -/
44-
lemma sup_indep.sup {α} [distrib_lattice α] [order_bot α] {s : finset ι'} {g : ι' → finset ι}
45-
{f : ι → α} (hs : s.sup_indep (λ i, (g i).sup f)) (hg : ∀ i' ∈ s, (g i').sup_indep f) :
84+
lemma sup_indep.sup [decidable_eq ι] {s : finset ι'} {g : ι' → finset ι} {f : ι → α}
85+
(hs : s.sup_indep (λ i, (g i).sup f)) (hg : ∀ i' ∈ s, (g i').sup_indep f) :
4686
(s.sup g).sup_indep f :=
4787
begin
48-
rintro i hi,
49-
rw disjoint_sup_right,
50-
refine λ j hj, _,
51-
rw mem_sup at hi,
52-
obtain ⟨i', hi', hi⟩ := hi,
53-
rw [mem_erase, mem_sup] at hj,
54-
obtain ⟨hij, j', hj', hj⟩ := hj,
55-
obtain hij' | hij' := eq_or_ne j' i',
56-
{ exact disjoint_sup_right.1 (hg i' hi' hi) _ (mem_erase.2 ⟨hij, hij'.subst hj⟩) },
57-
{ exact (hs hi').mono (le_sup hi) ((le_sup hj).trans $ le_sup $ mem_erase.2 ⟨hij', hj'⟩) }
88+
simp_rw sup_indep_iff_pairwise_disjoint at ⊢ hs hg,
89+
rw [sup_eq_bUnion, coe_bUnion],
90+
exact hs.bUnion_finset hg,
5891
end
5992

6093
/-- Bind operation for `sup_indep`. -/
61-
lemma sup_indep.bUnion {α} [distrib_lattice α] [order_bot α] {s : finset ι'} {g : ι' → finset ι}
62-
{f : ι → α} (hs : s.sup_indep (λ i, (g i).sup f)) (hg : ∀ i' ∈ s, (g i').sup_indep f) :
94+
lemma sup_indep.bUnion [decidable_eq ι] {s : finset ι'} {g : ι' → finset ι} {f : ι → α}
95+
(hs : s.sup_indep (λ i, (g i).sup f)) (hg : ∀ i' ∈ s, (g i').sup_indep f) :
6396
(s.bUnion g).sup_indep f :=
6497
by { rw ←sup_eq_bUnion, exact hs.sup hg }
6598

66-
lemma sup_indep.pairwise_disjoint (hs : s.sup_indep f) : (s : set ι).pairwise_disjoint f :=
67-
λ a ha b hb hab, (hs ha).mono_right $ le_sup $ mem_erase.2 ⟨hab.symm, hb⟩
68-
69-
-- Once `finset.sup_indep` will have been generalized to non distributive lattices, can we state
70-
-- this lemma for nondistributive atomic lattices? This setting makes the `←` implication much
71-
-- harder.
72-
lemma sup_indep_iff_pairwise_disjoint {α} [distrib_lattice α] [order_bot α] {f : ι → α} :
73-
s.sup_indep f ↔ (s : set ι).pairwise_disjoint f :=
74-
begin
75-
refine ⟨λ hs a ha b hb hab, (hs ha).mono_right $ le_sup $ mem_erase.2 ⟨hab.symm, hb⟩,
76-
λ hs a ha, _⟩,
77-
rw disjoint_sup_right,
78-
exact λ b hb, hs ha (mem_of_mem_erase hb) (ne_of_mem_erase hb).symm,
79-
end
80-
81-
alias sup_indep_iff_pairwise_disjoint ↔ finset.sup_indep.pairwise_disjoint
82-
set.pairwise_disjoint.sup_indep
83-
99+
end distrib_lattice
84100
end finset
85101

86-
-- TODO: Relax `complete_distrib_lattice` to `complete_lattice` once `finset.sup_indep` is general
87-
-- enough
88-
lemma complete_lattice.independent_iff_sup_indep [complete_distrib_lattice α] [decidable_eq ι]
89-
{s : finset ι} {f : ι → α} :
102+
lemma complete_lattice.independent_iff_sup_indep [complete_lattice α] {s : finset ι} {f : ι → α} :
90103
complete_lattice.independent (f ∘ (coe : s → ι)) ↔ s.sup_indep f :=
91104
begin
105+
classical,
106+
rw finset.sup_indep_iff_disjoint_erase,
92107
refine subtype.forall.trans (forall_congr $ λ a, forall_congr $ λ b, _),
93108
rw finset.sup_eq_supr,
94109
congr' 2,

0 commit comments

Comments
 (0)