% ================================================================= :- pred constr(bool). :- mode constr(in). :- ignore constr/1. % ================================================================= % Program :- pred quicksort(list(int),list(int)). :- mode quicksort(in,out). quicksort([], []). quicksort([X | Xs], ResL) :- partition(X, Xs, Smalls, Bigs), % partition of the tail Xs quicksort(Smalls, Ls), % with respect to the pivot X. quicksort(Bigs, Bs), % X is NOT in Xs. cons(X,Bs,XBs), append(Ls, XBs, ResL). :- pred partition(int,list(int),list(int),list(int)). :- mode partition(in,in,out,out). partition(X, [], [], []). partition(X, [Y | Ys], [Y | Ls], Bs) :- constr( (X>Y) ), partition(X, Ys, Ls, Bs). partition(X, [Y | Xs], Ls, [Y | Bs]) :- constr( (X= (LMin=SMin)) )), listmin(L,IsDefLMin,LMin), listmin(S,IsDefSMin,SMin), quicksort(L,S). % contracts (postcondition: true) :- spec partition(X,Ls,Smalls,Bigs) ==> listmin(Ls,B1,SLs), listmin(Smalls,B2,SSmalls), listmin(Bigs,B3,SBigs). :- spec append(Xs,Ys,Zs) ==> listmin(Xs,B1,SXs), listmin(Ys,B2,SYs), listmin(Zs,B3,SZs). :- spec cons(C,A,D) ==> listmin(A,B1,SA), listmin(D,B2,SD). % ================================================================= :- query ff1/0. % =================================================================