I found the solution to my first problem at 
https://github.com/clojure/core.logic/wiki/Features (with a few small 
changes by me):

(run* [q]
  (fresh [x y]
    (fd/in x y (fd/interval 0 9))
    (fd/eq
      (= (+ (* x 3) (* y 2)) 8))
    (== q [x y])))


I suppose that I could set (fd/interval 0 999999999) to do a fair 
approximation of the non-negative integers, but out of curiosity, would 
there be a better way of doing this?



On Tuesday, June 10, 2014 11:12:11 AM UTC-4, cej38 wrote:
>
> I am interested in solving a simple equation for all of its solutions when 
> some constraints are applied.  This sounds like a problem for core.logic.fd.
>
> Let's use a toy example:
>
> 8 = 3*x + 2*y,  where x and y must be non-negative integers.
>
> Here are the possible solutions:  [x,y]= {[2,1],[0,4]}.
>
>
> I tried something like this:
>
> (run* [q]
>       (fresh [x y]
>              (== q [x y])
>                    (project [x y]
>       (fd/+ (* x 2) (y 3) 8))))
>
> But I get a exception:
> "java.lang.ClassCastException: clojure.core.logic.LVar cannot be cast to 
> java.lang.Number"
>
> So I have two questions:
> 1. How should I rewrite the above command to get the solutions?
> 2. Are there any good blog posts/online presentations/etc. on 
> core.logic.fd?
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to