minizinc exists unique
- User
minizinc exists unique
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
minizinc exists unique
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
MiniZinc does not have a built-in “∃!” ( “exists-unique” ) quantifier.
Instead, you express “there exists exactly one … such that P” with a
cardinality / sum-of-booleans constraint.
For a finite index set I and a boolean condition P(i):
constraint sum(i in I)( bool2int( P(i) ) ) = 1;
(or, equivalently, use the global exactly from globals.mzn).
Why this works
• bool2int(B) turns a bool into 0/1.
• The sum counts how many indices satisfy P.
• “= 1” forces the count to be exactly one.
int: n = 6;
array[1..n] of var int: x;
include "globals.mzn"; % for the `exactly` global
constraint exactly(1, [ x[i] = 5 | i in 1..n ]);
% Equivalent, without the library:
% constraint sum(i in 1..n)( bool2int(x[i] = 5) ) = 1;
set of int: People = 1..4;
array[People] of var bool: selected;
constraint exactly(1, selected); % because `selected` is already var-bool
int: n = 8;
array[1..n] of var int: start;
array[1..n] of var int: finish;
% There is exactly one task that starts before time 3 and ends after time 10
constraint sum(t in 1..n)(
bool2int( start[t] < 3 /\ finish[t] > 10 )
) = 1;
array[1..n] of var int: x;
constraint card( { i | i in 1..n where x[i] = 5 } ) = 1;
(The sum/exactly versions usually propagate better than card.)
predicate exists_unique(set of int: I, array[I] of var bool: b) =
sum(i in I)( bool2int(b[i]) ) = 1;
/* usage */
array[1..n] of var bool: cond = [ x[i] = 5 | i in 1..n ];
constraint exists_unique(1..n, cond);
• MiniZinc gives you exists and forall;
• “Exists-unique” is modeled by counting with sum/exactly;
• Use bool2int, or build a boolean array and call exactly(1, …).
That’s all you need to state “∃! x : P(x)” in MiniZinc. Happy modeling!