I am experimenting with idea on using ZDD as keys of dict, in other words, on ZDD which has a value cell for each node. Reflecting on my limited experience on ZDD, ZDD looks like just a kind of dict which uses heavily hashing on keys of the dict. Although I have a goal in mind for this experiment, I am not sure there would be some interesting result for Prolog programming. But I have a small hope for the time being. As ZDD is roughly a kind of boolean algebra, if values in the cell form a similar algebra (i.e. homomorphic), it might contribute to algorithm like path counting in graphs.
If related or similar works are known, I will appreciate if they are shared here.
As my first try, I built powerset zdd (zdd_dict_power/3
below) which stores cardinality in the attached cells. In the code below, zdd_dict
is a core predicate, but which is almost my cofact/2
on ZDD without value cells.
Fortunately it works I expected.
:- module(zds, []).
:- use_module(zdd('zdd-array')).
:- use_module(zdd(zdd)).
:- use_module(pac(op)).
% ?- open_zdd_dict, zdd_dict(I, t(a, 0, 1), Val).
% ?- open_zdd_dict, zdd_dict(I, t(a, 0, 1), Val), Val=a.
% ?- open_zdd_dict, zdd_dict(I, t(a, 0, 1), Val), Val=a, zdd_dict(I, X, R).
% ?- open_zdd_dict, zdd_dict(I, t(a, 0, 1), Val), Val=a,
% zdd_dict(J, t(b, I, I), Val2), zdd_dict(I, _, Val2).
% ?- open_zdd_dict, zdd_dict(I, t(a, 0, 1), Val), Val=a,
% zdd_dict(J, t(b, I, I), Val2), Val2=c,
% zdd_dict(J, X, Val3),
% zdd_dict(K, X, Val4).
% ?- open_zdd_dict.
% ?- b_getval(zdd_dict, R), write(R).
% ?- open_hash(4, R), write(R).
% ?- trace.
% ?- open_zdd_dict, b_getval(zdd_dict, R), write(R).
% ?- open_zdd_dict, zdd_dict_power([a,b], P, C).
% ?- zdd_dict_power([], P, C).
% ?- open_zdd_dict, zdd_dict_power([a,b,c], P, C).
% ?- numlist(1, 100, Ns),open_zdd_dict, zdd_dict_power(Ns, P, C).
%@ Ns = [1, 2, 3, 4, 5, 6, 7, 8, 9|...],
%@ P = 101,
%@ C = 1267650600228229401496703205376.
zdd_dict_power([], 1, 1).
zdd_dict_power([A|As], X, C):-
zdd_dict_power(As, Y, C0),
zdd_dict(X, t(A, Y, Y), C),
C is C0 + C0.