Synthesizing Transducers from Complex Specifications

Anvay Grover, Ruediger Ehlers, Loris D'Antoni

Introduction

String transformations are a fundamental component of modern software, appearing in everything from data cleaning and format conversion to security sanitization. While automated program synthesis has made significant strides in generating these transformations from input-output examples, most existing tools rely on Domain-Specific Languages (DSLs). While efficient, DSL-based programs often lack the formal mathematical properties—such as closure under composition and decidability of equivalence—required for rigorous software verification.

To bridge this gap, researchers have developed ASTRA, a synthesis tool that generates Finite State Transducers (FTs). Unlike DSL programs, transducers are well-understood automata that facilitate formal reasoning. However, they are notoriously difficult for humans to design manually. ASTRA automates this process by encoding complex specifications—including examples, regular language types, and edit distance constraints—into Satisfiability Modulo Theories (SMT) constraints.

The Problem: The Verification Gap

Currently, if a developer wants to prove that a sanitization function is idempotent (i.e., applying it twice yields the same result as applying it once), doing so with a program written in a standard DSL is computationally difficult. Transducers offer a solution because they are closed under composition and their equivalence is decidable.

Despite these benefits, synthesizing transducers is challenging because the search space for automata is vast. ASTRA addresses this by treating synthesis as a constraint satisfaction problem, allowing it to handle not just simple examples, but also formal type signatures and semantic constraints on the transformation itself.

The ASTRA Methodology

ASTRA synthesizes a transducer by fixing the number of states ($k$) and the maximum output length per transition ($l$), then generating SMT constraints that a valid transducer must satisfy. The synthesis process is guided by three primary types of specifications:

  1. Input-Output Examples: The tool ensures the synthesized transducer maps specific input strings to their corresponding outputs by tracking the configuration (the current state and the position in the output string) through the execution trace.
  2. Input-Output Types: To guarantee that the transducer behaves correctly on all strings within a specific language, ASTRA utilizes a simulation relation. This relates the states of the synthesized transducer to the states of the input and output Deterministic Finite Automata (DFAs). This ensures that if the input string belongs to the valid input language, the output is guaranteed to belong to the valid output language.
  3. Edit Distance Constraints: To prevent the generation of "garbage" transformations that technically satisfy type constraints but are semantically incorrect, ASTRA bounds the mean edit distance. Using an "energy budget" approach inspired by game theory, each transition is assigned a weighted cost. The transducer must remain "out of debt" across its transitions to satisfy the global distance bound.

To handle real-world complexities like Unicode or transformations where the output depends on future characters, ASTRA extends this framework to Symbolic Finite Transducers (s-FTs) and incorporates lookahead capabilities.

Experimental Evaluation

ASTRA was evaluated on 18 benchmarks, including 11 tasks adapted from the state-of-the-art lens synthesis tool Optician and 7 real-world tasks such as unixToDos, escapeQuotes, and getTags. Additionally, the researchers tested ASTRA’s ability to repair buggy transducers in 12 different scenarios.

Key Results

  • Efficiency: ASTRA solved 15 out of 18 benchmarks. Most tasks were completed in under one second, with the most complex requiring approximately 50 seconds.
  • Robustness: Compared to DSL-based tools like Optician, ASTRA showed greater stability. While Optician’s performance often fluctuated based on the specific phrasing of regular expressions, ASTRA’s automata-based approach remained consistent.
  • Repair Capability: ASTRA successfully repaired 9 out of 12 faulty transducers. Because transducers are closed under union and composition, ASTRA can effectively "subtract" incorrect behaviors and synthesize a precise patch to fix the logic.

Insights and Future Directions

One of the most significant contributions of ASTRA is the "aggregate cost" trick. Computing global edit distances over infinite sets of strings is traditionally a hard problem. By approximating this through local transition costs and lookahead, ASTRA makes the problem tractable for SMT solvers.

However, limitations remain. The current distance metric is an over-approximation, which may lead the tool to reject valid transducers that use "delayed" outputs (where the transducer waits several steps before producing a character). Furthermore, like many SMT-based tools, ASTRA is susceptible to state-space explosion when dealing with exceptionally large input/output DFAs. Future research will focus on optimizing SMT encodings and developing more sophisticated heuristics for determining the optimal number of states for a given specification.

Conclusion

ASTRA represents a significant step toward verification-ready program synthesis. By producing transducers instead of DSL programs, it enables developers to generate string-transformation logic that is not only correct by construction but also compatible with downstream formal verification tools.

Summary updated

BibTeX
@inproceedings{grover2022synthesizing,
  author = {Anvay Grover and Ruediger Ehlers and Loris D'Antoni},
  title = {{Synthesizing Transducers from Complex Specifications}},
  booktitle = {FMCAD},
  year = {2022},
  url = {https://openreview.net/forum?id=e2qmfI-WRLU},
}
Figure