2つの設定値関数を定義します。
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.
フルドメインから、2つのサブセットを定義できます。
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()を生成するまで、親ノードは2つの子から生成できます。
いずれかの時点で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}