core.logic

EQ conditions which match against a negative result fail to find any results.

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    OS: Mac OSX
    JVM:
    java -version
    java version "1.8.0_91"
    Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
    Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Description

I was trying to follow the example provided by [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 [==])
(:require [clojure.core.logic :refer :all])
(:require [clojure.core.logic.fd :as fd]))

(run* [q]
(fresh [a0 a1]
(== q [a0 a1])
(fd/in a0 a1 (fd/interval 1 9))
(fd/- a0 a1 -1)
;(fd/eq
; (= (- a0 a1) -1))
))
```

Dependencies (though I tried clojure 1.8 and 1.9 too):
```
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/core.logic "0.8.11"]]
```

Activity

Hide
Stephen Hopper added a comment -

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.

Show
Stephen Hopper added a comment - 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.
Hide
Tom S added a comment - - edited

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 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.

Show
Tom S added a comment - - edited 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 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.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: