skip to main content
research-article

Constraints as control

Authors Info & Claims
Published:25 January 2012Publication History
Skip Abstract Section

Abstract

We present an extension of Scala that supports constraint programming over bounded and unbounded domains. The resulting language, Kaplan, provides the benefits of constraint programming while preserving the existing features of Scala. Kaplan integrates constraint and imperative programming by using constraints as an advanced control structure; the developers use the monadic 'for' construct to iterate over the solutions of constraints or branch on the existence of a solution. The constructs we introduce have simple semantics that can be understood as explicit enumeration of values, but are implemented more efficiently using symbolic reasoning. Kaplan programs can manipulate constraints at run-time, with the combined benefits of type-safe syntax trees and first-class functions. The language of constraints is a functional subset of Scala, supporting arbitrary recursive function definitions over algebraic data types, sets, maps, and integers.

Our implementation runs on a platform combining a constraint solver with a standard virtual machine. For constraint solving we use an algorithm that handles recursive function definitions through fair function unrolling and builds upon the state-of-the art SMT solver Z3. We evaluate Kaplan on examples ranging from enumeration of data structures to execution of declarative specifications. We found Kaplan promising because it is expressive, supporting a range of problem domains, while enabling full-speed execution of programs that do not rely on constraint programming.

Skip Supplemental Material Section

Supplemental Material

popl_2b_3.mp4

References

  1. H. Aït-Kaci. Warren's Abstract Machine: A Tutorial Reconstruction. MIT Press, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. S. Antoy. Definitional trees. In ALP, pages 143--157, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. S. Antoy and M. Hanus. Functional logic programming. CACM, 53 (4): 74--85, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. K. R. Apt and M. Wallace. Constraint logic programming using Eclipse. Cambridge University Press, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. K. R. Apt, J. Brunekreef, V. Partington, and A. Schaerf. Alma-O: An imperative language that supports declarative programming. TOPLAS, 20 (5): 1014--1066, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R.-J. Back and J. von Wright. Refinement Calculus. Springer-Verlag, 1998.Google ScholarGoogle Scholar
  7. T. Ball, D. Hoffman, F. Ruskey, R. Webber, and L. J. White. State generation and automated class testing. Softw. Test., Verif. Reliab., 10 (3), 2000.Google ScholarGoogle Scholar
  8. C. Barrett and C. Tinelli. CVC3. In CAV, volume 4590 of LNCS, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. G. M. Bierman, A. D. Gordon, C. Hritcu, and D. E. Langworthy. Semantic subtyping with an SMT solver. In ICFP, pages 105--116, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. A. Blass, Y. Gurevich, and D. Kozen. A zero-one law for logic with a fixed-point operator. Inf. Control, 67, October 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Boyapati, S. Khurshid, and D. Marinov. Korat: Automated testing based on Java predicates. In Proc. International Symposium on Software Testing and Analysis, pages 123--133, July 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. B. Braßel, M. Hanus, and M. Müller. High-level database programming in Curry. In PADL, pages 316--332, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. K. Claessen and J. Hughes. Quickcheck: a lightweight tool for random testing of haskell programs. In ICFP, pages 268--279, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Colmerauer, H. Kanoui, and M. V. Caneghem. Last steps towards an ultimate PROLOG. In IJCAI, pages 947--948, 1981. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. R. DeLine and K. R. M. Leino. BoogiePL: A typed procedural language for checking object-oriented programs. Technical Report MSR-TR-2005--70, Microsoft Research, March 2005.Google ScholarGoogle Scholar
  16. B. Demsky and M. C. Rinard. Automatic detection and repair of errors in data structures. In OOPSLA, pages 78--95, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. D. Detlefs, G. Nelson, and J. B. Saxe. Simplify: a theorem prover for program checking. J. ACM, 52 (3): 365--473, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. E. W. Dijkstra. Guarded commands, nondeterminacy and formal derivation of programs. Commun. ACM, 18 (8): 453--457, 1975. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. B. Dutertre and L. \noopsortMourade Moura. The Yices SMT solver, 2006. http://yices.csl.sri.com/tool-paper.pdf.Google ScholarGoogle Scholar
  20. B. Elkarablieh and S. Khurshid. Juzi: a tool for repairing complex data structures. In ICSE, pages 855--858, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Fischer, O. Kiselyov, and C. Shan. Purely functional lazy non-deterministic programming. In ICFP, volume 44, pages 11--22, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. H. Ganzinger, G. Hagen, R. Nieuwenhuis, A. Oliveras, and C. Tinelli. DPLL(T): Fast decision procedures. In CAV, pages 175--188, 2004.Google ScholarGoogle Scholar
  23. I. P. Gent, C. Jefferson, and I. Miguel. MINION: A fast, scalable, constraint solver. In European Conference on Artificial Intelligence, pages 98--102. IOS Press, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. M. Gligoric, T. Gvero, V. Jagannath, S. Khurshid, V. Kuncak, and D. Marinov. Test generation through programming in udita. In ICSE (1), pages 225--234, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. M. Grabmüller and P. Hofstedt. Turtle: A constraint imperative programming language. In Innovative Techniques and Applications of Artificial Intelligence, 2003.Google ScholarGoogle Scholar
  26. S. Gulwani, S. Jha, A. Tiwari, and R. Venkatesan. Synthesis of loop-free programs. In PLDI, pages 62--73, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. M. Hanus. Type-oriented construction of web user interfaces. In PPDP, pages 27--38, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. M. Hanus and C. Kluß. Declarative programming of user interfaces. In PADL, pages 16--30, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. D. Jackson. Structuring Z specifications with views. ACM Transactions on Software Engineering and Methodology, 4 (4), October 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. D. Jackson. Alloy: a lightweight object modelling notation. ACM Trans. Softw. Eng. Methodol., 11 (2): 256--290, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. J. Jaffar and J.-L. Lassez. Constraint logic programming. In POPL, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. J. C. King. A Program Verifier. PhD thesis, Carnegie Mellon University, 1970. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. A. S. Köksal, V. Kuncak, and P. Suter. Scala to the power of Z3: Integrating SMT and programming (system description). In CADE, pages 400--406, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. R. A. Kowalski and D. Kuehner. Linear resolution with selection function. Artif. Intell., 2 (3/4): 227--260, 1971.Google ScholarGoogle ScholarCross RefCross Ref
  35. V. Kuncak, M. Mayer, R. Piskac, and P. Suter. Complete functional synthesis. In PLDI, pages 316--329, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. L. Lamport. Specifying Systems: The TLAGoogle ScholarGoogle Scholar
  37. Language and Tools for Hardware and Software Engineers. Addison-Wessley, 2002.Google ScholarGoogle Scholar
  38. G. Lopez, B. Freeman-Benson, and A. Borning. Kaleidoscope: A constraint imperative programming language. In Constraint Programming, pages 313--329. Springer-Verlag, 1994.Google ScholarGoogle Scholar
  39. M. Z. Malik, J. H. Siddiqui, and S. Khurshid. Constraint-based program debugging using data structure repair. In ICST, pages 190--199, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Z. Manna and R. Waldinger. A deductive approach to program synthesis. ACM Trans. Program. Lang. Syst., 2 (1): 90--121, 1980. ISSN 0164-0925. http://doi.acm.org/10.1145/357084.357090. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. F. Maric and P. Janicic. Urbiva: Uniform reduction to bit-vector arithmetic. In IJCAR, pages 346--352, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. E. Michael Hanus. Curry: An integrated functional logic language. http://www.curry-language.org, 2006. vers. 0.8.2.Google ScholarGoogle Scholar
  43. A. Milicevic, D. Rayside, K. Yessenov, and D. Jackson. Unifying execution of imperative and declarative code. In ICSE, pages 511--520, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. C. Morgan. Programming from Specifications (2nd ed.). Prentice-Hall, Inc., 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. L. Mourade Moura and N. Bjørner. Z3: An efficient SMT solver. In TACAS, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. G. Nelson. Techniques for program verification. Technical report, XEROX Palo Alto Research Center, 1981.Google ScholarGoogle Scholar
  47. G. Nelson and D. C. Oppen. Fast decision procedures based on congruence closure. Journal of the ACM (JACM), 27 (2): 356--364, 1980. ISSN 0004--5411. http://doi.acm.org/10.1145/322186.322198. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. N. Nethercote, P. Stuckey, R. Becket, S. Brand, G. Duck, and G. Tack. MiniZinc: Towards a standard CP modelling language. Principles and Practice of Constraint Programming, pages 529--543, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. R. Nilsson. Scalacheck user guide. http://code.google.com/p/scalacheck/wiki/UserGuide, 2011.Google ScholarGoogle Scholar
  50. M. Odersky. Contracts in Scala. In International Conference on Runtime Verification. Springer LNCS, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. M. Odersky, L. Spoon, and B. Venners. Programming in Scala: a comprehensive step-by-step guide. Artima Press, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. D. Overton, Z. Somogyi, and P. J. Stuckey. Constraint-based mode analysis of Mercury. In ACM SIGPLAN Workshop on Principles and practice of declarative programming (PPDI), 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. L. C. Paulson, T. Nipkow, et al. Isabelle theorem prover - official website. http://www.cl.cam.ac.uk/Research/HVG/Isabelle.Google ScholarGoogle Scholar
  54. A. Pnueli and R. Rosner. On the synthesis of a reactive module. In POPL, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. A. Riesco and J. Rodrıguez-Hortalá. Programming with singular and plural non-deterministic functions. In PEPM, pages 83--92, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. H. Samimi, E. D. Aung, and T. D. Millstein. Falling back on executable specifications. In ECOOP, pages 552--576, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. T. Schrijvers, P. J. Stuckey, and P. Wadler. Monadic constraint programming. J. Funct. Program., 19 (6): 663--697, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. J. P. M. Silva and K. A. Sakallah. GRASP - a new search algorithm for satisfiability. In ICCAD, pages 220--227, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. A. Solar-Lezama, L. Tancau, R. Bodık, S. A. Seshia, and V. A. Saraswat. Combinatorial sketching for finite programs. In ASPLOS, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. P. Suter, M. Dotta, and V. Kuncak. Decision procedures for algebraic data types with abstractions. In ACM SIGPLAN POPL, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. P. Suter, A. S. Köksal, and V. Kuncak. Satisfiability modulo recursive programs. In Static Analysis Symposium (SAS), 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. G. Tack. Constraint Propagation - Models, Techniques, Implementation. PhD thesis, Saarland University, 2009.Google ScholarGoogle Scholar
  63. The Coq Development Team; INRIA LogiCal Project. The Coq proof assistant - official website. http://coq.inria.fr.Google ScholarGoogle Scholar
  64. E. Torlak and D. Jackson. Kodkod: A relational model finder. In Tools and Algorithms for Construction and Analysis of Systems (TACAS), 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. P. Van Roy. Logic programming in Oz with Mozart. In ICLP, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. R. N. Zaeem and S. Khurshid. Contract-based data structure repair using Alloy. In ECOOP, pages 577--598, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  67. L. Zhang, C. F. Madigan, M. W. Moskewicz, and S. Malik. Efficient conflict driven learning in boolean satisfiability solver. In ICCAD, pages 279--285, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Constraints as control

    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
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!