correct global_cardinality/2, after testing with:
correct global_cardinality/2, after testing with:

   :- use_module(library(clpfd)).

   test_constraints(_, [])     --> [].
   test_constraints(X, [_|Vs]) --> test_constraints(X, Vs).
   test_constraints(X, [V|Vs]) --> [X #\= V], test_constraints(X, Vs).

   all_constraints([], _)      --> [].
   all_constraints([V|Vs], Ns) -->
           test_constraints(V, Ns),
           all_constraints(Vs, Ns).

   run :-
           length(Vs, N),
           MaxLCs #= N^2,
           between(1, MaxLCs, LCs),
           length(Cs, LCs),
           numlist(1, N, Ns),
           portray_clause(N-LCs),
           phrase(all_constraints(Vs,Ns), Cs),
           Vs ins 1..N,
           maplist(call, Cs),
           length(Values, N),
           Values ins 0..N,
           pairs_keys_values(Pairs, Ns, Values),
           findall(Vs-Pairs, (label(Values),
                                 label(Vs),
                                 global_cardinality(Vs, Pairs)), Sol1),
           findall(Vs-Pairs, (global_cardinality(Vs, Pairs),
                                 label(Vs),
                                 label(Values)), Sol2),
           sort(Sol1, Sol1S),
           sort(Sol2, Sol2S),
           (   Sol1S == Sol2S -> true
           ;   portray_clause(maplist(call, [Vs ins 1..N, Values ins 0..N,
                                             global_cardinality(Vs,Pairs)|Cs])),
               portray_clause(Sol1S),
               portray_clause(Sol2S)
           ),
           false.

koryonik/swipl-devel,jn7163/swipl-devel,jn7163/swipl-devel,edechter/swipl-devel,mndrix/swipl-devel,koryonik/swipl-devel,edechter/swipl-devel,mndrix/swipl-devel,jn7163/swipl-devel,jn7163/swipl-devel,jn7163/swipl-devel,mndrix/swipl-devel,mndrix/swipl-devel,edechter/swipl-devel,koryonik/swipl-devel,edechter/swipl-devel,koryonik/swipl-devel,edechter/swipl-devel,koryonik/swipl-devel,mndrix/swipl-devel