JuliaSymbolics / SymbolicUtils.jl

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

`substitute` doesn't substitute `x*z` in `x*z*k`? #443

Open hwpang opened 2 years ago

hwpang commented 2 years ago

I expect substitute to substitute the xz in xz*k, but it doesn't? Is there a workaround? I'm using version 0.19.7. Here's a minimal working example:

using SymbolicUtils

@syms x y z k

y = x*z*k

eq = 0.0 ~ y

println(eq.rhs) #got x*z*k
println(substitute(eq.rhs,Dict(x*z=>0))) #expecting to get 0, but got x*z*k
YingboMa commented 2 years ago

substitute doesn't do commutative-associative matching. Have you tried to use @rule?

shashi commented 2 years ago

I think @rule is also inadequate or annoying here... I've been thinking about this a bit and i think we need better predicates for AC operations.

0x0f0f0f commented 4 months ago

I think @rule is also inadequate or annoying here... I've been thinking about this a bit and i think we need better predicates for AC operations.

Could e-matching with Metatheory.jl help out?

0x0f0f0f commented 4 months ago

I've been thinking a lot about supporting AC operations in e-graphs.