# Trace of tensors in pseudo-Riemannian manifolds

I know that on a pseudo-Riemannian manifold $$(M,g)$$ a $$(1,1)$$ tensor field can be thought as an endomorphism of the tangent bundle. When one computes, for example, the trace of a $$2$$-covariant tensor, it is done taking into account the signature of the metric; e.g., the trace of the metric tensor is always the dimension of the manifold, because taking a locally defined orthonormal frame $$\{E_i\}_{i=1}^n$$ with index $$\{\varepsilon_i\}_{i=1}^n$$ we obtain:

\begin{aligned} tr(g)=\sum_{i=1}^n\varepsilon_ig(E_i,E_i)=n \end{aligned}

So what I'm wondering is the following: when one takes the trace of an operator like the Weingarten shape operator $$(A_\xi)_p\colon T_pM\rightarrow T_pM$$, is it correct to sum all the values of the diagonal in a matrix representation? If not, how do I take into account here the index?

For a $$(1,1)$$-tensor — as opposed to a $$(2,0)$$ or $$(0,2)$$ tensor — the index is irrelevant. The trace of a linear map is independent of the matrix representation and, indeed, of any metric structure on the vector space. The index becomes relevant only when you need to use the metric to raise or lower indices to convert a tensor to a linear map.
$$\newcommand\R{\mathbb{R}}$$ $$T_pM$$ is just a vector space. Given a vector space $$V$$, a $$(1,1)$$ tensor is just a linear map $$L: V \rightarrow V$$. The trace of $$L$$ is defined as follows: Given any basis $$(e_1, \dots, e_n)$$ of $$V$$, there is a matrix $$M$$ such that $$L(e_j) = M_j^ie_i.$$ The trace of $$L$$ is $$\sum_{i=1}^n M^i_i$$. You can check that this is independent of the basis used. The trace of the shape operator uses this definition.
On the other hand, a $$(2,0)$$ tensor is a bilinear map $$b: V\times V \rightarrow \R$$. To take the trace, you need a nondegenerate $$(0,2)$$ tensor. A pseudoriemannian metric $$g$$ is a nondegenerate $$(2,0)$$ tensor, and its inverse defines a $$(0,2)$$ tensor. Given a basis $$(e_1, \dots, e_n)$$ of $$V$$, the trace of $$b$$ with respect to $$g$$ is defined to be $$g^{ij}b_{ij}.$$ And indeed the trace of $$g$$ with respect itself is $$n$$.