Skip to content

Q: Metatheory.jl - algebraic simplification for JuMP nonlinear expression  #157

Open
@vinhpb

Description

Hi,

I have a use case where I have long algebraic nonlinear expressions (type Expr) to be fed to an optimization model in JuMP, and I wish to simplify the expressions before feeding them to the model to reduce the solver running time and readability. I think Metatheory.jl is the right solution and have tried to use the code from test/integration/cas.jl to simplify my expressions. They were partially simplified, but not as much as SymbolicUtils.jl or MATLAB would do, as in the following example:

  • Original expression: expr = :((CB-T)-(((((((CA*T+(CA*CA-(((T+(CA-CB))-(((CA+CB)+(((((CA-(((Ti-((Ti-Ti)+CA))-((CB*CB-Ti)-(Ti-CB*CA)))+CB))-T)+((CA+CA)+(CA*T-(Ti+T))))-Ti*CB)+CA*CA))+(T+T)))+0)))+(Ti+(((((CA-((CA+(CB-T))+T))-T)+((CA+CA)+(CA*T-(Ti+CB))))-Ti*CB)+((CB+CA)-(CB-CB)))))+(((((CA+Ti)-T)+(Ti+Ti))-Ti*CB)+CA*Ti))+(((((CA-(((Ti-(CA+CB))-(((((CA-T)-T)+((CA+Ti*CA)+(CA*T-T*CA)))-Ti)-CA*T))+T))-T)+(((CA+CB)+CA)+(CA*T-(Ti+T))))-Ti*CB)+CB))-Ti)-Ti)-((Ti+Ti)-(CA-CB))))
  • Simplified with test/integration/cas.jl: expr_Meta = :((CB - T) - (CA + CB + (CA - CB) + ((((CA - (CA + T + (CB - T))) - T) + 2CA + (CA * T - (CB + Ti))) - CB * Ti) + (CA * (T + Ti) + ((((CA + Ti) - T) + 2Ti) - CB * Ti) + (CA ^ 2 - ((T + (CA - CB)) - (CA + CB + (((((CA - (CB + ((Ti - CA) - ((CB ^ 2 - Ti) - (Ti - CA * CB))))) - T) + 2CA + (CA * T - (T + Ti))) - CB * Ti) + CA ^ 2) + 2T)))) + (CB + ((CB + ((CA - (T + ((Ti - (CA + CB)) - (((2 * (CA - T) + CA * Ti) - Ti) - CA * T))))-T)+(CA*T-(T+Ti)) + 2CA) CB * Ti)) + -3Ti))
  • Simplified with SymbolicUtils.jl/MATLAB: simp_expr = 7*T - CB - 15*CA + 8*Ti - 2*CA^2 - CB^2 - CA*CB - 3*CA*T - 2*CA*Ti + 4*CB*Ti

I would really appreciate it if you can give some guidances on how should I improve the code from test/integration/cas.jl to reach simp_expr. Although SymbolicUtils.jl is able to simplify the expressions completely, Metatheory.jl is better for my use case due to its ability to transform Expr from JuMP directly. Thank you.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions