find shared constant in two expressions



The 'optimize' function looks for common subtrees, not common
subexpressions, so it is rarely useful for cases like this.

For example, optimize(a*b+a*b*c) and optimize(a*b+1/(a*b)) do not find the
common subexpression a*b, though optimize(a*b+k^(a*b)) does.  Similarly,
with dotassoc:false, optimize(a.b.c+b.c) does find the common subtree b.c,
since a.b.c is interpreted as a.(b.c).

               -s

On Sat, Sep 8, 2012 at 2:25 PM, Robert Dodier <robert.dodier at gmail.com>wrote:

> On 2012-09-07, nijso beishuizen <nijso at hotmail.com> wrote:
>
> > so even though xlog(x)*g(y) is separated correctly into xlog(x) and
> > g(y), it introduces the constant 4*log^2(2).
> > Is there a simple way to find out if two expressions have a shared
> > constant factor so I can eliminate the constant C?
>
> I don't know a general solution, but maybe the function 'optimize' can
> help.
>
>   e:4*log(2)^2;
>   L:[f(x)/e, e*g(y)];
>   optimize (L);
>    => block([%1],%1:log(2)^2,[f(x)/(4*%1),4*%1*g(y)])
>
> In this example, optimize found log(2)^2 as a common factor, but not
> 4*log(2)^2. I don't know if that's enough.
>
> best
>
> Robert Dodier
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>