1

Here is quote from from Blackburn and Bos book "Representation and Inference for Natural Language".

:- op(900,yfx,>). % implication
:- op(850,yfx,v). % disjunction
:- op(800,yfx,&). % conjunction
:- op(750, fy,-). % negation 

As expected negation have higher precedence then conjunction.

Now looking at SWI Prolog docs

\+ - negation as failure has precedence lower (900) than /\ conjunction (500).

Am I reading it correctly?

Is there another symbol for negation in SWI Prolog? I know there is not, but it is only kept for backwards compatibility.

Addition Does ~ have a meaning in SWI Prolog?

user1700890
  • 7,144
  • 18
  • 87
  • 183
  • Just because the numbers are not in the order you expect does not mean it is not working correctly. Have you created test cases to verify your assumptions? – Guy Coder Dec 19 '18 at 18:55
  • @GuyCoder, I am not concerned about absolute value of numbers used. I am expecting negation to have low precedence then conjunction e.g. precedence 3, conjunction 5 or similar. I am expecting only order to hold, not absolute values. – user1700890 Dec 19 '18 at 18:58
  • 4
    You can enumerate, by backtracking, all operators defined in a Prolog system by calling the standard `current_op/3` predicate. – Paulo Moura Dec 19 '18 at 18:58
  • 1
    Related, see the `logic` Logtalk example at https://github.com/LogtalkDotOrg/logtalk3/tree/master/examples/logic – Paulo Moura Dec 19 '18 at 19:00
  • 1
    The `-` negation is numeric negation used in arithmetic expressions. It's unrelated to the logical "negation as failure" operator, `\+` which applies to queries. And `~` is not a Prolog operator. The operator `/\` is bitwise AND, also numeric. – lurker Dec 19 '18 at 19:25
  • 3
    Standard Prolog does not define operators `&` and `v`. The /\ operator you see there is (I believe) for arithmetic expressions; the usual logical conjunction and disjunction operators are `,` and `;` respectively, which should match up with Prolog's negation `\+`. There's a ones-complement negation for arithmetic in \, but no logical/boolean negation, surprisingly. – Daniel Lyons Dec 19 '18 at 20:34
  • @DanielLyons, In case of `,` and `;` we are ok then, they have lower precedence relative to `\+`. 1000 and 1100 respectively. – user1700890 Dec 19 '18 at 21:17
  • 1
    It sounds to me like you want to create a mini-language with a meta-interpreter for your own logical inquiries. The standard operators are all multiples of ten partly so you can squeeze your own operators between them as you like. But that only helps if the standard ones are in the right order for your application. If they aren't, you are always free to define your own suite of operators. – Daniel Lyons Dec 19 '18 at 23:44
  • 2
    Do not redefine already existing operators like `>` and `-`. This will ensue havoc. Rather make your own operators. like `.>` in place of `>` etc. – false Dec 20 '18 at 11:45
  • @false, I agree, but I guess for the purpose of just one exercise, it is okay to do. – user1700890 Dec 20 '18 at 18:09
  • @DanielLyons, thank you, this freedom to define drives me nuts a bit. It looks like for the purpose of this exercise (simple model checker from Blackburn and Bos chapter 1), I have to redefine `>` and `v`. – user1700890 Dec 20 '18 at 18:12
  • 3
    This will ensue havoc in just one exercise, too. – false Dec 20 '18 at 18:34

1 Answers1

3

Be careful, (\+)/1 is a logical predicate (ISO core standard 7.8 Control constructs, 8.15 Logic and control) but (/\)/2 is a bitwise operation (ISO core standard 8.6 Arithmetic evaluation, 9.4 Bitwise functors) that is used inside (is)/2. The list would be:

 Logical Predicate       Bitwise Operation    Name
 (,)/2                   (/\)/2               Conjunction
 (;)/2                   (\/)/2               Disjunction
 (\+)/2                  (\)/1                Negation
 Etc..                   Etc..                Etc..

Examples:

?- X is \ 1. /* Bitwise Negation */
X = -2.

?- 1 < 2, 1 > 0.  /* Logical Conjunction */
true.

But since (\+)/1 has a slightly different semantics than classical negation we call it usually negation as failure. (~)/1 is used by CLP(B).