# Simplifying an unusual quadratic linear algebra expression

I came across the following expression when solving a maximisation problem. I have the following ingredients:

• Matrices $\Omega, P \in \mathbb{R}^{n \times n}$
• Vector $t \in \mathbb{R}^n$
• Also let $\mathrm{diag}(x), x \in \mathbb{R}^n$ denote the diagonal $n \times n$ matrix whose diagonal entries are the components of $x$, $\mathrm{tr}$ be the trace of a square matrix and $\cdot$ denote usual matrix-algebra multiplication

Now, I have the following expression: $$X = \mathrm{tr} \left( \Omega \cdot \mathrm{diag}(t) \cdot P \cdot \mathrm{diag}(t) \right)$$

So it seems to me that the expression is quadratic in vector $t$, linear in $P$ and $\Omega$ - so I would expect (hope?) that it can be written as $$X = t^T \cdot f(\Omega, P) \cdot t$$ for some function $$f : \mathbb{R}^{n \times n} \times \mathbb{R}^{n \times n} \rightarrow \mathbb{R}^{n \times n}$$ which is also hopefully is expressible as something simple (linear). Is this right? If so, how can I get there? Or perhaps there are some other simplifications to this effect?

Any help, including pointers, is highly appreciated.

The $ik$ element of the thing inside the trace is
$$\omega_{ij} t_j P_{js} t_s$$ with a sum over $j$ and $s$. The trace is the sum of the $ii$ elements, hence
$$\omega_{ij} t_j P_{ji} t_i$$ summed over $i$ and $j$, which is $$\sum_i \sum_j t_j \omega_{ij}P_{ji} t_i$$ That has the form you required, with $U = f(\Omega, P)$ being a matrix whose $ij$ element is $$u_{ij} = \omega_{ji}P_{ij}.$$