[ library(cardinal) | Reference Manual | Alphabetic Index ]
# domain(?SetVariable, ?Cardinality, ?Domain)

Accessing the domain of a set
*SetVariable*
- A set variable.
*Cardinality*
- An FD variable
*Domain*
- A list (pair) with glb and poss.

## Description

Domain is unified with the domain of SetVariable (which has cardinality
Cardinality) in the form [Glb:NIn,Poss:NMax],
where Glb is the (greatest) lower bound of SetVariable, and NIn its length,
Poss is the set of still possible elements of SetVariable (i.e. its lub\glb),
and NMax is the lub's cardinality (i.e. NIn + #(Poss)).
If SetVariable is a set of sets and a union function attribute has been set,
then each element of Poss comes annotated with its respective length.

Use domain/3 instead of domain/2 whenever Cardinality variable is available,
for efficiency reasons, since in the case of SetVariable being already
ground, it is not neccessary to recalculate its length (to retrieve
[Setvariable:Cardinality,[]:Cardinality]. This is due to the loss of
attributes of variables when these become instantiated.

Cardinality should be input to domain/3. Do not use this predicate to
retrieve the cardinality of a set, for it will only work when set is ground.

### Fail Conditions

Fails if Domain can not be unified with the current domain of SetVariable.
### Resatisfiable

No.
## Examples

?- S `::[c]+[a,b]:C, domain(S,C,D).
D = [[c]:1, [a,b]:3]
?- S `::[c]+[a,b]:C, S=[a,c], domain(S,C,D).
D = [[a,c]:2, []:2]
?- set(S, [],[[a,b],[b,c],[a,c],[b]],[union:[a,b,c],cardinality:C]), domain(S,C,D).
D = [[]:0, [[a,b]:2, [a,c]:2, [b]:1, [b,c]:2]:4]

## See Also

domain / 2, glb / 2, poss / 2, glb_poss / 3, lub / 2, lub / 4, cardinality / 2, # / 2