Iverson bracket

In mathematics, the Iverson bracket, named after Kenneth E. Iverson, is a notation that generalises the Kronecker delta, which is the Iverson bracket of the statement $x = y$. It maps any statement to a function of the free variables in that statement. This function is defined to take the value 1 for the values of the variables for which the statement is true, and takes the value 0 otherwise. It is generally denoted by putting the statement inside square brackets: $$[P] = \begin{cases} 1 & \text{if } P \text{ is true;} \\ 0 & \text{otherwise.} \end{cases}$$ In other words, the Iverson bracket of a statement is the indicator function of the set of values for which the statement is true.

The Iverson bracket allows using capital-sigma notation without restriction on the summation index. That is, for any property $$P(k)$$ of the integer $$k$$, one can rewrite the restricted sum $$\sum_{k : P(k)}f(k)$$ in the unrestricted form $$\sum_k f(k) \cdot[P(k)]$$. With this convention, $$f(k)$$ does not need to be defined for the values of $k$ for which the Iverson bracket equals $0$; that is, a summand $$f(k)[\textbf{false}]$$ must evaluate to 0 regardless of whether $$f(k)$$ is defined.

The notation was originally introduced by Kenneth E. Iverson in his programming language APL, though restricted to single relational operators enclosed in parentheses, while the generalisation to arbitrary statements, notational restriction to square brackets, and applications to summation, was advocated by Donald Knuth to avoid ambiguity in parenthesized logical expressions.

Properties
There is a direct correspondence between arithmetic on Iverson brackets, logic, and set operations. For instance, let A and B be sets and $$P(k_1,\dots)$$ any property of integers; then we have

$$\begin{align}[] [\,P \land Q\,] ~ &= ~ [\,P\,]\,[\,Q\,]; \\[1em] [\,P \lor Q\,] ~ &= ~ [\,P\,] \; + \; [\,Q\,] \; - \; [\,P\,]\,[\,Q\,]; \\[1em] [\,\neg \,P\,] ~ &= ~ 1 - [\,P\,]; \\[1em] [\,P {\scriptstyle\mathsf\text{ XOR }} Q\,] ~ &= ~ \Bigl|\,[\,P\,] \; - \; [\,Q\,] \, \Bigr| ; \\[1em] [\,k \in A\,] \; + \; [\,k \in B\,] ~ &= ~ [\,k \in A \cup B\,] \; + \; [\,k \in A \cap B\,]; \\[1em] [\,x \in A \cap B\,] ~ &= ~ [\,x \in A\,]\, [\,x \in B\,]; \\[1em] [\,\forall \,m\ : \, P(k, m)\,] ~ &= ~ \prod_m\, [\,P(k, m)\,]; \\[1em] [\,\exists \,m\ : \, P(k, m)\,] ~ &= ~ \min\Bigl\{\;1\,, \,\sum_m \,[\,P(k, m)\,]\;\Bigr\} = 1 \; - \;\prod_m \, [\,\neg\, P(k, m)\,] ; \\[1em] \#\Bigl\{\; m \,\Big| \, P(k, m)\;\Bigr\} ~ &= ~ \sum_m \, [\,P(k, m)\,]. \end{align}$$

Examples
The notation allows moving boundary conditions of summations (or integrals) as a separate factor into the summand, freeing up space around the summation operator, but more importantly allowing it to be manipulated algebraically.

Double-counting rule
We mechanically derive a well-known sum manipulation rule using Iverson brackets: $$\begin{align} \sum_{k\in A}f(k)+\sum_{k\in B}f(k) &=\sum_kf(k)\,[k\in A]+\sum_kf(k)\,[k\in B]\\ &=\sum_kf(k)\,([k\in A]+[k\in B]) \\&=\sum_kf(k)\,([k\in A\cup B]+[k\in A\cap B]) \\&=\sum_{k\in A\cup B}f(k)\ +\sum_{k\in A\cap B}f(k). \end{align}$$

Summation interchange
The well-known rule $\sum_{j=1}^n \sum_{k=1}^j f(j,k) = \sum_{k=1}^n \sum_{j=k}^n f(j,k)$ is likewise easily derived: $$\begin{align} \sum_{j=1}^n\,\sum_{k=1}^j f(j,k) &=\sum_{j,k}f(j,k)\,[1\leq j\leq n]\,[1\leq k\leq j] \\&=\sum_{j,k}f(j,k)\,[1\leq k\leq j\leq n] \\&=\sum_{j,k}f(j,k)\,[1\leq k\leq n]\,[k\leq j\leq n]

\\&=\sum_{k=1}^n\,\sum_{j=k}^n f(j,k). \end{align}$$

Counting
For instance, Euler's totient function that counts the number of positive integers up to n which are coprime to n can be expressed by $$ \varphi(n)=\sum_{i=1}^{n}[\gcd(i,n)=1],\qquad\text{for } n\in\N^+.$$

Simplification of special cases
Another use of the Iverson bracket is to simplify equations with special cases. For example, the formula $$\sum_{1\le k\le n \atop \gcd(k,n)=1}\!\!k = \frac{1}{2}n\varphi(n)$$

is valid for $n &gt; 1$ but is off by $1⁄2$ for $n = 1$. To get an identity valid for all positive integers $n$ (i.e., all values for which $$\phi(n)$$ is defined), a correction term involving the Iverson bracket may be added: $$\sum_{1\le k\le n \atop \gcd(k,n)=1}\!\!k = \frac{1}{2}n \Big(\varphi(n)+[n=1]\Big)$$

Common functions
Many common functions, especially those with a natural piecewise definition, may be expressed in terms of the Iverson bracket. The Kronecker delta notation is a specific case of Iverson notation when the condition is equality. That is, $$\delta_{ij} = [i=j].$$

The indicator function, often denoted $$\mathbf{1}_A(x)$$, $$\mathbf{I}_A(x)$$ or $$\chi_A(x)$$, is an Iverson bracket with set membership as its condition: $$\mathbf{I}_A(x) = [x\in A].$$

The Heaviside step function, sign function, and absolute value function are also easily expressed in this notation: $$\begin{align} H(x) &= [x \ge 0], \\ \sgn(x) &= [x > 0] - [x < 0], \end{align}$$

and $$\begin{align} |x| &= x[x > 0] - x[x < 0] \\ &= x([x > 0] - [x < 0]) \\ &= x \cdot \sgn(x). \end{align}$$

The comparison functions max and min (returning the larger or smaller of two arguments) may be written as $$\max(x, y) = x[x > y] + y[x \leq y]$$ and $$\min(x, y) = x[x \leq y] + y[x > y].$$

The floor and ceiling functions can be expressed as $$\lfloor x \rfloor = \sum_n n \cdot [n \le x < n + 1]$$ and $$\lceil x \rceil = \sum_n n \cdot [n - 1 < x \le n],$$ where the index $$n$$ of summation is understood to range over all the integers.

The ramp function can be expressed $$R(x) = x \cdot [x \geq 0].$$

The trichotomy of the reals is equivalent to the following identity: $$[a < b] + [a = b] + [a > b] = 1. $$

The Möbius function has the property (and can be defined by recurrence as ) $$\sum_{d|n} \mu(d) \ =\ [n=1].$$

Formulation in terms of usual functions
In the 1830s, Guglielmo dalla Sommaja used the expression $$0^{0^x}$$ to represent what now would be written $$[x > 0]$$; he also used variants, such as $$\left(1 - 0^{0^{-x}}\right) \left(1 - 0^{0^{x-a}}\right)$$ for $$[0 \leq x \leq a]$$. Following one common convention, those quantities are equal where defined: $$0^{0^x}$$ is 1 if $x > 0$, is 0 if $x = 0$, and is undefined otherwise.

Notational variations
In addition to the now-standard square brackets [ · ], and the original parentheses ( · ) , blackboard bold brackets have also been used, e.g. $⟦ · ⟧$ , as well as other unusual forms of bracketing marks available in the publisher's typeface, accompanied by a marginal note.