This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/chr/Benchmarks/primes.chr
2015-10-13 08:17:51 +01:00

30 lines
674 B
Plaintext

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Sieve of eratosthenes to compute primes
%% thom fruehwirth 920218-20, 980311
%% christian holzbaur 980207 for Sicstus CHR
%%
%% ported to hProlog by Tom Schrijvers
:- module(primes,[main/0,main/1]).
:- use_module(library(chr)).
:- chr_constraint candidate/1.
:- chr_constraint prime/1.
candidate(1) <=> true.
candidate(N) <=> primes:prime(N), N1 is N - 1, primes:candidate(N1).
absorb @ prime(Y) \ prime(X) <=> 0 =:= X mod Y | true.
main :-
main(2500).
main(N):-
cputime(X),
candidate(N),
cputime( Now),
Time is Now-X,
write(bench(primes ,N,Time,0,hprolog)), write('.'),nl.