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

Commit 27f622e

Browse files
committed
chore(data/fintype/basic): split, and reduce imports (#3319)
Following on from #3256 and #3235, this slices a little out of `data.fintype.basic`, and reduces imports, mostly in the vicinity of `data.fintype.basic`. Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
1 parent f90fcc9 commit 27f622e

File tree

16 files changed

+65
-41
lines changed

16 files changed

+65
-41
lines changed

src/combinatorics/composition.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Sébastien Gouëzel
55
-/
66
import data.fintype.card
7-
import tactic.omega
7+
import data.finset.sort
88

99
/-!
1010
# Compositions

src/control/bifunctor.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Author: Simon Hudon
66
Functors with two arguments
77
-/
88
import logic.function.basic
9-
import tactic.basic
9+
import control.functor
10+
import tactic.core
1011

1112
universes u₀ u₁ u₂ v₀ v₁ v₂
1213

src/control/bitraversable/basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Author: Simon Hudon
55
-/
66
import control.bifunctor
7+
import control.traversable.basic
78

89
/-!
910
# Bitraversable type class

src/control/bitraversable/instances.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ instance bitraversable.flip : bitraversable (flip t) :=
7676
open is_lawful_bitraversable
7777
instance is_lawful_bitraversable.flip [is_lawful_bitraversable t]
7878
: is_lawful_bitraversable (flip t) :=
79-
by constructor; intros; unfreezingI { casesm is_lawful_bitraversable t }; apply_assumption
79+
by constructor; intros; unfreezingI { casesm is_lawful_bitraversable t }; tactic.apply_assumption
8080

8181
open bitraversable functor
8282

src/data/equiv/list.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Author: Mario Carneiro
66
Additional equiv and encodable instances for lists, finsets, and fintypes.
77
-/
88
import data.equiv.denumerable
9+
import data.finset.sort
910

1011
open nat list
1112

src/data/finset/basic.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,18 @@ lemma exists_smaller_set (A : finset α) (i : ℕ) (h₁ : i ≤ card A) :
19401940
∃ (B : finset α), B ⊆ A ∧ card B = i :=
19411941
let ⟨B, _, x₁, x₂⟩ := exists_intermediate_set i (by simpa) (empty_subset A) in ⟨B, x₁, x₂⟩
19421942

1943+
/-- `finset.fin_range k` is the finset `{0, 1, ..., k-1}`, as a `finset (fin k)`. -/
1944+
def fin_range (k : ℕ) : finset (fin k) :=
1945+
⟨list.fin_range k, list.nodup_fin_range k⟩
1946+
1947+
@[simp]
1948+
lemma fin_range_card {k : ℕ} : (fin_range k).card = k :=
1949+
by simp [fin_range]
1950+
1951+
@[simp]
1952+
lemma mem_fin_range {k : ℕ} (m : fin k) : m ∈ fin_range k :=
1953+
list.mem_fin_range m
1954+
19431955
/-- Given a finset `s` of `ℕ` contained in `{0,..., n-1}`, the corresponding finset in `fin n`
19441956
is `s.attach_fin h` where `h` is a proof that all elements of `s` are less than `n`. -/
19451957
def attach_fin (s : finset ℕ) {n : ℕ} (h : ∀ m ∈ s, m < n) : finset (fin n) :=

src/data/finset/sort.lean

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Author: Mario Carneiro
55
-/
66
import data.finset.lattice
77
import data.multiset.sort
8+
import tactic.suggest
89

910
/-!
1011
# Construct a sorted list from a finset.
@@ -90,6 +91,7 @@ def mono_of_fin (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : α :=
9091
have A : (i : ℕ) < (s.sort (≤)).length, by simpa [h] using i.2,
9192
(s.sort (≤)).nth_le i A
9293

94+
9395
lemma mono_of_fin_strict_mono (s : finset α) {k : ℕ} (h : s.card = k) :
9496
strict_mono (s.mono_of_fin h) :=
9597
begin
@@ -175,6 +177,21 @@ begin
175177
exact (ne_of_lt (mono_of_fin_strict_mono s h ji) hj).elim }
176178
end
177179

180+
/-- Any increasing map between `fin k` and a finset of cardinality `k` has to coincide with
181+
the increasing bijection `mono_of_fin s h`. -/
182+
lemma mono_of_fin_unique' {s : finset α} {k : ℕ} (h : s.card = k)
183+
{f : fin k → α} (fmap : set.maps_to f set.univ ↑s) (hmono : strict_mono f) :
184+
f = s.mono_of_fin h :=
185+
begin
186+
have finj : set.inj_on f set.univ := hmono.injective.inj_on _,
187+
apply mono_of_fin_unique h (set.bij_on.mk fmap finj (λ y hy, _)) hmono,
188+
simp only [set.image_univ, set.mem_range],
189+
rcases surj_on_of_inj_on_of_card_le (λ i (hi : i ∈ finset.fin_range k), f i)
190+
(λ i hi, fmap (set.mem_univ i)) (λ i j hi hj hij, finj (set.mem_univ i) (set.mem_univ j) hij)
191+
(by simp [h]) y hy with ⟨x, _, hx⟩,
192+
exact ⟨x, hx.symm⟩
193+
end
194+
178195
/-- Two parametrizations `mono_of_fin` of the same set take the same value on `i` and `j` if and
179196
only if `i = j`. Since they can be defined on a priori not defeq types `fin k` and `fin l` (although
180197
necessarily `k = l`), the conclusion is rather written `i.val = j.val`. -/

src/data/fintype/basic.lean

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Author: Mario Carneiro
55
66
Finite types.
77
-/
8-
import data.finset.sort
98
import data.finset.powerset
9+
import data.finset.lattice
1010
import data.finset.pi
1111
import data.array.lemmas
1212

@@ -144,18 +144,6 @@ quot.rec_on_subsingleton (@univ α _).1
144144
theorem exists_equiv_fin (α) [fintype α] : ∃ n, nonempty (α ≃ fin n) :=
145145
by haveI := classical.dec_eq α; exact ⟨card α, nonempty_of_trunc (equiv_fin α)⟩
146146

147-
/-- Given a linearly ordered fintype `α` of cardinal `k`, the equiv `mono_equiv_of_fin α h`
148-
is the increasing bijection between `fin k` and `α`. Here, `h` is a proof that
149-
the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid
150-
casting issues in further uses of this function. -/
151-
noncomputable def mono_equiv_of_fin (α) [fintype α] [decidable_linear_order α] {k : ℕ}
152-
(h : fintype.card α = k) : fin k ≃ α :=
153-
equiv.of_bijective (mono_of_fin univ h) begin
154-
apply set.bijective_iff_bij_on_univ.2,
155-
rw ← @coe_univ α _,
156-
exact mono_of_fin_bij_on (univ : finset α) h
157-
end
158-
159147
instance (α : Type*) : subsingleton (fintype α) :=
160148
⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext_iff, h₁, h₂]⟩
161149

@@ -266,7 +254,7 @@ lemma finset.card_univ_diff [fintype α] [decidable_eq α] (s : finset α) :
266254
finset.card_sdiff (subset_univ s)
267255

268256
instance (n : ℕ) : fintype (fin n) :=
269-
⟨list.fin_range n, list.nodup_fin_range n⟩, list.mem_fin_range⟩
257+
finset.fin_range n, finset.mem_fin_range⟩
270258

271259
@[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n :=
272260
list.length_fin_range n
@@ -295,21 +283,6 @@ begin
295283
exact fin.eq_last_of_not_lt h }
296284
end
297285

298-
/-- Any increasing map between `fin k` and a finset of cardinality `k` has to coincide with
299-
the increasing bijection `mono_of_fin s h`. -/
300-
lemma finset.mono_of_fin_unique' [decidable_linear_order α] {s : finset α} {k : ℕ} (h : s.card = k)
301-
{f : fin k → α} (fmap : set.maps_to f set.univ ↑s) (hmono : strict_mono f) :
302-
f = s.mono_of_fin h :=
303-
begin
304-
have finj : set.inj_on f set.univ := hmono.injective.inj_on _,
305-
apply mono_of_fin_unique h (set.bij_on.mk fmap finj (λ y hy, _)) hmono,
306-
simp only [set.image_univ, set.mem_range],
307-
rcases surj_on_of_inj_on_of_card_le (λ i (hi : i ∈ finset.univ), f i)
308-
(λ i hi, fmap (set.mem_univ i)) (λ i j hi hj hij, finj (set.mem_univ i) (set.mem_univ j) hij)
309-
(by simp [h]) y hy with ⟨x, _, hx⟩,
310-
exact ⟨x, hx.symm⟩
311-
end
312-
313286
@[instance, priority 10] def unique.fintype {α : Type*} [unique α] : fintype α :=
314287
fintype.of_subsingleton (default α)
315288

src/data/fintype/sort.lean

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/-
2+
Copyright (c) 2017 Mario Carneiro. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Author: Mario Carneiro
5+
-/
6+
import data.fintype.basic
7+
import data.finset.sort
8+
9+
variables {α : Type*}
10+
11+
open finset
12+
13+
/-- Given a linearly ordered fintype `α` of cardinal `k`, the equiv `mono_equiv_of_fin α h`
14+
is the increasing bijection between `fin k` and `α`. Here, `h` is a proof that
15+
the cardinality of `s` is `k`. We use this instead of a map `fin s.card → α` to avoid
16+
casting issues in further uses of this function. -/
17+
noncomputable def mono_equiv_of_fin (α) [fintype α] [decidable_linear_order α] {k : ℕ}
18+
(h : fintype.card α = k) : fin k ≃ α :=
19+
equiv.of_bijective (mono_of_fin univ h) begin
20+
apply set.bijective_iff_bij_on_univ.2,
21+
rw ← @coe_univ α _,
22+
exact mono_of_fin_bij_on (univ : finset α) h
23+
end

src/data/polynomial.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import algebra.gcd_domain
1111
import ring_theory.euclidean_domain
1212
import ring_theory.multiplicity
1313
import data.finset.nat_antidiagonal
14+
import data.finset.sort
1415

1516
/-!
1617
# Theory of univariate polynomials

0 commit comments

Comments
 (0)