Re: rule sets and patterns, was ...Re: [ Homological Algebra in Maxima]



Hi Professor Fateman,

thanks for replying!  I was starting to worry nobody cared.

On Fri, Jun 13, 2003 at 11:21:42AM -0700, Richard Fateman wrote:
> Some of your stuff could be done with pattern matching,
> via tellsimp and matchdeclare
> some of it is not sufficiently defined, e.g.
> 
> tor(a+b,g) --->  tor(a,g) +  something.
> 
> Does b have to be nonzero?  if not, this is an infinite
> loop.

Is it really?  If I understand correctly, it would only lead to an
infinite loop if the system likes to introduce +0s.  In any case, I
think math'a's built in reductions for addition take precedence to my
function definitions and this problem doesn't really arise (ie the +0s
vanish before the above rewrite is ever even applied).

>  is tor(x+y+45) possible?

Certainly.  

Tor[a + b + c, G] => Tor[a, G] + Tor[b, G] + Tor[c, G]

In all the little term rewriting systems I've written by hand I
usually do + as a nested binary operation, so x+y+45 might for
instance be represented as x + (y+45) and the pattern works fine.
However, I certainly get the sense that math'a implements a long sum
as a single list rather than nested binary operations and I'm not sure
how the pattern matcher chooses to apply my binary rewrite to such a
list (I can certainly think of a few ways).  However, the way I
specified the rule (as the sum of two terms) is in fact the way that
the math'a book suggests implementing linearity: "x_ + y_ a sum of two
*or more* terms" (section 2.3.13)

Anyway, I certainly am not insisting that I implement the rewrites
within maxima the exact same way as I did in math'a.  I was just
providing the math'a code to try to illustrate as concretely as
possible what I'm trying to do.

> you can write functions like  tor(a,g):= if inpart(a,0)="+" then
>   map(lambda([r],tor(r,g)), a) else ....
> 
> which is not quite pattern replacement syntax, but may actually
> do the job a lot better.

Will this actually work?  So I would code up a bunch of conditions
checking for special reducible cases, but then what do I put at the
end if none of them match?  I can't do tor(a,g), can I?  Wouldn't that
lead to infinite recursion?

Thanks,
  Carl