title: Determining successor in prolog using recursion
body: <p>I'm trying (failing) to understand an exercise where I'm given the following clauses;</p>
  
  <pre><code>pterm(null).
  pterm(f0(X)) :- pterm(X).
  pterm(f1(X)) :- pterm(X).
  </code></pre>
  
  <p>They represent a number in binary, eg. f0(null) is equivalent to 0, f1(null) is equivalent to 1, etc.</p>
  
  <p>The objective is to define a predicate over <code>pterm</code> such that one is the successor of the other when true. It seems like a relatively simple exercise but I'm struggling to get my head around it.</p>
  
  <p>Here is the code I've written so far;</p>
  
  <pre><code>incr(X,Y) :- pterm(f0(X)), pterm(f1(Y)).
  incr(X,Y) :- pterm(f0(f1(X))), pterm(f1(f1(Y))).
  </code></pre>
  
  <p>Having tested this I know it's very much incorrect. How might I go about inspecting the top level arguments of each pterm?</p>
  
  <p>I've made minimal progress in the last 4 hours so any hints/help would be appreciated.</p>