JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
541 stars 108 forks source link

RFC Decouple rule definition and classical pattern matching from SU and Metatheory.jl for interstellar grade integration. #355

Open 0x0f0f0f opened 3 years ago

0x0f0f0f commented 3 years ago

Other than e-graphs rewriting, Metatheory.jl still offers some features that overlap with SymbolicUtils.jl features. Those features are rule creation and manipulation and classical rewriting/pattern matching. In SU classical rewriting is battle tested, in MT its used very few times and sucks. The purpose of classical rewriting is basically the same in both MT and SU. By now, in Metatheory v0.5 I've removed the dependency to the MatchCore.jl pattern matching system because it was a metaprogramming mess and did not bring any particular benefit over other approaches, and built from scratch a crappy pattern matcher that just works but is truly naive.

Most importantly, making those components shared will allow for seamless integration and interoperability between the two rewriting systems. A primary goal of this RFC is to make MT and SU accept the same systems of rules in both egraphs and classical rewriting, and to make MT use the already existing, excellent SU backend for classical rewriting without re-implementing the entire rule pattern matcher stack. The best goal would be having the same (abstract?) types for rules in both systems, and even better having a RewriteRules.jl package defining an interface to allow users to define their own rules semantics and pattern matchers, without being specifically tied to MT data structures or SU symbolic types , just to TermInterface.jl, to maintain generality without losing the specific optimizations of SU or the MT virtual machine egraph pattern matcher.

(Yes, I'd like to remove classical rewriting from MT and leave it to this shared component).

The steps may be the following: Separate the rule definition eDSL and make it shared with the same consistent, specified syntax. Separate the rule type hierarchy and make it shared. Separate the pattern matching system and make it shared, separate the pattern definition and type hierarchy and make it shared.

Rules and Pattern Matching

SU rules build from exprs, construct symbolics terms and then build a staged pattern matching RGF function. MT used to do this at first. Now it has got some useful types: Patterns. MT rules are part of a hierarchy <:AbstractRule with BidirectionalRule and SymbolicRule as the main types. SU does not yet have any BidirectionalRule system, while SU.Rule is nothing else than MT's DynamicRule. MT does not have yet knowledge of ACRule but that would be really cool to have. Ideas:

Benefits SU -> MT

Benefits MT -> SU

Inconsistencies

0x0f0f0f commented 3 years ago

See also https://github.com/JuliaSymbolics/TermInterface.jl/issues/6