Create parameterizable map between $\mathbb{Z}$ and $\mathbb{Z}^2$ I would like to create a parameterizable map between $\mathbb{Z}$ and $\mathbb{Z}^2$.  This map I'll call $M$ and the parameter I'll call $k$.  $k \in \mathbb{Z}$ (but if there is a better space for $k$, I'm open to suggestions)


*

*$M(z, k) \rightarrow (x, y)$

*$M^{-1}(x, y, k) \rightarrow z$


The requirements for $M$:


*

*$M$ and $M^{-1}$ are defined for all values in their domains

*For any $(x,y)$ there exists at least one set of values for $z$ and $k$ such that $M(z, k) = (x, y)$


My project
(for those who care about why I want to do this)
I'm a computer programmer, and I'm working on a side project (for fun).  My idea is that I want to build a model of an "entity" inside of an "environment".  
Entity


*

*Input: $z \in \mathbb{Z}$, $c \in \mathbb{R}, [0,1]$

*Output: $z' = z + \Delta z$


$\Delta z$ is calculated based on an internal algorithm that isn't important to the question.
Environment


*

*Internal State: $x, y \in \mathbb{Z}$

*Input (Output From Entity): $z'$

*Output (Input To Entity): $M^{-1}(M(z',k),k) = z$ and $c = e^{-|M(z',k)-p*|}$


** $p*$ is the "most content" state of the environment ($p* = (x*,y*)).
** |...| denotes a distance measurement
Note that $c$ can be any mapping between $[0, \infty] \rightarrow [1, 0]$ (sorry if that notation isn't conventional... 0 maps to 1, and $\infty$ maps to 0... and monotonically decreasing).
The goal of my project is to build an entity to search it's own internal state-space to maximize the contentment value ($c$) it receives from the environment... but it receives a $\mathbb{Z}$ input and it's trying to find the output which maps to a specific value in environment's internal $\mathbb{Z}^2$ space... how it does this will depend on $M$, but I'm confident that I can solve that part if I can find an appropriate (hopefully non-trivial) $M$.
The function $M^{-1}(x,y,k)$ maps a point $(x,y)$ to an integer $z$ which is input to the entity.  In a more "real" model, this would be like the entity's "perspective" of the environment. $k$ in my mind acts like a key, and the entity needs to find the key in order to "solve" the environment to achieve maximum contentment.
My motivation and why I think this is interesting is that any environment that an entity "lives in" has more state than the possible perceptions that an entity has of that environment.  This is a naive attempt to model that observation.  In the future, I'd look to combine multiple entities which are able to "solve" this $\mathbb{Z} \rightarrow \mathbb{Z}^2$ environment setup to "solve" generally an environment setup of $\mathbb{Z} \rightarrow \mathbb{Z}^m$
Attempts to solve the problem
My idea was that I needed some set of hashing functions $H_1$ and $H_2$ which act as an operator between two values in $\mathbb{Z}$.  The two functions I'd need are $H_1(z,k) = x$ and $H_2(z,k) = y$.  Then, I'd need to create inverse functions so that $M(H_1^{-1}(x,k), H_2^{-1}(y,k), k) = z$.
In my existing simulation, I only require one hash from $\mathbb{Z} \rightarrow \mathbb{Z}$ and there is no $k$.  Introducing $k$ was tricky to me and I didn't see an obvious way to do it.
 A: You can define $M_0$ to be a bijection between $\mathbb{Z}$ and $\mathbb{Z}^2$, and then define $M_k(z)=M_0(z+k)$.
For $M_0$ define $M_0(0)=(0,0)$, and for $z\neq0$, $M_0(z)=f\mathopen{}\left(\left\lvert2z\right\rvert-\frac{z}{2\left\lvert z\right\rvert}-\frac12\right)\mathclose{}$ where $f$ is a function from $\mathbb{N}$ to $\mathbb{Z}^2$ defined below.
$f$ maps $\mathbb{N}$ to $\mathbb{Z}^2$ by walking concentric diamonds around the origin. These diamonds have perimeters $4,8,12,16,\ldots$, so $f$ will take $z$ and decide which set $z$ is in from $\{1,\ldots,4\},\{5,\ldots,12\},\{13,\ldots,24\},\{25,\ldots,40\}$, etc. Then it will decide on which edge of the diamond $f(m)$ should lie. Here is how that formula looks.
Define some auxiliary variables $n=\left\lceil\frac{-1+\sqrt{1+2m}}{2}\right\rceil$ (providing us with the $n$th concentric diamond that $f(m)$ lives in), $u=m-(2(n-1)^2+2(n-1))$ (the index of $f(m)$ in the counterclockwise tracing out of the integer points in the $n$th diamond), and $w=\left\lceil\frac{u}{n}\right\rceil$ (telling is which of the four edges $f(m)$ lives in).
And we have $$f(m)=\delta_{w=1}(n+1-u,u-1)+\delta_{w=2}(n+1-u,2n+1-u)+\delta_{w=3}(u-3n-1,2n+1-u)+\delta_{w=4}(u-3n-1,u-4n-1)$$
So here is an example: find $M_3(96)$. This is $M_0(99)$. Which is $f(197)$. With $z=197$, we have $n=10$, $u=17$, and $w=2$. So $f(197)=(10+1-17,20+1-17)=(-6,4)$.
I think it wouldn't be impossible to write an explicit inverse formula for $M_0$, but I'm out of steam to actually think it through. As an outline, first you would identify which quadrant $(x,y)$ is in (counting axis rays as part of the quadrant that is clockwise to them). Then determine which line (having slope $\pm1$) that $(x,y)$ lies on. Then use that line's intercepts to determine which $n$th diamond $(x,y)$ is on. Use that to determine which block $\{1,\ldots,4\},\{5,\ldots,12\},\{13,\ldots,24\},\{25,\ldots,40\}$, etc. that $M_{-1}(x,y)$ lives in. And a few more details to settle on what $M^{-1}(x,y)$ actually is within that block.
