Why is mechanical differentiation so hard to get right?

This question is related to this question on differentiation/integration which asks why differentiation is mechanical but integration is an art. The answers given all make a huge assumption: that one is trying to differentiate a symbolic expression which denotes at least a continuous function, usually in fact assuming it is differentiable. Which makes sense, from a mathematical point of view: why would one want to differentiate a non-differentiable function?

The problem is, it is actually quite difficult to tell whether a function is in fact differentiable or not. But, nevertheless, one can blindly apply mechanical rules, and still get an answer, which appears to make sense. My favourite example is $\frac{1}{4i\pi}\ln\left( e^{2i\pi x^2} \right)$ (which is purely real for $x$ real), which both Maple and Mathematica will happily differentiate to $x$.

So the question is: if differentiation is indeed so easy, why is it just as easy to get completely bogus answers from both Maple and Mathematica on a seemingly simple differentiation problem?

-
Unless I am missing some tricky aspect of this problem, both Maple and Mathematica are giving an answer that is numerically correct in the neighborhood of x ~ 0 ... so why is this answer "completely bogus"? –  John Sidles May 31 '11 at 0:58
If we adopt the (nearly universal) convention that the logarithm function has a cut along the negative real axis, and stay away from the cut, then Maple and Mathematica agree (and all other computing environments that I know), both numerically and symbolically, that the derivative is simply x. –  John Sidles May 31 '11 at 1:38
And, of course, there is a natural sense in which that expression is legitimately $x2/2$... taking $x \mapsto e^x$ to be a function from complex numbers to lomplex numbers (where lomplex numbers aren't merely complex numbers, but are instead complex numbers with chosen logarithms (equivalently, continuous group homomorphisms from $\langle \mathbb{R},+ \rangle$ to $\langle \mathbb{C},\times\rangle$)) and $\ln$ to be a function from lomplex numbers to complex numbers, in the obvious way, they actually are full-on inverses to each other, no quibbles. So the trouble isn't that [to be continued] –  Sridhar Ramesh May 31 '11 at 1:44
An even simpler example would be $log(log(sin(x)))$ which doesn't make sense in the reals yet has a 'perfectly valid' (i.e.. mechanically derived) derivative $cot(x)/log(sin(x))$, which makes sense for certain values $x>0$. Ian Stewart discusses this one in his 'Concepts of modern mathematics' p. 64ff. I agree with L Spice that the question should more go into the direction of "When are we allowed to use these mechanical 'rules' - and when not?" –  vonjd May 31 '11 at 8:58
@Todd: the logarithm implemented in CAS is not multi-valued, but it does have a branch cut. The problem is not software, it is one where there is insufficient mathematics available to computer scientists to design a good mechanical differentiation algorithm. @vonjd: I also believe that the problem is more one of denotational semantics, something which mathematicians tend to avoid by simply 'not writing down' nonsensical expressions rather than trying to tackle them more directly. –  Jacques Carette May 31 '11 at 11:41