重构布尔方程

发布于 2024-07-23 06:47:46 字数 321 浏览 5 评论 0原文

假设您有一个布尔规则/表达式,如下所示

(A OR B) AND (D OR E) AND F

您希望将其转换为尽可能多的 AND only 表达式,例如

A AND D AND F
A AND E AND F
B AND D AND F
B AND E AND F

您只是减少 OR,使其变为

(A AND D AND F) OR (A AND E AND F) OR (...)

布尔代数中是否有一个属性可以做到这一点?

Let's say you have a Boolean rule/expression like so

(A OR B) AND (D OR E) AND F

You want to convert it into as many AND only expressions as possible, like so

A AND D AND F
A AND E AND F
B AND D AND F
B AND E AND F

You are just reducing the OR's so it becomes

(A AND D AND F) OR (A AND E AND F) OR (...)

Is there a property in Boolean algebra that would do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

记忆消瘦 2024-07-30 06:47:47

您的示例正在利用 AND 相对于 OR 的分布性,如此处所示。

您所需要做的就是依次应用它。 例如,使用 x*(y+z) = (x*y)+(x*z)(其中 * 表示 AND,+ 表示 OR):

0. (A + B) * (D + E) * F
1. Apply to the first 2 brackets results in ((A+B)*D)+((A+B)*E)
2. Apply to content of each bracket results in (A*D+B*D)+(A*E+B*E)
3. So now you have ((A*D+B*D)+(A*E+B*E))*F
4. Applying the law again results in (A*D+B*D)*F+(A*E+B*E)*F
5. Apply one more time results in A*D*F+B*D*F+A*E*F+B*E*F, QED

Your example is exploiting the the distributivity of AND over OR, as shown here.

All you need to do is apply that successively. For example, using x*(y+z) = (x*y)+(x*z) (where * denotes AND and + denotes OR):

0. (A + B) * (D + E) * F
1. Apply to the first 2 brackets results in ((A+B)*D)+((A+B)*E)
2. Apply to content of each bracket results in (A*D+B*D)+(A*E+B*E)
3. So now you have ((A*D+B*D)+(A*E+B*E))*F
4. Applying the law again results in (A*D+B*D)*F+(A*E+B*E)*F
5. Apply one more time results in A*D*F+B*D*F+A*E*F+B*E*F, QED
吻风 2024-07-30 06:47:47

您可能有兴趣阅读卡诺地图。 它们是简化布尔表达式的工具,但您也可以使用它们来确定所有单独的表达式。 我不确定你如何将其概括为你可以为其编写程序的算法。

You may be interested in reading about Karnaugh maps. They are a tool for simplifying boolean expressions, but you could use them to determine all of the individual expressions as well. I'm not sure how you might generalize this into an algorithm you could write a program for though.

属性 2024-07-30 06:47:47

您可能对合取范式或其兄弟析取范式

You might be interested in Conjunctive Normal form or its brother, Disjunctive normal form.

带上头具痛哭 2024-07-30 06:47:47

据我所知,布尔代数不能仅通过 AND 和 OR 运算来构建。
如果只有这两个运算,则无法接收 NOT 运算。

您可以将任何表达式转换为全套布尔运算。

这是一些完整的集合:

  • AND 和 NOT
  • OR 和 NOT

As far as I know boolean algebra can not be build only with AND and OR operations.
If you have only this two operation you are not able to receive NOT operation.

You can convert any expression to the full set of boolean operations.

Here is some full sets:

  • AND and NOT
  • OR and NOT
如歌彻婉言 2024-07-30 06:47:47

假设您可以使用 NOT 运算,则可以仅使用 AND 或仅使用 OR 重写任何布尔表达式。 在你的情况下:

(A OR B) AND (D OR E) AND F

我倾向于使用上面的工程速记并写:

  • AND作为产品(。或什么都没有);
  • 或作为总和 (+); 而
  • 不是单引号 (')。

所以:

(A+B)(D+E)F

算术推论实际上对于因式分解非常有用。

通过 德摩根定律

(A+B) => (A'B')'

因此您可以将表达式重写为:

(A+B)(D+E)F
(A'B')'(D'E')'F

Assuming you can use the NOT operation, you can rewrite any Boolean expression with only ANDs or only ORs. In your case:

(A OR B) AND (D OR E) AND F

I tend to use engineering shorthand for the above and write:

  • AND as a product (. or nothing);
  • OR as a sum (+); and
  • NOT as a single quote (').

So:

(A+B)(D+E)F

The corollary to arithmetic is actually quite useful for factoring terms.

By De Morgan's Law:

(A+B) => (A'B')'

So you can rewrite your expression as:

(A+B)(D+E)F
(A'B')'(D'E')'F
十级心震 2024-07-30 06:47:46

看看德摩根定理。 该链接指向与电子门相关的文档,但理论保持不变。

它表示,如果我们

  1. 将所有变量更改为它们的补码,则任何逻辑二进制表达式都保持不变。
  2. 将所有 AND 运算更改为 OR。
  3. 将所有 OR 运算更改为 AND。
  4. 取整个表达式的补集。

(引用上述链接文件)

Take a look at DeMorgan's theorem. The link points to a document relating to electronic gates, but the theory remains the same.

It says that any logical binary expression remains unchanged if we

  1. Change all variables to their complements.
  2. Change all AND operations to ORs.
  3. Change all OR operations to ANDs.
  4. Take the complement of the entire expression.

(quoting from the above linked document)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文