TL;DR
SWAPPER is a new framework that automatically generates domain-specific formula simplifiers for SMT solvers and program synthesis tools. By combining random DAG sampling with syntax-guided synthesis and empirical auto-tuning, it creates rewrite rules that outperform hand-crafted logic by 30-50% for less than the cost of a single hour of developer time.
What Problem Does This Paper Address?
In the world of formal methods, logic formulas are the primary currency. Tools like SMT solvers (e.g., Z3) and program synthesizers (e.g., Sketch) represent these formulas as Directed Acyclic Graphs (DAGs). Before a solver even attempts to find a solution, it must simplify these graphs to reduce their size and complexity.
Historically, these simplifiers have been hand-crafted by experts over years of trial and error. For example, the simplification module in the Sketch synthesis system took eight years to mature, yet it remains plagued by hard-to-identify bugs and misses domain-specific optimization opportunities. A general-purpose simplifier might be great for broad logic, but it fails to exploit recurring patterns found in specific applications, such as automated grading or database query extraction. The authors aim to replace this manual "black art" with an automated, data-driven pipeline.
Methods
The authors introduce SWAPPER, a framework that operates in four distinct phases:
- Pattern Finding: Using a novel random sampling algorithm, SWAPPER identifies "domain-significant" sub-graphs within a corpus of benchmark problems. It uses a custom similarity metric (based on DAG signatures) to cluster equivalent patterns, even accounting for commutative operations.
- Rule Generation: For each common pattern, SWAPPER attempts to find a Conditional Rewrite Rule ($LHS \xrightarrow{pred} RHS$). It uses a hybrid approach:
- Enumerative Search: To find the "weakest" (most permissive) guard predicates.
- Symbolic Synthesis: Using the Sketch tool itself to synthesize the smallest possible Right-Hand Side (RHS) that is semantically equivalent to the Left-Hand Side (LHS) under the given predicate.
- Code Generation: The discovered rules are compiled directly into efficient C++ code. This allows the simplifier to share the burden of pattern matching across multiple rules, ensuring that the simplification step itself remains a negligible fraction of the total solve time.
- Auto-tuning: Not all rules are beneficial; some might reduce formula size but make the underlying logic harder to solve, or prevent other, better rules from firing. SWAPPER uses OpenTuner to empirically test different subsets and orderings of rules on a training set to find the optimal configuration.
Datasets
The researchers evaluated SWAPPER using four distinct domains from the Sketch synthesis ecosystem:
- Storyboard: Specifications for storyboard-based programming.
- QBS: Query extraction specifications.
- AutoGrader: Formulas derived from student submissions in an introductory programming MOOC on edX.
- SyGuS: Benchmarks from the annual Syntax-Guided Synthesis competition.
The authors filtered these benchmarks to include only those with more than 5,000 terms and a solve time between 5 seconds and 5 minutes, ensuring there was enough "meat" for the patterns to emerge and for the auto-tuner to run efficiently.
Key Insights and Ideas
- The "Aha" of Domain Specificity: The most striking finding is that simplifiers are highly specialized. A simplifier generated for the SyGuS domain actually slowed down performance when applied to AutoGrader problems. This confirms that "one size fits all" logic simplification is a myth.
- Weak Predicates are Strong: The system prioritizes finding the weakest possible predicates. A weak predicate is easier to satisfy, meaning the rewrite rule can be applied more frequently across the DAG.
- Rule Interaction Matters: The auto-tuning phase is critical. The authors found that the "best" set of rules isn't just the union of all valid rules; it’s a carefully selected subset where rules don't "cannibalize" each other's opportunities for simplification.
- Synthesis for Synthesis: Using a program synthesizer (Sketch) to build a component for a program synthesizer is a clever recursive application of the technology.
Key Results
- Speedups: The auto-generated simplifiers improved the running times of the Sketch tool by 30-50% compared to the existing hand-crafted simplifier.
- Size Reduction: For the AutoGrader domain, SWAPPER reduced the number of terms in the problem DAGs by an average of 13.8% beyond what the expert-written code could achieve.
- Human vs. Machine: The average solve time for AutoGrader benchmarks dropped from 20 seconds (hand-coded) to 13 seconds (auto-generated).
- Cost-Effectiveness: The authors estimate that generating a domain-specific simplifier on the cloud costs roughly $22-$24 in compute time—significantly cheaper than hiring a PhD-level engineer for the weeks or months required to write one manually.
Limitations and Future Work
- Data Requirements: SWAPPER requires a representative corpus of problems to find patterns. In domains with very few benchmarks (like the QBS and Storyboard sets in this paper), the system struggled to generate enough rules for effective auto-tuning.
- Generation Time: While the resulting simplifier is fast, the generation process takes about 20-22 hours. While acceptable for a one-time cost, the authors suggest that further parallelization of the pattern-finding phase could reduce this wait time.
- Bounded Verification: The rules are synthesized using bounded inputs. While the authors add a secondary verification step using the Z3 solver to ensure correctness, a more integrated formal verification of the rules during the synthesis phase could be a future improvement.
Summary updated