SymbolicUtils.jl icon indicating copy to clipboard operation
SymbolicUtils.jl copied to clipboard

function to define a rule

Open qwertyjl opened this issue 3 years ago • 2 comments

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.

qwertyjl avatar Oct 17 '22 15:10 qwertyjl

you don't need $ there.

shashi avatar Oct 17 '22 16:10 shashi

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

qwertyjl avatar Oct 17 '22 16:10 qwertyjl