Algebra and Substitution in Quadratic Form―Einstein Summation Notation 
Schaum's Outline to Tensor Calculus ― chapter 1, example 1.5 ―――
If $y_i = a_{ij}x_j$, express the quadratic form $Q = g_{ij}y_iy_j$ in terms of the $x$-variables.
Solution: I can't substitute $y_i$ directly because it contains $j$ and there's already a $j$ in the given quadratic form. So $y_i = a_{i \huge{j}}x_{\huge{j}} = a_{i \huge{r}}x_{\huge{r}}$.
This implies $ y_{\huge{j}} = a_{{\huge{j}}r}x_r.$ But I already used $r$ (in the sentence before the previous) so need to replace $r$ ――― $ y_j = a_{j \huge{r}}x_{\huge{r}} =  a_{j \huge{s}}x_{\huge{s}}.$
Therefore, by substitution, $Q = g_{ij}(a_{ir}x_r)(a_{js}x_s)$
$$ = g_{ij}a_{ir}a_{js}x_rx_s. \tag{1}$$ $$= h_{rs}x_rx_s, \text{ where } h_{rs} = g_{ij}a_{ir}a_{js}.   \tag{2}$$

Equation ($1$): Why can they commute $a_{js}$ and $x_r$? How are any of the terms commutative?
Equation ($2$): How does $rs$ get to be the subscript of $h$? Why did they define $h_{rs}$?

In equation (1) $a_{js}$ and $x_r$ commute because these are just regular (reals or complex) numbers using standard multiplication which is commutative.
Equation (2) $h_{rs}$ is defined to save space more than anything, it's the coefficients of the polynomial in $x_i$.
