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

in(?X, ?Set, ?Bool)

Reified version of the set membership constraint
X
an integer or an (integer) variable
Set
a set, set variable, or set expression
Bool
0, 1 or a boolean variable

Description

This is the reified version of the in/2 constraint. This means that the boolean variable Bool reflects the truth of the relation X in Set. If Bool is 1, then in(X,Set,Bool) is the same as X in Set. If Bool is 0, then in(X,Set,Bool) is the same as X notin Set. Otherwise, Bool will be bound to 0 or 1 when X in Set is known to be false or true, respectively. The latter is only guaranteed to be detected after X has become instantiated.

Note that if one wants to have booleans corresponding to all or most of the set domain elements, it will be more efficient to use the membership_booleans/2 constraint in place of many in/3 constraints.

Exceptions

(4) instantiation fault
Set is a free variable without set domain

Examples

    ?- intset(S, 1, 9), in(E, S, B).
    E = E{[-10000000 .. 10000000]}
    S = S{([] .. [1, 2, 3, 4, 5, 6, 7, 8, 9]) : C{[0 .. 9]}}
    B = B{[0, 1]}
    There is 1 delayed goal.

    ?- intset(S, 1, 9), in(E, S, B), B = 1.
    E = E{[1 .. 9]}
    S = S{([] .. [1, 2, 3, 4, 5, 6, 7, 8, 9]) : C{[0 .. 9]}}
    B = 1
    There is 1 delayed goal.

    ?- intset(S, 1, 9), in(E, S, B), E = 3, B = 1.
    S = S{[3] \/ ([] .. [1, 2, 4, 5, 6, 7, 8, 9]) : C{[1 .. 9]}}
    E = 3
    B = 1

    ?- intset(S, 1, 9), in(E, S, B), E = 3, B = 0.
    S = S{([] .. [1, 2, 4, 5, 6, 7, 8, 9]) : C{[0 .. 8]}}
    E = 3
    B = 0
    Yes (0.00s cpu)

    ?- intset(S, 1, 9), in(E, S, B), E = 3, S includes [2, 3, 4].
    B = 1
    E = 3
    S = S{[2, 3, 4] \/ ([] .. [1, 5, 6, 7, 8, 9]) : C{[3 .. 9]}}
    There is 1 delayed goal.

    ?- intset(S, 1, 9), in(E, S, B), E = 3, S disjoint [2, 3, 4].
    B = 0
    E = 3
    S = S{([] .. [1, 5, 6, 7, 8, 9]) : C{[0 .. 6]}}
    There is 1 delayed goal.

    ?- in(3, S, 1).
    instantiation fault
    

See Also

in / 2, notin / 2, membership_booleans / 2