Re: [q-lang-users] Strong examples of Q equational programming wanted
Brought to you by:
agraef
From: Greg B. <gr...@sl...> - 2006-09-29 17:05:56
|
Albert Graef wrote: > Thanks a lot, Greg, for the very illustrative examples. You might wish > to compare those with the Q script at > http://q-lang.sf.net/examples/symbolic.q > > This illustrates my point very well -- even though those rules are in > fact fairly trivial, you really have to go to some lengths to implement > them in a more conventional language. Q makes this kind of stuff very > easy precisely because expressions are first-class and "definitions" are > just rewriting rules, so that you can just write down the rules "as is". As long as we're getting off-topic, here's another Haskell exmaple using algebraic data types... http://sleepingsquirrel.org/lisp/diff_ADT.html ...and a Prolog solution... diff(X,X,1). diff(U+V,X,Z) :- diff(U,X,Up), diff(V,X,Vp), simp(Up+Vp,Z),!. diff(U*V,X,C) :- diff(U,X,Up), diff(V,X,Vp), simp(U*Vp,A), simp(V*Up,B), simp(A+B,C),!. diff(_,X,0). simp(0*X,0). simp(X*0,0). simp(1*X,X). simp(X*1,X). simp(0+X,X). simp(X+0,X). simp(X,X). |