Symbolic Computation  Differential Calculus using Prolog
Note: It seemed that there was some kind of publishing Error in this post. Few symbols were missing. Now things are rectified and post is clear.
I write this after I got impressed with the Prolog’s powerful pattern matching stuff. There should be a alternative to Prolog in the pattern matching stuff, RegEx sounds convincing, but not as much like prolog.
Symbolic Computation is one of the interesting fields of mathematical computation that is implemented in computer for performing the symbolic mathematical operations such as Algebra, Differentiation, Integration. Lot of computer software packages like MatLab, Mathematics supports symbolic computations.
So what is symbolic computation?
Symbolic Computation is just performing the mathematical computation on symbols like , “x”, “y”, “dx” etc. in computer using some computer programming languages.
All the mathematical expression, including variable (with numeric sometime) based expression which are computed under certain mathematical rules are known as symbolic computation. Integrations are computed by integral rules, differentiation is differential calculus rules and so on.
The above are some examples of symbolic computing. But in manual work this seems to be easier, because humans know how to perform a simple simplification, derivative and integral.
But for computers, it is not possible. It need to be teached by writing programs to perform these operations. But now the question is, which programming language to use. Let’s have a brief discussion.
Which Programming Language?
Prolog was one of popular language used for Some of the AI stuffs . Since my problem is some what related to applying intelligence for a machine to perform symbolic computation, I choose Prolog. Since prolog language works on pattern matching, My symbolic computation also works in the same way i.e. pattern matching. if I have two “x” ( say, “x + x”) then I would add these two and write it as “x”. The same applies to y, x, a and any variable.
Prolog is easy to write and understand. I wrote all the things as Facts, as what we write in Java or C++ known as Methods encapsulated inside the Objects. All the function in prolog are named as Facts.
Getting Prolog :
Prolog is freely dustributed programming language, available for both windows and Linux platforms.
 For Linux, gnuprolog is available
 For windows Amzi Prolog  Students Version is one of the freely available prolog.
Here in this article I take an example of Differential Calculus (derivative) i.e. how to differentiate a given expression with respect to a variable and produce the result.
First I need to know the basic rules for differentiation: 

The above are some rules for basic differentiation. So the notation here I used are easily understandable, any way I explain them.
Notation 
Meaning 
d 
Differentiation Function 
1^{st} argument 
Function to be differentiated 
2^{nd} argument 
With respect to variable 
^ 
Raised to the poIr of 
* 
Multiplication 
+ 
Addition 
 
Subtraction 
/ 
division 
Now let us define the above rules in the prolog as facts. I first describe a structure for the differentiation function.
d ( f(x) , x , R ).
f(x) => function to be differentiated
x => with respect to variable
R => Result Now let us define the facts in prolog.
Symbolic Computation  Differential Calculus using Prolog  Part 1






Here I give you the full code for the differential calculus which covers the basic rules of differentiation.
Basic Rules for differential calculus ( full sMyce code ) 
d( X, X, 1 ): !. /* d(X) w.r.t. X is 1 */d( C, X, 0 ): atomic(C). /* If C is a constant then *//* d(C)/dX is 0 */d( U+V, X, R ): /* d(U+V)/dX = A+B where */ d( U, X, A ), /* A = d(U)/dX and */ d( V, X, B ), R = A + B. d( UV, X, R ): d( U, X, A), d( V, X, B), R = A  B. d( C*U, X, R ): atomic(C), C \= X, d( U, X, A ), R = C * A, !. d( U*V, X, U*B+V*A ): /* d(U*V)/dX = B*U+A*V where */ d( U, X, A ), /* A = d(U)/dX and */ d( V, X, B ). /* B = d(V)/dX */ d( U/V, X, (A*VB*U)/(V^2) ): /* d(U/V)/dX = (A*VB*U)/(V*V) */ d( U, X, A), /* where A = d(U)/dX and */ d( V, X, B). /* B = d(V)/dX */ d( U^C, X, R ): /* d(U^C)/dX = C*A*U^(C1) */ atomic(C), /* where C is a number or */ C\=X, d( U, X, A ), R = C * A * U ^ ( C  1 ). d( sin(W), X, Z*cos(W) ): /* d(sin(W))/dX = Z*cos(W) */ d( W, X, Z). /* where Z = d(W)/dX */ d( exp(W), X, Z*exp(W) ): /* d(exp(W))/dX = Z*exp(W) */ d( W, X, Z). /* where Z = d(W)/dX */ d( log(W), X, Z/W ): /* d(log(W))/dX = Z/W */ d( W, X, Z). /* where Z = d(W)/dX */ d( cos(W), X, (Z*sin(W)) ): /* d(cos(W))/dX = Z*sin(W) */ d( W, X, Z). /* where Z = d(W)/dX */ d( tan(W), X, (Z*sec(W)^2) ): /* d(tan(W))/dX = Z*sec(W)^2 */ d( W, X, Z). /* where Z = d(W)/dX */ 
To run the above program , save the file as “diff.pl”, start prolog interpreter and type “ [‘diff.pl’]. “( don’t miss the “.” , it says the end of function ) and press enter.
The above info would have given a breif idea to develope parsers that can be used in their programs. The prolog is more generalized language and the prolog code can be transformed into C,C++ or Java. Tools for converting prolog to C, C++ or Java are available in the internet for free of cost. My favorite is Prolog Café, which converts prolog programs into Java sMyce code and gnuprolog jar file which is used to use the direct prolog program in a java code without conversion.