Symbolic Differentiation Implementation in Prolog
Wojtek Jurczyk, Warsaw University of Technology
Sym-diff-prolog is an implementation of symbolic differentiation using Prolog. It is a bit optimized (it has arithmetic operations optimised; see the source code) but the implementation is still very simple. I hope you will find it useful for learning Prolog. Enjoy!
It is capable of calculating derivatives of:
- basic functions
- sum of functions
- subtraction of functions
- multiplication of functions
- division of functions
- powers (thus, square root)
- logarithmic and exponential functions
- some trigonometric functions
Any other functions can be easily added to the code :)
Let's ask about some derivative:
| ?- diff(x^(x*log(cos(x))), x, N).
The answer we get is:
N = x^(xlog(cos(x))-1)(xlog(cos(x))+(log(cos(x))+x(-sin(x)/cos(x)))xlog(x)) ?
The answer is correct and you can check it here by calculating, using WolframAlpha, derivative - N (it should be 0, and in fact it is).