1:- module(type_bool,
2 [
3 bool/1,
4 op(200, fy, not), 5 op(500, yfx, and), 6 op(500, yfx, or) 7 ]). 8
9:- current_module(arithmetic_types) -> true ; use_module(library(arithmetic_types)). 10
11:- arithmetic_function(and/2). 12:- arithmetic_function(or/2). 13:- arithmetic_function(not/1). 14:- arithmetic_function(== /2). 15:- arithmetic_function(\== /2). 16:- arithmetic_function(< /2). 17:- arithmetic_function(=< /2). 18:- arithmetic_function(>= /2). 19:- arithmetic_function(> /2). 20:- arithmetic_function(between/3). 21
25bool(B) :- integer(B), (B=0 ; B=1), !.
26
30and(B1,B2,R) :- bool(B1), bool(B2), R is B1*B2.
31
32or(B1,B2,R) :- bool(B1), bool(B2), R is max(B1,B2).
33
34not(B,R) :- bool(B), R is (B+1) mod 2.
35
39 ==(N1,N2,R) :- number(N1), number(N2), !, (N1 =:= N2 -> R=1 ; R=0).
40 ==(A1,A2,R) :- atomic(A1), atomic(A2), (A1 = A2 -> R=1 ; R=0).
41
42\==(N1,N2,R) :- number(N1), number(N2), !, (N1 =:= N2 -> R=0 ; R=1).
43\==(A1,A2,R) :- atomic(A1), atomic(A2), (A1 = A2 -> R=0 ; R=1).
44
45 <(N1,N2,R) :- number(N1), number(N2), !, (N1 < N2 -> R=1 ; R=0).
46 <(A1,A2,R) :- atomic(A1), atomic(A2), (A1 @< A2 -> R=1 ; R=0).
47
48 =<(N1,N2,R) :- number(N1), number(N2), !, (N1 =< N2 -> R=1 ; R=0).
49 =<(A1,A2,R) :- atomic(A1), atomic(A2), (A1 @=< A2 -> R=1 ; R=0).
50
51 >=(N1,N2,R) :- number(N1), number(N2), !, (N1 >= N2 -> R=1 ; R=0).
52 >=(A1,A2,R) :- atomic(A1), atomic(A2), (A1 @>= A2 -> R=1 ; R=0).
53
54 >(N1,N2,R) :- number(N1), number(N2), !, (N1 > N2 -> R=1 ; R=0).
55 >(A1,A2,R) :- atomic(A1), atomic(A2), (A1 @> A2 -> R=1 ; R=0).
56
60between(N1,N2,N,R) :- 61 =<(N1,N,B1),
62 =<(N,N2,B2),
63 and(B1,B2,R)