-
Notifications
You must be signed in to change notification settings - Fork 0
/
derivation.pl
54 lines (40 loc) · 960 Bytes
/
derivation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
derive(U+V, X, DU + DV) :-
derive(U, X, DU),
derive(V, X, DV).
derive(U-V, X, DU - DV) :-
derive(U, X, DU),
derive(V, X, DV).
derive(U*V, X, DU*V+DV*U) :-
derive(U, X, DU),
derive(V, X, DV).
derive(U/V, X, (DU*V-DV*U)/V^2) :-
derive(U, X, DU),
derive(V, X, DV).
derive(U^P, X, P*U^(P-1)*DU) :-
derive(U, X, DU).
derive(X,X,1).
derive(Y,X,0) :-
atomic(Y),
Y \== X.
simplification(Exp, Res) :-
Exp =.. [_, A1, A2],
number(A1),
number(A2),
Res is Exp.
simplification(Exp, Res) :-
Exp =.. [Op, A1, A2],
simplification(A1, Res1),
simplification(A2, Res2),
SExp =.. [Op, Res1, Res2],
Exp \== SExp,
simplification(SExp, Res).
simplification(0*_, 0).
simplification(_*0, 0).
simplification(0+E, E).
simplification(E+0, E).
simplification(1*E, E).
simplification(E*1, E).
simplification(E,E).
deriver(U, X, Res) :-
derive(U, X, Exp),
simplification(Exp, Res).