title: Fastest way to find all solutions of the binary equation
body: <p>I am trying to find a good solution for the simple problem (relatively simple). Well, I have a human-created binary equation like this one</p>
  <p><code>A &amp; B &amp; C | D &amp; (E | F) = 1</code></p>
  <p>So there is a set of binary variables (A, B... up to 12 variables) each can be 0 or 1. And some math operators between them (AND, OR) and also brackets.</p>
  <p>I have a large set of (A,B,С...) values (maybe a million or even more) and I need a way to select only those which give 1 on this specific equation.</p>
  <p>I definitely don't want to solve this equation for all items from the given list, this will require lots of CPU resources.</p>
  <p>Instead, I think there is a way to get a set of value vectors which gives 1 to us and then use this set as a hash table.</p>
  <p>May you recommend any method to create such a table of vectors? Any existing algorithm? Thank you.</p>
  <p>Sorry, my English, maybe an example will make things clearer:</p>
  <p>Let's say we got the equation looks like this: <code>A &amp; (B | C)</code> and so the respective list of vectors will be
  101, 110, 111.</p>
  <p>I need a solution to generate this list for the given equation.</p>
  <p><em>Why I need that?</em></p>
  <p>I have developed a fast full-text search algorithm, which works well for phrases too, but now I need to extend it by &quot;OR&quot;, &quot;AND&quot; and braces meta-operators to add some flexibility as Google does.</p>
  <p>For example, if the user entered the query &quot;master and margarita&quot; it will find the word &quot;master&quot; (A) and the word &quot;margarita&quot; (B) in all documents. Thus we have a set of A, B for each document. Next, we have the equation <code>A &amp; B</code> and all we need is just find documents that give 1 for this equation. When the user entered &quot;master OR margarita&quot;, the equation will be &quot;A OR B&quot;, etc.</p>