<< Back to previous view

[LOGIC-161] fd/eq returns strange results Created: 13/Oct/14  Updated: 16/Oct/14  Resolved: 16/Oct/14

Status: Closed
Project: core.logic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Dustin Conrad Assignee: David Nolen
Resolution: Completed Votes: 0
Labels: None

clojure.core.logic 0.8.8 on mac osx 10.9

(logic/run* [q]
  (logic/fresh [a b]
    (fd/in a b (fd/interval 0 10))
    (fd/eq (= 4 (* (- a b) 2)))
    (logic/== q [a b])))

I am fairly new to logic programming, but it seems to me this should return a result. I believe it is equivalent to

(logic/run* [q]
  (logic/fresh [a b]
    (fd/in a b (fd/interval 0 10))
    (fd/eq (= 2 (- a b)))
    (logic/== q [a b])))

which does return 9 results

Comment by Dustin Conrad [ 13/Oct/14 10:37 PM ]

I apologize for the formatting, I am unable to edit the description after posting.

Comment by David Nolen [ 15/Oct/14 6:01 PM ]

This appears to be a problem with the sugar `fd/eq`. If you stick to the primitives you should see the results that you expect.

Comment by David Nolen [ 15/Oct/14 6:02 PM ]

My suspicion is that some of the implicitly constructed logic vars are not getting assigned FD intervals.

Comment by David Nolen [ 15/Oct/14 8:10 PM ]

I dug into this quite a bit. The specific issue with this code example is that the multiplication will set the domain of a logic var such that negative values leak into the domain calculation causing the spurious appearance of negative values where they should not exist. We should think quite a bit more about the appearance of negative values.

Comment by Dustin Conrad [ 15/Oct/14 10:35 PM ]

Thanks for looking at this David.

Comment by David Nolen [ 16/Oct/14 4:49 PM ]

fixed https://github.com/clojure/core.logic/commit/719c23f80280762ff20216a579d88efa32da2de7

Generated at Wed Oct 22 21:36:00 CDT 2014 using JIRA 4.4#649-r158309.