integer_recalc2(value(IV),irange(I,I)) :- nonvar(IV), IV=int(I), number(I).
integer_recalc2(integer(I),irange(I,I)).
integer_recalc2(add(A,B),C) :-
get_interval_info(A,AI), get_interval_info(B,BI),
interval_addition(AI,BI,C).
integer_recalc2(minus(A,B),C) :-
get_interval_info(A,AI), get_interval_info(B,BI),
interval_subtraction(AI,BI,C).
integer_recalc2(unary_minus(A),C) :-
get_interval_info(A,AI),
interval_negation(AI,C).
integer_recalc2(multiplication(A,B),C) :-
get_interval_info(A,AI), get_interval_info(B,BI),
interval_multiplication(AI,BI,C).
integer_recalc2(division(A,B),C) :-
get_interval_info(A,AI), get_interval_info(B,BI),
AI=irange(Am,AMNr),BI=irange(Bm,_BM),
( number(Bm), Bm>=0 -> C = AI
; number(Am),number(AMNr) ->
M is max(abs(Am),abs(AMNr)),
C = irange(-M,M)
;
C = irange(-inf,inf)).
integer_recalc2(card(S),irange(MinCard,MaxCard)) :-
% TODO[DP,2016-04-20]: This is a very pessimistic approach:
% The cardinality is maximally as high as the type allows
% Maybe an alternative approach would be to add a second infered information to each node,
% the "guaranteed" integer interval which is independent of overflows. E.g. "card({a,b,c}) : 1..3"
get_texpr_set_type(S,Type),
% print(recalc(Type,S)),nl,
( extract_min_max_card(S,Type,C1,C2) -> (MinCard,MaxCard)=(C1,C2),
debug_println(9,extract_max_card_for_kodkod(C1,C2))
; max_type_cardinality(Type,MaxCard) -> MinCard=0
%; Card=64 % TO DO allow user to provide a custom upper bound ???
; MinCard=0, MaxCard = inf).