0

I have recieved a piece of code for an assignment called exShell. In it, the code uses (not)/1 for negation, I have currently replaced all instances with (\+)/1 but I was wondering why that would be there in the first place. Is it possible to alias (\+)/1 with (not)/1 or is that a convention of cprolog or some other prolog compiler (for instance cprolog).

solve(not A, C, Rules, (not Proof, C), T, Ask) :- !,
    T1 is -1 * T,
    solve(A, C1, Rules, Proof, T1, Ask),
    C is -1 * C1.

This is an example of it being used.

rumble
  • 3
  • 3
  • 4
    `(not)/1` and `(\+)/1` are already aliases. Only, `(not)/1` is deprecated while `(\+)/1` isn't. See [this answer](http://stackoverflow.com/a/8523825/1027951) for more explanations. the `+` stands for provable and the antislash for not actually, meaning "not provable", which is more correct than "not". – m09 Jul 25 '12 at 03:59
  • 1
    @Mog: I find your comment at least as much explicative as the linked answer... – CapelliC Jul 25 '12 at 09:29
  • actually in the program not is used as such 'not A' there is no brackets to the function, so wouldn't this be 'not/0'. – rumble Jul 26 '12 at 14:54

1 Answers1

0

looks like not here is a unary operator, declared e.g. with op(500,fy,not), so is used as symbolic data which the solve/6 predicate is processing. E.g.,

?- op(500,fy,not).

Yes
?- write( not 3).
not 3

Yes
?- write_canonical( not 3).
not(3)

Yes
?- not 3 =.. X .

X = [not, 3] 

Yes
?-
Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • So why then is is breaking on the compiler? Also, these commands all work in my listener, but any use of not on a variable or predicate throws an error, I don't understand what you mean by symbolic data. – rumble Jul 27 '12 at 12:59
  • any Prolog compound term is a symbolic data. It is just data, not a command or anything. The term `not(3)` has functor `not` and argument `3`. You inspect any compound term with `arg` or `=..` etc. From what you've shown there is a predicate `solve` defined somewhere that you use. It is supposed to handle terms of form `not(X)` apparently. Or so it looks like, from what you've posted. If you "use `not` on a variable" you rely on Prolog to handle it; but you show us some predicate `solve` that's handling it. I.e. not by itself in Prolog, but through the predicate `solve`. – Will Ness Jul 27 '12 at 15:30
  • so just for clarification and to make sure I'm following this, `not(x)` is logically equivalent to `\+`, in the case of this program `not` is causing a error because it's being handled improperly in the implementation. From a previous post it sounds like `not` is depreciated. Sorry I'm very new to prolog. – rumble Jul 27 '12 at 17:34
  • it depends, where. in what you've shown, not, it is not equivalent to anything by itself, it's just a piece of data - a compound term with a functor name `not` and one argument. It doesn't have a meaning by itself - or maybe it has, depending on the compiler. SWI Prolog e.g. does handle goals of the form `not(X)`, equivalently to how it handles `\+(X)`. What Prolog are you using and what error message do you get? --- but in the code you've shown it could've been named *anything*. Name by itself doesn't matter, only how is it handled matters - in that case, by that predicate, `solve`. – Will Ness Jul 27 '12 at 17:46
  • the predicate name `not` is deprecated because it is misleading. In Prolog, its semantics is "can't be proven that ...". So `\+(X)` is used instead. – Will Ness Jul 27 '12 at 17:49
  • Ok, that makes sense, in this piece of code it `not` could really be name anything. It's just a defined op, and is sensitive to how it's previously been define. I'm using was using gprolog, and was getting a predicate not existing error, I recopied the code to test without the find replace change, and now it's compiling fine. I guess I must have copied it wrong. I'm sorry waisting your time, but I do appreciate the help and it did make me understand the language more. – rumble Jul 27 '12 at 18:03