Introducing Yet Another REversible Language

02/14/2019 ∙ by Claudio Grandi, et al. ∙ Università di Torino 0

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.



There are no comments yet.


page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

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 [PaoliniPiccoloRoversi-ENTCS2016, Paolini2018NGC], and simplified in [PaoliniPiccoloRoversi:RPP]. 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 [PaoliniPiccoloRoversi:RPP]. 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.

1module Fibonacci                                 { 2 dcl coreFib : int, int 3 def coreFib := /*,*/        it[inc]; 4                /*,*/     /2 1/; 5                /*,*/     it[inc]; 6                /*,*/ inv[/2 1/] 7                /* ,*/ 8 9 dcl fib : int, int, int 10 def fib := /*,,*/             /2 3 1/; 11            /*,,*/                it[coreFib]; 12            /*,,*/ inv[/2 3 1/] 13            /*,,*/        }
Figure 1: The function fib as defined in Yarel-IDE.


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 [Lafont2003257].

Yarel can represent every program of SRL [matos03tcs], a reversible programming language derived from loop languages [MeyerRitchie67a]. 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 [matos03tcs]; (ii) the fixpoint problem, i.e. “Given any function , does a tuple of values exist such that ?”, is undecidable [PaoliniPiccoloRoversi-ENTCS2016].

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 [matosWorkInProgress2014, 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 /*DOTS*/ 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 .

id i-id neg i-neg
dec    i-dec inc    i-inc
seq    i-seq
par    i-par
ifg    ifs
ifz    i-if
itz    i-it
fcall    i-fcall    i-inv
Figure 2: Operational semantics of Yarel. The function id|DOTS|id|inc in itg contains as many occurrences of id as the length of . An analogous comment holds for its and itz.

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);DOTS;(|dec) and (|inc);DOTS;(|inc) where: (i) the number of parallel compositions that each of them contains is and (ii) is id|DOTS|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.

1public class seqComp implements RPP                     {
2  public seqComp() { } // Constructor
3  // l(eft-hand side) of the sequential composition
4  private RPP l = new RPP()                             {
5    private RPP f = new inc();  // an instance of inc
6    private final int a = f.getA();
7    public int[] b(int[] x) { return this.f.b(x); }
8    public int getA() { return this.a; }                };
9  // r(ight-hand side) of the sequential composition
10  private RPP r = new RPP()                             {
11    private RPP f = new dec();  // an instance of dec
12    private final int a = f.getA();
13    public int[] b(int[] x) { return this.f.b(x); }
14    public int getA() { return this.a; }                };
15  private final int a = l.getA(); // Same arity of l or r
16  public int[] b(int[] x)         { // Seq. composition
17    return this.r.b(this.l.b(x)); }
18  public int getA() { return this.a; }                    }
Figure 3: The compilation of scExample in Java.

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 [DBLP:journals/tit/Huffman59], 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 [DBLP:journals/entcs/Yokoyama10, 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 [Thomsen:2015:IPR:2897336.2897345], CoreFun [DBLP:conf/rc/JacobsenKT18], Inv [10.1007/978-3-540-27764-4_16] and Theseus [DBLP:journals/corr/abs-1811-03678].

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 [matos03tcs] 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 [MeyerRitchie67a]. The equivalence between Yarel and SRL is open.

Yarel is point-less like Inv [10.1007/978-3-540-27764-4_16] 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 [James2014TheseusAH]

, 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) [10.1007/978-3-642-79361-5_4] is in [ABRAMSKY2005441]. 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 [dipierro_hankin_wiklicky_2006]

deals with reversible combinators. It labels combinators and encodes their reduction history, something that strongly recalls how a Turing machine becomes reversible

[Bennett:1973:LRC:1664562.1664568] and which we avoided since our first steps.

Finally, even though not a combinator language, we cannot forget ROOPL [DBLP:journals/corr/Haulund17], object oriented extension of Janus [Lutz86, Yokoyama:2008:PRP:1366230.1366239, paolini2018lipics]. 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.