[ library(cardinal) | Reference Manual | Alphabetic Index ]
Cardinality of a set
- A Set (variable or ground).
- An integer or an FD variable.
Cardinality is the cardinality of SetVariable. If Cardinality is given
(as an integer or FD variable), then SetVariable is constrained to have such cardinality.
If Cardinality is a free variable, then it is unified with the set's cardinality as
an FD variable or an integer (if it is already known).
Fails if Cardinality can not be the cardinality of SetVariable.
?- S `::..[a,b], cardinality(S,C).
?- S `::..[a,b], cardinality(S,1).
?- S `::+[a,b]:1, cardinality(S,C).
C = 1
C = 2
?- S `::[c]+[a,b]:[1,3], C #> 1, cardinality(S,C).
S = [a,b,c]
C = 3
# / 2