Fork me on GitHub
#core-logic
<
2017-10-29
>
pbaille08:10:59

I'm struggling with this simple relation, the results are incomplete, and I don't understand why. I'm beginning with core.logic I don't know if it is a bug or my bad understanding of it.

(require '[clojure.core.logic :as l])
    (require '[clojure.core.logic.fd :as fd])
    
    (defn zip+o [x y z]
      (l/conde
        [(l/== () x) (l/== () y) (l/== () z)]
        [(l/fresh [fx rx fy ry fz rz]
                  (l/conso fx rx x)
                  (l/conso fy ry y)
                  (l/conso fz rz z)
                  (fd/in fx fy fz (fd/interval 10))
                  (fd/+ fx fy fz)
                  (zip+o rx ry rz))]))
    
    ; the same with defne macro
    (comment
      (l/defne zip+o [x y z]
               ([() () ()])
               ([[fx . rx]
                 [fy . ry]
                 [fz . rz]]
                 (fd/in fx fy fz (fd/interval 10))
                 (fd/+ fx fy fz)
                 (zip+o rx ry rz))))
    
    (def expected-solutions
      #{{:x [0 0] :y [1 1]}
        {:x [0 1] :y [1 0]}
        {:x [1 1] :y [0 0]}
        {:x [1 0] :y [0 1]}})
    
    (l/run* [q]
            (l/fresh [x y]
                     (l/== q {:x x :y y})
                     (zip+o x y [1 1])))
    
    ;=> ({:x (1 0), :y (0 1)}
    ;    {:x (0 0), :y (1 1)})