Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

distincto vs. fd/distinct in core.logic

What is the advantage of using fd/distinct in cases where the elements will be in a finite domain instead of distincto?

The following all return ([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]))))

Notably, although it appears you may use distincto in any place where you may use fd/distinct (but not the other way around), the same cannot be said for membero and fd/in.

like image 819
ToBeReplaced Avatar asked Feb 20 '13 16:02

ToBeReplaced


1 Answers

fd/distinct is much more highly optimized than distincto which must receive any kind of value. fd/distinct under the hood deals with efficient representations of constrained variables all at once using sets, distincto uses the disequality operator != in a pretty simple manner.

like image 156
dnolen Avatar answered Sep 28 '22 07:09

dnolen