Subject: Re: About unification

From: "Richard A. O'Keefe" <[email-masked]>
Date: Thu, 23 Nov 2000 12:17:52 +1300 (NZDT)

can someone explain this behavior in unification:
	
	?-  -A = -(3).
	A = 3
	Yes
	
This is exactly what you should expect.  On the left we have the
compound term -(A), and on the right we have the compound term -(3).  

	?- -A = -3.
	No
	
This is exactly what you should expect.  On the left we have the
compound term -(A), and on the right we have a simple number which
happens to be negative.  The failure of -3 to unify with -A is no
more surprising than the failure of 333 to unify with iA.

	Is it the right behavior?.
	
Yes of course.  It is essential to have a way of writing negative numbers
in patterns.  We could have gone the APL or ML route of using two different
symbols for <negate> and <start of negative number>, but that would have
confused pretty much everyone.  So the Edinburgh Prolog designers chose to
write negative numbers as, well, negative numbers.

	The only explanation I can think of is how the term '-A' is
	treated internally, as shown using display/1.

There is nothing special about -A.  It's the difference between the
simple negative number -1 and the compound term -(1) that has confused
you.

Note that it's the same in Scheme and Lisp: (- 3) is an arithmetic
expression that negates a 3 at run time, but -3 is a simple negative number.