This package contains definitions for common combinators that are useful for symbolic expression rewriting. Its purpose is to provide a shared library of combinators between various symbolic programming Julia packages, for example SymbolicUtils.jl, Symbolics.jl and Metatheory.jl.
A rewriter is any function which takes an expression and returns an expression
or nothing. If nothing is returned that means there was no changes applicable
to the input expression.
The Rewriters module contains some types which create and transform
rewriters.
Empty()is a rewriter which always returnsnothingChain(itr)chain an iterator of rewriters into a single rewriter which applies each chained rewriter in the given order. If a rewriter returnsnothingthis is treated as a no-change.RestartedChain(itr)likeChain(itr)but restarts from the first rewriter once on the first successful application of one of the chained rewriters.IfElse(cond, rw1, rw2)runs thecondfunction on the input, appliesrw1if cond returns true,rw2if it retuns falseIf(cond, rw)is the same asIfElse(cond, rw, Empty())Prewalk(rw; threaded=false, thread_cutoff=100)returns a rewriter which does a pre-order traversal of a given expression and applies the rewriterrw. Note that ifrwreturnsnothingwhen a match is not found, thenPrewalk(rw)will also return nothing unless a match is found at every level of the walk.threaded=truewill use multi threading for traversal.thread_cutoffis the minimum number of nodes in a subtree which should be walked in a threaded spawn.Postwalk(rw; threaded=false, thread_cutoff=100)similarly does post-order traversal.Fixpoint(rw)returns a rewriter which appliesrwrepeatedly until there are no changes to be made.PassThrough(rw)returns a rewriter which ifrw(x)returnsnothingwill instead returnxotherwise will returnrw(x).