Skip to main content
QUICK REVIEW

[Paper Review] Non-linear Associative-Commutative Many-to-One Pattern Matching with Sequence Variables

Manuel Krebber|arXiv (Cornell University)|May 2, 2017
Algorithms and Data CompressionComputer Science44 references7 citations
TL;DR

This paper presents a generalized discrimination net (MLDN) for non-linear, associative-commutative many-to-one pattern matching with sequence variables, implemented in an open-source Python library. It achieves significant speedups over one-to-one matching by exploiting pattern similarities, with performance gains observed even for moderate pattern set sizes and subject counts.

ABSTRACT

Pattern matching is a powerful tool which is part of many functional programming languages as well as computer algebra systems such as Mathematica. Among the existing systems, Mathematica offers the most expressive pattern matching. Unfortunately, no open source alternative has comparable pattern matching capabilities. Notably, these features include support for associative and/or commutative function symbols and sequence variables. While those features have individually been subject of previous research, their comprehensive combination has not yet been investigated. Furthermore, in many applications, a fixed set of patterns is matched repeatedly against different subjects. This many-to-one matching can be sped up by exploiting similarities between patterns. Discrimination nets are the state-of-the-art solution for many-to-one matching. In this thesis, a generalized discrimination net which supports the full feature set is presented. All algorithms have been implemented as an open-source library for Python. In experiments on real world examples, significant speedups of many-to-one over one-to-one matching have been observed.

Motivation & Objective

  • To address the lack of open-source support for advanced pattern matching features such as associative and commutative function symbols and sequence variables.
  • To extend discrimination nets—state-of-the-art for many-to-one matching—to support non-syntactic, non-linear pattern matching with associative, commutative, and variadic function symbols.
  • To implement and evaluate a many-to-one matching algorithm that outperforms one-to-one matching in repeated pattern matching scenarios.
  • To provide a practical, open-source solution for symbolic computation and compiler development, with integration potential into systems like SymPy.

Proposed method

  • Design a generalized discrimination net (MLDN) that supports associative, commutative, and non-linear patterns with sequence variables.
  • Extend term rewriting and pattern matching algorithms to handle non-syntactic matching under associativity and commutativity constraints.
  • Implement a many-to-one matching engine using MLDNs that pre-index patterns to exploit structural similarities across multiple matches.
  • Use a canonicalization strategy for associative-commutative terms to enable consistent pattern comparison and indexing.
  • Integrate the algorithm into the open-source Python library MatchPy, supporting both one-to-one and many-to-one matching.
  • Apply code generation and performance optimization techniques, including potential Cython porting, to improve runtime efficiency.

Experimental results

Research questions

  • RQ1Can a generalized discrimination net be designed to support non-linear, associative, commutative, and sequence-variable pattern matching in a many-to-one setting?
  • RQ2How does the performance of many-to-one matching with MLDNs compare to one-to-one matching in real-world symbolic computation workloads?
  • RQ3What is the break-even point for amortizing the construction cost of MLDNs, and how does it scale with pattern set size and subject count?
  • RQ4How do structural similarities and overlaps between patterns affect the efficiency and size of the resulting MLDN?
  • RQ5To what extent can the MLDN approach be extended to support additional features like context variables or function variables?

Key findings

  • The MLDN approach achieves significant speedups over one-to-one matching in real-world examples, with the break-even point for amortizing construction cost consistently reached within the magnitude of the pattern set size.
  • Many-to-one matching with MLDNs outperforms one-to-one matching for applications matching more than a few hundred subjects against the same pattern set.
  • The size of the MLDN grows sublinearly in practice, indicating good scalability for large but structurally similar pattern sets.
  • While VSDNs (variadic sequence discrimination nets) are faster at matching, they incur significantly higher setup times and can grow exponentially in state count, making them unsuitable for large or complex pattern sets.
  • The open-source library MatchPy, which implements the proposed algorithms, enables practical use of advanced pattern matching in symbolic computation and compiler development.
  • Future integration with SymPy and potential code generation or Cython porting could further enhance performance and usability for scientific computing workloads.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.