Ask Your Question

Revision history [back]

How to recursively factor a symbolic expression?

In integral containing products of bessel functions , the answer after applying the factor method is some expression whose numerator is not "completely factored". For aesthetics or because it is easier to work with, we may want to factor the numerator too.

Is there a way to factor a symbolic expression recursively?

Take this example:

sage: expr = x*y - x*z + 4*z*y*x
sage: factor(expr2)
(4*y*z + y - z)*x
sage: _.operands()[0].factor()
4*y*z + y - z
sage: __.operands()[0].canonicalize_radical() 
(4*y - 1)*z + y
sage: _.factor() 
4*y*z + y - z

so it seems that applying recursively the factor command to the expression tree alone doesn't succeed to get ((4*y - 1)*z + y)*x.

How to recursively factor a symbolic expression?

In integral containing products of bessel functions , the answer after applying the factor method is some expression whose numerator is not "completely factored". For aesthetics or because it is easier to work with, we may want to factor the numerator too.

Is there a way to factor a symbolic expression recursively?

Take this example:

sage: , var x y z
sage: expr = x*y - x*z + 4*z*y*x
sage: factor(expr2)
(4*y*z + y - z)*x
sage: _.operands()[0].factor()
4*y*z + y - z
sage: __.operands()[0].canonicalize_radical() 
(4*y - 1)*z + y
sage: _.factor() 
4*y*z + y - z

so it seems that applying recursively the factor command to the expression tree alone doesn't succeed to get ((4*y - 1)*z + y)*x.