我想在 OZ Mozart 中制作一个符号差异化程序,但我被卡住了,不知道如何开始,在 prolog 中会类似于下面的规则,但我至少需要帮助,了解如何在 OZ 中制作最简单的规则,例如,X 的导数等于 1,这样我就可以编写其余的代码,谢谢!
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, A+B ):- /* d(U+V)/dX = A+B where */
d( U, X, A ), /* A = d(U)/dX and */
d( V, X, B ). /* B = d(V)/dX */
d( U-V, X, A-B ):- /* d(U-V)/dX = A-B where */
d( U, X, A ), /* A = d(U)/dX and */
d( V, X, B ). /* B = d(V)/dX */
d( C*U, X, C*A ):- /* d(C*U)/dX = C*A where */
atomic(C), /* C is a number or variable */
C \= X, /* not equal to X and */
d( U, X, A ), !. /* A = d(U)/dX */
d( U*V, X, B*U+A*V ):- /* 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*V-B*U)/(V*V) ):- /* d(U/V)/dX = (A*V-B*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, C*A*U^(C-1) ):- /* d(U^C)/dX = C*A*U^(C-1) */
atomic(C), /* where C is a number or */
C\=X, /* variable not equal to X */
d( U, X, A ). /* and d(U)/dX = A */
d( U^C, X, C*A*U^(C-1) ):- /* d(U^C)/dX = C*A*U^(C-1) */
C = -(C1), atomic(C1), /* where C is a negated number or */
C1\=X, /* variable not equal to X */
d( U, X, A ). /* and d(U)/dX = A */
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 */