deriv(U+V,X,DU+DV) :- deriv(U,X,DU), deriv(V,X,DV). deriv(X,X,1) :- atom(X). deriv(C,X,0) :- atom(C), C \= X.