Rewriting broadcasted functions doesn't work
jenkspt opened this issue · comments
Penn Jenks commented
The following works as expected
julia> r = @rule a b log(a / b) --> log(a) - log(b)
julia> r(:(log(x / y)))
:(log(x) - log(y))
However I'm interested in matching broadcasted functions in expressions, but the following doesn't work:
julia> r = @rule a b log.(a./b) --> log.(a) - log.(b)
julia> r(:(log.(x./y)))
(nothing)
broadcasting binary operators does work
julia> r = @rule a b a .+ b --> b .+ a
julia> r(:(x .+ y))
:(y .+ x)
using the broadcast function doesn't work
julia> r = @rule a b broadcast(+, a, b) --> broadcast(+, b, a)
julia> r(:(broadcast(+, x, y)))
(nothing)
I briefly looked into TermInterface.jl, and am wondering if the fact that exprhead returns :.
for some expressions and :call
for others is the culprit.
julia> exprhead(:(a .+ b))
:call
julia> exprhead(:(log.(a)))
:.
Alessandro Cheli commented
Yes, may be the culprit. Need to debug.