On 2013-09-12, David Scherfgen <d.scherfgen at googlemail.com> wrote:
> (%i1) matchdeclare(f, true);
> defmatch(df_over_f, diff(f, x) / f);
> defmatch(df_times_f, diff(f, x) * f);
> df_over_f(cos(x) / sin(x));
> df_times_f(cos(x) * sin(x));
> (%o1) done
> (%o2) df_over_f
> (%o3) df_times_f
> (%o4) [f=sin(x)]
> (%o5) false
>
> In other words:
> The pattern matcher correctly recognizes cos(x)/sin(x), but fails to
> recognize cos(x)*sin(x) - the only difference being the operator.
There are a couple of things going on here. As mentioned elsewhere in
this thread, one is that the pattern matcher only tries one ordering
of terms -- it might match if the terms happen to match the order in
pattern. Another problem is diff(...) is a so-called verb expression
which, when the derivative is unknown, evaluates to 'diff (a so-called
noun expression), which is considered to be distinct by the match
function. Still another is that there is a bug in the match function
for df_over_f -- it fails to ensure that the expression to be matched
actually contains a literal diff(...), while df_times_f does ensure
that. (Maxima's pattern matcher mostly, but not entirely, looks for
literal matches.)
About recognizing df * f, if there are multiple terms, there are many
ways of grouping them into f and df (and you'll presumably want to
omit any terms not dependent on x). I'm sure it's possible to
enumerate them and cycle through them, but I don't see a way to get
Maxima to help very much -- as far as I can see, you'll have to do
most of the work.
HTH
Robert Dodier