JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
545 stars 114 forks source link

Simplification of Boolean expression runs forever #371

Open pevnak opened 3 years ago

pevnak commented 3 years ago

Hello,

I want to simplify a simple (in reality horribly complex and hige boolean expression, but when I add a custom simplification rules, it runs forever. A MWE follows

using Symbolics, SymbolicUtils
x1 =  SymbolicUtils.Sym{Real}(:x1)
x2 =  SymbolicUtils.Sym{Real}(:x2)

s = (x1 < 1.42) & ((x2 < 1.42) & (x2 <= -1.42))
rs = SymbolicUtils.Chain([
    @acrule (~x < ~a) & (~x <= ~b) => (~a < ~b) ? ~x <  ~a : ~x <= ~b
    @acrule (~x & ~y) & ~z  => ~x & (~y & ~z)
])

simplify(s, rewriter = rs)

but this works fine

julia> s = (x2 < 1.42) & (x2 <= -1.42)
(x2 < 1.42) & (x2 <= -1.42)

julia> simplify(s, rewriter = rs)
x2 <= -1.42

Thanks in advance for looking at the issue,