* Support make install DESTDIR=
[chr.git] / builtins.pl
blob345695b955b3bc21f4c6e3dadbf510dbced02cd1
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Author: Tom Schrijvers
3 % Email: Tom.Schrijvers@cs.kuleuven.ac.be
4 % Copyright: K.U.Leuven 2004
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 :- module(builtins,
8 negate_b/2,
9 entails_b/2,
10 binds_b/2
11 ]).
13 :- use_module(hprolog).
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16 negate_b(true,fail).
17 negate_b(fail,true).
18 negate_b(X =< Y, Y < X).
19 negate_b(X > Y, Y >= X).
20 negate_b(X >= Y, Y > X).
21 negate_b(X < Y, Y =< X).
22 negate_b(var(X),nonvar(X)).
23 negate_b(nonvar(X),var(X)).
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 entails_b(A,B) :-
27 ( var(B) ->
28 entails(A,B,[A])
30 once((
31 entails(A,C,[A]),
32 B == C
36 entails(A,A,_).
37 entails(A,C,History) :-
38 entails_(A,B),
39 \+ hprolog:memberchk_eq(B,History),
40 entails(B,C,[B|History]).
42 entails_(X > Y, X >= Y).
43 entails_(X > Y, Y < X).
44 entails_(X >= Y, Y =< X).
45 entails_(X < Y, Y > X).
46 entails_(X < Y, X =< Y).
47 entails_(X > Y, X \== Y).
48 entails_(X \== Y, Y \== X).
49 entails_(X == Y, Y == X).
50 entails_(ground(X),nonvar(X)).
51 entails_(compound(X),nonvar(X)).
52 entails_(atomic(X),nonvar(X)).
53 entails_(number(X),nonvar(X)).
54 entails_(atom(X),nonvar(X)).
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 binds_b(G,Vars) :-
57 binds_(G,L,[]),
58 sort(L,Vars).
60 binds_(var(_),L,L).
61 binds_(nonvar(_),L,L).
62 binds_(ground(_),L,L).
63 binds_(compound(_),L,L).
64 binds_(number(_),L,L).
65 binds_(atom(_),L,L).
66 binds_(atomic(_),L,L).
67 binds_(integer(_),L,L).
68 binds_(float(_),L,L).
70 binds_(_ > _ ,L,L).
71 binds_(_ < _ ,L,L).
72 binds_(_ =< _,L,L).
73 binds_(_ >= _,L,L).
74 binds_(_ =:= _,L,L).
75 binds_(_ =\= _,L,L).
76 binds_(_ == _,L,L).
77 binds_(_ \== _,L,L).
79 binds_(X is _,[X|L],L).
80 binds_((G1,G2),L,T) :-
81 binds_(G1,L,R),
82 binds_(G2,R,T).
83 binds_((G1;G2),L,T) :-
84 binds_(G1,L,R),
85 binds_(G2,R,T).
86 binds_((G1->G2),L,T) :-
87 binds_(G1,L,R),
88 binds_(G2,R,T).
90 binds_(\+ G,L,T) :-
91 binds_(G,L,T).