1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2%% 3%% Sieve of eratosthenes to compute primes 4%% thom fruehwirth 920218-20, 980311 5%% christian holzbaur 980207 for Sicstus CHR 6%% 7%% ported to hProlog by Tom Schrijvers 8 9:- module(primes,[]). 10:- use_module(library(chr)). 11 12:- constraints candidate/1. 13:- constraints prime/1. 14 15 16candidate(1) <=> true. 17candidate(N) <=> primes:prime(N), N1 is N - 1, primes:candidate(N1). 18 19absorb @ prime(Y) \ prime(X) <=> 0 is X mod Y | true. 20 21time(N):- 22 cputime(X), 23 candidate(N), 24 cputime( Now), 25 Time is Now-X, 26 write(N-Time), nl. 27 28cputime( Ts) :- 29 statistics( runtime, [Tm,_]), 30 Ts is Tm/1000. 31