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)
$$
$diag(u) = \sum_i u_i e_ie^T_i$
Can this help you?
– Rein May 08 '13 at 05:01To answer your second question:
You can simply use : $$A_{ij}=\cases{u_i\qquad i=j\0\qquad O/W}$$ You can use the basis vector representation in the comments as well.
– Inquest May 08 '13 at 05:04