I am struggling to understand the difference in functionality between clp(Z) and another relational arithmetic system used in MiniKanren.
In particular, clp(Z) apparently applies to bounded fields while Kiselyov et al. is described to apply to unbounded fields.
I tried to use various edge cases related to infinity and indetermination, but I wasn't able to find clear differences other than Kiselyov et al. obviously not supporting intervals and negative numbers.
What is the point/advantage of the Kiselyov system? Is it mainly that the implementation is simpler, or is there more?
Good question! There are many approaches to performing relational arithmetic, including CLP(Z), CLP(FD), "Kiselyov Arithmetic", and relational Peano Arithmetic. You can also restrict arithmetic to only work on ground numbers (and otherwise signal an error), or delay evaluation of arithmetic constraints until the arguments to a relation become ground enough to solve the relation deterministically.
All of these approaches are useful, and they all have their tradeoffs.
I've been thinking about writing a short paper on this topic. If you are interested, perhaps we could write it up together.
To briefly answer your question, we should keep in mind the distinction between CLP(Z) and CLP(FD). 'CLP(X)' stands for "Constraint Logic Programming over domain 'X'". CLP(FD) operates over a Finite Domain (FD) of integers. In CLP(Z), the domain is the set of all integers, and is therefore unbounded in size.
Obviously the FD domain is contained within the Z domain, so why bother having a separate CLP(FD) domain/solver? Because it may be faster or easier to solve problems within a restricted domain. Indeed, some problems that are undecidable in one domain may become decidable within a restricted domain.
In particular, clp(Z) apparently applies to bounded fields while Kiselyov et al. is described to apply to unbounded fields.
The Z domain in CLP(Z) is actually unbounded. The FD domain in CLP(FD) is bounded. In Kiselyov Arithmetic, the domain is unbounded.
Kiselyov Numerals are interesting in that one numeral can represent infinite sets of concrete numbers. For example,
(0 1 1)
is the Kiselyov Numeral representing 6. (Kiselyov Numerals are lists of binary digits in little-endian order, which is why 6 is represented with a leading '0' instead of a leading '1'.)
Consider this Kiselyov Numeral:
`(1 . ,x)
where x
is a "fresh" logic variable. This Kiselyov Numeral represents any positive odd integer. This is one advantage of Kiselyov Arithmetic: operations can be performed on partially-instantiated numerals, representing potentially infinitely many concrete natural numbers, and without grounding the (potentially infinitely many) answers. Representing infinitely many natural numbers as a single numeral sometimes allows us to reason about infinitely many concrete numbers at once. Alas, this only works in cases where the underlying set of natural numbers we want to represent can be represented using Kiselyov Numerals of the form
`(<bit sequence that doesn't end in 0> . ,x)
One disadvantage of Kiselyov Arithmetic is that each arithmetic relation is "solved" immediately: if we want to add two Kiselyov Numerals, then multiply the result by another Kiselyov Numeral, we have to either perform the complete addition or the complete multiplication first, then perform the other operation. In contrast a CLP(Z) or CLP(FD) solver can accumulate constraints, check satisfiability at each step, and only perform the full solving at the end of the computation, once all the constraints have been accumulated. This approach can be much more efficient, and can also find inconsistencies in a set of constraints, where naive use of Kiselyov Arithmetic would diverge.
other than Kiselyov et al. obviously not supporting intervals and negative numbers.
Kiselyov Arithmetic can be extended to support negative numbers, and also to support fractions/rational numbers. I suspect that supporting intervals is also doable. Alas, I don't know of any libraries that include these extensions.
There are many other tradeoffs between different approaches to relational arithmetic, worthy of a short paper, at least! I hope this gives you some idea, however.
Cheers,
--Will