@@ -238,6 +238,41 @@ instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕
238
238
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
239
239
by rw [sum.fintype, fintype.of_equiv_card]; simp
240
240
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
+
241
276
instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} :=
242
277
fintype.of_list l.attach l.mem_attach
243
278
@@ -267,6 +302,18 @@ instance pi.fintype {α : Type*} {β : α → Type*}
267
302
λ f, finset.mem_pi.2 $ λ a ha, mem_univ _⟩
268
303
⟨λ f a, f a (mem_univ _), λ f a _, f a, λ f, rfl, λ f, rfl⟩
269
304
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
+
270
317
instance d_array.fintype {n : ℕ} {α : fin n → Type *}
271
318
[∀n, fintype (α n)] : fintype (d_array n α) :=
272
319
fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm
0 commit comments