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

cardinality(?SetVariable, ?Cardinality)

Cardinality of a set
SetVariable
A Set (variable or ground).
Cardinality
An integer or an FD variable.

Description

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).

Fail Conditions

Fails if Cardinality can not be the cardinality of SetVariable.

Resatisfiable

No.

Examples

?- S `::[]..[a,b], cardinality(S,C).
?- S `::[]..[a,b], cardinality(S,1).
?- S `::[]+[a,b]:1, cardinality(S,C).
C = 1

?- cardinality([a,b],C).
C = 2

?- S `::[c]+[a,b]:[1,3], C #> 1, cardinality(S,C).
S = [a,b,c]
C = 3

See Also

# / 2