It is trivially possible to create a bijective function from \$\mathbb{Z}\$ (the set of all integers) to \$\mathbb{Z}\$ (e.g. the identity function).
It is also possible to create a bijective function from \$\mathbb{Z}\$ to \$\mathbb{Z}^2\$ (the set of all pairs of 2 integers; the cartesian product of \$\mathbb{Z}\$ and \$\mathbb{Z}\$). For example, we could take the lattice representing integer points on a 2D plane, draw a spiral from 0 outwards, and then encode pairs of integers as the distance along the spiral when it intersects that point.
(A function which does this with natural numbers is known as a pairing function.)
In fact, there exists a family of these bijective functions:
$$f_k(x) : \mathbb{Z} \to \mathbb{Z}^k$$
The Challenge
Define a family of functions \$f_k(x)\$ (where \$k\$ is a positive integer) with the property that \$f_k(x)\$ bijectively maps integers to \$k\$-tuples of integers.
Your submission should, given inputs \$k\$ and \$x\$, return \$f_k(x)\$.
This is code-golf, so the shortest valid answer (measured in bytes) wins.
Specifications
- Any family \$f_k(x)\$ can be used as long as it fulfills the above criteria.
- You are encouraged to add a description of how your function family works, as well as a snippet to compute the inverse of the function (this is not included in your byte count).
- It is fine if the inverse function is uncomputable, as long as you can prove it the function is bijective.
- You can use any suitable representation for signed integers and lists of signed integers for your language, but you must allow inputs to your function to be unbounded.
- You only need to support values of \$k\$ up to 127.
k
andx
instead of integers? \$\endgroup\$