Hostname: page-component-89b8bd64d-rbxfs Total loading time: 0 Render date: 2026-05-05T22:42:22.767Z Has data issue: false hasContentIssue false

Sparcl: A language for partially invertible computation

Part of: ICFP20/21

Published online by Cambridge University Press:  26 January 2024

KAZUTAKA MATSUDA
Affiliation:
Tohoku University, 6-3-09 Aramaki, Aza-Aoba, Aoba-ku, Sendai, Japan (e-mail: kztk@tohoku.ac.jp)
MENG WANG
Affiliation:
University of Bristol, BS8 1TH, Bristol, UK (e-mail: meng.wang@bristol.ac.uk)
Rights & Permissions [Opens in a new window]

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, Huffman coding, arithmetic coding, and LZ77 compression.

Information

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2024. Published by Cambridge University Press
Figure 0

Fig. 1. Invertible subs in Sparcl.

Figure 1

Fig. 2. Side-by-side comparison of partially invertible (a) and fully invertible (b) versions of subs.

Figure 2

Fig. 3. Typing rules for expressions and patterns.

Figure 3

Fig. 4. Evaluation relations: unidirectional, forward and backward.

Figure 4

Fig. 5. Invertible pre- and in-order traversal in Sparcl.

Figure 5

Fig. 6. Two-pass Huffman coding in Sparcl.

Figure 6

Fig. 7. Adaptive Huffman coding in Sparcl.

Figure 7

Fig. 8. LZ77 in Sparcl.

Submit a response

Discussions

No Discussions have been published for this article.