Matchability-Preserving Rewrites: A Survey
- Matchability-preserving rewrites are transformations that maintain the witness structures essential for valid matches across diverse formal systems.
- They use methodologies such as exact denotational equality in SQL and pullback-controlled embeddings in graph rewriting to ensure consistency.
- These rewrites enable reliable query reformulation and fault-tolerant quantum circuit extraction while balancing system-specific invariants with practical decoding needs.
Matchability-preserving rewrites are rewrite transformations that preserve the admissibility, existence, or structure of matches under the notion of matching native to a given formalism. The phrase is used explicitly for detector-aware ZX-diagram rewrites that preserve MWPM-decodability (Schweikart et al., 19 Mar 2026), but closely related concerns appear elsewhere under stronger or adjacent notions: denotational equivalence of SQL queries for all schemas and instances (Chu et al., 2016), preservation of user intent and improved document matchability in conversational query rewriting (Zheng et al., 26 Sep 2025), strong matching and controlled embedding in categorical graph rewriting (Overbeek et al., 2022), regularity of overlapping parallel graph matches (Tour et al., 2018), typing-preserving pattern rewriting in dependent type theory (Blanqui, 2020), and rewrite closure that keeps hedge languages automaton-recognizable (Jacquemard et al., 2012). Taken together, these works support a broad interpretation in which a rewrite is matchability-preserving when it preserves the relevant witness structure by which outputs, typings, detector events, or accepted trees are produced.
1. Scope of the concept
The literature does not provide a single domain-independent definition of matchability-preserving rewriting. Instead, each framework fixes its own preservation target. In HoTTSQL, the operative notion is stronger than mere matchability: for a rewrite , the original and rewritten SQL queries must denote the same output relation for all input schemas and instances, including tuple multiplicities under bag semantics and set-level membership after DISTINCT (Chu et al., 2016). In conversational RAG, the corresponding target is intent-preserving reformulation that makes the query easier to match to the right documents and easier for the generator to answer correctly (Zheng et al., 26 Sep 2025). In PBPO, the key issue is whether the embedding of the left-hand-side pattern into the host object is controlled by a strong match pullback, so that the matched occurrence is sharply delimited (Overbeek et al., 2022). In parallel graph rewriting, matchability preservation is characterized by regularity of a family of overlapping matches (Tour et al., 2018). In dependent type theory, the closest analogue is preservation of typability for all typable instances of a pattern left-hand side (Blanqui, 2020). In hedge rewriting, the question becomes whether the set of descendants of an automaton-recognizable language remains automaton-recognizable (Jacquemard et al., 2012).
This suggests that “matchability-preserving rewrite” is best understood as a family of invariants rather than a single theorem schema. The common structure is that rewriting must preserve the conditions under which a derivation remains valid: tuple-production witnesses, document-retrieval anchors, graph embeddings, parallel overlap compatibility, typing constraints, or detector bases.
2. Query rewriting: denotation, witnesses, and retrieval intent
In HoTTSQL, rewrite correctness is formulated as exact denotational equality. A query denotes a context-sensitive function
where relations are modeled as functions from tuples to univalent types, and the cardinality of represents multiplicity. The nearest formal reading of matchability preservation is therefore
which is stronger than preserving only tuple existence after truncation. Projection is the clearest witness-bearing operation: A tuple is produced exactly when there exist witness tuples in the source satisfying the relevant conditions, and rewrite proofs frequently proceed by transforming witnesses inside -types. The framework proves 23 rewrites, including basic algebraic rewrites, aggregation/group-by rewrites, subquery elimination, magic-set rewrites, index-based rewrites, and automated conjunctive-query equivalences. It does not develop a separate theory of syntactic pattern match preservation, provenance preservation, witness bijections, or query containment as a primary target (Chu et al., 2016).
The same theme appears in conversational query rewriting, but with a different operational target. SynRewrite is defined for multi-turn RAG and conversational question answering, where the current query depends on dialogue history
The paper distinguishes Syn_Unseen, built from 0 and 1, from Syn_Seen, built from 2, 3, 4, and 5. A good rewrite is one that captures the user’s true intent, is complete and unambiguous relative to the dialogue context, improves retrieval effectiveness, and supports downstream generation. The embedding cosine similarity between original queries and rewrites lies between 0.965 and 0.969, which the authors interpret as showing that rewriting does not deviate from the original user intent. On the TopiOCQA training set, Manual rewrites achieve MRR@5 37.70, Syn_Unseen 43.41, and Syn_Seen 61.31. This makes the paper directly relevant to a retrieval-oriented notion of matchability: the rewrite should remain semantically close to the conversational turn while improving document-space alignment. The paper also states a “clear trade-off between query rewriting effectiveness and sensitive entity leakage risk,” with a “near-linear correlation between information richness and exposure risk” (Zheng et al., 26 Sep 2025).
A common misconception is that all query rewrites preserve the same object. In HoTTSQL, the target is exact denotational equivalence, usually before truncation. In SynRewrite, the target is intent-preserving, retrieval-improving reformulation, and the best synthetic targets may use positive documents and gold answers during data construction. The first is stricter than mere matchability; the second is explicitly optimized for retrieval and answerability rather than literal paraphrase.
3. Graph rewriting: controlled embeddings and overlap regularity
PBPO6 treats matchability through strong matching. A PBPO7 rule is a canonical-form PBPO rule together with the stronger requirement that a match 8 satisfy a pullback square
9
In Set and Graph, the paper states that this means the preimage of 0 under 1 is 2 itself. This forbids extra host elements outside the image of 3 from mapping into the typed image 4. The framework proves that, given a strong match, 5 is monic iff 6 is monic, and that the interface embedding 7 is uniquely induced and inherits monicity under mild assumptions. For classifying rules, adherence is unique, yielding determinism up to isomorphism. With regular monic matching in quasitoposes, PBPO8 defines a strict superset of the rewrite relations definable by PBPO, AGREE, and DPO (Overbeek et al., 2022).
The set-theoretic framework for parallel graph rewriting addresses a different failure mode: overlap. Rules are organized as
9
with 0. The distinction between 1 and 2 is essential: 3 contains items that are not removed by a rule but are not guaranteed to survive globally. For matches 4, the paper defines preservation by
5
and a set 6 of matches is regular iff every 7 preserves every 8. The central theorem states
9
where 0 is the add-then-delete construction and 1 is the delete-then-add construction. Regularity is also equivalent to the six desired conditions for full parallel rewriting, notably that every right-hand side remains embeddable in the result and every requested deletion is respected (Tour et al., 2018).
The two graph-rewriting lines isolate two distinct notions of matchability preservation. PBPO2 preserves the exactness and locality of the current match by controlling embedding through a pullback. The parallel set-theoretic framework preserves mutual applicability of a family of overlaps by requiring regularity. Neither paper proves a universal theorem that all future matches are transported across a rewrite. Instead, each formalism characterizes the precise conditions under which current match structure remains valid.
4. Type-preserving and language-preserving rewrites
In dependent type theory, rewrite safety is defined by subject reduction: 3 The paper works in the 4-calculus modulo rewriting and argues that in dependent settings it is insufficient to require a single derivation 5 and 6. What matters is preservation of typing for all typable instances of the left-hand side. To capture this, the paper restricts left-hand sides to patterns and defines an inference procedure
7
where 8 is a set of equations that must hold whenever the left-hand side is typable. Its main theorem states that if
9
then the rule 0 preserves typing. A generalized version allows sound simplification 1, and the paper uses Knuth–Bendix completion to turn the induced closed equations into a convergent rewrite system. The closest matchability-like conditions are pattern left-hand sides, left-linearity, confluence, 2-injectivity, and non-interference conditions ensuring that added completion rules do not unify with non-variable subterms of left-hand sides (Blanqui, 2020).
In hedge rewriting, the same preservation issue is formulated language-theoretically. For a language 3, the forward closure is
4
The paper introduces bidimensional context-free hedge automata (5) and proves that membership for 6 is decidable and emptiness is decidable in PTIME. Its first principal closure result states that if 7 is recognized by a 8 and 9 is a finite, linear, inverse-monadic, 1-childvar HRS, then 0 is effectively recognizable by a 1. Its second principal result states that for a loop-free update PHRS containing node renaming, addition of child nodes, addition of sibling nodes, addition of parent node, node replacement/recursive deletion, and single node deletion, 2 is effectively recognizable by a CFHA. This includes the new parent-insertion rule
3
The practical significance is exact, not approximate, preservation of type-like recognizability after rewriting, although the target automaton class may need to be strengthened from HA to CFHA or 4 (Jacquemard et al., 2012).
These two bodies of work expose a shared principle. A rewrite may preserve applicability only after the ambient proof or recognition system is enriched: by inferred equations and completion in dependent types, or by moving from HA to CFHA or 5 in hedge languages. This suggests that matchability preservation often depends as much on the observer formalism as on the rewrite itself.
5. Detector-aware rewrites and MWPM-decodability
The most explicit formalization of matchability-preserving rewrites appears in ZX-diagram rewriting for fault-tolerant quantum computing. Let 6 be a basis of detecting Pauli webs for a ZX diagram 7. The paper defines matchability by the condition
8
For CSS matchability, the same bound is imposed separately in each color. Under the edge flip noise model, this means each atomic fault flips at most two detectors, which is exactly the structure required for MWPM decoding (Schweikart et al., 19 Mar 2026).
To track this structure through rewriting, the paper defines a detector-aware rewrite
9
consisting of a fault-equivalent ZX rewrite 0, a local detector basis on each side, and a boundary-respecting coupling between local boundary-active Pauli webs. A rewrite is then matchability-preserving if the local Pauli web multisets on both sides are matchable; it is CSS matchability-preserving if they are CSS matchable. The basic preservation theorem states that applying such a rewrite inside a larger diagram with a matchable Pauli web multiset yields a new multiset that is still matchable (Schweikart et al., 19 Mar 2026).
The paper proves several concrete rewrite families to be matchability-preserving or CSS matchability-preserving.
| Rewrite family | Local detector effect | Preservation claim |
|---|---|---|
Id-removal |
Neither side has detecting regions | (CSS) matchability preserving |
Spider-Unfuse / r_{fuse} |
Neither side has detecting regions | Matchability preserving |
r_4 |
RHS has one local detecting region; LHS has none | CSS matchability preserving |
r_{4n} |
Internal bundles with local detectors | CSS matchability preserving |
| Floral unfusing | Neither side has local detectors | Matchability preserving if circuit distance 1 |
r_{meas} |
Both sides have local detector bases | CSS matchability preserving |
r_{5n}, r_{6n} |
Alternative decomposition families | CSS matchability preserving |
The synthesis theorem is correspondingly local and structural: if 2 is a CSS matchable, phase-free ZX diagram with circuit distance 3 and all spiders have degree less than 4, then one can CSS matchability-preservingly extract a fault-equivalent quantum circuit from 5. The constructive procedure is to unfuse spiders until surrounding detecting regions form flower patterns, decompose flower-pattern spiders using 6, use 7 to decompose all spiders into spiders of weight three, and then use 8 and 9 to extract a circuit (Schweikart et al., 19 Mar 2026).
A central nuance is that the framework does not preserve the exact decoding problem or a fixed detector basis. Rewrites may change the number of detectors and the local detector basis, yet still preserve the existence of some basis in which every atomic fault flips at most two detectors. The paper explicitly contrasts this with stricter notions that aim to preserve the entire decoding problem.
6. Comparative themes, limitations, and misconceptions
A recurring misconception is that semantic equivalence or fault equivalence alone is sufficient. The ZX-diagram work is explicit that ordinary rewrites can preserve the represented linear map and even fault behavior while changing the detector basis enough to destroy MWPM-decodability (Schweikart et al., 19 Mar 2026). The parallel graph framework likewise shows that overlapping matches may each remain individually valid while failing to admit a common full parallel result satisfying both embeddability and deletion conditions; regularity is required (Tour et al., 2018). In SQL, HoTTSQL proves exact denotational equality, but it does not target provenance preservation or explicit witness bijections (Chu et al., 2016).
Another misconception is that preservation must mean literal identity of derivations or detector structures. In several settings the preserved object is weaker or differently structured. SynRewrite aims at intent-preserving, retrieval-improving reformulation rather than literal fidelity to user wording, and its best synthetic targets may use positive documents and gold answers during data construction, creating a trade-off with leakage (Zheng et al., 26 Sep 2025). The ZX framework preserves matchability up to detector-basis transformation rather than exact decoder equivalence (Schweikart et al., 19 Mar 2026). The hedge-automata results preserve exact rewrite closure, but sometimes only after moving from HA to CFHA or 0, which means recognizability is preserved while the language class changes (Jacquemard et al., 2012).
A further point is that many of these frameworks preserve the current matching discipline rather than every conceivable future match. PBPO1 is designed to preserve the exactness and locality of the matched occurrence, not to prove a universal future-match transport theorem (Overbeek et al., 2022). The dependent-type criterion preserves typing of all typable instances of a pattern left-hand side, not arbitrary higher-order matching behavior (Blanqui, 2020). HoTTSQL preserves the full tuple-to-univalent-type denotation, but not explicit provenance traces (Chu et al., 2016).
Across the literature, the strongest common interpretation is therefore conditional and formalism-relative. A rewrite is matchability-preserving when it preserves the witness structure that matters for the ambient semantics: the tuple witnesses that produce SQL results, the contextual anchors that make a conversational query retrievable, the pullback-controlled embedding of a graph occurrence, the compatibility of overlapping matches in a parallel step, the equations required for a typable pattern instance, the automaton-recognizable structure of hedge descendants, or the detector basis that keeps each atomic fault incident to at most two detection events. This suggests that matchability-preserving rewriting is less a single property than a general design principle for rewrite systems whose correctness depends on preserving admissible matches rather than merely preserving surface form.