finite_cardinality_as_int(Set,int(Card),WF) :- % print(card(Set)),nl,trace,
% if Card is already known we could give it to cardinality_as_int1 straightaway; but we would not detect certain WD-problems
%(number(Card) -> CardValue=Card ; true),
cardinality_as_int1(Set,Card,CardValue,WF), % print(card_value(CardValue,Card)),nl,
% clpfd_domain(CardValue,Low,Up), print(card(CardValue,Low,Up,Set)),nl,trace,
(clpfd_max_bounded(CardValue)
-> Card=CardValue % we cannot have an infinite return value for CardValue
; (nonvar(Set),is_interval_closure(Set,_,_)) -> % we must have a finite interval; no need to guard against inf
Card=CardValue % TO DO: let cardinality_as_int1 return a flag whether set can be infinite
% example i=2..x & card(i):10..2122110 & x > 2121000; see test 1625
; check_finite_card(CardValue,Card,Set,WF) % check that we have obtained a finite value; only propagate then
% TO DO: maybe detect a few more cases where infinite return values are not possible; e.g., based on type
% indeed: check_finite_card prevents propagation of CLPFD information
).