title: Defining (mathematical) function in Prolog
body: <p>I know Prolog (programming in logic) is all about returning true and false, and that a function is something which returns anything from lists, to numbers, to boolean values. Initially it doesn't seem that Prolog has the concept of functions but instead relies on unification, yet you can do stuff like:</p>
  
  <pre><code>?- X is log(42).
  X = 3.7376696182833684.
  </code></pre>
  
  <p>So it seems that there exist functions? Or is this really just some sort of syntactic sugar hiding the unification part?</p>
  
  <p>And if it really is just syntactic sugar, then how would I go about if I wanted to define a mathematical 'function' like log2?</p>
  
  <p>Of course I can use unification:</p>
  
  <pre><code>log2(X,Result) :- Result is log(X)/log(2).
  </code></pre>
  
  <p>But say I want to use the 'syntactic sugar function style' so I can write:</p>
  
  <pre><code>?- X is log2(8).
  X = 3.0.
  </code></pre>
  
  <p>How can I do that in Prolog?</p>