% lds(G, L).
% Meta-interprets the goal G by counting the number of times the right branch of
% a choice-point is chosen in L.

lds((A ; B), L) :-
   domain(L0, 0, 1024),
   domain(D, 0, 1),
   (
      D = 0,
      lds(A, L0)
    ;
      D = 1,
      lds(B, L0)
   ),
   L = D + L0.

lds((A, B), L) :-
   domain(L0, 0, 1024),
   domain(L1, 0, 1024),
   lds(A, L0),
   lds(B, L1),
   L = L0 + L1.

lds(B, L) :-
   builtin(B),
   B,
   L = 0.

lds(H, L) :-
   clause(H, B),
   lds(B, L).