Compositional Generator Equivalence (Extended Version)

📅 2026-06-21
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Existing property-based testing frameworks, such as Hedgehog, lack compositional semantics, making it difficult to formally verify the correctness of generator optimizations. This work develops a formal semantic model for such frameworks, revealing that their distributional semantics are inherently non-compositional. To address this, we propose Hedgehog→, a restricted variant based on arrow calculus, which trades modest expressiveness for compositional distributional semantics. This design enables, for the first time in property-based testing, compositional formal proofs of generator equivalence. We implement a Haskell prototype of Hedgehog→ and demonstrate that it retains sufficient expressiveness to encode practical test generators while providing a rigorous, compositional foundation for reasoning about generator optimizations.
📝 Abstract
Property-based testing (PBT) is a powerful technique for software verification that relies on random input generators and "shrinking" processes to find and minimize counterexamples to executable specifications called properties. While optimizing these generators is crucial for testing efficiency, formally justifying such optimizations is currently difficult because existing languages lack a compositional semantics that is coarse-grained enough for high-level reasoning. In this paper, we first provide a formal account of the syntax and semantics of Hedgehog, a popular PBT framework. We demonstrate that Hedgehog's distribution semantics - which models how users typically reason about generators - is non-compositional. Furthermore, we prove that any sound and complete compositional semantics for Hedgehog must necessarily be equivalent to its sampling semantics, which is too fine-grained to justify common program optimizations. To resolve this dilemma, we introduce Hedgehog$^\rightarrow$, a restricted version of the language based on the arrow calculus, and prove that Hedgehog$^\rightarrow$ possesses a compositional distribution semantics. We evaluate Hedgehog$^\rightarrow$ through a Haskell implementation and show that it remains expressive enough to capture generators of practical interest, while providing the formal foundation needed for compositional generator equivalence proofs.
Problem

Research questions and friction points this paper is trying to address.

property-based testing
compositional semantics
generator equivalence
formal verification
random input generators
Innovation

Methods, ideas, or system contributions that make the work stand out.

compositional semantics
property-based testing
generator equivalence
arrow calculus
formal verification
🔎 Similar Papers
No similar papers found.