Power function

From HaskellWiki

Revision as of 13:44, 26 February 2008 by Rk (Talk | contribs)

1  Question

Why are there several notions of power in Haskell, namely
(^)
,
(^^)
,
(**)
?

2  Answer

The reason is that there is no definition for the power function which covers all exotic choices for bases 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 1x, where x 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: [1]):

$f(t) = (1- i\cdot k\cdot t) ^ {-\frac{1}{2} + \frac{\mu_2}{k} + i\cdot \mu_1 }$

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:

For computing
(-1)**(1/3::Double)
the power implementation has to decide whether
(1/3::Double)
is close enough to $\frac{1}{3}$. If it does so it returns
(-1)
, otherwise it fails. However, why shall
0.333333333333333
represent $\frac{1}{3}$? It may be really meant as
333333333333333/10^15
,

and a real 1015th root of − 1 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.

basis type          provides  symbol  exponent type                    definition
any ring            *         ^       cardinal                         repeated multiplication                                          $a^b = \prod_{i=1}^b a$
any field           /         ^-      integer                          multiplication and division                                      $a^b = \begin{cases} a^b & b\ge 0 \\ \frac{1}{a^{-b}} & b<0 \end{cases}$
an algebraic field  root      ^/      rational                         list of polynomial zeros (length = denominator of the exponent)  $a^{\frac{p}{q}} = \{ x : a^p = x^q \}$
positive real       log       ^?      any ring with a notion of limit  exponential series                                               $a^b = \sum_{i=0}^{\infty} \frac{(b\cdot\ln a)^i}{i!}$
• examples for rings are: Polynomials, Matrices, Residue classes
• examples for fields: Fractions of polynomials (rational functions), Residue classes with respect to irreducible divisors, in fact we do not need fields, we only need the division and associativity, thus invertible Matrices are fine

That is
(^-)
replaces
(^^)
,
(^?)
replaces
(**)
,
(^)
remains and
(^/)
is new.

3  See also

• Haskell-Cafe: Proposal for restructuring Number classes
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 7, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8904457092285156, "perplexity_flag": "middle"}