I've never done anything in Prolog, and I'm terribly ignorant of what even the simplest of Prolog programs are doing.
I'm presented with such a Prolog program such as this:
edge(a,b).
edge(b,c).
edge(c,d).
edge(b,e).
edge(a,e).
path(X,Y):- edge(X,Y).
path(X,Z):- edge(X,Y), path(Y,Z).
For the most part, I've been able to discover that these facts represent a directed graph. The following 2 rules, as far as I figure, say something to the effect of (in English), "A path is made up of 2 nodes between X and Y, and the path between X and Y is bidirectional. Given the query to find the path between X and Z, first start with an edge between X and Y, and recursively proceed with Y until Z is reached."
At least, I think that's what it means.
So, when the above code is run against a query like:
path(X,Y)
You would get the following output:
X = a,
Y = b;
X = b,
Y = c;
X = c,
Y = d;
X = b,
Y = e;
X = a,
Y = e;
X = a,
Y = c;
X = a,
Y = e;
X = a,
Y = d;
X = b,
Y = d
Which is where the program would then fail.
Unfortunately for me, I don't even know what the initial query implies. Is running the query of "path(X,Y)" simply trying to find all the available paths between 2 nodes? That couldn't possibly be the case, and beyond that, I haven't a clue as to why it returns false as a path between B and D.
My justification for that last statement, about failing on B and D, is that since there's facts that say the edges {B,C} and {C,D} exist that it stands to reason that a path exists from {B, D} by way of C!
It was then that I drew out this graph, and I still haven't figured out much of anything.
Sorry for the long post. I just know there's something simple happening in here, and I can't figure it out and it's starting to make me a bit crazy.
I'm presented with such a Prolog program such as this:
edge(a,b).
edge(b,c).
edge(c,d).
edge(b,e).
edge(a,e).
path(X,Y):- edge(X,Y).
path(X,Z):- edge(X,Y), path(Y,Z).
For the most part, I've been able to discover that these facts represent a directed graph. The following 2 rules, as far as I figure, say something to the effect of (in English), "A path is made up of 2 nodes between X and Y, and the path between X and Y is bidirectional. Given the query to find the path between X and Z, first start with an edge between X and Y, and recursively proceed with Y until Z is reached."
At least, I think that's what it means.
So, when the above code is run against a query like:
path(X,Y)
You would get the following output:
X = a,
Y = b;
X = b,
Y = c;
X = c,
Y = d;
X = b,
Y = e;
X = a,
Y = e;
X = a,
Y = c;
X = a,
Y = e;
X = a,
Y = d;
X = b,
Y = d
Which is where the program would then fail.
Unfortunately for me, I don't even know what the initial query implies. Is running the query of "path(X,Y)" simply trying to find all the available paths between 2 nodes? That couldn't possibly be the case, and beyond that, I haven't a clue as to why it returns false as a path between B and D.
My justification for that last statement, about failing on B and D, is that since there's facts that say the edges {B,C} and {C,D} exist that it stands to reason that a path exists from {B, D} by way of C!
It was then that I drew out this graph, and I still haven't figured out much of anything.
Sorry for the long post. I just know there's something simple happening in here, and I can't figure it out and it's starting to make me a bit crazy.