skip to main content

Sparcl: a language for partially-invertible computation

Published:03 August 2020Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

a118-matsuda-presentation.mp4

mp4

40.6 MB

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 Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. David Eppstein. 1985. A Heuristic Approach to Program Inversion. In IJCAI. 219-221.Google ScholarGoogle Scholar
  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 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  18. Jeremy Gibbons. 2002. Calculating Functional Programs. Springer Berlin Heidelberg, Berlin, Heidelberg, 151-203. https: //doi.org/10.1007/3-540-47797-7_5 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Mark P. Jones. 1995. Qualified Types: Theory and Practice. Cambridge University Press, New York, NY, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial evaluation and automatic program generation. Prentice Hall.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle ScholarCross RefCross Ref
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Christopher Lutz. 1986. Janus: a time-reversible language. ( 1986 ). Letter to R. Landauer. Available on: http://tetsuo.jp/ref/ janus.pdf.Google ScholarGoogle Scholar
  37. Saunders Mac Lane. 1998. Categories for the Working Mathematician (second edition ed.). Graduate Texts in Matheematics, Vol. 5. Springer.Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  48. Karl Mazurak, Jianzhou Zhao, and Steve Zdancewic. 2010. Lightweight linear types in system fdegree. In TLDI. ACM, 77-88.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarCross RefCross Ref
  58. Flemming Nielson and Hanne Riis Nielson. 1992. Two-Level Functional Languages. Cambridge University Press. https: //doi.org/10.1017/CBO9780511526572 Google ScholarGoogle ScholarCross RefCross Ref
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Sparcl: a language for partially-invertible computation

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader