PART+, was: Re: [Maxima] Yet another units package



Hello Wolfgang,

In considering the example below, I found a bug in the
handling of match-anything variables (i.e., declared with
matchdeclare (, true)). I will fix it.
Thanks for your help.

As for the specific example you cited,

> You also completely changed some behaviour which I
> wouldn't consider as broken. 

This statement needs qualification.

> For example, in a fresh session,
> 
> matchdeclare(%b%,atom);
> const_true(x):=true;
> /* Btw, simply `true' ought to work, too */ 
> matchdeclare(%a%,const_true);
> defmatch(foo,%b%+%a%);
> foo(x+y+y^2+z+cos(x));
> 
> used to give
>                          2
> [%b% = z + y + x, %a% = y  + cos(x)]
> 
> but with your changes in PART+ (src/matrun.lisp) it now gives
> `false'.

I don't think we want to reproduce this, since it
is incorrect:  atom(z + y + x) => false.

I want PART+ and PART* to act correctly, but the behavior
of the previous version gives rather weak guidance; it is
easy to find examples in which it is strange, or flatly wrong. 

E.g., in the example above, if the roles of %a% and %b% are
exchanged (i.e., %a% is the atom and %b% is anything)
the result of foo is different. It is easy to find other
examples in which the results depend on the ordering of
the formal or actual variables (the existing PART+
has inherited this bug). In a new session,

  matchdeclare (%a%, atom, %b%, true)$ defmatch (foo ,%b% + %a%)$
  foo (x+y+y^2+z+cos(x)); => [%b% = z + y  + y + COS(x) + x, %a% = 0]

Hmm, I guess that's not incorrect, but it's still odd -- 
why didn't foo try to find a nontrival atom? I guess I'll 
give it some encouragement:

  nza(e) := atom(e) and e # 0$ matchdeclare (%a2%, nza)$
  defmatch (foo2, %b% + %a2%)$ foo2 (x+y+y^2+z+cos(x)); => false

Oops.

At this point I have two suggestions. (1) Why don't we steer 
the discussion towards how we want matching of + and * to work.
I will revise PART+/PART* as needed to make it conform.
(2) If you have some examples (existing or made-up, trivial
or nontrivial) which exercise PART+/PART*, I will be very
much obliged if you send them to me. I have a set of test
cases, but clearly it isn't large enough.

Pattern matching is very general, powerful, and useful.
I truly want it to work correctly. I know you do too, so
I can count on your help.

All the best,
Robert Dodier

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com