SWI-Prolog / issues

Dummy repository for issue tracking
8 stars 3 forks source link

Unexpected behaviour of sort/2 #92

Closed wolffw closed 5 years ago

wolffw commented 5 years ago

<!DOCTYPE html>

/*  reported by wolffw
 *  date 2019/10/22

 *  SWI-Prolog (threaded, 64 bits, version 7.7.19)
 *  Linux version 4.4.0-148-generic (buildd@lgw01-amd64-014) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) ) #174~14.04.1-Ubuntu SMP Thu May 9 08:17:37 UTC 2019
 * */

/*  Unexpected behaviour of sort/2
 *  possibly due to exotic atom 'sn-τός'
 * */
:- op(600, fx, ':').

list(1, [s,s,s,s,s,s,s,s,s,s,snp,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,sf,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,:σα,-,v,v,v,:σα,:σα,:σα,-,v,v,:ησα,v,v,v,:α,-,v,v,α:ησα,:σα,v,v,v,v,:α,v,:σα,:σα,v,:σα,v,v,v,v,v,v,v,v,:ξα,c,b,c,b,q,b,b,b,b,b,b,pi,aα,pi,pi,b,b,b,b,b,i,s,x,s,v,s,s,v,s,b,sf,a,s,s,s,:ξα,b,s,v,snp,s,s,s,s,s,o4,s,pp,o4,q,-,v,b,-,b,-,v,c,i,s,s,s,b,-,s,-,i,-,s,b,sn,b,-,b,b,s,sn,-,sf,s,n,s,q,s,s,s,p,b,s,-,sn,s,o4,s,s,s,sn,q,v,v,b,s,s,-,s,s,s,pi,a,b,-,-,n,-,-,-,i,s,s,-,s,o4,s,q,-,s,s,-,s,s,-,s,-,v,s,s,s,s,b,s,s,s,-,s,s,i,a,-,s,-,n,s,p,s,s,a,sn,-,b,s,-,s,v,pi,n,s,s,n,n,n,-,-,pp,v,s,x,pp,-,v,-,k,s,s,s,-,s,s,s,s,i,o4,c,q,q,v,i,pi,b,s,n,s,s,s,o4,i,v,s,v,s,n,n,s,v,s,s,s,s,s,s,s,a,s,b,v,ά:ησα,c,-,b,s,-,i,i,a,v,snη,b,:σα,s,s,s,s,b,:σα,s,:ξα,v,o4,?,s,b,:σα,-,s,:ησα,b,s,vd,s,a,-,sni,b,s,vi,-,a,v,a,o2,b,-,v,b,α:ησα,-,v,v,b,-,v,v,s,b,a,s,s,s,b,v,a,s,s,s,-,s,b,s,b,s,b,b,:σα,s,ά:ησα,vp,v,c,sfp,-,s,s,a,a,s,s,v,s,snp,s,a,aα,a,a,b,b,s,sn,sn,sn,v,sn,s,s,s,sn,s,s,s,s,s,s,s,s,snp,s,s,s,s,s,:α,vm,vd,vi,vi,vu,ά:ηξα,:σα,:υνα,c,[],-,b,s,s,:σα,s,s,s,a,a,a,s,s,a,s,aα,s,s,s,a,b,s,s,s,:ξα,a,:ξα,:σα,ά:ησα,v,s,s,:ησα,s,s,s,s,s,s,s,a,:ησα,s,snp,s,s,'sn-τός',s,s,:σα,a,s,s,s,:α,s,s,ά:ησα,a,s,s,a,s,a,s,>,>,a,a,:ησα,:σα,s,s,s,a,s,s,s,sn,v,a,s,aα,:ξα,s,s,s,s,s,s,o4,a,s,a,s,s,sn,a,o2,a,:να,:ήγαγα,v,s,s,a,s,>,a,a,b]
    ).
list(2, [s,s,s,s,s,s,s,s,s,s,snp,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,sf,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,:σα,-,v,v,v,:σα,:σα,:σα,-,v,v,:ησα,v,v,v,:α,-,v,v,α:ησα,:σα,v,v,v,v,:α,v,:σα,:σα,v,:σα,v,v,v,v,v,v,v,v,:ξα,c,b,c,b,q,b,b,b,b,b,b,pi,aα,pi,pi,b,b,b,b,b,i,s,x,s,v,s,s,v,s,b,sf,a,s,s,s,:ξα,b,s,v,snp,s,s,s,s,s,o4,s,pp,o4,q,-,v,b,-,b,-,v,c,i,s,s,s,b,-,s,-,i,-,s,b,sn,b,-,b,b,s,sn,-,sf,s,n,s,q,s,s,s,p,b,s,-,sn,s,o4,s,s,s,sn,q,v,v,b,s,s,-,s,s,s,pi,a,b,-,-,n,-,-,-,i,s,s,-,s,o4,s,q,-,s,s,-,s,s,-,s,-,v,s,s,s,s,b,s,s,s,-,s,s,i,a,-,s,-,n,s,p,s,s,a,sn,-,b,s,-,s,v,pi,n,s,s,n,n,n,-,-,pp,v,s,x,pp,-,v,-,k,s,s,s,-,s,s,s,s,i,o4,c,q,q,v,i,pi,b,s,n,s,s,s,o4,i,v,s,v,s,n,n,s,v,s,s,s,s,s,s,s,a,s,b,v,ά:ησα,c,-,b,s,-,i,i,a,v,snη,b,:σα,s,s,s,s,b,:σα,s,:ξα,v,o4,?,s,b,:σα,-,s,:ησα,b,s,vd,s,a,-,sni,b,s,vi,-,a,v,a,o2,b,-,v,b,α:ησα,-,v,v,b,-,v,v,s,b,a,s,s,s,b,v,a,s,s,s,-,s,b,s,b,s,b,b,:σα,s,ά:ησα,vp,v,c,sfp,-,s,s,a,a,s,s,v,s,snp,s,a,aα,a,a,b,b,s,sn,sn,sn,v,sn,s,s,s,sn,s,s,s,s,s,s,s,s,snp,s,s,s,s,s,:α,vm,vd,vi,vi,vu,ά:ηξα,:σα,:υνα,c,[],-,b,s,s,:σα,s,s,s,a,a,a,s,s,a,s,aα,s,s,s,a,b,s,s,s,:ξα,a,:ξα,:σα,ά:ησα,v,s,s,:ησα,s,s,s,s,s,s,s,a,:ησα,s,snp,s,s,s,s,:σα,a,s,s,s,:α,s,s,ά:ησα,a,s,s,a,s,a,s,>,>,a,a,:ησα,:σα,s,s,s,a,s,s,s,sn,v,a,s,aα,:ξα,s,s,s,s,s,s,o4,a,s,a,s,s,sn,a,o2,a,:να,:ήγαγα,v,s,s,a,s,>,a,a,b]
    ).

run0 :-
    list(1, L1),
    length(L1, N_L1),
    sort(L1, S1),
    format('sorted list1 (with repeated elements):~n  ~q~n~n', [S1]),
    length(S1, N1),
    %
    list(2, L2),
    length(L2, N_L2),
    sort(L2, S2),
    length(S2, N2),
    format('unsorted lists differ by one element: ~w~n', [N_L1-N_L2]),
    format('sorted lists differ by three:         ~w > 1~n', [N1-N2]).

/*  Result is 44-41, not as expected 42-41 */
JanWielemaker commented 5 years ago

Sorry for the late response. Your test reproduces. This indeed looks like a bug. The sorted version of list 1 has two duplicate elements: snp and v. So far, no clue why.

JanWielemaker commented 5 years ago

Fixed with SWI-Prolog/swipl-devel@89010fa64041dc8970216e41b08ba5f8150e5619