# Find the binary input function given the outputs (part 2)

Here we have three binary variables $$x_1$$, $$x_2$$, $$x_3$$ $$\in \{0,1\}$$.
I want to find the form of the function $$f(x_1, x_2, x_3)$$ such that the following are satisfied:

if $$\ x_1 = 0,\ x_2 = 0,\ x_3 = 0 \$$ then $$\ f(x_1, x_2, x_3) = 6$$
if $$\ x_1 = 0,\ x_2 = 0,\ x_3 = 1 \$$ then $$\ f(x_1, x_2, x_3) = 4$$
if $$\ x_1 = 0,\ x_2 = 1,\ x_3 = 0 \$$ then $$\ f(x_1, x_2, x_3) = 5$$
if $$\ x_1 = 0,\ x_2 = 1,\ x_3 = 1 \$$ then $$\ f(x_1, x_2, x_3) = 2$$
if $$\ x_1 = 1,\ x_2 = 0,\ x_3 = 0 \$$ then $$\ f(x_1, x_2, x_3) = 5$$
if $$\ x_1 = 1,\ x_2 = 0,\ x_3 = 1 \$$ then $$\ f(x_1, x_2, x_3) = 3$$
if $$\ x_1 = 1,\ x_2 = 1,\ x_3 = 0 \$$ then $$\ f(x_1, x_2, x_3) = 4$$
if $$\ x_1 = 1,\ x_2 = 1,\ x_3 = 1 \$$ then $$\ f(x_1, x_2, x_3) = 0$$

I imagine it like having a "virtual sum" which starts at 1 and it is increased by 1 at each step in the sequence. Every time I see a zero, this virtual sum "becomes real" and is reset. For instance:

• $$\ x_1 = 1,\ x_2 = 1,\ x_3 = 0 \$$ After seeing the first one the virtual sum is 2. After the second one the virtual sum is 3. Finally there is a zero, so the virtual sum becomes 4, "becomes real" and is reset. The final result is 4.
• $$\ x_1 = 0,\ x_2 = 1,\ x_3 = 0 \$$ After seeing the first zero the sum is 2 and the virtual sum is reset to 1. After the second one the virtual sum is 2. Finally there is a zero, so the virtual sum is incremented at 3 and "becomes real". The final result is 2 + 3 = 5.
• $$\ x_1 = 1,\ x_2 = 1,\ x_3 = 1 \$$ We have three ones, so the virtual sum is 4 at the end of the sequence. However, since there are no zeroes it does not "become real" and the result is 0.
• $$\ x_1 = 0,\ x_2 = 0,\ x_3 = 0 \$$ We have three zeroes, so we get 2 at each step and the sum is 6.

I had already asked a similar question (Find the binary input function given the outputs), which was (brilliantly) solved. This is a generalisation in which the "virtual sum" starts from one rather then zero and that, with respect to the previous question, inverts the binary value of the variables $$x_1$$, $$x_2$$, $$x_3$$.

How about (completed) $$f(x_1,x_2,x_3) = 6\cdot (1-x_1)(1-x_2)(1-x_3) + 4\cdot (1-x_1)(1-x_2)x_3 \\+ 5\cdot (1-x_1)x_2(1-x_3) + 2\cdot (1-x_1)x_2x_3 +5\cdot x_1(1-x_2)(1-x_3) + 3\cdot x_1(1-x_2)x_3 + 4\cdot x_1x_2(1-x_3) + 0\cdot x_1x_2x_3.$$
• Is the complete formula $f(x_1,x_2,x_3) = 6(1-x_1)(1-x_2)(1-x_3) + 4(1-x_1)(1-x_2)x_3 + 2(1-x_1)x_2x_3$? Because it doesn't work for many inputs. Try (0,1,0) for example. – aprospero Jan 16 '19 at 16:26