2.3 Operation

The itemsets are transformed using various operations defined in ZDD. By combining the operations, the ZDD objects can be flexibly processed and manipulated.

Several examples are shown below. Some operations are computed just like general polynomial expressions, while some are not.

> (a+a).show # Weights are incorporated by the addition of the identical itemsets.
2 a
> (2*a).show # The result is the same by multiplying the variable.
2 a
> (a*b).show # An item is added to the itemset when multiplying different items.
a b
> (a*a).show # When multiplying the same item, the weight becomes 2 items 
since there are two items.
2 a
> (2*a-a).show # Subtraction
a
> ((a*b*c+b*d+c)/b).show # Division
a c + d
> ((a+b)*(c+d)).show
a c + a d + b c + b d 
> ((a+1)*(a+1)).show #  "1" in the last term is the weight of the empty item set.
3 a + 1
> ((a+1)*(a-1)).show
a - 1

Finally, let’s enumerate all subsets of the itemset {a,b,c,d} for this example. The expression and its results are shown below.

> f=(a+1)*(b+1)*(c+1)*(d+1)
> f.show
a b c d + a b c + a b d + a b + a c d + a c + a d + a + b c d + b c +
  b d + b + c d + c + d + 1

The method for expanding the expression above is similar expanding polynomial expressions. The calculation results on the right side are constructed as ZDD object and substituted into Ruby variable f. Consequently, 16($=2^4$) itemsets are enumerated. Note that the last term "1" is the weight of an empty itemset.