Arithmetic and clojure functions on core.logic lvars

Two related questions in one:

Can Clojure module core.logic do arithmetic, logical comparison, etc. like regular Prolog? I foresee the following:

(defrel points person n) (fact :bob 2) (fact :charlie 3) (run* [q] (fresh [xy] (points :bob x) (points :charlie y) (< xy) (== q (+ xy)))) => (5) 

In this example, neither a logical comparison (< xy) nor an attempt to associate q with (+ xy) are performed. I believe this is due to the fact that I am working with LVar s and not integers at this point, and I cannot make these comparisons because the characters are not yet connected. But it works in the prologue:

 points(bob, 2). points(charlie, 3). ?- points(bob, X), points(charlie, Y), Result is X + Y. => Result = 5. 

In a similar vein, can you somehow use the Clojure functions (which return boolean values ​​or other "true" values) as logical predicates? In other words, use functions to say Minikanren that combine terms or not. Something like:

 (defmagic startswithhi-o [v] (.startsWith v "hi")) (defrel person n) (fact person "bob") (fact person "hillary") (run* [q] (fresh [n] (person n) (startswithhi-o n) (== qn))) => ("hillary") 

If I try such things, I get errors, also complaining that LVars are not connected. Is there any way to do this?

Finally, if someone read this far, I might also ask: are there any plans to include probabilistic logic in core.logic, according to:

http://dtai.cs.kuleuven.be/problog/ ?

I can't hold my breath, but that would be awesome!

+8
logic clojure prolog
source share
2 answers

Nonequilibrium arithmetic is possible through project .

 (run 1 [q] (fresh [xy] (== x 1) (== y 2) (project [xy] (== q (+ xy))))) (3) 

I believe that the given Prolog example is also not relational.

The second half of your question can also be resolved with project , but you must be careful to always enter the main value.

 (defn startwith [x] (project [x] (== true (.startsWith x "hi")))) 

PS: Hold your breath to program Constraint logic to go to core.logic!

+10
source share

I believe that before you apply a function to it, you should "project" (unrelated / project) a logical variable:

 (defrel points person n) (fact points :bob 2) (fact points :charlie 3) (run* [q] (exist [xy] (points :bob x) (points :charlie y) (project [xy] (== true (< xy)) (== q (+ xy))))) 

Please note that there are substitutes for fresh ones in the source fragment and an additional argument for declaring facts.

+2
source share

All Articles