a not operator that works... 
Author Message
 a not operator that works...

Quote:

> Assuming the following definition
> user_error(X,Y) :- write(user_error(X,Y)),nl.

> you still have non-logical behaviour such as this to deal with:

> ?- not(not(X=1)),X=2.                          
> user_error(should be ground,not(_122=1))

This catches indeed the double not/1 trick - given that the innermost
not/1 is unsound (as X=1 would succeed). This is because the trick
itself tries to check provability without binding - for which \+ \+
could be used if someone really wants it.

Quote:
> X = 2 ? ;

> Why present an answer that is clearly wrong (even though the error message
> printed indicates that something is wrong, it can be hidden in lots of
> output)?

> I accept your reasoning if the last clause is

> not(X):-write(user_error('should be ground',not(X))),nl, abort.

Agreed with this - in fact in BinProlog - from where I pasted
the example - user_error always failed - therefore abort was
always called:

Quote:
> >not(X):- \+ X,!.
> >not(X):-ground(X),!,fail.
> >not(X):-user_error('should be ground',not(X))->fail;abort.

> >The reasoning is that if a goal X fails (and its
> >negation succeeds), it would do just the same if it
> >were instantiated before (or after) X was called.

In fact, raising an exception is another possibility
in this case - if implementors dare to trust users :-)

Paul Tarau
===================================================================
Just released: NEW version of Jinni 2000 fast Java based Prolog
with smart Reflection based interface. It figures out what you
mean when you call JAVA methods :-) Visit http://www.*-*-*.com/
or click on demo at: http://www.*-*-*.com/
===================================================================



Sat, 22 May 2004 05:24:06 GMT  
 a not operator that works...
We might even try to be a little more "logical" and try this:

not(not(X)) :- X.
not(X):- X\=not(_), \+ X,!.
not(X):-X\=not(_), ground(X),!,fail.
not(X):-X\=not(_), write(user_error('should be ground',not(X))),nl, abort.

This allows a constructive use of  any even number of not's while
trapping the "odd" case.
Check for instance
?- not(not(member(X,[1,2,3]))).

In many cases this corresponds to
replacing not(not(X)) with X until no more not(not(X)) occurs, i.e. any
even number of not's
are removed, when consulting, if you want to be more efficient and avoid
some interpretation.

Quote:


>>Assuming the following definition
>>user_error(X,Y) :- write(user_error(X,Y)),nl.

>>you still have non-logical behaviour such as this to deal with:

>>?- not(not(X=1)),X=2.                          
>>user_error(should be ground,not(_122=1))

>This catches indeed the double not/1 trick - given that the innermost
>not/1 is unsound (as X=1 would succeed). This is because the trick
>itself tries to check provability without binding - for which \+ \+
>could be used if someone really wants it.



Fri, 28 May 2004 07:22:03 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software