介绍
复习数字逻辑课上学到的卡诺图,这一种是化简逻辑表达式的工具
用法示例
假设有一个四变量的逻辑表达式 Y(A, B, C, D) 为:
\begin{align*}
Y & = \sum m(2, 4, 6, 10, 11, 14, 15) \\
& = m_2 + m_4 + m_6 + m_{10} + m_{11} + m_{14} + m_{15} \\
& = A'B'CD' + A'BC'D' + A'BCD' \\
& \qquad + AB'CD' + AB'CD + ABCD' + ABCD
\end{align*}
\sum m 的写法叫做逻辑函数的最小项之和形式
画出四变量最小项的卡诺图,对应函数式中各最小项的位置填 1,其余位置填 0,得到 Y 的卡诺图:
<style>
table#my_table.use_my_css {
--td-width: 3em;
--td-height: 1.5em;
border-collapse: collapse;
min-width: 0;
width: calc(6 * var(--td-width));
height: calc(6 * var(--td-height));
margin: auto;
display: block;
border: none;
}
table#my_table.use_my_css th,
table#my_table.use_my_css td {
font-weight: normal;
width: var(--td-width);
height: var(--td-height);
line-height: var(--td-height);
padding: 0;
color: #000;
background-color: #fff;
border: 1px solid #000;
text-align: center;
}
table#my_table.use_my_css tr:nth-of-type(4) td:nth-of-type(3) { position: relative; }
table#my_table.use_my_css tr:nth-of-type(4) td:nth-of-type(3)::after {
content: "";
display: block;
width: calc(2 * var(--td-width));
height: calc(2 * var(--td-height));
position: absolute;
border: 1.5px dashed #f60;
top: 2px;
left: 2px;
z-index: 1;
}
table#my_table.use_my_css tr:nth-of-type(2) td:nth-of-type(4) { position: relative; }
table#my_table.use_my_css tr:nth-of-type(2) td:nth-of-type(4)::after {
content: "";
display: block;
width: calc(1 * var(--td-width) - 6px);
height: calc(4 * var(--td-height) - 4px);
position: absolute;
border: 1.5px dashed #6f0;
top: 2px;
left: 2px;
z-index: 1;
}
table#my_table.use_my_css tr:nth-of-type(3) td:nth-of-type(1),
table#my_table.use_my_css tr:nth-of-type(3) td:nth-of-type(4) { position: relative; }
table#my_table.use_my_css tr:nth-of-type(3) td:nth-of-type(1)::after,
table#my_table.use_my_css tr:nth-of-type(3) td:nth-of-type(4)::after {
content: "";
display: block;
width: calc(1 * var(--td-width) - 6px);
height: calc(1 * var(--td-height) - 6px);
position: absolute;
border: 1.5px dashed #60f;
top: 2px;
left: 2px;
z-index: 1;
}
</style>
<table id="my_table" class="use_my_css">
<tr> <th>Y</th> <th>C'D'</th> <th>C'D</th> <th>CD</th> <th>CD'</th> </tr>
<tr> <th>A'B'</th> <td>0</td> <td>0</td> <td>0</td> <td>1</td> </tr>
<tr> <th>A'B</th> <td>1</td> <td>0</td> <td>0</td> <td>1</td> </tr>
<tr> <th>AB</th> <td>0</td> <td>0</td> <td>1</td> <td>1</td> </tr>
<tr> <th>AB'</th> <td>0</td> <td>0</td> <td>1</td> <td>1</td> </tr>
</table>
卡诺图将真值表中的信息以一种特殊的排列方式组合在一个二维网格中
逻辑变量 A、B 和 C、D 的取值在表头中的排列顺序是 00,01,11,10 (而不是 00,01,10,11),这保证了图中几何位置相邻的最小项在逻辑上也具有相邻性
上图中的蓝色框部分,A'BC'D' 和 A'BCD' 具有逻辑相邻性,合并消掉 C 和 C',化简为 A'BD'。同理,红色框部分化简为 AC,绿色框部分化简为 CD',最终得
Y = A'BD' + AC + CD'
附
Q: 如何用 HTML 与 CSS 绘制卡诺图表格?
A: 我猜你是想知道我怎么画的虚线框。我使用 :nth-of-type
选中单元格,并使用 ::after
绘制虚线框
<style>
/* 表格基本样式 */
#my_table {
--td-width: 3em;
--td-height: 1.5em;
border-collapse: collapse;
}
#my_table th,
#my_table td {
font-weight: normal;
width: var(--td-width);
height: var(--td-height);
line-height: var(--td-height);
padding: 0;
color: #000;
background-color: #fff;
border: 1px solid #000;
text-align: center;
}
/* 红色虚线框 */
#my_table tr:nth-of-type(4) td:nth-of-type(3) { position: relative; }
#my_table tr:nth-of-type(4) td:nth-of-type(3)::after {
content: "";
display: block;
width: calc(2 * var(--td-width));
height: calc(2 * var(--td-height));
position: absolute;
border: 1.5px dashed #f60;
top: 2px;
left: 2px;
z-index: 1;
}
/* 绿色虚线框 */
#my_table tr:nth-of-type(2) td:nth-of-type(4) { position: relative; }
#my_table tr:nth-of-type(2) td:nth-of-type(4)::after {
content: "";
display: block;
width: calc(1 * var(--td-width) - 6px);
height: calc(4 * var(--td-height) - 4px);
position: absolute;
border: 1.5px dashed #6f0;
top: 2px;
left: 2px;
z-index: 1;
}
/*蓝色虚线框 */
#my_table tr:nth-of-type(3) td:nth-of-type(1),
#my_table tr:nth-of-type(3) td:nth-of-type(4) { position: relative; }
#my_table tr:nth-of-type(3) td:nth-of-type(1)::after,
#my_table tr:nth-of-type(3) td:nth-of-type(4)::after {
content: "";
display: block;
width: calc(1 * var(--td-width) - 6px);
height: calc(1 * var(--td-height) - 6px);
position: absolute;
border: 1.5px dashed #60f;
top: 2px;
left: 2px;
z-index: 1;
}
</style>
<!-- 卡诺图表格 -->
<table id="my_table">
<tr><th>Y</th> <th>C'D'</th> <th>C'D</th><th>CD</th><th>CD'</th></tr>
<tr><th>A'B'</th><td>0</td> <td>0</td> <td>0</td> <td>1</td> </tr>
<tr><th>A'B</th> <td>1</td> <td>0</td> <td>0</td> <td>1</td> </tr>
<tr><th>AB</th> <td>0</td> <td>0</td> <td>1</td> <td>1</td> </tr>
<tr><th>AB'</th> <td>0</td> <td>0</td> <td>1</td> <td>1</td> </tr>
</table>