Papers
Topics
Authors
Recent
Search
2000 character limit reached

Hyper Pattern Matching: Theory & Applications

Updated 6 July 2026
  • Hyper pattern matching is a generalization of conventional pattern matching that extracts relational witnesses from multiple words or data structures.
  • It employs nondeterministic asynchronous finite automata to capture tuples of subwords, enabling analysis of hyperproperties like noninterference and robustness.
  • Advanced heuristics such as FJS-style skipping and projection-based pruning improve performance on NP-complete matching problems in various practical applications.

Hyper pattern matching denotes a family of pattern-matching problems in which the evidence for a match is not confined to a single exact occurrence in a single word. In the most explicit formalization, it is a generalization of pattern matching from one word to a finite set of words, with matches defined by tuples of subwords accepted by a nondeterministic asynchronous finite automaton (NAA) (Waga et al., 16 Jul 2025). Related research on generalized function matching, non-linear matching over unfree data types, many-to-one matching modulo associativity and commutativity, Cartesian-tree matching, and hypergraph pattern matching suggests a broader usage in which “hyper” designates pattern systems that match structural, relational, or higher-arity constraints rather than literal symbol equality (Mincu, 2019).

1. Formal scope and core definitions

In the runtime-verification formulation, the input is a finite set of words $w \subseteq \Alphabet^*$, and the pattern is an NAA

$A = (\Alphabet, K, S, S_0, F, \delta),$

where $K = \{\var[1], \dots, \var[k]\}$ is a finite set of directions, SS is a finite nonempty set of states, S0SS_0 \subseteq S is the set of initial states, FSF \subseteq S is the set of accepting states, and $\delta \subseteq S \times \Alphabet \times K \times S$ is the transition relation. The language of the automaton is a set of kk-tuples of words,

$L(A) \subseteq (\Alphabet^*)^k,$

obtained by projecting accepting words over $\Alphabet \times K$ to each direction. The match set is

$A = (\Alphabet, K, S, S_0, F, \delta),$0

so a hyper match is a tuple of intervals, possibly drawn from different words, whose extracted subwords jointly satisfy the automaton (Waga et al., 16 Jul 2025).

This formalization differs from conventional pattern matching in two respects. First, the witness is relational: it is a tuple of substrings rather than a single substring. Second, the reading discipline is asynchronous: different directions advance independently. The counting example in the NAA model accepts pairs $A = (\Alphabet, K, S, S_0, F, \delta),$1 such that $A = (\Alphabet, K, S, S_0, F, \delta),$2 and $A = (\Alphabet, K, S, S_0, F, \delta),$3, already showing that the fundamental object is a relation between words rather than a language of single words (Waga et al., 16 Jul 2025).

A broader technical landscape uses different formalisms for analogous goals. Generalized function matching asks, for a pattern $A = (\Alphabet, K, S, S_0, F, \delta),$4 and text $A = (\Alphabet, K, S, S_0, F, \delta),$5, for a mapping $A = (\Alphabet, K, S, S_0, F, \delta),$6 such that

$A = (\Alphabet, K, S, S_0, F, \delta),$7

a substring of $A = (\Alphabet, K, S, S_0, F, \delta),$8; the non-empty-image variant restricts $A = (\Alphabet, K, S, S_0, F, \delta),$9 (Mincu, 2019). Egison-style systems instead define pattern matching over unfree data types such as sets and multisets, with multiple decompositions, non-linear constraints, and backtracking (Egi, 2014). Hypergraph pattern matching takes a query hypergraph $K = \{\var[1], \dots, \var[k]\}$0 and a data hypergraph $K = \{\var[1], \dots, \var[k]\}$1 and seeks all subhypergraph embeddings (Song et al., 11 Dec 2025). This suggests that “hyper pattern matching” is not a single universal formalism but a cluster of formalisms united by relational, structural, or higher-order matching semantics.

2. Hyperproperties and asynchronous witness extraction

The explicit motivation for hyper pattern matching arises in runtime verification. Ordinary pattern matching on a single word can witness violations of trace properties, but witnessing violations of hyperproperties requires evidence across multiple traces or across multiple parts of the same trace. Hyperproperties are properties of sets of traces rather than individual traces. Noninterference and robustness are canonical examples: they relate pairs of executions, not single executions (Waga et al., 16 Jul 2025).

The NAA formalism is used to encode such relational witnesses. In the noninterference example, two directions represent two executions. The automaton first synchronizes on the same initial public value and the same input sequence, then transitions to an accepting “inconsistent” state when the public outputs diverge. Any element of $K = \{\var[1], \dots, \var[k]\}$2 is therefore a concrete witness of interference: a pair of sub-executions with aligned low inputs but different low outputs (Waga et al., 16 Jul 2025).

The robustness example uses words over $K = \{\var[1], \dots, \var[k]\}$3, with $K = \{\var[1], \dots, \var[k]\}$4 and $K = \{\var[1], \dots, \var[k]\}$5. The NAA uses self-loops to account for stuttering, and it checks that stutter-equivalent inputs induce stutter-equivalent input-output traces. A match in $K = \{\var[1], \dots, \var[k]\}$6 is a pair of subwords showing a violation of stuttering robustness. The same mechanism also applies when different directions are assigned to different intervals of the same word, so the model is not limited to multiple logs; it can also witness relations between disjoint segments of one log (Waga et al., 16 Jul 2025).

This asynchronous automata-theoretic view is significant because it differs from synchronous hyper logics that compare traces positionwise. The NAA semantics permits different directions to advance at different rates, which is essential for stuttering robustness and similar asynchronous hyperproperties. The paper explicitly situates this setting against asynchronous logics such as A-HyperLTL, HyperLTL$K = \{\var[1], \dots, \var[k]\}$7, HyperLTL$K = \{\var[1], \dots, \var[k]\}$8, GHyperLTL$K = \{\var[1], \dots, \var[k]\}$9, HyperMTL, and SS0, with the practical goal of extracting fine-grained witnesses rather than only verdicts (Waga et al., 16 Jul 2025).

3. Algorithms and complexity in the set-of-words model

The decision problem “is SS1 nonempty?” is NP-complete. NP-hardness is shown by reduction from SAT, and membership in NP follows by guessing the selected words, interval boundaries, and an accepting extended word over SS2 whose projections equal the chosen subwords (Waga et al., 16 Jul 2025). This establishes that hyper pattern matching over word sets is intrinsically harder than single-word regular pattern matching.

The naive algorithm enumerates all starting tuples

SS3

with SS4 and SS5, then simulates asynchronous reading by maintaining configurations of pending buffers and automaton states. Its worst-case running time is

SS6

which is polynomial in word length for fixed SS7 but exponential in the number of directions (Waga et al., 16 Jul 2025).

Two heuristics are introduced to improve practical performance. The first is FJS-style skipping, combining QS-style and KMP-style skip values generalized to NAAs. It uses shortest-match information SS8, character sets SS9, and direction-specific skip functions S0SS_0 \subseteq S0 and S0SS_0 \subseteq S1 to prune ranges of starting indices that cannot begin a match. The second is projection-based pruning: for each direction S0SS_0 \subseteq S2, the NAA is projected to a single-tape automaton S0SS_0 \subseteq S3, and only indices that belong to some projected match are retained as candidate starts. The S0SS_0 \subseteq S4 procedure computes a transformed word over S0SS_0 \subseteq S5, marking irrelevant positions with S0SS_0 \subseteq S6 (Waga et al., 16 Jul 2025).

These techniques are implemented in the Rust tool HypPAu. Experiments on Interference, Robustness, PacketPairs, and ManyDirs show that two-direction instances with words of length in the thousands are feasible, and that even four-direction instances on words of length S0SS_0 \subseteq S7 can be handled within a few minutes. The heuristics are especially effective in the ManyDirs benchmark; for S0SS_0 \subseteq S8, the naive algorithm often times out, whereas S0SS_0 \subseteq S9, FSF \subseteq S0, and FSF \subseteq S1 remain practical. The performance gains are pattern-dependent: on Interference and Robustness, skip values are often FSF \subseteq S2, so FJS gives little advantage; on PacketPairs, both skipping and projection pruning are effective (Waga et al., 16 Jul 2025).

4. Generalized sequence and term matching

A major adjacent strand studies pattern symbols as variables over strings or terms. Generalized function matching defines the problem of finding FSF \subseteq S3 such that FSF \subseteq S4 is a substring of the text, and the paper focuses on the non-empty-image variant FSF \subseteq S5, motivated by the observation that allowing FSF \subseteq S6 permits degenerate “deletion” of pattern symbols (Mincu, 2019). The paper proves that substring matching can be reduced to whole-text matching by augmenting the pattern with fresh boundary symbols, and then presents a suffix-tree-based heuristic. The pattern is decomposed into a repetitive subsequence FSF \subseteq S7 and non-repetitive gap counts FSF \subseteq S8; the text is processed into repetition structures extracted from a suffix tree; candidate mappings from repeated pattern symbols to repeated substrings are enumerated; and trimming plus gap checks enforce consistency. The worst-case time is

FSF \subseteq S9

and for uniform random strings the expected bound is

$\delta \subseteq S \times \Alphabet \times K \times S$0

The underlying decision problem for $\delta \subseteq S \times \Alphabet \times K \times S$1 is NP-complete (Mincu, 2019).

At the term level, non-linear associative-commutative many-to-one matching with sequence variables extends standard term matching by allowing repeated variables, associative and commutative function symbols, and variables $\delta \subseteq S \times \Alphabet \times K \times S$2 that match sequences or multisets of terms. The thesis formalizes substitutions $\delta \subseteq S \times \Alphabet \times K \times S$3, uses weak compositions to distribute arguments among sequence variables in non-commutative contexts, and uses linear Diophantine equations to distribute remaining multiplicities in commutative contexts (Krebber, 2017). For many-to-one matching, it introduces the Associative Discrimination Net and the Multilayer Discrimination Net, combining nondeterministic automata, bipartite matching for commutative subpatterns, and cached Diophantine solutions. The implementation in MatchPy reports significant speedups of many-to-one over one-to-one matching, specifically $\delta \subseteq S \times \Alphabet \times K \times S$4–$\delta \subseteq S \times \Alphabet \times K \times S$5 on the linear-algebra benchmark (Krebber, 2017).

A different structural generalization appears in multiple pattern Cartesian tree matching, where a pattern matches a text window when both have the same Cartesian tree. The paper introduces two fingerprints: the parent-distance encoding

$\delta \subseteq S \times \Alphabet \times K \times S$6

which has a one-to-one correspondence with Cartesian trees, and the binary encoding

$\delta \subseteq S \times \Alphabet \times K \times S$7

which is only a necessary condition but supports $\delta \subseteq S \times \Alphabet \times K \times S$8 rolling updates. These fingerprints are combined with Wu-Manber, Rabin-Karp, and Alpha Skip Search for multiple-pattern matching. The Wu-Manber-based algorithm runs up to $\delta \subseteq S \times \Alphabet \times K \times S$9 times faster than the previous algorithm, and the method is explicitly motivated by time-series applications such as stock-price analysis (Gu et al., 2019).

Taken together, these models show a common technical theme: the pattern no longer denotes a fixed literal string, but a structured constraint over substrings, term arguments, or order-derived encodings. This suggests one broad interpretation of hyper pattern matching as matching with latent variables, algebraic theories, or structural fingerprints rather than exact symbol-by-symbol identity.

5. Non-free data types and pattern-match-oriented programming

Another major lineage treats hyper pattern matching as highly expressive matching over non-free data types. Egison’s system enables non-linear pattern matching against unfree data types such as sets, multisets, and graphs; it supports multiple occurrences of the same variable, multiple results from a single match, and modularized matching semantics via matchers (Egi, 2014). The operational model uses matching-states, matching-atoms kk0, and matching-nodes for lexically scoped pattern-functions. Pattern matching proceeds from the left side of a pattern, and a binding to a variable can be referred to on its right side through value-patterns. Breadth-first traversal is used so that infinite search trees do not starve finite solutions (Egi, 2014).

The Scheme embedding of Egison compiles this semantics into macros and ordinary functional code. A matcher is transformed into a function of type

kk1

match-all is compiled to map over gen-match-results, and value patterns are transformed into functions over intermediate results (Egi, 2019). The implementation preserves non-linear matching, backtracking, and extensible matchers for non-free data types. In the benchmark with kk2, Egison with optimized Multiset takes kk3s, Scheme with optimized Multiset takes kk4s, and the hand-written functional Scheme baseline takes kk5s, showing that the macro-based implementation is much faster than the Egison interpreter and within a small constant factor of direct functional code (Egi, 2019).

Pattern-match-oriented programming pushes this further by making pattern matching the primary control mechanism and confining recursion inside matchers and pattern constructs. It introduces not-patterns, loop patterns, and sequential patterns, and uses them to redefine functions such as map, concat, and unique, as well as a SAT solver, a computer algebra system, and a database query language (Egi et al., 2020). The central claim is that recursion still exists but is hidden inside matcher definitions rather than written explicitly in every user function. This yields a style in which algorithms are described as patterns over lists, multisets, sets, graphs, or mathematical expressions (Egi et al., 2020).

Amethyst occupies a related but compiler-oriented position. It is a pattern-matching system embedded in Ruby that serves as a generator of parsers of programming languages, can serve as an alternative to tools for matching regular expressions, and supports pattern matching of general data structures useful for compiler optimizations such as constant folding, instruction scheduling, and dataflow analysis (Bílka, 2012). Its key formal notions are structured grammars and relativized regular expressions, together with the nested(start, middle, end) operator for nested recursion and the Enter operator kk6 for matching over trees and objects. Linear time for parsing is obtained under the structured-grammar discipline, and dynamic parsing for IDE-like use is supported with worst-case kk7 incremental recomputation (Bílka, 2012).

These programming-language systems establish a second major meaning of hyper pattern matching: non-linear, backtracking, extensible matching in which decomposition semantics are supplied by user-defined matchers and may range over multisets, sets, graphs, syntax trees, or general objects.

6. Hypergraphs, higher arity, and exact relational constraints

In hypergraph pattern matching, the input is a query hypergraph kk8 and a data hypergraph kk9. A hypergraph is $L(A) \subseteq (\Alphabet^*)^k,$0, where $L(A) \subseteq (\Alphabet^*)^k,$1 is a finite set of vertices, $L(A) \subseteq (\Alphabet^*)^k,$2 is a set of non-empty subsets called hyperedges, and $L(A) \subseteq (\Alphabet^*)^k,$3 is a label function (Song et al., 11 Dec 2025). Subhypergraph isomorphism asks for an injective vertex mapping $L(A) \subseteq (\Alphabet^*)^k,$4 that preserves vertex labels and maps every query hyperedge $L(A) \subseteq (\Alphabet^*)^k,$5 to a data hyperedge $L(A) \subseteq (\Alphabet^*)^k,$6. This is the hypergraph analogue of graph pattern matching, but with hyperedges connecting arbitrary numbers of vertices (Song et al., 11 Dec 2025).

The main theoretical contribution is the intersection constraint. For a set of vertices $L(A) \subseteq (\Alphabet^*)^k,$7, the signature is

$L(A) \subseteq (\Alphabet^*)^k,$8

Given a hyperedge mapping $L(A) \subseteq (\Alphabet^*)^k,$9, $\Alphabet \times K$0 is an embedding if and only if for every subset $\Alphabet \times K$1,

$\Alphabet \times K$2

This condition is both necessary and sufficient (Song et al., 11 Dec 2025). The algorithmic framework MaCH builds on this with the Candidate Hyperedge Space, which stores candidate hyperedges for each query hyperedge and connections between candidates that satisfy the pairwise connectivity constraint, and with the Match-and-Filter framework, which interleaves matching and filtering during backtracking (Song et al., 11 Dec 2025).

The implementation uses incident hyperedge bitmaps and cell signatures to evaluate the intersection constraint efficiently. The CheckIntersection procedure runs in $\Alphabet \times K$3 time for a candidate mapping $\Alphabet \times K$4, improving over the $\Alphabet \times K$5 verification used in HGMatch (Song et al., 11 Dec 2025). Experimental results on real-world datasets show that MaCH significantly outperforms state-of-the-art algorithms, by up to orders of magnitude in terms of query processing time, while initial filtering can eliminate up to $\Alphabet \times K$6 of candidates and $\Alphabet \times K$7 of connections on AR. The method is exact, hyperedge-centric, and specifically designed for higher-arity relations (Song et al., 11 Dec 2025).

This higher-arity setting broadens the notion of hyper pattern matching once again. Instead of matching substrings or algebraic terms, the task is to match relational structures whose primitive units already connect many vertices simultaneously. A plausible implication is that the term “hyper” in pattern matching often signals a move from unary or binary structure toward explicitly relational structure, whether that relation is between traces, between repeated variables and substrings, or between overlapping hyperedges.

Across these strands, a consistent picture emerges. Hyper pattern matching is not a single settled formalism; it is a technically diverse area in which exact symbol matching is generalized to asynchronous tuples of words, string variables with equality constraints, non-free decompositions with backtracking, algebraic theories with sequence variables, structural fingerprints over numeric sequences, and higher-arity hypergraph embeddings. The common thread is that patterns denote relations or structures whose witnesses are richer than a single exact occurrence.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Hyper Pattern Matching.