Why are there several notions of power in Haskell, namely
The reason is that there is no definition for the power function which covers all exotic choices for basis and exponent. It is even sensible to refine the set of power functions as it is done in the NumericPrelude project. In mathematical notation we don't respect types and we do not distinguish between powers of different types. However if we assume the most general types for both basis and exponent, the result of the power is no longer unique. Actually all possible solutions of say , where is irrational is dense in the complex unit circle. In the past I needed the power of two complex numbers only once, namely for the Cauchy wavelet (see also: ):
However, I could not use the built-in complex power function
because the resulting function became discontinuous. Of course, powers of complex numbers have the problem of branch cuts and the choice of the branch built into the implementation of the complex power is quite arbitrary and might be inappropriate.
But also for real numbers there are problems:
(-1)**(1/3::Double) the power implementation has to decide whether
(1/3::Double) is close enough to .
If it does so it returns
(-1), otherwise it fails.
However, why shall
0.333333333333333 represent ?
It may be really meant as
and a real th root of does not exist.
So I propose some balancing: The more general the basis the less general the exponent and vice versa.
I also think the following symbols are more systematic and intuitive.
They are used in NumericPrelude.
any ring (provides *) ^ cardinal any field (provides /) ^- integer an algebraic field (provides 'root') ^/ rational (computing a list of powers depending on the denominator of the rational) positive real (including transcendent) ^? anything (unqiue via exponential series)
(^) remains and
(^/) is new.
- Haskell-Cafe: Proposal for restructuring Number classes