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) = 0$
if $\ x_1 = 0,\ x_2 = 0,\ x_3 = 1 \ $ then $\ f(x_1, x_2, x_3) = 3$
if $\ x_1 = 0,\ x_2 = 1,\ x_3 = 0 \ $ then $\ f(x_1, x_2, x_3) = 2$
if $\ x_1 = 0,\ x_2 = 1,\ x_3 = 1 \ $ then $\ f(x_1, x_2, x_3) = 3$
if $\ x_1 = 1,\ x_2 = 0,\ x_3 = 0 \ $ then $\ f(x_1, x_2, x_3) = 1$
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) = 2$
if $\ x_1 = 1,\ x_2 = 1,\ x_3 = 1 \ $ then $\ f(x_1, x_2, x_3) = 3$
I imagine it like having a "virtual sum" which is increased by one each step in the sequence. Every time I see a one, this virtual sum "becomes real" and is zeroed. For instance:
- $\ x_1 = 0,\ x_2 = 0,\ x_3 = 1 \ $. After seeing the first zero the virtual sum is 1. After the second zero the virtual sum is 2. Finally there is a one, so the virtual sum becomes 3 and is reset. The final result is 3.
- $\ x_1 = 0,\ x_2 = 0,\ x_3 = 0 \ $ We have three zero, so the virtual sum is 3 at the end of the sequence. However, since there are no ones it does not "become real" and the result is 0.
In the two variables case it is enough to write $f(x_1, x_2) = x_1 + x_2$, but in higher dimensions things start to become more difficult.