Skip to content

Instantly share code, notes, and snippets.

@zkessin
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkessin/43545458cd5c29088803 to your computer and use it in GitHub Desktop.
Save zkessin/43545458cd5c29088803 to your computer and use it in GitHub Desktop.
Code for partially ordered sets in prolog
connected(A,B) :-
edge(A,B).
sib(A,B) :-
path(C,A,_),
path(C,B,_),
\+path(A,B,_),
\+path(B,A,_).
ancestor(A,B) :-
path(A,B,_).
descendent(A,B) :-
path(B,A,_).
path(A,B,Path) :-
travel(A,B,[A],Q),
reverse(Q,Path).
travel(A,B,P,[B|P]) :-
connected(A,B).
travel(A,B,Visited,Path) :-
connected(A,C),
C \== B,
\+member(C,Visited),
travel(C,B,[C|Visited],Path).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment