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

### Cached

### Download Links

### BibTeX

@MISC{Kiselyov_pure,declarative,,

author = {Oleg Kiselyov and William E. Byrd and Daniel P. Friedman and Chung-chieh Shan},

title = {Pure, Declarative, and Constructive Arithmetic Relations (Declarative Pearl) ⋆},

year = {}

}

### OpenURL

### Abstract

Abstract. 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. 1

### Citations

3973 |
Computer Architecture: A Quantitative Approach, 3 rd ed
- Hennessy, Patterson, et al.
- 2002
(Show Context)
Citation Context ...y numbers rather their magnitude.s4 Addition and Subtraction Our treatment of addition is inspired by hardware full-adders and multi-bit adders, as found in a digital computer’s arithmetic logic unit =-=[11]-=-. A one-bit fulladder full1_adder(Cin, A, B, S, Cout) relates two input bits A, B and the incoming carry bit Cin with the sum bit S and the outgoing carry bit Cout, according to the equation Cin+A+B =... |

1855 |
Foundations of Logic Programming
- Lloyd
- 1987
(Show Context)
Citation Context ... of the logic programming system away from Kowalski’s ‘predicate as function’ model [3]. We present fully relational arithmetic on the unbounded domain of binary natural numbers for conventional (SLD =-=[4]-=-, or SLD with interleaving [5]) logic programming systems. We define predicates for addition, multiplication, division with remainder, and logarithm with remainder. These predicates express the remain... |

709 | The semantics of predicate logic as a programming language
- Emden, Kowalski
- 1976
(Show Context)
Citation Context ...he anonymous reviewers for many helpful comments.sthe arithmetic domain to be finite and changes the evaluation mode of the logic programming system away from Kowalski’s ‘predicate as function’ model =-=[3]-=-. We present fully relational arithmetic on the unbounded domain of binary natural numbers for conventional (SLD [4], or SLD with interleaving [5]) logic programming systems. We define predicates for ... |

214 | Unification theory
- Baader, Schulz
- 1998
(Show Context)
Citation Context ...variable with the term it is bound to, so all variables are free for us, as for Lloyd [4]. Our goals are all pure (contain no var/1, negation, or cuts). We assume an idempotent notion of substitution =-=[10]-=-: a substitution θ is a finite map { Xi = ti } from logic variables Xi to terms ti such that no tj contains any Xi. We write the application of the substitution θ to a term t as tθ; this application e... |

205 | H.: Disjunctive datalog
- Eiter, Gottlob, et al.
- 1997
(Show Context)
Citation Context ... multiplicands and the product because of mode restrictions on the first two arguments. Constraint logic programming (CLP) overcomes this drawback to some extent [1]; for example, disjunctive Datalog =-=[2]-=- treats arithmetic relationally. Indeed, relational handling of arithmetic was one of the motivations for CLP. Unfortunately, this flexibility has a price: CLP restricts ⋆ We thank Ronald Garcia and t... |

168 | Principles of Constraint Programming
- Apt
- 2003
(Show Context)
Citation Context ... treated as a ternary relation between multiplicands and the product because of mode restrictions on the first two arguments. Constraint logic programming (CLP) overcomes this drawback to some extent =-=[1]-=-; for example, disjunctive Datalog [2] treats arithmetic relationally. Indeed, relational handling of arithmetic was one of the motivations for CLP. Unfortunately, this flexibility has a price: CLP re... |

146 |
Hilbert’s tenth problem
- Matiyasevich
- 1993
(Show Context)
Citation Context ...ected, since conjunctions of arithmetic goals can express Diophantine equations; were such conjunctions guaranteed to terminate, we would be able to solve Hilbert’s 10th problem, which is undecidable =-=[8]-=-. We also do not guarantee termination if the goal’s arguments share variables. Such a goal can be expressed by conjoining a sharing-free base goal and equalities. We proceed as follows. In §2 we defi... |

22 |
The Reasoned Schemer
- Friedman, Byrd, et al.
- 2005
(Show Context)
Citation Context ...n in §5. Because the base-2 case is so simple, we treat it separately. 7 Related Work We first presented arithmetic predicates over binary natural numbers (including division and logarithm) in a book =-=[12]-=-. The book used miniKanren [13], which like its big sister Kanren [6] is an embedding of logic programming in Scheme. That presentation had no detailed explanations, proofs, or formal analysis, which ... |

13 | On termination of constraint logic programs
- COLUSSI, MARCHIORI, et al.
- 1995
(Show Context)
Citation Context ...solutions generated by programs using SLD. Our solution sets are coarser, and thus easier to reason with, than the partial trace semantics often used to study termination of constraint logic programs =-=[14]-=-. Our approach is minimalist and pure; therefore, its methodology can be used in other logic systems, specifically, Haskell type classes. Hallgren [15] first implemented (unary) arithmetic in such a s... |

7 |
Backtracking, interleaving, and terminating monad transformers
- Kiselyov, Shan, et al.
(Show Context)
Citation Context ...em away from Kowalski’s ‘predicate as function’ model [3]. We present fully relational arithmetic on the unbounded domain of binary natural numbers for conventional (SLD [4], or SLD with interleaving =-=[5]-=-) logic programming systems. We define predicates for addition, multiplication, division with remainder, and logarithm with remainder. These predicates express the remaining arithmetic operations, inc... |

6 | Position: Lightweight static resources: Sexy types for embedded and systems programming
- Kiselyov, Shan
- 2007
(Show Context)
Citation Context ...he full version of this paper 9 includes appendices outlining proofs of the properties of solution sets. We have also implemented declarative arithmetic as Haskell type-level relations (type classes) =-=[9]-=-. 2 Predicates for Unary Arithmetic We begin with unary numerals. Unary is simpler than binary, since every unary numeral is structurally part of its successor, so we may use structural recursion. How... |

5 |
Declaring numbers
- Braßel, Fischer, et al.
(Show Context)
Citation Context ...without cuts, reflection, or any way to distinguish a logic variable. This aim for purity is a challenge that in return makes our approach most elucidating and extensible. 7 Braßel, Fischer, and Huch =-=[7]-=- describe the drawbacks of this residuation-based approach in functional logic programming.sThe final challenge is that the binary representation of a number may not be structurally part of that of it... |

4 |
A declarative applicative logic programming system. http://kanren.sourceforge.net
- Friedman, Kiselyov
- 2005
(Show Context)
Citation Context ... 7 Related Work We first presented arithmetic predicates over binary natural numbers (including division and logarithm) in a book [12]. The book used miniKanren [13], which like its big sister Kanren =-=[6]-=- is an embedding of logic programming in Scheme. That presentation had no detailed explanations, proofs, or formal analysis, which is the focus of this paper. Braßel, Fischer, and Huch’s paper [7] app... |

1 | D.P.: From variadic functions to variadic relations: A miniKanren perspective
- Byrd, Friedman
- 2006
(Show Context)
Citation Context ...e is so simple, we treat it separately. 7 Related Work We first presented arithmetic predicates over binary natural numbers (including division and logarithm) in a book [12]. The book used miniKanren =-=[13]-=-, which like its big sister Kanren [6] is an embedding of logic programming in Scheme. That presentation had no detailed explanations, proofs, or formal analysis, which is the focus of this paper. Bra... |

1 |
Fun with functional dependencies. http://www.cs. chalmers.se/~hallgren/Papers/wm01.html
- Hallgren
- 2001
(Show Context)
Citation Context ...o study termination of constraint logic programs [14]. Our approach is minimalist and pure; therefore, its methodology can be used in other logic systems, specifically, Haskell type classes. Hallgren =-=[15]-=- first implemented (unary) arithmetic in such a system, but with restricted modes. Kiselyov [16, §6] treats decimal addition more relationally. Kiselyov and Shan [9] first demonstrated all-mode arithm... |

1 | Number-parameterized types. The Monad.Reader 5 - Kiselyov - 2005 |

1 |
Fun with functional dependencies. http://www.cs
- Hallgren
- 2001
(Show Context)
Citation Context ...o study termination of constraint logic programs [14]. Our approach is minimalist and pure; therefore, its methodology can be used in other logic systems, specifically, Haskell type classes. Hallgren =-=[15]-=- first implemented (unary) arithmetic in such a system, but with restricted modes. Kiselyov [16, §6] treats decimal addition more relationally. Kiselyov and Shan [9] first demonstrated all-mode arithm... |

1 | Definitional trees. In: Algebraic and Logic Programming. Volume 632 of LNCS - Antoy - 1992 |