Re: [Scheme-reports] Definition of expt when the base is exact 0 (was Re: John Cowan's votes and rationales on the seventh ballot) Alex Shinn (20 Sep 2012 02:26 UTC)

Re: [Scheme-reports] Definition of expt when the base is exact 0 (was Re: John Cowan's votes and rationales on the seventh ballot) Alex Shinn 20 Sep 2012 02:23 UTC

On Thu, Sep 20, 2012 at 1:06 AM, Mark H Weaver <mhw@netris.org> wrote:
> On 09/19/2012 03:32 AM, Alex Shinn wrote:
>>
>> Please read at least the wikipedia article on exponentiation.
>
> Okay, I just read it.

Good, then at least we're on the same page.

The next step is to be clear what we are talking about.
There is a difference between mathematical definition (in
this case of exponentiation), convention (such as 0^0 = 1),
and the conventions of a programming language.  The latter
should never contradict a pure mathematical definition, but
is free to return values for undefined operations for
practical reasons such as the machine representation of
numbers (IEE 754) and programming convenience.

It's important to also be clear that machine and programming
language concepts such as NaN and the exact/inexact
distinction are outside the scope of the mathematical
definitions, although we can make analogies and try to
extend the definitions as best as possible.

After all this, we have a programming language _standard_
which in our case the goal is to reflect what the existing
implementations agree on.

Now, the definition of exponentiation is well defined for
integral exponents, as well as rational exponents in terms
of n-th roots. These definitions are valid for base 0 so
long as the exponent is positive - I'm assuming you're no
longer debating that.

Extending the definition to irrational exponents can be done
with limits.  I'm actually not sure why the wp article says
the base must be positive - the limit exists just as well
for 0, and in the later section "Limits of powers" it states
0^x = 0 for all x > 0.  If you don't want to accept this I
could argue, but fortunately we don't have to.  With the
exception of non-standard extensions like Lucier's
computable reals package, Scheme implementations cannot
represent irrational numbers.  And if you really want we can
take a poll among implementations - there's simply no way we
could say (expt 0 x) could be anything other than 0 for
positive real x.

You started backtracking and bringing into the question the
result of 0^0.  This is a matter of mathematical convention,
but in computing it is an overwhelming convention, a de
facto standard among Scheme implementations, and a de jure
standard since R3RS.  There is no grounds for changing this.
The exact/inexact distinction is orthogonal to this
convention.

Exponentiation also has a well accepted extension to complex
numbers, which I agree is not clear when the base is 0.
This is a corner case of a corner case, and the R6RS
convention seemed reasonable enough to me, but since it's
being contested we might as well talk it out.  I retract my
previous claim that we can just extend the result of Euler's
formula for non-zero bases - even using IEEE 754 math we get
at best NaN.  Indeed, checking a handful of implementations
we don't even have agreement here, and most seem to return
+nan.0+nan.0i for (expt 0.0 1+i).

Unless someone else knows why R6RS chose to extend expt for
0 to a complex power, and the reason is strong enough to
dictate implementations change their current result, I'm
going to update the ballot and argue this should also fall
into the "is an error" case.

Standards are silent and implementations differ in the
result of (expt +nan.0 0).  For an inexact zero exponent the
results are all over the place, including 1.0, +nan.0 and
signalling an error.  For an exact zero exponent it looks
like implementations tend to agree the result is 1 but
disagree in exactness.  John, could you check the full list?
So we could say the result is 1 and leave the exactness
unspecified, but I'm inclined to continue to say nothing
here for now.

We could also debate the exactness of (expt <inexact> 0) and
(expt 0 <non-negative-inexact>).  I think here too the
results will differ, and at best we could add a note that
implementations are allowed to break the usual inexact rule
and return exact results here (analogous to #407), but this
would require a vote.

--
Alex

>> Rational exponents are defined in terms of roots.  Real exponents
>> are defined in terms of limits using rational exponents.
>
>
> The wikipedia article states that those definitions are valid only when the
> base is a positive real number.  Furthermore, they can be used only for real
> exponents.  They are no help at all in determining a value for (expt 0
> 1.3+1.4i).
>
>
>> Complex
>> exponents are defined in terms of real exponents using the
>> formula I gave.
>
>
> Again, the formula you gave cannot be used to define (expt 0 z) because the
> formula involves log(r) where 'r' is the magnitude of the base.  In this
> case, the magnitude of the base is exact 0, therefore log(r) is undefined.
> Furthermore, the formula depends on 'theta', the angle of the base, which is
> not defined for exact 0.
>
> See the "Zero to the power of zero" section of that article.  It admits that
> (expt <zero> <zero>) => 1 only when the exponent is discrete, in other words
> (in the language of Scheme) when the exponent is exact 0. In other cases it
> states that (expt <zero> <zero>) must be handled as an indeterminate form.
>
> In "Branch Cuts for Elementary Functions", Kahan argues that
> (expt 0.0 0.0) => 1.0 as follows:
>
>    Consider two expressions z := z(Xi) and w := w(Xi) that depend on
>    some variable Xi, and suppose that z(Beta) = w(Beta) = 0 and that
>    z and w are analytic functions of Xi in some open neighbourhood of
>    Xi = Beta.  This means that z(Xi) and w(Xi) can be expanded in
>    Taylor series in powers of Xi-Beta valid near Xi = Beta, and both
>    series begin with positive powers of Xi-Beta.  Then we find that
>    z -> 0 and w -> 0 and z^w = exp(w ln(z)) -> 1 as Xi -> Beta
>    regardless of the branch chosen for ln.  Since this phenomenon
>    occurs for /all/ pairs of analytic expressions 'z' and 'w', it is
>    very common.
>
> and I accept this rationale for (expt 0.0 0.0) => 1.0.
>
> However, Kahan did not consider a system involving exact numbers, and the
> reasoning above does not apply for (expt 0 0.0).  In that case, the Taylor
> series for z does _not_ begin with a positive power of Xi-Beta. Although
> Kahan does not explicitly mention this case, his reasoning above implicitly
> assumes that z is not zero everywhere.
>
> To evaluate (expt 0 0.0) using limits using the traditional method, we
> should evaluate the limit of (expt 0 x) as 'x' approaches zero from above.
> However, we cannot evaluate this limit using either of the two usual
> definitions of exponentiation which Kahan considers.
>
> Suppose, for the sake of argument, that we admit that (expt 0 x) => zero for
> arbitrary positive real 'x'.  In that case, (expt 0 0.0) =>
> (limit of (expt 0 x) as 'x' approaches zero from above) => 0.0.
>
> In summary, I've still seen no justification for the claims that
> (= 1 (expt 0 0.0)) and (expt 0 z) => zero for arbitrary complex 'z' with
> positive real part.
>
>    Regards,
>      Mark

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports