Introducing Yet Another REversible Language
Claudio Grandi, Dariush Moshiri, Luca Roversi

TL;DR
Yarel is a reversible programming language that implements a class of permutations, with a Java compiler and an Eclipse IDE, contributing to the development of practical reversible computing tools.
Contribution
This paper introduces Yarel, a new reversible language with a complete implementation and an IDE, advancing practical reversible programming.
Findings
Yarel implements primitive recursive complete permutations.
Yarel compiler translates to Java, enabling execution.
Yarel-IDE supports development within Eclipse.
Abstract
Yarel is a core reversible programming language that implements a class of permutations, defined recursively, which are primitive recursive complete. The current release of Yarel syntax and operational semantics, implemented by compiling Yarel to Java, is 0.1.0, according to Semantic Versioning 2.0.0. Yarel comes with Yarel-IDE, developed as an Eclipse plug-in by means of XText.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsLogic, programming, and type systems · Distributed systems and fault tolerance · Computability, Logic, AI Algorithms
11institutetext: Dipartimento di Informatica, C.so Svizzera 185, 10149 Torino (IT) 11email: [email protected] 11email: [email protected] 11email: [email protected],[email protected]
Introducing Yet Another REversible Language
Claudio Grandi
Dariush Moshiri
Luca Roversi
Abstract
Yarel is a core reversible programming language that implements a class of permutations, defined recursively, which are primitive recursive complete. The current release of Yarel syntax and operational semantics, implemented by compiling Yarel to Java, is 0.1.0, according to Semantic Versioning 2.0.0. Yarel comes with Yarel-IDE, developed as an Eclipse plug-in by means of XText.
Keywords:
Reversible computation Programming language Integrated development environment.
1 Introduction
Common programming practice often depends on the solution of problems which are specific examples of reversible computations. Various models that catch the meaning of reversible computation exist. One of them is the class of Reversible Primitive Permutations (RPP), introduced in [18, 19], and simplified in [17]. Those works speculate about how to extend the formal pattern under the design of Primitive Recursive Functions (PRF) in order to capture computational reversible behaviors. Every permutation in RPP has as domain and co-domain, for some . RPP contains total functions and is primitive recursive complete, i.e. every primitive recursive function can be compiled to an equivalent in RPP [17]. The translation relies on proving that RPP represents Cantor Pairing, a pair of isomorphisms between and that stack elements of . So, RPP is at least as expressive as PRF.
Contributions.
Yarel stands for Yet Another REversible Language. Its current release is 0.1.0, i.e. a preliminary one, according to Semantic Versioning 2.0.0.
Since Yarel implements RPP, it inherits its properties. Mainly, it is Primitive Recursive Complete. At the time of this writing we are implementing the above Cantor Pairing in it. Moreover, the functions we can define in Yarel manage their arguments linearly by construction because RPP builds on the monoidal structure of the algebraic theory for boolean circuits in [10].
Yarel can represent every program of SRL [12], a reversible programming language derived from loop languages [14]. So, Yarel inherits also the properties of SRL: (i) every Yarel program free of nested iterations is equivalent to a linear transformation , with a matrix having determinant equal to 1 and a constant [12]; (ii) the fixpoint problem, i.e. “Given any function , does a tuple of values exist such that ?”, is undecidable [18].
Concerning the syntax, the topmost grammatical construct of Yarel are the modules, every one with a name. Directives to import other modules, declarations of functions, i.e. their arity and types, and function definitions can freely alternate in a module. Currently, the only types are comma-separated lists of the keyword int. Functions in Yarel are the least class that we can build from identity id, increment inc, decrement dec, negation neg and finite permutations //, by means of serial composition ****;, parallel composition**|, iteration it[], selection if[,,]** or inverse inv**[]**, given some function and in Yarel. Figure 1 is an example of module. Both fibCore and fib are translations from SRL [13, p. 26]. Like every function in Yarel, fib is arity preserving. The comment **/,,/ identifies its three arguments. If , then fib gives triples by reorganizing its inputs in order to iterate coreFib times. We exploit comments /…/ to show the flow of the values in the functions of Yarel, which is point-free, i.e. a language of combinators with no explicit reference to variable names. For example, /,/it[inc];/,/ in Figure 1 says that the iteration it[inc]** of inc maps the pair to .
The operational semantics of Yarel is in Figure 2. Every is a list of values in , with as many elements as the arity of the function it is argument or conclusion of. For example, the rule itg unfolds it**[]** to a sequential composition of (|dec);…;(|dec) and (|inc);…;(|inc) where: (i) the number of parallel compositions that each of them contains is and (ii) is id**|…|id** with as many id as the length of , i.e. the arity of . Moreover, itz reduces an iteration to a suitable number of id. Finally, fname yields the body of the function with name fname in fcall and i-fcall. .
Yarel-IDE is an integrated development environment, distributed as an Eclipse plug-in, that we generate by means of XText, a further Eclipse plug-in for developing domain specific languages.
XText naturally leads to compile a domain specific language implemented with it into Java classes. Yarel is not an exception and the above operational semantics drives the compilation. As an example, Figure 3 is the object code of compiling a function seqComp, defined as inc**;dec**. The class has name seqComp and implements a suitable interface RPP. Two private fields l and r contain the compilation of the left and of the right-hand side of the sequential composition. I.e., l is an anonymous class that contains an instance of the compilation inc**()** of inc whose arity is in a and whose behaviour is in int**[] b(int[] x). Analogous comments hold on r. Given l and r, we let the arity of the sequential composition coincide with l.getA()** while the behavior is the sequential composition of l**.b** and r**.b** in lines 15 and 16. Every function of Yarel is compiled under analogous patterns.
Remarkably, compiling some given in Yarel to Java let the compilation of and of its inverse available in Java as methods that we can freely use with the proviso of never dropping any of the arguments that assure the reversibility. We see this as pursuing the vision of [7], focused on formalizing classes of classical functions with lossless inverses. Moreover, whatever we write in Yarel becomes compliant with the object oriented conceptual tools that Java supplies without any ad-hoc extension of Yarel with object oriented features.
Finally, our compilation assures that the -bits modular arithmetic of Java on its integers preserves the reversibility in case of overflow. For example, a standard definition of sum in Yarel compiles to a method sum**.b** whose behavior can be inverted even after computing 5 + Integer**.MAX_VALUE**, which results in an overflow. We get for free what the implementation of Janus in [21, pp. 78] requires explicitly, i.e. a sum on a -bits binary representation defined as .
Related work.
Yarel is functional. Reversible functional languages we are aware of are RFUN [20], CoreFun [8], Inv [15] and Theseus [3].
The introduction of linear variables in the functional language FUN which leads to RFUN is similar to the introduction of the linear management of variables leading from Primitive Recursive Functions (PRF) to Reversible Primitive Permutations (RPP), i.e. to Yarel. A multiple output arity endows Yarel with an iteration it**[]** and a selection if**[,,]** whose inverses do not need any reference to an analogous of RFUN’s first-match policy.
Yarel syntactically extends SRL [12] by means of the selection if**[,,]** and of the explicit use of inv**[]** that inverts the interpretation of . The operational semantics of the iteration it**[]** in Yarel slightly differs from the corresponding construct for** x()** of SRL. Every other aspects of the two languages perfectly overlap, despite SRL derives from loop languages [14]. The equivalence between Yarel and SRL is open.
Yarel is point-less like Inv [15] introduced to ease the management of reversible aspects in the area of document constructions. The basic compositional operators of Yarel and Inv overlap but differ on the basic combinators. Both languages allow the duplication of arguments, but on radical different philosophical basis. Investigating how and if the two ideas of duplication relate each other will contribute to improve our insights about the reversible computation.
The focus on type isomorphisms and on combinators that preserve information leads to Theseus [9], language based on conventional pattern matching which must be subject to restrictions that guarantees no information loss. The designers of Theseus discarded a point-less style on purpose. The experience of point-less programming in Yarel suggests to exploit comments for a sort of correctness check. They allow to describe the flow of values that, otherwise, would remain hidden in the name of variables.
A class of circuit models coming from a categorical interpretation of the Geometry of Interaction (GoI) [5] is in [1]. A possible connection is that Yarel, like the above classes of circuits, has a natural representation in terms of string diagrams whose computation can be described by a flow of tokens.
Also [4] deals with reversible combinators. It labels combinators and encodes their reduction history, something that strongly recalls how a Turing machine becomes reversible [2] and which we avoided since our first steps.
Finally, even though not a combinator language, we cannot forget ROOPL [6], object oriented extension of Janus [11, 22, 16]. Yarel is not at all an object oriented programming language, but it can interact with an object oriented environment because we compile it to Java.
2 Conclusions
We are extending Yarel with primitive and compound types. We are also writing a first set of libraries. Being Yarel a core language, everything needs to be programmed from scratch, generally producing inefficient algorithms. A way out is to first program reversible algorithms in Yarel to identify the interface. Then, it is possible to re-implement them directly in Java, preserving that interface, but dramatically improving the efficiency.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Samson Abramsky “A structural approach to reversible computation” In Theoretical Computer Science 347.3 , 2005, pp. 441 –464 DOI: https://doi.org/10.1016/j.tcs.2005.07.002 · doi ↗
- 2[2] C. H. Bennett “Logical Reversibility of Computation” In IBM J. Res. Dev. 17.6 Riverton, NJ, USA: IBM Corp., 1973, pp. 525–532 DOI: 10.1147/rd.176.0525 · doi ↗
- 3[3] Jacques Carette, Roshan P. James and Amr Sabry “Embracing the Laws of Physics: Three Reversible Models of Computation” In Co RR abs/1811.03678 , 2018 URL: http://arxiv.org/abs/1811.03678
- 4[4] Alessandra Di Pierro, Chris Henkin and Herbert Wiklicky “Reversible combinatory logic” In MSCS 16.4 CUP, 2006, pp. 621–637 DOI: 10.1017/S 0960129506005391 · doi ↗
- 5[5] Jean-Yves Girard “On Geometry of Interaction” In Proof and Computation Springer Berlin Heidelberg, 1995, pp. 145–191
- 6[6] Tue Haulund “Design and Implementation of a Reversible Object-Oriented Programming Language” In Co RR abs/1707.07845 , 2017 URL: http://arxiv.org/abs/1707.07845
- 7[7] David A. Huffman “Canonical forms for information-lossless finite-state logical machines” In IRE Trans. Information Theory 5.5 , 1959, pp. 41–59 DOI: 10.1109/TIT.1959.1057537 · doi ↗
- 8[8] Petur Andrias Højgaard Jacobsen, Robin Kaarsgaard and Michael Kirkedal Thomsen “ Core Fun : A Typed Functional Reversible Core Language” In RC’18, Leicester, UK 11106 , LNCS Springer, 2018, pp. 304–321 URL: https://doi.org/10.1007/978-3-319-99498-7\_21 · doi ↗
