Skip to content

Commit

Permalink
LOGIC-90: <=fd constraint could diverge
Browse files Browse the repository at this point in the history
The `-relevant?` implementation for `<=fdc` was wrong. If we have two
singleton domains we just check that they are not <= to each
other. However we can also discard the constraint if we have
`interval-<`. Added test case.
  • Loading branch information
swannodette committed Jan 1, 2013
1 parent f60a835 commit 7ea49df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/clojure/clojure/core/logic.clj
Expand Up @@ -3432,10 +3432,11 @@
IRelevant
(-relevant? [this s]
(let-dom s [u du v dv]
(cond
(not (singleton-dom? du)) true
(not (singleton-dom? dv)) true
:else (not (<= du dv)))))))
(if (and (domain? du) (domain dv))
(if (and (singleton-dom? du) (singleton-dom? dv))
(not (<= du dv))
(not (interval-< du dv)))
true)))))

(defn <=fd
"A finite domain constraint. u must be less than or equal to v.
Expand Down
8 changes: 8 additions & 0 deletions src/test/clojure/clojure/core/logic/tests.clj
Expand Up @@ -1356,6 +1356,14 @@
(firsto r x))
'([[1 2] 1 2 1]))))

(deftest test-90-<fd-diverge
(is (= (run 1 [a b c d]
(infd a b c d (interval 0 4))
(<fd a b)
(<fd c d)
(<fd d a))
'([2 3 0 1]))))

;; =============================================================================
;; cKanren

Expand Down

0 comments on commit 7ea49df

Please sign in to comment.