Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Sparcl: a language for partially-invertible computation

Published: 03 August 2020 Publication History
  • Get Citation Alerts
  • 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.

    Supplementary Material

    Presentation at ICFP '20 (a118-matsuda-presentation.mp4)

    References

    [1]
    Andreas Abel and James Chapman. 2014. Normalization by Evaluation in the Delay Monad: A Case Study for Coinduction via Copatterns and Sized Types. In Proceedings 5th Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2014, Grenoble, France, 12 April 2014 (EPTCS), Paul Levy and Neel Krishnaswami (Eds.), Vol. 153. 51-67. https://doi.org/10.4204/EPTCS.153.4
    [2]
    Sergei M. Abramov, Robert Glück, and Yuri A. Klimov. 2006. An Universal Resolving Algorithm for Inverse Computation of Lazy Languages. In Ershov Memorial Conference (Lecture Notes in Computer Science), Irina Virbitskaite and Andrei Voronkov (Eds.), Vol. 4378. Springer, 27-40.
    [3]
    Samson Abramsky. 2005. A structural approach to reversible computation. Theor. Comput. Sci. 347, 3 ( 2005 ), 441-464. https://doi.org/10.1016/j.tcs. 2005. 07.002
    [4]
    Samson Abramsky, Esfandiar Haghverdi, and Philip J. Scott. 2002. Geometry of Interaction and Linear Combinatory Algebras. Mathematical Structures in Computer Science 12, 5 ( 2002 ), 625-665. https://doi.org/10.1017/S0960129502003730
    [5]
    Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2010. Monads Need Not Be Endofunctors. In Foundations of Software Science and Computational Structures, 13th International Conference, FOSSACS 2010, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2010, Paphos, Cyprus, March 20-28, 2010. Proceedings (Lecture Notes in Computer Science), C.-H. Luke Ong (Ed.), Vol. 6014. Springer, 297-311. https://doi.org/10.1007/978-3-642-12032-9_21
    [6]
    Thorsten Altenkirch and Jonathan Grattage. 2005. A Functional Quantum Programming Language. In 20th IEEE Symposium on Logic in Computer Science (LICS 2005 ), 26-29 June 2005, Chicago, IL, USA, Proceedings. IEEE Computer Society, 249-258. https://doi.org/10.1109/LICS. 2005.1
    [7]
    Sergio Antoy, Rachid Echahed, and Michael Hanus. 2000. A needed narrowing strategy. J. ACM 47, 4 ( 2000 ), 776-822. https://doi.org/10.1145/347476.347484
    [8]
    Holger Bock Axelsen, Robert Glück, and Tetsuo Yokoyama. 2007. Reversible Machine Code and Its Abstract Processor Architecture. In Computer Science-Theory and Applications, Second International Symposium on Computer Science in Russia, CSR 2007, Ekaterinburg, Russia, September 3-7, 2007, Proceedings (Lecture Notes in Computer Science), Volker Diekert, Mikhail V. Volkov, and Andrei Voronkov (Eds.), Vol. 4649. Springer, 56-69. https://doi.org/10.1007/978-3-540-74510-5_9
    [9]
    Henry G. Baker. 1992. NREVERSAL of Fortune-The Thermodynamics of Garbage Collection. In Memory Management, International Workshop IWMM 92, St. Malo, France, September 17-19, 1992, Proceedings (Lecture Notes in Computer Science), Yves Bekkers and Jacques Cohen (Eds.), Vol. 637. Springer, 507-524. https://doi.org/10.1007/BFb0017210
    [10]
    Charles H. Bennett. 1973. Logical Reversibility of Computation. IBM Journal of Research and Development 17, 6 (Nov 1973 ), 525-532. https://doi.org/10.1147/rd.176.0525
    [11]
    Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. 2018. Linear Haskell: practical linearity in a higher-order polymorphic language. PACMPL 2, POPL ( 2018 ), 5 : 1-5 : 29. https://doi.org/ 10.1145/3158093
    [12]
    Venanzio Capretta. 2005. General recursion via coinductive types. Logical Methods in Computer Science 1, 2 ( 2005 ). https://doi.org/10.2168/LMCS-1( 2 :1) 2005
    [13]
    Wei-Ngan Chin. 1993. Towards an Automated Tupling Strategy. In Proceedings of the ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM' 93, Copenhagen, Denmark, June 14-16, 1993, David A. Schmidt (Ed.). ACM, 119-132. https://doi.org/10.1145/154630.154643
    [14]
    Rowan Davies and Frank Pfenning. 2001. A modal analysis of staged computation. J. ACM 48, 3 ( 2001 ), 555-604. https: //doi.org/10.1145/382780.382785
    [15]
    David Eppstein. 1985. A Heuristic Approach to Program Inversion. In IJCAI. 219-221.
    [16]
    J. Nathan Foster, Michael B. Greenwald, Jonathan T. Moore, Benjamin C. Pierce, and Alan Schmitt. 2007. Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem. ACM Trans. Program. Lang. Syst. 29, 3 ( 2007 ).
    [17]
    Michael P. Frank. 1997. The R Programming Language and Compiler. MIT Reversible Computing Project Memo #M8, MIT AI Lab. Available on: https://github.com/mikepfrank/Rlang-compiler/blob/master/docs/MIT-RCP-MemoM8-RProgLang.pdf.
    [18]
    Jeremy Gibbons. 2002. Calculating Functional Programs. Springer Berlin Heidelberg, Berlin, Heidelberg, 151-203. https: //doi.org/10.1007/3-540-47797-7_5
    [19]
    Robert Glück and Masahiko Kawabe. 2003. A Program Inverter for a Functional Language with Equality and Constructors. In APLAS (Lecture Notes in Computer Science), Atsushi Ohori (Ed.), Vol. 2895. Springer, 246-264. https://doi.org/10.1007/978-3-540-40018-9_17
    [20]
    Robert Glück and Masahiko Kawabe. 2004. Derivation of Deterministic Inverse Programs Based on LR Parsing. In FLOPS (Lecture Notes in Computer Science), Yukiyoshi Kameyama and Peter J. Stuckey (Eds.), Vol. 2998. Springer, 291-306.
    [21]
    Robert Glück and Tetsuo Yokoyama. 2016. A Linear-Time Self-Interpreter of a Reversible Imperative Language. Computer Software 33, 3 ( 2016 ), 3_108-3_128. https://doi.org/10.11309/jssst.33.3_108
    [22]
    Robert Glück and Tetsuo Yokoyama. 2019. Constructing a binary tree from its traversals by reversible recursion and iteration. Inf. Process. Lett. 147 ( 2019 ), 32-37. https://doi.org/10.1016/j.ipl. 2019. 03.002
    [23]
    Carsten K. Gomard and Neil D. Jones. 1991. A Partial Evaluator for the Untyped lambda-Calculus. J. Funct. Program. 1, 1 ( 1991 ), 21-69. https://doi.org/10.1017/S0956796800000058
    [24]
    Soichiro Hidaka, Zhenjiang Hu, Kazuhiro Inaba, Hiroyuki Kato, Kazutaka Matsuda, and Keisuke Nakano. 2010. Bidirectionalizing graph transformations. In Proceeding of the 15th ACM SIGPLAN international conference on Functional programming, ICFP 2010, Baltimore, Maryland, USA, September 27-29, 2010, Paul Hudak and Stephanie Weirich (Eds.). ACM, 205-216. https://doi.org/10.1145/1863543.1863573
    [25]
    Zhenjiang Hu, Hideya Iwasaki, Masato Takeichi, and Akihiko Takano. 1997. Tupling Calculation Eliminates Multiple Data Traversals. In Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming (ICFP '97), Amsterdam, The Netherlands, June 9-11, 1997., Simon L. Peyton Jones, Mads Tofte, and A. Michael Berman (Eds.). ACM, 164-175. https://doi.org/10.1145/258948.258964
    [26]
    Zhenjiang Hu, Shin-Cheng Mu, and Masato Takeichi. 2004. A programmable editor for developing structured documents based on bidirectional transformations. In Proceedings of the 2004 ACM SIGPLAN Workshop on Partial Evaluation and Semantics-based Program Manipulation, 2004, Verona, Italy, August 24-25, 2004, Nevin Heintze and Peter Sestoft (Eds.). ACM, 178-189. https://doi.org/10.1145/1014007.1014025
    [27]
    Petur Andrias Højgaard Jacobsen, Robin Kaarsgaard, and Michael Kirkedal Thomsen. 2018. \mathsf CoreFun : A Typed Functional Reversible Core Language. In Reversible Computation-10th International Conference, RC 2018, Leicester, UK, September 12-14, 2018, Proceedings (Lecture Notes in Computer Science), Jarkko Kari and Irek Ulidowski (Eds.), Vol. 11106. Springer, 304-321. https://doi.org/10.1007/978-3-319-99498-7_21
    [28]
    Roshan P. James and Amr Sabry. 2012. Information efects. In Proceedings of the 39th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2012, Philadelphia, Pennsylvania, USA, January 22-28, 2012, John Field and Michael Hicks (Eds.). ACM, 73-84. https://doi.org/10.1145/2103656.2103667
    [29]
    Mark P. Jones. 1995. Qualified Types: Theory and Practice. Cambridge University Press, New York, NY, USA.
    [30]
    Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial evaluation and automatic program generation. Prentice Hall.
    [31]
    André Joyal, Ross Street, and Dominic Verity. 1996. Traced Monoidal Categories. Mathematical Proceedings of the Cambridge Philosophical Society 119, 3 (Apr 1996 ), 447-468.
    [32]
    Andrew J. Kennedy and Dimitrios Vytiniotis. 2012. Every bit counts: The binary representation of typed data and programs. J. Funct. Program. 22, 4-5 ( 2012 ), 529-573.
    [33]
    Armin Kühnemann, Robert Glück, and Kazuhiko Kakehi. 2001. Relating Accumulative and Non-accumulative Functional Programs. In RTA (Lecture Notes in Computer Science), Aart Middeldorp (Ed.), Vol. 2051. Springer, 154-168.
    [34]
    Rolf Landauer. 1961. Irreversibility and Heat Generation in the Computing Process. IBM Journal of Research and Development 5, 3 ( 1961 ), 183-191. https://doi.org/10.1147/rd.53.0183
    [35]
    John Launchbury and Simon L. Peyton Jones. 1994. Lazy Functional State Threads. In Proceedings of the ACM SIGPLAN'94 Conference on Programming Language Design and Implementation (PLDI), Orlando, Florida, USA, June 20-24, 1994, Vivek Sarkar, Barbara G. Ryder, and Mary Lou Sofa (Eds.). ACM, 24-35. https://doi.org/10.1145/178243.178246
    [36]
    Christopher Lutz. 1986. Janus: a time-reversible language. ( 1986 ). Letter to R. Landauer. Available on: http://tetsuo.jp/ref/ janus.pdf.
    [37]
    Saunders Mac Lane. 1998. Categories for the Working Mathematician (second edition ed.). Graduate Texts in Matheematics, Vol. 5. Springer.
    [38]
    Kazutaka Matsuda. 2020. Modular Inference of Linear Types for Multiplicity-Annotated Arrows. In Programming Languages and Systems-29th European Symposium on Programming, ESOP 2020, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2020, Dublin, Ireland, April 25-30, 2020, Proceedings (Lecture Notes in Computer Science), Peter Müller (Ed.), Vol. 12075. Springer, 456-483. https://doi.org/10.1007/978-3-030-44914-8_17 The full version is available on: http://arxiv.org/abs/ 1911.00268v2.
    [39]
    Kazutaka Matsuda, Zhenjiang Hu, Keisuke Nakano, Makoto Hamana, and Masato Takeichi. 2007. Bidirectionalization transformation based on automatic derivation of view complement functions. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007, Freiburg, Germany, October 1-3, 2007, Ralf Hinze and Norman Ramsey (Eds.). ACM, 47-58. https://doi.org/10.1145/1291151.1291162
    [40]
    Kazutaka Matsuda, Kazuhiro Inaba, and Keisuke Nakano. 2012. Polynomial-time inverse computation for accumulative functions with multiple data traversals. Higher-Order and Symbolic Computation 25, 1 ( 2012 ), 3-38. https://doi.org/10. 1007/s10990-013-9097-8
    [41]
    Kazutaka Matsuda, Shin-Cheng Mu, Zhenjiang Hu, and Masato Takeichi. 2010. A Grammar-Based Approach to Invertible Programs. In ESOP (Lecture Notes in Computer Science), Andrew D. Gordon (Ed.), Vol. 6012. Springer, 448-467.
    [42]
    Kazutaka Matsuda and Meng Wang. 2013. FliPpr: A Prettier Invertible Printing System. In ESOP (Lecture Notes in Computer Science), Matthias Felleisen and Philippa Gardner (Eds.), Vol. 7792. Springer, 101-120. https://doi.org/10.1007/978-3-642-37036-6_6
    [43]
    Kazutaka Matsuda and Meng Wang. 2015a. Applicative bidirectional programming with lenses. In ICFP, Kathleen Fisher and John H. Reppy (Eds.). ACM, 62-74. https://doi.org/10.1145/2784731.2784750
    [44]
    Kazutaka Matsuda and Meng Wang. 2015b. "Bidirectionalization for free" for monomorphic transformations. Sci. Comput. Program. 111 ( 2015 ), 79-109. https://doi.org/10.1016/j.scico. 2014. 07.008
    [45]
    Kazutaka Matsuda and Meng Wang. 2018a. Applicative bidirectional programming: Mixing lenses and semantic bidirectionalization. J. Funct. Program. 28 ( 2018 ), e15. https://doi.org/10.1017/S0956796818000096
    [46]
    Kazutaka Matsuda and Meng Wang. 2018b. Embedding invertible languages with binders: a case of the FliPpr language. In Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell, Haskell@ICFP 2018, St. Louis, MO, USA, September 27-17, 2018, Nicolas Wu (Ed.). ACM, 158-171. https://doi.org/10.1145/3242744.3242758
    [47]
    Kazutaka Matsuda and Meng Wang. 2018c. HOBiT: Programming Lenses Without Using Lens Combinators. In ESOP (Lecture Notes in Computer Science), Amal Ahmed (Ed.), Vol. 10801. Springer, 31-59. https://doi.org/10.1007/978-3-319-89884-1_2
    [48]
    Karl Mazurak, Jianzhou Zhao, and Steve Zdancewic. 2010. Lightweight linear types in system fdegree. In TLDI. ACM, 77-88.
    [49]
    Conor McBride and Ross Paterson. 2008. Applicative programming with efects. J. Funct. Program. 18, 1 ( 2008 ), 1-13. https://doi.org/10.1017/S0956796807006326
    [50]
    Torben Æ. Mogensen. 2005. Semi-inversion of Guarded Equations. In Generative Programming and Component Engineering, 4th International Conference, GPCE 2005, Tallinn, Estonia, September 29-October 1, 2005, Proceedings (Lecture Notes in Computer Science), Robert Glück and Michael R. Lowry (Eds.), Vol. 3676. Springer, 189-204. https://doi.org/10.1007/ 11561347_14
    [51]
    Torben Æ. Mogensen. 2006. Report on an Implementation of a Semi-inverter. In Ershov Memorial Conference (Lecture Notes in Computer Science), Irina Virbitskaite and Andrei Voronkov (Eds.), Vol. 4378. Springer, 322-334.
    [52]
    Torben Æ. Mogensen. 2008. Semi-inversion of functional parameters. In Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM 2008, San Francisco, California, USA, January 7-8, 2008, Robert Glück and Oege de Moor (Eds.). ACM, 21-29. https://doi.org/10.1145/1328408.1328413
    [53]
    Eugenio Moggi. 1998. Functor Categories and Two-Level Languages. In Foundations of Software Science and Computation Structure, First International Conference, FoSSaCS'98, Held as Part of the European Joint Conferences on the Theory and Practice of Software, ETAPS'98, Lisbon, Portugal, March 28-April 4, 1998, Proceedings (Lecture Notes in Computer Science), Maurice Nivat (Ed.), Vol. 1378. Springer, 211-225. https://doi.org/10.1007/BFb0053552
    [54]
    J. Garrett Morris. 2016. The best of both worlds: linear functional programming without compromise. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, Nara, Japan, September 18-22, 2016, Jacques Garrigue, Gabriele Keller, and Eijiro Sumii (Eds.). ACM, 448-461. https://doi.org/10.1145/2951913.2951925
    [55]
    Shin-Cheng Mu and Richard S. Bird. 2003. Rebuilding a Tree from Its Traversals: A Case Study of Program Inversion. In Programming Languages and Systems, First Asian Symposium, APLAS 2003, Beijing, China, November 27-29, 2003, Proceedings (Lecture Notes in Computer Science), Atsushi Ohori (Ed.), Vol. 2895. Springer, 265-282. https://doi.org/10.1007/978-3-540-40018-9_18
    [56]
    Shin-Cheng Mu, Zhenjiang Hu, and Masato Takeichi. 2004a. An Algebraic Approach to Bi-directional Updating. In Programming Languages and Systems: Second Asian Symposium, APLAS 2004, Taipei, Taiwan, November 4-6, 2004. Proceedings (Lecture Notes in Computer Science), Wei-Ngan Chin (Ed.), Vol. 3302. Springer, 2-20. https://doi.org/10.1007/978-3-540-30477-7_2
    [57]
    Shin-Cheng Mu, Zhenjiang Hu, and Masato Takeichi. 2004b. An Injective Language for Reversible Computation. In Mathematics of Program Construction, 7th International Conference, MPC 2004, Stirling, Scotland, UK, July 12-14, 2004, Proceedings (Lecture Notes in Computer Science), Dexter Kozen and Carron Shankland (Eds.), Vol. 3125. Springer, 289-313. https://doi.org/10.1007/978-3-540-27764-4_16
    [58]
    Flemming Nielson and Hanne Riis Nielson. 1992. Two-Level Functional Languages. Cambridge University Press. https: //doi.org/10.1017/CBO9780511526572
    [59]
    Naoki Nishida, Masahiko Sakai, and Toshiki Sakabe. 2005. Partial Inversion of Constructor Term Rewriting Systems. In Term Rewriting and Applications, 16th International Conference, RTA 2005, Nara, Japan, April 19-21, 2005, Proceedings (Lecture Notes in Computer Science), Jürgen Giesl (Ed.), Vol. 3467. Springer, 264-278. https://doi.org/10.1007/978-3-540-32033-3_20
    [60]
    Naoki Nishida and Germán Vidal. 2011. Program Inversion for Tail Recursive Functions. In RTA (LIPIcs), Manfred SchmidtSchauß (Ed.), Vol. 10. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 283-298.
    [61]
    Ross Paterson. 2012. Constructing Applicative Functors. In MPC (Lecture Notes in Computer Science), Jeremy Gibbons and Pablo Nogueira (Eds.), Vol. 7342. Springer, 300-323. https://doi.org/10.1007/978-3-642-31113-0_15

    Cited By

    View all

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 4, Issue ICFP
    August 2020
    1070 pages
    EISSN:2475-1421
    DOI:10.1145/3415018
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution International 4.0 License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 03 August 2020
    Published in PACMPL Volume 4, Issue ICFP

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. linear types
    2. reversible computation

    Qualifiers

    • Research-article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)122
    • Downloads (Last 6 weeks)11
    Reflects downloads up to 10 Aug 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024) Sparcl : A language for partially invertible computation Journal of Functional Programming10.1017/S095679682300012634Online publication date: 26-Jan-2024
    • (2024)Connecting Reversible and Classical Computing Through Hybrid SSAReversible Computation10.1007/978-3-031-62076-8_11(161-178)Online publication date: 29-May-2024
    • (2024)Reconciling Partial and Local InvertibilityProgramming Languages and Systems10.1007/978-3-031-57267-8_3(59-89)Online publication date: 6-Apr-2024
    • (2023)Embedding by UnembeddingProceedings of the ACM on Programming Languages10.1145/36078307:ICFP(1-47)Online publication date: 30-Aug-2023
    • (2023)Contract lenses: Reasoning about bidirectional programs via calculationJournal of Functional Programming10.1017/S095679682300005933Online publication date: 6-Nov-2023
    • (2023)Reversible computing from a programming language perspectiveTheoretical Computer Science10.1016/j.tcs.2022.06.010953:COnline publication date: 10-Apr-2023
    • (2022)Synbit: synthesizing bidirectional programs using unidirectional sketchesFormal Methods in System Design10.1007/s10703-023-00436-961:2-3(198-247)Online publication date: 1-Dec-2022
    • (2021)Synbit: synthesizing bidirectional programs using unidirectional sketchesProceedings of the ACM on Programming Languages10.1145/34854825:OOPSLA(1-31)Online publication date: 15-Oct-2021
    • (2021)Haskell⁻¹: automatic function inversion in HaskellProceedings of the 14th ACM SIGPLAN International Symposium on Haskell10.1145/3471874.3472982(41-55)Online publication date: 18-Aug-2021

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media