2013-02-20 5 views
5

を使用する利点は、要素がdistinctoの代わりに有限のドメインにある場合はどうなりますか?core.logicのdistincto対fd/distinct

以下はすべて返品([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])))) 

、あなたが同じmemberofd/inのために言うことができない、あなたはfd/distinct(ただし、他の方法で回避)を使用することができます任意の場所でdistinctoを使用することが表示されますが。

答えて

3

fd/distinctは、どんな種類の値を受け取らなければならないdistinctoよりはるかに高度に最適化されています。フードの下のfd/distinctは、束縛変数の効率的な表現を、集合を用いて一気に扱うことを扱い、distinctoは、かなり簡単な方法で疾患演算子!=を使用する。

関連する問題