# Temporal Multimodal Data-Processing Algorithms Based on Algebraic System of Aggregates
## 5 Algorithms of Operations on Aggregates
### Logical Operations
\[A_{1}=\llbracket M_{1},M_{2}^{1},\ldots,M_{k},\ldots,M_{N^{1}}^{1} \mid\left\langle a_{1}^{1,1},a_{2}^{1,1},\ldots,a_{n_{1}^{1}}^{1,1}\right\rangle,\left\langle a_{1}^{1,2},a_{2}^{1,2},\ldots,a_{n_{2}^{1}}^{1,2}\right\rangle,\ldots,\left\langle a_{1}^{1,k},a_{2}^{1,k},\ldots,a_{n_{k}^{1}}^{1,k}\right\rangle,\ldots,\] \[\left\langle a_{1}^{1,N^{1}},a_{2}^{1,N^{1}},\ldots,a_{n_{N^{1}}}^ {1,N^{1}}\right\rangle\rrbracket,\] \[A_{2}=\llbracket M_{1},M_{2}^{2},\ldots,M_{k},\ldots,M_{N^{2}}^{2} \mid\left\langle a_{1}^{2,1},a_{2}^{2,1},\ldots,a_{n_{1}^{2}}^{2,1}\right\rangle,\left\langle a_{1}^{2,2},a_{2}^{2,2},\ldots,a_{n_{2}^{2}}^{2,2}\right\rangle,\ldots,\left\langle a_{1}^{2,k},a_{2}^{2,k},\ldots,a_{n_{k}^{2}}^{2,k}\right\rangle,\ldots,\] \[\left\langle a_{1}^{2,N^{2}},a_{2}^{2,N^{2}},\ldots,a_{n_{N^{2}}}^ {2,N^{2}}\right\rangle\rrbracket,\]  
(a) elements of the \(i\)-tuple of the aggregate \(A_{2}\) are added to the end of the \(i\)-tuple of the aggregate \(A_{1}\), if the elements of these tuples belong to the same \(i\)-set;  
(b) for all \(i\)-tuples whose elements belong to different sets, the tuple of tuples of aggregate \(A_{2}\) is added to the end of the tuple of tuples of aggregate \(A_{1}\), and the tuple of sets of aggregate \(A_{2}\) is added to the end of the tuple of sets of aggregate \(A_{1}\), with the exception of tuples subject to rule (a), which are excluded from the tuple of tuples:  
\[R_{\mathrm{U}}=A_{1}\cup A_{2}=\llbracket M_{1},M_{2}^{1},\ldots, M_{k},\ldots,M_{N^{1}}^{1},M_{2}^{2},\ldots,M_{N^{2}}^{2}\mid\left\langle a_{1}^{1,1 },a_{2}^{1,1},\ldots,a_{n_{1}^{1}}^{1,1},\right. \tag{11}\] \[\left.a_{1}^{2,1},a_{2}^{2,1},\ldots,a_{n_{1}^{2}}^{2,1}\right\rangle,\left\langle a_{1}^{1,2},a_{2}^{1,2},\ldots,a_{n_{1}^{2}}^{1,2}\right\rangle,\ldots,\left\langle a_{1}^{1,k},a_{2}^{1,k},\ldots,a_{n_{1}^{k}}^{1,k},a_{2} ^{2,k},\ldots,a_{n_{k}^{2}}^{2,k}\right\rangle,\ldots,\] \[\left.\left\langle a_{1}^{1,N^{1}},a_{2}^{1,N^{1}},\ldots,a_{n_{N ^{1}}^{1,N^{1}}}^{1}\right\rangle,\left\langle a_{1}^{2,2},a_{2}^{2,2},\ldots,a_{n_{2}^{2}}^{2,2}\right\rangle,\ldots,\left\langle a_{1}^{2,N^{2}},a_{2}^{2,N^{2}},\ldots,a_{n_{N^{2}}^{2}}^{2,N^{2}}\right\rangle\rrbracket\]This mathematical definition can be presented as the algorithm for finding a result of the union of two aggregates as shown in Listing 2. ```
Input: aggregates \(A_{1}\) and \(A_{2}\) Output: aggregate \(R\) if\(A_{1}\doteq A_{2}\)then for\(i=1:N\)do for\(k_{i}=1:n_{i}^{1}\)do\(r_{k_{i}}=a_{k_{i}}^{1,i}\) for\(k_{i}=\left(n_{i}^{1}+1\right):\left(n_{i}^{1}+n_{i}^{2}\right)\)do\(r_{k_{i}}=a_{k_{i}}^{2,i}\) end elseif\(A_{1}\doteq A_{2}\)then for\(i=1:N^{1}\)do\(\left\langle r_{k_{i}}\right\rangle_{k_{i}=1}^{n_{i}}=\left\langle a_{k_{i}}^{1,i} \right\rangle_{k_{i}=1}^{n_{i}^{1}}\) for\(i=\left(N^{1}+1\right):\left(N^{1}+N^{2}\right)\)do\(\left\langle r_{k_{i}}\right\rangle_{k_{i}=1}^{n_{i}^{2}}=\left\langle a_{k_{i}}^{2,i} \right\rangle_{k_{i}=1}^{n_{i}^{2}}\) else for\(i=1:\left(N^{1}+N^{2}\right)\)do if\(\left\langle a_{k_{i}}^{1,i}\right\rangle_{k_{i}=1}^{n_{i}^{1}}\) and \(\left\langle a_{k_{i}}^{2,i}\right\rangle_{k_{i}=1}^{n_{i}^{2}}\in M_{i}\)then for\(k_{i}=1:n_{i}^{1}\)do\(r_{k_{i}}=a_{k_{i}}^{1,i}\) for\(k_{i}=\left(n_{i}^{1}+1\right):\left(n_{i}^{1}+n_{i}^{2}\right)\)do\(r_{k_{i}}=a_{k_{i}}^{2,i}\) else \(\left\langle b_{k_{i}}\right\rangle_{k_{i}=1}^{n_{i}^{2}}=\left\langle a_{k_{i} }^{2,i}\right\rangle_{k_{i}=1}^{n_{i}^{2}}\) end end for for\(i=\left(N^{1}+N^{2}+1\right):\left(N^{1}+N^{2}+N^{b}\right)\) \(\left\langle r_{k_{i}}\right\rangle_{k_{i}=1}^{n_{i}^{2}}=\left\langle b_{k_{ i}}\right\rangle_{k_{i}=1}^{n_{i}^{2}}\) end
```  
**Algorithm 2**Algorithm of the union operation for two aggregates. The _intersection_ of the aggregates \(A_{1}\) and \(A_{2}\) is the aggregate \(R_{\cap}\), which contains components that are common to these aggregates and are ordered according to the rule defined in [18]. This rule can be presented as the algorithm for finding a result of the intersection of two aggregates as shown in Listing 3.