Brachylog icon indicating copy to clipboard operation
Brachylog copied to clipboard

Consider using all_distinct/1 instead of all_different/1

Open triska opened this issue 9 years ago • 4 comments

The constraint all_distinct/1 is typically preferable:

When all_distinct/1 is slower than all_different/1, it is typically acceptably slower.

On the other hand, when all_different/1 leads to slower programs than using all_distinct/1, the programs are typically unacceptably slower because the constraint propagation is simply too weak with all_different/1.

A few benchmarks involving common constraint problems could help to make the right decision. Overall, I recommend all_distinct/1 for the reasons above.

triska avatar Jul 08 '16 15:07 triska

@triska Thansk for the advice, I'll change that. What use does all_different/1 typically have then?

JCumin avatar Jul 08 '16 16:07 JCumin

all_different/1 is sometimes faster, but its propagation is so weak that many benchmarks are also unacceptably slow with it. However, all_different/1 is a lot easier to implement of course, so it is also provided by more systems.

triska avatar Jul 08 '16 17:07 triska

@triska I have reverted (maybe temporarily) back to all_different because of the following case:

?- Z in 1..sup, all_distinct([111111111,3,Z]).
ERROR: Out of global stack

Whereas:

?- Z in 1..sup, all_different([111111111,3,Z]).
Z in 1..2\/4..111111110\/111111112..sup,
all_different([111111111, 3, Z]).

Note that this is almost certainly a bug, because if I don't constrain Z to be in 1..sup, we get:

?- all_distinct([111111111,3,Z]).
Z in inf..2\/4..111111110\/111111112..sup,
all_distinct([111111111, 3, Z]).

And if we put the Z in 1..sup after all_distinct, it also works properly:

?- all_distinct([111111111,3,Z]), Z in 1..sup.
Z in 1..2\/4..111111110\/111111112..sup,
all_distinct([111111111, 3, Z]).

(This was found because of this)

JCumin avatar May 03 '17 08:05 JCumin

Please try the latest git version. Thank you for reporting this case.

triska avatar May 03 '17 19:05 triska