Naturals pairing function #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file defines a pairing function for the naturals as follows:
0 1 4 9 16
2 3 5 10 17
6 7 8 11 18
12 13 14 15 19
20 21 22 23 24
It has the advantage of being monotone in both directions and sending ⟦0, n^2 - 1⟧
to
⟦0, n - 1⟧²
.
@[simp]
An equivalence between ℕ × ℕ
and ℕ
.
Equations
- nat.mkpair_equiv = {to_fun := function.uncurry nat.mkpair, inv_fun := nat.unpair, left_inv := nat.mkpair_equiv._proof_1, right_inv := nat.mkpair_unpair}
@[simp]
theorem
nat.mkpair_lt_mkpair_left
{a₁ a₂ : ℕ}
(b : ℕ)
(h : a₁ < a₂) :
nat.mkpair a₁ b < nat.mkpair a₂ b
theorem
nat.mkpair_lt_mkpair_right
(a : ℕ)
{b₁ b₂ : ℕ}
(h : b₁ < b₂) :
nat.mkpair a b₁ < nat.mkpair a b₂
theorem
nat.max_sq_add_min_le_mkpair
(m n : ℕ) :
linear_order.max m n ^ 2 + linear_order.min m n ≤ nat.mkpair m n