好懂的Quine-McCluskey算法

下文的大字.html版 3KB

我们有4个逻辑变量a,b,c,d, 要用它们造出一个输出y来,即y=f(a,b,c,d). 

先看简单的例子: f(0000)=1, f(0001)=1, f(其它)=0.

当abcd=0000时,~a & ~b & ~c & ~d = 1. 当abcd=0001时,~a & ~b & ~c & d = 1. 
1) 4个数and起来是1 => 它们都是1. 
2) 看到0写~a, 1写a. b,c,d依次类推,如上面abcd=0001时的情况。

f=(~a & ~b & ~c & ~d) | (~a & ~b & ~c & d)即为所求…………吗?
        m(0)                   m(1)
        
首先证明它正确。显然, 当abcd=0000或0001时,f为1。当abcd取其它值时,m(0)和m(1)中4个要去&的东西,必然至少有一个是0,从而导致m(0)和m(1)都是0,最终f = 0 | 0 = 0.

其次Quine-McCluskey Algorithm可以找到最简的式子,如何证明我不知道,反正大家都这么说。:-)

1) m代表minterm(最小项). m(6)=m(0110), 依次类推。
2) m(x)|m(x) = m(x), m(0)|m(8) = m(0)|m(0)|m(8)诸如此类——增是为了简,这是多么深刻的道理。:-)

看个复杂的例子。我们把真值表列出来,不用列出完整的16行(2**4),仅列出输出为1的行即可:
a b c d  abcd中的1的个数
0 0 0 0  0
0 1 0 0  1
0 1 0 1  2
0 1 1 1  3
1 0 0 0  1
1 0 1 1  3
1 1 0 0  2
1 1 1 1  4

or是不讲究顺序的。我们按照1的个数对行排序和分组: O(n * log(n))
a b c d  1的个数  minterm
0 0 0 0  0        (~a & ~b & ~c & ~d) = (~a & ~c & ~d & ~b) = (tuo & ~b)
0 1 0 0  1        (~a & b & ~c & ~d) = (~a & ~c & ~d & b) = (tuo & b)
1 0 0 0  1        
0 1 0 1  2
1 1 0 0  2
0 1 1 1  3
1 0 1 1  3
1 1 1 1  4

(tuo & ~b) | (tuo & b) = tuo & (b | ~b) = tuo. 此例tuo = ~a & ~c & ~d. 有纸没纸都得那啥啊。:-)
或者说:
0 0 0 0
0 1 0 0
+ + + +
0 1 0 0  结果为1的可以被化简掉,下面用-表示。- plus - = -, 已经化简掉了嘛。

中间结果:
groups minterm    a b c d  used
0-1     m(0, 4)   0 - 0 0  yes
        m(0, 8)   - 0 0 0  yes
1-2     m(4, 5)   0 1 0 -  no
        m(4, 12)  - 1 0 0  yes
        m(8, 12)  1 - 0 0  yes
2-3     m(5, 7)   0 1 - 1  no
3-4     m(7, 15)  - 1 1 1  no
        m(11, 15) 1 - 1 1  no
        
The 'used' column keeps track of whether we used the minterm when combining the minterms. 这列是不断更新的。m(5)和m(7)形成m(5,7)后就不再被use了。

groups列中的数代表0或1的个数。m(0,4)代表m(0)|m(4).

        m(0, 4)   0 - 0 0
        m(8, 12)  1 - 0 0
        +++++++++++++++++
                  - - 0 0
                  
        m(0, 8)   - 0 0 0
        m(4, 12)  - 1 0 0
        +++++++++++++++++
                  - - 0 0
                  
不是- plus x = -,如m(7,15)=(b&c&d), m(11,15)=(a&c&d), (b&c&d)|(a&c&d)不等于(c&d),如abcd=0011时。

m(0,4,8,12) | m(0,8,4,12)  = m(0,4,8,12) = (~c & ~d), 代表了m(0),m(4),m(8)和m(12).

m(4)|m(5)|m(7)|m(11)|m(15) = m(4,5)|m(5,7)|m(7,15)|m(11,15),把它们列在下面:

        m(4, 5)   0 1 0 -
        m(5, 7)   0 1 - 1
        m(7, 15)  - 1 1 1
        m(11, 15) 1 - 1 1

From the minterms that aren't used, we create a table with the variables on the left and the
values from the function at the beginning on the right. 下表有5行,
m(0,4,8,12), m(4,5), m(5,7), m(7,15), m(11,15):

a  b  c  d  0  4  5  7  8  11  12  15
     ~c ~d  X  X        X       X     m(0,4,8,12)
~a b ~c        X  X                   m(4,5)
~a b     d        X  X                m(5,7)
   b  c  d           X              X m(7,15)
a     c  d                 X        X m(11,15)

Once we have this table setup, we look for the "essential prime implicants". When we find them,
we go to the row and add it to our final expression.

答案: m(0,4,8,12)|m(5,7)|m(11,15) = (~c & ~d)|(~a & b & d)|(a & c & d)
0 4 5 7 8 11 12 15都出现了。

f(0)=1, f(其它)=0 和 f(any)=1是不一样的。
译自 replit.com
Minimizing Boolean functions by hand using the classical Karnaugh maps is a laborious, tedious and error prone process. It isn't suited for more than six input variables and practical only for up to four variables. The first alternative method to become popular was the tabular method developed by Willard Quine and Edward McCluskey. Although this Quine-McCluskey algorithm is very well suited to be implemented in a computer program, the result is still far from efficient in terms of processing time and memory usage. Adding a variable to the function will roughly double both of them, because the truth table length increases exponentially with the number of variables. A different approach to this issue is followed in the Espresso algorithm...
posted @ 2021-12-27 21:02  Fun_with_Words  阅读(628)  评论(0编辑  收藏  举报









 张牌。