Dynamic Symbolic Computation for Domain-Specific Language Implementation
Abstract
A domain-specific language (DSL) is a specification language designed to facilitate programming in a certain application domain. A well-designed DSL reflects the natural structure of the modeled domain, enforces abstraction, and its implementation exploits domain-specific properties for safety and performance. Expounding on the latter, in this paper we describe a simple, but powerful method for gradually enhancing a base implementation with computational performance improvements. It consists of adding constructors for expensive operations if this facilitates asymptotic performance improvements in some contexts, with at most constant-factor overhead. The resulting implementation can be thought of as executing “standard” computation steps from the base implementation interleaved with symbolic computation steps on the newly introduced constructors. Evaluation of constructor expressions is lazy in a strong sense: It does not only delay evaluation by thunkifying its standard evaluation, but performs run-time inspection to evaluate constructor expressions in a nonstandard way.
Extending earlier work by Henglein and Larsen [1] on generic multiset programming we arrive at novel multiset representations with constructors for unions, Cartesian products, scalar multiplication, and mapping binary functions over Cartesian products. We show how the resulting implementation can be used to implement finite probability distributions with exact (rational) probabilities. It supports computing both the expected value and, what we believe to be novel, the variance of random variables over n-ary product distributions efficiently by avoiding enumeration of the product sample space.
Keywords
Scalar Multiplication Relational Algebra Functional Programming Symbolic Processing Base ImplementationPreview
Unable to display preview. Download preview PDF.
References
- 1.Henglein, F., Larsen, K.: Generic multiset programming with discrimination-based joins and symbolic Cartesian products. Higher-Order and Symbolic Computation (HOSC) 23, 337–370 (2010); (Publication date: November 24, 2011)MathSciNetMATHCrossRefGoogle Scholar
- 2.Trinder, P., Wadler, P.: List comprehensions and the relational calculus. In: Proc. 1988 Glasgow Workshop on Functional Programming, Rothesay, Scotland, pp. 115–123 (August 1988)Google Scholar
- 3.Peyton Jones, S., Wadler, P.: Comprehensive comprehensions. In: Proc. 2007 Haskell Workshop, Freiburg, Germany (2007)Google Scholar
- 4.Giorgidze, G., Grust, T., Schreiber, T., Weijers, J.: Haskell Boards the Ferry. In: Hage, J., Morazán, M.T. (eds.) IFL 2010. LNCS, vol. 6647, pp. 1–18. Springer, Heidelberg (2011)CrossRefGoogle Scholar
- 5.Peyton Jones, S.: The Haskell 98 language. J. Functional Programming (JFP) 13(1), 0–146 (2003)Google Scholar
- 6.Cheney, J., Hinze, R.: First-class phantom types. CUCIS TR2003-1901, Cornell University (2003)Google Scholar
- 7.Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proc. 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 224–235. ACM (2003)Google Scholar
- 8.Bentley, J.: Programming pearls: Little languages. Commun. ACM 29(8), 711–721 (1986)MathSciNetCrossRefGoogle Scholar
- 9.Hudak, P., Peterson, J., Fasel, J.H.: A gentle introduction to Haskell Version 98. Online Tutorial (May 1999)Google Scholar
- 10.Henglein, F.: Optimizing relational algebra operations using discrimination-based joins and lazy products. In: Proc. ACM SIGPLAN 2010 Workshop on Partial Evaluation and Program Manipulation, January 18-19, pp. 73–82. ACM, New York (2010); Also DIKU TOPPS D-report no. 611CrossRefGoogle Scholar
- 11.Henglein, F., Larsen, K.: Generic multiset programming for language-integrated querying. In: Proceedings of the 6th ACM SIGPLAN Workshop on Generic Programming (WGP), pp. 49–60. ACM (2010)Google Scholar
- 12.Henglein, F.: Generic top-down discrimination for sorting and partitioning in linear time. Invited Submission to Journal of Functional Programming (JFP) (December 2010)Google Scholar
- 13.Selinger, P.G., Astrahan, M.M., Chamberlin, D.D., Lorie, R.A., Price, T.G.: Access path selection in a relational database management system. In: Proc. 1979 ACM SIGMOD Int’l. Conf. on Management of Data, SIGMOD 1979, pp. 23–34. ACM, New York (1979)CrossRefGoogle Scholar
- 14.Hughes, J.: Generalising monads to arrows. Science of Computer Programming 37(1-3), 67–111 (2000)MathSciNetMATHCrossRefGoogle Scholar
- 15.Boehm, H.J., Atkinson, R., Plass, M.: Ropes: An alternative to strings. Software: Practice and Experience 25(12), 1315–1330 (1995)CrossRefGoogle Scholar
- 16.Meertens, L.: Algorithmics–towards programming as a mathematical activity. In: Proc. CWI Symp. on Mathematics and Computer Science, pp. 289–334. North-Holland (1986)Google Scholar
- 17.Bird, R.: An introduction to the theory of lists. Technical Report PRG-56, Oxford University (October 1986)Google Scholar
- 18.Backhouse, R.: An exploration of the Bird-Meertens formalism. In: STOP Summer School on Constructive Algorithmics (1989)Google Scholar
- 19.Meijer, E., Fokkinga, M., Paterson, R.: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)CrossRefGoogle Scholar
- 20.Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1998)CrossRefGoogle Scholar
- 21.Hughes, J.: A novel representation of lists and its application to the function “reverse”. Information Processing Letters 22, 141–144 (1986)CrossRefGoogle Scholar
- 22.Kühnemann, A., Glück, R., Kakehi, K.: Relating Accumulative and Non-accumulative Functional Programs. In: Middeldorp, A. (ed.) RTA 2001. LNCS, vol. 2051, pp. 154–168. Springer, Heidelberg (2001)CrossRefGoogle Scholar
- 23.Voigtländer, J.: Concatenate, reverse and map vanish for free. In: Proc. Int’l. Conf. on Functional Programming (ICFP), Pittsburgh, PA, pp. 14–25 (2002)Google Scholar
- 24.Wadler, P.: The concatenate vanishes. Unpublished manuscript (December 1987) (revised November 1989)Google Scholar
- 25.Gill, A., Launchbury, J., Jones, S.P.: A short cut to deforestation. In: Proceedings of Functional Programming Languages and Computer Architecture (FPCA), pp. 223–232. ACM Press (1993)Google Scholar
- 26.Coutts, D., Leshchinskiy, R., Stewart, D.: Stream fusion: from lists to streams to nothing at all. In: Hinze, R., Ramsey, N. (eds.) ICFP, pp. 315–326. ACM (2007)Google Scholar
- 27.Axelsson, E., Claessen, K., Dévai, G., Horváth, Z., Keijzer, K., Lyckegard, B., Persson, A., Sheeran, M., Svenningsson, J., Vajdax, A.: Feldspar: A domain specific language for digital signal processing algorithms. In: Proc. 8th IEEE/ACM Int’l. Conf. on Formal Methods and Models for Codesign (MEMOCODE), pp. 169–178. IEEE (2010)Google Scholar
- 28.Chakravarty, M., Keller, G., Lee, S., McDonell, T., Grover, V.: Accelerating Haskell array codes with multicore GPUs. In: Proc. 6th Workshop on Declarative Aspects of Multicore Programming (DAMP), pp. 3–14. ACM (2011)Google Scholar
- 29.Keller, G., Chakravarty, M., Leshchinskiy, R., Peyton Jones, S., Lippmeier, B.: Regular, shape-polymorphic, parallel arrays in Haskell. ACM SIGPLAN Notices 45(9), 261–272 (2010)CrossRefGoogle Scholar
- 30.Emoto, K., Fischer, S., Hu, Z.: Generate, Test, and Aggregate —a Calculation-Based Framework for Systematic Parallel Programming with MapReduce. In: Seidl, H. (ed.) ESOP 2012. LNCS, vol. 7211, pp. 254–273. Springer, Heidelberg (2012)CrossRefGoogle Scholar
- 31.Ramsey, N., Pfeffer, A.: Stochastic lambda calculus and monads of probability distributions. ACM SIGPLAN Notices 37(1), 154–165 (2002)CrossRefGoogle Scholar
- 32.Dechter, R.: Bucket elimination: A unifying framework for probabilistic inference. NATO ASI Series D, Behavioural and Social Sciences 89, 75–104 (1998)Google Scholar
- 33.Erwig, M., Kollmansberger, S.: Probabilistic functional programming in Haskell (functional pearl). J. Functional Programming 16(01), 21–34 (2006)MATHCrossRefGoogle Scholar
- 34.Larsen, K.F.: Memory efficient implementation of probability monads. Unpublished manuscript (August 2011)Google Scholar
- 35.Kiselyov, O., Shan, C.-C.: Embedded Probabilistic Programming. In: Taha, W.M. (ed.) DSL 2009. LNCS, vol. 5658, pp. 360–384. Springer, Heidelberg (2009)CrossRefGoogle Scholar
- 36.Park, S., Pfenning, F., Thrun, S.: A probabilistic language based on sampling functions. ACM TOPLAS 31(1), 4 (2008)CrossRefGoogle Scholar
- 37.Mogensen, T.: Troll, a language for specifying dice-rolls. In: Proc. 2009 ACM Symp. on Applied Computing (SAC), pp. 1910–1915. ACM (2009)Google Scholar
- 38.Bhat, S., Agarwal, A., Vuduc, R., Gray, A.: A type theory for probability density functions. In: Proc. 39th SIGACT-SIGPLAN Symp. on Principles of Programming Languages (POPL). ACM press (January 2012)Google Scholar
- 39.Grust, T., Sakr, S., Teubner, J.: XQuery on SQL hosts. In: Proc. 30th Int’l. Conf. on Very Large Bata Bases, vol. 30, p. 263 (2004)Google Scholar
- 40.Grust, T.: Purely relational FLWORs. In: Proc. XIME-P (2005)Google Scholar
- 41.Grust, T., Rittinger, J., Schreiber, T.: Avalanche-safe LINQ compilation. Proc. VLDB Endow 3, 162–172 (2010)Google Scholar
- 42.Swierstra, W.: Data types à la carte. J. Functional Programming 18(4), 423–436 (2008)MathSciNetMATHCrossRefGoogle Scholar
- 43.Bahr, P., Hvitved, T.: Compositional data types. In: Proc. 7th ACM SIGPLAN Workshop on Generic Programming (WGP), pp. 83–94. ACM (2011)Google Scholar
- 44.Bahr, P., Hvitved, T.: Parametric compositional data types. In: Proc. Mathematically Structured Functional Programming, MSFP (2012)Google Scholar
- 45.Clavel, M., Durán, F., Eker, S., Lincoln, P., Martí-Oliet, N., Meseguer, J., Quesada, J.: Maude: Specification and programming in rewriting logic. Theoretical Computer Science 285(2), 187–243 (2002)MathSciNetMATHCrossRefGoogle Scholar