1 | /* -*- Mode:Prolog; coding:ISO-8859-1; -*- */ | |
2 | :- module(csp_basic,[safe_less_than/2, safe_less_than_equal/2, | |
3 | safe_less_than/3, safe_less_than_equal/3, | |
4 | enumerate_csp_int/3]). | |
5 | ||
6 | :- use_module(probsrc(module_information)). | |
7 | :- module_info(group,csp). | |
8 | :- module_info(description,'Basic operations on CSP values.'). | |
9 | ||
10 | :- use_module(probsrc(self_check)). | |
11 | :- assert_must_succeed( (csp_basic:safe_less_than(X,Y), X=1,Y=2)). | |
12 | :- assert_must_fail( (csp_basic:safe_less_than(X,Y), X=1,Y=1)). | |
13 | :- assert_must_fail( (csp_basic:safe_less_than(X,Y), X=2,Y=1)). | |
14 | ||
15 | :- block safe_less_than(-,?),safe_less_than(?,-). | |
16 | safe_less_than(X,Y) :- X<Y. | |
17 | ||
18 | :- assert_must_succeed( (csp_basic:safe_less_than(X,Y,R), X=1,Y=2,R==true)). | |
19 | :- assert_must_succeed( (csp_basic:safe_less_than(X,Y,R), X=2,Y=2,R==false)). | |
20 | :- block safe_less_than(-,?,?),safe_less_than(?,-,?). | |
21 | safe_less_than(X,Y,R) :- (X<Y -> R=true ; R=false). | |
22 | ||
23 | :- assert_must_succeed( (csp_basic:safe_less_than_equal(X,Y), X=1,Y=2)). | |
24 | :- assert_must_succeed( (csp_basic:safe_less_than_equal(X,Y), X=1,Y=1)). | |
25 | :- assert_must_fail( (csp_basic:safe_less_than_equal(X,Y), X=2,Y=1)). | |
26 | :- block safe_less_than_equal(-,?),safe_less_than_equal(?,-). | |
27 | safe_less_than_equal(X,Y) :- X=<Y. | |
28 | ||
29 | :- assert_must_succeed( (csp_basic:safe_less_than_equal(X,Y,R), X=1,Y=2,R==true)). | |
30 | :- assert_must_succeed( (csp_basic:safe_less_than_equal(X,Y,R), X=2,Y=2,R==true)). | |
31 | :- assert_must_succeed( (csp_basic:safe_less_than_equal(X,Y,R), X=2,Y=1,R==false)). | |
32 | :- block safe_less_than_equal(-,?,?),safe_less_than_equal(?,-,?). | |
33 | safe_less_than_equal(X,Y,R) :- (X=<Y -> R=true ; R=false). | |
34 | ||
35 | :- assert_must_succeed( (csp_basic:enumerate_csp_int(X,1,10), X==5)). | |
36 | enumerate_csp_int(N,X,Y) :- X=<Y, | |
37 | ? | (N=X ; X1 is X+1, enumerate_csp_int(N,X1,Y)). |