[英]Algorithm to simplify boolean expressions
I want to simplify a very large boolean function of the form : 我想简化表单的一个非常大的布尔函数:
f(a1,a2,....,an)= (a1+a2+a5).(a2+a7+a11+a23+a34)......(a1+a3+an).
'.' '' means OR
是指OR
'+' means AND '+'表示AND
there may be 100 such terms ('.' with each other ) value of n may go upto 30. 可能有100个这样的术语('。'相互之间)n的值可能高达30。
Is there any feasible algorithm to simplify this? 有没有可行的算法来简化这个?
NOTE: this is not a lab assignment, a small part of my project on rule generation by rough set where f is dissimilarity function. 注意:这不是实验室分配,是我的项目中通过粗糙集生成规则的一小部分,其中f是不相似函数。
The well-known ways to do this are: 众所周知的方法是:
The second way is most commonly used on a computer. 第二种方式最常用于计算机上。 It's tabular and straight-forward.
这是表格和直截了当的。 The first way is the best way to do by hand and is more fun, but you can't use it for anything more than 4 variables reliably.
第一种方法是手动完成的最佳方式,更有趣,但你不能可靠地使用它超过4个变量。
The typical method is to use boolean algebra to reduce the statement to its simplest form. 典型的方法是使用布尔代数将语句简化为最简单的形式。
If, for example, you have something like: 例如,如果你有类似的东西:
(A AND B) OR (A AND C)
you can convert it to a more simple form: 你可以将它转换为更简单的形式:
A AND (B OR C)
If you represent the a values as an int
or long
where a1 has value 2, a2 has value 4, a3 has value 8 etc.: 如果将a值表示为
int
或long
,其中a1的值为2,则a2的值为4,a3的值为8等:
int a = (a1 ? 2^1 : 0) + (a2 ? 2^2 : 0) + (a3 ? 2^3 : 0) + ...; int a =(a1?2 ^ 1:0)+(a2?2 ^ 2:0)+(a3?2 ^ 3:0)+ ...;
(wasting a bit to keep it simple and ignoring the fact that you'd be better off with an a0 = 1) (为了保持简单而浪费一点,忽略了a0 = 1你会更好的事实)
And you do the same for all of the terms: 并且您对所有术语都这样做:
long[] terms = ...;
terms[0] = 2^0 + 2^3 + 2^5 // a1+a2+a5
terms[1] = 2^2 + 2^7 + 2^23 + 2^34 // (a2+a7+a11+a23+a34)
Then you can find the result: 然后你可以找到结果:
foreach(var term in terms)
{
if (a & term == term) return true;
}
return false;
BUT this only works well for up to n=64. 但这只适用于n = 64。 Above that it's messy.
在它之上它是凌乱的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.