Search code examples
prologlogic

What does the bitwise negation operator(\) do in prolog?


I have to implement some functions, one of which is f= ~p/\~q.

I have the following :

p(a). p(b).
q(a). q(b). q(c).

I found the function as:

f(X):-p(\X);q(\X).

When I verify it ( f(X). , f(a). , f(b). , f(c). ) it always returns false.

Shouldn't it return true for c since c is not of type p?

Thank you!


Solution

  • (\)/1 is an evaluable functor for bitwise complement. If you use it directly in an argument, it is only an uninterpreted functor. Evaluation is only performed with (is)/2, (>)/2 and other comparison operators.

    In all current Prolog implementations you get:

    ?- X is \ 1.
       X = -2.
    

    Fine print: An ISO conforming system is free to define the value for \. That is, it is free, whether it uses 2's complement or another representation. However, there are only systems that use 2's complement.