Re: [pure-lang-users] equations in Q vs Pure
Status: Beta
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2008-07-26 07:49:46
|
Eddie Rucker wrote: > Ok. I've figured I need to do stuff like > > (a*b)+(c*d) = (a+c)*b if b === d; > a*b=a^2 if a===b; Yeah, that's exactly how to do it. (In fact, the Q interpreter does exactly the same for non-linearities, it's only done automatically behind the scenes.) > (a+b)*(c+d) = a*c+a*d+b*c+b*d; > a*b = b*a if numberp b; > > Then > > (x+4)*(x+3) > x^2+3*x+4*x+12 > > Why doesn't the rule '(a*b)+(c*d) = (a+c)*b if b === d;' reduce it > further to > > x^2+7x+12 Because that rule doesn't apply. Note that x^2+3*x+4*x+12 === (x^2+3*x)+4*x+12 !== x^2+(3*x+4*x)+12. Pure doesn't do any rewriting modulo AC (associativity+commutativity). Neither does Q, it will return exactly the same result with your equations. What you can do to make this example work is add the following rule: x+(a*b)+(c*d) = x+(a+c)*b if b === d; Cheers, Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |