Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.logic by

I was trying to follow the example provided by (link: this blog post)(https://mattsenior.com/2014/02/using-clojures-core-logic-to-solve-simple-number-puzzles) and found that it only worked if I removed the conditions that test for subtraction with a negative result. I removed a lot of different things and found that even this basic example does not find any matches:

(ns example.core
(:refer-clojure :exclude (link: ==))
(:require (link: clojure.core.logic :refer :all))
(:require (link: clojure.core.logic.fd :as fd)))

(run* (link: q)
(fresh (link: a0 a1)

(== q (link: a0 a1))
(fd/in a0 a1 (fd/interval 1 9))
(fd/- a0 a1 -1)
;  (= (- a0 a1) -1))


Dependencies (though I tried clojure 1.8 and 1.9 too):
:dependencies (link: [org.clojure/clojure "1.7.0")

             (link: org.clojure/core.logic "0.8.11")]


3 Answers

0 votes

Comment made by: enragedginger

I've narrowed this down a bit more. This code works fine on core.logic "0.8.7" and "0.8.8" but is broken in "0.8.9" and beyond.

0 votes

Comment made by: joinr

Up to commit 36d4e03055c57094e09aa81e2bc37883de1dfbde, this works as advertised

(defn test []
(run* [q]

(fresh [x y z]
  (fd/in x y z  (fd/interval 1 9))
  (fd/eq (= (- (* x y) z) -1))
  (== q [x y z]))))


Looks like (link: https://github.com/clojure/core.logic/commit/719c23f80280762ff20216a579d88efa32da2de7)
introduced a regression (although it may have solved other problems).

Suggest adding the above as a simple regression test (after revisiting reasons for LOGIC-161 bugfix). I'm lost in the fd code at the moment, aside from seeing the changes to domain/interval creation that the regression introduced. I tried munging the negative value a number of ways, never could get a result.

0 votes
Reference: https://clojure.atlassian.net/browse/LOGIC-188 (reported by enragedginger)