Using set-builder notation in an unusual way for more concise expressions in a definition. Good style?

67 Views Asked by At

What do you think about the following usage of the set-builder notation $\{ x \mid P(x) \}$? Let $Y = \{ p_1, \ldots, p_n \}$ be $n$ objects and $A,B$ subsets of $Y$. Define a function from $\{1,\ldots,n\} \times X$, where $X$ is a set, to subsets of $Y$ in the following way for each $i \in \{1,\ldots,n\}$: $$ f(i, x) = \begin{cases} \{ p_i \mid x \in A \} \cup \{ p_{i+1} \mid x \in B \} & \text{if } i \in \{1,\ldots,n-1\}, \\ \{ p_i \mid x \in A \} & \text{if } i = n. \end{cases} $$ In the more "traditional" notation it would be written as: $$ f(i, x) = \begin{cases} \{ p_i, p_{i+1} \} & \text{if } x \in A \cap B, i \in \{1,\ldots,n-1\} \\ \{ p_i \} & \text{if } x \in A \setminus B \text{ or } i = n, x \in A \\ \emptyset & \text{otherwise.} \end{cases} $$ The first variant is probably not how set-builder notation is intended to be used, as it basically reduces to $\{ p_i \mid TRUE \} = \{p_i\}$ or $\{ p_i \mid FALSE \} = \emptyset$ depending on the value of $x$. I think it is valid to write expressions like that. But what do you think style-wise? Do you think such a usage should be avoided? In my opinion the first version is a little more concise, but this is just my personal opinion. Maybe you disagree...