# MultiAspect Graphs: Algebraic Representation and Algorithms
## 4 MAG Algorithms
### Universality of Matrix Algorithms  
In this section, we show that every function that can be obtained from a MAG to a given co-domain set can also be obtained from a matrix representation of the MAG. Here the set \(\mathbb{H}\) is the quotient set of finite MAGs under isomorphism defined in Section 2.1. Note that a permutation \(\sigma\) of a given adjacency matrix \(\mathbf{J}(H)\), together with the function \(D_{\sigma}\), represents the same MAG \(H\) as \(\mathbf{J}(H)\), so that permutations of adjacency matrices are isomorphic. Thus, we have the set \(\mathbb{J}\), which is a quotient set of pairs \((\mathbf{J}_{e},D_{\sigma})\) of adjacency matrices and association functions \(D\), under adjacency matrix permutations. Therefore, an element of \(\mathbb{J}\) is an equivalence class of adjacency matrices and \(D\) functions. Since we consider the pair \((\mathbf{J}(H),\tau(H))\) as the canonical adjacency matrix representation of the MAG \(H\), we assign this pair as the class representative of the MAG \(H\) in \(\mathbb{J}\). Theorem 1: _The adjacency matrix \(\mathbf{J}(H)\) and companion tuple \(\tau(H)\) obtained from the MAG \(H\) by Algorithm 5 are isomorphic to the MAG \(H\)._  
Proof: We show that Algorithm 5 can be seen as a function that takes a given MAG \(H\) to its adjacency matrix and companion tuple, and that this function preserves the adjacency structure of the original MAG. Further, we show that, from the adjacency matrix \(\mathbf{J}(H)\) and companion tuple \(\tau(H)\), we can construct a MAG \(\hat{H}\) that is isomorphic to MAG \(H\). * \(\implies\) Given the sets \(\mathbb{H}\) and \(\mathbb{J}\), Algorithm 5 can be seen as a function \[ \begin{split}\mathrm{Y}:\mathbb{H}&\to\mathbb{J}\\ H&\mapsto(\mathbf{J}(H),\tau(H)).\end{split} \] (33) Considering the loop depicted at lines 5 to 9 in Algorithm 5, it can be seen that every edge \(e\in E(H)\) is converted in a pair of composite vertices (\(\mathbf{u}\) and \(\mathbf{v}\)) and then represented as an edge on the adjacency matrix \(\mathbf{J}(H)\). Therefore, if the composite vertices \(\mathbf{u}\) and \(\mathbf{v}\) are adjacent in MAG \(H\), then a entry \(1\) is present at the intersection of row \(D(\mathbf{u},\tau(H))\) and column \(D(\mathbf{v},\tau(H))\) of \(\mathbf{J}(H)\), indicating the corresponding adjacency in the matrix. Hence, the adjacency structure of the MAG \(H\) is preserved by the function \(\mathrm{Y}\). * \(\Longleftarrow\) Given the adjacency matrix \(\mathbf{J}(H)\) and companion tuple \(\tau(H)\), we construct MAG \(\hat{H}\), which we then show to be isomorphic to the MAG \(H\). We obtain \(A(\hat{H})\) from \(\tau(H)\) by constructing a list \(A(\hat{H})\) with \(p=|\tau(H)|\) elements, in which every element \(i\) of this list is a set such that \(|A(\hat{H})[i]|=\tau[i]\). Without loss of generality, we can assume that the elements of each aspect \(A(\hat{H})[i]\) are natural numbers ranging from \(1\) to \(\tau[i]\). We then construct the edge set \(E(\hat{H})\), by starting with an empty set and then inserting an edge for each entry with value \(1\) in \(\mathbf{J}(H)\). For constructing each of these edges, we take an entry of value \(1\), make \(r\) equal to its row number, and \(c\) equal to its column number. We then build the edge \(e=(D^{-1}(r,\tau(H)),D^{-1}(c,\tau(H))\), which is a tuple of length \(2p\), where the first \(p\) entries correspond to the origin composite vertex and the last \(p\) entries correspond to the destination composite vertex of the edge. Note that function \(D^{-1}\) simply retrieves the original composite vertex entries from the row and column numbers of the adjacency matrix. Further, we construct the set \(\mathbb{V}(\hat{H})\) of composite vertices, which is the cartesian product of the sets in \(A(\hat{H})\), so that \[\mathbb{V}(\hat{H})=\bigvee_{n=1}^{p}A(\hat{H})[n],\] (34)where \(p=|\tau(H)|\) is the number of aspects in the MAG \(H\). We now show that the MAG \(\hat{H}\), constructed from \(\mathbf{J}(H)\) and \(\tau(H)\), is isomorphic to the original MAG \(H\).