[LOGIC-139] to-stream fails on constraints Created: 23/Jun/13 Updated: 28/Jul/13 Resolved: 03/Jul/13
|Reporter:||Norman Richards||Assignee:||David Nolen|
(run* [q] (fresh [x] (!= x 1) (foo x)))
The problem is that to-stream uses unify, which doesn't consider constraints. Here's two alternate implementations of stream (not replacements for to-stream, but basically performing the same task). One uses unify and the other uses bind and == to unify. The bind version produces the correct results.
(defn my-stream-unify [s v vals]
(defn my-stream-bind [s v vals]
(defn myval-unify [x]
(defn myval-bind [x]
I've fixed my use of to-stream in pldb 0.1.3 in https://github.com/threatgrid/pldb/commit/8e8036fa0fedca7bb6ccee4af41a2bf6a66ffc2b
(db-rel foo n)
If I've analyzed and fixed the problem correctly, I'd be happy to fix this small in core.logic. (and maybe it's time to get cracking on moving pldb into core.logic?)
|Comment by David Nolen [ 23/Jun/13 12:19 PM ]|
The bind solution looks good to me. Please attach a patch, thanks!
And +1 to getting pldb into core.logic
|Comment by Norman Richards [ 24/Jun/13 11:55 AM ]|
Note - I could not test the change to the datomic use of to-stream, and there are no test cases covering it. If you don't have a way to verify that change (or would rather not touch that code) then we could not apply that part of the patch and leave the broken to-stream in for the datomic support.
|Comment by David Nolen [ 24/Jun/13 11:59 AM ]|
Can we actually get the patch attached to the ticket as a file upload? Thanks!
As far as fixing Datomic support it's not high priority, it's an experiment not a feature
|Comment by Norman Richards [ 24/Jun/13 12:48 PM ]|
The problem is that we either need to fix that code or leave in the broken method. I guess the best approach is to move to-stream to datomic.clj, so I did that with the attached patch.
|Comment by Norman Richards [ 25/Jun/13 5:33 PM ]|
Did some more testing with this. It seems that the use of mplus here eats the stack up for larger data sets. I'm working on an alternate implementation that won't blow the stack.
|Comment by Norman Richards [ 25/Jun/13 7:41 PM ]|
second version - doesn't blow the stack
|Comment by Norman Richards [ 25/Jun/13 7:46 PM ]|
Upon further reflection, to-stream really wasn't in error. It was the use of unify instead of ==. I didn't know how to apply the goal without mplus/bind. But, obviously, I can call the == goal directly to accomplish what bind was doing, and the existing choice in to-stream is sufficient to go what mplus was doing.
This second patch works on with the larger dbs I have and also passes the test case I added.
|Comment by David Nolen [ 03/Jul/13 8:28 PM ]|