My apologies if this has already been addressed.
Let’s say we have
using ModelingToolkit
@variables t x(t) y(t) z(t)
ex = x * y + z
How should I extract the sub-expression x * y
from ex
? It’s not clear to me how I’d traverse the expression tree in the documentation, nor did I see any way to do this via filtering.
I don’t seek to build a function. I’m fine with the output being an expression or string x * y
. I want to extract products to populate nodes in a graph later on. For now, all the expressions would just have sums and products, and I’d want to get all the products.
I could do split(string(ex), ['+', '-'])
, and use this result, and am currently working on this route. I still wonder if I’m not seeing a better way.