JuliaSymbolics / Metatheory.jl

Makes Julia reason with equations. General purpose metaprogramming, symbolic computation and algebraic equational reasoning library for the Julia programming language: E-Graphs & equality saturation, term rewriting and more.

Home Page:https://juliasymbolics.github.io/Metatheory.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rewriting broadcasted functions doesn't work

jenkspt opened this issue · 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)))
:.

Yes, may be the culprit. Need to debug.