edge(1,2). edge(2,1). edge(1,3). path(X,Y) :- edge(X,Y). path(X,Y) :- edge(X,Z), path(Z,Y), !. cycle(X) :- path(X,X), !.