 <p>Your recursive predicate isConnected/2 misses the base case:</p> <pre><code>isConnected(X,Y) :- graph1(X,Y). </code></pre> <p>(assuming we are checking graph1, of course).</p> <p>Anyway, you cannot use isConnected/2, since Prolog will loop on cyclic graphs.</p>