Trouble with the pattern matcher ...



On 9/13/2013 12:24 AM, Rupert Swarbrick wrote:
> Robert Dodier <robert.dodier at gmail.com> writes:
>> About recognizing df * f, if there are multiple terms, there are many
>> ways of grouping them into f and df (and you'll presumably want to
>> omit any terms not dependent on x). I'm sure it's possible to
>> enumerate them and cycle through them, but I don't see a way to get
>> Maxima to help very much -- as far as I can see, you'll have to do
>> most of the work.
> I was thinking about this. Could we not extend the pattern matcher to
> test the n! possible permutations when someone gives it an operator with
> more than two operands.
There is a substantial literature on what in logic is called 
unification.  If you have
commutativity, and identities, it gets costly.  There is also a 
substantial literature
including programs, on expression matching.  This is not exactly the 
same as unification
(which really has 2 patterns to match).

Probably one way of thinking (more) about this is to read all about the 
Mathematica
pattern matcher, and decide if that is what you really want.  If so, use 
an implementation
of it (in Lisp).  Matches can take time exponential in the size of the 
input.


>   We'd change the "This doesn't work with + or *"
> to "This is horrifically slow with + or *", but the result would
> probably still be more useful... ?
Short of adopting the whole thing, you could write a  "matchplus" and 
"matchtimes"
program, and have it do whatever you want. But then the user might have 
other
commutative-with-identity-n-ary operators in mind.

   Should the pattern a*b  match the expression
4?   If so,  and there are conditions such as f(a,b)>3,  what do you do?
Try {a=1,b=4}, {a=4,b=1}  { a=1/9, b=36} ....

>
> I haven't thought through the interface carefully: for example, should
> the user have to specify the number of operands? David's 1*f example
> gives a case where maybe it's not completely obvious how many there are.
It is not just the interface that matters.  Does the pattern a^2 +b 
match  (x-1)*(x+1)?

Looking at existing PROGRAMS shows something of the spectrum of 
possibilities.
In addition to Mathematica, there are matching programs in Reduce, 
Maple,  and
probably Axiom.  There are 3 matching programs in Maxima:  see 
letrules,  defmatch,
and the (internal, lisp) matcher called M1  or M2 in the integration 
program.

RJF