I'm looking for a bijection from N to N×N×N.
- I know it exists
- I know an informal way to define one, ordering the triplets of natural numbers in a 3D array an counting them diagonally as they do here with 2D array.
- And I know a bijection from N×N×N to N from this answer which uses factorization
But how to write it explicitly?
Thank you very much.
Answer
Use Cantor's pairing function ⟨⋅,⋅⟩:N×N→N twice: (a,b,c)↦⟨⟨a,b⟩,c⟩. Cantor's pairing function has an inverse which is easily-stated if a bit fiddly (see the proof of bijectivity on the linked Wikipedia page).
No comments:
Post a Comment