title: Prolog recursive function not behaving as expected
body: <p>I'm trying to implement the recursive version of the Fibonacci sequence in Prolog. Below is the code:</p>
  
  <pre><code>fib(0,F) :- F is 0.
  fib(1,F) :- F is 1.
  fib(N,F) :- N &gt; 1,
  AA is (N - 1),
  BB is (N - 2),
  fib(AA,CC),
  fib(BB,DD),
  RR is (CC + DD),
  F == RR,
  F is RR.
  </code></pre>
  
  <p>The problem is that it's not behaving as I logically expect it to. When I use <code>trace</code> to call fib(3,2), I get the following lines:</p>
  
  <pre><code>   Call: (7) fib(3, 2) ? creep
     Call: (8) 3&gt;1 ? creep
     Exit: (8) 3&gt;1 ? creep
     Call: (8) _G2569 is 3+ -1 ? creep
     Exit: (8) 2 is 3+ -1 ? creep
     Call: (8) _G2572 is 3+ -2 ? creep
     Exit: (8) 1 is 3+ -2 ? creep
     Call: (8) fib(2, _G2573) ? creep
     Call: (9) 2&gt;1 ? creep
     Exit: (9) 2&gt;1 ? creep
     Call: (9) _G2575 is 2+ -1 ? creep
     Exit: (9) 1 is 2+ -1 ? creep
     Call: (9) _G2578 is 2+ -2 ? creep
     Exit: (9) 0 is 2+ -2 ? creep
     Call: (9) fib(1, _G2579) ? creep
     Call: (10) _G2578 is 1 ? creep
     Exit: (10) 1 is 1 ? creep
  </code></pre>
  
  <p>What catches my attention is the last call, Call: (10), which says "_G2578 is 1 ?", even though I'm calling fib(1, _G2579). My expectation is that it's _G2579 that's going to be changed, but that does not appear to be the case. I need to find out why because I highly suspect that this is why fib(3,2) is returning false instead of true.</p>