Abstract

Invertibility is a fundamental concept in computer science, with various manifestations in software development (serializer/deserializer, parser/printer, redo/undo, compressor/decompressor, and so on). Full invertibility necessarily requires bijectivity, but the direct approach of composing bijective functions to develop invertible programs is too restrictive to be useful. In this paper, we take a different approach by focusing on partially-invertible functions—functions that become invertible if some of their arguments are fixed. The simplest example of such is addition, which becomes invertible when fixing one of the operands. More involved examples include entropy-based compression methods (e.g., Huffman coding), which carry the occurrence frequency of input symbols (in certain formats such as Huffman tree), and fixing this frequency information makes the compression methods invertible. We develop a language Sparcl for programming such functions in a natural way, where partial-invertibility is the norm and bijectivity is a special case, hence gaining significant expressiveness without compromising correctness. The challenge in designing such a language is to allow ordinary programming (the “partially” part) to interact with the invertible part freely, and yet guarantee invertibility by construction. The language Sparcl is linear-typed, and has a type constructor to distinguish data that are subject to invertible computation and those that are not. We present the syntax, type system, and semantics of the language, and prove that Sparcl correctly guarantees invertibility for its programs. We demonstrate the expressiveness of Sparcl with examples including tree rebuilding from preorder and inorder traversals and Huffman coding.

Highlights

  • INTRODUCTIONFact that looking beyond the surface syntax, the definition is identical in structure to how subs is defined in a conventional language: goSubs has the same recursive pattern with two cases for empty and non-empty lists

  • Invertible computation, known as reversible computation in physics and more hardwareoriented contexts, is a fundamental concept in computing

  • Type system, and semantics of the language, and prove that Sparcl correctly guarantees invertibility for its programs

Read more

Summary

INTRODUCTION

Fact that looking beyond the surface syntax, the definition is identical in structure to how subs is defined in a conventional language: goSubs has the same recursive pattern with two cases for empty and non-empty lists This close resemblance to the conventional programming style is what we strive for in the design of Sparcl. This guarantee of bijectivity is clearly different from the case of (functional) logic programming languages such as Prolog and Curry Those languages relies on (lazy) generate-and-test [Antoy et al 2000] to find inputs corresponding to a given output, a technique that may be adopted in the context of inverse computation [Abramov et al 2006]. All the artifacts are linked from the Sparcl web page (https://bx-lang.github.io/EXHIBIT/sparcl.html)

Linear-Typed Programming
Multiplication
Why Linearity Itself is Insufficient but Still Matters
Running Reversible Computation
Importing Existing Invertible Functions
Composing Partially-Invertible Functions
Implementations
Central Concept
Typing Relation
Operational Semantics
Three Evaluation Relations
Extension with The lift Operator
LARGER EXAMPLES
Rebuilding Trees from a Pre-Order and an In-Order Traversals
Huffman Coding
RELATED WORK
Functional Quantum Programming Languages
Bidirectional Programming Languages
CONCLUSION
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call