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

Rewriting broadcasted functions doesn't work

Open jenkspt opened this issue 2 years ago • 1 comments

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)))
:.

jenkspt avatar Apr 01 '22 18:04 jenkspt

Yes, may be the culprit. Need to debug.

0x0f0f0f avatar Apr 05 '22 09:04 0x0f0f0f