Created
June 7, 2016 20:12
-
-
Save hutchison/0a3943175bb8e9d3ce736733aa162b7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% vim:set noet sts=0 sw=8 ts=8 ft=prolog: | |
expr(E) :- integer(E). | |
expr(E) :- atomic(E). | |
expr(potenz(E,I)) :- expr(E), integer(I). | |
expr(-E) :- expr(E). | |
expr(E1+E2) :- expr(E1), expr(E2). | |
expr(E1-E2) :- expr(E1), expr(E2). | |
expr(E1*E2) :- expr(E1), expr(E2). | |
expr(E1/E2) :- expr(E1), expr(E2). | |
potenz(E, I) :- expr(E), integer(I). | |
ableitung(E, _, 0) :- integer(E), !. | |
ableitung(X, X, 1) :- atomic(X), !. | |
ableitung(X, Y, 0) :- atomic(X), atomic(Y), dif(X,Y). | |
ableitung(potenz(X, 1), X, 1) :- !. | |
ableitung(potenz(X, I1), X, I1*potenz(X, I2)) :- I2 is I1-1. | |
ableitung(-E, X, -D) :- ableitung(E, X, D). | |
ableitung(E1+E2, X, D1+D2) :- | |
ableitung(E1, X, D1), | |
ableitung(E2, X, D2). | |
ableitung(E1-E2, X, D1-D2) :- | |
ableitung(E1, X, D1), | |
ableitung(E2, X, D2). | |
ableitung(E1*E2, X, D1*E2+D2*E1) :- | |
ableitung(E1, X, D1), | |
ableitung(E2, X, D2). | |
ableitung(E1/E2, X, (D1*E2-E1*D2)/potenz(E2,2)) :- | |
ableitung(E1, X, D1), | |
ableitung(E2, X, D2). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment