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

Add a single `@rule` to `simplify`

Open greimel opened this issue 3 years ago • 3 comments

I would it be nice if one could easily add a custom simplification rules on top of the default rules in simplify.

@shashi said on slack, that this is not so easy currently, and asked me to open an issue here.

greimel avatar Aug 11 '22 06:08 greimel

It seems to be solved with

expr = 1/Symbolics.Term(sqrt, 2))^2 
#
r1 = @rule sqrt(~x)^2 => ~x
r2 = @rule (~x/~y)^2 => (~x)^2 / (~y)^2
#
simplify(expr, RuleSet([r1,r2]))
image

mmikhasenko avatar Dec 29 '22 12:12 mmikhasenko

Not sure. Doesn't that only use the two specified rules?

I'd like all predefined rules plus one or two extra.

greimel avatar Dec 29 '22 19:12 greimel

I see. You are probably right. One might need to apply one more |> simplify after your extra rule.

mmikhasenko avatar Dec 30 '22 10:12 mmikhasenko