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

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 nonlogical operators. The purity and minimalism of our approach allows us to declare arithmetic in other logic systems, such as Haskell type classes.

[1]  Georg Gottlob,et al.  Disjunctive datalog , 1997, TODS.

[2]  KiselyovOleg,et al.  Backtracking, interleaving, and terminating monad transformers , 2005 .

[3]  Sebastian Fischer,et al.  Declaring Numbers , 2008, WFLP@RDP.

[4]  D. Friedman,et al.  From Variadic Functions to Variadic Relations A miniKanren Perspective , 2006 .

[5]  Sergio Antoy Definitional Trees , 1992, ALP.

[6]  David A. Patterson,et al.  Computer Architecture: A Quantitative Approach , 1969 .

[7]  Francesca Rossi,et al.  Principles and Practice of Constraint Programming — CP '95 , 1995, Lecture Notes in Computer Science.

[8]  Elena Marchiori,et al.  On Termination of Constraint Logic Programs , 1995, CP.

[9]  Krzysztof R. Apt,et al.  Principles of constraint programming , 2003 .

[10]  Amr Sabry,et al.  Backtracking, interleaving, and terminating monad transformers: (functional pearl) , 2005, ICFP '05.

[11]  J. Lloyd Foundations of Logic Programming , 1984, Symbolic Computation.

[12]  Robert A. Kowalski,et al.  Predicate Logic as Programming Language , 1974, IFIP Congress.

[13]  Oleg Kiselyov oleg Number-parameterized types , 2022 .

[14]  David A. Patterson,et al.  Computer Architecture - A Quantitative Approach, 5th Edition , 1996 .

[15]  Alan Robinson,et al.  Handbook of automated reasoning , 2001 .

[16]  Franz Baader,et al.  Unification theory , 1986, Decis. Support Syst..

[17]  Marilyn Bohl,et al.  Information processing , 1971 .

[18]  Chung-chieh Shan,et al.  Position : Lightweight static resources ? Sexy types for embedded and systems programming , 2007 .

[19]  Paliath Narendran,et al.  Unification Theory , 2001, Handbook of Automated Reasoning.

[20]  William E. Byrd,et al.  The reasoned schemer , 2005 .

[21]  J. W. Lloyd,et al.  Foundations of logic programming; (2nd extended ed.) , 1987 .