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

element(?Index, +Values, ?Element)

Element is the Index'th element of the collection Values.
A variable or an integer.
A non-empty collection of numbers or variables.
A variable or a number.


Values is a collection (see eval_to_array/2) of numbers or numeric variables, and the constraint states that its Index'th element is equal to Element.

The most common use for this constraint is to state a relation between two variables, where one is a linear index and the other an arbitrary value defined by an entry in a table of constants.

More generally, the table can itself contain problem variables.

If Values contains only instantiated integers, then the implementation maintains domain-consistency between Index and Element.

If Values contains reals or domain variables, the implementation maintains bounds-consistency for Element and the variables in Values, and domain-consistency for Index.

Fail Conditions

Fails if Element is not the Index'th element of Values.




    ?- element(I, [1,3,6,3], V).
    I = I{1 .. 4}
    V = V{[1, 3, 6]}
    There is 1 delayed goal.

    ?- element(I, [](1,3,6,3), V), V #\= 3.
    I = I{[1, 3]}
    V = V{[1, 6]}
    There is 1 delayed goal.

    ?- A#::2..4, B#::8..9, C#::4..5, element(I, [A,B,C], X), X#=<7.
    A = A{2 .. 4}
    B = B{[8, 9]}
    C = C{[4, 5]}
    I = I{[1, 3]}
    X = X{2 .. 5}
    There is 1 delayed goal.
    Yes (0.00s cpu)

See Also

:: / 2, eval_to_array / 2