Re: pattern bugs and comment on intuitive syntax for the New Year

*To*: mathgroup at smc.vnet.net*Subject*: [mg115205] Re: pattern bugs and comment on intuitive syntax for the New Year*From*: Richard Fateman <fateman at eecs.berkeley.edu>*Date*: Tue, 4 Jan 2011 04:25:44 -0500 (EST)*References*: <ifs30a$oor$1@smc.vnet.net> <4D21F917.2020209@cs.berkeley.edu> <48AEFA8B-880D-4B9A-B9CC-C1C7414D1384@mimuw.edu.pl>

On 1/3/2011 10:22 AM, Andrzej Kozlowski wrote: > In fact I was wrong on some points of detail concerning the role of the Flat and OneIdenitity attributes although it was you who quite spuriously introduced them into this issue. Puzzled, were you? ... snip.... > But the problem is obvious. The default for multiplication is 1 not 0. So, as you noted yourself, you need more patterns. > >> Now, using 2 rules seems to help: >> quadp[a_. x_^2+ b_. x_+c_., x_]:= qq[c,b,a] /; FreeQ[{a,b,c},x] >> quadp[a_. x_^2 +c_., x_]:= qq[c,0,a] /; FreeQ[{a,c},x] > but this clearly shows a (shocking!) lack of understanding of what is going on! Try > > quadp[x + 1, x] > > quadp(x+1,x) > This is the right answer. x+1 is not a quadratic in x. > Well, it fails on the simpler case above. As for this case, if will work if you first use Collect[r*x^2+s*x^2+1,x]. Actually you can incorporate doing Collect automatically into your function. I don't know about your wasting YOUR time. I wrote the (non-pattern) version first, and not only does it work, some simple benchmarks have it running 160X faster. Fiddling with patterns was tricky, as you seem to agree, which is really the point I was trying to explain in an article I've been writing. Indeed I then wasted MY time trying to find a pattern solution to "quadratic identification". Pattern matching is not easy to use even for moderately complicated situations, as people find out. RJF