# Notation for multiplying with logical ($x_i > N$)

For a vector $$x_i$$ and numeric values $$\theta_j$$ and $$\beta_j$$, I can write this vectorized calculation in R:

y = (x > theta1) * beta1 + (x > theta2) * beta2 + (x > theta3) * beta3


In programming, x > theta1 evaluates to TRUE (1) and FALSE (0) and multiplication is straightforward. But how do I write this as a mathematical expression? This was my first hunch, but I'm not sure it would fare well:

\begin{align} y_i =& (x_i > \theta_1) \beta_1 + (x > \theta_2) \beta_2 + (x > \theta_3) \beta_3 \\ =& \sum_{j = 1}^{3} (x_i > \theta_j) \beta_j \end{align}

I would like to avoid a notation where the cumulative nature of the expression is less obvious and which quickly grows overly long. I have many more terms and comparators in actual equations.

$$y_i = \begin{cases} \beta_1 & \text{if } x_i > \theta_1 \\ \beta_1 + \beta_2 & \text{if } x_i > \theta_2 \\ \beta_1 + \beta_2 + \beta_3 & \text{if } x_i > \theta_3 \\ \end{cases}$$

$$x_i$$ and $$\theta_j$$ are monotonically increasing.

• Are we to take it that the sequence $\theta_1, \theta_2, \ldots$ is increasing? Dec 10, 2019 at 15:45
• @CalumGilhooley, yes, and so too for $x_i$. I've updated the question with that clarification. Dec 10, 2019 at 15:59

## 2 Answers

What you are looking for is called an indicator function, which has value 1 for true expressions and value 0 for false expressions. Conventionally it is denoted by putting the logical expression in square brackets (i.e '[]').

If you are writing this up for more than your own edification, I strongly recommend that you explicitly describe this notation up front so people don't get confused wondering why you are using 'mixed' grouping symbols.

• Thank you! This is also called Iverson brackets. en.wikipedia.org/wiki/Indicator_function Dec 10, 2019 at 16:09
• See: Donald E. Knuth, "Two Notes on Notation", Amer. Math. Monthly 99, No. 5 (May, 1992), pp.403-422; and/or Ronald L. Graham, Donald E. Knuth and Oren Patashnik, Concrete Mathematics (2nd ed. 1994), p.24f. From Knuth: "I hope that within five years everybody will be able to use these notations in published papers without needing to explain what they mean." Dec 10, 2019 at 16:26

Convenient though it undoubtedly is, I don't know if the Iverson bracket notation is widely enough accepted to be used in a paper without an explanation or a reference, e.g. one of the references in the Wikipedia article just cited, including those I gave in a comment on the other answer.

(Perhaps one of the professional mathematicians who post here could comment authoritatively on that point?)

In any case, I feel that because the sequence $$\theta_1, \theta_2, \ldots$$ is increasing (incidentally, I don't think it is relevant that the sequence $$x_1, x_2, \ldots$$ is increasing), which results in the special form of the sums for the $$y_i$$ as shown at the end of the question, it would be clearer (although less snappy) to write something along these general lines (vary according to taste): $$\begin{gather*} N_x = \max\{j : \theta_j < x\}, \\ s(x) = \sum_{j=1}^{N_x}\beta_j, \\ y_i = s(x_i). \end{gather*}$$