ModelingToolkit: variables in an expression and expression simplification

Hi,
I have two questions about the ModelingToolkit package:

  • is there a function that determines the list of variables that occur in an expression?
    Example: x^2 + y - exp(y) contains x and y

  • is there a function that simplifies an expression? After writing a linear combination of expressions in my code, a “1x - 0y” pops up, and I would like the second term to be simplified (otherwise, the result of my first question may be irrelevant :sweat_smile:)

Thanks,

Charlie

No, we should add one.

simplify_expressions IIRC. It’s pretty bad and we actually need Rewrite.jl integration to be completed.

Got it, thanks Chris!
There’s a simplified_expr, but it doesn’t do the trick.

no, that’s different. That for producing Julia Exprs.

simplify_constants

Yeah, this one simplifies the multiplicative constants (it returns x - 0).

Yeah, it needs to be better. FWIW, fixing the case you mentioned there is easy, so it might be a nice thing to add. But in general, we need a rewrite system

1 Like

Hi,

I just found out that

ModelingToolkit.vars

does the trick. It returns a Set of all variables that appear in an expression.

Charlie

1 Like