% ================================================================= :- pred constr(bool). :- mode constr(in). :- ignore constr/1. % =========================================================== %Program :- pred revacc(list(int),list(int)). :- mode revacc(in,out). revacc(L,R) :- reva(L,EL,R), emptylist(EL). :- pred reva(list(int),list(int),list(int)). % reva([1,2], [7,9,8], F). F=[2,1,7,9,8]. :- mode reva(in,in,out). % the accumulator remains "as is" at the right end % of the reversed list. reva([],[],[X]). %error: delete clause reva([],A,A). reva([H|T],A,R) :- cons(H,A,HA), reva(T,HA,R). :- pred emptylist(list(int)). :- mode emptylist(in). emptylist([]). :- pred cons(int,list(int),list(int)). :- mode cons(in,in,out). cons(H,T,[H|T]). % =========================================================== % Catamorphisms :- pred listmember(int,list(int),bool). :- mode listmember(in,in,out). :- cata listmember/3-2. listmember(X,[],Res) :- constr(~Res). listmember(X,[Y|Ys],B) :- constr( B=ite(X=Y,true,B1) ) , listmember(X,Ys,B1). % =========================================================== % Property to verify :- pred ff1. ff1 :- constr( ~( (N1=N2) ) ), listmember(X,L,N1), listmember(X,R,N2), revacc(L,R). :- spec reva(L,Acc,RL) ==> listmember(X,L,SL), listmember(X,Acc,SAcc), listmember(X,RL,SRL) => constr(true). :- spec emptylist(L) ==> listmember(X,L,SL) => constr(true). :- spec cons(H,T,HT) ==> listmember(X,T,ST), listmember(X,HT,SHT) => constr(true). % =========================================================== :- query ff1/0. % ===========================================================