deriv was part of the thesis of Warren to show that Prolog can
be used for the same things as LISP, since the very original
deriv dates back toWarren, D.H.D. (1978): Applied Logic - Its Use andImplementation as a Programming Tool,
@Samer Abdallah If you add subst and eval, you can also do taylor
expansion. I understand that you try to have eval via CHR instantiation.
The example you show indicates this.
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
understanding them and in further developing them. There seems
to be a forward and backward mode of computing derivations,
which I do not yet understand.
Also using duals numbers, already used
by the German mathematician Eduard Study have a certain appeal
to me since they can combine derive and subst in one step, but I didn't
figure out yet how to effectively do the n-the derivative.
For more introductory information see for example here:
Automatic differentiation - H°avard Berland 2016
http://www.robots.ox.ac.uk/~tvg/publications/talks/autodiff.pdf
Am Samstag, 15. April 2017 11:57:09 UTC+2 schrieb Jan Burse:a) Requirement 1: For each summand of the taylor expansion
we need the n-th derivative. So typically when we have compute
a derivative, we will keep it and not instantiate it, to be in position
of computing the next derivatve.
b) Requirement 2: For each summand of the taylor expansion,
or for simplicity look at Maclaurin series where a=0, we need
to evaluate the derivative at the point x=0. This calls for instantiation,
but maybe its in conflict with requirement 1.
BTW: I fixed the performance problem, I introduce some
structure sharing into the d (U/V)/dx rule. You don't have
such a rule, you seem to use U^(-1).
So that I have implemented
d (U/V)/dx = (d U/dx - d V/dx *(U/V)) / V
expressions such as a+sqrt(b) symbolically? (**)
I have a next challenge. But its not really differentiation, but more
dealing with symbolic expressions in general, but still relevant. I
dunno how much has done in Prolog already.
Lets look at algebraic numbers, they are zeros of a polynomial
p(x). For a polynomial p(x) of degree n, we can define a new
one p*(x) as follows:
(**)
I would like to do taylor expansion of sqrt(1+x). But I didn't
introduce radicals already. A cludge might be to view it as (1+x)^(1/2),
which could already work for Samer Abdallah approach.
?- add(1,X,H), pow(H,-1,J), taylor(J,X,5,R).
R = [1, -1, 1, -1, 1, -1],
/* lots of constraints */
R = [1.0, 0.5, -0.125, 0.0625, -0.0390625, 0.02734375],
/* lots of constraints */
?- add(1,X,H), pow(H,0.5,J), taylor(J,X,3,R).
R = [1.0, 0.5, -0.125, 0.0625],
add(1, X, H),
mul(0.5, _G22806, _G22807),
mul(-0.5, _G22819, _G22806),
mul(-1.5, _G22832, _G22819),
mul(0.5, _G22845, _G22846),
mul(-0.5, _G22858, _G22845),
mul(0.5, _G22871, _G22872),
pow(H, -2.5, _G22832),
pow(H, -1.5, _G22858),
pow(H, -0.5, _G22871),
pow(H, 0.5, J).
?- time((between(1,1000,_), add(1,X,H), pow(H,-1,J), taylor(J,X,8,R), fail; true)).
% 24,492,000 inferences, 4.179 CPU in 4.281 seconds (98% CPU, 5860286 Lips)
true.
42 ?- time((between(1,1000,_), add(1,X,H), pow(H,0.5,J), taylor(J,X,8,R), fail; true)).
% 24,492,000 inferences, 4.091 CPU in 4.272 seconds (96% CPU, 5987529 Lips)
true.
I wanted to try your gist with SWI-Prolog 7.5.5, but its not working.
When I have fixed the singleton warning for Cs0, I still get no result:
?- add(1.0,X,X1), pow(-1,X1,Y), time(taylor(5,X,Y,Cs)), X=0.0.
% 2,235 inferences, 0.000 CPU in 0.001 seconds (0% CPU, Infinite Lips)
X = 0.0,
X1 = Y, Y = 1.0,
Cs = [1.0, 0.0, 0.0, 0.0, 0.0].
The correct result should be [1.0, -1.0, 1.0, -1.0, 1.0] I guess.
Whats going wrong?
https://gist.github.com/samer--/3bc9d4785bbafcbf24bb15e1c3f0efe4
Am Montag, 5. Juni 2017 14:00:57 UTC+2 schrieb Samer Abdallah:.. All of this leads me to a question which I had on my mind a while ago — why doboth lambda libraries (Ullrich’s lambda and the newer yall) use copy_term_natand not just copy_term? What’s wrong with copying the attributes? If there aren’tany, it won’t make any difference, and if there are, then arguably it makes more senseto keep them.
So I made my own version, with a copying subst, see source
at end of my post. Seems to work and doesn't use copy_term:?- add(1,X,H), pow(H,-1,J), taylor(J,X,5,R).R = [1, -1, 1, -1, 1, -1],/* lots of constraints */?- add(1,X,H), pow(H,0.5,J), taylor(J,X,5,R).R = [1.0, 0.5, -0.125, 0.0625, -0.0390625, 0.02734375],/* lots of constraints */
I dunno yet how to get rid of the lots of constraint, I was
thinking of using a signally constraint dispose/1,
but it would be unsafe, could also remove subterms
used in a deriv result.
/* partial evaluation */
add(X,Y,Z) <=> number(X), number(Y) | Z is X+Y.
mul(X,Y,Z) <=> number(X), number(Y) | Z is X*Y.
pow(X,Y,Z) <=> number(X) | Z is X^Y.
/* simplification */
add(0,X,Y) <=> Y=X.
add(X,0,Y) <=> Y=X.
add(X,X,Y) <=> mul(2,X,Y).
mul(0,_,Y) <=> Y=0.
mul(_,0,Y) <=> Y=0.
mul(1,X,Y) <=> Y=X.
mul(X,1,Y) <=> Y=X.
mul(X,X,Y) <=> pow(X,2,Y).
pow(_,0,Y) <=> Y=1.
pow(X,1,Y) <=> Y=X.
/* derivation */
deriv(C,_,R) <=> number(C) | R = 0.
add(A,B,C) \ deriv(C,X,R) <=>
deriv(A,X,S), deriv(B,X,T), add(S,T,R).
What I don't understand why I can write:
add(A,B,C) \ deriv(C,X,R) <=>
deriv(A,X,S), deriv(B,X,T), add(S,T,R).
And don't need to write:
add(A,B,C) \ deriv(D,X,R) <=> C == D |
deriv(A,X,S), deriv(B,X,T), add(S,T,R).
Have to check!
Am Dienstag, 6. Juni 2017 04:56:14 UTC+2 schrieb Jan Burse:Since the subst solution doesn't use copy_term and leaves
a lot of garbage it is even a tick faster than everything else
so far, and I am using my old slow mac:?- time((between(1,1000,_), add(1,X,H), pow(H,-1,J), taylor(J,X,8,R), fail; true)).% 24,492,000 inferences, 4.179 CPU in 4.281 seconds (98% CPU, 5860286 Lips)true.42 ?- time((between(1,1000,_), add(1,X,H), pow(H,0.5,J), taylor(J,X,8,R), fail; true)).% 24,492,000 inferences, 4.091 CPU in 4.272 seconds (96% CPU, 5987529 Lips)true.This gives it, if we divide by 1000-iterations, around 0.004 ms for
the taylor expansion. In your paper you show 0.006 ms, and maybe
your mac is similar like mine?
(P.S.: Evidence that the subst is faster my be already given by the
number of inferences, in your paper I see 26,038 inferences,
and the above has 24,492 inferences)
Am Dienstag, 6. Juni 2017 04:37:52 UTC+2 schrieb Jan Burse:So I made my own version, with a copying subst, see source
at end of my post. Seems to work and doesn't use copy_term:
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+unsubscribe@googlegroups.com.
Samer, Janyour thread is passionating... please don't leave now :)