JuliaSymbolics / SymbolicUtils.jl

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

Issue with creating rule for even and odd function of cos and sin #545

Closed yewalenikhil65 closed 10 months ago

yewalenikhil65 commented 10 months ago
using SymbolicUtils
@syms z
r  = @acrule(cos(-1(~x)) => 1*cos(~x))

gives as expected

julia> r(cos(-z))
cos(z)

but for following, it doesn't work

julia> r(cos(-2z))

gives nothing

Can any one help me to generalise this rule ?

NilsNiggemann commented 9 months ago

Why was this closed as completed? As far as I can see, this is still not working and in particular one cannot use it to simplify expressions in Symbolics.jl.


julia> r  = @acrule(cos(-1(~x)) => 1*cos(~x))
ACRule(cos(-1 * ~x) => 1 * cos(~x))

julia> simplify(cos(a) - cos(-a),rewriter = r)
cos(a) - cos(-a)

julia> r = @rule cos(-(~x))  => cos(~x)
cos(-(~x)) => cos(~x)

julia> simplify(cos(a) - cos(-a),rewriter = r)
cos(a) - cos(-a)

arguably, these properties should be included in the standard rules, or at least there should be some mention in the docs if it is not possible to make them work.

yewalenikhil65 commented 9 months ago

@NilsNiggemann I was told by Symbolics code maintainer to close it since it was answered to me on slack.. I will post details how i did it as soon as possible next week and try to make a PR out of this