Elm Exactly

Basis entryBasics.pow

A value of Basics. Its type is in Section C.3 Basics.

Static basis

op stands for ↦ OTSTAT(op)^ pow ↦ (∀number. number→number→number,v)\begin{array}{|clcl|}\hline \opv {\ }& \text{stands for} {\ }& \mapsto {\ }& \OTstat(\opv)\\\hline \kw{\textasciicircum} {\ }& \href{/standard/basis/Basics/pow}{\kw{pow}} {\ }& \mapsto {\ }& (\forall\mv{number}.\,\mv{number} \rightarrow \mv{number} \rightarrow \mv{number}, \isv)\\\hline\end{array}
Figure 40: The Static Operator Table, OTSTAT\OTstat

Dynamic basis

opstands for ↦ OTDYN(op)arity^pow ↦ basic value2\begin{array}{|clclc|}\hline \opv {\quad}& \text{stands for} {\ }& \mapsto {\ }& \OTdyn(\opv) {\qquad}& \arity\\\hline \kw{\textasciicircum} {\quad}& \href{/standard/basis/Basics/pow}{\kw{pow}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 2\\\hline\end{array}
Figure 46: The Dynamic Operator Table, OTDYN\OTdyn

Its APPLY

APPLY(pow,m,n) = {norm(mn)}if n≥0 = {1}if n<0 and m=1 = {(−1)n}if n<0 and m=−1 = {0}if n<0 and m∉{1,−1}\begin{array}{rcll} \APPLY(\kw{pow},m,n) {\ }& = {\ }& \{\norm(m^{n})\} {\quad}& \text{if}\ n\geq 0\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ n<0\ \text{and}\ m=1\\ {\ }& = {\ }& \{(-1)^{n}\} {\quad}& \text{if}\ n<0\ \text{and}\ m=-1\\ {\ }& = {\ }& \{0\} {\quad}& \text{if}\ n<0\ \text{and}\ m\notin\{1,-1\} \end{array}
Figure 49: APPLY\APPLY on Int Values
APPLY(pow,x,y) = {1}if y is a zero = {1}if x is 1 = {NaN}if x or y is NaN = {sgn(x)⋅∞}if x is a zero and y<0 an odd integer = {+∞}if x is a zero and y<0 = {x}if x is a zero and y>0 an odd integer = {+0}if x is a zero and y>0 = {1}if x=−1 and y∈{+∞,−∞} = {+0}if ∣x∣<1 and y=+∞ = {+0}if ∣x∣>1 and y=−∞ = {+∞}if ∣x∣>1 and y=+∞ = {+∞}if ∣x∣<1 and y=−∞ = {+0}if x=+∞ and y<0 = {+∞}if x=+∞ and y>0 = {−0}if x=−∞ and y<0 an odd integer = {−∞}if x=−∞ and y>0 an odd integer = {+0}if x=−∞ and y<0 = {+∞}if x=−∞ and y>0 = {NaN}if x<0 and y is not an integer = {fl(xy)}otherwise\begin{array}{rcll} \APPLY(\kw{pow},x,y) {\ }& = {\ }& \{1\} {\quad}& \text{if}\ y\ \text{is a zero}\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ x\ \text{is}\ 1\\ {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x\ \text{or}\ y\ \text{is}\ \dbNaN\\ {\ }& = {\ }& \{\dbsgn(x)\cdot\infty\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y<0\ \text{an odd integer}\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y<0\\ {\ }& = {\ }& \{x\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y>0\ \text{an odd integer}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x\ \text{is a zero and}\ y>0\\ {\ }& = {\ }& \{1\} {\quad}& \text{if}\ x=-1\ \text{and}\ y\in\{+\infty,-\infty\}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ |x|<1\ \text{and}\ y=+\infty\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ |x|>1\ \text{and}\ y=-\infty\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ |x|>1\ \text{and}\ y=+\infty\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ |x|<1\ \text{and}\ y=-\infty\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x=+\infty\ \text{and}\ y<0\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x=+\infty\ \text{and}\ y>0\\ {\ }& = {\ }& \{-0\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y<0\ \text{an odd integer}\\ {\ }& = {\ }& \{-\infty\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y>0\ \text{an odd integer}\\ {\ }& = {\ }& \{+0\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y<0\\ {\ }& = {\ }& \{+\infty\} {\quad}& \text{if}\ x=-\infty\ \text{and}\ y>0\\ {\ }& = {\ }& \{\dbNaN\} {\quad}& \text{if}\ x<0\ \text{and}\ y\ \text{is not an integer}\\ {\ }& = {\ }& \{\dbfl(x^{y})\} {\quad}& \text{otherwise} \end{array}
Figure 51: APPLY\APPLY on Floats: Power
Read it in its chapter·Permanent address: /standard/basis/Basics/pow

Tests (10)

  • elm / FloatEdgeTest
    Float edge cases: `round` on halves, NaN in equality, `min` and `compare`, `truncate` of NaN, and an Int power beyond 2^32.
  • elm / InfixAssocRightPowTest
    `^` associates to the right.
  • elm / InfixNegatedOperandTest
    A negation symbol in an operator chain negates the atomic expression after it, and no more.
  • elm / InfixPrecApplicationFirstTest
    Application binds more tightly than any operator.
  • elm / InfixPrecPowOverMulTest
    `^` (precedence 8) binds more tightly than `*` (precedence 7).
  • elm-core / CoreIssue960PowNegativeExponentIntTest
    `(^)` on two `Int`s with a negative exponent returns a fraction typed as `Int`.
  • elm-core / FloatPowTest
    `^` on Floats computes powers with positive, zero and negative exponents.
  • elm-core / IntPowTest
    Checks integer exponentiation `^`, including a zero exponent and a negative base with an odd exponent.
  • elm-core / StandardA43PowNegativeTest
    Int `^` with a negative exponent: `1 ^ n` is `1`, `(-1) ^ n` is `1` or `-1` by the parity of `n`, and any other base gives `0`.
  • elm-core / StandardA65PowOneTest
    Float `1 ^ y` is `1` for every `y`, and `(-1) ^ y` is `1` for an infinite `y`.

Discussions

Discuss this basis entry·Search the discussions on GitHub

Discussions are on GitHub; one about this basis entry has [b:Basics.pow] in its title.

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.