skip to main content
10.1145/3551357.3551379acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

A Predicate Construct for Declarative Programming in Imperative Languages

Published:20 September 2022Publication History

ABSTRACT

Imperative and object-oriented programming languages are among the most common languages for general-purpose programming. These languages work well for handling many common tasks necessary for most applications. However, there are still many hard problems that remain difficult to implement directly in imperative languages. Declarative languages have worked well for solving many of these problems by providing a syntax that allows the user to focus on modeling the problem rather than on designing an algorithm. Logic programming languages, like Prolog, have seen success in constraint satisfaction problems, logical databases, and various NP-Hard problems. Unfortunately, these languages have not seen the same success in general-purpose programming, and most of the problems they solve do not exist in isolation. Furthermore, many imperative programmers are still unfamiliar with and unaware of logic programming.

In this work, we aim to integrate a logical predicate, borrowed from logic programming, into an imperative language to facilitate a model-based approach to programming. Rather than attempting to embed Prolog directly into the language, we provide a logic for reasoning over imperative expressions using the common Boolean operators familiar to imperative programmers. While logic programming relies on unification, our predicate relies on variable assignment which is standard in imperative languages. We have implemented the predicate into the syntax of the Python programming language along with a solver built into the runtime for solving queries on the predicate. We demonstrate the use of the construct through solving commonly-known problems, such as graph coloring and the N-Queens problem. To evaluate the viability of our predicate, we compare the performance results of our predicate against current implementations of Prolog. By bringing this predicate construct to imperative languages, it is our hope that we can help to bridge the gap between imperative and logic programming as well as provide an approach to logic programming that is more intuitive for imperative programmers.

References

  1. Analía Amandi, Marcelo Campo, and Alejandro Zunino. 2005. JavaLog: a framework-based integration of Java and Prolog for agent-oriented programming. Computer languages, systems & structures 31, 1 (2005), 17–33.Google ScholarGoogle Scholar
  2. Krzysztof Apt, J Brunekreef, V Partinton, and A Schaerf. 1998. Alma-0: An imperative language thet supports declarative programming. ACM transactions on programming languages and systems 20, 5 (1998), 1014–1066.Google ScholarGoogle Scholar
  3. Krzysztof R. Apt and Andrea Schaerf. 1997. Search and Imperative Programming. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Paris, France) (POPL ’97). Association for Computing Machinery, New York, NY, USA, 67–79. https://doi.org/10.1145/263699.263709Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Krzysztof R. Apt and Andrea Schaerf. 1999. The Alma Project, or How First-Order Logic Can Help Us in Imperative Programming. https://doi.org/10.48550/ARXIV.CS/9907027Google ScholarGoogle Scholar
  5. Krzysztof R. Apt and M. H. van Emden. 1982. Contributions to the Theory of Logic Programming. J. ACM 29, 3 (jul 1982), 841–862. https://doi.org/10.1145/322326.322339Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. M. A. (Max A.) Bramer. 2005. Logic programming with Prolog. Springer, New York.Google ScholarGoogle Scholar
  7. T.A Budd. 1991. Blending imperative and relational programming. IEEE software 8, 1 (1991), 58–65.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Wolfgang Dvořák, Georg Gottlob, Reinhard Pichler, and Stefan Woltran. 2009. Alternation as a Programming Paradigm. In Proceedings of the 11th ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (Coimbra, Portugal) (PPDP ’09). Association for Computing Machinery, New York, NY, USA, 61–72. https://doi.org/10.1145/1599410.1599419Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Michael Gelfond. 2008. Chapter 7 Answer Sets. In Foundations of Artificial Intelligence. Vol. 3. Elsevier, Amsterdam, 285–316.Google ScholarGoogle Scholar
  10. Sergio Greco. 2016 - 2016. Datalog and logic databases. Morgan & Claypool Publishers, San Rafael, California.Google ScholarGoogle Scholar
  11. John Harrison. 1996. Optimizing proof search in model elimination. In International Conference on Automated Deduction. Springer, Springer Berlin Heidelberg, Berlin, Heidelberg, 313–327.Google ScholarGoogle ScholarCross RefCross Ref
  12. Vladimir. Lifschitz. 2019. Answer Set Programming(1st ed. 2019. ed.). Springer International Publishing, Cham.Google ScholarGoogle Scholar
  13. P.D. Lincoln and N. Shankar. 1994. Proof search in first-order linear logic and other cut-free sequent calculi. In Proceedings Ninth Annual IEEE Symposium on Logic in Computer Science. IEEE, Paris, France, 282–291. https://doi.org/10.1109/LICS.1994.316061Google ScholarGoogle ScholarCross RefCross Ref
  14. J. W. (John Wylie) Lloyd. 1987. Foundations of logic programming(2nd, extended ed. ed.). Springer-Verlag, Berlin ;.Google ScholarGoogle Scholar
  15. Kim Marriott, Peter J Stuckey, and Mark Wallace. 2006. Constraint Logic Programming. In Foundations of Artificial Intelligence. Vol. 2. Elsevier Science & Technology, Oxford, 409–452.Google ScholarGoogle Scholar
  16. Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An efficient SMT solver. In International conference on Tools and Algorithms for the Construction and Analysis of Systems. Springer, Springer Berlin Heidelberg, Berlin, Heidelberg, 337–340.Google ScholarGoogle ScholarCross RefCross Ref
  17. Python. 2021. Python 3.9.5 Documentation. https://docs.python.org/3.9/ Accessed: 2021-05-12.Google ScholarGoogle Scholar
  18. python constraint. 2021. python-constraint: Constraint Solving Problem resolver for Python. https://github.com/python-constraint/python-constraint Accessed on: Oct. 12, 2021.Google ScholarGoogle Scholar
  19. Dimitri Racordon and Didier Buchs. 2020. LogicKit: bringing logic programming to swift. In Conference Companion of the 4th International Conference on art, science, and engineering of programming(20). ACM, New York, NY, USA, 13–16.Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. A Radensky. 1990. Toward integration of the imperative and logic programming paradigms: Horn-clause programming in the Pascal environment. SIGPLAN notices 25, 2 (1990), 25–34.Google ScholarGoogle Scholar
  21. James Smith, Chris Henderson, and Ajay Bansal. 2021. Integrating a General Search Agent into an Imperative Programming Language. In 2021 IEEE Fourth International Conference on Artificial Intelligence and Knowledge Engineering (AIKE). IEEE, 54–61.Google ScholarGoogle ScholarCross RefCross Ref
  22. Leon. Sterling. 1994. The art of Prolog : advanced programming techniques (2nd ed. ed.). MIT Press, Cambridge, Mass.Google ScholarGoogle Scholar
  23. Joost Vennekens. 2016. Lowering the Learning Curve for Declarative Programming: A Python API for the IDP System. In Practical Aspects of Declarative Languages(Lecture Notes in Computer Science). Springer International Publishing, Cham, 86–102.Google ScholarGoogle Scholar
  24. Jan Wielemaker, Tom Schrijvers, Markus Triska, and Torbjörn Lager. 2012. SWI-Prolog. Theory and Practice of Logic Programming 12, 1-2 (2012), 67–96.Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A Predicate Construct for Declarative Programming in Imperative Languages

          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
          • Published in

            cover image ACM Other conferences
            PPDP '22: Proceedings of the 24th International Symposium on Principles and Practice of Declarative Programming
            September 2022
            187 pages
            ISBN:9781450397032
            DOI:10.1145/3551357

            Copyright © 2022 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 20 September 2022

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article
            • Research
            • Refereed limited

            Acceptance Rates

            Overall Acceptance Rate230of486submissions,47%
          • Article Metrics

            • Downloads (Last 12 months)34
            • Downloads (Last 6 weeks)2

            Other Metrics

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader

          HTML Format

          View this article in HTML Format .

          View HTML Format