title: Prolog - simplify derivative
body: <p>so I just got started with Prolog this semester, and got the homework to implement a pretty basic <code>d(function, variable, derivative)</code> which I did like this:</p>
  
  <pre><code>d(X,X,1) :- !.
  d(C,X,0) :- atomic(C). %, (C \= X).
  d(X**E,X,E*X**(E-1)).
  d(U+V,X,A+B) :- d(U,X,A), d(V,X,B).
  d(U-V,X,A-B) :- d(U,X,A), d(V,X,B).
  d(U*V,X,DU*V+U*DV) :- d(U,X,DU), d(V,X,DV).
  d(U/V,X,(DU*V-U*DV)/(V*V)) :- d(U,X,DU), d(V,X,DV).
  </code></pre>
  
  <p>I know this is not complete, but it covers all the tasks required in the exercise.</p>
  
  <p>However, 
  <code>?- d((x*x+2*x+3)/(3*x),x,R).</code>
  leads to</p>
  
  <p><code>R = ((1*x+x*1+ (0*x+2*1)+0)* (3*x)- (x*x+2*x+3)* (0*x+3*1))/ (3*x* (3*x)).</code>
  which doesn't look pretty at all. <em>is/2</em> unfortunately doesn't like my x as it is not a number...</p>
  
  <p>Is there a simple solution to achieve a cleaner result?</p>