JuliaSymbolics / SymbolicUtils.jl

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

function to define a rule #479

Open qwertyjl opened 1 year ago

qwertyjl commented 1 year ago

It would be nice to have a function to define a rule. The problem with macros is that sometimes it becomes difficult to interpolate all the variables correctly.


I also report a problem:

@variables x[1:10]
r1 = [@acrule(*($i, $j, $k) => 0) for (i, j, k) in collect(combinations(x, 3))] # example: x[1]*x[2]*x[3] => 0
println(r1[1]) # ACRule($i * $j * $k => 0), instead of ACRule(x[1] * x[2] * x[3] => 0) 

Despite this, the generated rules work correctly when simplifying.

shashi commented 1 year ago

you don't need $ there.

qwertyjl commented 1 year ago

Sometimes if I don't put $, the rules don't work in simplification. Example:

@variables x[1:10]

r2 = [@acrule(*(x[2], x[5]) => 0)]
r3 = [@acrule(*($(x[2]), $(x[5])) => 0)]
f = x[2]*x[5]

simplify(f, RuleSet(r2)) # x[2]*x[5]
simplify(f, RuleSet(r3)) # 0