function tuple(var bool, var int): element_safe( array of int: a, var int: x ) = let { set of int: idx = index_set(x) var bool: total = x in idx; var idx: xs; int: m = min(idx); % Give xs the value of x when result is total constraint total -> xs = x; % Otherwise, give xs the value m instead to avoid a free variable constraint not total -> xs = m; % element constraint that is guaranteed to be total tuple(var bool, var int): ret = (total, element(a, xs)); } in ret;