1
votes

I would like to separate this math expression 'log(2x)cos(x)' into 'log(2x)' and 'cos(x)'. Im using Sympy to solve each part of the expression. I tried regex and ast.parse to separate math operation by parts but I didn't succeeded. What I'm trying to do is to solve 'log(2x)' first, 'cos(x)' second and then 'log(2*x)*cos(x)'. How can I get each math operation from an math expression?

1
Are you always using this format x(a)operationy(b)? - NelsonGon

1 Answers

2
votes

You really shouldn't be doing this using regular expressions. You should be letting sympy parse it, and sympy separate it into terms.

>>> expr = log(2 * x) * cos(x)
>>> expr.as_ordered_factors()
[log(2*x), cos(x)]