• Subject: Re: integer exponentiation with negative exponent
• From: Leo Razoumov <slonik.az@...>
• Date: Wed, 4 Jun 2014 09:00:53 -0400

```On 5/22/14, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> Let's add some rigor. In order to be consistent, Arithmetic is build
>> on top of a algebraic field.
>
> Why? Wolfram MathWorld, for instance, says "Arithmetic is the branch
> of mathematics dealing with INTEGERS or, more generally, numerical
> computation" (my emphasis).
>
> Number theory (integers, too) is ususally called "higher Arithmetic".
>
> -- Roberto
>

Well, in this regard Lua's math support is probably closer to "higher
Arithmetic".
But let us consider what happens if Lua would use Wolfram's
MathWorld definition literally.  The only numbers are INTEGERS.
All arithmetic operations including division return integers no
matter what (rounding, truncation, does not matter). Then the
important properties of arithmetic operations are violated

(a*b)/c  ~= a*(b/c) ~= (a/c)*b
(a+b)/c  ~= a/c + b/c

Limiting the domain of numbers to INTEGERS breaks the properties of
arithmetic operations.  This is adressed by algebra with its
important concept of fields. And integers do not form a field.
Well, a set of integers {0,1,...,p-1} where p is prime form a field
when arithmetic operations are taken modulo p. But 32 or 64 bit
integers are not.

Rational numbers are probably the best candidate for consistent math
but without hardware support on the level of CPU instruction set
level the performance of rational number arithmetics is not good
enough.

BTW, strictly speaking, fixed bit-width floating numbers violate the
distribution and associative laws as well. This is why every
computation math text book advices against using == to compare
floating numbers. But this violations can be handled if proper care
is exercised.

--Leo--

```