I am trying to find a bijective function (a map):
$$
f: \mathbb{N}^{n} \to \mathbb{N} \\
f(x_{1}, x_{2}, x_{3},..., x_{n}) = y
$$
That behaves like this:
$f(0, \ 0, \ 0, \ 0, \ ..., \ 0) = A$
$f(1, \ 0, \ 0, \ 0, \ ..., \ 0) = B$
$f(2, \ 0, \ 0, \ 0, \ ..., \ 0) = C$
$...$
$f(W, \ 0, \ 0, \ 0, \ ..., \ 0) = D$
$f(W, \ 1, \ 0, \ 0, \ ..., \ 0) = E$
$f(W, \ 2, \ 0, \ 0, \ ..., \ 0) = F$
$...$
$f(W, \ W, \ 0, \ 0, \ ..., \ 0) = G$
$...$
$f(W, \ W, \ W, \ W, \ ..., \ W) = H$
Where:
- $W \to \infty$
- $A \lt B \lt C \lt \ ... \ \lt D \lt E \lt F \lt \ ... \ \lt G \lt \ ... \ \lt H$
- $A = y_{min}$
- $H = y_{max}$
I know that this is a bit "similar" to how the number base system works
(assume base = $W$, $x_{1}$ would be a number of units, $x_{2}$ a number of tens and so on).
I am aware that the simplest function that fulfills my requirements is:
$$
f(x_{1}, \ x_{2}, \ x_{3}, \ ..., \ x_{n}) = \sum_{i=1}^{n} x_{i} \cdot W^{\left(i - 1\right)}
$$
Unfortunately, there is a problem; this solution doesn't like infinities. And it's rather critical for me to be able to "set" $W = \infty$ (yes, I know that nothing can be equal to $\infty$, "equal" is just to represent a general idea).
I need this because I am trying to implement a tree-like structure in C++ that doesn't restrict me on the number of children a node can have and still allows me to sort the tree in a meaningful way.
Any ideas are more than welcome.
P.S.
- $n$ would be a height of a tree
- $W$ would be a max number of children a node can have,
- $\left(x_{1}, x_{2}, x_{3},..., x_{n}\right)$ are the coordinates on the tree ($x_{1}$ nodes on the 1st level, $x_{2}$ nodes on the 2nd level, etc)
If I understand your function correctly, you want something like the following:
$$f:\mathbb{N\cup\infty}^n \rightarrow \mathbb{N}$$ $$\forall i>0 \in \mathbb{N} f(i,0,\ldots,0)<f(\infty,1,0,\ldots,0)$$
This however is not possible, as the set $\{f(\mathbb{N},0,\ldots,0)\}$ is unbounded, since we have $f(i,0,\ldots,0)\leq f(i+1,0,\ldots,0)+1$, hence $f(i,0\ldots,0)\geq i$.
There is a generalisation of the natural numbers "called the ordinary numbers", which essentially exactly does what you want, but as you want to implement this on C it's probably not helping.
Alternatives that could help you: Change your domain to a subset of $\mathbb{N}$ or change the image to $\mathbb{Q}$