title: How to stop backtracking and end the recursion in Prolog
body: <p>I'm currently learning SWI-Prolog. I want to implement a function factorable(X) which is true if X can be written as <code>X = n*b.</code><br>
  This is what I've gotten so far:  </p>
  
  <pre><code>isTeiler(X,Y) :- Y mod X =:= 0.
  
  hatTeiler(X,X) :- fail,!.  
  hatTeiler(X,Y) :- isTeiler(Y,X), !; Z is Y+1, hatTeiler(X,Z),!.
  
  factorable(X) :- hatTeiler(X,2).
  </code></pre>
  
  <p>My problem is now that I don't understand how to end the recursion with a fail without backtracking. I thought the cut would do the job but after <code>hatTeiler</code>fails when both arguments are equal it jumps right to <code>isTeiler</code> which is of course true if both arguments are equal. I also tried using <code>\+</code> but without success.</p>