Built with
doc-gen4 , running Lean4.
Bubbles (
) indicate interactive fragments: hover for details, tap to reveal contents.
Use
Ctrl+↑ Ctrl+↓ to navigate,
Ctrl+🖱️ to focus.
On Mac, use
Cmd instead of
Ctrl .
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
! This file was ported from Lean 3 source module data.countable.basic
! leanprover-community/mathlib commit 1f0096e6caa61e9c849ec2adbd227e960e9dff58
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Logic.Equiv.Nat
import Mathlib.Logic.Equiv.Fin
import Mathlib.Data.Countable.Defs
/-!
# Countable types
In this file we provide basic instances of the `Countable` typeclass defined elsewhere.
-/
universe u v w
open Function
instance : Countable ℤ :=
Countable.of_equiv ℕ Equiv.intEquivNat . symm : {α : Sort ?u.10} → {β : Sort ?u.9} → α ≃ β → β ≃ α symm
/-!
### Definition in terms of `Function.Embedding`
-/
section Embedding
variable { α : Sort u } { β : Sort v }
theorem countable_iff_nonempty_embedding : Countable α ↔ Nonempty ( α ↪ ℕ ) :=
⟨ fun ⟨⟨ f , hf ⟩⟩ => ⟨⟨ f , hf ⟩⟩, fun ⟨ f ⟩ => ⟨⟨ f , f . 2 ⟩⟩⟩
#align countable_iff_nonempty_embedding countable_iff_nonempty_embedding
theorem nonempty_embedding_nat ( α ) [ Countable α ] : Nonempty ( α ↪ ℕ ) :=
countable_iff_nonempty_embedding . 1 : ∀ {a b : Prop }, (a ↔ b ) → a → b 1 ‹_›
#align nonempty_embedding_nat nonempty_embedding_nat
protected theorem Function.Embedding.countable [ Countable β ] ( f : α ↪ β ) : Countable α :=
f . injective . countable
#align function.embedding.countable Function.Embedding.countable
end Embedding
/-!
### Operations on `Type _`s
-/
section type
variable { α : Type u } { β : Type v } { π : α → Type w }
instance [ Countable α ] [ Countable β ] : Countable ( Sum α β ) := by
rcases exists_injective_nat α with ⟨ f , hf ⟩
rcases exists_injective_nat β with ⟨ g , hg ⟩
exact ( Equiv.natSumNatEquivNat : ℕ ⊕ ℕ ≃ ℕ Equiv.natSumNatEquivNat. injective . comp <| hf . sum_map hg ). countable
instance [ Countable α ] : Countable ( Option α ) :=
Countable.of_equiv _ ( Equiv.optionEquivSumPUnit .{_, 0} α ). symm : {α : Sort ?u.787} → {β : Sort ?u.786} → α ≃ β → β ≃ α symm
instance [ Countable α ] [ Countable β ] : Countable ( α × β ) := by
rcases exists_injective_nat α with ⟨ f , hf ⟩
rcases exists_injective_nat β with ⟨ g , hg ⟩
exact ( Nat.pairEquiv . injective . comp <| hf . Prod_map hg ). countable
instance [ Countable α ] [∀ a , Countable ( π a )] : Countable ( Sigma : {α : Type ?u.1086} → (α → Type ?u.1085 ) → Type (max?u.1086?u.1085) Sigma π ) := by
rcases exists_injective_nat α with ⟨ f , hf ⟩
choose g hg using fun a => exists_injective_nat ( π a )
exact (( Equiv.sigmaEquivProd : (α : Type ?u.1161) → (β : Type ?u.1160) → (_ : α ) × β ≃ α × β Equiv.sigmaEquivProd ℕ ℕ ). injective . comp <| hf . sigma_map hg ). countable
end type
section sort
variable { α : Sort u } { β : Sort v } { π : α → Sort w }
/-!
### Operations on `Sort _`s
-/
instance ( priority := 500) SetCoe.countable { α } [ Countable α ] ( s : Set α ) : Countable s :=
Subtype.countable
#align set_coe.countable SetCoe.countable
instance [ Countable α ] [ Countable β ] : Countable ( PSum : Sort ?u.1599 → Sort ?u.1598 → Sort (max(max1?u.1599)?u.1598) PSum α β ) :=
Countable.of_equiv ( Sum ( PLift α ) ( PLift β )) ( Equiv.plift . sumPSum : {α₁ : Type ?u.1617} →
{α₂ : Sort ?u.1616} → {β₁ : Type ?u.1615} → {β₂ : Sort ?u.1614} → α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ ⊕ β₁ ≃ α₂ ⊕' β₂ sumPSum Equiv.plift )
instance [ Countable α ] [ Countable β ] : Countable ( PProd : Sort ?u.1725 → Sort ?u.1724 → Sort (max(max1?u.1725)?u.1724) PProd α β ) :=
Countable.of_equiv ( PLift α × PLift β ) ( Equiv.plift . prodPProd : {α₁ : Type ?u.1743} →
{α₂ : Sort ?u.1742} → {β₁ : Type ?u.1741} → {β₂ : Sort ?u.1740} → α₁ ≃ α₂ → β₁ ≃ β₂ → α₁ × β₁ ≃ PProd α₂ β₂ prodPProd Equiv.plift )
instance [ Countable α ] [∀ a , Countable ( π a )] : Countable ( PSigma : {α : Sort ?u.1856} → (α → Sort ?u.1855 ) → Sort (max(max1?u.1856)?u.1855) PSigma π ) :=
Countable.of_equiv (Σ a : PLift α , PLift ( π a . down )) ( Equiv.psigmaEquivSigmaPLift : {α : Sort ?u.1882} → (β : α → Sort ?u.1881 ) → (i : α ) ×' β i ≃ (i : PLift α ) × PLift (β i .down ) Equiv.psigmaEquivSigmaPLift π ). symm : {α : Sort ?u.1888} → {β : Sort ?u.1887} → α ≃ β → β ≃ α symm
instance [ Finite α ] [∀ a , Countable ( π a )] : Countable (∀ a , π a ) := by
have : ∀ n , Countable ( Fin n → ℕ ) := by
intro n
induction' n with n ihn
· change Countable ( Fin 0 → ℕ ) ; infer_instance
· haveI := ihn
exact Countable.of_equiv ( ℕ × ( Fin n → ℕ )) ( Equiv.piFinSucc : (n : ℕ ) → (β : Type ?u.2176) → (Fin (n + 1 ) → β ) ≃ β × (Fin n → β ) Equiv.piFinSucc _ _ ). symm : {α : Sort ?u.2180} → {β : Sort ?u.2179} → α ≃ β → β ≃ α symm
rcases Finite.exists_equiv_fin α with ⟨ n , ⟨ e ⟩ ⟩
have f := fun a => ( nonempty_embedding_nat ( π a )). some
exact (( Embedding.piCongrRight : {α : Sort ?u.2300} →
{β : α → Sort ?u.2299 } → {γ : α → Sort ?u.2298 } → ((a : α ) → β a ↪ γ a ) → ((a : α ) → β a ) ↪ (a : α ) → γ a Embedding.piCongrRight f ). trans : {α : Sort ?u.2317} → {β : Sort ?u.2316} → {γ : Sort ?u.2315} → (α ↪ β ) → (β ↪ γ ) → α ↪ γ trans ( Equiv.piCongrLeft' : {α : Sort ?u.2331} →
{β : Sort ?u.2330} → (P : α → Sort ?u.2329 ) → (e : α ≃ β ) → ((a : α ) → P a ) ≃ ((b : β ) → P (↑e .symm b ) ) Equiv.piCongrLeft' _ : ?m.2332 → Sort ?u.2329 _ e ). toEmbedding : {α : Sort ?u.2340} → {β : Sort ?u.2339} → α ≃ β → α ↪ β toEmbedding ). countable
end sort