%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% Generating the set of all the prime numbers smaller %%% than a given integer N %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Last revision: August 2002 (G.Rossi) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% primes(N,S): %%% true if S is the set of all the prime numbers smaller than N primes(N,S) :- M is N - 1 & S = {X : X in int(2,M) & labeling(X) & is_prime(X)}!. is_prime(X) :- Y is X -1 & forall(Z in int(2,Y), non_div(Z,X)). non_div(A,B) :- Rmdr is (B mod A) & Rmdr neq 0. % Sample goal: % % {log}=> primes(15,S). % S = {2,3,5,7,11,13} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% start predicate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start :- nl & write('Generating the set of all the prime numbers smaller ') & nl & write('than a given integer N ') & nl & nl & write('Give the goal primes(N,S): ') & nl & write('S is the set of all the prime numbers smaller than N'). %:-start.