# [Maxima] patterns for integration

Richard Fateman fateman at cs.berkeley.edu
Mon Mar 24 17:40:45 CDT 2008

```first of all, I think this pattern is handled inside sin.lisp, the symbolic
integration code by Joel Moses.

Next, if you want to match products, you might want to make sure that the
target expression is factored. That is, x*sin(x)+3*sin(x) does not
necessarily match the pattern (polynomial)*sin(x).

also, if you want to match a complicated expression, you can do it in steps.

for example,
matchdeclare(tt,true);

then look for  tt*sin(x),  etc.

Or you might write a program that looks through an expression and finds all
occurrences of sin, cos, exp.
then tests their arguments to see if they look like a*x+b. then when you
know a,b,
look for
tt*sin(a*x+b)
etc

Then see if tt is a polynomial in x.

If you want the program to just flounder around for a while trying all
possible ways of matching something, don't expect it to be efficient or even
effective.
You seem to want some kind of unification program, rather than matching, and
that is extremely expensive to run.

RJf

> -----Original Message-----
> From: maxima-bounces at math.utexas.edu
> [mailto:maxima-bounces at math.utexas.edu] On Behalf Of Robert Dodier
> Sent: Sunday, March 23, 2008 9:18 AM
> To: Robert Marik
> Cc: maxima at math.utexas.edu
> Subject: Re: [Maxima] patterns for integration
>
> On 3/22/08, Robert Marik <marik at mendelu.cz> wrote:
>
> > polynomialpx(e):=polynomialp(e,[maw_var]) and
> > hipow(e,maw_var)>0;
> > nonzero_constant(e):=constantp(e) and (e#0);
> > matchdeclare(pp1,polynomialpx,aa1,nonzero_constant,bb1,constantp);
> > defmatch(polexp,pp1*exp(aa1*maw_var+bb1));
> >
> > (maw_var is variable)
> > Is it possible to modify it to match the pattern
> "polynomial*f(a*x+b)"
> > where f is sin, cos or exp ?
>
> Yes, a function name can be a match variable (and for defmatch
> and defrule, it can even be the main operator).
> Unfortunately while working with the example you showed,
> I encountered a bug in the pattern-matching code. I fixed it,
> but the stuff shown below doesn't work with any existing release.
>
> So (after the bug is fixed) a pattern of the form
>
> matchdeclare (foo, lambda ([ee], member (ee, '[sin, cos])));
> defmatch (polfoo, pp1 * foo (aa1 * maw_var + bb1));
>
> detects a polynomial times sin or cos. e.g.
>
> maw_var : 'u;
> polfoo ((5*u^3 + u - 7) * sin (2*u + 6));
>  => [bb1 = 6, aa1 = 2, foo = sin, pp1 = 5*u^3 + u - 7]
>
> Unfortunately there is still more strangeness.
> member(ee, '[sin, cos, exp]) fails to detect exp(...) because
> exp(...) simplifies to %e^(...). I suppose it is possible to work
> around that although I suspect it is somewhat involved.
> Also, a different match function is constructed if the pattern
> is sorted differently, e.g. cc1 * foo(...) vs pp1 * foo(...),
> and that function matches some different patterns.
> That's a bug too, and I don't yet see a way to fix it.
>
> So in summary I'm afraid I have to tel you that the existing
> pattern-matching functions aren't well-suited to this
> particular problem.
>
> best,
>
> Robert Dodier
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
```