Skip to main content
Log in

Functional programs as compressed data

  • Published:
Higher-Order and Symbolic Computation

Abstract

We propose an application of programming language techniques to lossless data compression, where tree data are compressed as functional programs that generate them. This “functional programs as compressed data” approach has several advantages. First, it follows from the standard argument of Kolmogorov complexity that the size of compressed data can be optimal up to an additive constant.

Secondly, a compression algorithm is clean: it is just a sequence of β-expansions (i.e., the inverse of β-reductions) for λ-terms. Thirdly, one can use program verification and transformation techniques (higher-order model checking, in particular) to apply certain operations on data without decompression. In this article, we present algorithms for data compression and manipulation based on the approach, and prove their correctness. We also report preliminary experiments on prototype data compression/transformation systems.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4

Similar content being viewed by others

Notes

  1. Fibonacci words and its generalization called Sturmian words have been studied in a field called Stringology [8].

  2. It may also make sense to choose the smallest one instead.

  3. Strictly speaking, as our language does not have deconstructors for tree constructors a 1,…,a n dom(Σ), we need to transform M into M′ a 1 ⋯ a n where M′ is a pure λ-term, and then transform it into fM′ a 1 ⋯ a n .

  4. http://corpus.canterbury.ac.nz/descriptions/large/E.coli.html.

  5. http://prize.hutter1.net/.

References

  1. Apostolico, A., Lonardi, S.: Some theory and proactive of greedy off-line textual substitution. In: Data Compression Conference 1998 (DCC98), pp. 119–128 (1998)

    Google Scholar 

  2. Barendregt, H., Coppo, M., Dezani-Ciancaglini, M.: A filter lambda model and the completeness of type assignment. J. Symb. Log. 48(4), 931–940 (1983)

    Article  MATH  MathSciNet  Google Scholar 

  3. Broadbent, C.H., Carayol, A., Ong, C.-H.L., Serre, O.: Recursion schemes and logical reflection. In: Proceedings of LICS 2010, pp. 120–129. IEEE Computer Society Press, Los Alamitos (2010)

    Google Scholar 

  4. Busatto, G., Lohrey, M., Maneth, S.: Efficient memory representation of XML document trees. Inf. Syst. 33(4–5), 456–474 (2008)

    Article  Google Scholar 

  5. Charikar, M., Lehman, E., Liu, D., Panigrahy, R., Prabhakaran, M., Sahai, A., Shelat, A.: The smallest grammar problem. IEEE Trans. Inf. Theory 51(7), 2554–2576 (2005)

    Article  MATH  MathSciNet  Google Scholar 

  6. Church, A.: The calculi of lambda-conversion. In: Annals of Mathematics Studies, vol. 6. Princeton University Press, Princeton (1941)

    Google Scholar 

  7. Comon, H., Dauchet, M., Gilleron, R., Löding, C., Jacquemard, F., Lugiez, D., Tison, S., Tommasi, M.: Tree automata techniques and applications (2007). Available on http://www.grappa.univ-lille3.fr/tata. Release October, 12th 2007

  8. Crochemore, M., Rytter, W.: Jewels of Stringology. World Scientific, Singapore (2002)

    Book  Google Scholar 

  9. Dam, W.: The IO- and OI-hierarchies. Theor. Comput. Sci. 20, 95–207 (1982)

    Article  Google Scholar 

  10. Engelfriet, J.: Bottom-up and top-down tree transformations—a comparison. Math. Syst. Theory 9(3), 198–231 (1975)

    Article  MATH  MathSciNet  Google Scholar 

  11. Engelfriet, J., Rozenberg, G., Slutzki, G.: Tree transducers, L systems, and two-way machines. J. Comput. Syst. Sci. 20(2), 150–202 (1980)

    Article  MATH  MathSciNet  Google Scholar 

  12. Engelfriet, J., Vogler, H.: High level tree transducers and iterated pushdown tree transducers. Acta Inform. 26(1/2), 131–192 (1988)

    Article  MATH  MathSciNet  Google Scholar 

  13. Gill, A.J., Launchbury, J., Peyton-Jones, S.L.: A short cut to deforestation. In: FPCA, pp. 223–232 (1993)

    Chapter  Google Scholar 

  14. Hague, M., Murawski, A., Ong, C.-H.L., Serre, O.: Collapsible pushdown automata and recursion schemes. In: Proceedings of LICS 2008, pp. 452–461. IEEE Computer Society, Los Alamitos (2008)

    Google Scholar 

  15. Hutter, M.: Universal Artificial Intelligence: Sequential Decisions Based on Algorithmic Probability. Springer, Berlin (2004)

    Google Scholar 

  16. Kaji, H., Kida, Y., Morimoto, Y.: Learning translation templates from bilingual text. In: COLING, pp. 672–678 (1992)

    Google Scholar 

  17. Karpinski, M., Rytter, W., Shinohara, A.: An efficient pattern matching algorithm for strings with short description. Nord. J. Comput. 4(2), 129–144 (1997)

    MathSciNet  Google Scholar 

  18. Kida, T., Matsumoto, T., Shibata, Y., Takeda, M., Shinohara, A., Arikawa, S.: Collage system: a unifying framework for compressed pattern matching. Theor. Comput. Sci. 1(298), 253–272 (2003)

    Article  MathSciNet  Google Scholar 

  19. Knapik, T., Niwinski, D., Urzyczyn, P.: Higher-order pushdown trees are easy. In: Proceedings of FOSSACS 2002. Lecture Notes in Computer Science, vol. 2303, pp. 205–222. Springer, Berlin (2002)

    Google Scholar 

  20. Kobayashi, N.: Model-checking higher-order functions. In: Proceedings of PPDP 2009, pp. 25–36. ACM Press, New York (2009)

    Google Scholar 

  21. Kobayashi, N.: Types and higher-order recursion schemes for verification of higher-order programs. In: Proceedings of ACM SIGPLAN/SIGACT Symposium on Principles of Programming Languages (POPL), pp. 416–428 (2009)

    Google Scholar 

  22. Kobayashi, N.: A practical linear time algorithm for trivial automata model checking of higher-order recursion schemes. In: Proceedings of FOSSACS 2011. Lecture Notes in Computer Science, vol. 6604, pp. 260–274. Springer, Berlin (2011)

    Google Scholar 

  23. Kobayashi, N.: Model checking higher-order programs. J. ACM 60(3) (2013)

  24. Kobayashi, N., Matsuda, K., Shinohara, A.: Functional programs as compressed data. In: Proceedings of PEPM 2012, pp. 121–130. ACM Press, New York (2012)

    Google Scholar 

  25. Kobayashi, N., Ong, C.-H.L.: A type system equivalent to the modal mu-calculus model checking of higher-order recursion schemes. In: Proceedings of LICS 2009, pp. 179–188. IEEE Computer Society Press, Los Alamitos (2009)

    Google Scholar 

  26. Kobayashi, N., Ong, C.-H.L.: Complexity of model checking recursion schemes for fragments of the modal mu-calculus. Logical Methods in Computer Science 7(4) (2011)

  27. Larsson, N.J., Moffat, A.: Offline dictionary-based compression. In: Proc. Data Compression Conference ’99 (DCC’99), pp. 296–305. IEEE Computer Society, Los Alamitos (1999)

    Google Scholar 

  28. Li, M., Vitányi, P.M.B.: Kolmogorov complexity and its applications. In: Handbook of Theoretical Computer Science, vol. A: Algorithms and Complexity, pp. 187–254. MIT Press, Cambridge (1990)

    Google Scholar 

  29. Li, M., Vitányi, P.M.B.: An Introduction to Kolmogorov Complexity and Its Applications, 3rd edn. Texts in Computer Science Springer, Berlin (2009)

    Google Scholar 

  30. Lohrey, M., Maneth, S., Mennicke, R.: Tree structure compression with repair. In: Data Compression Conference (DCC 2011), pp. 353–362. IEEE Computer Society, Los Alamitos (2011)

    Chapter  Google Scholar 

  31. Maneth, S., Busatto, G.: Tree transducers and tree compressions. In: Proceedings of FOSSACS 2004. Lecture Notes in Computer Science, vol. 2987, pp. 363–377. Springer, Berlin (2004)

    Google Scholar 

  32. Matsubara, W., Inenaga, S., Ishino, A., Shinohara, A., Nakamura, T., Hashimoto, K.: Efficient algorithms to compute compressed longest common substrings and compressed palindromes. Theor. Comput. Sci. 410(8–10), 900–913 (2009)

    Article  MATH  MathSciNet  Google Scholar 

  33. Nevill-Manning, C.G., Witten, I.H.: Compression and explanation using hierarchical grammars. Comput. J. 40(2/3), 103–116 (1997)

    Article  Google Scholar 

  34. Ong, C.-H.L.: On model-checking trees generated by higher-order recursion schemes. In: LICS 2006, pp. 81–90. IEEE Computer Society Press, Los Alamitos (2006)

    Google Scholar 

  35. Plandowski, W.: Testing equivalence of morphisms on context-free languages. In: ESA’94. Lecture Notes in Computer Science, vol. 855, pp. 460–470. Springer, Berlin (1994)

    Google Scholar 

  36. Rytter, W.: Application of Lempel-Ziv factorization to the approximation of grammar-based compression. Theor. Comput. Sci. 302(1–3), 211–222 (2003)

    Article  MATH  MathSciNet  Google Scholar 

  37. Rytter, W.: Grammar compression, LZ-encodings, and string algorithms with implicit input. In: ICALP’04. Lecture Notes in Computer Science, vol. 3142, pp. 15–27. Springer, Berlin (2004)

    Google Scholar 

  38. Sakamoto, H.: A fully linear-time approximation algorithm for grammar-based compression. J. Discrete Algorithms 3(2–4), 416–430 (2005)

    Article  MATH  MathSciNet  Google Scholar 

  39. Sakamoto, H., Maruyama, S., Kida, T., Shimozono, S.: A space-saving approximation algorithm for grammar-based compression. IEICE Trans. Inf. Syst. E 92-D(2), 158–165 (2009)

    Article  Google Scholar 

  40. Somers, H.L.: Review article: example-based machine translation. Mach. Transl. 14(2), 113–157 (1999)

    Article  MathSciNet  Google Scholar 

  41. Statman, R.: The typed lambda-calculus is not elementary recursive. Theor. Comput. Sci. 9, 73–81 (1979)

    Article  MATH  MathSciNet  Google Scholar 

  42. Stirling, C.: Decidability of higher-order matching. Log. Methods Comput. Sci. 5(3) (2009)

  43. Storer, J.: NP-completeness results concerning data compression. Technical Report 234, Department of Electrical Engineering and Computer Science, Princeton University, Princeton, NJ (1997)

  44. Takano, A., Meijer, E.: Shortcut deforestation in calculational form. In: Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, FPCA’95, pp. 306–313. ACM, New York (1995)

    Chapter  Google Scholar 

  45. Terui, K.: Semantic evaluation, intersection types and complexity of simply typed lambda calculus. In: 23rd International Conference on Rewriting Techniques and Applications (RTA’12). LIPIcs, vol. 15, pp. 323–338. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik (2012)

    Google Scholar 

  46. Tozawa, A.: XML type checking using high-level tree transducer. In: Functional and Logic Programming, 8th International Symposium (FLOPS 2006). Lecture Notes in Computer Science, vol. 3945, pp. 81–96. Springer, Berlin (2006)

    Chapter  Google Scholar 

  47. Tromp, J.: Binary lambda calculus and combinatory logic. In: Claude, C.S. (ed.) Randomness and Complexity, from Leibniz to Chaitin, pp. 237–260. World Scientific, Singapore (2008)

    Google Scholar 

  48. Tsukada, T., Kobayashi, N.: Untyped recursion schemes and infinite intersection types. In: Proceedings of FOSSACS 2010. Lecture Notes in Computer Science, vol. 6014, pp. 343–357. Springer, Berlin (2010)

    Google Scholar 

  49. van Bakel, S.: Complete restrictions of the intersection type discipline. Theor. Comput. Sci. 102(1), 135–163 (1992)

    Article  MATH  Google Scholar 

  50. van Bakel, S.: Intersection type assignment systems. Theor. Comput. Sci. 151(2), 385–435 (1995)

    Article  MATH  Google Scholar 

  51. Vytiniotis, D., Kennedy, A.: Functional pearl: every bit counts. In: Proceedings of ICFP 2010, pp. 15–26 (2010)

    Google Scholar 

Download references

Acknowledgements

We would like to thank Oleg Kiselyov, Tatsunari Nakajima, Kunihiko Sadakane, John Tromp, and anonymous referees for discussions and useful comments. This work was partially supported by Kakenhi 23220001.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Naoki Kobayashi.

Additional information

A preliminary summary of this article appeared in Proceedings of PEPM 2012, pp. 121–130, 2012.

Appendix: Proofs for Sect. 2

Appendix: Proofs for Sect. 2

In this section, we shall prove the following lemma, which corresponds to the “only if” direction of Theorem 1.

Lemma 11

If ∅⊢M:o, then there exists a tree T such that \(M\longrightarrow ^{*}_{\beta}T\).

As sketched in the proof of Theorem 1, the lemma follows from more or less standard properties of intersection types [2, 50]. Nevertheless, we provide a self-contained proof of Lemma 11 below to familiarize readers with the type-based transformation techniques used in Sect. 4.2.

We prove the lemma by using the strong normalization of the simply-typed λ-calculus. To this end, we define a type-based transformation relation ΓM:τN, which transforms a well-typed λ-term M (in the intersection type system) into a corresponding term N of the simply-typed λ-calculus. It is defined by the following extension of typing rules.

figure l

Here, we assume that the simply-typed λ-calculus has a base type ⋆(≠o), inhabited by ( ). The idea of the translation to the simply-typed λ-calculus is to replicate each function argument according to its type. Thus, we replicate a formal parameter x to \(x_{\tau_{1}},\ldots,x_{\tau_{n}}\) in rule STr-Abs above, and accordingly duplicate an actual parameter M 2 to N 2,1,…,N 2,n in rule STr-App. The dummy formal (actual, resp.) parameter x (( ), resp.) is added in STr-AbsT (STr-AppT, resp.) to enforce that the transformation preserves the “shape” of a term. Note that without the dummy parameter, an application M 1 M 2 would be transformed to a term of arbitrary shape (when n=0 in STr-AppT).

We first show that the result of the transformation is simply-typed. We write Γ ST N:κ for the standard type judgment relation for the simply-typed λ-calculus, where the syntax of types are generated by

$$\kappa::= \mathtt {o}\mid \star \mid\kappa_1 \rightarrow \kappa_2. $$

We define the translation ⋅ from intersection types to simple types by:

$$\begin{aligned} &{ \mathtt {o}}^\dagger = \mathtt {o}\qquad {(\top \rightarrow \tau)}^\dagger = \star \rightarrow {\tau}^\dagger \\ &{(\tau_1\land\cdots\land\tau_k \rightarrow \tau)}^\dagger = {\tau_1}^\dagger \rightarrow \cdots \rightarrow {\tau_k}^\dagger \rightarrow {\tau}^\dagger \mbox{(if $k\geq1$)}. \end{aligned}$$

We extend the translation to type environments by:

$${\varGamma}^\dagger = \{x_{\tau} \mathbin {:}{\tau}^\dagger \mid x\mathbin {:}\tau\in \varGamma\}. $$

We assume that \(x_{\tau} = x'_{\tau'}\) if and only if x=x′ and τ=τ′ so that Γ is a simple type environment.

Lemma 12

If ΓM:κN, then Γ ST N:κ .

Proof

This follows by straightforward induction on the derivation of ΓM:κN. □

Lemma 13

Suppose \(x\not\in \mathit {dom}(\varGamma)\). If Γ,x:τ 1,…,x:τ k M:τN and ΓK:τ i N i for each i∈{1,…,k}, then \(\varGamma \vdash [K/x]M:\tau \Longrightarrow [N_{1}/x_{\tau_{1}},\ldots,N_{k}/x_{\tau_{k}}]N\).

Proof

This follows by induction on the structure of M.

  • Case M=x: In this case, \(N= x_{\tau_{i}}\) and τ=τ i for some i∈{1,…,k}. The result follows immediately from ΓK:τ i N i .

  • Case M=y(≠x): In this case, we have y:τΓ and N=y τ . Thus, [K/x]M=y and \([N_{1}/x_{\tau_{1}},\ldots,N_{k}/x_{\tau_{k}}]N=y_{\tau}\). By using STr-Var, we have \(\varGamma \vdash [K/x]M:\tau \Longrightarrow [N_{1}/x_{\tau_{1}},\ldots,N_{k}/x_{\tau_{k}}]N\) as required.

  • Case M=a: The result follows immediately, as M=N=a and τ=o Σ(a)o.

  • Case M=λy.M 0: We can assume that yx without loss of generality. By the assumption, we have:

    $$\begin{array}{l} \varGamma,y\mathbin {:}\tau'_1,\ldots,y\mathbin {:}\tau'_\ell \vdash M_0:\tau' \Longrightarrow N_0\\ (\ell\geq1\land N = \lambda y_{\tau'_1}.\cdots\lambda y_{\tau'_\ell }.N_0) \lor(\ell=0\land N = \lambda y_{\star }.N_0)\\ \tau= \tau'_1\land\cdots\land\tau'_\ell \rightarrow \tau' \end{array} $$

    By the induction hypothesis, we have \(\varGamma,y\mathbin {:}\tau_{1},\ldots,y\mathbin {:}\tau_{\ell} \vdash [K/x]M_{0}:\tau' \Longrightarrow [N_{1}/x_{\tau_{1}},\ldots, N_{k}/x_{\tau_{k}}]N_{0}\). By applying STr-Abs or STr-AbsT, we obtain Γ⊢[K/x]M:τN as required.

  • Case M=M 1 M 2: By the assumption, we have:

    $$\begin{array}{l} \varGamma \vdash M_1:\tau'_1\land\cdots\land\tau'_\ell \rightarrow \tau \Longrightarrow N_1'\\ \varGamma \vdash M_2:\tau'_i \Longrightarrow N_{2,i} \mbox{ for each $i\in \{1,\ldots,\ell\}$}\\ (\ell\geq1 \land N = N'_1\, N_{2,1} \cdots N_{2,k})\lor(\ell=0\land N = N'_1\,(\,)) \end{array} $$

    By the induction hypothesis, we have:

    $$\begin{array}{l} \varGamma \vdash [K/x]M_1:\tau_1\land\cdots \land\tau_k\rightarrow \tau \Longrightarrow [N_1/x_{\tau_1},\ldots,N_k/x_{\tau_k}]N'_1\\ \varGamma \vdash [K/x]M_2:\tau_i \Longrightarrow [N_1/x_{\tau_1},\ldots,N_k/x_{\tau_k}]N_{2,i} \mbox{ for each $i\in \{1,\ldots,k\}$}\\ \end{array} $$

    By applying STr-App or STr-AppT, we obtain \(\varGamma \vdash [K/x]M:\tau \Longrightarrow [N_{1}/x_{\tau _{1}},\ldots, N_{k}/x_{\tau_{k}}]N\) as required. □

The following is a special case of Lemma 13 above, where k=0.

Corollary 1

If \(x\not\in \mathit {dom}(\varGamma)\) and ΓM:τN, then Γ⊢[K/x]M:τN holds for any K.

We are now ready to show the main lemmas (Lemmas 14 and 15 below), which say that if ΓM:τN, then reductions of M and N can be simulated by each other.

Lemma 14

If ΓM:τN and M β M′, then there exists Nsuch that ΓM′:τNwith \(N\longrightarrow ^{*}_{\beta}N'\).

Proof

This follows by easy induction on the derivation of ΓM:τN. We omit details as the proof is similar to that of Lemma 5 in Sect. 4.2.1. □

Lemma 15

If ΓM:τN and N β N′, then there exist Mand Nsuch that ΓM′:τNwith \(M\longrightarrow ^{*}_{\beta}M'\) and \(N'\longrightarrow ^{*}_{\beta}N''\).

Proof

The proof proceeds by induction on derivation of ∅⊢M:τN, with case analysis on the last rule used. By the assumption N β N′, the last rule cannot be ST-Var or ST-Const.

  • Case STr-Abs: In this case, we have:

    $$\begin{array}{l} \varGamma,x\mathbin {:}\tau_1,\ldots,x\mathbin {:}\tau_k \vdash M_1\mathbin {:}\tau'\Longrightarrow N_1\\ M = \lambda x.M_1\qquad N = \lambda x_{\tau_1}.\cdots\lambda x_{\tau _k}.N_1\qquad N' = \lambda x_{\tau_1}.\cdots\lambda x_{\tau_k}.N_1'\\ N_1 \longrightarrow _\beta N_1'\\ \tau= \tau_1\land\cdots\land\tau_k\rightarrow \tau' \end{array} $$

    By the induction hypothesis, we have \(M_{1}'\) and \(N_{1}''\) such that \(\varGamma,x\mathbin {:}\tau_{1},\ldots,x\mathbin {:}\tau_{k} \vdash M_{1}'\mathbin {:}\tau'\Longrightarrow N_{1}''\) with \(M_{1}\longrightarrow ^{*}_{\beta}M_{1}'\) and \(N_{1}'\longrightarrow ^{*}_{\beta}N_{1}''\). Thus, the required properties hold for \(M'=\lambda x.M_{1}'\) and \(N'' = \lambda x_{\tau_{1}}.\cdots\lambda x_{\tau_{k}}.N_{1}'\).

  • Case STr-AbsT: Similar to the case STr-Abs.

  • Case STr-App: In this case, we have:

    $$\begin{array}{l} \varGamma \vdash M_1:\tau_1\land\cdots\land\tau_k\rightarrow \tau \Longrightarrow N_1\quad (k\geq1)\\ \varGamma \vdash M_2: \tau_i\Longrightarrow N_{2,i} \mbox{ for each $i\in \{1,\ldots ,k\}$}\\ M = M_1M_2\qquad N = N_1\, N_{2,1}\cdots N_{2,k}\\ \end{array} $$

    By the assumption \(N\longrightarrow ^{*}_{\beta}N'\), there are three cases to consider:

    1. (1)

      \(N_{1}\longrightarrow ^{*}_{\beta}N_{1}'\) with \(N'=N_{1}'\, N_{2,1}\cdots N_{2,k}\).

    2. (2)

      \(N_{2,j}\longrightarrow ^{*}_{\beta}N_{2,j}\) with \(N'=N_{1}\,N_{2,1}\cdots N_{2,j-1}\,N'_{2,j}\,N_{2,j+1}\cdots N_{2,k}\).

    3. (3)

      \(N_{1} = \lambda x.N_{1}'\) with \(N' = ([N_{2,1}/x]N_{1}') N_{2,2}\cdots N_{2,k}\).

    The result for case (1) follows immediately from the induction hypothesis. In case (2), by the induction hypothesis, we have \(\varGamma \vdash M'_{2}:\tau_{j}\Longrightarrow N''_{2,j}\) with \(M_{2}\longrightarrow ^{*}_{\beta}M_{2}'\) and \(N'_{2,j}\longrightarrow ^{*}_{\beta}N''_{2,j}\) for some \(M'_{2}\) and \(N''_{2,j}\). By Lemma 14, for each i∈{1,…,k}∖{j}, there exists \(N''_{2,i}\) such that \(\varGamma \vdash M'_{2}:\tau_{i}\Longrightarrow N''_{2,i}\) and \(N_{2,i}\longrightarrow ^{*}_{\beta}N''_{2,i}\). Let \(M' = M_{1}M'_{2}\) and \(N''=N_{1} N''_{2,1}\cdots N''_{2,k}\). Then we have ΓM′:τN″ with \(M\longrightarrow ^{*}_{\beta}M'\) and \(N'\longrightarrow ^{*}_{\beta}N''\) as required.

    In case (3), by the transformation rules, ΓM 1:τ 1∧⋯∧τ k τN 1 must have been derived from STr-Abs, so that we have:

    $$\begin{array}{l} M_1 = \lambda y.M_3\\ \varGamma,y\mathbin {:}\tau_1,\ldots,y\mathbin {:}\tau_k \vdash M_3:\tau \Longrightarrow N_3\\ (\lambda x.N_1') = (\lambda y_{\tau_1}.\cdots\lambda y_{\tau_k}.N_3) \end{array} $$

    Let M′=[M 2/x]M 3 and \(N''=[N_{2,1}/y_{\tau_{1}},\ldots ,N_{2,k}/y_{\tau_{k}}]N_{3}\). Then we have \(M\longrightarrow ^{*}_{\beta}M'\) and \(N'\longrightarrow ^{*}_{\beta}N''\). Furthermore, by Lemma 13, we have ΓM′:τN″ as required.

  • Case STr-AppT: In this case, we have:

    $$\begin{array}{l} \varGamma \vdash M_1:\top \Longrightarrow N_1\\ M = M_1M_2\qquad N = N_1\, (\,)\\ \end{array} $$

    By the assumption \(N\longrightarrow ^{*}_{\beta}N'\), there are two cases to consider:

    1. (1)

      \(N_{1}\longrightarrow ^{*}_{\beta}N_{1}'\) with \(N'=N_{1}'\, (\,)\).

    2. (2)

      \(N_{1} = \lambda x.N_{1}'\) with \(N' = [(\,)/x]N_{1}'\).

    The result for case (1) follows immediately from the induction hypothesis. In case (2), ΓM 1:⊤τN 1 must have been derived from STr-AbsT, so that we have:

    $$\begin{array}{l} M_1 = \lambda x.M_3\qquad \varGamma \vdash M_3: \tau \Longrightarrow N_1'\qquad x\not\in \mathit {dom}(\varGamma) \end{array} $$

    By Lemma 12, we have \({\varGamma}^{\dagger} \vdash _{\mathtt {ST}}N_{1}'\), so that x does not occur in \(N_{1}'\). Thus, \(N' = [(\,)/x]N_{1}' = N_{1}'\). Let M′ be [M 2/x]M 3 and N″ be N′. Then we have \(M\longrightarrow ^{*}_{\beta}M'\) and \(N'\longrightarrow ^{*}_{\beta}N''\). Furthermore, by Lemma 1 we have ΓM′:τN″ as required. □

Lemma 16

If ∅⊢M:oN and N is a β-normal form, then M is a tree and M=N.

Proof

The proof proceeds by induction on the structure of N. By Lemma 12, we have ∅⊢N:o. Since N does not contain any β-redex, N must be of the form aN 1 ⋯ N k , where k may be 0. By the transformation rules, we have:

$$\begin{array}{l} M = a\,M_{1}\,\cdots\,M_{k}\\ \varSigma(a)=k\\ \emptyset \vdash M_i:\mathtt {o}\Longrightarrow N_i \mbox{ for each $i\in \{1,\ldots,k\}$} \end{array} $$

By the induction hypothesis, M i is a tree and M i =N i . Thus, M is also a tree and M=N as required. □

We are now ready to prove Lemma 11.

Proof of Lemma 11

If ∅⊢M:o, then by the transformation rules, there exists N such that ∅⊢M:oN. By Lemma 12, we have ∅⊢ ST N:o. By the strong normalization property of the simply-typed λ-calculus, there exists a β-normal form N′ such that \(N\longrightarrow ^{*}_{\beta}N'\). By Lemma 15, there exists M′ such that \(M\longrightarrow ^{*}_{\beta}M'\) and ∅⊢M′:oN′. By Lemma 16, M′ is a tree. □

Rights and permissions

Reprints and permissions

About this article

Cite this article

Kobayashi, N., Matsuda, K., Shinohara, A. et al. Functional programs as compressed data. Higher-Order Symb Comput 25, 39–84 (2012). https://doi.org/10.1007/s10990-013-9093-z

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-013-9093-z

Keywords

Navigation