Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat: port Logic.Equiv.Nat #1227

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Equiv.Embedding
import Mathlib.Logic.Equiv.LocalEquiv
import Mathlib.Logic.Equiv.MfldSimpsAttr
import Mathlib.Logic.Equiv.Nat
import Mathlib.Logic.Equiv.Option
import Mathlib.Logic.Equiv.Set
import Mathlib.Logic.Function.Basic
Expand Down
21 changes: 10 additions & 11 deletions Mathlib/Logic/Equiv/Nat.lean
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ namespace Equiv

variable {α : Type _}

/-- An equivalence between `bool × ℕ` and `ℕ`, by mapping `(tt, x)` to `2 * x + 1` and `(ff, x)` to
`2 * x`.
-/
/-- An equivalence between `Bool × ℕ` and `ℕ`, by mapping `(true, x)` to `2 * x + 1` and
`(false, x)` to `2 * x`. -/
@[simps]
def boolProdNatEquivNat : Bool × ℕ ≃
ℕ where
toFun := uncurry bit
invFun := boddDiv2
left_inv := fun ⟨b, n⟩ => by simp only [bodd_bit, div2_bit, uncurry_apply_pair, bodd_div2_eq]
right_inv n := by simp only [bit_decomp, bodd_div2_eq, uncurry_apply_pair]
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]
#align equiv.bool_prod_nat_equiv_nat Equiv.boolProdNatEquivNat

/-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(sum.inl x)` to `2 * x` and `(sum.inr x)` to
/-- An equivalence between `ℕ ⊕ ℕ` and `ℕ`, by mapping `(Sum.inl x)` to `2 * x` and `(Sum.inr x)` to
`2 * x + 1`.
-/
@[simps symmApply]
def natSumNatEquivNat : Sum ℕ ℕ ≃ ℕ :=
@[simps symm_apply]
def natSumNatEquivNat : ℕ ⊕ ℕ ≃ ℕ :=
(boolProdEquivSum ℕ).symm.trans boolProdNatEquivNat
#align equiv.nat_sum_nat_equiv_nat Equiv.natSumNatEquivNat

set_option linter.deprecated false in
@[simp]
theorem nat_sum_nat_equiv_nat_apply : ⇑nat_sum_nat_equiv_nat = Sum.elim bit0 bit1 := by
theorem natSumNatEquivNat_apply : ⇑natSumNatEquivNat = Sum.elim bit0 bit1 := by
ext (x | x) <;> rfl
#align equiv.nat_sum_nat_equiv_nat_apply Equiv.nat_sum_nat_equiv_nat_apply
#align equiv.nat_sum_nat_equiv_nat_apply Equiv.natSumNatEquivNat_apply

/-- An equivalence between `ℤ` and `ℕ`, through `ℤ ≃ ℕ ⊕ ℕ` and `ℕ ⊕ ℕ ≃ ℕ`.
-/
Expand All @@ -63,7 +63,6 @@ def prodEquivOfEquivNat (e : α ≃ ℕ) : α × α ≃ α :=
α × α ≃ ℕ × ℕ := prodCongr e e
_ ≃ ℕ := mkpairEquiv
_ ≃ α := e.symm

#align equiv.prod_equiv_of_equiv_nat Equiv.prodEquivOfEquivNat

end Equiv