Pure, Declarative, and Constructive Arithmetic Relations (Declarative Pearl)

  • Oleg Kiselyov
  • William E. Byrd
  • Daniel P. Friedman
  • Chung-chieh Shan
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4989)


We present decidable logic programs for addition, multiplication, division with remainder, exponentiation, and logarithm with remainder over the unbounded domain of natural numbers. Our predicates represent relations without mode restrictions or annotations. They are fully decidable under the common, DFS-like, SLD resolution strategy of Prolog or under an interleaving refinement of DFS . We prove that the evaluation of our arithmetic goals always terminates, given arguments that share no logic variables. Further, the (possibly infinite) set of solutions for a goal denotes exactly the corresponding mathematical relation. (For SLD without interleaving, and for some infinite solution sets, only half of the relation’s domain may be covered.) We define predicates to handle unary (for illustration) and binary representations of natural numbers, and prove termination and completeness of these predicates. Our predicates are written in pure Prolog, without cut (!), var/1, or other non-logical operators. The purity and minimalism of our approach allows us to declare arithmetic in other logic systems, such as Haskell type classes.


Logic Programming Logic Variable Solution Sequence Constraint Logic Programming Logic Programming System 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Apt, K.R.: Principles of Constraint Programming. Cambridge University Press, Cambridge (2003)Google Scholar
  2. 2.
    Eiter, T., Gottlob, G., Mannila, H.: Disjunctive Datalog. ACM Transactions on Database Systems 22(3), 364–418 (1997)CrossRefGoogle Scholar
  3. 3.
    Kowalski, R.: Predicate logic as programming language. In: Rosenfeld, J.L. (ed.) Information Processing, pp. 569–574. North-Holland, Amsterdam (1974)Google Scholar
  4. 4.
    Lloyd, J.W.: Foundations of Logic Programming. Springer, Heidelberg (1987)zbMATHGoogle Scholar
  5. 5.
    Kiselyov, O., Shan, C.c., Friedman, D.P., Sabry, A.: Backtracking, interleaving, and terminating monad transformers. In: Proceedings of the International Conference on Functional Programming, pp. 192–203 (2005)Google Scholar
  6. 6.
    Friedman, D.P., Kiselyov, O.: A declarative applicative logic programming system (2005),
  7. 7.
    Braßel, B., Fischer, S., Huch, F.: Declaring numbers. In: Workshop on Functional and (Constraint) Logic Programming, pp. 23–36 (2007)Google Scholar
  8. 8.
    Matiyasevich, Y.V.: Hilbert’s Tenth Problem. MIT Press, Cambridge (1993)Google Scholar
  9. 9.
    Kiselyov, O., Shan, C.c.: Lightweight static resources: Sexy types for embedded and systems programming. In: Draft Proceedings of Trends in Functional Programming, Seton Hall University (2007), TR-SHU-CS-2007-04-1Google Scholar
  10. 10.
    Baader, F., Snyder, W.: Unification theory. In: Robinson, A., Voronkov, A. (eds.) Handbook of Automated Reasoning, pp. 445–532. Elsevier, Amsterdam (2001)Google Scholar
  11. 11.
    Hennessy, J.L., Patterson, D.A.: Computer Architecture: A Quantitative Approach, 3rd edn. Morgan Kaufmann, San Francisco (2002)zbMATHGoogle Scholar
  12. 12.
    Friedman, D.P., Byrd, W.E., Kiselyov, O.: The Reasoned Schemer. MIT Press, Cambridge (2005)Google Scholar
  13. 13.
    Byrd, W.E., Friedman, D.P.: From variadic functions to variadic relations: A miniKanren perspective. In: 7th Scheme and Functional Programming Workshop, University of Chicago, pp. 105–117 (2006), TR-2006-06Google Scholar
  14. 14.
    Colussi, L., Marchiori, E., Marchiori, M.: On termination of constraint logic programs. In: Montanari, U., Rossi, F. (eds.) CP 1995. LNCS, vol. 976, pp. 431–448. Springer, Heidelberg (1995)Google Scholar
  15. 15.
    Hallgren, T.: Fun with functional dependencies. (2001)
  16. 16.
    Kiselyov, O.: Number-parameterized types. The Monad.Reader 5 (2005)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2008

Authors and Affiliations

  • Oleg Kiselyov
    • 1
  • William E. Byrd
    • 2
  • Daniel P. Friedman
    • 2
  • Chung-chieh Shan
    • 3
  1. 1.FNMOC 
  2. 2.Indiana University 
  3. 3.Rutgers University 

Personalised recommendations