# Temporal Multimodal Data-Processing Algorithms Based on Algebraic System of Aggregates
## 5 Algorithms of Operations on Aggregates
### Ordering Operations  
The ordering operations [19] on aggregates are sets ordering, sorting, singling, extraction, and insertion. _Sets ordering_ is an ordering operation that reorders the tuple of sets and the corresponding tuple of tuples of the aggregate \(A\), according to the given hiddenly compatible aggregate \(A_{T}\), which consists of any arbitrary elements, including dummy ones, as shown in Figure 16. The result of _sets ordering_ is the aggregate \(A_{\vdash}=A\vDash A_{T}\). The sets ordering operation can be fulfilled according to the algorithm in Listing 7. ```
Input: aggregates \(A\) and \(A_{T}\) Output: aggregate \(R\) whilenot ordereddo \(j=1\) for\(i=1:N\)do if\(\left\langle a_{i}^{j}\right\rangle_{k=1}^{n_{i}}\in M_{T}^{T}\)then \(\left\langle r_{k}\right\rangle_{k=1}^{n_{i}}=\left\langle a_{k}^{j}\right\rangle _{k=1}^{n_{i}}\) \(j=j+1\) if\(j>N\)then  sets are ordered  end end  end
```  
**Algorithm 1**The theorem on compatibility. The sets ordering operation has an important practical value that can be discovered through the following theorem and its corollary. **Theorem 1**. : _The theorem on compatibility. If \(\hat{A_{1}}=A_{1}\vDash A_{2}\) and \(\hat{A_{2}}=A_{2}\vDash A_{1}\), then \(\hat{A_{1}}\vDash A_{2}\) and \(\hat{A_{2}}\vDash A_{1}\) for \(\forall\)\(A_{1}\), \(\forall\)\(A_{2}\), such as \(A_{1}(\vDash A_{2}\)._  
**Proof of Theorem 1. ** Let us consider two arbitrary hiddenly compatible aggregates \(A_{1}\) and \(A_{2}\), i. e., \(A_{1}(\vDash)\)\(A_{2}\), and apply the sets ordering operation to these aggregates in two ways as follows:  
1. \(\hat{A_{1}}=A_{1}\vDash A_{2}\);
2. \(\hat{A_{2}}=A_{2}\vDash A_{1}\). Let us consider the aggregates \(\hat{A_{1}}\) and \(A_{2}\). As \(\hat{A_{1}}\) is the result of applying the sets ordering operation, then by Definition 11, the result of its application to the given hiddenly compatible aggregates \(A_{1}\) and \(A_{2}\) is the aggregate \(\hat{A_{1}}=\llbracket\{A_{2}\}\mid\left\langle a_{i}^{j}\right\rangle_{i=1}^{ n_{j}}\rrbracket_{j=1}^{N}\), where \(\left\langle a_{i}^{j}\right\rangle_{i=1}^{n_{j}}\in\left\langle A_{1}\right\rangle\), \(\left\langle\hat{A_{1}}\right\rangle\equiv\left\langle A_{1}\right\rangle\), which means \(\hat{A_{1}}=\llbracket\{A_{2}\}\mid\left\langle A_{1}\right\rangle\rrbracket\). Figure 16: An example of applying the sets ordering operation. According to Definition 1, the aggregate \(A_{2}\) can be presented as \(A_{2}=\llbracket\{A_{2}\}\mid\langle A_{2}\rangle\rrbracket\). According to Definition 5, two aggregates are hiddenly compatible if \(\{A_{1}\}\equiv\{A_{2}\}\), \(\mid A_{1}\mid=\mid A_{2}\mid=N\) and \(\forall M_{j}\subset\{A_{k}\},j=[1,\ldots,N]\), \(k=[1,\ 2]\). Then, \(\hat{A_{1}}=\llbracket\{A_{2}\}\mid\langle A_{1}\rangle\rrbracket\), \(A_{2}=\llbracket\{A_{2}\}\mid\langle A_{2}\rangle\rrbracket\), \(\mid\hat{A_{1}}\mid=\mid A_{2}\mid=N\). According to Definition 2, the aggregates \(\hat{A_{1}}\) and \(A_{2}\) are compatible because \(\mid\hat{A_{1}}\mid=\mid A_{2}\mid\) and \(\{\hat{A_{1}}\}\equiv\{A_{2}\}\), which we would have to prove. The compatibility of the aggregates of \(A_{1}\) and \(\hat{A_{2}}\) can be proved analogously. \(\square\)  
**Remark 1**. : _The corollary of Theorem 1. The practical significance of applying the sets ordering operation to hiddenly compatible aggregates \(A_{1}\) and \(A_{2}\) is that the components of one aggregate (\(A_{1}\)) can be rearranged according to the sequence of the components of the second aggregate (\(A_{2}\)); therefore, as a result of applying the sets ordering operation, the hiddenly compatible aggregates become compatible._  
The _sorting_ operation [19] yields a new (sorted) sequence of elements of a certain tuple named the primary tuple.