From: Joachim Schimpf <joachim.schimpf_at_infotech.monash.edu.au>

Date: Thu, 11 Feb 2010 12:44:33 +1100

Date: Thu, 11 Feb 2010 12:44:33 +1100

Andreas Berger wrote: ... > I want to express a Constraint of the Form: > > "Give me a Number X, which is bitwise connected (C++ '&' ) with a second > Number A is 0. > > Something like: A /\ X = 0, give me a possible X when A = 9. > > I can't find an appropiate predicate for such kind of problem. I tried > the following construct: > 9 /\ X #= 0, but of course it does not work. > > Can someone give me a hint to solve this problem please. First, you should consider whether it is not better to use boolean (0/1) variables for the individual bits. Your constraints may then be easier to express. For example, if you represent your numbers as lists of boolean digits, you can define bool_bitand(X, Y, Z) :- ( foreach(Xi,X), foreach(Yi,Y), foreach(Zi,Z) do [Xi,Yi,Zi]::0..1, Zi #= (Xi and Yi) ). and express your example as ?- bool_bitand(X, [1, 0, 0, 1], [0, 0, 0, 0]). X = [0, _368{[0, 1]}, _457{[0, 1]}, 0] Yes (0.00s cpu) Second, if your bit vectors represent sets, you could also consider using the ic_set solver's set-variables to represent them. Third, with your original representation, you could prototype such a constraint as follows: :- lib(propia). int_bitand(X, Y, Z) :- ( labeling([X,Y,Z]), X/\Y =:= Z ) infers ic. which solves your example in this way: ?- X :: 0 .. 9, int_bitand(X, 9, 0). X = X{[0, 2, 4, 6]} Yes (0.00s cpu) -- JoachimReceived on Thu Feb 11 2010 - 02:43:52 CET

*
This archive was generated by hypermail 2.2.0
: Thu Feb 02 2012 - 02:31:58 CET
*