CS 140 Logic Programming

Homework #a

Due Wed. September 27

 

 

On Monday September 25, 2006 we started developing a Prolog program that performs symbolic differentiation.

 

We did not finish debugging the program listed below because we encountered problems with the predicate “A different from B”. Your homework consists in correcting the code below so that it yields the right results, when any variable different from z is to be used in the formula to be differentiated.

 

Notice that we tried to implement a toy simplification program; your program should handle simplifications that eliminate additions of a zero, multiplications by zero, and multiplication by one (This has to be handled recursively recursively).

 

There are several ways to modify the program below so that it yields the appropriate results. Find one that is suitable. For example you may decide to first perform the differentiation that yields an un-simplified formula and then write a predicate simplify that performs the desired simplifications. This is probably the best way to correct the program given below.

 

 

 

 

diff(mult(1,X),z,R):-diff(X,z,R).

diff(mult(0,X),z,R):-diff(0,z,R).

diff(0,z,0).

diff(z,z,1).

diff(u,z,0).

diff(add(X,Y), z, R) :- diff(X,z,Rx), diff(Y,z,Ry), R = add(Rx, Ry).

diff(mult(X,Y), z, R) :- diff(X,z,Rx), diff(Y,z,Ry), R= add(mult(Rx,Y), mult(Ry,X)).