[Haskell-cafe] Comments on Haskell 2010 Report

Daniel Fischer daniel.is.fischer at web.de
Sun Jul 11 05:20:28 EDT 2010


On Sunday 11 July 2010 00:40:07, Julian Fleischer wrote:
> Hi wren,
>
> >> x**0 := 1, by convention.
> >
> > [...]
> > So far as I'm aware, the x**0=1 vs 0**y=0 conflict leads to 0**0
> > [being] undefined
>
> x**0 is 1 /by definition, 0**y naturally is 0, since (for example) 0**2
> expands to 0*0 (being 0 of course).

But I would not want 0**(-1) to be 0, nor 0**(0 :+ 1) :: Complex Double.
0**y = 0 is the natural choice for positive real y or complex y with a 
positive real part, not for all y.

(**) is quite a different beast from (^) or (^^). The latter two have a 
natural interpretation as product of |n| copies of x (resp. reciprocal 
thereof if n < 0 for (^^)). (**) is more complicated.

> So there is not a conflict of two
> definitions, it's simply a definition somehow /overriding/ the natural
> attempt. I guess I'm actually messing things up using the word "natural"
> - how can "expand the multiplication of zero with itself zero times" be
> natural?
>
> > [...] more helpful in mathematics.
> > </source-please>
>
> Try it yourself:
> * Prove the binomial theorem *without* the convention 0**0 := 1

Except that in the binomial theorem, one uses (^) and not (**).
For (^), setting x ^ 0 = 1 is, as far as I'm aware, uncontested.

> * Consider the function f(x) := x**0 - is it continuous (over the set of
> natural numbers including zero)?

Continuity over the set of natural numbers is a non-issue, since usually 
one chooses the discrete topology there, so let's consider x real.

But what about the function

p = \x y -> x ** y

, where lim_{x -> +0, y -> +0} p x y doesn't exist?

Note: I, too, consider 0 ** 0 = 1 the best choice, and 0 ** y = 0 for 
positive y. It's just not so clear cut, there are reasons to consider it 
undefined.

>
> Donald E. Knuth writes on the issue [1] (see page 6 of the generated
> output), defending the position x**0 being 1.
>
> Further: C99, Java define it that way. GHC does it that way.

Yay. Unfortunately, GHC uses the default method

x ** y = exp (y * log x)

for complex numbers, so

Prelude Data.Complex> 0 ** 0 :: Complex Double
NaN :+ NaN
Prelude Data.Complex> 0 ** 1 :: Complex Double
NaN :+ NaN

:sigh:

Possibly the default method is the reason for making 0 ** y undefined.

And hugs:
Hugs> 0 ** 0 :: Double

Program error: argument out of range

Hugs> 0 ** 1 :: Double

Program error: argument out of range


> Standard Prelude of Haskell 98 Report defines ^ (** for natural numbers)
> as "x ^ 0 = 1" [sic] The convention is also used in 6.4.3: "The value of
> x^0 or x^^0 is 1 for any x, including zero" [2]
>
> I know it's about "^" in that section, but why should x^0 be 1 and x**0
> be undefined? (or: is the natural zero not the real zero?)

Exponentiation with integer exponents isn't the same as exponentiation with 
arbitrary real (or complex) exponents.
Nevertheless, it is desirable that the latter be an extension of the 
former.

>
> greetings,
> Julian
>
> [1] http://www-cs-faculty.stanford.edu/~knuth/papers/tnn.tex.gz
> [2] http://www.haskell.org/onlinereport/basic.html#sect6.4.3

Cheers,
Daniel



More information about the Haskell-Cafe mailing list