Let matrix $A$ be sparse and symmetric but not semidefinite. Since I would like to use projected gradient descent, I must find the gradient of $x \mapsto \frac{1}{2}(x^2)^\top A(x^2)$, where $x^2 = \operatorname{diag}(x)x$, $$\operatorname{diag}\begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} = \begin{pmatrix} x_1 & 0 & 0 \\ 0 & x_2 & 0 \\ 0 & 0 & x_3 \end{pmatrix},$$ and $x \in \mathbb R^n$. How can I do it?
I know the cases where $x^2$ is replaced by $x$ but not this case.
Let \begin{gather*} f(x)=\frac{1}{2}x^{\mathsf{T}}\mathcal{A}x \\ g(x)=\mathrm{diag}(x)x \end{gather*}
You already know $$\mathcal{D}(f)(x)=x^{\mathsf{T}}\mathcal{A}$$ We can compute directly $$\mathcal{D}(g)(x)_{j,k}=\frac{\partial(x_j^2)}{\partial x_k}=2x_j\delta_{j,k}$$ where $\delta$ is the Kronecker delta. Thus $$\mathcal{D}(g)(x)=2\mathrm{diag}{(x)}$$
Finally, by the multivariate chain rule, $$\mathcal{D}(f\circ g)(x)=\mathcal{D}(f)(g(x))\mathcal{D}(g)(x)=2x^{\mathsf{T}}\mathrm{diag}(x)^{\mathsf{T}}\mathcal{A}\mathrm{diag}{(x)}$$