experimental: specialize chr_enum/1 type in experiment mode
[chr.git] / Examples / leq.chr
blob5002679a31d6737c997852962cf964bc7d58883f
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%
3 %% simple constraint solver for inequalities between variables
4 %% thom fruehwirth ECRC 950519, LMU 980207, 980311
5 %%
6 %% ported to hProlog by Tom Schrijvers 
8 :- module(leq,[]).
9 :- use_module(library(chr)).
11 :- constraints leq/2.
12 reflexivity  @ leq(X,X) <=> true.
13 antisymmetry @ leq(X,Y), leq(Y,X) <=> X = Y.
14 idempotence  @ leq(X,Y) \ leq(X,Y) <=> true.
15 transitivity @ leq(X,Y), leq(Y,Z) ==> leq(X,Z).
17 time(N):-
18         cputime(X),
19         length(L,N),
20         genleq(L,Last),
21         L=[First|_],
22         leq(Last,First),
23         cputime( Now),
24         Time is Now-X,
25         write(N-Time), nl.
27 genleq([Last],Last) :- ! .
28 genleq([X,Y|Xs],Last):-
29         leq(X,Y),
30         genleq([Y|Xs],Last).
32 cputime( Ts) :- 
33         statistics( runtime, [Tm,_]),
34         Ts is Tm/1000.