I am working on a problem relating to Lyapunov exponents of products of random matrices, and this has led me to the following question which I suspect is best approached using techniques outside my area of expertise:

Let $\tau \colon SL_2^\pm(\mathbb{R})^k \to \mathbb{R}$ be a function which has the form $$\tau(A_1,\ldots,A_k):=\mathrm{tr }\left(A_{i_n}A_{i_{n-1}}\cdots A_{i_2}A_{i_1}\right)$$ for some fixed indices $i_1,i_2,\ldots,i_n \in \{1,\ldots,k\}$. Can $\tau$ have a local maximum or a local minimum at one of its zeros?

My main area of mathematical expertise is analysis, so I apologise if this is actually very easy to solve using tools with which I am unfamiliar. Since I am not sure which aspects of the problem are most significant in its solution I have taken a somewhat scattershot approach to tagging: please feel free to adjust the tags if you feel that they are inappropriate.

Some remarks on the question:

- Local maxima and minima are of course not strict, since if $B \in SL_2(\mathbb{R})$ is close to the identity then $(B^{-1}A_1B,\ldots,B^{-1}A_kB)$ is close to, and typically distinct from, $(A_1,\ldots,A_k)$ but is taken to the same value by $\tau$.
- It is certainly possible for a function of this type to have a local minimum. For example, if $k=1$, $\tau(A_1):=\mathrm{tr }A_1^2$ then a local minimum is achieved when $A_1$ has trace zero and determinant $-1$. The value of $\tau$ at the minimum in this case is $2$.
- A solution which treated only the case $k=2$, but in which $n$ and $i_1,\ldots,i_n \in \{1,2\}$ were allowed to be arbitrary, would still be interesting to me.
- I would find a complete treatment of the case $\det A_{i_n} \cdots A_{i_1}=1$ mildly interesting, but my main interest is in the case where the determinant of the product is negative.

**Updated to add**: Will Sawin shows below that if $(A_1,\ldots,A_n)$ is a critical point of $\tau$ with respect to differentiation in the variable $A_r$, and is also a zero of $\tau$, then
$$\sum_{\substack{1 \leq \ell \leq n\\ i_\ell=r}} A_{i_\ell} \cdots A_{i_1}A_{i_n}\cdots A_{i_{\ell+1}}=0$$
and this equation is impossible if $(A_1,\ldots,A_k) \in SL_2(\mathbb{R})^k$. Using a slightly different argument suggested by Will's answer I can show that a tuple $(A_1,\ldots,A_k) \in SL_2^\pm(\mathbb{R})^k$ which satisfies $\tau(A_1,\ldots,A_k)=0$ is a critical point of $\tau$ if and only if for each $r \in \{1,\ldots,k\}$
$$\sum_{\substack{1 \leq \ell \leq n\\ i_\ell=r}} \left((A_{i_n}\cdots A_{i_{\ell+1}})X(A_{i_n}\cdots A_{i_{\ell+1}})^{-1}+(A_{i_\ell}\cdots A_{i_{1}})^{-1}X(A_{i_\ell}\cdots A_{i_{1}}))\right)=0$$
for every traceless matrix $X$. Details are given below as an answer. This result implies in particular that if any symbol $r \in \{1,\ldots,k\}$ occurs exactly once in the word $i_1\cdots i_n$, then $\tau$ does not have a zero which is also a critical point, a result which is clearly also implied by Will's work.

It is at this stage an open question whether $\tau$ can have critical points which are also zeros.

Here is an example which shows that a zero of $\tau$ can be a critical point with respect to directional derivatives in a single co-ordinate. Define $$B_1:=\left(\begin{array}{cc}1&0\\0&1\end{array}\right),\qquad B_2:=\left(\begin{array}{cc}0&1\\1&0\end{array}\right),\qquad B_3:=\left(\begin{array}{cc}1&0\\0&-1\end{array}\right).$$ It can be checked by hand that $B_3e^{tX}B_1B_2e^{tX}B_1$ is traceless for all $t \in \mathbb{R}$ when $X$ is any of the traceless matrices $$\left(\begin{array}{cc}1&0\\0&-1\end{array}\right),\qquad \left(\begin{array}{cc}0&1\\0&0\end{array}\right),\qquad \left(\begin{array}{cc}0&1\\1&0\end{array}\right)$$ and in particular in this case the derivative of $\tau$ in the first variable at $(B_1,B_2,B_3)$ is zero. One may easily check by hand that $B_3B_1B_2B_1$ is traceless and hence is a zero of $\tau(A_1,A_2,A_3):=A_3A_1A_2A_1$. This triple is not a critical point with respect to directional derivatives in the other variables.