Papers
Topics
Authors
Recent
Search
2000 character limit reached

TensorRocq: Enabling diagrammatic reasoning in Rocq

Published 19 Apr 2026 in cs.LO and cs.PL | (2604.17592v1)

Abstract: Symmetric monoidal categories (SMCs) are a common framework for reasoning about computation, focusing on the parallel and sequential compositionality of operations. String diagrams are a ubiquitous and powerful tool for reasoning about equations in SMCs, leveraging eliding the fine details of compositionality to focus on connectivity. However, when working with SMCs in a proof assistant, the rigid equational structure of composition occludes the essential connective information, longer proofs filled with uninformative syntactic manipulation. To address the gap between proof assistants and paper proof, we have developed verified tools for diagrammatic reasoning in Rocq, including inferring term equivalence and rewriting modulo the deformation of string diagrams. This is achieved by converting between syntactic representations of SMC terms and hypergraphs with interfaces, while preserving a common tensor semantics. We provide tools to develop simple SMC theories from generators and relations, and perform equational reasoning these systems. We also enable our tactics to be used in existing verification projects about SMCs which can be given semantics as tensor expressions.

Summary

  • The paper introduces TensorRocq, which automates diagrammatic reasoning in symmetric monoidal categories by mapping SMC terms to hypergraphs with tensor semantics.
  • It employs a certified rewriting engine based on hypergraph double-pushout techniques that bypasses syntactic bureaucracy in proof assistants.
  • The framework integrates abstract rewriting with concrete instantiations like the ZX-calculus, ensuring semantic soundness and robust performance for complex proofs.

TensorRocq: Formalizing Diagrammatic Reasoning for Symmetric Monoidal Categories in Rocq

Introduction

The paper "TensorRocq: Enabling diagrammatic reasoning in Rocq" (2604.17592) presents TensorRocq, a verified infrastructure enabling diagrammatic reasoning about symmetric monoidal categories (SMCs) within the Rocq proof assistant. TensorRocq allows proofs over SMCs to reflect the diagrammatic manipulations familiar to paper-based reasoning, closing the gap between formal mechanization and informal string diagrammatic proofs. It accomplishes this by bridging SMC terms, hypergraph representations, and tensor semantics, thereby automating proofs up to SMC coherence (i.e., "only connectivity matters"). The framework supports both abstract rewriting (via generators and relations) and instantiation to extant theories, exemplified by comprehensive support for the ZX-calculus and direct application to existing libraries.

Theoretical and Methodological Framework

TensorRocq is architected on three interrelated formal structures:

  • Tensors. Tensors are instantiated as multi-dimensional arrays over a field, equipped with contraction and product operations. This structure embodies the compositionality of morphisms in an SMC, with contractions modeling sequential composition and products capturing parallel composition. Tensor semantics are used as the ultimate soundness criterion for both hypergraph and SMC term operations, leaning heavily on the categorical formalization of tensors as symmetric traced monoidal structures [Kissinger2014].
  • Hypergraphs with interfaces (cospans). Hypergraphs generalize graphs by permitting edges incident to arbitrary sets of vertices, realizing the connectivity of operations in SMCs. By introducing ordered interfaces as input/output boundaries (akin to cospans in category theory), hypergraphs precisely encode the wires of a string diagram. Labeled directed hypergraphs with interfaces can be assigned tensor semantics by coupling edge labels with tensor interpretations and defining the semantics as product and contractions over indices assigned to interface and internal vertices.
  • PROPs and APROPs. The syntactic objects manipulated by TensorRocq are formalized as Autonomous PROPs (APROPs): symmetric monoidal categories with special morphisms for cap and cup (unit, counit). These cap/cup morphisms correspond exactly to delta tensors enforcing equality of wires, giving APROPs both a tractable syntax for reflected rewriting and straightforward tensor semantics.

Through well-specified correspondences, APROP terms are mapped to hypergraphs with interfaces (for matching, decomposition, and rewriting), which in turn have a guaranteed tensor interpretation. Conversely, hypergraph terms admitting acyclic monogamous structure can always be synthesized back into APROP terms, ensuring round-trip translation and tactic applicability.

Verified Diagrammatic Rewriting and Tactic Infrastructure

The fundamental contribution is an isomorphism-based, semantics-verified rewriting engine:

  • Associativity and structural bureaucracy. In proof assistants, SMC laws like associativity, unitors, and symmetries clutter proofs with irrelevant syntactic reshuffling. TensorRocq's tactics automatically factor away these isomorphisms by conducting matching and rewriting at the hypergraph level, where only connectivity governs equivalence—mirroring the behavioral equivalence in string diagrams.
  • Matching and hypergraph double-pushout rewrites. The system implements effective (albeit potentially partial) reflective matching algorithms for identifying sub-hypergraphs up to isomorphism. Rewriting is performed by double-pushout style decompositions: a graph HH is decomposed into context and subdiagram via interfaces, LL and RR (a known equivalence) are exchanged, and the syntactic result is synthesized if possible, cross-checked by a certified isomorphism test.
  • Extensibility and integration. TensorRocq is designed to be parameterized by arbitrary SMC signatures, supporting both theory-oriented and concrete, data-carrying signatures (such as those for the ZX-calculus or linear algebra). Integration with existing Rocq developments is provided by a typeclass-based quotation/denotation layer, allowing tactics to operate on native types rather than only on APROPs, provided tensor semantics can be assigned.

Examples and Empirical Assessment

Abstract Reasoning via Signatures

The infrastructure supports defining SMC theories via generators and rewriting relations (e.g., Frobenius algebras). Users provide:

  • a type for generators
  • an equivalence relation
  • a list of rewriting rules at the APROP level

The framework lifts these syntactic relations to semantic equalities via automatic inference in polynomial rings, enabling tactics that perform rewriting modulo all SMC equalities. The mechanism is demonstrated for monoid/comonoid axioms and derivations of composite relations, with tactics (smcat, srw, etc.) mirroring the minimal, connectivity-centric proofs possible in informal string diagram calculus.

Instantiated Reasoning: The ZX-Calculus

TensorRocq instances can be engineered for specific SMCs, as shown by the integration with VyZX [lehmann2026vyzxformalverificationgraphical], a formalized graphical language for quantum circuits. The typeclass-based instance layer automatically translates between native constructions (e.g., ZX-spiders, wires, swaps) and APROPs, while maintaining alignment with tensor semantics (QuantumLib matrices).

Proofs that previously required extensive reassociation and manual term manipulation in proof assistants are dramatically condensed, since subdiagrammatic equivalence is detected via hypergraph isomorphism and context-independent rewriting.

The system is robust to underlying representation changes; e.g., altering the definition of a quantum gate or swapping operations inside an SMC term does not impact the ability to recognize applicable rewrites as long as the underlying connectivity and semantics remain invariant.

Implications and Future Directions

TensorRocq makes several bold assertions, among them:

  • Resilience and maintainability. Proofs are largely immune to definitional and structural perturbations, fostering maintainable, evolvable libraries.
  • Semantic soundness. All rewrites are verified against tensor semantics; semantic preservation does not rely on the correctness of unverified matching, but is enforced via certified isomorphism checks.
  • Performance. The isomorphism check is efficient for moderately sized hypergraphs (dozens of edges), making it feasible to scale to non-toy fragments of realistic circuit design and process theories.

However, current limitations remain, notably:

  • Visualization and interactive guidance, which are critical for practical use, are not yet fully integrated. Priorities for further development include Rocq-LSP binding and extraction to external graphical editors, similar to Chyp [chyp] and Pous' string diagram tools [pous2026string].
  • Full support for parametric generators, variable-arity operations, and richer matching modulo additional SMC axioms (e.g., strong permutativity properties as in ZX-calculus spiders) represents ongoing research.
  • Automatic reasoning in broader algebraic contexts (e.g., general linear algebra, monoidal computer science, categorical quantum mechanics) is enabled by design but would benefit from further user-facing libraries and tactic automation.

Conclusion

TensorRocq systematically eliminates most of the administrative complexity associated with mechanized reasoning in symmetric monoidal categories. By representing SMC operations as hypergraphs with tensor semantics, TensorRocq raises the level of abstraction for formal proofs up to that of graphical, connectivity-based reasoning, verified within the Rocq proof assistant. The dual focus on both generic (signature-based) and concrete instantiations positions TensorRocq as a foundational tool for both category-theoretic formalization and the mechanized verification of graphical quantum languages, quantum circuit rewrites, and other process theories central to computer science and physics. The approach, emphasizing the centrality of connectivity and the importance of verifying at the semantic layer, sets a technical blueprint for future work in diagrammatic proof automation and certified categorical programming.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

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

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.