In
computer programming
Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by-step specifications of proc ...
, bidirectional transformations (bx) are programs in which a single piece of code can be run in several ways, such that the same data are sometimes considered as input, and sometimes as output. For example, a bx run in the forward direction might transform input I into output O, while the same bx run backward would take as input versions of I and O and produce a new version of I as its output.
Bidirectional model transformations are an important special case in which a model is input to such a program.
Some bidirectional languages are
''bijective''. The bijectivity of a language is a severe restriction of its power,
because a bijective language is merely relating two different ways to present the very same information.
More general is a lens language, in which there is a distinguished forward direction ("get") that takes a concrete input to an abstract output, discarding some information in the process: the concrete state includes all the information that is in the abstract state, and usually some more. The backward direction ("put") takes a concrete state and an abstract state and computes a new concrete state. Lenses are required to obey certain conditions to ensure sensible behaviour.
The most general case is that of symmetric bidirectional transformations. Here the two states that are related typically share some information, but each also includes some information that is not included in the other.
Usage
Bidirectional transformations can be used to:
* Maintain the consistency of several sources of information
* Provide an 'abstract view' to easily manipulate data and write them back to their source
Definition
Bidirectional transformations fall into various well-studied categories.
A ''lens'' is a pair of functions
,
relating a ''source''
and a ''view''
. If these functions obey the three lens laws:
* PutGet:
* GetPut:
* PutPut:
It is called a ''well-behaved lens''.
A related notion is that of a prism, in which the signatures of the functions are instead
,
. Unlike a lens, a prism may not always give a view; also unlike a lens, given a prism, a view is ''sufficient'' to construct a source. If lenses allow "focusing" (viewing, updating) on a part of a
product type, prisms allow focusing (possible viewing, building) on a part of a
sum type.
Both lenses and prisms, as well as other constructions such as traversals, are more general notion of bidirectional transformations known as optics.
Examples of implementations
*
Boomerang
A boomerang () is a thrown tool typically constructed with airfoil sections and designed to spin about an axis perpendicular to the direction of its flight, designed to return to the thrower. The origin of the word is from Australian Aborigin ...
is a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that allows writing lenses to process text data formats bidirectionally
*
Augeas is a configuration management library whose lens language is inspired by the Boomerang project
* ''biXid'' is a programming language for processing
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
data bidirectionally
* ''XSugar'' allows translation from XML to non-XML formats
See also
*
Bidirectionalization
*
Reverse computation
*
Transformation language
References
External links
*
*
* {{cite conference , last1=Pacheco , first1=Hugo , first2=Alcino , last2=Cunha , url=https://repositorium.sdum.uminho.pt/bitstream/1822/24674/1/icmt12-1.pdf , title=Multifocal: A strategic bidirectional transformation language for XML schemas , conference=International Conference on Theory and Practice of Model Transformations , location=Springer, Berlin, Heidelberg , date=2012 , doi=10.1007/978-3-642-30476-7_6
Mathematical relations