Richard F.L.R.Snashall said:
Eric said:
Richard F.L.R.Snashall wrote On 11/10/05 13:42,:
Eric Sosman wrote:
"By math definition" there is no such thing as a
minimum integer at all. This should alert you to the
fact that a Java `int' is not a mathematical integer.
Knowing that, you should not expect an `int' to imitate
all properties of an integer with perfect fidelity.
Sure there is. [...]
Care to write it out for us? (When you've finished,
I'll tack on a `- 1' at the end.)
For a two's complement machine, the machine integers are
simply the intersection of the integers with the half-open
interval [-2^(n-1),2^(n-1)), where n is the number of bits in
the particular integer type. As such, a + and a * can be
derived from those of the integers (or real numbers),
provided the result is within the set. It's only when the
"mathematical" answer is not in the set that we end up
with all this nonsense and are forced to go to new definitions.
So obviously the argument over whether or not there is a minimum integer
arose because of a misunderstanding of what one meant by "integer" (i.e. was
it the mathematical concept or the computer-science concept?)
What I wanted to bring up is that we don't need to "go to new
definitions" in the case of the + (and -) operations if we consider the
"machine-integers" to form a group.
I haven't examined it rigorously, but I believe all 3 (and a half)
properties of a group hold:
1) Associativity: for all a, b, c in our group G: (a + b) + c = a + (b +
c)
Trivially (?) true.
2) Identity: There is an element e such that for all a, e + a = a + e =
a
In our case, e = 0.
3) Inverse element: For all a in G, there is an element b such that a +
b = b + a = e.
This trivially is true for all elements greater than
Integer.MIN_INTEGER. (i.e. if a != Integer.MIN_INTEGER, then the inverse of
a is -a). I believe Integer.MIN_INTEGER is it's own inverse. Consider a
2-bit architecture, so the integers are -2, -1, 0 and 1. -2 + -2 is -2
decremented twice. -2 decremented once becomes 1. -2 decremented a second
time becomes 0, which is e.
3.5) Closure: For all a and b in G, a + b is in G.
This is true assuming we allow standard Java overflow/underflow
behaviour.
It seems that the integers and the multiplication does NOT form a group,
as we don't have closure.
- Oliver