graph,prolog,logic,failure-slice,transitive-closure

Because rules don't work the same as facts, and you are spiraling off into an infinite loop if you use the same predicate. Let's take the example ?-edge(5,2). We will end up calling -- edge(5,2) :- edge(2,5). Ok, what happens when we call edge(2,5)? edge(2,5) :- edge(5,2). ... Uh oh....

I think the basic problem is that you do not check if L2 is already found in the first clause of t_brother/3. And the initial L1 should be added to the list in brother/2: brother(L1, L2) :- t_brother(L1, L2, [L1]). % <-- [L1] instead of [] t_brother(L1, L2, IntermediateNodes) :-...

recursion,prolog,transitive-closure

Your code can prove ?- smarter(jake, dik). because using X = jake, Y = dik it founds a Z=nik such that smarter(jake,nik) (this is a fact) and then smarter(nik,dik), (this is proved considering X1=nik, Y1=dik, Z1=wes). However, in order to prove ?- smarter(dik, jake). with X =dik, Y=jake, prolog needs...

recursion,prolog,maze,transitive-closure

Define in one predicate, what a valid step is - including all restrictions you have. Stick to this naming convention: X0 the "first" value, X the "last" value step(Forbidden,[X0,Y0],[X,Y]) :- possibleMoves(X0,Y0,L), % rather: possibleMove([X0,Y0],L), member([X,Y],L), between(1,8,X), between(1,8,Y), non_member([X,Y],Forbidden). Now you have a path with: ..., closure0(step(Forbidden), S0,S), ... closure0/3 takes...

You can make a rule that passes an extra list of users that you have "seen" so far, and ignore follows originating from these users: follows(A, B, Seen). To do that, define a "follow transitive" rule that wraps the actual rule, like this: follows_tx(A, B) :- follows(A, B, []). Now...

First, two assumptions: the actual code you wanted to write is the following one, with appropriate dots: friends(mia,ellen). friends(mia,lucy). friends(X,Y) :- friends(X,Z), friends(Z,Y). transivity holds: friends of friends are my friends too (I would rather model friendship as a distance: "A is near B" and "B is near C" does...

recursion,prolog,transitive-closure

It sounds like your cost is: 100 + 50 per intermediate city? If that's the case, you want something like route(W, Z, 100) :- connection(W, Z). route(W, Z, Cost) :- connection(W, Y), route(Y, Z, Cost2), Cost is Cost2+50. That will evaluate to 100 once the direct link is found, or...