This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/symdiff/power2.lgt
2001-06-06 19:40:57 +00:00

49 lines
766 B
Plaintext

:- object(_ ** _,
implements(symdiffp)).
:- info([
authors is 'Paulo Moura',
version is 1.0,
date is 1999/12/29,
parnames is ['Expression', 'Power'],
comment is 'Symbolic differentiation and simplification of **/2 expressions.',
source is 'Example based on the Clocksin and Mellish Prolog book.']).
diff(Diff) :-
this(X ** Y),
once(diff(X, Y, Diff)).
diff(X, Y, Y * X ** Y2 * DX) :-
integer(Y),
Y2 is Y - 1,
X::diff(DX).
diff(X, Y, Y * X ** Y2 * DX) :-
Y2 = Y - 1,
X::diff(DX).
simplify(S) :-
this(X ** Y),
once(simplify(X, Y, S)).
simplify(_, 0, 1).
simplify(X, 1, X).
simplify(X, Y, S ** Y) :-
integer(Y),
X::simplify(S).
simplify(X, Y, SX ** SY) :-
X::simplify(SX),
Y::simplify(SY).
:- end_object.