title: Quick Explanation of fail
body: <p>I am very new to prolog and I am having difficulty in understanding the way of which, <code>fail</code> works.</p>
  
  <p>I have a simple code below and I enter into the query  I get the false result:</p>
  
  <pre><code>?- f1(X).
   false.
  </code></pre>
  
  <hr>
  
  <pre><code>a(1).
  a(2).
  a(3).
  a(4).
  a(5).
  
  b(2).
  b(3).
  b(4).
  b(5).
  
  c(3).
  c(4).
  c(5).
  
  d(4).
  d(5).
  
  f1(X):-  a(X),!, fail, b(X).
  f1(X):-  d(X).
  </code></pre>
  
  <p>But if the f1(X) was defined like:</p>
  
  <pre><code>f1(X):-  a(X), b(X), fail.
  f1(X):-  d(X).
  </code></pre>
  
  <p>And the output of the same query would be:</p>
  
  <pre><code> X = 4 ;
   X = 5.
  </code></pre>
  
  <p>Could anyone explain how does this work?</p>