In the derivation of Lagrange's equation from D'Alembert principle I don't understand how the term $\frac{\partial\mathbf{v}_i} {\partial q_j}$ appears.
$\sum_i \frac{\text{d}\mathbf{p}_i} {dt} \cdot \delta \mathbf{r}_i = \sum_i m_i \ddot{r}_i \cdot \delta \mathbf{r}_i = \sum_{i,j} m_i \ddot{r}_i \cdot \frac{\partial\mathbf{r}_i} {\partial q_j} \delta q_j = \sum_{i,j} \left[\frac{\partial} {\partial t} \left (m_i \dot{\mathbf{r}_i} \cdot \frac{\partial\mathbf{r}_i} {\partial q_j} - m_i \dot{\mathbf{r}_i} \cdot \frac{\partial\mathbf{v}_i} {\partial q_j} \right)\right]\delta q_j$
Apparentely it is due to the possibility to interchange the differentiation with respect to t and qj
$\frac{d}{dt} \left(\frac{\partial\mathbf{r}_i} {\partial q_j} \right) = \frac{\partial\mathbf{v}_i} {\partial q_j}$
What property of differentiation is this? the position of the particle is a function of the generalized coordinates and time:
$\mathbf{r}_i = f(q_1,q_2, \ldots, q_n, t)$
and the qs are the generalised coordinates: $\mathbf{q}(t) = (q_1(t), q_2(t), \ldots, q_n(t))$