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