Clean Reversible Simulations of Ranking Binary Trees

  • Yuhi Ohkubo
  • Tetsuo YokoyamaEmail author
  • Chishun Kanayama
Part of the Emergence, Complexity and Computation book series (ECC, volume 30)


We propose clean reversible simulations of ranking binary trees and unranking as reversible algorithms for reversible computing systems, which are useful for enumerating and randomly generating binary trees. Algorithms for ranking binary trees and their inverses have been studied since the 1970s. Each of these algorithms can be converted into a reversible simulation by saving all data and control information otherwise lost, and each pair of ranking and unranking reversible programs can be combined to realize a clean reversible simulation by using the Bennett method. However, such a clean reversible simulation requires multiple traversal of the given data and/or intermediate data as well as additional storage proportional to the length of the computation. We show that for Knott’s ranking and unranking algorithms, additional storage usage can be reduced by using the proper assertions of reversible loops in embedded reversible simulations. We also show a clean reversible simulation that involves only one traversal. The running time and memory usage of the proposed clean reversible simulations are asymptotically equivalent to those of the original programs by Knott with intermediate garbage of constant size. In general, the derivation strategy of efficient reversible programs from irreversible ones has not yet been established, and this study can be seen as one of the case studies. All the reversible programs presented in this paper can be run on an interpreter of the reversible programming language Janus.



The authors would like to thank Kota Kimura for insightful comments on an early draft of this paper, and the anonymous reviewers for their helpful and constructive comments. Preliminary versions of this paper were presented at the 33rd Workshop of the Japan Society for Software Science and Technology and the 19th JSSST Workshop on Programming and Programming Languages. This work was supported by JSPS KAKENHI Grant Number JP25730049 and Nanzan University Pache Research Subsidy I-A-2 for the 2017 academic year.


  1. 1.
    Axelsen, H.B., Glück, R.: A simple and efficient universal reversible Turing machine. In: Dediu, A.H., Inenaga, S., Martín-Vide, C. (eds.) Language and Automata Theory and Applications. Lecture Notes in Computer Science, vol. 6638, pp. 117–128. Springer, Berlin (2011).
  2. 2.
    Axelsen, H.B., Glück, R.: What do reversible programs compute? In: Hofmann, M. (ed.) Foundations of Software Science and Computation Structures. Proceedings. Lecture Notes in Computer Science, vol. 6604, pp. 42–56. Springer, Berlin (2011).
  3. 3.
    Axelsen, H.B., Yokoyama, T.: Programming techniques for reversible comparison sorts. In: Feng, X., Park, S. (eds.) Programming Languages and Systems. Lecture Notes in Computer Science, vol. 9458, pp. 407–426. Springer, Berlin (2015).
  4. 4.
    Baker, H.G.: NREVERSAL of fortune — the thermodynamics of garbage collection. In: Bekkers, Y., Cohen, J. (eds.) International Workshop on Memory Management. Proceedings. Lecture Notes in Computer Science, vol. 637, pp. 507–524. Springer, Berlin (1992).
  5. 5.
    Bennett, C.H.: Logical reversibility of computation. IBM J. Res. Dev. 17(6), 525–532 (1973).
  6. 6.
    Bennett, C.H.: Time/space trade-offs for reversible computation. SIAM J. Comput. 18(4), 766–776 (1989).
  7. 7.
    Bennett, C.H., Landauer, R.: The fundamental physical limits of computation. Sci. Am. 253(1), 48–56 (1985)CrossRefGoogle Scholar
  8. 8.
    Burignat, S., Vermeirsch, K., De Vos, A., Thomsen, M.K.: Garbageless reversible implementation of integer linear transformations. In: Glück, R., Yokoyama, T. (eds.) Reversible Computation. Proceedings. Lecture Notes in Computer Science, vol. 7581. Springer, Berlin (2013)Google Scholar
  9. 9.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. The MIT Press, Cambridge (2009)zbMATHGoogle Scholar
  10. 10.
    De Vos, A.: Reversible Computing: Fundamentals, Quantum Computing, and Applications. Wiley-VCH, New York (2010)CrossRefzbMATHGoogle Scholar
  11. 11.
    Early, D., Gao, A., Schellekens, M.: Frugal encoding in reversible \(\cal MOQA\it \): A case study for quicksort. In: Glück, R., Yokoyama, T. (eds.) Reversible Computation. Proceedings. Lecture Notes in Computer Science, vol. 7581, pp. 85–96. Springer, Berlin (2013).
  12. 12.
    Er, M.C.: Enumerating ordered trees lexicographically. The Comput. J. 28(5), 538–542 (1985)CrossRefzbMATHGoogle Scholar
  13. 13.
    Feynman, R.P.: Reversible computation and the thermodynamics of computing (Chapter 5). In: Hey, A.J.G., Allen, R.W. (eds.) Feynman Lectures on Computation, pp. 137–184. Addison-Wesley, Reading (1996)Google Scholar
  14. 14.
    Foster, J.N., Greenwald, M.B., Moore, J.T., Pierce, B.C., Schmitt, A.: Combinators for bi-directional tree transformations: a linguistic approach to the view update problem. ACM Trans. Program. Lang. Syst. 29(3), 1–65 (2007).
  15. 15.
    Frank, M.P.: Reversibility for efficient computing. Ph.D. thesis, Massachusetts Institute of Technology (1999)Google Scholar
  16. 16.
    Fredkin, E., Toffoli, T.: Conservative logic. Int. J. Theor. Phys. 21, 219–253 (1982).
  17. 17.
    Glück, R., Kawabe, M.: Derivation of deterministic inverse programs based on LR parsing. In: Kameyama, Y., Stuckey, P.J. (eds.) Functional and Logic Programming. Proceedings. Lecture Notes in Computer Science, vol. 2998, pp. 291–306. Springer, Berlin (2004).
  18. 18.
    Glück, R., Yokoyama, T.: A linear-time self-interpreter of a reversible imperative language. Comput. Softw. 33(3), 108–128 (2016).
  19. 19.
    Gries, D.: Inverting programs. The Science of Programming. Texts and Monographs in Computer Science, pp. 265–274. Springer, Berlin (1981)Google Scholar
  20. 20.
    James, R.P., Sabry, A.: Information effects. Principles of Programming Languages. Proceedings, pp. 73–84. ACM Press (2012).
  21. 21.
    Knott, G.D.: A numbering system for binary trees. Commun. ACM 20(2), 113–115 (1977).
  22. 22.
    Knuth, D.E.: The Art of Computer Programming, Volume 1: Fundamental Algorithms, vol. 1, 3rd edn. Addison-Wesley Professional, Reading (1997)Google Scholar
  23. 23.
    Landauer, R.: Information is physical. Phys. Today 44(5), 23–29 (1991)CrossRefGoogle Scholar
  24. 24.
    Lutz, C.: Janus: A time-reversible language. Letter to R, Landauer (1986)Google Scholar
  25. 25.
    Mogensen, T.Æ.: Garbage-free reversible multipliers for arbitrary constants. ACM J. Emerg. Technol. Comput. Syst. 11(2), 1–18 (2014)CrossRefGoogle Scholar
  26. 26.
    Morita, K.: A simple universal logic element and cellular automata for reversible computing. In: Margenstern, M., Rogozhin, Y. (eds.) Machines, Computations, and Universality. Lecture Notes in Computer Science, vol. 2055, pp. 102–113. Springer, Berlin (2001).
  27. 27.
    Morita, K.: Reversible computing and cellular automata – a survey. Theor. Comput. Sci. 395(1), 101–131 (2008).
  28. 28.
    Morita, K.: Simulating reversible Turing machines and cyclic tag systems by one-dimensional reversible cellular automata. Theor. Comput. Sci. 412(30), 3856–3865 (2011).
  29. 29.
    Nishida, N., Sakai, M., Sakabe, T.: Partial inversion of constructor term rewriting systems. In: Giesl, J. (ed.) Term Rewriting and Applications. Proceedings. Lecture Notes in Computer Science, vol. 3467, pp. 264–278. Springer, Berlin (2005)Google Scholar
  30. 30.
    Perumalla, K.S.: Introduction to Reversible Computing. CRC Press, Boca Raton (2013)Google Scholar
  31. 31.
    Pesu, T., Phillips, I.: Real-Time Methods in Reversible Computation, pp. 45–59. Springer International Publishing, Berlin (2015)Google Scholar
  32. 32.
    Saeedi, M., Markov, I.L.: Synthesis and optimization of reversible circuits — a survey. ACM Comput. Surv. 45(2), 21:1–21:34 (2013).
  33. 33.
    Sprugnoli, R.: The generation of binary trees as a numerical problem. J. ACM 39(2), 317–327 (1992).
  34. 34.
    Thomsen, M.K., Axelsen, H.B., Glück, R.: A reversible processor architecture and its reversible logic design. In: De Vos, A., Wille, R. (eds.) Reversible Computation. Proceedings. Lecture Notes in Computer Science, vol. 7165, pp. 30–42. Springer, Berlin (2012).
  35. 35.
    Vitányi, P.: Time, space, and energy in reversible computing. Computing Frontiers. Proceedings, pp. 435–444. ACM Press (2005).
  36. 36.
    Wille, R., Drechsler, R.: Towards a Design Flow for Reversible Logic. Springer, Berlin (2010)CrossRefzbMATHGoogle Scholar
  37. 37.
    Yokoyama, T., Glück, R.: A reversible programming language and its invertible self-interpreter. Partial Evaluation and Semantics-Based Program Manipulation. Proceedings, pp. 144–153. ACM Press (2007).
  38. 38.
    Yokoyama, T., Axelsen, H.B., Glück, R.: Principles of a reversible programming language. Computing Frontiers. Proceedings, pp. 43–54. ACM Press (2008).
  39. 39.
    Yokoyama, T., Axelsen, H.B., Glück, R.: Optimizing clean reversible simulation of injective functions. J. Multi. Valued Log. Soft Comput. 18(1), 5–24 (2012)zbMATHGoogle Scholar
  40. 40.
    Yokoyama, T., Axelsen, H.B., Glück, R.: Towards a reversible functional language. In: De Vos, A., Wille, R. (eds.) Reversible Computation. Proceedings. Lecture Notes in Computer Science, vol. 7165, pp. 14–29. Springer, Berlin (2012).

Copyright information

© Springer International Publishing AG 2018

Authors and Affiliations

  • Yuhi Ohkubo
    • 1
  • Tetsuo Yokoyama
    • 1
    Email author
  • Chishun Kanayama
    • 1
  1. 1.Department of Software EngineeringNanzan UniversityNagoyaJapan

Personalised recommendations