Skip to content

Commit

Permalink
split(data/finset/*): Split data.finset.card and data.finset.fin
Browse files Browse the repository at this point in the history
…off `data.finset.basic` (#10796)

This moves stuff from `data.finset.basic` in two new files:
* Stuff about `finset.card` goes into `data.finset.card`
* Stuff about `finset.fin_range` and `finset.attach_fin` goes into `data.finset.fin`. I expect this file to be shortlived as I'm planning on killing `fin_range`.

I reordered lemmas thematically and it appeared that there were two pairs of duplicated lemmas:
* `finset.one_lt_card`, `finset.one_lt_card_iff`. They differ only for binder order.
* `finset.card_union_eq`, `finset.card_disjoint_union`. They are literally the same.

All are used so I will clean up in a later PR.

I'm crediting:
* Microsoft Corporation, Leonardo, Jeremy for 8dbee5b
* Chris Hughes for #231
* Scott for #3319
  • Loading branch information
YaelDillies committed Dec 18, 2021
1 parent fa46ef1 commit 2c4e66f
Show file tree
Hide file tree
Showing 9 changed files with 565 additions and 538 deletions.
2 changes: 1 addition & 1 deletion src/combinatorics/set_family/compression/uv.lean
Expand Up @@ -3,7 +3,7 @@ Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import data.finset.basic
import data.finset.card

/-!
# UV-compressions
Expand Down
538 changes: 4 additions & 534 deletions src/data/finset/basic.lean

Large diffs are not rendered by default.

506 changes: 506 additions & 0 deletions src/data/finset/card.lean

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/data/finset/fin.lean
@@ -0,0 +1,49 @@
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Scott Morrison, Johan Commelin
-/
import data.finset.card

/-!
# Finsets in `fin n`
A few constructions for finsets in `fin n`.
## Main declarations
* `finset.fin_range`: `{0, 1, ..., n - 1}` as a `finset (fin n)`.
* `finset.attach_fin`: Turns a finset of naturals strictly less than `n` into a `finset (fin n)`.
-/

variables {n : ℕ}

namespace finset

/-- `finset.fin_range n` is the finset `{0, 1, ..., n - 1}`, as a `finset (fin n)`. -/
def fin_range (n : ℕ) : finset (fin n) := ⟨list.fin_range n, list.nodup_fin_range n⟩

@[simp]
lemma fin_range_card : (fin_range n).card = n := by simp [fin_range]

@[simp]
lemma mem_fin_range (m : fin n) : m ∈ fin_range n := list.mem_fin_range m

@[simp] lemma coe_fin_range (n : ℕ) : (fin_range n : set (fin n)) = set.univ :=
set.eq_univ_of_forall mem_fin_range

/-- Given a finset `s` of `ℕ` contained in `{0,..., n-1}`, the corresponding finset in `fin n`
is `s.attach_fin h` where `h` is a proof that all elements of `s` are less than `n`. -/
def attach_fin (s : finset ℕ) {n : ℕ} (h : ∀ m ∈ s, m < n) : finset (fin n) :=
⟨s.1.pmap (λ a ha, ⟨a, ha⟩) h, multiset.nodup_pmap (λ _ _ _ _, fin.veq_of_eq) s.2

@[simp] lemma mem_attach_fin {n : ℕ} {s : finset ℕ} (h : ∀ m ∈ s, m < n) {a : fin n} :
a ∈ s.attach_fin h ↔ (a : ℕ) ∈ s :=
⟨λ h, let ⟨b, hb₁, hb₂⟩ := multiset.mem_pmap.1 h in hb₂ ▸ hb₁,
λ h, multiset.mem_pmap.2 ⟨a, h, fin.eta _ _⟩⟩

@[simp] lemma card_attach_fin {n : ℕ} (s : finset ℕ) (h : ∀ m ∈ s, m < n) :
(s.attach_fin h).card = s.card :=
multiset.card_pmap _ _ _

end finset
2 changes: 1 addition & 1 deletion src/data/finset/nat_antidiagonal.lean
Expand Up @@ -3,7 +3,7 @@ Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import data.finset.basic
import data.finset.card
import data.multiset.nat_antidiagonal

/-!
Expand Down
2 changes: 1 addition & 1 deletion src/data/finset/option.lean
Expand Up @@ -3,7 +3,7 @@ Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Mario Carneiro, Sean Leather
-/
import data.finset.basic
import data.finset.card
import order.hom.basic

/-!
Expand Down
2 changes: 1 addition & 1 deletion src/data/finset/prod.lean
Expand Up @@ -3,7 +3,7 @@ Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash
-/
import data.finset.basic
import data.finset.card

/-!
# Finsets in product types
Expand Down
1 change: 1 addition & 0 deletions src/data/fintype/basic.lean
Expand Up @@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.array.lemmas
import data.finset.fin
import data.finset.option
import data.finset.pi
import data.finset.powerset
Expand Down
1 change: 1 addition & 0 deletions src/group_theory/perm/support.lean
Expand Up @@ -3,6 +3,7 @@ Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import data.finset.card
import data.fintype.basic
import group_theory.perm.basic

Expand Down

0 comments on commit 2c4e66f

Please sign in to comment.