Brachylog
Brachylog copied to clipboard
Consider using all_distinct/1 instead of all_different/1
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 Thansk for the advice, I'll change that. What use does all_different/1 typically have then?
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 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)
Please try the latest git version. Thank you for reporting this case.