ToB*_*ced 7 clojure clojure-core.logic
fd/distinct在元素将在有限域而不是distincto?的情况下使用的优点是什么?
以下全部返回([0 1] [1 0]).
;;; With distincto
(run* [q]
(fresh [x y]
(fd/in x y (fd/interval 1))
(distincto [x y])
(== q [x y])))
;;; With fd/distinct
(run* [q]
(fresh [x y]
(fd/in x y (fd/interval 1))
(fd/distinct [x y])
(== q [x y])))
;;; Without fd at all.
(let [interval [0 1]]
(run* [q]
(fresh [x y]
(membero x interval)
(membero y interval)
(distincto [x y])
(== q [x y]))))
Run Code Online (Sandbox Code Playgroud)
值得注意的是,虽然看起来你可能会distincto在你可能使用的任何地方使用fd/distinct(但不是相反),但不能说membero和fd/in.
fd/distinct比distincto必须获得任何价值的优化程度更高。fd/distinct在distincto幕后使用集立即处理约束变量的有效表示,!=并以非常简单的方式使用不等式运算符。
| 归档时间: |
|
| 查看次数: |
329 次 |
| 最近记录: |