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

Commit 8ed673d

Browse files
committed
feat(data/set/countable): finite sets are countable
1 parent 28b46a2 commit 8ed673d

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

data/encodable.lean

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@ variables {α : Type*} {β : Type*}
2020

2121
open encodable
2222

23-
/-
24-
25-
def encodable_finType* [instance] {α : Type*} [h₁ : finType* α] [h₂ : decidable_eq α] :
26-
encodable α :=
27-
encodable.mk
28-
(λ a, find a (elements_of α))
29-
(λ n, nth (elements_of α) n)
30-
(λ a, find_nth (finType*.complete a))
31-
-/
32-
3323
instance encodable_nat : encodable nat :=
3424
encodable.mk (λ a, a) (λ n, some n) (λ a, rfl)
3525

26+
instance encodable_empty : encodable empty :=
27+
encodable.mk (λ a:_root_.empty, a.rec _) (λ n, none) (λ a:_root_.empty, a.rec _)
28+
29+
instance encodable_unit : encodable unit :=
30+
encodable.mk (λ_, 0) (λn, if n = 0 then some () else none) (λ⟨⟩, by simp)
31+
3632
instance encodable_option {α : Type*} [h : encodable α] : encodable (option α) :=
3733
encodable.mk
3834
(λ o, match o with
@@ -320,6 +316,8 @@ def encodable_of_equiv [h : encodable α] : α ≃ β → encodable β
320316
(λ b, by rewrite r; reflexivity)
321317
end
322318

319+
instance : encodable bool := encodable_of_equiv equiv.bool_equiv_unit_sum_unit.symm
320+
323321
end encodable
324322

325323
/-

data/set/countable.lean

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,25 @@ by_cases
102102
⟨nat.mkpair i j, by simp [function.comp, nat.unpair_mkpair, hi, hj]⟩⟩)
103103
(assume : ¬ nonempty α, ⟨λ_, 0, assume a, (this ⟨a⟩).elim⟩)
104104

105+
lemma countable_Union {s : set α} {t : α → set β} (hs : countable s) (ht : ∀a∈s, countable (t a)) :
106+
countable (⋃a∈s, t a) :=
107+
have ⋃₀ (t '' s) = (⋃a∈s, t a), from lattice.Sup_image,
108+
by rw [←this];
109+
from (countable_sUnion (countable_image hs) $ assume a ⟨s', hs', eq⟩, eq ▸ ht s' hs')
110+
111+
lemma countable_union {s₁ s₂ : set α} (h₁ : countable s₁) (h₂ : countable s₂) : countable (s₁ ∪ s₂) :=
112+
have s₁ ∪ s₂ = (⨆b ∈ ({tt, ff} : set bool), bool.cases_on b s₁ s₂),
113+
by simp [lattice.supr_or, lattice.supr_sup_eq]; refl,
114+
by rw [this]; from countable_Union countable_encodable (assume b,
115+
match b with
116+
| tt := by simp [h₂]
117+
| ff := by simp [h₁]
118+
end)
119+
120+
lemma countable_insert {s : set α} {a : α} (h : countable s) : countable (insert a s) :=
121+
by rw [set.insert_eq]; from countable_union countable_singleton h
122+
123+
lemma countable_finite {s : set α} (h : finite s) : countable s :=
124+
h.rec_on countable_empty $ assume a s _ _, countable_insert
125+
105126
end set

0 commit comments

Comments
 (0)