Module docstring
{"# Equivalences involving ℕ
This file defines some additional constructive equivalences using Encodable and the pairing
function on ℕ.
"}
{"# Equivalences involving ℕ
This file defines some additional constructive equivalences using Encodable and the pairing
function on ℕ.
"}
Equiv.boolProdNatEquivNat
definition
: Bool × ℕ ≃ ℕ
/-- An equivalence between `Bool × ℕ` and `ℕ`, by mapping `(true, x)` to `2 * x + 1` and
`(false, x)` to `2 * x`. -/
@[simps]
def boolProdNatEquivNat : BoolBool × ℕBool × ℕ ≃ ℕ where
toFun := uncurry bit
invFun := boddDiv2
left_inv := fun ⟨b, n⟩ => by simp only [bodd_bit, div2_bit, uncurry_apply_pair, boddDiv2_eq]
right_inv n := by simp only [bit_decomp, boddDiv2_eq, uncurry_apply_pair]
Equiv.natSumNatEquivNat
definition
: ℕ ⊕ ℕ ≃ ℕ
/-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(Sum.inl x)` to `2 * x` and `(Sum.inr x)` to
`2 * x + 1`.
-/
@[simps! symm_apply]
def natSumNatEquivNat : ℕℕ ⊕ ℕℕ ⊕ ℕ ≃ ℕ :=
(boolProdEquivSum ℕ).symm.trans boolProdNatEquivNat
Equiv.natSumNatEquivNat_apply
theorem
: ⇑natSumNatEquivNat = Sum.elim (2 * ·) (2 * · + 1)
@[simp]
theorem natSumNatEquivNat_apply : ⇑natSumNatEquivNat = Sum.elim (2 * ·) (2 * · + 1) := by
ext (x | x) <;> rfl
Equiv.intEquivNat
definition
: ℤ ≃ ℕ
/-- An equivalence between `ℤ` and `ℕ`, through `ℤ ≃ ℕ ⊕ ℕ` and `ℕ ⊕ ℕ ≃ ℕ`.
-/
def intEquivNat : ℤℤ ≃ ℕ :=
intEquivNatSumNat.trans natSumNatEquivNat
Equiv.prodEquivOfEquivNat
definition
(e : α ≃ ℕ) : α × α ≃ α
/-- An equivalence between `α × α` and `α`, given that there is an equivalence between `α` and `ℕ`.
-/
def prodEquivOfEquivNat (e : α ≃ ℕ) : α × αα × α ≃ α :=
calc
α × α ≃ ℕ × ℕ := prodCongr e e
_ ≃ ℕcalc
α × α ≃ ℕ × ℕ := prodCongr e e
_ ≃ ℕ := pairEquiv
_ ≃ α := e.symm