Melding ZDDs
Let be ZDDs in the same universe . How do we construct their union, ?
If one family is the empty or unit family then the question is easy, and these special cases also hint at the general solution. In particular, if (represented by the single node ) and (so contains a nonterminal node) then, if it does not already exist, we add a dotted edge so that we can travel from the root of to to by following the LO branch every time: bubbles down from the root of along dotted lines and then attaches itself to the ZDD with a dotted line.
Consider the case when both and contain more than one node, that is, neither is the empty or unit family. Suppose they both have a root node labelled for some . Let be the ZDDs on the LO and HI edges respectively. Define similarly:
Recall partition the families of sets of on whether they contain or not, and similarly for , hence our solution must be:
where we recursively find and .
This argument holds for any binary operation that distributes over union satisfying , namely the output lies within the union of the inputs. This ensures we can compute by solving two subproblems, one involving only sets of the families containing a particular element , and the other involving only those not containing .
Thus the only case requiring deeper investigation is when and have root nodes with differing integer labels. Suppose has root node with label and has root node with label , and . Let be the LO and HI children of respectively.
Now is the smallest integer contained in any set of , hence no set in contains . Thus is:
where . Hence "bubbles down the dotted line" whenever . Compare with the special case we discussed earlier, which we can accommodate by defining to be larger than every integer.
Thus we have described all cases of a top-down recursive algorithm for constructing the union of any two families. There are two technicalities: we avoid creating nodes whose HI edges point to , and we avoid duplicating any nodes.
As , for these operations, the above arguments apply when have root nodes with the same label. Similarly, the "bubble-down" argument still holds when the root of is greater than the root of . The only difference is in the handling of . For intersections, since this represents the sets of containing and since no set in contains , we lop off the entire branch leaving only the ZDD . For the difference and symmetric difference, as in the union, we leave intact as it represents sets of not present in .
One more wrinkle: the case is symmetric except for the asymmetric difference operation. We have in this case.
Let us summarize the nonterminal cases. Let be one of . We reuse the above notation, that is, are nontrivial ZDDs with roots labelled respectively, and are the LO and HI children of respectively and are similarly defined.
When , then is recursively defined by:
where .
When , let . If then , otherwise is:
Lastly, when the cases are symmetric except when , whence .
TODO: computing the join, meet, ….