Finding the smallest common denominator
<p>I have the following problem. I have a arrays of <code>L</code> binary entries.(<code>L</code> is usually between 2 and 8 if it is of interest.) All possible combinations do exist. So there are <code>2^L</code> arrays in one realisation. Now each combination will get randomly a fitness value assigned. The fitness value is also either <code>1</code> or <code>0</code>. Now for example it could be, that the following arrays have fitness value <code>0</code>:</p>

<pre><code>1000
1010
1100
1001
1011
</code></pre>

<p>Then it is true, that all arrays with a <code>10__</code> are zero and all with <code>1_00</code>. This is actually my problem. I need an algorithm which find these similarities and sort them for their rank. Like <code>10__</code> is of rank <code>2</code> and <code>1_00</code> is of rank <code>3</code>. It is most of the time possible to define all arrays with zero fitness either with a small number of low ranks or with many high ranks. So my output must be ordered and I need to know how many I have of each rank. I can imagine that this is a known problem and there is already a solution?  I hope you can help :) </p>

<p>Assuming that this <code>fitness value</code> may depend of the value of each bit in your binary entry, and that you're searching the rules that can sum up your truth table (I'm not sure I understood your question very well about this point), You could use something like a <a href="https://en.wikipedia.org/wiki/Karnaugh_map" rel="nofollow">Karnaugh map</a></p>

<p>These maps work like this :</p>

<p>You list your factors (here value of 1st bit, 2nd bit...) and separate them in two lists (one for the rows, one for the columns).</p>

<p>Order each list with a <a href="https://en.wikipedia.org/wiki/Gray_code" rel="nofollow">Gray Code</a>.</p>

<p>Use the set of values for each list for respectively columns and rows in a table.</p>

<p>You know have a table that represent every possibilities of values for your binary entries.</p>

<p>Then, you list the fitness values for each entry in your table (1 or 0).</p>

<p>Then you'll have to make groups of Trues values (or false) in your table and that will permit you to find the rule for this group (by finding the common caracteristics). You usually group these by squares, or by corners (cf. first wikipedia link).</p>

<h2>Here is a (simple) example with 3 bit entries :</h2>

<p>Assuming you have the following Truth table :</p>

<pre><code>ABC|R
-----
000|0
001|0
010|1
011|1
100|1
101|0
110|1
111|1
</code></pre>

<p>You can establish the following Karnaugh table :</p>

<pre><code>        AB
  |     00 |     01 |     11 |     10   &lt;-- AB
--------------------------------------
0 |      0 | (1)  1 | (1)  1 | (2)  1
--------------------------------------
1 |      0 | (1)  1 | (1)  1 |      0

^
|
C
</code></pre>

<ul>
<li><p>You can group the 4 in the middle, these 4 have all B True, but A and C may be True or False, so you can sum it up like this :</p>

<p>(1) <code>B -&gt; R</code></p></li>
<li><p>You also have the one on the top right :</p>

<p>(2) <code>A and !B and !C -&gt; R</code></p></li>
</ul>

<p>So your rule in this case is :</p>

<pre><code>B or (A and !B and !C) -&gt; R
</code></pre>

<p>As I mentionned in my comment, I am not sure about what you really want to achieve. But if you're trying to find some simple rules to sum up your truth table, maybe listing the rules found with this step is enough?</p>

<p>I have no python implementation to provide but you may find some on the internet. :) At least you can do it with paper and pencil now. :)</p>

<p>Feel free to ask if something isn't clear!</p>

<p>Here is one of the many tutorials you can find on the internet :</p>

<p><a href="http://www.facstaff.bucknell.edu/mastascu/eLessonsHTML/Logic/Logic3.html" rel="nofollow">http://www.facstaff.bucknell.edu/mastascu/eLessonsHTML/Logic/Logic3.html</a></p>

<p><strong>PS :</strong></p>

<p><code>B</code> means that B is true, and <code>!B</code> means it's false.</p>

<p><strong>PS-2 :</strong></p>

<p>You can also use Boole algebra to reduce your rules.</p>

python