I'm trying to implement univariate polynomials using ZDDs, as suggested in a comment in an other question.
I've read the paper of S. Minato(you may download it here), but I don't understand how to implement the operations on these ZDDs.
The idea in the paper is that polynomials can be represented using x^(2^i)
as variables. For example x^5 + x^3 + x
can be rewritten as x^4x^1 + x^2x^1 + x^1
, if you create nodes for each x^(2^i)
variable and connect with the "1-edge" variables that are multiplied together and with the "0-edge" variables that are added together you can easily obtain a graph representing that polynomial. The ZDDs are graphs of this kind that enforce some condition on the graph(for more information read the article of Minato and the wikipedia's page on BDDs)
The coefficients can be similarly represented using sums of powers of 2 (e.g. 5 = 2^2 + 2^0
etc. With every 2^i
being a variable and the nodes are connected with 1- and 0-edges in the same fashion).
Now, my problem is the algorithm for addition of two ZDDs. The algorithm seems quite simple:
If F and G (ZDDs)have no common combinations, the addition (F + G) can be completed by just merging them. When they contain some common combinations, we compute the following formulas: (F + G) = S + (Cx2), where C = F ∩ G, S = (F U G) \ C . By repeating this process, common combinations are eventually exhausted and the procedure is completed.
The problem is: how can I find "C" and "S" efficiently?
The author provides code for the multiplication, but the code is actually trivial once you have the previous algorithms implemented. And since these algorithms are not provided also the multiplication one is "useless".
Also the notion of "merge" ZDDs is not well explained, even though, considering the fact that the order of the variables should be consistent, there is only one way to merge the graphs together, and the rules to maintain this order are probably simple enough(I did not formalize them yet, but I've got a rough idea of what these are).