%% Monotone Aggregation % Schema %------- database({sure(Person:string), friend(Person:string, Friend:string)}). %Derivated predicates and rules %------------------------------ % first, the primitive mcount single(mcount, Y, 1). multi(mcount, Y, Old, New) <- New=Old+1. ereturn(mcount, Y, Old, New) <- if(Old=nil then New = 1 else New = Old+1). willcome(P)<- sure(P). willcome(P)<- c_friends(P, K), K >= 3. c_friends(P, mcount) <- willcome(F), friend(P, F). export willcome(X). % second, the more advanced kcount single(kcount, (K,Y), 1). multi(kcount, (K,Y), Old, New) <- Old) <- wllcm(F,_), friend(X,F). export wllcm(X, Y). % third, the even more advance zcount single(zcount, (K,X), 1). multi(zcount, (K,X), Old, New) <- Old < K, New=Old+1. ereturn(zcount, (K,X), K1) <- K1~=nil, K=K1+1. wllcom(F) <- sure(F). wllcom(X, zcount<(3,F)>) <- wllcom(F), friend(X, F). export wllcom(X).