简体   繁体   English

在SOP格式中最小化布尔函数的方法

[英]Method to minimize boolean function in SOP-form

I'm dealing with boolean functions of which I can only (but safely) assume that they come in as a SOP and contain no negations (eg (A && B && C) || (A && B && D) ). 我正在处理布尔函数,我只能(但安全地)假设它们作为SOP进入并且不包含否定(例如(A && B && C)||(A && B && D) )。 The number of disjunctions is usually > 5, the number of conjunctions within usually > 10. 析取的数量通常> 5,连词的数量通常> 10。

Because in my case computing the value of each variable is hard and the result is to be considered ephemeral , I need to be able to minimize said functions with respect to variable occurrence. 因为在我的情况下计算每个变量的值很难并且结果被认为是短暂的 ,我需要能够最小化关于变量出现的所述函数。 The result of this minimization does not need to be in any normal form and is allowed to be nested arbitrarily deep. 这种最小化的结果不需要是任何正常形式,并且允许任意深度嵌套。

Having asked a similar question before, SO points to general solutions using fanout-minimization, Karnough maps, QM or BDDs. 在问过类似问题之前,SO 指出了使用扇出最小化,卡诺图,QM或BDD的一般解决方案。 Before dealing with these approaches - which would blow up my code extensively - I'd like to double-check if the a priori known facts about the input function do not yield the possibility to use a smaller though less general approach of minimization. 在处理这些方法之前 - 这会大大夸大我的代码 - 我想仔细检查关于输入函数的先验已知事实是否不会产生使用较小但尽管不那么通用的最小化方法的可能性。

AFAICS applying the absorption and distributivity laws will always provide the minimal form. 应用吸收和分配规律的AFAICS将始终提供最小的形式。 Is there a possibility to exploit the fact that the functions come in as SOPs and have no negations? 是否有可能利用这些功能作为SOP而没有否定的事实? It appears to me that there should be a recursive algorithm of simple intersection- and union-operations on the variables that will yield the desired result. 在我看来,对变量应该有一个简单的交集和并集运算的递归算法,它将产生所需的结果。

Can one describe that algorithm? 可以描述一下这个算法吗?

Edit: Request for comments: Having done some research on the topic, it appears to me that the question asked here is equivalent to finding the optimal variable ordering of the reduced BDD of the given functions. 编辑:征求意见:在对该主题做了一些研究之后,在我看来,这里提出的问题等同于找到给定函数的简化BDD的最优变量排序。


Background: The minimized function is passed on to a job queue to figure out the value of all required variables. 背景:最小化的函数被传递到作业队列以计算所有必需变量的值。 The function is evaluated afterwards. 之后评估该功能。 Consider the application examples: 考虑应用示例:

  • The input function (A && B && C) || 输入函数(A && B && C)|| (A && B && D) can be written as A && B && (C || D) , which eliminates having to evaluate A and B twice. (A && B && D)可以写成A && B &&(C || D) ,这样就不必再评估AB两次。 Evaluation of C and D is serialized in the job queue because only one of them needs to be proven true. CD的评估在作业队列中被序列化,因为只需要证明其中一个是真的。
  • (A && B && C) || (A && B && C)|| (A && B && C && D) || (A && B && C && D)|| (A && B && X && E) is reduced to A && B && (C || (X && E)) . (A && B && X && E)减少为A && B &&(C ||(X && E)) The evaluation of X && E is considered more hard and therefor placed behind evaluation of C in the queue, the evaluation of D is dropped. X && E的评估被认为更加困难,因此在队列中评估CD的评估被删除。

Here is a simple algorithm : 这是一个简单的算法:

let's consider an exampe : ABC+ABD 让我们考虑一个例子:ABC + ABD

there is

  • 2 terms T1 = ABC and T2=ABD 2个术语T1 = ABC,T2 = ABD
  • 4 vars A,B,C and D 4个变量A,B,C和D.

First convert your expression to a 2D table (it's not a k-map) : 首先将表达式转换为2D表(它不是k-map):

    T1  T2
A   1   1 
B   1   1   
C   1   0
D   0   1 

**begin** 
**While** the table is not empty do :
    **if** a row or a column have only zeros, **then** 
           remove it from table and continue. 
    **end if**
    **if** there is a row or more with only ones **then** 
           factor the vars corresponding to the rows 
           and remove the rows from the table 
    **else** 
           get the rows having a max number of ones, 
           do their scalar prod 
           from the scalar prod obtained, 
           get the columns corresponding to zeros (terms) 
           and put aside the one having a min number of ones 
           and remove its column from the table
    **end else**

**end while**

close brackets
**end**

Application to the table above : 申请表上面:

    T1  T2
A   1   1 
B   1   1   
C   1   0
D   0   1 

iteration 1 : there is 2 rows having only ones, A and B, factor them and remove them from table : 迭代1:有两行只有一个,A和B,因为它们并从表中删除它们:

the expression will begin with : AB(... and the table is now : 表达式将从以下开始:AB(...并且表现在是:

    T1  T2  
C   1   0
D   0   1 

iteration 2 : no rows having only ones. 迭代2:没有行只有一行。 two rows having a max number of ones equal to 1 , their scalar prod is 0 0 , two columns having a zero, T1 and T2 both have the same number of 1 , no min , take one of them aside, let's take T1 and remove it from the table : the expression will begin with : AB(T1+ and T1 is 1*C+0*D = C the expression will begin with : AB(C+... the table is now : 两行的最大数量为1,其标量为0 0,两列为零,T1和T2都具有相同的数字1,无分钟,将其中一个放在一边,让我们取T1并删除它来自表格:表达式将从以下开始:AB(T1 +和T1是1 * C + 0 * D = C表达式将从以下开始:AB(C + ......表现在是:

    T2  
C   0
D   1 

iteration 3 : the row C have only zeros, we shall remove it , the row D have only ones, we factor it and remove it from table 迭代3:行C只有零,我们将删除它,行D只有一个,我们将它排除并从表中删除它

the expression is now : AB(C+D(... 表达式现在是:AB(C + D(...

the table is now : empty 表现在是:空的

iteration4: the table is empty -> end of while iteration4:表是空的 - >结束时间

close brackets : 近括号

the expression is AB(C+D) 表达式为AB(C + D)

it's not an optimal algorithm but it's less general than k-maps because it takes into consideration the fact that the expression is SOP and without negations 它不是一个最优算法,但它不如k-maps更通用,因为它考虑到表达式是SOP而没有否定的事实

According to your assumptions, you'll need a function to evaluate your signature before executing the required function. 根据您的假设,您需要一个函数来在执行所需函数之前评估您的签名。

There's no a priori algorithm that will do this for you, at least in java, hence you'll need to codify it and keep iterating until you find the most general abstraction. 没有一个先验算法可以为你做这个,至少在java中,因此你需要编写它并继续迭代,直到找到最一般的抽象。

Boolean algebra 布尔代数

There you have all the properties applied in logic, being the first three the most useful for you as you don't want to use the NOT operation. 在那里你有所有应用在逻辑中的属性,因为你不想使用NOT操作,前三个对你最有用。 I hope this helps. 我希望这有帮助。

I would do it with a "common sense" algorithm; 我会用“常识”算法做到这一点; I am not sure it is optimal, but "optimality" is difficult to express in that case. 我不确定它是最优的,但在这种情况下很难表达“最优性”。 I assume that you don't have any 'preference' in the order in which the clauses are evaluated, but this could be included in the procedure without difficulty. 我假设你没有按照评估条款的顺序有任何“偏好”,但这可以毫无困难地包含在程序中。

Let x_1 ... x_n be your decision variables, y_1 ... y_m be the conjonctive clauses of the form prod_{i in I_j} x_i for each j : the expression you wish to minimize is then the sum from j=1 to m of the y_j . x_1 ... x_n是你的决策变量, y_1 ... y_m是每个j的形式prod_{i in I_j} x_i的连接子句:你希望最小化的表达式是从j=1m的总和的y_j

The decision variables can be "partitioned" first: 决策变量可以首先“分区”:

  • if they appear in all the I_j , they need to be evaluated anyway; 如果它们出现在所有I_j ,它们无论如何都需要进行评估; do this first (and remove those from the sets I_j afterward) 首先执行此操作(然后从集合I_j删除它们)
  • if they appear in none of the sets I_j , they do not need to be evaluated (remove them from the sets I(j) too). 如果它们不出现在I_j集合中,则不需要对它们进行评估(也可以从集合I(j)删除它们)。

If one of the x_i that appeared in all the clauses is false, then the expression is false; 如果所有子句中出现的x_i之一为false,则表达式为false; END. 结束。

Otherwise, the objective is to find one of the sets I_j such as all the x_i are true (or to prove that none exist). 否则,目标是找到其中一个集合I_j例如所有x_i都为真(或证明不存在)。

Order the I_j by increasing cardinality, to minimize the number of evaluation. 通过增加基数来订购I_j ,以最小化评估的数量。 Keep an array (say z_i ) such as z_i=1 if x_i was already evaluated to true, and false otherwise. 如果x_i已经被评估为真,则保持数组(比如z_i ),例如z_i=1 ,否则保持为假。 For each of the sets I_j in that ordered list: 对于该有序列表中的每个集合I_j

For each i in I_j : 对于I_j每个i

  • evaluate x_i (if z_i is false); x_i (如果z_i为假);

    • if x_i is false, remove I_j and all the sets that contain i . 如果x_i为false,则删除I_j和包含i所有集合。
    • if it is true, store 1 in z_j and continue 如果是, z_j 1存储在z_j并继续
  • if this loop ends (all the x_i were true), the expression is true. 如果此循环结束(所有x_i都为真),则表达式为true。 END. 结束。

  • if the list of the sets I_j is empty, the expression is false. 如果集合I_j的列表为空,则表达式为false。 END. 结束。
  • otherwise, go to the next I_j . 否则,转到下一个I_j

It has the advantage of being really simple to implement, and should be quite efficient I believe. 它的优点是实现起来非常简单,我相信它应该非常有效。

From a complexity standpoint, I think there are some partly related results that would seem to suggest that this problem is hard. 从复杂性的角度来看,我认为有一些部分相关的结果似乎表明这个问题很难。

According to "On the Readability of Monotone Boolean Formulae" by Elbassioni, Makino, & Rauf (pdf link), it is NP-hard to determine whether a Boolean formula in CNF or DNF can be rewritten as a formula where each variable appears at most k times (for k >= 2). 根据Elbassioni,Makino和Rauf的“关于单调布尔公式的可读性”(pdf链接),确定CNF或DNF中的布尔公式是否可以重写为每个变量最多出现的公式是NP难的k次(k> = 2)。 Note that this result does not match the problem statement because the original formula is not monotone (ie: may contain negations). 请注意,此结果与问题陈述不匹配,因为原始公式不是单调的(即:可能包含否定)。

According to "Complexity of DNF and Isomorphism of Monotone Formulas" by Goldsmith, Hagen, & Mundelhenk (pdf link) , it is NP-hard to compute the minimal DNF for an arbitrary montone Boolean function. 根据Goldsmith,Hagen和Mundelhenk的“DNF的复杂性和单调公式的同构性”(pdf link) ,计算任意单音布尔函数的最小DNF是NP难的。 This result doesn't match exactly because the original formula is not given in DNF and the output formula is restricted to DNF. 此结果不完全匹配,因为DNF中未给出原始公式,并且输出公式仅限于DNF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM