I’m trying to translate some patterns written in Mathematica to Symbolics.jl to explore the latter package. I’m interested in conditions (e.g. type constraints) imposed on patterns. This is handled by “predicates” in SymbolicUtils.jl. As a simple example, a Mathematica pattern f[a_Integer]
is translated into f(~a::Int)
in Symbolics.jl.
Now a slightly more complicated situation. Is it possible to write down a pattern which only matches f(a, b)
if a<b
is satisfied? In Mathematica, this pattern is written as f[a_, b_] /; a<b
. Is there any equivalent in Symbolics.jl, or elsewhere in the Julia ecosystem for term rewriting?
A more concrete example. In Mathematica, I can use rewrite rules to sort a list of arguments (just for fun), like this
sortRule = f[a___, b_, c_, d___] /; b>c :> f[a, c, b, d]
Then f[3, 1, 2] //. sortRule
evaluates to the sorted version f[1, 2, 3]
. Is it possible to reproduce this example using rewriting rules in Symbolics.jl or other Julia packages?
P.S. The roadmap for Symbolics.jl mentions the exciting goal of porting Rubi, a Mathematica package for indefinite integration based on a large collection of rewrite rules. I suppose that feature parity with Mathematica’s pattern matching would be needed to make this happen?