% ================================================================= :- pred constr(bool). :- mode constr(in). :- ignore constr/1. % ================================================================= % Program. ascending sorting :- pred insertionsort(list(int),list(int)). :- mode insertionsort(in,out). insertionsort([],[]). insertionsort([X|Xs],S) :- ord_ins(X,TS,S), insertionsort(Xs,TS). :- pred ord_ins(int,list(int),list(int)). :- mode ord_ins(in,in,out). ord_ins(A,[],[A]). ord_ins(A,[B|Xs],[A,B|Xs]) :- constr( A=B ), ord_ins(A,Xs,AXs). % ================================================================= % catamorphism :- pred listcount(int,list(int),int). :- mode listcount(in,in,out). :- cata listcount/3-2. listcount(X,[],Res) :- constr( (Res=0) ). listcount(X,[Y|Ys],Res) :- constr( Res=ite(X=Y,ResT+1,ResT) ), listcount(X,Ys,ResT). % ================================================================= % Verification. % Property: :- pred ff1. ff1 :- constr( ~(CL=CS)), listcount(X,L,CL), listcount(X,S,CS), insertionsort(L,S). % contracts (postcondition: true) :- spec ord_ins(A,L1,L2) ==> listcount(X,L1,L1N), listcount(X,L2,L2N). % ================================================================= :- query ff1/0. % =================================================================