/* SYS$USER2:[PROLOG.PRO]DERIV.DAT;1 */ /* d(Exp,X,D) -> D is the derivative of the expression Exp */ /* with respect to constant X */ ?-op(301,yfx,'^'). d(X,X,1) :- ! . d(C,X,0) :- atomic(C). d( ~ U,X, ~ A) :- d(U,X,A). d(U+V,X,A+B) :- d(U,X,A),d(V,X,B). d(U-V,X,A-B) :- d(U,X,A),d(V,X,B). d(C * U,X,C * A) :- atomic(C), C \= X , d(U,X,A), ! . d(U * V,X,B * U + A * V) :- d(U,X,A),d(V,X,B). d(U / V,X,A) :- d(U * V ^ ( ~ 1) ,X,A). d(U ^ V,X,V * W * U ^ (V-1)) :- atomic(V),V \= X , d(U,X,W). d(log(U),X,A * U ^ ( ~ 1)) :- d(U,X,A). ?- d(x+1,x,Dx). ?- d(x*x-2,x,Dx).