title: Maxima - differentiating a piecewise function
body: <p>Suppose you have a function defined by intervals, such as</p>
  
  <pre><code>f(x):=block(if x&lt;0 then x^2 else x^3);
  </code></pre>
  
  <p>When we differentiate it with</p>
  
  <pre><code>diff(f(x),x);
  </code></pre>
  
  <p>we get</p>
  
  <pre><code>d/dx (if x&lt;0 then x^2 else x^3)
  </code></pre>
  
  <p>whereas I'd like to get</p>
  
  <pre><code>(if x&lt;0 then 2*x else 3*x^2)
  </code></pre>
  
  <p>Is there a way to obtain such result?</p>