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

Commit aedbc12

Browse files
ChrisHughes24digama0
authored andcommitted
feat(data/fintype): card lemmas (#168)
1 parent c2f54ad commit aedbc12

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

algebra/big_operators.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,16 @@ finset.induction_on s (by simp) (assume a s has ih h,
188188
(assume hna : f a ≠ 1,
189189
⟨a, mem_insert_self _ _, hna⟩))
190190

191+
@[simp] lemma prod_const [decidable_eq α] (b : β) : s.prod (λ a, b) = b ^ s.card :=
192+
finset.induction_on s rfl (by simp [pow_add, mul_comm] {contextual := tt})
193+
191194
end comm_monoid
192195

196+
@[simp] lemma sum_const [add_comm_monoid β] [decidable_eq α] (b : β) :
197+
s.sum (λ a, b) = add_monoid.smul s.card b :=
198+
@prod_const _ (multiplicative β) _ _ _ _
199+
attribute [to_additive finset.sum_const] prod_const
200+
193201
section comm_group
194202
variables [comm_group β]
195203

@@ -343,6 +351,10 @@ finset.induction_on s (by simp [abs_zero]) $
343351

344352
end discrete_linear_ordered_field
345353

354+
@[simp] lemma card_pi {δ : α → Type*} (s : finset α) (t : Π a, finset (δ a)) :
355+
(s.pi t).card = s.prod (λ a, card (t a)) :=
356+
multiset.card_pi _ _
357+
346358
end finset
347359

348360
section group

data/fintype.lean

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,41 @@ instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕
238238
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
239239
by rw [sum.fintype, fintype.of_equiv_card]; simp
240240

241+
lemma fintype.card_le_of_injective [fintype α] [fintype β] (f : α → β)
242+
(hf : function.injective f) : fintype.card α ≤ fintype.card β :=
243+
by haveI := classical.prop_decidable; exact
244+
finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h)
245+
246+
lemma fintype.card_eq_one_iff [fintype α] : fintype.card α = 1 ↔ (∃ x : α, ∀ y, y = x) :=
247+
by rw [← fintype.card_unit, fintype.card_eq];
248+
exact ⟨λ ⟨a⟩, ⟨a.symm unit.star, λ y, a.bijective.1 (subsingleton.elim _ _)⟩,
249+
λ ⟨x, hx⟩, ⟨⟨λ _, unit.star, λ _, x, λ _, (hx _).trans (hx _).symm,
250+
λ _, subsingleton.elim _ _⟩⟩⟩
251+
252+
lemma fintype.card_eq_zero_iff [fintype α] : fintype.card α = 0 ↔ (α → false) :=
253+
⟨λ h a, have e : α ≃ empty := classical.choice (fintype.card_eq.1 (by simp [h])), (e a).elim,
254+
λ h, have e : α ≃ empty := ⟨λ a, (h a).elim, λ a, a.elim, λ a, (h a).elim, λ a, a.elim⟩,
255+
by simp [fintype.card_congr e]⟩
256+
257+
lemma fintype.card_pos_iff [fintype α] : 0 < fintype.card α ↔ nonempty α :=
258+
⟨λ h, classical.by_contradiction (λ h₁,
259+
have fintype.card α = 0 := fintype.card_eq_zero_iff.2 (λ a, h₁ ⟨a⟩),
260+
lt_irrefl 0 $ by rwa this at h),
261+
λ ⟨a⟩, nat.pos_of_ne_zero (mt fintype.card_eq_zero_iff.1 (λ h, h a))⟩
262+
263+
lemma fintype.card_le_one_iff [fintype α] : fintype.card α ≤ 1 ↔ (∀ a b : α, a = b) :=
264+
let n := fintype.card α in
265+
have hn : n = fintype.card α := rfl,
266+
match n, hn with
267+
| 0 := λ ha, ⟨λ h, λ a, (fintype.card_eq_zero_iff.1 ha.symm a).elim, λ _, ha ▸ nat.le_succ _⟩
268+
| 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := fintype.card_eq_one_iff.1 ha.symm in
269+
by rw [hx a, hx b],
270+
λ _, ha ▸ le_refl _⟩
271+
| (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial,
272+
(λ h, fintype.card_unit ▸ fintype.card_le_of_injective (λ _, ())
273+
(λ _ _ _, h _ _))⟩
274+
end
275+
241276
instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} :=
242277
fintype.of_list l.attach l.mem_attach
243278

@@ -267,6 +302,18 @@ instance pi.fintype {α : Type*} {β : α → Type*}
267302
λ f, finset.mem_pi.2 $ λ a ha, mem_univ _⟩
268303
⟨λ f a, f a (mem_univ _), λ f a _, f a, λ f, rfl, λ f, rfl⟩
269304

305+
@[simp] lemma fintype.card_pi {β : α → Type*} [fintype α] [decidable_eq α]
306+
[f : Π a, fintype (β a)] : fintype.card (Π a, β a) = univ.prod (λ a, fintype.card (β a)) :=
307+
by letI f' : fintype (Πa∈univ, β a) :=
308+
⟨(univ.pi $ λa, univ), assume f, finset.mem_pi.2 $ assume a ha, mem_univ _⟩;
309+
exact calc fintype.card (Π a, β a) = fintype.card (Π a ∈ univ, β a) : fintype.card_congr
310+
⟨λ f a ha, f a, λ f a, f a (mem_univ a), λ _, rfl, λ _, rfl⟩
311+
... = univ.prod (λ a, fintype.card (β a)) : finset.card_pi _ _
312+
313+
@[simp] lemma fintype.card_fun [fintype α] [decidable_eq α] [fintype β] :
314+
fintype.card (α → β) = fintype.card β ^ fintype.card α :=
315+
by rw [fintype.card_pi, finset.prod_const, nat.pow_eq_pow]; refl
316+
270317
instance d_array.fintype {n : ℕ} {α : fin n → Type*}
271318
[∀n, fintype (α n)] : fintype (d_array n α) :=
272319
fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm

0 commit comments

Comments
 (0)