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

Remove `unsorted_arguments` from Walks in Rewriters

0x0f0f0f opened this issue · comments

x = p.similarterm(x, operation(x), map(PassThrough(p), unsorted_arguments(x)); exprhead=exprhead(x))

This was something that could have made sense strictly in SymbolicUtils.jl where terms are optimized during construction, in a general purpose setting this may make things slower but won't mess up terms.

An example of why this is an issue. In SymbolicUtils.jl @ syms a b ; b + a is always automatically reduced to a + b because of the constructor of Add. In other term types, if unsorted_arguments really provides an unsorted representation, it is dangerous to use it in Walk, because the constructor may just store arguments in their order. This has happened to me with Term. cc @shashi

The speedup here is good enough that we need to allow it, preferably by default. I don't yet believe it is dangerous in walk -- walk means to visit every node.