Counting cycles in a rectangle undirected grid graph

Problem: Enumerate all cycles in a rectangle area rect(w, h) of integer points (k, j) ( 0=< k =< w, 0=<j=<h ).

I happened to find a solution to this problem on the long way of struggling with the problem of enumerating paths from (0,0) to (w, h). (Thanks to J.Burse) That is, a slight change to the latter codes works for the former.

I hope this would be a small contribution to Prolog because I could find nothing comparative so far. Of course I know this is far from worth to be proud when compared with other languages. But I would like to keep steps toward ZDD in Prolog no matter what pace is slow.

I hope some one follows me, catch up, and will go ahead far soon.

% ?- time(count_rect_cycles(rect(10,10), C)).
%@ % 6,626,002,510 inferences, 639.629 CPU in 644.225 seconds (99% CPU, 10359131 Lips)
%@ C = 988808811046283595068099.

Circling a region is also a task in Go. Makes me think
again we should try to apply ZDD to games.

AlphaGo - The Movie | Full award-winning documentary