Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vinhpb opened this issue May 29, 2023 · 0 comments
Open

Comments

@vinhpb
Copy link

vinhpb commented May 29, 2023

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.

@vinhpb vinhpb changed the title Q: Metatheory.jl code algebraic simplification for JuMP nonlinear expression Q: Metatheory.jl - algebraic simplification for JuMP nonlinear expression May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant