I couldn't help but overhear that you're working with Constraint 
Programming, so I thought I'd suggest that you try loco 
<http://github.com/aengelberg/loco>, which is a Clojure wrapper of a Java 
library specifically designed to work with these types of problems.

The loco solution to your problem would look like this:
(use 'loco.core 'loco.constraints)
(solutions [($in :x 0 100)
            ($in :y 0 100)
            ($= ($+ ($* :x 2)
                    ($* :y 3))
                8)])
=> ({:y 0, :x 4} {:y 2, :x 1})
While loco doesn't free you from all the limitations you previously had 
(like having to specify arbitrarily large domains), it might be a better 
choice than core.logic in this case because I think it's more elegant to 
write problems, and it's much faster. (I wrote the library so I'm a bit 
biased.)

On Tuesday, June 10, 2014 8:32:33 AM UTC-7, David Nolen wrote:
>
> That's that's the suggested way - just pick a large bound. 
>
> David 
>
> On Tue, Jun 10, 2014 at 11:28 AM, cej38 <junke...@gmail.com <javascript:>> 
> wrote: 
> > 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 clo...@googlegroups.com 
> <javascript:> 
> > Note that posts from new members are moderated - please be patient with 
> your 
> > first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com <javascript:> 
> > 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+u...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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