title: Backtracking in Prolog
body: <p>I am very new to Prolog and have a question about backtracking</p>
  <p>I am given facts</p>
  <pre><code>p(X, Y):- q(X, Y).
  p(X, Y):- r(X, Y).
  
  q(X, Y):- s(X), t(Y).
  r(X, Y):- u(X, Y).
  </code></pre>
  <p>I am given the database</p>
  <pre><code>s(f(a)).
  t(g(b)).
  u(a, g(b)).
  </code></pre>
  <p>And the goal of</p>
  <pre><code>?- p(a, g(Y)).
  </code></pre>
  <p>I am aware there is one solution to this query</p>
  <pre><code>Y = b
  </code></pre>
  <p>However, I am unsure of how many times Prolog backtracks. I believe the answer is 3 times as Prolog works from the top down and checks each fact to ensure that the previous facts cannot be combined and used to solve the goal. Any help would be appreciated.</p>
  <p>One last Q, the facts having nested facts, IE</p>
  <pre><code>s(f(a))
  </code></pre>
  <p>where f is undefined, can I assume this is syntactically equal to s(a)?</p>