find shared constant in two expressions



Thanks for your question.

In the future, could you please provide *reproducible* examples (i.e.
including the code of 'separable') and show output in linear form
(display2d:false)?  That will make it much easier for us to help you.

In this case, it looks like %o2 is [x*log(x)/(4*log(2)^2),4*g(y)*log(2)^2].
 Call that L.

If L[1] and L[2] are always in multiplicative form, I'd think you could do
something pretty simple-minded:

constant_factors(expr) :=
      block([inflag:true],
           if not mapatom(expr) and op(expr)="*"
           then xreduce("*",listify(subset(setify(args(expr)),'constantp)))
           else 1)$
/* remember to do declare([param1,param2,...],constant) if you have
symbolic parameters */
/* alternatively, you could pass the variables as arguments and use
'member' in the subset filter */

separable_fix(list) :=

block([common:gcd(constant_factors(1/factor(list[1])),constant_factors(factor(list[2])))],
                  [list[1]*common,list[2]/common ] )$

separable_fix(L) => [x*log(x),g(y)]

Then again, you might be able to use similar techniques to rewrite
'separable'.  But since you haven't shared the code for that with us, ....

              -s


On Fri, Sep 7, 2012 at 5:41 PM, nijso beishuizen <nijso at hotmail.com> wrote:

>  Hello,
>
> I have written a simple function separable(expr,x,y) to test if expr is
> separable, i.e. expr can be written as f(x)*g(y).
> However, the algorithm sometimes leads to the introduction of constants
> like f(x)/C and C*g(x).
> example:
> (%i2) L:separable(x*log(x)*g(y),x,y);
>                  x log(x)                2
> (%o2)/R/  [---------, 4 g(y) log (2)]
>                      2
>               4 log (2)
>
>
> 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?
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>