Are there any properties of the diag operator? Let $u$ and $v$ be a column vector of same dimension. 


*

*1.) Can anyone give some properties about the operations of function, such as $\text{diag}(u)+\text{diag}(v)=\text{diag}(u+v)$? 

*2.) Is there any mathematical representation  to express the function diag? 


Thanks a lot. 
 A: Compilation of comments: 
1) The operator $\mathrm{diag}$ is a linear isomorphism between $\mathbb F^n$ and the subspace of $n\times n$ diagonal matrices. (EuYu) If both spaces are equipped with natural inner products, $\mathrm{diag}$ becomes an isometric isomorphism. 
2) $\operatorname{diag}(u) = \sum_i u_i e_ie^T_i$ (Rein), where you can put $u_i=e_i^T u$ if you prefer.
A: The previous answers are using the definition of the $diag$ that is the mapping $\mathbb{R}^n \rightarrow \mathbb{R}^{n\times n}$. Which can be represented as,
\begin{align*}
diag(u)= \left( u {\bf 1}^{\sf T}\right) \odot {\bf I}
\end{align*}
where $u \in \mathbb{R}^n$ is a column vector, ${\bf 1}$ is a column vecotr of all ones, ${\bf I} \in \mathbb{R}^{n\times n}$ is the identity matrix, and $\odot$ is the elementwise (or Hadamard) product. This definition will have proofs very similar to the following.
Assuming the operator being talked about is the $diag$ operator that maps $\mathbb{R}^{n\times n}\rightarrow \mathbb{R}^{n\times n}$, specifically the operator that `selects' the diagonal of a matrix. Then it can be represented as:
\begin{align*}
diag(A)={\bf I} \odot A
\end{align*}
where $A\in \mathbb{R}^{n\times n}$, $\bf I$ is the identity matrix, and $\odot$ is the elementwise (or Hadamard) product. This can be quite useful for deriving any properties of the operator that is needed. Additionally, the Hadamard product has plenty of properties that can be used to infer properties of the $diag $ operator. In order to show the properties you ask for in the question, the main thing to note would be the Hadamard product functions identically to multiplication for scalars. Namely, associativity, this is unlike normal matrix multiplication. To see this note:
$$
{\bf I} \odot A \rightarrow {\bf I}_{\{i,j\}}A_{\{i,j\}}\\
$$
Where the lower indices represent a matrix element. The right-hand side of this equation technically represents $n^2$ scalar equations which when `stacked' correctly result in the left-hand side. Note that the right-hand side splits into two possibilities, $A_{\{i,j\}}$ if and only if $i=j$, otherwise $0$. For proving the properties asked for the indexed notation is simpler to work with. Take a matrix $B \in \mathbb{R}^{n\times n}$, then
$$
A + B \rightarrow A_{\{i,j\}} + B_{\{i,j\}}
$$
Therefore looking at the sum of their diagonals
\begin{align*}
diag(A)+diag(B) = {\bf I} \odot A + {\bf I} \odot B &\rightarrow {\bf I}_{\{i,j\}}A_{\{i,j\}} + {\bf I}_{\{i,j\}}B_{\{i,j\}} \\\
%
&= {\Big \{}^{ \mbox{if $i=j$     } A_{\{i,j\}} + B_{\{i,j\}}}_{\mbox{otherwise    0}} \\\
&= {\bf I}_{\{i,j\}}\left(A_{\{i,j\}} + B_{\{i,j\}}\right)\\\
&\rightarrow diag(A+B)
\end{align*}
Similarly, treating the objects similarly can be used for further proof. Additionally note that timesing the left and right of $\left({\bf I} \odot A\right)$ with a column vector of ones will result in the trace of a matrix. Specifically,
\begin{align*}
Trace\left(A\right) = {\bf 1}^{\sf T}diag\left( A \right){\bf 1} ={\bf 1}^{\sf T}\left({\bf I} \odot A \right){\bf 1}
\end{align*}
Therefore it is simple to see that the previously prooved property of the diag function also holds for the trace,
$$
Trace(A) + Trace(B) = Trace(A+B) 
$$
