Reference. Synthesizing bijective lenses
Bidirectional transformations between different data representations occur frequently in modern software systems. They appear as serializers and deserializers, as parsers and pretty printers, as database views and view updaters, and as a multitude of different kinds of ad hoc data converters. Manually building bidirectional transformations—by writing two separate functions that are intended to be inverses—is tedious and error prone. A better approach is to use a domain-specific language in which both directions can be written as a single expression. However, these domain-specific languages can be difficult to program in, requiring programmers to manage fiddly details while working in a complex type system. We present an alternative approach. Instead of coding transformations manually, we synthesize them from declarative format descriptions and examples. Specifically, we present Optician, a tool for type-directed synthesis of bijective string transformers. The inputs to Optician are a pair of ordinary regular expressions representing two data formats and a few concrete examples for disambiguation. The output is a well-typed program in Boomerang (a bidirectional language based on the theory of lenses). The main technical challenge involves navigating the vast program search space efficiently. In particular, and unlike most prior work on type-directed synthesis, our system operates in the context of a language with a rich equivalence relation on types (the theory of regular expressions). Consequently, program synthesis requires search in two dimensions: First, our synthesis algorithm must find a pair of “syntactically compatible types,” and second, using the structure of those types, it must find a type- and example-compliant term. Our key insight is that it is possible to reduce the size of this search space without losing any computational power by defining a new language of lenses designed specifically for synthesis. The new language is free from arbitrary function composition and operates only over types and terms in a new disjunctive normal form. We prove (1) our new language is just as powerful as a more natural, compositional, and declarative language and (2) our synthesis algorithm is sound and complete with respect to the new language. We also demonstrate empirically that our new language changes the synthesis problem from one that admits intractable solutions to one that admits highly efficient solutions, able to synthesize intricate lenses between complex file formats in seconds. We evaluate Optician on a benchmark suite of 39 examples that includes both microbenchmarks and realistic examples derived from other data management systems including Flash Fill, a tool for synthesizing string transformations in spreadsheets, and Augeas, a tool for bidirectional processing of Linux system configuration files.
Cite
Cited by (2)
Saggitarius: A DSL for Specifying Grammatical Domains miltner-2023-saggitarius
Common data types like dates, addresses, phone numbers and tables can have multiple textual representations, and many heavily-used languages, such as SQL, come in several dialects. These variations can cause data to be misinterpreted, leading to silent data corruption, failure of data processing systems, or even security vulnerabilities. Saggitarius is a new language and system designed to help programmers reason about the format of data, by describing grammatical domains—that is, sets of context-free grammars that describe the many possible representations of a datatype. We describe the design of Saggitarius via example and provide a relational semantics. We show how Saggitarius may be used to analyze a data set: given example data, it uses an algorithm based on semi-ring parsing and MaxSAT to infer which grammar in a given domain best matches that data. We evaluate the effectiveness of the algorithm on a benchmark suite of 110 example problems, and we demonstrate that our system typically returns a satisfying grammar within a few seconds with only a small number of examples. We also delve deeper into a more extensive case study on using Saggitarius for CSV dialect detection. Despite being general-purpose, we find that Saggitarius offers comparable results to hand-tuned, specialized tools; in the case of CSV, it infers grammars for 84% of benchmarks within 60 seconds, and has comparable accuracy to custom-built dialect detection tools.
Synthesizing symmetric lenses miltner-2019-synthesizing
Lenses are programs that can be run both “front to back” and “back to front,” allowing updates to either their source or their target data to be transferred in both directions. Since their introduction by Foster et al., lenses have been extensively studied, extended, and applied. Recent work has also demonstrated how techniques from type-directed program synthesis can be used to efficiently synthesize a simple class of lenses—so-called bijective lenses over string data—given a pair of types (regular expressions) and a small number of examples. We extend this synthesis algorithm to a much broader class of lenses, called simple symmetric lenses, including all bijective lenses, all of the popular category of “asymmetric” lenses, and a rich subset of the more powerful “symmetric lenses” proposed by Hofmann et al. Intuitively, simple symmetric lenses allow some information to be present on one side but not the other and vice versa. They are of independent theoretical interest, being the largest class of symmetric lenses that do not rely on persistent internal state. Synthesizing simple symmetric lenses is substantially more challenging than synthesizing bijective lenses: Since some of the information on each side can be “disconnected” from the other side, there will, in general, be many lenses that agree with a given example. To guide the search process, we use stochastic regular expressions and ideas from information theory to estimate the amount of information propagated by a candidate lens, generally preferring lenses that propagate more information, as well as user annotations marking parts of the source and target data structures as either irrelevant or essential. We describe an implementation of simple symmetric lenses and our synthesis procedure as extensions to the Boomerang language. We evaluate its performance on 48 benchmark examples drawn from Flash Fill, Augeas, the bidirectional programming literature, and electronic file format synchronization tasks. Our implementation can synthesize each of these lenses in under 30 seconds.
Cites 43 works (1 here)
With notes (1)
A Completeness Theorem for Kleene Algebras and the Algebra of Regular Events KOZEN1994366
We give a finitary axiomatization of the algebra of regular events involving only equations and equational implications. Unlike Salomaa′s axiomatizations, the axiomatization given here is sound for all interpretations over Kleene algebras.
External (42)
- Automatic program inversion using symbolic transducers (2017)
- Requirements and compatibility (Team Foundation Server setup, update and administration) (2017)
- Synthesizing bijective lenses (arXiv version) (2017)
- Microsoft Program Synthesis using Examples SDK (2017)
- Reflections on Monadic Lenses (2016)
- Component-based synthesis of table consolidation and transformation tasks from examples (2016)
- BiGUL: a formally verified core language for putback-based bidirectional programming (2016)
- BlinkFill: Semi-supervised Programming By Example for Syntactic String Transformations (2016)
- Synthesizing transformations on hierarchically structured data (2016)
- Brul: a putback-based bidirectional transformation library for updatable views (2016)
- Synthesizing data structure transformations from input-output examples (2015)
- The essence of bidirectional programming (2015)
- Type-and-example-directed program synthesis (2015)
- Program synthesis from polymorphic refinement types (2015)
- Which simple types have a unique inhabitant? (2015)
- Example-directed synthesis: a type-theoretic interpretation (extended version) (2015)
- BiYacc: roll your parser and reflective printer into one (2015)
- FlashExtract: a framework for data extraction by examples (2014)
- Bidirectional spreadsheet formulas (2014)
- BiFluX: A Bidirectional Functional Update Language for XML (2014)
- Test-driven synthesis (2014)
- A new API for Visual Studio Online (2014)
- Complete completion using types and weights (2013)
- Learning Semantic String Transformations from Examples (2012)
- Automating string processing in spreadsheets using input-output examples (2011)
- GRoundTram: An integrated framework for developing well-behaved bidirectional model transformations (2011)
- Matching lenses: alignment and view update (2010)
- Bidirectionalizing graph transformations (2010)
- Bidirectional Transformations: A Cross-Discipline Perspective (2009)
- Semirings and Formal Power Series (2009)
- Boomerang: resourceful lenses for string data (2008)
- Quotient lenses (2008)
- Program synthesis by sketching (2008)
- Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem (2007)
- Bidirectional interpretation of XQuery (2007)
- Augeas: A Linux Configuration API (2007)
- Relational lenses: a language for updatable views (2006)
- [Haskell] Announcing Djinn, version 2004-12-11, a coding wizard (2004)
- Complete Systems of B-Rational Identities (1991)
- Ambiguity in Graphs and Expressions (1971)
- Regular algebra and finite machines (1971)
- Two Complete Axiom Systems for the Algebra of Regular Events (1966)