# Notation for the last X sorted elements of a set

I have a set of ages, $\mathbb{T}=\{30, 33, 39, 40, 41\}$. I'd like to refer to the last $X$ of these ages by $\mathbb{T}^{(X)}$. So, $\mathbb{T}^{(2)} = \{ 40, 41 \}$.

But how can I define this $\mathbb{T}^{(X)}$? Somehow I need to communicate, formally, that $\mathbb{T}^{(X)}$ is the subset of $\mathbb{T}$ containing the last $X$ elements of $\mathbb{T}$ when sorted.

FYI: I'm open to using something other than a superscripted parenthetical numeral if there's something more standard.

Why not define the $\newcommand{\T}{\mathbb T}X$ last number $\T_{(-X)}$ like this $$\T_{(-X)}=\max\left(t\mbox{ such that }\#\{s\in\T\ |\ s\geq t\}=X\right)$$ and then $$\T^{(X)}=\{t\in\T\ |\ t\geq\T_{(-X)}\}$$

• That's very nice notation! Great :) – synaptik Dec 14 '13 at 23:47

In order to use correct notation, you should note that you are dealing with a sequence, rather than a set. It is conceivable that the "set of ages" you present may have duplicate elements. In addition, you impose an order on the "set" by saying you want to take the last two. These properties are characteristic of a sequence but not of a set.

The same probably applies to your result. Presumably, if the last two elements of your sequence have the same value, you want the result to be a sequence of these two values.

It seems to me that operations on whole sequences are not very common in mathematics, however I can imagine they can be very useful. With all this in mind, we can make the following definitions, where the last definition is the one we are after. Note that we are implicitly assuming here that sequences start with index 1, although it also common to start indexing at 0.

### Definition

Let $N \in \mathbb{N}$ and for all $1 \le i \le N$ let $\ a_i \in \mathbb{R}$ and let $A = (a_i)_{i=1}^N$ be a sequence. We define $\text{sort}(A)$ as the unique nondecreasing sequence $B = (b_i)_{i=1}^N$ satisfying

$$\forall 1 \le k \le N \quad |\lbrace i \in \mathbb{N} \,|\, a_i = a_k \rbrace| = |\lbrace i \in \mathbb{N} \,|\, b_i = a_k \rbrace|$$

Note that the last equation above in words is just: $A$ has the same elements as $B$ (and when there is duplication, duplicate elements occur equally often). Probably it is more convenient to use the following instead, which just uses words.

### Definition (alternative)

Let $A$ be a sequence of real numbers. We define the sequence $\text{sort}(A)\subset \mathbb{R}$ to be the result of sorting $A$, preserving duplicate elements.

Using either definition of "sort", we can then define what you want.

### Definition

Let $N, K \in \mathbb{N}$ and for all $1 \le i \le N$ let $\ a_i \in \mathbb{R}$ and let $A = (a_i)_{i=1}^N$ be a sequence. Let $B = (b_i)_{i=1}^N = \text{sort}(A)$. We define $A^{(K)}$ to be the sequence $A^{(K)} = (c_i)_{i=1}^K$ of real numbers satisfying, for all $1 \le i \le K$, $c_i = b_{N-K+i}$.

• I would like to remark that sequences can also have duplicate elements. – Sid Aug 12 '17 at 23:20