Reputation: 15
How can i map in swi-prolog true and false to 1's and 0's respectively? i need to evaluate ones and zeroes like true and falses (like in truth tables). i am having some difficulties since whenever i try to use 1 as logical value swi-prolog dosent take it kindly and returns erros.
I would like to try something like this
0 :- false.
1 :- true.
and when i query my logical "and" operation, it should return logical and operation applied to both values.
? my_and_operation(1, 0).
false
? my_and_operation(1, 1).
true
Upvotes: 0
Views: 552
Reputation: 7493
Alternatively you could do something like :
map(1, true).
map(0, false).
boolAnd(X, Y) :-
maplist(map, [X, Y], [A, B]),
(A, B).
boolOr(X, Y) :-
maplist(map, [X, Y], [A, B]),
(A; B).
Upvotes: 1
Reputation: 21972
Simple way to do what you need is just determine some isTrue/1
and isFalse/1
predicates.
isTrue( 1 ).
isFalse( 0 ).
booleanAnd( X, Y ) :-
isTrue( X ),
isTrue( Y ).
Usage.
?- booleanAnd( 1, 0 ).
false.
?- booleanAnd( 1, 1 ).
true.
Upvotes: 3