These functions are incredibly useful for anyone wanting to set up
enumeration schemes, and in general give a single number for every
coordinate in an infinite space.
They follow as:
pair[x_, y_] := (x^2 + x + 2x y + 3y + y^2)/2
this number can be transformed back into the original two numbers by:
unpair[z_] := With[{i = Floor[-1/2 + (Sqrt[1 + 8 z])/2]}, {1/2 i (3 + i) - z, -1/2 i (1 + i) + z}]
This can be used to enumerate all state configurations of multiple
infinitely growing paramaters. You can think of it as a way of growing
towers so that every configuration of tower height is visited and has a
unique number for it.
this function is only designed for two parameters but one can imagine a
kind folding that pairs many parameters together by successively
combining your set of numbers. Such a function can be constructed. One
implementation of this is as follows:
Combine[sequence__] := Fold[pair[#2, #1] &, First@{sequence}, Rest@{sequence}]
To uncombine a number into a set of other numbers, the number of
parameters must be specified. Here is the code for that:
Uncombine[number_, numParams_] := Reverse[Nest[Flatten[{Most@Flatten@{#}, unpair[Last[Flatten@{#}]]}] &, Last@{number}, numParams - 1]]
- Parameters:
paired
- components
-
- Returns:
- return the elements.