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/minus2.lgt
pmoura 75392e54c7 Logtalk 2.15.0 release files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@757 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2003-02-05 00:15:28 +00:00

73 lines
1.0 KiB
Plaintext

:- object(_ - _,
implements(symdiffp)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 1999/12/29,
parnames is ['Expression1', 'Expression2'],
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(I, J, 0) :-
integer(I),
integer(J).
diff(X, J, DX) :-
integer(J),
X::diff(DX).
diff(I, Y, DY) :-
integer(I),
Y::diff(DY).
diff(X, Y, DX - DY) :-
X::diff(DX),
Y::diff(DY).
simplify(S) :-
this(X - Y),
once(simplify(X, Y, S)).
simplify(X, X, 0).
simplify(I, J, S) :-
integer(I),
integer(J),
S is I - J.
simplify(X, 0, S) :-
X::simplify(S).
simplify(0, Y, S) :-
Y::simplify(S).
simplify(X, J, S - J) :-
integer(J),
X::simplify(S).
simplify(I, Y, I - S) :-
integer(I),
Y::simplify(S).
simplify(X, Y, S) :-
X::simplify(SX),
Y::simplify(SY),
(X - Y \= SX - SY ->
(SX - SY)::simplify(S)
;
S = SX - SY).
:- end_object.