Differentiation
- The rules of symbolic differentiation, such as,
d d d - (A+B) = - A + - B dx dx dx
- can be easily expressed in Prolog, e.g.,
diff(plus(A,B), X, plus(DA, DB)) <= diff(A, X, DA) and diff(B, X, DB).
NB. The 'and not equal(Y, X)' in the definition of 'diff(.,.,.)' above is necessary to prevent d/dx 7=1, say.
It is a good exercise, and not so easy, to write Prolog to simplify the result of differentiation, for example, to replace times(1,x)) with x and so on.
Just in case you were wondering, the differentiator cannot be run backwards to get an integrator, which is a pity. It is possible to write a program to perform symbolic integration in Prolog, but it is far from easy (in any programming language) if more than polynomials must be handled.
There are more Prolog examples here.