简体   繁体   English

clp(Z) 与 Kiselyov 关系算术

[英]clp(Z) vs. Kiselyov relational arithmetic

I am struggling to understand the difference in functionality between clp(Z) and another relational arithmetic system used in MiniKanren .我正在努力理解 clp(Z) 和MiniKanren 中使用的另一个关系算术系统之间的功能差异。

In particular, clp(Z) apparently applies to bounded fields while Kiselyov et al.特别是,clp(Z) 显然适用于有界场,而 Kiselyov等人。 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.我尝试使用与无穷大和不确定性相关的各种边缘情况,但除了 Kiselyov等人之外,我无法找到明显的差异。 obviously not supporting intervals and negative numbers.显然不支持区间和负数。

What is the point/advantage of the Kiselyov system? Kiselyov 系统的要点/优势是什么? 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".好问题,有很多方法可以执行关系算术,包括 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).和关系 Peano 算术,您还可以将算术限制为仅适用于地面数字(否则会发出错误信号)。 or delay evaluation of arithmetic constraints until the arguments to a relation become ground enough to solve the relation deterministically.或延迟算术约束的评估,直到 arguments 与关系变得足以确定性地解决关系。

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(Z) 和 CLP(FD) 之间的区别。 'CLP(X)' stands for "Constraint Logic Programming over domain 'X'". 'CLP(X)' 代表“域'X'上的约束逻辑编程”。 CLP(FD) operates over a Finite Domain (FD) of integers. CLP(FD) 在整数的有限域 (FD) 上运行。 In CLP(Z), the domain is the set of all integers, and is therefore unbounded in size.在 CLP(Z) 中,域是所有整数的集合,因此大小是无限的。

Obviously the FD domain is contained within the Z domain, so why bother having a separate CLP(FD) domain/solver?显然 FD 域包含在 Z 域中,那么为什么还要有一个单独的 CLP(FD) 域/求解器呢? 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.特别是,clp(Z) 显然适用于有界场,而 Kiselyov 等人。 is described to apply to unbounded fields.被描述为适用于无界字段。

The Z domain in CLP(Z) is actually unbounded. CLP(Z) 中的 Z 域实际上是无界的。 The FD domain in CLP(FD) is bounded. CLP(FD) 中的 FD 域是有界的。 In Kiselyov Arithmetic, the domain is unbounded.在 Kiselyov 算术中,域是无界的。

Kiselyov Numerals are interesting in that one numeral can represent infinite sets of concrete numbers. Kiselyov 数字的有趣之处在于一个数字可以代表无限组的具体数字。 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'.)是表示 6 的 Kiselyov 数字。(Kiselyov 数字是按小端顺序排列的二进制数字列表,这就是为什么 6 用前导 '0' 而不是前导 '1' 表示的原因。)

Consider this Kiselyov Numeral:考虑这个 Kiselyov 数词:

`(1 . ,x)

where x is a "fresh" logic variable.其中x是一个“新鲜”的逻辑变量。 This Kiselyov Numeral represents any positive odd integer.这个 Kiselyov 数字代表任何正奇数 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.这是 Kiselyov Arithmetic 的一个优点:可以对部分实例化的数字执行运算,表示可能无限多的具体自然数,而不需要(可能无限多)答案的基础。 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唉,这仅适用于我们想要表示的基础自然数集可以使用形式的 Kiselyov 数字表示的情况

`(<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. Kiselyov 算术的一个缺点是每个算术关系都会立即“解决”:如果我们想将两个 Kiselyov 数相加,然后将结果乘以另一个 Kiselyov 数,我们必须先执行完全加法或完全乘法,然后再执行另一个操作。 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.相比之下,CLP(Z) 或 CLP(FD) 求解器可以累积约束,在每一步检查可满足性,并且只有在所有约束都累积后,才在计算结束时执行完整求解。 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.这种方法可以更有效,并且还可以在一组约束中发现不一致,在这些约束中,天真地使用 Kiselyov Arithmetic 会产生分歧。

other than Kiselyov et al.除了 Kiselyov 等人。 obviously not supporting intervals and negative numbers.显然不支持区间和负数。

Kiselyov Arithmetic can be extended to support negative numbers, and also to support fractions/rational numbers. Kiselyov Arithmetic 可以扩展为支持负数,也可以支持分数/有理数。 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 - 将要

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM