Solving equation set with boolean operators and very specific format

104 Views Asked by At

I have to write a program to solve a set of equations like the following (+ is XOR and * is AND):

b0 = 0 + (a0 * a2)
b1 = 0 + (a0 * a3) + (a1 * a2)
b2 = 0 + (a1 * a3)
b3 = 0

or

b0 = 0 + (a0 * a4)
b1 = 0 + (a0 * a5) + (a1 * a4)
b2 = 0 + (a0 * a6) + (a1 * a5) + (a2 * a4)
b3 = 0 + (a0 * a7) + (a1 * a6) + (a2 * a5) + (a3 * a4)
b4 = 0 + (a1 * a7) + (a2 * a6) + (a3 * a5)
b5 = 0 + (a2 * a7) + (a3 * a6)
b6 = 0 + (a3 * a7)
b7 = 0

each variable b[0-N] and a[0-N] is a single bit. I know the values of all the b variables, and need to find all the possible combinations of the a variables (it is guaranteed to not be more then a few)

The example above is a reduced set. In practice the number of variables changes, but the construction of the equations follows the same pattern.

The pattern is:

for i from 0 to N/2:
  for j from 0 to N/2:
    b[i+j] += a[i]*a[j+N/2]

If someone can give me an idea how to solve automatically even just for a specific case (say for N=3 above), I could probably extrapolate on my own.