I have a ANTLR expression parser which can evaluate expressions of the form ( A & ( B | C ) ) using the generated visitor. A , B and C can take any of the 2 values true
or false
. However I am faced with a challenge of finding all combinations of A,B and C for which the expression is true. I tried to solve this by the following method.
- Evaluate the expression for the 3 variables taking true and false each
- This comes to 8 combinations since 2 ^ 3 is 8
- I evaluate giving values like 000, 001, 010 ....... 111 to the variables and evaluate using the visitor
Though this works this method becomes compute intensive as the number of variables increases. Hence for an expression with 20 variables 1048576 computations are required. How can I optimise this complexity so that I get all the true expressions ? I hope this falls under Boolean satisfiabilty problem