2013-02-20 3 views
5

요소가 distincto 대신 유한 도메인에있는 경우 fd/distinct을 사용하면 어떤 점이 유리합니까?core.logic에서 distincto 대 fd/distinct

다음은 모두 ([0 1] [1 0])입니다. 당신이 (주변이 아닌 다른 방법) fd/distinct를 사용할 수 있습니다 위치를 어떤 장소에 distincto을 사용할 수 있습니다 보이지만

;;; 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라고 할 수 없습니다.

답변

3

fd/distinct은 어떤 종류의 값을 받아야하는 distincto보다 훨씬 더 최적화되어 있습니다. 후드 아래의 fd/distinct은 집합을 사용하여 제약 된 변수를 모두 효율적으로 나타냅니다. distincto은 매우 간단한 방법으로 질병 연산자 !=을 사용합니다.