Compute all true bytes from boolean expression without testing each possible byte

12 Views Asked by At

Given is a boolean expression $f = f(x_1,x_2,...x_n)$. How do I find all bytes of size $n$ that make $f=1$? I want to do this without having to check for each possible byte of size $n$, see if they result in $f=1$ or $f=0$, and collect the ones that turned out true.

For example, consider the case of a boolean expression which depends on two values, $a$ and $b$, and thus $n=2$. Then for the boolean expression $f = a'.b$, I immediately "know" that there is only one byte that turns this expression true, which is "01". No iterations needed. (Note, I use "." for the logical and, "+" for the logical or, and " ' " for the logical not.)

On the other hand $f = a + b$ would have three bytes that make $f$ true, namely "01", "10", and "11".

What methods exist though so that I could handle larger boolean expressions? To give an example of a larger boolean function that I just worked with: $f(a,b,c,x,y,z) = a'.b'.c' + c'.b'.a.y.x + c'.b.a'.z.y + c.b'.a'.z.x + z.y.x$

I have written a python script, where I create all bytes for 6 bits (a,b,c,x,y,z), and then test each byte to see if the boolean expression turns true. The solution is shown below. (There are 18 true bytes from the boolean expression shown above.)

This process however seems inefficient and unnecessary, and I want to be able to handle much larger boolean expressions. How do I do this without iterating through all possible bytes?

0 0 0 0 0 0
0 0 0 0 0 1
0 0 0 0 1 0
0 0 0 0 1 1
0 0 0 1 0 0
0 0 0 1 0 1
0 0 0 1 1 0
0 0 0 1 1 1
0 0 1 0 1 1
0 0 1 1 1 1
0 1 0 1 1 0
0 1 0 1 1 1
0 1 1 1 1 1
1 0 0 1 0 1
1 0 0 1 1 1
1 0 1 1 1 1
1 1 0 1 1 1
1 1 1 1 1 1