Ordering: Difference between revisions

212 bytes added ,  26 May 2020
Line 28: Line 28:
The is a 1-1 mapping <math>\mathbb{Z}^2 \to \mathbb{Z}</math>.   
The is a 1-1 mapping <math>\mathbb{Z}^2 \to \mathbb{Z}</math>.   


We first derive the function from <math>\mathbb{Z}^2</math> to <math>\mathbb{z}</math> as shown in Figure 2.
We first derive the function from <math>(x,y) \in \mathbb{Z}^2</math> to <math>z \in \mathbb{Z}</math> as shown in Figure 2.
Let <math>(x,y)</math> be the coordinates in <math>\{(0,0), (1, 0), (1,1), ...\}</math> which will map to <math>\({0, 1, 2, ...\}</math>.   
Let <math>(x,y)</math> be the coordinates in <math>\{(0,0), (1, 0), (1,1), ...\}</math> which will map to <math>\({0, 1, 2, ...\}</math>.   
First note that <math>\sum_{0}^{k}i = \frac{(k)(k+1)}{2}</math>.
First note that <math>\sum_{0}^{k}i = \frac{(k)(k+1)}{2}</math>.
Line 40: Line 40:


To calculate the inverse formula:   
To calculate the inverse formula:   
Given an integer <math>z</math>, we want to find <math>(x, y)</math>
Given an integer <math>z</math>, we want to find <math>(x, y)</math>. 
Inverting <math>\frac{x(x+1)}{2}</math>, we get:
<math display="block">
\begin{align}
x &= \left\lfloor \frac{-1 + \sqrt{1+8z}}{2} \right\rfloor\\
y &= z - \frac{x(x+1)}{2}
\end{align}
</math>


The formula is figure 1 is as follows:
The formula is figure 1 is as follows: