定义两个集值函数:
N(d1...dn): The subset of the image where members start with a particular sequence of digits d0...dn.
D(d1...dn): The subset of the inputs that produce N(d1...dn).
然后当序列为空时,我们就有了完整的问题:
D(): The entire domain.
N(): The entire image.
从完整域中,我们可以定义两个子集:
D(0) = The subset of D() such that F(x)[1]==0 for any x in D().
D(1) = The subset of D() such that F(x)[1]==1 for any x in D().
这个过程可以递归地应用来为每个序列生成 D。
D(d1...d[m+1]) = D(d1...dm) & {x | F(x)[m+1]==d[m+1]}
然后我们可以确定完整序列的 N(x):
N(d1...dn) = 0 if D(d1...dn) = {}
N(d1...dn) = 1 if D(d1...dn) != {}
父节点可以从两个孩子中产生,直到我们产生 N()。
如果在任何时候我们确定 D(d1...dm) 为空,那么我们知道 N(d1...dm) 也是空的,我们可以避免处理该分支。这是主要的优化。
以下代码(在 Python 中)概述了该过程:
def createImage(input_set_diagram,function_diagrams,index=0):
if input_set_diagram=='0':
# If the input set is empty, the output set is also empty
return '0'
if index==len(function_diagrams):
# The set of inputs that produce this result is non-empty
return '1'
function_diagram=function_diagrams[index]
# Determine the branch for zero
set0=intersect(input_set_diagram,complement(function_diagram))
result0=createImage(set0,function_diagrams,index+1)
# Determine the branch for one
set1=intersect(input_set_diagram,function_diagram)
result1=createImage(set1,function_diagrams,index+1)
# Merge if the same
if result0==result1:
return result0
# Otherwise create a new node
return {'index':index,'0':result0,'1':result1}