Given a non-polynomial expression such as:
expr = x z Sin[x] Sin[y]
and that we know that the variables are:
var = {x,y,z}
... is there a neat way to express expr
as:
{x Sin[x], Sin[y], z}
i.e. with the $x$ terms separated out, the $y$ terms separated out and the $z$ terms separated out ... if that separation is possible. The order does not matter ... what matters is that if the function is separable into $x$, $y$ and $z$, then that we separate the output into parcels containing just $x$, just $y$ and just $z$. If it helps, am happy to assume that expr
is a product of terms.
Most of the functions I have looked at (like MonomialList
or Collect
) seem to assume polynomial expressions.
I was thinking of something like: expr /. Times -> List
followed by some FreeQ
checks, but it might be messy, and I was wondering if anyone has a neater approach?
Second example
expr2 = x z Sin[x] Sin[y+z]
should return:
{x Sin[x], z Sin[y+z]}
expr2 = x z Sin[x] Sin[y + z]
? $\endgroup$expr2
, as: {x Sin[x]
,z Sin[y+z]}
$\endgroup$