I have a table of relations between various foods (each with each). Maybe that could be defined as a matrix. Here is a small 4 x 4 example:
Rice Soup Ice cream Salad
Rice 0 1 2 1
Soup 1 0 2 2
Ice cream 2 2 0 2
Salad 1 2 2 0
(The higher the value/distance, the less the compatibility between foods.)
My question is, is there some way to get out of such a relation table/matrix a unique function/formula?
Maybe such a function could define some pattern how these relations are set?
The first thing to notice is that the elements of a matrix are described by rows and columns and, in your case, are equal to a single integer. So, your function will be of the form $f(x,y)=n$. It would be valid to define the function on a case-by-case basis, for all elements but you can tidy it up slightly.
The matrix is symmetric across the main diagonal, so $f(x,y)=f(y,x)$. The main diagonal is $0$, so $f(x,x)=0$. Aside from that, every element of the matrix is $2$, except for $f(\text{'rice'},\text{'soup'})$, $f(\text{'rice'},\text{'salad'})$ and the corresponding inputs with $x$ and $y$ swapped. This defines the function fully:
$f(x,y)=\begin{cases}0,&y=x \\ 1,&x=\text{'rice'}\ \text{and}\ y=\text{'soup'},\ \text{'salad'} \\ &\text{or} \\&x=\text{'soup'},\ \text{'salad'}\ \text{and}\ y=\text{'rice'} \\ 2,&\text{else} \end{cases}$
The definition would likely be even simpler if the foods are indexed.
Regarding whether there's a unique formula: no, since the function can be expressed in different ways. The function may be unique depending on the definition of the range and domain.