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

?Vars &:: +Domain

All elements of Vars have a value in the domain Domain
Vars
Variable or atomic value, list of them, or submatrix of them
Domain
List of atomic values, or domain name (atom)

Description

Constrains a variable (or a list of variables, or a submatrix of variables), to have the domain Domain. The domain is specified simply as an unordered list of atomic values. A domain variable can only be instantiated to values within its domain.

For compatibility with library(ic_symbolic), domains can also be pre-declared using domain/1, and domain variables then declared by just giving the domain name rather than the list of values. Note however that even in this case the domain is considered unordered, i.e. the order of domain elements in the declaration is not important for the purposes of this library.

Note that, on the left hand side of &::/2, the atom [] is not interpreted as the empty list (of variables or values), but as a single atomic value, i.e. a potential domain element. This is in keeping with the behaviour of the ic_symbolic library, but in contrast with the behaviour of numeric solvers such as ic.

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Examples

    ?- X &:: [mo, tu, we, th, fr, sa, su].
    X = X{[fr, mo, sa, su, th, tu, we]}
    Yes (0.00s cpu)

    ?- [X,Y,we] &:: [mo, tu, we, th, fr, sa, su].
    X = X{[fr, mo, sa, su, th, tu, we]}
    Y = Y{[fr, mo, sa, su, th, tu, we]}
    Yes (0.00s cpu)

    ?- dim(M, [3]), M[1..3] &:: [a,e,i,o,u].
    M = [](_354{[a,e,i,o,u]}, _364{[a,e,i,o,u]}, _374{[a,e,i,o,u]})
    Yes (0.00s cpu)

    ?- [X,Y] &:: [we,fr,su].
    X = X{[we, fr, su]}
    Y = Y{[we, fr, su]}

    ?- X &:: [].
    No (0.00s cpu)

    % Using a named, pre-declared domain
    ?- local domain(colour(r, g, b)).
    Yes (0.01s cpu)

    ?- X &:: colour.
    X = X{[b, g, r]}
    Yes (0.00s cpu)
    

See Also

indomain / 1, get_domain_as_list / 2, get_domain_size / 2, domain / 1