[ library(ic_sets) | Reference Manual | Alphabetic Index ]

membership_booleans(?Set, ?BoolArr)

BoolArr is an array of booleans describing Set
a set, set variable, free variable or set expression
A variable or an array (structure) of boolean variables


This constraint maintains the correspondence between a finite set and an array of booleans (0/1 variables). The set is constrained to contain those (and only those) integers I between 1 and N (the size of the array) where the corresponding array element is 1.

Operationally, setting a array element I to 0 will exclude the element I from Set's domain. Setting I to 1 will include I in Set's lower bound. Adding and removing elements from Set will be reflected in the corresponding boolean being instantiated to 1 or 0 respectively.

When called with BoolArr being a free variable, an array will be created whose arity is at least as big as the largest potential set member. Set members smaller than 1 will be excluded from the set. When called with BoolArr being instantiated to an array, set members smaller than 1 or bigger than the array size will be excluded from the set.


    ?- S::[2,4]..[1,2,3,4,5], membership_booleans(S,B).

    S = S{[2, 4] \/ ([] .. [1, 3, 5]) : _{[2 .. 5]}}
    B = [](_{[0, 1]}, 1, _{[0, 1]}, 1, _{[0, 1]})

    Delayed goals:

    ?- membership_booleans(S, [](0,1,0,1,B5)).

    S = S{[2, 4] \/ ([] .. [5]) : _{[2, 3]}}
    B5 = B5{[0, 1]}

    Delayed goals: