Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using all_distinct/1 instead of all_different/1 #25

Open
triska opened this issue Jul 8, 2016 · 4 comments
Open

Consider using all_distinct/1 instead of all_different/1 #25

triska opened this issue Jul 8, 2016 · 4 comments

Comments

@triska
Copy link
Contributor

triska commented Jul 8, 2016

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.

@JCumin
Copy link
Owner

JCumin commented Jul 8, 2016

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

@JCumin JCumin closed this as completed Jul 8, 2016
@triska
Copy link
Contributor Author

triska commented Jul 8, 2016

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.

@JCumin
Copy link
Owner

JCumin commented May 3, 2017

@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 JCumin reopened this May 3, 2017
@triska
Copy link
Contributor Author

triska commented May 3, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants