PART+, was: Re: [Maxima] Yet another units package
Subject: PART+, was: Re: [Maxima] Yet another units package
From: Robert Dodier
Date: Wed, 4 May 2005 07:42:22 -0700 (PDT)
--- Wolfgang Jenkner wrote:
> Richard Fateman writes:
>
> > A pattern like a+b does NOT try all possible partitions.
> > I believe that it picks one item for a. Everything else
> > is grouped as b.
>
> It picks all items matching a (as the example shows).
> Whoever wrote this version of PART+, the code is quite
> clear (I constructed the example after looking at it)
> and it leaves no doubt about the intended behaviour.
This interpretation is in conflict with the description
of matchdeclare given in the post-2000 texinfo files
(i.e., after Project MAC and before I touched either the
code or the documents). The description states,
"MATCHDECLARE associates a predicate with a pattern variable
so that the variable will only match expressions for which
the predicate is not FALSE... If the match succeeds then the
variable is set to the matched expression."
This statement rules out matching a variable to a sum of
terms satisfying the match predicate (unless the sum also
satisfies the predicate).
A consequence of the interpretation favored by Wolfgang
is that one cannot distinguish the operands foo(x) and
foo(y) in an expression foo(x) + foo(y). This seems odd.
A more plausible interpretation of the code is that it
is intended to try different orderings of arguments, so
that different permutations of the arguments can match.
In fact, the code works in exactly this manner, so long
as all arguments are distinguishable according to the
predicates (otherwise the behavior described above is triggered).
(%i1) matchdeclare (a1, integerp, b1, listp)$
(%i2) matchdeclare (b2, integerp, a2, listp)$
(%i3) defmatch (foo1, a1 + b1);
B1 + A1 partitions SUM
(%o3) foo1
(%i4) defmatch (foo2, a2 + b2);
B2 + A2 partitions SUM
(%o4) foo2
(%i5) listarith: false$
(%i6) foo1 (88 + [1, 2, 3]);
(%o6) [B1 = [1, 2, 3], A1 = 88]
(%i7) foo2 (88 + [1, 2, 3]);
(%o7) [B2 = 88, A2 = [1, 2, 3]]
For reference: the code in question is the loop beginning
with the label A in PART+, from A to the end of the function.
http://cvs.sourceforge.net/viewcvs.py/maxima/maxima/src/matrun.lisp?rev=1.1
regards,
Robert Dodier
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com