Skip to content

Commit 7ea49df

Browse files
committed
LOGIC-90: <=fd constraint could diverge
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.
1 parent f60a835 commit 7ea49df

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main/clojure/clojure/core/logic.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,10 +3432,11 @@
34323432
IRelevant
34333433
(-relevant? [this s]
34343434
(let-dom s [u du v dv]
3435-
(cond
3436-
(not (singleton-dom? du)) true
3437-
(not (singleton-dom? dv)) true
3438-
:else (not (<= du dv)))))))
3435+
(if (and (domain? du) (domain dv))
3436+
(if (and (singleton-dom? du) (singleton-dom? dv))
3437+
(not (<= du dv))
3438+
(not (interval-< du dv)))
3439+
true)))))
34393440

34403441
(defn <=fd
34413442
"A finite domain constraint. u must be less than or equal to v.

src/test/clojure/clojure/core/logic/tests.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,14 @@
13561356
(firsto r x))
13571357
'([[1 2] 1 2 1]))))
13581358

1359+
(deftest test-90-<fd-diverge
1360+
(is (= (run 1 [a b c d]
1361+
(infd a b c d (interval 0 4))
1362+
(<fd a b)
1363+
(<fd c d)
1364+
(<fd d a))
1365+
'([2 3 0 1]))))
1366+
13591367
;; =============================================================================
13601368
;; cKanren
13611369

0 commit comments

Comments
 (0)