逻辑:是(A&!(B || C))|| (B || C)与(A || B || C)相同吗? [英] Logic: is ( A && !(B || C)) || ( B || C ) the same as ( A || B || C )?

查看:72
本文介绍了逻辑:是(A&!(B || C))|| (B || C)与(A || B || C)相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些obj-c代码,我想知道是否有一种方法可以简化它:

I've encountered some obj-c code and I'm wondering if there's a way to simplify it:

#if ( A && !(B || C)) || ( B || C )

这和吗?

#if ( A || B || C )

如果没有,还有另一种表达方式更容易阅读吗?

If not, is there another way to formulate it that would be easier to read?

在提出问题之前,我尝试过使用真值表,但由于我怀疑Foundation.framework/Foundation.h是否会采用这种更复杂的形式,因此我不得不错过一些东西.有充分的理由吗?

[edit] I tried the truth table before asking the question, but thought I had to be missing something because I doubted that Foundation.framework/Foundation.h would employ this more complex form. Is there a good reason for it?

这是原始代码(来自Foundation.h):

Here's the original code (from Foundation.h):

#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)

推荐答案

是.就像其他人说的那样,您可以对它进行表述. De Morgan规则也可以提供帮助.

Yes. Like others said, you can truth table it. The De Morgan rules can also help.

但是,我认为最好的选择是使用 Karnaugh地图.它需要花费几分钟的时间进行学习,但是Karnaugh Maps允许您始终为布尔逻辑找到最小的表达式.真值表可以验证最小化,但无法将其提供给您.

However, I think the best option is to use a Karnaugh Map. It takes a few minutes to learn, but Karnaugh Maps allow you to consistently find the most minimal expression for boolean logic. Truth tables can verify a minimization, but they can't give it to you.

这是我的方法:

首先,表格布局:

         AB
     00   01   11   10
  0|    |    |    |    |
C 1|    |    |    |    |

现在,考虑您的方程B || C总是会导致一个事实:

Now, considering your equation, B || C will always cause a truth:

         AB
     00   01   11   10
  0|    |  T |  T |    |
C 1|  T |  T |  T |  T |

这只剩下两种情况.在这两种情况下,右侧的结果均为false.对于000,左侧也将计算为false(0&!(无论如何)为false).对于100,1&& !(0 ||| 0)计算为true.因此,该说法是正确的.填写:

This leaves only two cases. In either case, the right side evaluates to false. For 000, the left side also evaluates to false (0 && !(whatever) is false). For 100, 1 && !(0 ||| 0) evaluates to true. Thus, the statement is true. Filling in:

         AB
     00   01   11   10
  0|  F |  T |  T |  T |
C 1|  T |  T |  T |  T |

现在,我们只需要掩盖"所有事实. "C"将覆盖底部的行. "B"将覆盖中间的正方形(四个值).因此,"B || C"覆盖了除右上角正方形以外的所有区域.现在,"A"将覆盖右边的四个空格的正方形.可以,这是多余的.因此,"A || B || C"覆盖了所有真实的正方形,并省略了唯一的错误正方形.

Now, we only need to "cover" all the truths. "C" will cover the bottom row. "B" will cover the middle square (of four values). Thus, "B || C" covers all but the top right square. Now, "A" will cover the right four-space square. It's OK that this is redundant. Thus, "A || B || C" covers all the true squares and omits the only false one.

这篇关于逻辑:是(A&!(B || C))|| (B || C)与(A || B || C)相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆